2 * "getopt" routine customized for top.
6 * Many modern-day Unix implementations already have this function
7 * in libc. The standard "getopt" is perfectly sufficient for top's
8 * needs. If such a function exists in libc then you certainly don't
9 * need to compile this one in. To prevent this function from being
10 * compiled, define "HAVE_GETOPT". This is usually done in the "CFLAGS"
11 * line of the corresponding machine module.
15 * This empty declaration exists solely to placate overexhuberant C
16 * compilers that like to warn you about content-free files.
18 static void __empty();
31 #define ERR(s, c) if(opterr){\
34 errbuf[0] = c; errbuf[1] = '\n';\
35 (void) write(2, argv[0], strlen(argv[0]));\
36 (void) write(2, s, strlen(s));\
37 (void) write(2, errbuf, 2);}
46 getopt(argc
, argv
, opts
)
56 argv
[optind
][0] != '-' || argv
[optind
][1] == '\0')
58 else if(strcmp(argv
[optind
], "--") == 0) {
62 optopt
= c
= argv
[optind
][sp
];
63 if(c
== ':' || (cp
=strchr(opts
, c
)) == NULL
) {
64 ERR(": unknown option, -", c
);
65 if(argv
[optind
][++sp
] == '\0') {
72 if(argv
[optind
][sp
+1] != '\0')
73 optarg
= &argv
[optind
++][sp
+1];
74 else if(++optind
>= argc
) {
75 ERR(": argument missing for -", c
);
79 optarg
= argv
[optind
++];
82 if(argv
[optind
][++sp
] == '\0') {
90 #endif /* HAVE_GETOPT */