[xiph-commits] r3799 - liboggz/trunk/src/tools/oggz-chop

conrad at svn.annodex.net conrad at svn.annodex.net
Thu Nov 20 02:33:27 PST 2008


Author: conrad
Date: 2008-11-20 02:33:27 -0800 (Thu, 20 Nov 2008)
New Revision: 3799

Modified:
   liboggz/trunk/src/tools/oggz-chop/cmd.c
   liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
   liboggz/trunk/src/tools/oggz-chop/oggz-chop.h
Log:
oggz-chop: add --dry-run and --verbose options to cmdline tool;
implement --dry-run


Modified: liboggz/trunk/src/tools/oggz-chop/cmd.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/cmd.c	2008-11-19 23:00:38 UTC (rev 3798)
+++ liboggz/trunk/src/tools/oggz-chop/cmd.c	2008-11-20 10:33:27 UTC (rev 3799)
@@ -3,7 +3,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
 #include <getopt.h>
 
 #include "oggz-chop.h"
@@ -26,12 +25,20 @@
   printf ("                         Specify end time\n");
   printf ("  -k , --no-skeleton     Do NOT include a Skeleton bitstream in the output");
   printf ("\nMiscellaneous options\n");
+  printf ("  -n, --dry-run          Don't actually write the output\n");
   printf ("  -h, --help             Display this help and exit\n");
   printf ("  -v, --version          Output version information and exit\n");
+  printf ("  -V, --verbose          Verbose operation, prints to stderr\n");
   printf ("\n");
   printf ("Please report bugs to <ogg-dev at xiph.org>\n");
 }
 
+static int
+version (FILE *stream)
+{
+    return fprintf (stream, "%s version " VERSION "\n", progname);
+}
+
 int
 cmd_main (OCState * state, int argc, char * argv[])
 {
@@ -39,16 +46,18 @@
   int show_help = 0;
   int i;
 
-  char * optstring = "s:e:o:khv";
+  char * optstring = "s:e:o:knhvV";
 
 #ifdef HAVE_GETOPT_LONG
   static struct option long_options[] = {
-    {"start",   required_argument, 0, 's'},
-    {"end",   required_argument, 0, 'e'},
+    {"start",    required_argument, 0, 's'},
+    {"end",      required_argument, 0, 'e'},
     {"output",   required_argument, 0, 'o'},
-    {"no-skeleton",   no_argument, 0, 'k'},
+    {"no-skeleton", no_argument, 0, 'k'},
+    {"dry-run",  no_argument, 0, 'n'},
     {"help",     no_argument, 0, 'h'},
     {"version",  no_argument, 0, 'v'},
+    {"verbose",  no_argument, 0, 'V'},
     {0,0,0,0}
   };
 #endif
@@ -95,12 +104,18 @@
     case 'k': /* no-skeleton */
       state->do_skeleton = 0;
       break;
+    case 'n': /* dry-run */
+      state->dry_run = 1;
+      break;
     case 'h': /* help */
       show_help = 1;
       break;
     case 'v': /* version */
       show_version = 1;
       break;
+    case 'V': /* verbose */
+      state->verbose = 1;
+      break;
     case 'o': /* output */
       state->outfilename = optarg;
       break;
@@ -110,7 +125,9 @@
   }
 
   if (show_version) {
-    printf ("%s version " VERSION "\n", progname);
+    version (stdout);
+  } else if (state->verbose) {
+    version (stderr);
   }
 
   if (show_help) {

Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.c	2008-11-19 23:00:38 UTC (rev 3798)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.c	2008-11-20 10:33:27 UTC (rev 3799)
@@ -177,12 +177,14 @@
 }
 
 static void
-fwrite_ogg_page (FILE * outfile, const ogg_page * og)
+fwrite_ogg_page (OCState * state, const ogg_page * og)
 {
   if (og == NULL) return;
 
-  fwrite (og->header, 1, og->header_len, outfile);
-  fwrite (og->body, 1, og->body_len, outfile);
+  if (!state->dry_run) {
+    fwrite (og->header, 1, og->header_len, state->outfile);
+    fwrite (og->body, 1, og->body_len, state->outfile);
+  }
 }
 
 /************************************************************
@@ -494,7 +496,7 @@
                          (void *)(min_cn+1+CN_OFFSET));
 
       /* Write out minimum page */
-      fwrite_ogg_page (state->outfile, min_og);
+      fwrite_ogg_page (state, min_og);
     }
 
     /* Let's lexically forget about this CN_OFFSET silliness */
@@ -583,11 +585,11 @@
       chop_glue (state, oggz);
     }
 
-    fwrite_ogg_page (state->outfile, og);
+    fwrite_ogg_page (state, og);
   } else if (state->end != -1.0 && page_time > state->end) {
     /* This is the first page past the end time; set EOS */
     _ogg_page_set_eos (og);
-    fwrite_ogg_page (state->outfile, og);
+    fwrite_ogg_page (state, og);
 
     /* Stop handling this track */
     oggz_set_read_page (oggz, serialno, NULL, NULL);
@@ -676,7 +678,7 @@
       }
     }
   } else {
-    fwrite_ogg_page (state->outfile, og);
+    fwrite_ogg_page (state, og);
 
     ts = oggz_table_lookup (state->tracks, serialno);
     ts->headers_remaining -= ogg_page_packets (OGG_PAGE_CONST(og));
@@ -747,15 +749,17 @@
 
   if (oggz == NULL) return -1;
 
-  if (state->outfilename == NULL) {
-    state->outfile = stdout;
-  } else {
-    state->outfile = fopen (state->outfilename, "wb");
-    if (state->outfile == NULL) {
-      fprintf (stderr, "oggz-chop: unable to open output file %s\n",
-	       state->outfilename);
-      oggz_close(oggz);
-      return -1;
+  if (!state->dry_run) {
+    if (state->outfilename == NULL) {
+      state->outfile = stdout;
+    } else {
+      state->outfile = fopen (state->outfilename, "wb");
+      if (state->outfile == NULL) {
+        fprintf (stderr, "oggz-chop: unable to open output file %s\n",
+  	       state->outfilename);
+        oggz_close(oggz);
+        return -1;
+      }
     }
   }
 
@@ -774,7 +778,7 @@
 
   oggz_close (oggz);
 
-  if (state->outfilename != NULL) {
+  if (state->outfilename != NULL && !state->dry_run) {
     fclose (state->outfile);
   }
 

Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.h
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.h	2008-11-19 23:00:38 UTC (rev 3798)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.h	2008-11-20 10:33:27 UTC (rev 3799)
@@ -64,6 +64,10 @@
   double end;
 
   int original_had_skeleton;
+
+  /* Commandline options */
+  int dry_run;
+  int verbose;
 } OCState;
 
 



More information about the commits mailing list