1: #! /usr/bin/env tclsh
2:
3: namespace eval ::minirivet {}
4:
47dcf5fc27 2019-05-01 5: proc ::minirivet::parseString {string} {
47dcf5fc27 2019-05-01 6:
7: set fixMap [list]
8: foreach char [list "\{" "\}" "\\"] {
9: lappend fixMap $char "\}; puts -nonewline \"\\$char\"; puts -nonewline \{"
10: }
11:
12: set code ""
13: while {$string ne ""} {
14: set endIndex [string first "<?" $string]
15: if {$endIndex == -1} {
16: set endIndex [expr {[string length $string] + 1}]
17: }
18:
19:
20: append code "puts -nonewline \{" [string map $fixMap [string range $string 0 $endIndex-1]] "\}; "
21: set string [string range $string $endIndex end]
22: set endIndex [string first "?>" $string]
23: if {$endIndex == -1} {
24: set endIndex [expr {[string length $string] + 1}]
25: }
26:
27: set work [string range $string 0 2]
28: if {$work eq "<?="} {
29: set startIndex 3
30: append code "puts -nonewline [string trim [string range $string 3 $endIndex-1]]; "
31: } else {
32: append code [string range $string 2 $endIndex-1] "\n"
33: }
34:
35: set string [string range $string $endIndex+2 end]
36:
37:
38: }
39:
40: tailcall namespace eval ::request $code
41: }
42:
43: proc ::minirivet::parse {file} {
44: set fd [open $file]
45: set data [read $fd]
46: close $fd
47: tailcall parseString $data
48: }
49:
50: package provide minirivet 1