Improve help/man page of para_write.
authorAndre Noll <maan@systemlinux.org>
Sat, 6 Dec 2008 13:37:03 +0000 (14:37 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 6 Dec 2008 13:37:03 +0000 (14:37 +0100)
Makefile.in
alsa_write.c
alsa_write.ggo
configure.ac
file_write.c
file_write.ggo
write.c
write.ggo
write.h
write_common.c

index 9e78b67..1563739 100644 (file)
@@ -117,6 +117,7 @@ grab_client.cmdline.h grab_client.cmdline.c: grab_client.ggo
                fsck.ggo) O="--unamed-opts=table";; \
                afh.ggo) O="--unamed-opts=audio_file";; \
                filter.ggo) O="--no-handle-help";; \
+               write.ggo) O="--no-handle-help";; \
        esac; \
        if test $< != fsck.ggo; then O="$$O --conf-parser "; fi; \
        gengetopt $$O \
@@ -148,6 +149,10 @@ man/man1/para_filter.1: para_filter
        mkdir -p man/man1
        help2man -h --detailed-help -N ./$< > $@
 
+man/man1/para_write.1: para_write
+       mkdir -p man/man1
+       help2man -h --detailed-help -N ./$< > $@
+
 man/man1/%.1: %
        mkdir -p man/man1
        help2man -N ./$< > $@
index 89d1995..9f60d6d 100644 (file)
@@ -21,6 +21,7 @@
 #include "string.h"
 #include "list.h"
 #include "sched.h"
+#include "ggo.h"
 #include "write.h"
 #include "alsa_write.cmdline.h"
 #include "error.h"
@@ -236,10 +237,19 @@ err_out:
  */
 void alsa_write_init(struct writer *w)
 {
+       struct alsa_write_args_info dummy;
+
+       alsa_cmdline_parser_init(&dummy);
        w->open = alsa_open;
        w->close = alsa_close;
        w->pre_select = alsa_write_pre_select;
        w->post_select = alsa_write_post_select;
        w->parse_config = alsa_parse_config;
        w->shutdown = NULL; /* nothing to do */
+       w->help = (struct ggo_help) {
+               .purpose = alsa_write_args_info_purpose,
+               .usage = alsa_write_args_info_usage,
+               .short_help = alsa_write_args_info_help,
+               .detailed_help = alsa_write_args_info_detailed_help
+       };
 }
index 371ec89..84f49d5 100644 (file)
@@ -1,28 +1,34 @@
-section "alsa options"
-######################
-
 option "device" d
 #~~~~~~~~~~~~~~~~
 "set PCM device"
-       string typestr="device"
-       default="default"
-       optional
+string typestr="device"
+default="default"
+optional
+details="
+       On systems with dmix, a better choice than the default
+       value might be to use \"plug:swmix\".
+"
 
 option "channels" c
 #~~~~~~~~~~~~~~~~~~
-"number of channels (only necessary for raw
-audio)"
-
-       int typestr="num"
-       default="2"
-       optional
+"specify number of channels"
+int typestr="num"
+default="2"
+optional
+details="
+       This option is only necessary for playing raw audio with
+       para_write.  In all other cases (plaing wav files with
+       para_write or using this writer with para_audiod), the number
+       of channels will be obtained from other resources.
+"
 
 option "samplerate" s
 #~~~~~~~~~~~~~~~~~~~~~
-
-"force given sample rate (only necessary for
-raw audio)"
-
-       int typestr="num"
-       default="44100"
-       optional
+"force given sample rate"
+int typestr="num"
+default="44100"
+optional
+details="
+       Again, it is only necessary to specify this when playing raw
+       audio with para_write.
+"
index 2429bfb..04a4e93 100644 (file)
@@ -127,7 +127,7 @@ server_ldflags=""
 server_audio_formats=" mp3"
 
 write_cmdline_objs="write.cmdline file_write.cmdline"
-write_errlist_objs="write write_common file_write time fd string sched stdin"
+write_errlist_objs="write write_common file_write time fd string sched stdin ggo"
 write_ldflags=""
 writers=" file"
 default_writer="FILE_WRITE"
index 839515f..be1e771 100644 (file)
@@ -12,6 +12,7 @@
 #include "para.h"
 #include "list.h"
 #include "sched.h"
+#include "ggo.h"
 #include "write.h"
 #include "string.h"
 #include "fd.h"
@@ -109,10 +110,19 @@ __malloc static void *file_write_parse_config(const char *options)
 /** the init function of the file writer */
 void file_write_init(struct writer *w)
 {
+       struct file_write_args_info dummy;
+
+       file_cmdline_parser_init(&dummy);
        w->open = file_write_open;
        w->pre_select = file_write_pre_select;
        w->post_select = file_write_post_select;
        w->parse_config = file_write_parse_config;
        w->close = file_write_close;
        w->shutdown = NULL; /* nothing to do */
+       w->help = (struct ggo_help) {
+               .purpose = file_write_args_info_purpose,
+               .usage = file_write_args_info_usage,
+               .short_help = file_write_args_info_help,
+               .detailed_help = file_write_args_info_detailed_help
+       };
 }
index a172f75..56c44f7 100644 (file)
@@ -1,11 +1,9 @@
-section "file writer options"
-
 option "filename" f
 #~~~~~~~~~~~~~~~~~~
