Commit 3c8e3522 authored by conrad's avatar conrad
Browse files

add --version option to oggzdump


git-svn-id: http://svn.annodex.net/liboggz/trunk@509 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 2fae2910
...@@ -88,6 +88,7 @@ usage (char * progname) ...@@ -88,6 +88,7 @@ usage (char * progname)
printf (" -o filename, --output filename\n"); printf (" -o filename, --output filename\n");
printf (" Specify output filename\n"); printf (" Specify output filename\n");
printf (" -h, --help Display this help and exit\n"); printf (" -h, --help Display this help and exit\n");
printf (" -v, --version Output version information and exit\n");
} }
static void static void
...@@ -362,6 +363,9 @@ revert_file (char * infilename) ...@@ -362,6 +363,9 @@ revert_file (char * infilename)
int int
main (int argc, char ** argv) main (int argc, char ** argv)
{ {
int show_version = 0;
int show_help = 0;
OGGZ * oggz; OGGZ * oggz;
char * infilename = NULL, * outfilename = NULL; char * infilename = NULL, * outfilename = NULL;
int revert = 0; int revert = 0;
...@@ -381,11 +385,12 @@ main (int argc, char ** argv) ...@@ -381,11 +385,12 @@ main (int argc, char ** argv)
table = oggz_table_new(); table = oggz_table_new();
while (1) { while (1) {
char * optstring = "hbxnro:s:OSGP"; char * optstring = "hvbxnro:s:OSGP";
#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'},
{"binary", no_argument, 0, 'b'}, {"binary", no_argument, 0, 'b'},
{"hexadecimal", no_argument, 0, 'x'}, {"hexadecimal", no_argument, 0, 'x'},
{"new", no_argument, 0, 'n'}, {"new", no_argument, 0, 'n'},
...@@ -406,15 +411,16 @@ main (int argc, char ** argv) ...@@ -406,15 +411,16 @@ main (int argc, char ** argv)
if (i == -1) break; if (i == -1) break;
if (i == ':') { if (i == ':') {
usage (progname); usage (progname);
oggz_table_delete(table); oggz_table_delete(table);
return (1); exit (1);
} }
switch (i) { switch (i) {
case 'h': /* help */ case 'h': /* help */
usage (progname); show_help = 1;
oggz_table_delete(table); break;
return (0); case 'v': /* version */
show_version = 1;
break; break;
case 'b': /* binary */ case 'b': /* binary */
dump_bits = 1; dump_bits = 1;
...@@ -450,10 +456,21 @@ main (int argc, char ** argv) ...@@ -450,10 +456,21 @@ main (int argc, char ** argv)
} }
} }
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);
oggz_table_delete(table); goto exit_err;
return (1);
} }
infilename = argv[optind++]; infilename = argv[optind++];
...@@ -465,16 +482,14 @@ main (int argc, char ** argv) ...@@ -465,16 +482,14 @@ 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);
oggz_table_delete(table); goto exit_err;
return (1);
} }
} }
if (revert) { if (revert) {
if (dump_bits) { if (dump_bits) {
fprintf (stderr, "%s: Revert of binary dump not supported\n", progname); fprintf (stderr, "%s: Revert of binary dump not supported\n", progname);
oggz_table_delete(table); goto exit_err;
return (1);
} }
revert_file (infilename); revert_file (infilename);
...@@ -495,8 +510,7 @@ main (int argc, char ** argv) ...@@ -495,8 +510,7 @@ main (int argc, char ** argv)
fprintf (stderr, "%s: %s: %s\n", fprintf (stderr, "%s: %s: %s\n",
progname, infilename, strerror (errno)); progname, infilename, strerror (errno));
} }
oggz_table_delete(table); goto exit_err;
return (1);
} }
if (dump_all_serialnos) { if (dump_all_serialnos) {
...@@ -513,7 +527,12 @@ main (int argc, char ** argv) ...@@ -513,7 +527,12 @@ main (int argc, char ** argv)
oggz_close (oggz); oggz_close (oggz);
} }
oggz_table_delete(table);
return (0); exit_ok:
oggz_table_delete (table);
exit (0);
exit_err:
oggz_table_delete (table);
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