+// Increment the iterator, test for an additional non-option command line argument.
+// Causes the caller to return if there are no remaining arguments or if the next
+// argument begins with '-'.
+#define TEST_EXTRA_ARG(i,c) if ( ++i >= argc || argv[(i)][0] == '-' ) \
+ { \
+ fprintf(stderr, "Argument not found for option -%c.\n", (c)); \
+ return; \
+ }
+
+//
+void
+banner(FILE* stream = stdout)
+{
+ fprintf(stream, "\n\
+%s (asdcplib %s)\n\n\
+Copyright (c) 2005-2008 John Hurst\n\
+%s is part of the asdcplib DCP tools package.\n\
+asdcplib may be copied only under the terms of the license found at\n\
+the top of every file in the asdcplib distribution kit.\n\n\
+Specify the -h (help) option for further information about %s\n\n",
+ PROGRAM_NAME, ASDCP::Version(), PROGRAM_NAME, PROGRAM_NAME);
+}
+
+//
+void
+usage(FILE* stream = stdout)
+{
+ fprintf(stream, "\
+USAGE: %s [-r] [-v] <input-file> [<input-file2> ...]\n\
+\n\
+ %s [-h|-help] [-V]\n\
+\n\
+ -h | -help - Show help\n\
+ -r - When KLV data is an MXF OPAtom file, display OPAtom headers\n\
+ -v - Verbose. Prints informative messages to stderr\n\
+ -V - Show version information\n\
+\n\
+ NOTES: o There is no option grouping, all options must be distinct arguments.\n\
+ o All option arguments must be separated from the option by whitespace.\n\
+\n", PROGRAM_NAME, PROGRAM_NAME);
+}
+
+//
+//
+ class CommandOptions
+ {
+ CommandOptions();
+
+ public:
+ bool error_flag; // true if the given options are in error or not complete
+ bool version_flag; // true if the version display option was selected
+ bool help_flag; // true if the help display option was selected
+ bool verbose_flag; // true if the informative messages option was selected
+ bool read_mxf_flag; // true if the -r option was selected
+ FileList_t inFileList; // File to operate on
+
+ CommandOptions(int argc, const char** argv) :
+ error_flag(true), version_flag(false), help_flag(false), verbose_flag(false), read_mxf_flag(false)
+ {
+ for ( int i = 1; i < argc; i++ )
+ {
+
+ if ( (strcmp( argv[i], "-help") == 0) )
+ {
+ help_flag = true;
+ continue;
+ }
+
+ if ( argv[i][0] == '-' && isalpha(argv[i][1]) && argv[i][2] == 0 )
+ {
+ switch ( argv[i][1] )
+ {
+ case 'h': help_flag = true; break;
+ case 'r': read_mxf_flag = true; break;
+ case 'V': version_flag = true; break;
+ case 'v': verbose_flag = true; break;
+
+ default:
+ fprintf(stderr, "Unrecognized option: %s\n", argv[i]);
+ return;
+ }
+ }
+ else
+ {
+ if ( argv[i][0] != '-' )
+ inFileList.push_back(argv[i]);
+
+ else
+ {
+ fprintf(stderr, "Unrecognized option: %s\n", argv[i]);
+ return;
+ }
+ }
+ }
+
+ if ( help_flag || version_flag )
+ return;
+
+ if ( inFileList.empty() )
+ {
+ fputs("Input filename(s) required.\n", stderr);
+ return;
+ }
+
+ error_flag = false;
+ }
+ };
+
+
+//---------------------------------------------------------------------------------------------------
+//