1 /* cmdline.h: macros to help process command-line arguments. */
2 
3 #ifndef CMDLINE_H
4 #define CMDLINE_H
5 
6 #include "getopt.h"
7 #include "types.h"
8 #include "strgicmp.h"
9 #include <string.h>
10 
11 
12 /* Test whether getopt found an option ``A''.
13    Assumes the option index is in the variable `option_index', and the
14    option table in a variable `long_options'.  */
15 
16 #define ARGUMENT_IS(a) strgicmp (long_options[option_index].name, a)
17 
18 /* Perform common actions at the end of parsing the arguments.  Assumes
19    lots of variables: `printed_version', a boolean for whether the
20    version number has been printed; `optind', the current option index;
21    `argc'; `argv'.  */
22 
23 #define FINISH_COMMAND_LINE()						\
24   do									\
25     {									\
26       /* Just wanted to know the version number?  */			\
27       if (printed_version && optind == argc) exit (0);			\
28                                                                         \
29       /* Exactly one (non-empty) argument left?  */			\
30       if (optind + 1 == argc && *argv[optind] != 0)			\
31         {								\
32           return (argv[optind]);					\
33         }								\
34       else								\
35         {								\
36           fprintf (stderr, "Usage: %s [options] <image_name>.\n", argv[0]);\
37           fprintf (stderr, "(%s.)\n", optind == argc ? "Missing <image_name>"\
38                                       : "Too many <image_name>s");	\
39           fputs ("For more information, use ``-help''.\n", stderr);	\
40           exit (1);							\
41         }								\
42       return NULL; /* stop warnings */					\
43     }									\
44   while (0)
45 
46 #define GETOPT_USAGE \
47 "  You can use `--' or `-' to start an option.\n\
48   You can use any unambiguous abbreviation for an option name.\n\
49   You can separate option names and values with `=' or ` '.\n\
50 "
51 
52 /* What to pass to `strtok' to separate different arguments to an
53    option, as in `-option=arg1,arg2,arg3'.  It is useful to allow
54    whitespace as well so that the option value can come from a file, via
55    the shell construct "`cat file`" (including the quotes).  */
56 #define ARG_SEP ", \t\n"
57 
58 #endif /* not CMDLINE_H */
59 
60