2013年9月6日星期五

Ask about getopt ()

As described below :
1, command line parameters
command line program designed primary task is to parse command line arguments , GUI programmers rarely care about this faction . Here, the parameters adopted a more popular definition: In addition to the command name on the command line outside of the string. Constituted by a number of parameters , between items separated from each other by whitespace .
parameters are further divided into Options and operand . Option is used to modify the default behavior of the program or programs to provide information, the agreement is relatively old with a dash. Options can be followed by a number of parameters , called Option parameters. The rest is the operand of .
2, POSIX POSIX conventions expressed Portable Operating System Interface : Portable Operating System Interface, Electrical and Electronics Engineers (Institute of Electrical and Electronics Engineers, IEEE) was originally developed POSIX standard UNIX environment to improve application portability . However , POSIX is not limited to UNIX. Many other operating systems, such as DEC OpenVMS and Microsoft Windows NT, both support the POSIX standard .

Here is the POSIX standard on the program name , the parameters of convention :

01. program name should not be less than 2 characters and no more than at 9 characters
02. program name should only contain lowercase letters and Arabic numerals
03. option name should be a single character or a single numbers, and the dash ' - ' as the former
04. multiple no option parameter options can be combined . ( For example : foo-a-b-c ----> foo-abc)
05. Between the option and its arguments are separated by whitespace < br /> 06. option argument not optional
07. If the option parameter multiple values ​​to a string and pass it in. For example : myprog-u "arnold, joe, jane". In this case , these parameters need to solve their own separation problems .
08. option should appear before the operand appears
09. specific parameter ' - ' indicates all the parameters are over, its after any argument that is the operand .
10. option does not matter how they are arranged , but mutually exclusive options , if an option's operating results cover operating results of the other options , the last option to work ; if the option repeat the sequence processing .
11. allow the order of the operands affect program behavior, but needs to be documented .
12. literacy program should specify a single file parameter ' - ' as a meaningful standard input or output to be treated.

3, GNU long option

GNU encourage programmers to use the - help, - verbose form of long options . These options are not only conflict with the POSIX conventions , and easy to remember , while also provides consistency among all the GNU tools opportunities. GNU long options have their own conventions :

13. POSIX conventions have followed for GNU programs, each option has a corresponding short length option.
14. extra for GNU long option does not require a corresponding short option , only recommended to have .
15. long options can be abbreviated to hold uniqueness of the shortest string.
16. option parameters and long option or through whitespace between living through a '=' to separate .
17. Option parameter is optional ( option is valid only for short ) .
18. Allow long options are prefixed with a dash .


where , I ask,
1, what is the operand ? What is the relationship and connection options ?
2,06. What does this mean ? Example
3,12. What does this mean ? Illustrate
------ Solution -------------------------------------- ------
operand is a non-option and non- option arguments parameter a , cat abc.txt abc.txt here is the operand of .
06 presentation option after option arguments are common , can not be an optional parameter ,-a parameter can not be followed if you want to take this type of band -b , only abc
because would -b as another option .
12 When using the file as an operand when - expressed as the standard input or output , such as cat - should logically with the file , but did not file , this time - which means read from stdin as operands < br> ------ Solution ----------------------------------------- ---
12. literacy program should specify a single file parameter ' - ' as a meaningful standard input or output to be treated.
This can be illustrated by an example
gzip-cd foo.tar.gz | tar-xvf -
parameter options f parameter indicates the standard input.
------ Solution ---------------------------------------- ----
reference e text data it: http://www.gnu .org / software / libc / manual / html_node / Getopt-Long-Options.html # Getopt-Long-Options
including a description of the 18 , which getopt_long_only (...), as follows:
- Function: int getopt_long_only (int argc, char * const * argv, const char * shortopts, const struct option * longopts, int * indexptr)

The getopt_long_only function is equivalent to the getopt_long function but it allows to specify the user of the application to pass long options with only '-' instead of '-'. The '-' prefix is ​​still recognized but instead of looking through the short options if a '-' is seen it is first tried whether this parameter names a long option. If not , it is parsed as a short option.

Assuming getopt_long_only is used starting an application with

app-foo

