Commit 1e025d04 authored by conrad's avatar conrad

add --help and --version options to oggzmerge


git-svn-id: http://svn.annodex.net/liboggz/trunk@586 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent c4f6f41c
...@@ -49,7 +49,14 @@ read_page (OGGZ * oggz, const ogg_page * og, void * user_data); ...@@ -49,7 +49,14 @@ read_page (OGGZ * oggz, const ogg_page * og, void * user_data);
static void static void
usage (char * progname) usage (char * progname)
{ {
printf ("Usage: %s [options] filename\n", progname); printf ("Usage: %s [options] filename ...\n", progname);
printf ("\nMiscellaneous options\n");
printf (" -o filename, --output filename\n");
printf (" Specify output filename\n");
printf (" -h, --help Display this help and exit\n");
printf (" -v, --version Output version information and exit\n");
printf ("\n");
} }
typedef struct _OMData OMData; typedef struct _OMData OMData;
...@@ -225,6 +232,9 @@ oggz_merge (OMData * omdata, FILE * outfile) ...@@ -225,6 +232,9 @@ oggz_merge (OMData * omdata, FILE * outfile)
int int
main (int argc, char * argv[]) main (int argc, char * argv[])
{ {
int show_version = 0;
int show_help = 0;
char * progname; char * progname;
char * infilename = NULL, * outfilename = NULL; char * infilename = NULL, * outfilename = NULL;
FILE * infile = NULL, * outfile = NULL; FILE * infile = NULL, * outfile = NULL;
...@@ -241,11 +251,12 @@ main (int argc, char * argv[]) ...@@ -241,11 +251,12 @@ main (int argc, char * argv[])
omdata = omdata_new(); omdata = omdata_new();
while (1) { while (1) {
char * optstring = "ho:"; char * optstring = "hvo:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
static struct option long_options[] = { static struct option long_options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"output", required_argument, 0, 'o'}, {"output", required_argument, 0, 'o'},
{0,0,0,0} {0,0,0,0}
}; };
...@@ -257,29 +268,44 @@ main (int argc, char * argv[]) ...@@ -257,29 +268,44 @@ main (int argc, char * argv[])
if (i == -1) break; if (i == -1) break;
if (i == ':') { if (i == ':') {
usage (progname); usage (progname);
omdata_delete (omdata); goto exit_err;
return (1);
} }
switch (i) { switch (i) {
case 'h': /* help */ case 'h': /* help */
usage (progname); show_help = 1;
omdata_delete (omdata); break;
return (0); case 'v': /* version */
show_version = 1;
break; break;
case 'o': /* output */ case 'o': /* output */
outfilename = optarg; outfilename = optarg;
break; break;
default: default:
printf ("Random option %c\n", i);
break; break;
} }
} }
if (show_version) {
printf ("%s version " VERSION "\n", progname);
}
if (show_help) {
usage (progname);
}
if (show_version || show_help) {
goto exit_ok;
}
if (optind >= argc) { if (optind >= argc) {
usage (progname); usage (progname);
omdata_delete (omdata); goto exit_err;
return (1); }
if (optind >= argc) {
usage (progname);
goto exit_err;
} }
while (optind < argc) { while (optind < argc) {
...@@ -300,14 +326,17 @@ main (int argc, char * argv[]) ...@@ -300,14 +326,17 @@ main (int argc, char * argv[])
if (outfile == NULL) { if (outfile == NULL) {
fprintf (stderr, "%s: unable to open output file %s\n", fprintf (stderr, "%s: unable to open output file %s\n",
progname, outfilename); progname, outfilename);
omdata_delete (omdata); goto exit_err;
return (1);
} }
} }
oggz_merge (omdata, outfile); oggz_merge (omdata, outfile);
exit_ok:
omdata_delete (omdata); omdata_delete (omdata);
exit (0);
return (0); exit_err:
omdata_delete (omdata);
exit (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