⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getoptsl.man

📁 国外网站上的一些精典的C程序
💻 MAN
字号:
FUNCTION:   getopts_lite()ABSTRACT:   Command line argument processor. A subset of getopts() (also in            SNIPPETS), handles switches, options, literal data, file names            with or without wildcards. Only statically defined default values            are supported. Range checking and response files are not            supported.CALL WITH:  int getopts_lite(int argc, char *argv[])            argc and argv are passed from main()            Option switches set up in an array of Option_Tag structures.PROTOTYPED: In GETOPTSL.H.ALSO USES:  DIRPORT.HPORTABILITY:      Although written for DOS, getopts_lite() should port with                  little effort to other environments. The only significant                  barrier to portability is directory and filename                  processing.PROCESSING LITERAL DATA AND FILE NAMESUSING getopts_lite() WITHOUT OPTION PROCESSING:-----------------------------------------------You can call getopts_lite() without option processing by simply adding thefollowing line to your program:struct Option_Tag options[] = {{ NUL, Error_Tag, NULL, 0}};This is an empty options list which tells getopts_lite() not to look foroptions.  When called this way, only the global xargc and xargv[] data aresaved.All arguments will be treated as file names and getopts will try to expandthem. See the section below on options processing for more information onspecifying command line options.Using xargs processing, the global variable xargc will be the total number ofarguments returned, including expanded filenames, plus 1. The full list ofarguments, including expanded filenames, is returned in the global xargvarray. Just as with argv, xargv[0] is the executing program's file name,copied from argv[0].If the arguments cannot be expanded, the xargv array will hold the samecontents as the original argv array. Note that command line options arestripped from the xargv array, so if your command line had 10 arguments, ofwhich 5 were options, the xargv array would contain only 6 elements (rememberxargv[0]), assuming no wildcard expansion occurred.PROCESSING OPTIONS USING getopts_lite():----------------------------------------Each program using getopts_lite() must specify an options[] array ofOption_Tag structures. Each of these structures must contain the following 7fields:Field 1 -   An integer specifying the letter used to control the option. For            example if you wanted to add a optional filename specification            using "-Ofilename", you would place 'O' in field 1. Note that            options are case-sensitive, to make a case-insensitive option,            you need to create two entries, in this example, one for 'O' and            one for 'o'.Field 2 -   This field contains the enumerated type of data to be changed.            Valid values are:            Boolean_Tag Used to specify True_/False_ switches.            Word_Tag    Used to specify unsigned short values.            DWord_Tag   Used to specify unsigned long values.            Double_Tag  Used to specify double values.            String_Tag  Used to specify strings (character arrays).            Error_Tag   Used only in terminating records (see above).Field 3 -   The address where the option data is to be stored.Field 4 -   Specifies the size of the buffer (used only for strings).Build your options[] array by specifying each option structure. When you'redone, terminate the array with a terminating record as shown above. See theGETOPTST.C test file for an example.OPTION STRING FORMATTING BY TYPE:---------------------------------Boolean_Tag       N.A.Word_Tag          Decimal numeric constant.DWord_Tag         Decimal numeric constant.Double_Tag        Decimal numeric constant.String_Tag        String literal.String literals are saved just as typed. The only problem is with stringscontaining spaces. Most operating systems split command line arguments atwhitespace, so if you wanted to specify a string containing spaces, theentire argument, including the switch itself, must be enclosed in quotes, e.g.-o"This is a string".SPECIAL OPTIONS CONSIDERATIONS:-------------------------------All options are of the basic form, <switch_char><option>, and are processedleft-to-right in sequence. The getopts_lite() function allows the use of '-'(DOS- style) or '/' (Unix-style) option switch characters. Should you need toenter a filename which uses a switch character, simply precede it with a '-'.Thus getopts_lite() will perform the translation, e.g.--file.ext  =>    -file.extPer standard Unix practice, an option consisting only of back-to-back switchcharacters, typically "--", is interpreted as a command to turn off furtheroption processing. Therefore a command tail consisting of...-ofoo -ibar -xyz -- -oops...where "-o", "-i", and "-x" are valid option characters defined in theoptions[] array, would process the first three options, then return the fifthargument as the string literal "-oops" in the xargv array.Boolean options take the extended form, <switch_char><option>[<action>],where the optional third action switch controls whether to turn the switchoff (the default action is to turn it on). Thus if you have a boolean optiondefined which is controlled by the letter, 'a',-a    turns on the option, while-a-   turns off the option.The getopts_lite() function does not allow for spaces between the switchcharacter and the following argument. Therefore, if you have defined anoption of type double, which is controlled by the letter, 'n',-n98.6      is valid, while-n 123.45   is invalid.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -