diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-26 16:38:00 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-26 16:38:00 -0400 |
| commit | 97d5c458cfa039d857301e1ca7d5af3beb37131d (patch) | |
| tree | b460cd850d0537eb71806ba30358840377b27688 /static/unix-v10/man3/getflags.3 | |
| parent | b89dc2331a50c63f8b33272a5c4c61ab98abdaa3 (diff) | |
build: Better Build System
Diffstat (limited to 'static/unix-v10/man3/getflags.3')
| -rw-r--r-- | static/unix-v10/man3/getflags.3 | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/static/unix-v10/man3/getflags.3 b/static/unix-v10/man3/getflags.3 new file mode 100644 index 00000000..1352e5a5 --- /dev/null +++ b/static/unix-v10/man3/getflags.3 @@ -0,0 +1,116 @@ +.TH GETFLAGS 3 +.CT 2 data_man +.SH NAME +getflags \(mi process flag arguments in argv +.SH SYNOPSIS +.nf +#include </usr/include/getflags.h> +.PP +.B int getflags(argc, argv, flags) +.B char **argv, *flags; +.PP +.B usage(tail) +.B char *tail; +.PP +.B extern char **flag[], cmdline[], *cmdname, *flagset[]; +.fi +.SH DESCRIPTION +.I Getflags +digests an argument vector +.IR argv , +finding flag arguments listed in +.IR flags . +.I 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 +.RB ` - ' +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. +.PP +The global array +.I flag +is set to point to an array of parameters for each flag found. +Thus, if flag +.B -x +was seen, +.B flag['x'] +is non-zero, and +.B flag['x'][i] +is the flag's +.IR i th +parameter. +If flag +.B -x +has no parameters +.BR flag['x']==flagset . +Flags not found +are marked with a zero. +Flags and their parameters are deleted from +.I argv. +.I Getflags +returns the adjusted argument count. +.PP +.I Getflags +stops scanning for flags upon encountering a non-flag argument, +or an argument whose only character is +.RB ` - ', +which argument is deleted. +.PP +.I Getflags +places a pointer to +.I argv[0] +in the external variable +.I cmdname. +It also concatenates the original members of +.IR argv , +separated by spaces, and places the result in the external array +.IR cmdline . +.PP +.I Usage +constructs a usage message, prints it on the standard error file, +and exits with status 1. +The command name printed is +.IR argv[0] . +Appropriate flag usage syntax is generated from +.IR flags . +As an aid, +explanatory information about flag parameters may be included in +.I flags +in square brackets as in the example. +.I Tail +is printed at the end of the message. +If +.I getflags +encountered an error, +.I usage +tries to indicate the cause. +.SH EXAMPLES +.EX + main(argc, argv) + char *argv[]; + { + if((argc=getflags(argc, argv, "vinclbhse:1[expr]", 1))==-1) + usage("[file ...]"); + } +.EE +might print: +.EX + Illegal flag -u + Usage: grep [-vinclbhs] [-e expr] [file ...] +.EE +.SH "SEE ALSO" +.IR getopt (3) +.SH DIAGNOSTICS +.I Getflags +returns \-1 on error: +a syntax error in +.I flags, +setting a flag more than once, setting a flag not mentioned +in +.IR flags , +or running out of argv while collecting a flag's parameters. |
