Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getopt(3C) — sys5 — Apollo Domain/OS SR10.4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getopts(1)

GETOPT(3C)                           SysV                           GETOPT(3C)



NAME
     getopt - get option letter from argument vector

SYNOPSIS
     #include <stdio.h>
     #include <stdlib.h>

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

     extern char *optarg;
     extern int optind, opterr;

DESCRIPTION
     The getopt function is a command line parser.  It returns the next flag
     character in the argv argument list that matches a character in the
     optstring argument.  The getopt function is used to help programs
     interpret shell command-line flags that are passed to them.

     The arguments are as follows:

     argc Specifies the number of arguments passed to the routine.

     argv Points to an array of argc pointers to argument strings.

     optstring
          Specifies a string of recognized option characters.  If a character
          is followed by a colon, the flag is expected to take a argument that
          may or may not be separated from it by white space.

     The optarg external variable is set to point to the start of the flag's
     argument on return from the getopt function.

     The getopt function places the argv index of the next argument to be
     processed in optind.  The optind variable is externally initialized to 1
     before the first call to getopt so that argv[0] is not processed.

DIAGNOSTICS
     Upon successful completion, the getopt function returns the flag
     character that was detected.  If it encounters a flag that is not
     included in the optstring argument, or if the : (colon) character is used
     incorrectly, the getopt function prints an error message on stderr and
     returns a ? (question mark).  The error message can be suppressed by
     setting the int variable opterr to 0 (zero).

WARNING
     Although relaxations to the command syntax rule are permitted under the
     current implementation, they should not be used because they may not be
     supported in future releases of the system.

     When all flags have been processed (that is, up to the first nonflag
     argument), the getopt function returns EOF.  The special flag -- (dash
     dash) can be used to delimit the end of the flags; EOF is returned, and
     the -- string is skipped.

SEE ALSO
     Commands: getopts(1)

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