Annotation For lib/minirivet/minirivet.tcl

Origin for each line in lib/minirivet/minirivet.tcl from check-in 5dc4de14de:

47dcf5fc27 2019-05-01    1: #! /usr/bin/env tclsh
47dcf5fc27 2019-05-01    2: 
47dcf5fc27 2019-05-01    3: namespace eval ::minirivet {}
47dcf5fc27 2019-05-01    4: 
b07616bee9 2019-09-20    5: if {![info exists ::minirivet::_outputChannel] && ![info exists ::minirivet::_outputVariable]} {
b07616bee9 2019-09-20    6: 	set ::minirivet::_outputChannel stdout
b07616bee9 2019-09-20    7: }
b07616bee9 2019-09-20    8: 
b07616bee9 2019-09-20    9: proc ::minirivet::setOutputChannel {channel} {
b07616bee9 2019-09-20   10: 	unset -nocomplain ::minirivet::_outputVariable
b07616bee9 2019-09-20   11: 	set ::minirivet::_outputChannel $channel
b07616bee9 2019-09-20   12: }
b07616bee9 2019-09-20   13: 
b07616bee9 2019-09-20   14: proc ::minirivet::setOutputVar {variable} {
b07616bee9 2019-09-20   15: 	unset -nocomplain ::minirivet::_outputChannel
b07616bee9 2019-09-20   16: 	set ::minirivet::_outputVariable $variable
b07616bee9 2019-09-20   17: }
b07616bee9 2019-09-20   18: 
b07616bee9 2019-09-20   19: proc ::minirivet::_emitOutput {string} {
b07616bee9 2019-09-20   20: 	if {[info exists ::minirivet::_outputChannel]} {
b07616bee9 2019-09-20   21: 		puts -nonewline $::minirivet::_outputChannel $string
b07616bee9 2019-09-20   22: 	}
b07616bee9 2019-09-20   23: 	if {[info exists ::minirivet::_outputVariable]} {
b07616bee9 2019-09-20   24: 		append $::minirivet::_outputVariable $string
b07616bee9 2019-09-20   25: 	}
b07616bee9 2019-09-20   26: 	return
b07616bee9 2019-09-20   27: }
b07616bee9 2019-09-20   28: 
5dc4de14de 2019-09-20   29: proc ::minirivet::parseStringToCode {string {outputCommand ""}} {
5dc4de14de 2019-09-20   30: 	if {$outputCommand eq ""} {
5dc4de14de 2019-09-20   31: 		set outputCommand [list ::minirivet::_emitOutput]
5dc4de14de 2019-09-20   32: 	}
5dc4de14de 2019-09-20   33: 
47dcf5fc27 2019-05-01   34: 	set code ""
47dcf5fc27 2019-05-01   35: 	while {$string ne ""} {
47dcf5fc27 2019-05-01   36: 		set endIndex [string first "<?" $string]
47dcf5fc27 2019-05-01   37: 		if {$endIndex == -1} {
47dcf5fc27 2019-05-01   38: 			set endIndex [expr {[string length $string] + 1}]
47dcf5fc27 2019-05-01   39: 		}
47dcf5fc27 2019-05-01   40: 
5dc4de14de 2019-09-20   41: 		append code [list {*}$outputCommand [string range $string 0 $endIndex-1]] "; "
47dcf5fc27 2019-05-01   42: 		set string [string range $string $endIndex end]
47dcf5fc27 2019-05-01   43: 		set endIndex [string first "?>" $string]
47dcf5fc27 2019-05-01   44: 		if {$endIndex == -1} {
47dcf5fc27 2019-05-01   45: 			set endIndex [expr {[string length $string] + 1}]
47dcf5fc27 2019-05-01   46: 		}
47dcf5fc27 2019-05-01   47: 
47dcf5fc27 2019-05-01   48: 		set work [string range $string 0 2]
47dcf5fc27 2019-05-01   49: 		if {$work eq "<?="} {
47dcf5fc27 2019-05-01   50: 			set startIndex 3
5dc4de14de 2019-09-20   51: 			append code "$outputCommand [string trim [string range $string 3 $endIndex-1]]; "
47dcf5fc27 2019-05-01   52: 		} else {
47dcf5fc27 2019-05-01   53: 			append code [string range $string 2 $endIndex-1] "\n"
47dcf5fc27 2019-05-01   54: 		}
47dcf5fc27 2019-05-01   55: 
47dcf5fc27 2019-05-01   56: 		set string [string range $string $endIndex+2 end]
47dcf5fc27 2019-05-01   57: 
47dcf5fc27 2019-05-01   58: 
47dcf5fc27 2019-05-01   59: 	}
47dcf5fc27 2019-05-01   60: 
f09ab16ca1 2019-05-08   61: 	return $code
f09ab16ca1 2019-05-08   62: }
f09ab16ca1 2019-05-08   63: 
f09ab16ca1 2019-05-08   64: proc ::minirivet::parseString {string} {
f09ab16ca1 2019-05-08   65: 	set code [parseStringToCode $string]
47dcf5fc27 2019-05-01   66: 	tailcall namespace eval ::request $code
47dcf5fc27 2019-05-01   67: }
47dcf5fc27 2019-05-01   68: 
47dcf5fc27 2019-05-01   69: proc ::minirivet::parse {file} {
47dcf5fc27 2019-05-01   70: 	set fd [open $file]
47dcf5fc27 2019-05-01   71: 	set data [read $fd]
47dcf5fc27 2019-05-01   72: 	close $fd
47dcf5fc27 2019-05-01   73: 	tailcall parseString $data
47dcf5fc27 2019-05-01   74: }
47dcf5fc27 2019-05-01   75: 
47dcf5fc27 2019-05-01   76: package provide minirivet 1