Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getopt(3C) — sys5 — Apollo

Media Vault

Software Library

Restoration Projects

Artifacts Sought



GETOPT(3C)      DOMAIN/IX Reference Manual (SYS5)      GETOPT(3C)



NAME
     getopt - get option letter from argument vector

USAGE
     int getopt (argc, argv, optstring)
     int argc;
     char **argv, *opstring;

     extern char *optarg;
     extern int optind, opterr;

DESCRIPTION
     Getopt returns the next option letter in argv that matches a
     letter in optstring.  Optstring is a string of recognized
     option letters.  If a letter is followed by a colon, the
     option should have an argument.  Optarg is set to point to
     the start of the option argument on return from getopt.

     Getopt places the argv index of the next argument to be pro-
     cessed in optind Because optind is external, it is automati-
     cally set to zero before the first call to getopt.

     When all the options have been processed (i.e., up to the
     first non-option argument), getopt returns EOF.  The special
     option -- may be used to delimit the end of the options; EOF
     will be returned, and -- will be skipped.

EXAMPLE
     The following code fragment shows how to process the argu-
     ments for a command that can take the mutually exclusive
     options a and b, and the options f and o, both of which
     require arguments:

          main (argc, argv)
          int argc;
          char **argv;
          {
               int c;
               extern char *optarg;
               extern int optind;
               .
               .
               .
               while ((c = getopt(argc, argv, "abf:o:")) != EOF)
                    switch (c) {
                    case 'a':
                         if (bflg)
                              errflg++;
                         else
                              aflg++;
                         break;
                    case 'b':



Printed 5/10/85                                          GETOPT-1





GETOPT(3C)      DOMAIN/IX Reference Manual (SYS5)      GETOPT(3C)



                         if (aflg)
                              errflg++;
                         else
                              bproc( );
                         break;
                    case 'f':
                         ifile = optarg;
                         break;
                    case 'o':
                         ofile = optarg;
                         break;
                    case '?':
                         errflg++;
                    }
               if (errflg) {
                    fprintf(stderr, "usage: . . . ");
                    exit (2);
               }
               for ( ; optind < argc; optind++) {
                    if (access(argv[optind], 4)) {
               .
               .
               .
          }

DIAGNOSTICS
     Getopt prints an error message on stderr and returns a ques-
     tion mark (?) when it encounters an option letter that is
     not included in optstring.  This error message may be dis-
     abled by setting opterr to a non-zero value.

RELATED INFORMATION
     getopt(1)






















GETOPT-2                                          Printed 5/10/85



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026