Make it accept an optional parameter, e.g. -help codecs/formats/... is
possible.

Make -formats/-codecs/... options aliases for -help <...>.
---
 avconv.c                     |    3 +--
 avplay.c                     |    5 +----
 avprobe.c                    |    3 +--
 avserver.c                   |    2 +-
 cmdutils.c                   |   32 +++++++++++++++++++++++++++-----
 cmdutils.h                   |   40 ++++++++++------------------------------
 cmdutils_common_opts.h       |   18 +++++++++---------
 doc/fftools-common-opts.texi |    6 ++++--
 ffmpeg.c                     |    3 +--
 9 files changed, 55 insertions(+), 57 deletions(-)

diff --git a/avconv.c b/avconv.c
index 6804a3b..6819647 100644
--- a/avconv.c
+++ b/avconv.c
@@ -3737,14 +3737,13 @@ static void show_usage(void)
     printf("\n");
 }
 
-static void show_help(void)
+void show_help(void)
 {
     AVCodec *c;
     AVOutputFormat *oformat = NULL;
     AVInputFormat  *iformat = NULL;
     const AVClass *class;
 
-    av_log_set_callback(log_callback_help);
     show_usage();
     show_help_options(options, "Main options:\n",
                       OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | 
OPT_GRAB, 0);
diff --git a/avplay.c b/avplay.c
index 198dce1..8fdc0b4 100644
--- a/avplay.c
+++ b/avplay.c
@@ -216,8 +216,6 @@ typedef struct VideoState {
     int refresh;
 } VideoState;
 
-static void show_help(void);
-
 /* options specified by the user */
 static AVInputFormat *file_iformat;
 static const char *input_filename;
@@ -2977,10 +2975,9 @@ static void show_usage(void)
     printf("\n");
 }
 
-static void show_help(void)
+void show_help(void)
 {
     const AVClass *class;
-    av_log_set_callback(log_callback_help);
     show_usage();
     show_help_options(options, "Main options:\n",
                       OPT_EXPERT, 0);
diff --git a/avprobe.c b/avprobe.c
index 5e83916..825fd2b 100644
--- a/avprobe.c
+++ b/avprobe.c
@@ -358,10 +358,9 @@ static void opt_input_file(void *optctx, const char *arg)
     input_filename = arg;
 }
 
-static void show_help(void)
+void show_help(void)
 {
     const AVClass *class = avformat_get_class();
-    av_log_set_callback(log_callback_help);
     show_usage();
     show_help_options(options, "Main options:\n", 0, 0);
     printf("\n");
diff --git a/avserver.c b/avserver.c
index df9d07d..de405e4 100644
--- a/avserver.c
+++ b/avserver.c
@@ -4648,7 +4648,7 @@ static void opt_debug(void)
     logfilename[0] = '-';
 }
 
-static void show_help(void)
+void show_help(void)
 {
     printf("usage: avserver [options]\n"
            "Hyper fast multi format Audio/Video streaming server\n");
diff --git a/cmdutils.c b/cmdutils.c
index 52ec96f..6a94ef1 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -524,7 +524,7 @@ void show_license(void)
     );
 }
 
-void show_formats(void)
+static void show_formats(void)
 {
     AVInputFormat *ifmt=NULL;
     AVOutputFormat *ofmt=NULL;
@@ -573,7 +573,7 @@ void show_formats(void)
     }
 }
 
-void show_codecs(void)
+static void show_codecs(void)
 {
     AVCodec *p=NULL, *p2;
     const char *last_name;
@@ -649,7 +649,7 @@ void show_codecs(void)
 "worse.\n");
 }
 
-void show_bsfs(void)
+static void show_bsfs(void)
 {
     AVBitStreamFilter *bsf=NULL;
 
@@ -659,7 +659,7 @@ void show_bsfs(void)
     printf("\n");
 }
 
-void show_protocols(void)
+static void show_protocols(void)
 {
     void *opaque = NULL;
     const char *name;
@@ -673,7 +673,7 @@ void show_protocols(void)
         printf("%s\n", name);
 }
 
-void show_filters(void)
+static void show_filters(void)
 {
     AVFilter av_unused(**filter) = NULL;
 
@@ -717,6 +717,28 @@ void show_pix_fmts(void)
     }
 }
 
+int show_help_common(const char *opt, const char *arg)
+{
+    av_log_set_callback(log_callback_help);
+
+    if      (!strcmp(opt, "codecs")    || (arg && !strcmp(arg, "codecs")))
+        show_codecs();
+    else if (!strcmp(opt, "formats")   || (arg && !strcmp(arg, "formats")))
+        show_formats();
+    else if (!strcmp(opt, "bsfs")      || (arg && !strcmp(arg, "bsfs")))
+        show_bsfs();
+    else if (!strcmp(opt, "protocols") || (arg && !strcmp(arg, "protocols")))
+        show_protocols();
+    else if (!strcmp(opt, "pix_fmts")  || (arg && !strcmp(arg, "pix_fmts")))
+        show_pix_fmts();
+    else if (!strcmp(opt, "filters")   || (arg && !strcmp(arg, "filters")))
+        show_filters();
+    else
+        show_help();
+
+    return 0;
+}
+
 int read_yesno(void)
 {
     int c = getchar();
diff --git a/cmdutils.h b/cmdutils.h
index 989d769..3dfd4eb 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -155,6 +155,16 @@ typedef struct {
 void show_help_options(const OptionDef *options, const char *msg, int mask, 
int value);
 
 /**
+ * Tool's own specific help function.
+ */
+void show_help(void);
+
+/*
+ * Common help function.
+ */
+int show_help_common(const char *opt, const char *arg);
+
+/**
  * Parse the command line arguments.
  *
  * @param optctx an opaque options context
@@ -242,36 +252,6 @@ void show_version(void);
 void show_license(void);
 
 /**
- * Print a listing containing all the formats supported by the
- * program.
- */
-void show_formats(void);
-
-/**
- * Print a listing containing all the codecs supported by the
- * program.
- */
-void show_codecs(void);
-
-/**
- * Print a listing containing all the filters supported by the
- * program.
- */
-void show_filters(void);
-
-/**
- * Print a listing containing all the bit stream filters supported by the
- * program.
- */
-void show_bsfs(void);
-
-/**
- * Print a listing containing all the protocols supported by the
- * program.
- */
-void show_protocols(void);
-
-/**
  * Print a listing containing all the pixel formats supported by the
  * program.
  */
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h
index 9b5e5d2..ce9910f 100644
--- a/cmdutils_common_opts.h
+++ b/cmdutils_common_opts.h
@@ -1,13 +1,13 @@
     { "L", OPT_EXIT, {(void*)show_license}, "show license" },
-    { "h", OPT_EXIT, {(void*)show_help}, "show help" },
+    { "h", OPT_EXIT,         {.func_arg = show_help_common}, "show help" },
     { "?", OPT_EXIT, {(void*)show_help}, "show help" },
-    { "help", OPT_EXIT, {(void*)show_help}, "show help" },
-    { "-help", OPT_EXIT, {(void*)show_help}, "show help" },
+    { "help", OPT_EXIT,      {.func_arg = show_help_common}, "show help" },
+    { "-help", OPT_EXIT,     {.func_arg = show_help_common}, "show help" },
     { "version", OPT_EXIT, {(void*)show_version}, "show version" },
-    { "formats"  , OPT_EXIT, {(void*)show_formats  }, "show available formats" 
},
-    { "codecs"   , OPT_EXIT, {(void*)show_codecs   }, "show available codecs" 
},
-    { "bsfs"     , OPT_EXIT, {(void*)show_bsfs     }, "show available bit 
stream filters" },
-    { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available 
protocols" },
-    { "filters",   OPT_EXIT, {(void*)show_filters  }, "show available filters" 
},
-    { "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel 
formats" },
+    { "formats"  , OPT_EXIT, {.func_arg = show_help_common}, "show available 
formats" },
+    { "codecs"   , OPT_EXIT, {.func_arg = show_help_common}, "show available 
codecs" },
+    { "bsfs"     , OPT_EXIT, {.func_arg = show_help_common}, "show available 
bit stream filters" },
+    { "protocols", OPT_EXIT, {.func_arg = show_help_common}, "show available 
protocols" },
+    { "filters",   OPT_EXIT, {.func_arg = show_help_common}, "show available 
filters" },
+    { "pix_fmts" , OPT_EXIT, {.func_arg = show_help_common}, "show available 
pixel formats" },
     { "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", 
"loglevel" },
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 8ffc329..1dc003e 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -20,8 +20,10 @@ These options are shared amongst the ff* tools.
 @item -L
 Show license.
 
-@item -h, -?, -help, --help
-Show help.
+@item -h, -?, -help, --help [@var{item}]
+Show help. If @var{item} is specified, show help on it.
+@var{item} may be one of @code{formats}, @code{codecs}, @code{bsfs},
+@code{protocols}, @code{filters}, @code{pix_fmts}.
 
 @item -version
 Show version.
diff --git a/ffmpeg.c b/ffmpeg.c
index a440b9d..397f3c3 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3921,14 +3921,13 @@ static void show_usage(void)
     printf("\n");
 }
 
-static void show_help(void)
+void show_help(void)
 {
     AVCodec *c;
     AVOutputFormat *oformat = NULL;
     AVInputFormat  *iformat = NULL;
     const AVClass *class;
 
-    av_log_set_callback(log_callback_help);
     show_usage();
     show_help_options(options, "Main options:\n",
                       OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | 
OPT_GRAB, 0);
-- 
1.7.5.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to