Commit b4dc262a authored by conrad's avatar conrad

oggz-chop: add --dry-run and --verbose options to cmdline tool;

implement --dry-run


git-svn-id: http://svn.annodex.net/liboggz/trunk@3799 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 776f0bd2
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include "oggz-chop.h" #include "oggz-chop.h"
...@@ -26,12 +25,20 @@ usage (char * progname) ...@@ -26,12 +25,20 @@ usage (char * progname)
printf (" Specify end time\n"); printf (" Specify end time\n");
printf (" -k , --no-skeleton Do NOT include a Skeleton bitstream in the output"); printf (" -k , --no-skeleton Do NOT include a Skeleton bitstream in the output");
printf ("\nMiscellaneous options\n"); 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 (" -h, --help Display this help and exit\n");
printf (" -v, --version Output version information and exit\n"); printf (" -v, --version Output version information and exit\n");
printf (" -V, --verbose Verbose operation, prints to stderr\n");
printf ("\n"); printf ("\n");
printf ("Please report bugs to <ogg-dev@xiph.org>\n"); printf ("Please report bugs to <ogg-dev@xiph.org>\n");
} }
static int
version (FILE *stream)
{
return fprintf (stream, "%s version " VERSION "\n", progname);
}
int int
cmd_main (OCState * state, int argc, char * argv[]) cmd_main (OCState * state, int argc, char * argv[])
{ {
...@@ -39,16 +46,18 @@ cmd_main (OCState * state, int argc, char * argv[]) ...@@ -39,16 +46,18 @@ cmd_main (OCState * state, int argc, char * argv[])
int show_help = 0; int show_help = 0;
int i; int i;
char * optstring = "s:e:o:khv"; char * optstring = "s:e:o:knhvV";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
static struct option long_options[] = { static struct option long_options[] = {
{"start", required_argument, 0, 's'}, {"start", required_argument, 0, 's'},
{"end", required_argument, 0, 'e'}, {"end", required_argument, 0, 'e'},
{"output", required_argument, 0, 'o'}, {"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'}, {"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'}, {"version", no_argument, 0, 'v'},
{"verbose", no_argument, 0, 'V'},
{0,0,0,0} {0,0,0,0}
}; };
#endif #endif
...@@ -95,12 +104,18 @@ cmd_main (OCState * state, int argc, char * argv[]) ...@@ -95,12 +104,18 @@ cmd_main (OCState * state, int argc, char * argv[])
case 'k': /* no-skeleton */ case 'k': /* no-skeleton */
state->do_skeleton = 0; state->do_skeleton = 0;
break; break;
case 'n': /* dry-run */
state->dry_run = 1;
break;
case 'h': /* help */ case 'h': /* help */
show_help = 1; show_help = 1;
break; break;
case 'v': /* version */ case 'v': /* version */
show_version = 1; show_version = 1;
break; break;
case 'V': /* verbose */
state->verbose = 1;
break;
case 'o': /* output */ case 'o': /* output */
state->outfilename = optarg; state->outfilename = optarg;
break; break;
...@@ -110,7 +125,9 @@ cmd_main (OCState * state, int argc, char * argv[]) ...@@ -110,7 +125,9 @@ cmd_main (OCState * state, int argc, char * argv[])
} }
if (show_version) { if (show_version) {
printf ("%s version " VERSION "\n", progname); version (stdout);
} else if (state->verbose) {
version (stderr);
} }
if (show_help) { if (show_help) {
......
...@@ -177,12 +177,14 @@ _ogg_page_set_eos (const ogg_page * og) ...@@ -177,12 +177,14 @@ _ogg_page_set_eos (const ogg_page * og)
} }
static void static void
fwrite_ogg_page (FILE * outfile, const ogg_page * og) fwrite_ogg_page (OCState * state, const ogg_page * og)
{ {
if (og == NULL) return; if (og == NULL) return;
fwrite (og->header, 1, og->header_len, outfile); if (!state->dry_run) {
fwrite (og->body, 1, og->body_len, outfile); fwrite (og->header, 1, og->header_len, state->outfile);
fwrite (og->body, 1, og->body_len, state->outfile);
}
} }
/************************************************************ /************************************************************
...@@ -494,7 +496,7 @@ write_accum (OCState * state) ...@@ -494,7 +496,7 @@ write_accum (OCState * state)
(void *)(min_cn+1+CN_OFFSET)); (void *)(min_cn+1+CN_OFFSET));
/* Write out minimum page */ /* 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 */ /* Let's lexically forget about this CN_OFFSET silliness */
...@@ -583,11 +585,11 @@ read_plain (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data) ...@@ -583,11 +585,11 @@ read_plain (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
chop_glue (state, oggz); 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) { } else if (state->end != -1.0 && page_time > state->end) {
/* This is the first page past the end time; set EOS */ /* This is the first page past the end time; set EOS */
_ogg_page_set_eos (og); _ogg_page_set_eos (og);
fwrite_ogg_page (state->outfile, og); fwrite_ogg_page (state, og);
/* Stop handling this track */ /* Stop handling this track */
oggz_set_read_page (oggz, serialno, NULL, NULL); oggz_set_read_page (oggz, serialno, NULL, NULL);
...@@ -676,7 +678,7 @@ read_headers (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data) ...@@ -676,7 +678,7 @@ read_headers (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
} }
} }
} else { } else {
fwrite_ogg_page (state->outfile, og); fwrite_ogg_page (state, og);
ts = oggz_table_lookup (state->tracks, serialno); ts = oggz_table_lookup (state->tracks, serialno);
ts->headers_remaining -= ogg_page_packets (OGG_PAGE_CONST(og)); ts->headers_remaining -= ogg_page_packets (OGG_PAGE_CONST(og));
...@@ -747,15 +749,17 @@ chop (OCState * state) ...@@ -747,15 +749,17 @@ chop (OCState * state)
if (oggz == NULL) return -1; if (oggz == NULL) return -1;
if (state->outfilename == NULL) { if (!state->dry_run) {
state->outfile = stdout; if (state->outfilename == NULL) {
} else { state->outfile = stdout;
state->outfile = fopen (state->outfilename, "wb"); } else {
if (state->outfile == NULL) { state->outfile = fopen (state->outfilename, "wb");
fprintf (stderr, "oggz-chop: unable to open output file %s\n", if (state->outfile == NULL) {
state->outfilename); fprintf (stderr, "oggz-chop: unable to open output file %s\n",
oggz_close(oggz); state->outfilename);
return -1; oggz_close(oggz);
return -1;
}
} }
} }
...@@ -774,7 +778,7 @@ chop (OCState * state) ...@@ -774,7 +778,7 @@ chop (OCState * state)
oggz_close (oggz); oggz_close (oggz);
if (state->outfilename != NULL) { if (state->outfilename != NULL && !state->dry_run) {
fclose (state->outfile); fclose (state->outfile);
} }
......
...@@ -64,6 +64,10 @@ typedef struct _OCState { ...@@ -64,6 +64,10 @@ typedef struct _OCState {
double end; double end;
int original_had_skeleton; int original_had_skeleton;
/* Commandline options */
int dry_run;
int verbose;
} OCState; } OCState;
......
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