From 32fec829b2118efbc32a74844d1d2bfc7ba0d929 Mon Sep 17 00:00:00 2001 From: tibs Date: Tue, 16 Jun 2009 20:27:25 +0000 Subject: [PATCH] Amendments suggested by alexw, to whom thanks: 1. Fix some print_msg to be print_err 2. Rename the function to make error messages go to stderr to redirect_output_stderr, which is more sensible. 3. Make the -stdout switch always force error messages to stderr 4. Add the "-err" switch to all programs, which allows the user to choose whether they prefer errors to go to stdout or stderr That last is something I meant to do as part of the stdout/stderr changes - thanks again to alexw for causing me to get round to it. This now allows: cat data/ed24p_11.ts | ts2ps -stdin -stdout | ps2ts -stdin -stdout | mplayer - to work -- it didn't before. --HG-- extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%40145 --- es2ts.c | 21 ++++++++++++++++++++- esdots.c | 18 ++++++++++++++++++ esfilter.c | 21 ++++++++++++++++++++- esmerge.c | 18 ++++++++++++++++++ esreport.c | 18 ++++++++++++++++++ esreverse.c | 21 ++++++++++++++++++++- m2ts2ts.c | 20 ++++++++++++++++++++ pcapreport.c | 19 +++++++++++++++++++ pes.c | 20 ++++++++++++-------- printing.c | 2 +- printing_fns.h | 2 +- ps.c | 16 ++++++++++------ ps2ts.c | 21 ++++++++++++++++++++- psdots.c | 18 ++++++++++++++++++ psreport.c | 18 ++++++++++++++++++ stream_type.c | 18 ++++++++++++++++++ test_printing.c | 2 +- ts2es.c | 21 ++++++++++++++++++++- ts2ps.c | 29 ++++++++++++++++++++++++----- ts_packet_insert.c | 18 ++++++++++++++++++ tsinfo.c | 18 ++++++++++++++++++ tsplay.c | 24 +++++++++++++++++++++--- tsreport.c | 18 ++++++++++++++++++ tsserve.c | 18 ++++++++++++++++++ 24 files changed, 389 insertions(+), 30 deletions(-) diff --git a/es2ts.c b/es2ts.c index 814e729..092cd6c 100644 --- a/es2ts.c +++ b/es2ts.c @@ -159,9 +159,11 @@ static void print_usage() " -verbose, -v Output summary information about each ES packet\n" " as it is read\n" " -quiet, -q Only output error messages\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Take input from , instead of a named file\n" " -stdout Write output to , instead of a named file\n" - " Forces -quiet.\n" + " Forces -quiet and -err stderr.\n" " -host , -host :\n" " Writes output (over TCP/IP) to the named ,\n" " instead of to a named file. If is not\n" @@ -254,6 +256,23 @@ int main(int argc, char **argv) { had_output_name = TRUE; // more or less use_stdout = TRUE; + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("es2ts",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### es2ts: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else if (!strcmp("-host",argv[ii])) { diff --git a/esdots.c b/esdots.c index b993d34..8e4b7ac 100644 --- a/esdots.c +++ b/esdots.c @@ -688,6 +688,8 @@ static void print_usage() "Switches:\n" " -verbose, -v Preface the output with an explanation of the\n" " characters being used.\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Take input from , instead of a named file\n" " -max , -m Maximum number of entities to read\n" " -pes, -ts The input file is TS or PS, to be read via the\n" @@ -757,6 +759,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("esdots",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### esdots: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-stdin",argv[ii])) { had_input_name = TRUE; // more or less diff --git a/esfilter.c b/esfilter.c index 87a3d8b..b17f721 100644 --- a/esfilter.c +++ b/esfilter.c @@ -802,9 +802,11 @@ static void print_usage() "Switches:\n" " -verbose, -v Output extra (debugging) messages\n" " -quiet, -q Only output error messages\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Take input from , instead of a named file\n" " -stdout Write output to , instead of a named file\n" - " Forces -quiet.\n" + " Forces -quiet and -err stderr.\n" " -host , -host :\n" " Writes output (over TCP/IP) to the named ,\n" " instead of to a named file. If is not\n" @@ -922,6 +924,23 @@ int main(int argc, char **argv) { had_output_name = TRUE; // more or less use_stdout = TRUE; + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("esfilter",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### esfilter: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else if (!strcmp("-host",argv[ii])) { diff --git a/esmerge.c b/esmerge.c index c698a56..af1251a 100644 --- a/esmerge.c +++ b/esmerge.c @@ -602,6 +602,8 @@ static void print_usage() " is the resultant TS file.\n" "\n" "Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -quiet, -q Only output error messages.\n" " -verbose, -v Output information about each audio/video frame.\n" " -x Output diagnostic information.\n" @@ -679,6 +681,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("esmerge",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### esmerge: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-verbose",argv[ii]) || !strcmp("-v",argv[ii])) { verbose = TRUE; diff --git a/esreport.c b/esreport.c index 28357f3..073ddce 100644 --- a/esreport.c +++ b/esreport.c @@ -997,6 +997,8 @@ static void print_usage() " (in fact, both of these imply -frame).\n" "\n" "Other switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -verbose, -v For H.262 data, output information about the data\n" " in each MPEG-2 item. For ES units, output information\n" " about the data in each ES unit. Ignored for H.264 data.\n" @@ -1071,6 +1073,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("esreport",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### esreport: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-avc",argv[ii]) || !strcmp("-h264",argv[ii])) { force_stream_type = TRUE; diff --git a/esreverse.c b/esreverse.c index f32c8b3..e8739f4 100644 --- a/esreverse.c +++ b/esreverse.c @@ -404,9 +404,11 @@ static void print_usage() "\n" "Switches:\n" " -verbose, -v Output additional (debugging) messages\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -quiet, -q Only output error messages\n" " -stdout Write output to , instead of a named file\n" - " Forces -quiet.\n" + " Forces -quiet and -err stderr.\n" " -host , -host :\n" " Writes output (over TCP/IP) to the named ,\n" " instead of to a named file. If is not\n" @@ -509,6 +511,23 @@ int main(int argc, char **argv) { had_output_name = TRUE; // more or less use_stdout = TRUE; + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("esreverse",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### esreverse: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else if (!strcmp("-host",argv[ii])) { diff --git a/m2ts2ts.c b/m2ts2ts.c index b25958b..b7a84be 100644 --- a/m2ts2ts.c +++ b/m2ts2ts.c @@ -286,8 +286,11 @@ static void print_usage(void) " is an H.222 Transport Stream file (but see -stdout)\n" "\n" "General Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input instead of a file\n" " -stdout Output to standard output instead of a file\n" + " Forces -quiet and -err stderr.\n" " -verbose, -v Output informational/diagnostic messages\n" " -quiet, -q Only output error messages\n" " -buffer , -b Number of TS packets to buffer for reordering\n" @@ -358,6 +361,23 @@ int main(int argc, char *argv[]) { use_stdout = TRUE; had_output_name = TRUE; // ish + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("m2ts2ts",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### m2ts2ts: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else { diff --git a/pcapreport.c b/pcapreport.c index 54fbd74..eb32fdc 100644 --- a/pcapreport.c +++ b/pcapreport.c @@ -361,6 +361,9 @@ static void print_usage() " -skew-discontinuity-threshold \n" " -skew Gives the skew discontinuity threshold in 90kHz units.\n" "\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" + "\n" " Specifying 0.0.0.0 for destination IP will capture all hosts, specifying 0 destination\n" " port will capture all ports on the destination host.\n" "\n" @@ -396,6 +399,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("pcapreport",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### pcapreport: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("--output", argv[ii]) || !strcmp("-output", argv[ii]) || !strcmp("-o", argv[ii])) { diff --git a/pes.c b/pes.c index 1a09cfa..d0d2ad4 100644 --- a/pes.c +++ b/pes.c @@ -1037,16 +1037,20 @@ static int determine_TS_program_info(PES_reader_p reader) print_err("### Error finding TS program information\n"); return 1; } - err = seek_using_TS_reader(reader->tsreader,0); - if (err) + // It's only possible to rewind if we're not reading from standard + // input. If it's not feasible, don't try. + if (reader->tsreader->file != STDIN_FILENO) { - print_err("### Error rewinding TS stream after finding initial" - " program information\n"); - return 1; + if (err) + { + print_err("### Error rewinding TS stream after finding initial" + " program information\n"); + return 1; + } + // Having rewound, we mustn't forget to reset our notion of the TS packet + // position + reader->posn = 0; } - // Having rewound, we mustn't forget to reset our notion of the TS packet - // position - reader->posn = 0; return 0; } diff --git a/printing.c b/printing.c index 3eb26fe..c98c002 100644 --- a/printing.c +++ b/printing.c @@ -209,7 +209,7 @@ extern void flush_msg(void) * to go to stdout. This is the "traditional" mechanism used by * Unices. */ -extern void redirect_output_traditional(void) +extern void redirect_output_stderr(void) { fns.print_message_fn = &print_message_to_stdout; fns.print_error_fn = &print_message_to_stderr; diff --git a/printing_fns.h b/printing_fns.h index f145bb2..38162f1 100644 --- a/printing_fns.h +++ b/printing_fns.h @@ -68,7 +68,7 @@ extern void flush_msg(void); * to go to stdout. This is the "traditional" mechanism used by * Unices. */ -extern void redirect_output_traditional(void); +extern void redirect_output_stderr(void); /* * Calling this causes all output to go to stdout. This is simpler, * and is likely to be more use to most users. diff --git a/ps.c b/ps.c index 290a82c..b35c387 100644 --- a/ps.c +++ b/ps.c @@ -168,13 +168,17 @@ extern int build_PS_reader(int input, return 1; } - // But we don't *really* want to have read its start yet - err = seek_using_PS_reader(new,new->start); - if (err) + // Seeking won't work on standard input, so don't even try + if (input != STDIN_FILENO) { - print_err("### Error seeking to start of first pack header\n"); - free(new); - return 1; + // But we don't *really* want to have read its start yet + err = seek_using_PS_reader(new,new->start); + if (err) + { + print_err("### Error seeking to start of first pack header\n"); + free(new); + return 1; + } } if (!quiet && new->start != 0) diff --git a/ps2ts.c b/ps2ts.c index bf99946..1a66f63 100644 --- a/ps2ts.c +++ b/ps2ts.c @@ -98,8 +98,10 @@ static void print_usage() " e.g., using psreport)\n" "\n" "Output switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdout Write output to , instead of a named file\n" - " Forces -quiet.\n" + " Forces -quiet and -err stderr.\n" " -host , -host :\n" " Writes output (over TCP/IP) to the named ,\n" " instead of to a named file. If is not\n" @@ -256,6 +258,23 @@ int main(int argc, char **argv) { had_output_name = TRUE; // more or less use_stdout = TRUE; + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("ps2ts",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### ps2ts: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else if (!strcmp("-dvd",argv[ii])) { diff --git a/psdots.c b/psdots.c index 3489113..17b6761 100644 --- a/psdots.c +++ b/psdots.c @@ -257,6 +257,8 @@ static void print_usage() " is an H.222 Program Stream file (but see -stdin)\n" "\n" "Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -verbose, -v Output a description of the characters used\n" " -max , -m Maximum number of PS packets to read\n" @@ -292,6 +294,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("psdots",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### psdots: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-verbose",argv[ii]) || !strcmp("-v",argv[ii])) { verbose = TRUE; diff --git a/psreport.c b/psreport.c index 1ac5d46..aa1aa29 100644 --- a/psreport.c +++ b/psreport.c @@ -471,6 +471,8 @@ static void print_usage() " is an H.222 Program Stream file (but see -stdin)\n" "\n" "Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -verbose, -v Output packet data as well.\n" " -max , -m Maximum number of PS packets to read\n" @@ -512,6 +514,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("psreport",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### psreport: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-verbose",argv[ii]) || !strcmp("-v",argv[ii])) { verbose = TRUE; diff --git a/stream_type.c b/stream_type.c index ea81486..bbe06c1 100644 --- a/stream_type.c +++ b/stream_type.c @@ -377,6 +377,8 @@ static void print_usage() " is the file to analyse\n" "\n" "Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -verbose, -v Output more detailed information about how it is\n" " making its decision\n" " -quiet, -q Only output error messages\n" @@ -416,6 +418,22 @@ int main(int argc, char **argv) verbose = TRUE; quiet = FALSE; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("stream_type",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### stream_type: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-quiet",argv[ii]) || !strcmp("-q",argv[ii])) { verbose = FALSE; diff --git a/test_printing.c b/test_printing.c index 3c54d5e..74b802d 100644 --- a/test_printing.c +++ b/test_printing.c @@ -89,7 +89,7 @@ int main(int argc, char **argv) printf("-------------------------------------------\n"); printf("Choosing 'traditional' output and repeating\n"); printf("-------------------------------------------\n"); - redirect_output_traditional(); + redirect_output_stderr(); print_msg("1. Printing a normal message\n"); print_err("2. Printing an error message\n"); fprint_msg("3. Printing a formatted '%s'\n","message"); diff --git a/ts2es.c b/ts2es.c index fdf2ff3..76b64a6 100644 --- a/ts2es.c +++ b/ts2es.c @@ -432,9 +432,11 @@ static void print_usage() " named in the (first) PMT\n" "\n" "General switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -stdout Output to standard output, instead of a file\n" - " Forces -quiet.\n" + " Forces -quiet and -err stderr.\n" " -verbose, -v Output informational/diagnostic messages\n" " -quiet, -q Only output error messages\n" " -max , -m Maximum number of TS packets to read\n" @@ -530,6 +532,23 @@ int main(int argc, char **argv) { use_stdout = TRUE; had_output_name = TRUE; // so to speak + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("ts2es",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### ts2es: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else { diff --git a/ts2ps.c b/ts2ps.c index 27e07aa..7ed0e81 100644 --- a/ts2ps.c +++ b/ts2ps.c @@ -186,14 +186,14 @@ static int extract_data(int input, #define MAX_LENGTH 0xFFFF if (PES_packet_length > MAX_LENGTH) { - fprint_msg("PES packet of 'zero' length is really %6d - too long for one packet\n", + fprint_err("PES packet of 'zero' length is really %6d - too long for one packet\n", PES_packet_length); // Output what we can of the original packet reader->packet->data[4] = (MAX_LENGTH & 0xFF00) >> 8; reader->packet->data[5] = (MAX_LENGTH & 0x00FF); // Remember that we also write out the 6 bytes preceding those // MAX_LENGTH bytes... - fprint_msg(".. writing out %5d (%5d total)\n",MAX_LENGTH,MAX_LENGTH+6); + fprint_err(".. writing out %5d (%5d total)\n",MAX_LENGTH,MAX_LENGTH+6); count = fwrite(reader->packet->data,MAX_LENGTH+6,1,output); if (count != 1) { @@ -214,7 +214,7 @@ static int extract_data(int input, // we can write is three less than the (otherwise) maximum. int this_length = min(MAX_LENGTH-3,PES_packet_length); int err; - fprint_msg(".. writing out %5d\n",this_length); + fprint_err(".. writing out %5d\n",this_length); err = write_PES_packet(output,start,this_length, reader->packet->data[3]); if (err) @@ -229,7 +229,7 @@ static int extract_data(int input, } else { - fprint_msg("PES packet of 'zero' length, adjusting to %6d-6=%6d" + fprint_err("PES packet of 'zero' length, adjusting to %6d-6=%6d" " (stream id %02x, 'length' %d)\n", reader->packet->data_len,PES_packet_length, reader->packet->data[3],reader->packet->length); @@ -286,9 +286,11 @@ static void print_usage() " is an H.222 Program Stream file (but see -stdout)\n" "\n" "General switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -stdout Output to standard output, instead of a file\n" - " Forces -quiet.\n" + " Forces -quiet and -err stderr.\n" " -verbose, -v Output informational/diagnostic messages\n" " -quiet, -q Only output error messages\n" " -max , -m Maximum number of TS packets to read\n" @@ -368,6 +370,23 @@ int main(int argc, char **argv) { use_stdout = TRUE; had_output_name = TRUE; // so to speak + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("ts2ps",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### ts2ps: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; } else { diff --git a/ts_packet_insert.c b/ts_packet_insert.c index 3a07cb3..dfb37f2 100644 --- a/ts_packet_insert.c +++ b/ts_packet_insert.c @@ -175,6 +175,8 @@ static void print_usage() " An H.222 Transport Stream file.\n" "\n" "Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -p This a a colon (':') delimited string of numbers\n" " between 0 and 1, representing how far through to put \n" " each TS packet. E.g., -p 0.1:0.4:0.7:0.9 will insert\n" @@ -290,6 +292,22 @@ int main(int argc, char **argv) assert(pos_index == n_pos); } + else if (!strcmp("-err",argv[argno])) + { + CHECKARG("ts_packet_insert",argno); + if (!strcmp(argv[argno+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[argno+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### ts_packet_insert: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[argno+1]); + return 1; + } + argno++; + } else if (!strcmp("-pid",argv[argno])) { int err; diff --git a/tsinfo.c b/tsinfo.c index 2155306..8d1a47c 100644 --- a/tsinfo.c +++ b/tsinfo.c @@ -296,6 +296,8 @@ static void print_usage() " is an H.222 Transport Stream file (but see -stdin)\n" "\n" "Switches:\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -verbose, -v Output extra information about packets\n" " -max , -m Number of TS packets to scan. Defaults to 10000.\n" @@ -333,6 +335,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("tsinfo",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### tsinfo: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-verbose",argv[ii]) || !strcmp("-v",argv[ii])) { verbose = TRUE; diff --git a/tsplay.c b/tsplay.c index 912c0e7..2ea20bd 100644 --- a/tsplay.c +++ b/tsplay.c @@ -865,12 +865,14 @@ static void print_usage(int summary) ); if (summary) print_msg( - " -stdout Output is to standard output. Forces -quiet.\n" + " -stdout Output is to standard output. Forces -quiet and -err stderr.\n" ); else print_msg( - " -stdout Output is to standard output. This does not\n" - " make sense with -tcp or -udp. This forces -quiet.\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" + " -stdout Output is to standard output. This does not make sense\n" + " with -tcp or -udp. This forces -quiet and -err stderr.\n" ); print_msg( "\n" @@ -1229,6 +1231,22 @@ int main(int argc, char **argv) use_network = FALSE; how = TS_W_STDOUT; output_name = NULL; + redirect_output_stderr(); + } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("tsplay",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### tsplay: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } ii++; } else if (!strcmp("-tcp",argv[ii])) diff --git a/tsreport.c b/tsreport.c index 02f28c7..b648640 100644 --- a/tsreport.c +++ b/tsreport.c @@ -1022,6 +1022,8 @@ static void print_usage() " By default, normal operation just reports the number of TS packets.\n" " -timing, -t Report timing information based on the PCRs.\n" " -data Show TS packet/payload data as bytes\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -verbose, -v Also output (fairly detailed) information on each TS packet.\n" " -quiet, -q Only output summary information (this is the default)\n" " -max , -m Maximum number of TS packets to read\n" @@ -1111,6 +1113,22 @@ int main(int argc, char **argv) verbose = TRUE; quiet = FALSE; } + else if (!strcmp("-err",argv[ii])) + { + CHECKARG("tsreport",ii); + if (!strcmp(argv[ii+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[ii+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### tsreport: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[ii+1]); + return 1; + } + ii++; + } else if (!strcmp("-timing",argv[ii]) || !strcmp("-t",argv[ii])) { report_timing = TRUE; diff --git a/tsserve.c b/tsserve.c index aac1243..d81042e 100644 --- a/tsserve.c +++ b/tsserve.c @@ -3325,6 +3325,8 @@ static void print_usage() "General Switches:\n" " -details Print out more detailed help information,\n" " including some less common options.\n" + " -err stdout Write error messages to standard output (the default)\n" + " -err stderr Write error messages to standard error (Unix traditional)\n" " -quiet, -q Suppress informational and warning messages.\n" " -verbose, -v Output additional diagnostic messages\n" " -port Listen for a client on port (default 88)\n" @@ -3607,6 +3609,22 @@ int main(int argc, char **argv) print_usage(); return 0; } + else if (!strcmp("-err",argv[argno])) + { + CHECKARG("tsserve",argno); + if (!strcmp(argv[argno+1],"stderr")) + redirect_output_stderr(); + else if (!strcmp(argv[argno+1],"stdout")) + redirect_output_stdout(); + else + { + fprint_err("### tsserve: " + "Unrecognised option '%s' to -err (not 'stdout' or" + " 'stderr')\n",argv[argno+1]); + return 1; + } + argno++; + } else if (!strcmp("-details",argv[argno])) { print_detailed_usage();