the getopt_long_only will first look for a long option named 'foo'. If this is not found, the short options 'f', 'o', and again 'o' are recognized.
------ For reference only ----- ----------------------------------
clear, 06 and 17 is not a relationship ?
on the second floor about 06 parsing I have doubts
------ For reference only ------------------------- --------------
and 18 long option allows a dash for the prefix , it does not mess it ? How to distinguish between " short options option parameters" and " long options " ?
------ For reference only -------------------------------------- -
have to have an expert please help me 1,4 F 2,3 floor to answer questions, thank you
------ For reference only ------------- --------------------------
18 bar does not , ah, long options and short options will not be confused , not a long option letters, of course, when a letter is unique .
------ For reference only -------------------------------------- -
  The reply deleted by an administrator at 2013-09-05 08:41:39

------ For reference only ---------------------------------- -----
moderator to call this son of a bitch u011973105 8th floor garbage stickers deleted !
------ For reference only -------------------------------------- -
left now 6,17 puzzled , please adequate guidance twelve
------ For reference only ----------------- ----------------------
on POSIX.1-2008 part in the http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html has e paper describes .
Chinese translation stuff, out of context, bumbling , full extension Ma dog eating uncooked rice indigestion , da da shit I do not know said to odds and ends !
see e text version of it !
------ For reference only -------------------------------------- -
about GNU extension, see http://www.gnu.org/prep/standards/html_node/Command_002dLine -Interfaces.html
wording is not very organized system , better than nothing right
------ For reference only -------------------------- -------------
about the landlord 6, in the http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
......
Guideline 7:
Option-arguments should not be optional.
......
Note: see this article, we must first pre-research concept paper three words option, option-argument, operand
------ For reference only ------ ---------------------------------
really a feather ah ! That is not devoted !
------ For reference only -------------------------------------- -
about GNU extension, but also look http://www.gnu.org/software/libc/manual / html_node / Argument-Syntax.html
------ For reference only -------------------------- -------------
relevant option, option-argument, operand instructions , you can then refer to : http://pic.dhe.ibm.com/infocenter/director/pubs/index.jsp?topic =% 2Fcom.ibm.esa.director.help% 2Fservice_and_support_cli_syntax_diagram_conventions.html & lang% 3Dzh_CN
------ For reference only -------------------------------------- -
http://www.cs.virginia.edu/ ~ lcc-win32 /
http://apr.apache.org/docs/apr/1.2/group__apr__getopt.html
http://www.gtk.org/
http://www.boost.org/doc/libs/1_54_0 / doc / html / program_options.html
http://www.codeproject .com/Articles/1940/XGetopt-A-Unix-compatible-getopt-for-MFC-and-Win32
http://bytes.com/topic/c/answers/733516-getopt -under-windows
http://www.gnu.org/prep/standards/html_node/Command_002dLine -Interfaces.html
http://linux.chinaitlab.com/c/809314.html
http://linux.chinaunix.net/techdoc/system/2006 / 06/08/934020.shtml
http://pic.dhe.ibm.com/infocenter/director/pubs/index.jsp?topic =% 2Fcom.ibm.esa.director.help% 2Fservice_and_support_cli_syntax_diagram_conventions.html & lang% 3Dzh_CN
http://blog.csdn.net/johnpher/article/details/6957934
http://cpp-prog.com/2009/1102/172.html
http://www.itzk.com/b/1104/580184.shtml
http://www.codeproject .com/Articles/1940/XGetopt-A-Unix-compatible-getopt-for-MFC-and-Win32
http://enos.itcollege.ee/ ~ jpoial / docs / tutorial / essential / attributes / _posix.html
http://www.startos.com/linux/tips/2010121515236.html
http://blog.csdn.net/huangxiaohu_coder/article/details/7475156
http://www.ibm.com/developerworks/cn / aix / library / au-unix-getopt.html
http://www.gnu.org/prep/standards / html_node / Option-Table.html # Option-Table
http://www.gnu.org/software/libc/manual / html_node / Getopt.html # Getopt
http://www.codeproject.com / Articles/157001/Full-getopt-Port-for-Unicode-and-Multibyte-Microso
http://www.wcode.net/plus/view.php?aid=1541069
http://www.cppblog.com/flyonok/archive/2010 / 09/04/125884.html
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
http://bbs.csdn.net/topics/390580439
http://mih.voxindeserto.de/argvparser.html

没有评论:

发表评论