Commit 816a940a authored by colinw's avatar colinw

Fixed some problems whereby the tools were crashing if no filename was passed

in on the command line



git-svn-id: http://svn.annodex.net/liboggz/trunk@451 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent db5c02b0
...@@ -77,7 +77,7 @@ dump_char_line (unsigned char * buf, long n) ...@@ -77,7 +77,7 @@ dump_char_line (unsigned char * buf, long n)
int i; int i;
fprintf (outfile, " "); fprintf (outfile, " ");
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (isgraph(buf[i])) fprintf (outfile, "%c", buf[i]); if (isgraph(buf[i])) fprintf (outfile, "%c", buf[i]);
else if (isspace(buf[i])) fprintf (outfile, " "); else if (isspace(buf[i])) fprintf (outfile, " ");
...@@ -259,7 +259,7 @@ revert_file (char * infilename) ...@@ -259,7 +259,7 @@ revert_file (char * infilename)
if (current_serialno != -1) { if (current_serialno != -1) {
int ret; int ret;
#ifdef DEBUG #ifdef DEBUG
printf ("feeding packet (%010ld) %ld bytes\n", printf ("feeding packet (%010ld) %ld bytes\n",
current_serialno, op.bytes); current_serialno, op.bytes);
#endif #endif
...@@ -271,7 +271,7 @@ revert_file (char * infilename) ...@@ -271,7 +271,7 @@ revert_file (char * infilename)
fwrite (buf, 1, 1024, outfile); fwrite (buf, 1, 1024, outfile);
} }
} }
/* Start new packet */ /* Start new packet */
bos = 0; eos = 0; bos = 0; eos = 0;
if (sscanf (&line[line_offset], " *** %[b]%[o]%[s]%n", &c, &c, &c, if (sscanf (&line[line_offset], " *** %[b]%[o]%[s]%n", &c, &c, &c,
...@@ -327,7 +327,7 @@ revert_file (char * infilename) ...@@ -327,7 +327,7 @@ revert_file (char * infilename)
op.packet = packet; op.packet = packet;
} }
} }
packet[op.bytes-1] = (unsigned char) val; packet[op.bytes-1] = (unsigned char) val;
line_offset += consumed; line_offset += consumed;
...@@ -355,7 +355,8 @@ main (int argc, char ** argv) ...@@ -355,7 +355,8 @@ main (int argc, char ** argv)
progname = argv[0]; progname = argv[0];
if (argc < 2) { if (argc < 2) {
printf ("usage: %s filename\n", progname); usage (progname);
return (1);
} }
table = oggz_table_new(); table = oggz_table_new();
...@@ -387,14 +388,14 @@ main (int argc, char ** argv) ...@@ -387,14 +388,14 @@ main (int argc, char ** argv)
if (i == ':') { if (i == ':') {
usage (progname); usage (progname);
oggz_table_delete(table); oggz_table_delete(table);
exit (1); return (1);
} }
switch (i) { switch (i) {
case 'h': /* help */ case 'h': /* help */
usage (progname); usage (progname);
oggz_table_delete(table); oggz_table_delete(table);
exit (0); return (0);
break; break;
case 'b': /* binary */ case 'b': /* binary */
dump_bits = 1; dump_bits = 1;
...@@ -433,7 +434,7 @@ main (int argc, char ** argv) ...@@ -433,7 +434,7 @@ main (int argc, char ** argv)
if (optind >= argc) { if (optind >= argc) {
usage (progname); usage (progname);
oggz_table_delete(table); oggz_table_delete(table);
exit (1); return (1);
} }
infilename = argv[optind++]; infilename = argv[optind++];
...@@ -446,7 +447,7 @@ main (int argc, char ** argv) ...@@ -446,7 +447,7 @@ main (int argc, char ** argv)
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); oggz_table_delete(table);
exit (1); return (1);
} }
} }
...@@ -454,7 +455,7 @@ main (int argc, char ** argv) ...@@ -454,7 +455,7 @@ main (int argc, char ** argv)
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); oggz_table_delete(table);
exit (1); return (1);
} }
revert_file (infilename); revert_file (infilename);
...@@ -476,7 +477,7 @@ main (int argc, char ** argv) ...@@ -476,7 +477,7 @@ main (int argc, char ** argv)
progname, infilename, strerror (errno)); progname, infilename, strerror (errno));
} }
oggz_table_delete(table); oggz_table_delete(table);
exit (1); return (1);
} }
if (dump_all_serialnos) { if (dump_all_serialnos) {
...@@ -490,9 +491,10 @@ main (int argc, char ** argv) ...@@ -490,9 +491,10 @@ main (int argc, char ** argv)
} }
while ((n = oggz_read (oggz, 1024)) > 0); while ((n = oggz_read (oggz, 1024)) > 0);
oggz_close (oggz); oggz_close (oggz);
} }
oggz_table_delete(table); oggz_table_delete(table);
exit (0);
return (0);
} }
...@@ -159,12 +159,12 @@ read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) ...@@ -159,12 +159,12 @@ read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
vorbis_info_init (&vi); vorbis_info_init (&vi);
vorbis_comment_init (&vc); vorbis_comment_init (&vc);
if ((ret = vorbis_synthesis_headerin (&vi, &vc, op)) == 0) { if ((ret = vorbis_synthesis_headerin (&vi, &vc, op)) == 0) {
if (vi.rate != 0) { if (vi.rate != 0) {
printf ("Got vorbis info: version %d\tchannels %d\trate %ld\n", printf ("Got vorbis info: version %d\tchannels %d\trate %ld\n",
vi.version, vi.channels, vi.rate); vi.version, vi.channels, vi.rate);
init_stream (serialno, vi.rate, 1, 0); init_stream (serialno, vi.rate, 1, 0);
} }
} }
...@@ -172,14 +172,14 @@ read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) ...@@ -172,14 +172,14 @@ read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
} else if (!strncmp ((char *)&op->packet[0], "Speex ", 8)) { } else if (!strncmp ((char *)&op->packet[0], "Speex ", 8)) {
#ifdef HAVE_SPEEX #ifdef HAVE_SPEEX
SpeexHeader * header; SpeexHeader * header;
header = speex_packet_to_header ((char *)op->packet, op->bytes); header = speex_packet_to_header ((char *)op->packet, op->bytes);
if (header) { if (header) {
init_stream (serialno, header->rate, 1, 0); init_stream (serialno, header->rate, 1, 0);
printf ("Got speex samplerate %d\n", header->rate); printf ("Got speex samplerate %d\n", header->rate);
free (header); free (header);
} }
#endif #endif
...@@ -215,7 +215,8 @@ main (int argc, char ** argv) ...@@ -215,7 +215,8 @@ main (int argc, char ** argv)
long n; long n;
if (argc < 2) { if (argc < 2) {
printf ("usage: %s filename\n", argv[0]); printf ("Usage: %s filename\n", argv[0]);
return (1);
} }
granule_rate = 1000000; granule_rate = 1000000;
...@@ -227,7 +228,7 @@ main (int argc, char ** argv) ...@@ -227,7 +228,7 @@ main (int argc, char ** argv)
if ((oggz = oggz_open ((char *)argv[1], OGGZ_READ)) == NULL) { if ((oggz = oggz_open ((char *)argv[1], OGGZ_READ)) == NULL) {
printf ("unable to open file %s\n", argv[1]); printf ("unable to open file %s\n", argv[1]);
exit (1); return (1);
} }
oggz_set_metric (oggz, -1, gp_metric, NULL); oggz_set_metric (oggz, -1, gp_metric, NULL);
...@@ -245,5 +246,5 @@ main (int argc, char ** argv) ...@@ -245,5 +246,5 @@ main (int argc, char ** argv)
oggz_close (oggz); oggz_close (oggz);
exit (0); return (0);
} }
...@@ -73,13 +73,13 @@ main (int argc, char ** argv) ...@@ -73,13 +73,13 @@ main (int argc, char ** argv)
long n; long n;
if (argc < 2) { if (argc < 2) {
printf ("usage: %s filename\n", argv[0]); printf ("Usage: %s filename\n", argv[0]);
return (1);
} }
if ((oggz = oggz_open ((char *)argv[1], OGGZ_READ)) == NULL) { if ((oggz = oggz_open ((char *)argv[1], OGGZ_READ)) == NULL) {
printf ("unable to open file %s\n", argv[1]); printf ("unable to open file %s\n", argv[1]);
exit (1); return (1);
} }
oggz_set_read_callback (oggz, -1, read_packet, NULL); oggz_set_read_callback (oggz, -1, read_packet, NULL);
...@@ -87,5 +87,5 @@ main (int argc, char ** argv) ...@@ -87,5 +87,5 @@ main (int argc, char ** argv)
oggz_close (oggz); oggz_close (oggz);
exit (0); return (0);
} }
...@@ -117,7 +117,7 @@ omdata_delete (OMData * omdata) ...@@ -117,7 +117,7 @@ omdata_delete (OMData * omdata)
} }
oggz_table_delete (omdata->inputs); oggz_table_delete (omdata->inputs);
free (omdata); free (omdata);
} }
static int static int
...@@ -140,7 +140,7 @@ omdata_add_input (OMData * omdata, FILE * infile) ...@@ -140,7 +140,7 @@ omdata_add_input (OMData * omdata, FILE * infile)
ominput_delete (input); ominput_delete (input);
return -1; return -1;
} }
return 0; return 0;
} }
...@@ -213,6 +213,12 @@ main (int argc, char * argv[]) ...@@ -213,6 +213,12 @@ main (int argc, char * argv[])
int i; int i;
progname = argv[0]; progname = argv[0];
if (argc < 2) {
usage (progname);
return (1);
}
omdata = omdata_new(); omdata = omdata_new();
while (1) { while (1) {
...@@ -233,14 +239,14 @@ main (int argc, char * argv[]) ...@@ -233,14 +239,14 @@ main (int argc, char * argv[])
if (i == ':') { if (i == ':') {
usage (progname); usage (progname);
omdata_delete (omdata); omdata_delete (omdata);
exit (1); return (1);
} }
switch (i) { switch (i) {
case 'h': /* help */ case 'h': /* help */
usage (progname); usage (progname);
omdata_delete (omdata); omdata_delete (omdata);
exit (0); return (0);
break; break;
case 'o': /* output */ case 'o': /* output */
outfilename = optarg; outfilename = optarg;
...@@ -254,7 +260,7 @@ main (int argc, char * argv[]) ...@@ -254,7 +260,7 @@ main (int argc, char * argv[])
if (optind >= argc) { if (optind >= argc) {
usage (progname); usage (progname);
omdata_delete (omdata); omdata_delete (omdata);
exit (1); return (1);
} }
while (optind < argc) { while (optind < argc) {
...@@ -276,7 +282,7 @@ main (int argc, char * argv[]) ...@@ -276,7 +282,7 @@ main (int argc, char * argv[])
fprintf (stderr, "%s: unable to open output file %s\n", fprintf (stderr, "%s: unable to open output file %s\n",
progname, outfilename); progname, outfilename);
omdata_delete (omdata); omdata_delete (omdata);
exit (1); return (1);
} }
} }
...@@ -284,5 +290,5 @@ main (int argc, char * argv[]) ...@@ -284,5 +290,5 @@ main (int argc, char * argv[])
omdata_delete (omdata); omdata_delete (omdata);
exit (0); return (0);
} }
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