You are here

tclGetOpts 1.1

admin의 아바타

홈페이지 : http://www.waxandwane.com/toolbox/tclGetOpts/getopt.html

getopt sets the variable optret to the next option letter in arglist that matches a letter in optstring. optstring must contain the option letters the command using getopt will recognize; if a letter is followed by a colon, the option is expected to have an argument. The variable argret will be set to the option argument, if any.
getopt sets the global variables optind and optindc to point to the next option letter in arglist to be processed; optind holds the index of the option in the list, and optindc holds the index of the option letter in the string.

When all options have been processed (that is, up to the first non-option argument), getopt returns an empty string. The special option -- may be used to delimit the end of the options; when it is encountered, optret will be set to the empty string, and the -- will be skipped.

If getopt encounters an option in arglist that is not described in optstring, or it finds an option with no argument when the option requires one, it sets optret to a blank string and argret to an error message.

getopt returns 1 if an option was found, 0 if no more options were found, and -1 if an error occurred.

Example
The following script accepts the exclusive options -a and -b, and the option -o with an argument.

#!/usr/local/bin/tclsh

     set opts(a) 0
     set opts(b) 0
     set opts(o) ""

     proc usage {} {
       puts stderr "Usage: $argv0 [ -a | -b ] [ -o  ]"
       exit 22
     }

     while { [ set err [ getopt $argv "abo:" opt arg ]] } {
       if { $err 
첨부 파일파일 크기
Binary Data tclGetOpts1.1.tar.gz8.47 KB