-
-"select output file name. Defaults to a
-random filename in ~/.paraslash."
-
-       string typestr="filename"
-       optional
+"specify output file name"
+string typestr="filename"
+optional
+details="
+       Defaults to a random filename in ~/.paraslash.
+"
 
diff --git a/write.c b/write.c
index 998a6d2..6e78e77 100644 (file)
--- a/write.c
+++ b/write.c
@@ -14,6 +14,7 @@
 #include "write.cmdline.h"
 #include "list.h"
 #include "sched.h"
+#include "ggo.h"
 #include "stdin.h"
 #include "write.h"
 #include "write_common.h"
@@ -129,20 +130,6 @@ static struct writer_node_group *check_args(void)
        struct writer_node_group *g = NULL;
        struct initial_delay_task *idt = &the_initial_delay_task;
 
-       if (conf.list_writers_given) {
-               char *msg = NULL;
-               FOR_EACH_WRITER(i) {
-                       char *tmp = make_message("%s%s%s",
-                               i? msg : "",
-                               i? " " : "",
-                               writer_names[i]);
-                       free(msg);
-                       msg = tmp;
-               }
-               fprintf(stderr, "%s\n", msg);
-               free(msg);
-               exit(EXIT_SUCCESS);
-       }
        if (conf.start_time_given) {
                long unsigned sec, usec;
                if (sscanf(conf.start_time_arg, "%lu:%lu",
@@ -174,6 +161,33 @@ out:
        return NULL;
 }
 
+__noreturn static void print_help_and_die(void)
+{
+       int i, d = conf.detailed_help_given;
+       const char **p = d? write_args_info_detailed_help
+               : write_args_info_help;
+
+       printf_or_die("%s\n\n", WRITE_CMDLINE_PARSER_PACKAGE "-"
+               WRITE_CMDLINE_PARSER_VERSION);
+       printf_or_die("%s\n\n", write_args_info_usage);
+       for (; *p; p++)
+               printf_or_die("%s\n", *p);
+
+       printf_or_die("\nAvailable writers: \n\t");
+       FOR_EACH_WRITER(i)
+               printf_or_die("%s%s", i? " " : "", writer_names[i]);
+       printf_or_die("\n\n");
+       FOR_EACH_WRITER(i) {
+               struct writer *w = writers + i;
+
+               if (!w->help.short_help)
+                       continue;
+               printf_or_die("Options for %s:\n", writer_names[i]);
+               ggo_print_help(&w->help, d);
+       }
+       exit(0);
+}
+
 /**
  * Para_write's main function.
  *
@@ -192,9 +206,11 @@ int main(int argc, char *argv[])
        struct check_wav_task *cwt = &the_check_wav_task;
        struct initial_delay_task *idt = &the_initial_delay_task;
 
+       init_supported_writers();
        write_cmdline_parser(argc, argv, &conf);
        HANDLE_VERSION_FLAG("write", conf);
-       init_supported_writers();
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
 
        wng = check_args();
        if (!wng)
index 1ea8abf..8f557bb 100644 (file)
--- a/write.ggo
+++ b/write.ggo
@@ -1,45 +1,35 @@
-section "general options"
-#########################
-
-option "list_writers" L
-#~~~~~~~~~~~~~~~~~~~~~~
-"print available writers and exit"
-
-       flag off
-
 option "loglevel" l
 #~~~~~~~~~~~~~~~~~~
 "set loglevel (0-6)"
-
-       int typestr="level"
-       default="4"
-       optional
+int typestr="level"
+default="4"
+optional
 
 option "bufsize" b
 #~~~~~~~~~~~~~~~~~
 "input buffer size"
-
-       int typestr="kilobytes"
-       default="64"
-       optional
+int typestr="kilobytes"
+default="64"
+optional
 
 option "writer" w
 #~~~~~~~~~~~~~~~~
-
-"select stream writer
-may be give multiple times. The same writer
-may be specified more than once"
-
-       string typestr="name"
-       default="alsa (file if alsa is unsupported)"
-       optional
-       multiple
+"select stream writer"
+string typestr="name"
+default="alsa (file if alsa is unsupported)"
+optional
+multiple
+details="
+       May be give multiple times. The same writer may be specified
+       more than once.
+"
 
 option "start_time" t
 #~~~~~~~~~~~~~~~~~~~~
-"start playback at given time which must be
-in a:b format where a denotes seconds and b
-denotes microseconds since the epoch"
-
-       string typestr="timeval"
-       optional
+"defer playback"
+string typestr="timeval"
+optional
+details="
+       Start playback at given time which must be in a:b format where
+       a denotes seconds and b denotes microseconds since the epoch.
+"
diff --git a/write.h b/write.h
index 9723977..7df62f9 100644 (file)
--- a/write.h
+++ b/write.h
@@ -84,6 +84,7 @@ struct writer {
         * This is a optional function pointer used for cleaning up.
         */
        void (*shutdown)(struct writer_node *);
+       struct ggo_help help;
 };
 
 /**
index 3bf5d11..d66b20c 100644 (file)
@@ -10,6 +10,7 @@
 #include "string.h"
 #include "list.h"
 #include "sched.h"
+#include "ggo.h"
 #include "write.h"
 #include "error.h"