2 Copyright (c) 2005-2006, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /*! \file kmuuidgen.cpp
29 \brief UUID generation utility
37 const char* PACKAGE = "kmuuidgen";
39 // Increment the iterator, test for an additional non-option command line argument.
40 // Causes the caller to return if there are no remaining arguments or if the next
41 // argument begins with '-'.
42 #define TEST_EXTRA_ARG(i,c) if ( ++i >= argc || argv[(i)][0] == '-' ) \
44 fprintf(stderr, "Argument not found for option -%c.\n", (c)); \
50 banner(FILE* stream = stdout)
54 Copyright (c) 2003-2006 John Hurst\n\n\
55 %s is part of the asdcp DCP tools package.\n\
56 asdcplib may be copied only under the terms of the license found at\n\
57 the top of every file in the asdcplib distribution kit.\n\n\
58 Specify the -h (help) option for further information about %s\n\n",
59 PACKAGE, ASDCP::Version(), PACKAGE, PACKAGE);
64 usage(FILE* stream = stdout)
67 USAGE: %s [-c] [-n] [-v]\n\
71 -c - Output a C-language struct containing the value\n\
72 -h | -help - Show help\n\
73 -n - Suppress the newline\n\
74 -v - Verbose. Prints informative messages to stderr\n\
75 -V - Show version information\n\
77 NOTES: o There is no option grouping, all options must be distinct arguments.\n\
78 o All option arguments must be separated from the option by whitespace.\n\
79 \n", PACKAGE, PACKAGE);
88 bool error_flag; // true if the given options are in error or not complete
89 bool no_newline_flag; //
91 bool version_flag; // true if the version display option was selected
92 bool help_flag; // true if the help display option was selected
93 bool verbose_flag; // true if the verbose flag was selected
96 CommandOptions(int argc, const char** argv) :
97 error_flag(true), no_newline_flag(false), c_array_flag(false), version_flag(false),
98 help_flag(false), verbose_flag(false)
100 for ( int i = 1; i < argc; i++ )
103 if ( (strcmp( argv[i], "-help") == 0) )
109 if ( argv[i][0] == '-' && isalpha(argv[i][1]) && argv[i][2] == 0 )
111 switch ( argv[i][1] )
113 case 'c': c_array_flag = true; break;
114 case 'n': no_newline_flag = true; break;
115 case 'h': help_flag = true; break;
116 case 'v': verbose_flag = true; break;
117 case 'V': version_flag = true; break;
120 fprintf(stderr, "Unrecognized option: %s\n", argv[i]);
126 fprintf(stderr, "Unrecognized option: %s\n", argv[i]);
131 if ( help_flag || version_flag )
142 main(int argc, const char** argv)
144 CommandOptions Options(argc, argv);
146 if ( Options.version_flag )
149 if ( Options.help_flag )
152 if ( Options.version_flag || Options.help_flag )
155 if ( Options.error_flag )
157 fprintf(stderr, "There was a problem. Type %s -h for help.\n", PACKAGE);
162 Kumu::GenRandomValue(UUID);
165 if ( Options.c_array_flag )
167 const byte_t* p = UUID.Value();
170 byte_t uuid_buf[] = {\n\
172 UUID.EncodeHex(uuid_buf, 40));
174 for ( ui32_t i = 0; i < 16; i++ )
175 printf(" 0x%02x,", p[i]);
183 fputs(UUID.EncodeHex(uuid_buf, 40), stdout);
186 if ( Options.no_newline_flag == 0 )