2 * getopt - get option letter from argv
4 * This is a version of the public domain getopt() implementation by
5 * Henry Spencer, changed for 4.3BSD compatibility (in addition to System V).
6 * It allows rescanning of an option list by setting optind to 0 before
7 * calling, which is why we use it even if the system has its own (in fact,
8 * this one has a unique name so as not to conflict with the system's).
9 * Thanks to Dennis Ferguson for the appropriate modifications.
11 * This file is in the Public Domain.
18 #include "ntp_stdlib.h"
25 char *ntp_optarg; /* Global argument pointer. */
26 int ntp_optind = 0; /* Global argv index. */
27 int ntp_opterr = 1; /* for compatibility, should error be printed? */
28 int ntp_optopt; /* for compatibility, option character checked */
30 static char *scan = NULL; /* Private scan pointer. */
31 static const char *prog = "amnesia";
34 * Print message about a bad option.
45 (void) putc(ch, stderr);
46 (void) putc('\n', stderr);
59 register const char *place;
64 if (ntp_optind == 0) {
69 if (scan == NULL || *scan == '\0') {
70 if (ntp_optind >= argc
71 || argv[ntp_optind][0] != '-'
72 || argv[ntp_optind][1] == '\0') {
75 if (argv[ntp_optind][1] == '-'
76 && argv[ntp_optind][2] == '\0') {
81 scan = argv[ntp_optind++]+1;
85 ntp_optopt = c & 0377;
86 for (place = optstring; place != NULL && *place != '\0'; ++place)
90 if (place == NULL || *place == '\0' || c == ':' || c == '?') {
91 return (badopt(": unknown option -", c));
99 } else if (ntp_optind >= argc) {
100 return (badopt(": option requires argument -", c));
102 ntp_optarg = argv[ntp_optind++];