From 31250295c2bc515565bf10c62839bebda97db398 Mon Sep 17 00:00:00 2001 From: CSRG Date: Mon, 9 Sep 1985 23:04:53 -0800 Subject: [PATCH] BSD 4_3 development Work on file usr/contrib/dipress/src/bin/ipf/getopt.c Synthesized-from: CSRG/cd1/4.3 --- usr/contrib/dipress/src/bin/ipf/getopt.c | 62 ++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 usr/contrib/dipress/src/bin/ipf/getopt.c diff --git a/usr/contrib/dipress/src/bin/ipf/getopt.c b/usr/contrib/dipress/src/bin/ipf/getopt.c new file mode 100644 index 0000000000..0fd2c24d01 --- /dev/null +++ b/usr/contrib/dipress/src/bin/ipf/getopt.c @@ -0,0 +1,62 @@ +/* + * getopt - get option letter from argv + * This software is in the public domain + * Originally written by Henry Spenser at the U. of Toronto + */ + +#include + +char *optarg; /* Global argument pointer. */ +int optind = 0; /* Global argv index. */ + +static char *scan = NULL; /* Private scan pointer. */ + +extern char *index(); + +int +getopt(argc, argv, optstring) +int argc; +char *argv[]; +char *optstring; +{ + register char c; + register char *place; + + optarg = NULL; + + if (scan == NULL || *scan == '\0') { + if (optind == 0) + optind++; + + if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') + return(EOF); + if (strcmp(argv[optind], "--")==0) { + optind++; + return(EOF); + } + + scan = argv[optind]+1; + optind++; + } + + c = *scan++; + place = index(optstring, c); + + if (place == NULL || c == ':') { + fprintf(stderr, "%s: unknown option -%c\n", argv[0], c); + return('?'); + } + + place++; + if (*place == ':') { + if (*scan != '\0') { + optarg = scan; + scan = NULL; + } else { + optarg = argv[optind]; + optind++; + } + } + + return(c); +} -- 2.20.1