Annotation For xvfs-create

Origin for each line in xvfs-create from check-in e592c85e70:

47dcf5fc27 2019-05-01    1: #! /usr/bin/env tclsh
47dcf5fc27 2019-05-01    2: 
47dcf5fc27 2019-05-01    3: set sourceDirectory [file dirname [file normalize [info script]]]
f09ab16ca1 2019-05-08    4: 
47dcf5fc27 2019-05-01    5: lappend auto_path [file join $sourceDirectory lib]
f09ab16ca1 2019-05-08    6: 
2b7fa3a8fa 2019-09-20    7: set template [file join $sourceDirectory lib xvfs xvfs.c.rvt]
47dcf5fc27 2019-05-01    8: 
47dcf5fc27 2019-05-01    9: package require minirivet
47dcf5fc27 2019-05-01   10: 
f09ab16ca1 2019-05-08   11: set mode "run"
f09ab16ca1 2019-05-08   12: if {[lindex $argv 0] == "--dump-tcl"} {
f09ab16ca1 2019-05-08   13: 	set mode "dump-tcl"
0bdbe4333e 2019-09-20   14: }
0bdbe4333e 2019-09-20   15: 
0bdbe4333e 2019-09-20   16: foreach {arg val} $argv {
0bdbe4333e 2019-09-20   17: 	switch -exact -- $arg {
0bdbe4333e 2019-09-20   18: 		"--output" {
0bdbe4333e 2019-09-20   19: 			set outputFile $val
2b7fa3a8fa 2019-09-20   20: 		}
09e53d3c38 2019-09-20   21: 		"--header" {
09e53d3c38 2019-09-20   22: 			set headerFile $val
09e53d3c38 2019-09-20   23: 		}
0bdbe4333e 2019-09-20   24: 	}
d80c88cee0 2019-09-16   25: }
d80c88cee0 2019-09-16   26: 
d80c88cee0 2019-09-16   27: proc remove_debug {input} {
d80c88cee0 2019-09-16   28: 	set output [list]
d80c88cee0 2019-09-16   29: 
d80c88cee0 2019-09-16   30: 	set lastLine -
d80c88cee0 2019-09-16   31: 	foreach line [split $input "\n"] {
d80c88cee0 2019-09-16   32: 		if {[string match -nocase "*XVFS_DEBUG*" $line]} {
d80c88cee0 2019-09-16   33: 			continue
d80c88cee0 2019-09-16   34: 		}
d80c88cee0 2019-09-16   35: 
d80c88cee0 2019-09-16   36: 		if {$lastLine eq "" && $line eq ""} {
d80c88cee0 2019-09-16   37: 			continue
d80c88cee0 2019-09-16   38: 		}
d80c88cee0 2019-09-16   39: 
d80c88cee0 2019-09-16   40: 		set lastLine $line
d80c88cee0 2019-09-16   41: 		lappend output $line
d80c88cee0 2019-09-16   42: 	}
d80c88cee0 2019-09-16   43: 
d80c88cee0 2019-09-16   44: 	return [join $output "\n"]
d80c88cee0 2019-09-16   45: }
d80c88cee0 2019-09-16   46: 
f09ab16ca1 2019-05-08   47: switch -- $mode {
f09ab16ca1 2019-05-08   48: 	"run" {
d36db7c01b 2019-09-20   49: 		package require xvfs
d36db7c01b 2019-09-20   50: 
0bdbe4333e 2019-09-20   51: 		if {[info exists outputFile]} {
0bdbe4333e 2019-09-20   52: 			set fd [open $outputFile w]
d36db7c01b 2019-09-20   53: 			::xvfs::setOutputChannel $fd
d36db7c01b 2019-09-20   54: 		}
d36db7c01b 2019-09-20   55: 
09e53d3c38 2019-09-20   56: 		if {[info exists headerFile]} {
09e53d3c38 2019-09-20   57: 			::xvfs::staticIncludeHeader $headerFile
09e53d3c38 2019-09-20   58: 		}
e592c85e70 2019-09-20   59: 		::xvfs::run {*}$argv
0bdbe4333e 2019-09-20   60: 
0bdbe4333e 2019-09-20   61: 		if {[info exists fd]} {
0bdbe4333e 2019-09-20   62: 			close $fd
0bdbe4333e 2019-09-20   63: 		}
f09ab16ca1 2019-05-08   64: 	}
f09ab16ca1 2019-05-08   65: 	"dump-tcl" {
f09ab16ca1 2019-05-08   66: 		set xvfs_tcl [file join $sourceDirectory lib xvfs xvfs.tcl]
7664854ef9 2019-05-08   67: 		set xvfs_core_h [file join $sourceDirectory xvfs-core.h]
7664854ef9 2019-05-08   68: 		set xvfs_core_c [file join $sourceDirectory xvfs-core.c]
7664854ef9 2019-05-08   69: 
b8cca3a6b4 2019-05-08   70: 		set cleanup {
b8cca3a6b4 2019-05-08   71: 			"#include <xvfs-core.h>" ""
b8cca3a6b4 2019-05-08   72: 			"#include <xvfs-core.c>" ""
b8cca3a6b4 2019-05-08   73: 		}
7664854ef9 2019-05-08   74: 
7664854ef9 2019-05-08   75: 		set core_header_data ""
7664854ef9 2019-05-08   76: 		append core_header_data [string map $cleanup [read [open $xvfs_core_h]]] "\n"
7664854ef9 2019-05-08   77: 		append core_header_data [string map $cleanup [read [open $xvfs_core_c]]] "\n"
7664854ef9 2019-05-08   78: 
d80c88cee0 2019-09-16   79: 		if {[lsearch -exact $argv "--remove-debug"] != -1} {
d80c88cee0 2019-09-16   80: 			set core_header_data [remove_debug $core_header_data]
d80c88cee0 2019-09-16   81: 		}
d80c88cee0 2019-09-16   82: 
f09ab16ca1 2019-05-08   83: 		puts "#! /usr/bin/env tclsh"
d80c88cee0 2019-09-16   84: 		puts ""
0bdbe4333e 2019-09-20   85: 		puts [list namespace eval ::minirivet {}]
0bdbe4333e 2019-09-20   86: 		puts [list set ::minirivet::_outputChannel stdout]
0bdbe4333e 2019-09-20   87: 		puts [list proc ::minirivet::_emitOutput [info args ::minirivet::_emitOutput] [info body ::minirivet::_emitOutput]]
2b7fa3a8fa 2019-09-20   88: 		puts ""
f09ab16ca1 2019-05-08   89: 		puts [read [open $xvfs_tcl]]
f09ab16ca1 2019-05-08   90: 		puts ""
2b7fa3a8fa 2019-09-20   91: 		puts {set ::xvfs::argv $::argv}
2b7fa3a8fa 2019-09-20   92: 		puts {
2b7fa3a8fa 2019-09-20   93: 			foreach {arg val} $argv {
2b7fa3a8fa 2019-09-20   94: 				switch -exact -- $arg {
2b7fa3a8fa 2019-09-20   95: 					"--output" {
2b7fa3a8fa 2019-09-20   96: 						set ::minirivet::_outputChannel [open $val w]
2b7fa3a8fa 2019-09-20   97: 					}
2b7fa3a8fa 2019-09-20   98: 				}
2b7fa3a8fa 2019-09-20   99: 			}
2b7fa3a8fa 2019-09-20  100: 		}
2b7fa3a8fa 2019-09-20  101: 		puts ""
2b7fa3a8fa 2019-09-20  102: 		puts [list ::minirivet::_emitOutput $core_header_data]
2b7fa3a8fa 2019-09-20  103: 		puts ""
2b7fa3a8fa 2019-09-20  104: 
7664854ef9 2019-05-08  105: 		puts ""
7664854ef9 2019-05-08  106: 		puts [string map $cleanup [::minirivet::parseStringToCode [read [open $template]]]]
f09ab16ca1 2019-05-08  107: 	}
f09ab16ca1 2019-05-08  108: 	default {
f09ab16ca1 2019-05-08  109: 		puts stderr "error: Invalid mode: $mode"
f09ab16ca1 2019-05-08  110: 		exit 1
f09ab16ca1 2019-05-08  111: 	}
f09ab16ca1 2019-05-08  112: }