Commit 3cf909ce authored by Josh Coalson's avatar Josh Coalson
Browse files

add -v, --version options

parent 4dc35070
......@@ -276,6 +276,14 @@
<A NAME="general_options"><FONT SIZE="+1"><B>General Options</B></FONT></A>
</TD>
</TR>
<TR>
<TD NOWRAP ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
<TT>-v</TT>, <TT>--version</TT>
</TD>
<TD>
Show the <B><TT>flac</TT></B> version number.
</TD>
</TR>
<TR>
<TD NOWRAP ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
<TT>-h</TT>, <TT>--help</TT>
......
......@@ -3,7 +3,7 @@
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.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
......
......@@ -4,7 +4,7 @@
<!ENTITY dhfirstname "<firstname>Matt</firstname>">
<!ENTITY dhsurname "<surname>Zimmerman</surname>">
<!-- Please adjust the date whenever revising the manpage. -->
<!ENTITY dhdate "<date>August 13, 2002</date>">
<!ENTITY dhdate "<date>August 19, 2002</date>">
<!-- SECTION should be 1-8, maybe w/ subsection other parameters are
allowed: see man(7), man(1). -->
<!ENTITY dhsection "<manvolnum>1</manvolnum>">
......@@ -73,6 +73,14 @@
<title>Generic Options</title>
<variablelist>
<varlistentry>
<term><option>-v</option>, <option>--version</option>
</term>
<listitem>
<para>Show the flac version number</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option>, <option>--help</option>
</term>
......
......@@ -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");
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment