From 3cf909cef2e01585acbf1843b598b58fcd9d296a Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Tue, 20 Aug 2002 03:57:59 +0000 Subject: [PATCH] add -v, --version options --- doc/html/documentation.html | 8 ++++++++ man/flac.1 | 5 ++++- man/flac.sgml | 10 +++++++++- src/flac/main.c | 22 ++++++++++++++++++++-- src/metaflac/main.c | 19 ++++++++++++++++++- 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/doc/html/documentation.html b/doc/html/documentation.html index 4928b4f..6f70da8 100644 --- a/doc/html/documentation.html +++ b/doc/html/documentation.html @@ -278,6 +278,14 @@ + -v, --version + + + Show the flac version number. + + + + -h, --help diff --git a/man/flac.1 b/man/flac.1 index 8fa3873..76188c3 100644 --- a/man/flac.1 +++ b/man/flac.1 @@ -3,7 +3,7 @@ .\" .\" Please send any bug reports, improvements, comments, patches, .\" etc. to Steve Cheng . -.TH "FLAC" "1" "13 August 2002" "" "" +.TH "FLAC" "1" "19 August 2002" "" "" .SH NAME flac \- Free Lossless Audio Codec .SH SYNOPSIS @@ -25,6 +25,9 @@ A summary of options is included below. For a complete description, see the HTML documentation. .SS "GENERIC OPTIONS" .TP +\fB-v, --version \fR +Show the flac version number +.TP \fB-h, --help \fR Show basic usage and a list of all options .TP diff --git a/man/flac.sgml b/man/flac.sgml index b23d2df..000710f 100644 --- a/man/flac.sgml +++ b/man/flac.sgml @@ -4,7 +4,7 @@ Matt"> Zimmerman"> - August 13, 2002"> + August 19, 2002"> 1"> @@ -74,6 +74,14 @@ + , + + + Show the flac version number + + + + , diff --git a/src/flac/main.c b/src/flac/main.c index 415ff1e..31263c8 100644 --- a/src/flac/main.c +++ b/src/flac/main.c @@ -52,6 +52,7 @@ static void free_options(); static int usage_error(const char *message, ...); static void short_usage(); +static void show_version(); static void show_help(); static void show_explain(); static void format_mistake(const char *infilename, const char *wrong, const char *right); @@ -72,6 +73,8 @@ static struct FLAC__share__option long_options_[] = { * general options */ { "help", 0, 0, 'h' }, + { "explain", 0, 0, 'H' }, + { "version", 0, 0, 'v' }, { "decode", 0, 0, 'd' }, { "analyze", 0, 0, 'a' }, { "test", 0, 0, 't' }, @@ -176,6 +179,7 @@ static struct FLAC__share__option long_options_[] = { static struct { FLAC__bool show_help; FLAC__bool show_explain; + FLAC__bool show_version; FLAC__bool mode_decode; FLAC__bool verify; FLAC__bool verbose; @@ -246,7 +250,11 @@ int do_it() { int retval = 0; - if(option_values.show_explain) { + if(option_values.show_version) { + show_version(); + return 0; + } + else if(option_values.show_explain) { show_explain(); return 0; } @@ -462,7 +470,7 @@ int parse_options(int argc, char *argv[]) int option_index = 1; FLAC__bool had_error = false; /*@@@ E and R: are deprecated */ - const char *short_opts = "0123456789ab:cdeFhHl:mMo:pP:q:r:sS:tV"; + const char *short_opts = "0123456789ab:cdeFhHl:mMo:pP:q:r:sS:tvV"; while ((short_option = FLAC__share__getopt_long(argc, argv, short_opts, long_options_, &option_index)) != -1) { switch (short_option) { @@ -642,6 +650,9 @@ int parse_option(int short_option, const char *long_option, const char *option_a case 'H': option_values.show_explain = true; break; + case 'v': + option_values.show_version = true; + break; case 'd': option_values.mode_decode = true; break; @@ -854,6 +865,11 @@ int usage_error(const char *message, ...) return 1; } +void show_version() +{ + printf("flac %s\n", FLAC__VERSION_STRING); +} + static void usage_header() { printf("===============================================================================\n"); @@ -911,6 +927,7 @@ void show_help() usage_header(); usage_summary(); printf("generic options:\n"); + printf(" -v, --version Show the flac version number\n"); printf(" -h, --help Show this screen\n"); printf(" -H, --explain Show detailed explanation of usage and options\n"); printf(" -d, --decode Decode (the default behavior is to encode)\n"); @@ -1016,6 +1033,7 @@ void show_explain() printf("files using -fr.\n"); printf("\n"); printf("generic options:\n"); + printf(" -v, --version Show the flac version number\n"); printf(" -h, --help Show basic usage a list of all options\n"); printf(" -H, --explain Show this screen\n"); printf(" -d, --decode Decode (the default behavior is to encode)\n"); diff --git a/src/metaflac/main.c b/src/metaflac/main.c index 826f3f0..b379b1d 100644 --- a/src/metaflac/main.c +++ b/src/metaflac/main.c @@ -72,6 +72,7 @@ static struct FLAC__share__option long_options_[] = { { "add-padding", 1, 0, 0 }, /* major operations */ { "help", 0, 0, 0 }, + { "version", 0, 0, 0 }, { "list", 0, 0, 0 }, { "append", 0, 0, 0 }, { "remove", 0, 0, 0 }, @@ -188,6 +189,7 @@ typedef struct { FLAC__bool utf8_convert; FLAC__bool use_padding; FLAC__bool show_long_help; + FLAC__bool show_version; FLAC__bool application_data_format_is_hexdump; struct { Operation *operations; @@ -219,6 +221,7 @@ static void append_new_argument(CommandLineOptions *options, Argument argument); static Operation *append_major_operation(CommandLineOptions *options, OperationType type); static Operation *append_shorthand_operation(CommandLineOptions *options, OperationType type); static Argument *append_argument(CommandLineOptions *options, ArgumentType type); +static void show_version(); static int short_usage(const char *message, ...); static int long_usage(const char *message, ...); static char *local_strdup(const char *source); @@ -286,6 +289,7 @@ void init_options(CommandLineOptions *options) options->utf8_convert = true; options->use_padding = true; options->show_long_help = false; + options->show_version = false; options->application_data_format_is_hexdump = false; options->ops.operations = 0; @@ -329,7 +333,7 @@ FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options) if(options->prefix_with_filename == 2) options->prefix_with_filename = (argc - FLAC__share__optind > 1); - if(FLAC__share__optind >= argc && !options->show_long_help) { + if(FLAC__share__optind >= argc && !options->show_long_help && !options->show_version) { fprintf(stderr,"ERROR: you must specify at least one FLAC file;\n"); fprintf(stderr," metaflac cannot be used as a pipe\n"); had_error = true; @@ -473,6 +477,9 @@ FLAC__bool parse_option(int option_index, const char *option_argument, CommandLi else if(0 == strcmp(opt, "help")) { options->show_long_help = true; } + else if(0 == strcmp(opt, "version")) { + options->show_version = true; + } else if(0 == strcmp(opt, "list")) { (void) append_major_operation(options, OP__LIST); } @@ -671,6 +678,11 @@ Argument *append_argument(CommandLineOptions *options, ArgumentType type) return options->args.arguments + (options->args.num_arguments - 1); } +void show_version() +{ + printf("metaflac %s\n", FLAC__VERSION_STRING); +} + static void usage_header(FILE *out) { fprintf(out, "==============================================================================\n"); @@ -784,6 +796,8 @@ int long_usage(const char *message, ...) fprintf(out, " the extra 4 bytes is for the metadata block header.\n"); fprintf(out, "\n"); fprintf(out, "Major operations:\n"); + fprintf(out, "--version\n"); + fprintf(out, " Show the metaflac version number.\n"); fprintf(out, "--list\n"); fprintf(out, " List the contents of one or more metadata blocks to stdout. By default,\n"); fprintf(out, " all metadata blocks are listed in text format. Use the following options\n"); @@ -1094,6 +1108,9 @@ FLAC__bool do_operations(const CommandLineOptions *options) if(options->show_long_help) { long_usage(0); } + if(options->show_version) { + show_version(); + } else if(options->args.checks.num_major_ops > 0) { FLAC__ASSERT(options->args.checks.num_shorthand_ops == 0); FLAC__ASSERT(options->args.checks.num_major_ops == 1); -- 2.7.4