Both, the Tcl procedure and the C function work very similar. Both expect an object (for which the method was called) and an argument list (argc, argv in C, and a simple list in Tcl). In C the argument list consists (besides administrativia) of multiple blocks of six single arguments, and in Tcl the argument list consists of muliple sublists of six elements each. For both, the C and the Tcl version, the six items have the following meanings:
The type of the argument in Tcl is one of the follwing constants
[Phones p] add a b c d e f FeatureSet fs proc myproc { obj args } { global p set fixPar1 123 set fixPar2 alpha set fixPar3 {1 2} set optPar1 fs2 set optPar2 y set optPar3 -1 set optPar4 {7 8 9} itfParseArgv myproc $args [list [ list <par1> int {} fixPar1 {} {first parameter} ] [ list <par2> string {} fixPar2 {} {second parameter} ] [ list <par3> liarray {} fixPar3 $obj.list {third parameter} ] [ list -par4 object {} optPar1 FeatureSet {fourth parameter} ] [ list -par5 char {} optPar2 {} {fifth parameter} ] [ list -par6 lindex {} optPar3 $obj.list {sixth parameter} ] [ list -par7 iarray {} optPar4 {} {seventh parameter} ] ] puts "fixPar1 $fixPar1" puts "fixPar2 $fixPar2" puts "fixPar3 $fixPar3" puts "optPar1 $optPar1" puts "optPar2 $optPar2" puts "optPar3 $optPar3" puts "optPar4 $optPar4" } Phones method m myproc -text "helptext for method m" # puts "----------------" puts "get help message" # puts [ p m -help ] # puts "---------------------------------------------------" puts "regular call of method with all optional parameters" # puts [ p m 7 bla { d e a } -par6 c -par5 n -par4 fs -par7 { 3 4 5 } ] # puts "---------------------------" puts "not enough fixed parameters" # puts [ p m 7 bla -par6 c ] # puts "------------------------------------------" puts "too many fixed parameters (== sick option)" # puts [ p m 7 bla { d e a } sick -par5 n -par4 fs ] # puts "------------------------" puts "illegal integer argument" # puts [ p m seven bla { d e a } -par5 n ] # puts "-----------------------" puts "illegal object argument" # puts [ p m 7 bla { d e a } -par4 feat ] # puts "--------------------------" puts "illegal character argument" # puts [ p m 7 bla { d e a } -par5 foo ] # puts "------------------------------" puts "illegal integer array argument" # puts [ p m 7 bla { d e a } -par7 { 1 2 foo 3 } ]
% source testParseArgv.tcl ---------------- get help message Parameters of 'myproc' are: <par1> first parameter (int:123) <par2> second parameter (string:alpha) <par3> third parameter (index array in p.list:1 2) -par4 fourth parameter (FeatureSet:fs2) -par5 fifth parameter (char:y) -par6 sixth parameter (index in p.list:-1) -par7 seventh parameter (iarray:7 8 9) fixPar1 123 fixPar2 alpha fixPar3 1 2 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9 --------------------------------------------------- regular call of method with all optional parameters fixPar1 7 fixPar2 bla fixPar3 3 4 0 optPar1 fs optPar2 n optPar3 2 optPar4 3 4 5 --------------------------- not enough fixed parameters undefined option: c Parameters of 'myproc' are: <par1> first parameter (int:7) <par2> second parameter (string:bla) <par3> third parameter (index array in p.list:-1) -par4 fourth parameter (FeatureSet:fs2) -par5 fifth parameter (char:y) -par6 sixth parameter (index in p.list:-1) -par7 seventh parameter (iarray:7 8 9) fixPar1 7 fixPar2 bla fixPar3 -1 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9 ------------------------------------------ too many fixed parameters (== sick option) undefined option: sick Parameters of 'myproc' are: <par1> first parameter (int:7) <par2> second parameter (string:bla) <par3> third parameter (index array in p.list:3 4 0) -par4 fourth parameter (FeatureSet:fs2) -par5 fifth parameter (char:y) -par6 sixth parameter (index in p.list:-1) -par7 seventh parameter (iarray:7 8 9) fixPar1 7 fixPar2 bla fixPar3 3 4 0 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9 ------------------------ illegal integer argument expected int argument for <par1>, but got "seven" fixPar1 123 fixPar2 alpha fixPar3 1 2 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9 ----------------------- illegal object argument expected FeatureSet argument for -par4, but got "feat" fixPar1 7 fixPar2 bla fixPar3 3 4 0 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9 -------------------------- illegal character argument expected char argument for -par4, but got "foo" fixPar1 7 fixPar2 bla fixPar3 3 4 0 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9 ------------------------------ illegal integer array argument expected iarray argument for -par4, but got " 1 2 foo 3 " fixPar1 7 fixPar2 bla fixPar3 3 4 0 optPar1 fs2 optPar2 y optPar3 -1 optPar4 7 8 9