2 * Macros for processing command arguments.
4 * Conforms closely to the command option requirements of intro(1) in System V
5 * and intro(C) in Xenix.
7 * A command consists of: cmdname [ options ] [ cmdarguments ]
9 * Options consist of a leading dash '-' and a flag letter. An argument may
10 * follow optionally preceded by white space.
11 * Options without arguments may be grouped behind a single dash.
12 * A dash on its own is interpreted as the end of the options and is retained
13 * as a command argument.
14 * A double dash '--' is interpreted as the end of the options and is discarded.
17 * zap -xz -f flame -q34 -- -x
19 * where zap.c contains the following in main():
21 * OPTIONS("[-xz] [-q queue-id] [-f dump-file] user")
25 * fp = fopen(file, "w");
33 * fp = fopen("flame", "w")
39 * Should the user enter unknown flags or leave out required arguments,
42 * Usage: zap [-xz] [-q queue-id] [-f dump-file] user
44 * will be printed. This message can be printed by calling pusage(), or
45 * usage(). usage() will also cause program termination with exit code 1.
47 * Author: Stephen McKay, February 1991
49 * Based on recollection of the original options.h produced at the University
50 * of Queensland by Ross Patterson (and possibly others).
61 * Avoid gratuitously loading stdio.
63 write(2, "Usage: ", 7);
64 write(2, O_name, strlen(O_name));
66 write(2, O_usage, strlen(O_usage));
70 #define usage() (pusage(), exit(1))
72 #define OPTIONS(usage_msg) \
75 O_usage = (usage_msg); \
77 while (*++argv && **argv == '-') \
79 if ((*argv)[1] == '\0') \
82 if ((*argv)[1] == '-' && (*argv)[2] == '\0') \
97 #define FLAG(x,flag) \
106 if (*++*argv == '\0' && (--argc, *++argv == 0)) \
110 #define NUMBER(x,n) \
114 if (*++*argv == '\0' && (--argc, *++argv == 0)) \
118 #define STRING(x,str) \
122 if (*++*argv == '\0' && (--argc, *++argv == 0)) \
126 #define SUFFIX(x,str) \