5 .param pmc argv :slurpy
8 options = get_root_global ['_tcl'; 'helpers'; 'lsearch'], 'options'
10 .local pmc select_switches, switches
11 select_switches = get_root_global ['_tcl'], 'select_switches'
12 switches = select_switches(options, argv, 0, 1, 'option')
17 if argc != 2 goto bad_args
19 .local string option, pattern
20 .local pmc list, toList
22 toList = get_root_global [ '_tcl' ] , 'toList'
28 iter = new 'Iterator', list
30 .local int pos, result
35 lc = exists switches['nocase']
36 unless lc goto got_case
37 pattern = downcase pattern
40 $I1 = exists switches['exact']
41 if $I1 goto exact_loop
42 $I1 = exists switches['regexp']
43 if $I1 goto regexp_begin
47 globber = compreg 'Tcl::Glob'
48 .local pmc rule, match
49 rule = globber.'compile'(pattern)
54 unless lc goto glob_match
58 unless match goto glob_next
65 regexp_begin: # very similar to glob_...
67 regexp = compreg 'PGE::P5Regex'
68 .local pmc rule, match
69 rule = regexp(pattern)
74 unless lc goto regexp_match
78 unless match goto regexp_next
88 unless lc goto exact_match
91 if $S0 != pattern goto exact_next
102 die 'wrong # args: should be "lsearch ?options? list pattern"'
105 .sub 'anon' :anon :load
107 options = new 'TclList'
109 push options, 'ascii'
110 push options, 'decreasing'
111 push options, 'dictionary'
112 push options, 'exact'
114 push options, 'increasing'
115 push options, 'index'
116 push options, 'inline'
117 push options, 'integer'
118 push options, 'nocase'
121 push options, 'regexp'
122 push options, 'sorted'
123 push options, 'start'
124 push options, 'subindices'
126 set_root_global ['_tcl'; 'helpers'; 'lsearch'], 'options', options
134 # vim: expandtab shiftwidth=4 ft=pir: