[daala] Add --version flag to examples #84

Tristan Matthews tmatth at videolan.org
Mon Apr 27 14:37:30 PDT 2015


On Mon, Apr 27, 2015 at 5:11 PM, Danesh Daroui <danesh.daroui at gmail.com> wrote:
> Here comes a new patch where I used PACKAGE_STRING to show when "--version"
> is used in example codes.

> ---
>  examples/dump_video.c      | 15 ++++++++++++++-
>  examples/encoder_example.c | 10 ++++++++++
>  examples/player_example.c  |  3 +++
>  3 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/examples/dump_video.c b/examples/dump_video.c
> index c111493..b3e13b2 100644
> --- a/examples/dump_video.c
> +++ b/examples/dump_video.c
> @@ -63,6 +63,7 @@ const char *optstring = "o:r";
>  struct option options [] = {
>    { "output", required_argument, NULL, 'o' },
>    { "raw", no_argument, NULL, 'r' }, /*Disable YUV4MPEG2 headers:*/
> +  { "version", no_argument, NULL, 0},
>    { NULL, 0, NULL, 0 }
>  };
>
> @@ -164,7 +165,13 @@ static void usage(void) {
>     "                            this option is not given, the\n"
>     "                            decompressed data is sent to stdout.\n"
>     "  -r --raw                  Output raw YUV with no framing instead\n"
> -   "                            of YUV4MPEG2 (the default).\n");
> +   "                            of YUV4MPEG2 (the default).\n"
> +   "     --version              Displays version information.\n");

No -v?

> +  exit(EXIT_FAILURE);
> +}
> +
> +static void version(void) {
> +  fprintf(stderr, "%s\n", PACKAGE_STRING);
>    exit(EXIT_FAILURE);

This should exit(EXIT_SUCCESS), IMHO since --version presumably wasn't
called in error.

>  }
>
> @@ -210,6 +217,12 @@ int main(int argc, char *argv[]) {
>          raw = 1;
>          break;
>        }
> +      case 0: {
> +        if (strcmp(options[long_option_index].name, "version") == 0) {
> +          version();
> +        }
> +        break;
> +      }
>        default: usage(); break;
>      }
>    }
> diff --git a/examples/encoder_example.c b/examples/encoder_example.c
> index 5520a32..0f4ddaa 100644
> --- a/examples/encoder_example.c
> +++ b/examples/encoder_example.c
> @@ -383,6 +383,7 @@ static const struct option OPTIONS[] = {
>    { "mv-res-min", required_argument, NULL, 0 },
>    { "mv-level-min", required_argument, NULL, 0 },
>    { "mv-level-max", required_argument, NULL, 0 },
> +  { "version", no_argument, NULL, 0},

No -v?

>    { NULL, 0, NULL, 0 }
>  };
>
> @@ -420,10 +421,16 @@ static void usage(void) {
>     "                                 0 (default) and 4.\n"
>     "     --mv-level-max <n>          Maximum motion vectors level between\n"
>     "                                 0 and 4 (default).\n"
> +   "     --version                   Displays version information."
>     " encoder_example accepts only uncompressed YUV4MPEG2 video.\n\n");
>    exit(1);
>  }
>
> +static void version(void) {
> +  fprintf(stderr, "%s\n", PACKAGE_STRING);
> +  exit(1);

Likewise.

> +}
> +
>  int main(int argc, char **argv) {
>    FILE *outfile;
>    av_input avin;
> @@ -592,6 +599,9 @@ int main(int argc, char **argv) {
>              exit(1);
>            }
>          }
> +        else if (strcmp(OPTIONS[loi].name, "version") == 0) {
> +          version();
> +        }
>          break;
>        }
>        case 'h':
> diff --git a/examples/player_example.c b/examples/player_example.c
> index aa2a1fd..4dfaf7f 100644
> --- a/examples/player_example.c
> +++ b/examples/player_example.c
> @@ -428,6 +428,9 @@ int main(int argc, char *argv[]) {
>         "r to restart\nl to loop\ns for slow\n. to step\nspace to pause\n"
>         "p to switch planes\nq to quit");
>        exit(1);
> +    } else if ((argc == 2) && memcmp(argv[1], "-v", 2)) {

The logic is inverted here, you should be testing memcmp(argv[1], "-v", 2) == 0.

> +      fprintf(stderr, "%s\n", PACKAGE_STRING);
> +      exit(1);

exit(0);

Best,
Tristan

>
> On Mon, Apr 27, 2015 at 2:53 PM, Tristan Matthews <tmatth at videolan.org>
> wrote:
>>
>> On Sun, Apr 26, 2015 at 5:56 PM, Danesh Daroui <danesh.daroui at gmail.com>
>> wrote:
>>>
>>> Dear Daala people,
>>>
>>>
>>> This is small patch I have written to address the issue #84. Hope that it
>>> will help.
>>
>>
>> The version text should probably contain the PACKAGE_VERSION string
>> (generated in config.h). In fact, if it only contained this string you
>> wouldn't need a version.h header at all.
>>
>> Best,
>> Tristan
>
>
>
> _______________________________________________
> daala mailing list
> daala at xiph.org
> http://lists.xiph.org/mailman/listinfo/daala
>


More information about the daala mailing list