4 .HLL 'Tcl', 'tcl_group'
8 # similar to but not exactly like [string]'s subcommand dispatch
9 # - we pass in a boolean (array or not), the array itself, and the name
10 # - we know we need an array name for *all* args, so we test for it here.
13 .param pmc argv :slurpy
18 if argc < 2 goto few_args # subcommand *and* array name
20 .local string subcommand_name
21 subcommand_name = shift argv
24 options = new 'ResizablePMCArray'
25 options[0] = 'anymore'
26 options[1] = 'donesearch'
30 options[5] = 'nextelement'
33 options[8] = 'startsearch'
34 options[9] = 'statistics'
37 .local pmc select_option
38 select_option = get_root_global ['_tcl'], 'select_option'
39 .local string canonical_subcommand
40 canonical_subcommand = select_option(options, subcommand_name)
42 .local pmc subcommand_proc
45 subcommand_proc = get_root_global ['_tcl'; 'helpers'; 'array'], canonical_subcommand
46 if null subcommand_proc goto bad_args
49 .local string array_name
52 array_name = shift argv
57 __find_var = get_root_global ['_tcl'], '__find_var'
58 the_array = __find_var(array_name)
60 if_null the_array, array_no
62 $I99 = does the_array, 'hash'
63 if $I99==0 goto array_no
72 .return subcommand_proc(is_array,the_array,array_name,argv)
75 .return ('') # once all commands are implemented, remove this...
78 tcl_error 'wrong # args: should be "array option arrayName ?arg ...?"'
84 .namespace [ 'helpers' ; 'array' ]
89 .param string array_name
99 tcl_error 'wrong # args: should be "array exists arrayName"'
105 .param string array_name
110 if argc goto bad_args
112 if is_array == 0 goto size_none
120 tcl_error 'wrong # args: should be "array size arrayName"'
126 .param string array_name
131 if argc != 1 goto bad_args
137 __list = get_root_global ['_tcl'], '__list'
138 elems = __list(elems)
144 if $I0 == 1 goto odd_args
146 # pull out all the key/value pairs and set them.
153 set = get_root_global ['_tcl'], '__set'
155 if_null the_array, new_array # create a new array if no var
159 the_array = new 'TclArray'
160 set(array_name,the_array) # create an empty named array...
163 if loop >= count goto done
169 # Do this just as if were were calling each set manually, as tcl's
170 # error messages indicate it seems to.
172 # equals creates an alias, so use assign.
174 subvar = '' # why is this necessary, if we're doing an assign ???
175 assign subvar, array_name
187 tcl_error 'wrong # args: should be "array set arrayName list"'
190 tcl_error 'list must have an even number of elements'
194 .include 'iterator.pasm'
198 .param string array_name
203 if argc > 1 goto bad_args
205 .local string match_str
206 # ?pattern? defaults to matching everything.
209 # if it's there, get it from the arglist
210 if argc == 0 goto no_args
211 match_str = shift argv
214 if is_array == 0 goto not_array
222 globber = compreg 'Tcl::Glob'
224 rule = globber.'compile'(match_str)
226 iter = new 'Iterator', the_array
228 retval = new 'TclList'
234 unless iter goto push_end
239 unless $P2 goto push_loop
253 tcl_error 'wrong # args: should be "array get arrayName ?pattern?"'
262 .param string array_name
267 if argc > 1 goto bad_args
270 .local string match_str
271 # ?pattern? defaults to matching everything.
274 # if it's there, get it from the arglist
275 if argc == 0 goto no_args
276 match_str = shift argv
279 if is_array == 0 goto not_array
287 globber = compreg 'Tcl::Glob'
289 (rule, $P0, $P1) = globber.'compile'(match_str)
291 iter = new 'Iterator', the_array
294 unless iter goto push_end
299 unless $P2 goto push_loop
301 delete the_array[str]
309 tcl_error 'wrong # args: should be "array unset arrayName ?pattern?"'
318 .param string array_name
325 if argc > 2 goto bad_args
327 .local string mode, pattern
330 if argc == 0 goto skip_args
331 if argc == 1 goto skip_mode
338 .local pmc match_proc
341 match_proc = get_hll_global [ 'helpers'; 'array'; 'names_helper' ], mode
342 if null match_proc goto bad_mode
344 if is_array == 0 goto not_array
346 .return match_proc(the_array, pattern)
349 tcl_error 'wrong # args: should be "array names arrayName ?mode? ?pattern?"'
354 $S0 .= '": must be -exact, -glob, or -regexp'
358 tcl_error '' # is this right? -Coke
361 .namespace [ 'helpers' ; 'array'; 'names_helper' ]
365 .param string pattern
370 .local pmc globber, retval
371 globber = compreg 'Tcl::Glob'
373 rule = globber.'compile'(pattern)
375 iter = new 'Iterator', the_array
377 retval = new 'TclList'
383 unless iter goto check_end
386 unless $P0 goto check_loop
401 .local pmc iter, retval
404 iter = new 'Iterator', the_array
406 retval = new 'String'
410 unless iter goto check_end
413 if name == match goto found_match
425 .param string pattern
430 .local pmc tclARE, retval
431 tclARE = compreg 'PGE::P5Regex'
433 rule = tclARE(pattern)
435 iter = new 'Iterator', the_array
437 retval = new 'TclList'
443 unless iter goto check_end
446 unless $P0 goto check_loop
461 # vim: expandtab shiftwidth=4 ft=pir: