|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 1521 (0x5f1) Types: TextFile Names: »getopt.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Sonnet/getopt.c«
/* ** Return options and their values from the command line. ** This comes from the AT&T public-domain getopt published in mod.sources. */ #include <stdio.h> /* Pick one */ #define IDX index /* .. */ /*#define IDX strchr /* .. */ #define TYPE int #define ERR(s, c) \ if (opterr) { \ char buff[2]; \ buff[0] = c; buff[1] = '\n'; \ (void)write(2, av[0], (TYPE)strlen(av[0])); \ (void)write(2, s, (TYPE)strlen(s)); \ (void)write(2, buff, 2); \ } int opterr = 1; int optind = 1; int optopt; char *optarg; int getopt(ac, av, opts) int ac; char *av[]; char *opts; { static int i = 1; register char *p; /* Move to next value from argv? */ if (i == 1) { if (optind >= ac || av[optind][0] != '-' || av[optind][1] == '\0') return EOF; if (strcmp(av[optind], "--") == 0) { optind++; return EOF; } } /* Get next option character. */ if ((optopt = av[optind][i]) == ':' || (p = IDX(opts, optopt)) == NULL) { ERR(": illegal option -- ", optopt); if (av[optind][++i] == '\0') { optind++; i = 1; } return '?'; } /* Snarf argument? */ if (*++p == ':') { if (av[optind][i + 1] != '\0') optarg = &av[optind++][i + 1]; else { if (++optind >= ac) { ERR(": option requires an argument -- ", optopt); i = 1; return '?'; } optarg = av[optind++]; } i = 1; } else { if (av[optind][++i] == '\0') { i = 1; optind++; } optarg = NULL; } return optopt; }