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).
63 * Avoid gratuitously loading stdio.
65 write(STDERR_FILENO, "usage: ", 7);
66 write(STDERR_FILENO, O_name, strlen(O_name));
67 write(STDERR_FILENO, " ", 1);
68 write(STDERR_FILENO, O_usage, strlen(O_usage));
69 write(STDERR_FILENO, "\n", 1);
72 #define usage() (pusage(), exit(1))
74 #define OPTIONS(usage_msg) \
77 O_usage = (usage_msg); \
79 while (*++argv && **argv == '-') \
81 if ((*argv)[1] == '\0') \
84 if ((*argv)[1] == '-' && (*argv)[2] == '\0') \
99 #define FLAG(x,flag) \
108 if (*++*argv == '\0' && (--argc, *++argv == 0)) \
112 #define NUMBER(x,n) \
116 if (*++*argv == '\0' && (--argc, *++argv == 0)) \
120 #define STRING(x,str) \
124 if (*++*argv == '\0' && (--argc, *++argv == 0)) \
128 #define SUFFIX(x,str) \