[xiph-commits] r3374 - liboggz/trunk/src/tools

conrad at svn.annodex.net conrad at svn.annodex.net
Wed Jan 23 14:14:27 PST 2008


Author: conrad
Date: 2008-01-23 14:14:25 -0800 (Wed, 23 Jan 2008)
New Revision: 3374

Modified:
   liboggz/trunk/src/tools/oggzdump.c
Log:
'oggzdiff --revert' fixes for long oggzdump packetinfo lines


Modified: liboggz/trunk/src/tools/oggzdump.c
===================================================================
--- liboggz/trunk/src/tools/oggzdump.c	2008-01-21 04:40:18 UTC (rev 3373)
+++ liboggz/trunk/src/tools/oggzdump.c	2008-01-23 22:14:25 UTC (rev 3374)
@@ -333,11 +333,33 @@
 }
 
 static void
+revert_packet (OGGZ * oggz, ogg_packet * op, long serialno, int flush)
+{
+  unsigned char buf[1024];
+  long n;
+  int ret;
+
+#ifdef DEBUG
+  printf ("feeding packet (%010ld) %ld bytes %s, %s\n",
+          current_serialno, op->bytes,
+          op->b_o_s ? "bos" : "not bos",
+          op->e_o_s ? "eos" : "not eos");
+#endif
+  if ((ret = oggz_write_feed (oggz, op, serialno, flush, NULL)) != 0) {
+    fprintf (stderr, "%s: oggz_write_feed error %d\n", progname, ret);
+  }
+
+  while ((n = oggz_write_output (oggz, buf, 1024)) > 0) {
+    fwrite (buf, 1, n, outfile);
+  }
+}
+
+static void
 revert_file (char * infilename)
 {
   OGGZ * oggz;
   FILE * infile;
-  char line[80];
+  char line[120];
   int hh, mm, ss;
   unsigned int offset;
   long current_serialno = -1, serialno;
@@ -350,10 +372,8 @@
   unsigned char * packet = NULL;
   long max_bytes = 0;
 
-  unsigned char buf[1024];
   ogg_packet op;
   int flush = 1;
-  long n;
   char c;
 
   if (strcmp (infilename, "-") == 0) {
@@ -364,7 +384,7 @@
 
   oggz = oggz_new (OGGZ_WRITE|OGGZ_NONSTRICT|OGGZ_AUTO);
 
-  while (fgets (line, 80, infile)) {
+  while (fgets (line, 120, infile)) {
     line_offset = 0;
 
     /* Skip time offsets, OR ensure line_offset is 0 */
@@ -389,20 +409,7 @@
     if (is_packetinfo) {
       /* flush any existing packets */
       if (current_serialno != -1) {
-	int ret;
-
-#ifdef DEBUG
-	printf ("feeding packet (%010ld) %ld bytes %s\n",
-		current_serialno, op.bytes,
-		op.b_o_s ? "bos" : "not bos");
-#endif
-	if ((ret = oggz_write_feed (oggz, &op, current_serialno, flush, NULL)) != 0) {
-	  fprintf (stderr, "%s: oggz_write_feed error %d\n", progname, ret);
-	}
-
-	while ((n = oggz_write_output (oggz, buf, 1024)) > 0) {
-	  fwrite (buf, 1, n, outfile);
-	}
+        revert_packet (oggz, &op, current_serialno, flush);
       }
 
       /* Start new packet */
@@ -435,6 +442,8 @@
 
       if (current_serialno != -1 &&
 	  sscanf (line, "%x:%n", &offset, &line_offset) >= 1) {
+        /* NUL-terminate after hex data: don't scan char representation */
+        line[50] = '\0';
 	while (nread < 16 &&
 	       (sscanf (&line[line_offset], "%2x%n", &val, &consumed) > 0)) {
 	  op.bytes++;
@@ -471,6 +480,11 @@
     }
   }
 
+  /* flush any existing packets */
+  if (current_serialno != -1) {
+    revert_packet (oggz, &op, current_serialno, flush);
+  }
+
   fclose (infile);
 }
 



More information about the commits mailing list