glenda.party
term% ls -F
term% cat index.txt
GETFLAGS(9.2)                                                    GETFLAGS(9.2)

NAME
       getflags, usage - process flag arguments in argv

SYNOPSIS
       #include <libg.h>

       #include <fb.h>

       int getflags(int argc, char *argv[], char *flags)

       int usage(char *tail)

       extern char **flag[], cmdline[], *cmdname, *flagset[];

DESCRIPTION
       Getflags digests an argument vector argv, finding flag arguments listed
       in  flags.   Flags is a string of flag letters.  A letter followed by a
       colon and a number is expected to have the given number of  parameters.
       A  flag  argument starts with ‘-' and is followed by any number of flag
       letters.  A flag with one or more parameters must be the last  flag  in
       an  argument.   If  any characters follow it, they are the flag's first
       parameter.  Otherwise the following argument is  the  first  parameter.
       Subsequent parameters are taken from subsequent arguments.

       The  global  array  flag  is set to point to an array of parameters for
       each flag found.  Thus, if flag -x was seen, flag['x'] is non-zero, and
       flag['x'][i] is the flag's ith parameter.  If flag -x has no parameters
       flag['x']==flagset.  Flags not found are marked with a zero.  Flags and
       their parameters are deleted from argv.  Getflags returns the  adjusted
       argument count.

       Getflags  stops  scanning  for flags upon encountering a non-flag argu‐
       ment, or the argument --, which is deleted.

       Getflags places a pointer to argv[0] in the external variable  cmdname.
       It also concatenates the original members of argv, separated by spaces,
       and places the result in the external array cmdline.

       Usage constructs a usage message, prints it on the standard error file,
       and  exits with status 1.  The command name printed is argv[0].  Appro‐
       priate flag usage syntax is generated from flags.  As an aid,  explana‐
       tory  information  about  flag  parameters  may be included in flags in
       square brackets as in the example.  Tail is printed at the end  of  the
       message.  If getflags encountered an error, usage tries to indicate the
       cause.

EXAMPLES
            main(int argc, char *argv[]){
                 if((argc=getflags(argc, argv, "vinclbhse:1[expr]", 1))==-1)
                      usage("[file ...]");
            }
       might print:
            Illegal flag -u
            Usage: grep [-vinclbhs] [-e expr] [file ...]

SOURCE
       /sys/src/libfb/getflags.c

SEE ALSO
       ARG(2)

DIAGNOSTICS
       Getflags  returns  -1 on error: a syntax error in flags, setting a flag
       more than once, setting a flag not mentioned in flags, or  running  out
       of arguments while collecting a flag's parameters.

                                                                 GETFLAGS(9.2)