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 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "oggz-chop.h"
......@@ -26,12 +25,20 @@ usage (char * progname)
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@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 @@ cmd_main (OCState * state, int argc, char * argv[])
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 @@ cmd_main (OCState * state, int argc, char * argv[])
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 @@ cmd_main (OCState * state, int argc, char * argv[])
}
if (show_version) {
printf ("%s version " VERSION "\n", progname);
version (stdout);
} else if (state->verbose) {
version (stderr);
}
if (show_help) {
......
......@@ -177,12 +177,14 @@ _ogg_page_set_eos (const ogg_page * og)
}
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 @@ write_accum (OCState * state)
(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 @@ read_plain (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
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 @@ read_headers (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
}
}
} 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 @@ chop (OCState * state)
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 @@ chop (OCState * state)
oggz_close (oggz);
if (state->outfilename != NULL) {
if (state->outfilename != NULL && !state->dry_run) {
fclose (state->outfile);
}
......
......@@ -64,6 +64,10 @@ typedef struct _OCState {
double end;
int original_had_skeleton;
/* Commandline options */
int dry_run;
int verbose;
} 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