1 .HLL 'Tcl', 'tcl_group'
5 .param pmc argv :slurpy
15 if argc < 2 goto bad_args
17 unless argc goto bad_args
19 $S1 = substr $S0, 0, 1
20 if $S0 == '--' goto get_subj
21 if $S1 != '-' goto skip_subj
24 if $S0 == '-exact' goto set_mode
25 if $S0 == '-glob' goto set_mode
26 if $S0 == '-regexp' goto set_mode
27 if $S0 == '-nocase' goto set_case
28 if $S0 == '-matchvar' goto set_fvar
29 if $S0 == '-indexvar' goto set_fvar
45 unless argv goto bad_args
50 unless nocase goto get_body
51 subject = downcase subject
56 if argc != 1 goto body_from_argv
60 __list = get_root_global ['_tcl'], '__list'
71 if $I0 == 0 goto bad_args_with_curlies
73 if $I0 == 1 goto extra_pattern
75 # check to make sure the last option isn't a fall-through
77 unless $S0 == '-' goto check_mode
79 $S0 = 'no body specified for pattern "' . $S0
84 .local string pattern, code
85 if mode == '-exact' goto exact_mode
86 if mode == '-glob' goto glob_mode
87 if mode == '-regexp' goto regex_mode
91 unless body goto body_end
94 unless nocase goto exact_do
95 pattern = downcase pattern
99 if subject == pattern goto body_match
103 .local pmc globber, rule
104 globber = compreg 'Tcl::Glob'
106 unless body goto body_end
109 unless nocase goto glob_do
110 pattern = downcase pattern
114 (rule, $P1, $P2) = globber.'compile'(pattern)
116 if $P0 goto body_match
120 .local pmc tclARE,rule,match
121 tclARE = compreg 'PGE::P5Regex'
123 unless body goto body_end
126 unless nocase goto re_do
127 pattern = downcase pattern
130 rule = tclARE(pattern)
131 match = rule(subject)
132 if match goto body_match
136 if pattern == 'default' goto body_match
144 if code == '-' goto fallthrough
146 __script = get_root_global ['_tcl'], '__script'
151 tcl_error 'extra switch pattern with no body'
154 tcl_error 'wrong # args: should be "switch ?switches? string pattern body ... ?default body?"'
156 bad_args_with_curlies:
157 tcl_error 'wrong # args: should be "switch ?switches? string {pattern body ... ?default body?}"'
162 $S1 .= '": must be -exact, -glob, -indexvar, -matchvar, -nocase, -regexp, or --'
170 # vim: expandtab shiftwidth=4 ft=pir: