1: /*
   2:  * getopt - get option letter from argv
   3:  *	This software is in the public domain
   4:  *	Originally written by Henry Spenser at the U. of Toronto
   5:  */
   6: 
   7: #include <stdio.h>
   8: 
   9: char    *optarg;    /* Global argument pointer. */
  10: int optind = 0; /* Global argv index. */
  11: 
  12: static char *scan = NULL;   /* Private scan pointer. */
  13: 
  14: extern char *index();
  15: 
  16: int
  17: getopt(argc, argv, optstring)
  18: int argc;
  19: char *argv[];
  20: char *optstring;
  21: {
  22:     register char c;
  23:     register char *place;
  24: 
  25:     optarg = NULL;
  26: 
  27:     if (scan == NULL || *scan == '\0') {
  28:         if (optind == 0)
  29:             optind++;
  30: 
  31:         if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
  32:             return(EOF);
  33:         if (strcmp(argv[optind], "--")==0) {
  34:             optind++;
  35:             return(EOF);
  36:         }
  37: 
  38:         scan = argv[optind]+1;
  39:         optind++;
  40:     }
  41: 
  42:     c = *scan++;
  43:     place = index(optstring, c);
  44: 
  45:     if (place == NULL || c == ':') {
  46:         fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
  47:         return('?');
  48:     }
  49: 
  50:     place++;
  51:     if (*place == ':') {
  52:         if (*scan != '\0') {
  53:             optarg = scan;
  54:             scan = NULL;
  55:         } else {
  56:             optarg = argv[optind];
  57:             optind++;
  58:         }
  59:     }
  60: 
  61:     return(c);
  62: }

Defined functions

getopt defined in line 16; used 1 times

Defined variables

optarg defined in line 9; used 3 times
optind defined in line 10; used 11 times
scan defined in line 12; used 7 times
Last modified: 1985-09-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 926
Valid CSS Valid XHTML 1.0 Strict