Check-in [dbb450841d]
Overview
Comment:Updated to support very basic processing of the command-line
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:dbb450841da8050c38aefd368160471b5b42a105
User & Date: rkeene on 2017-10-13 19:56:05
Other Links: manifest | tags
Context
2017-10-13
19:59
Fixed typo and added test for process_command_line check-in: 6641266e0b user: rkeene tags: trunk
19:56
Updated to support very basic processing of the command-line check-in: dbb450841d user: rkeene tags: trunk
17:59
Updated not produce an error if we cannot load the tcc4tcl shared object since it is possible to use the Tcl-only portion check-in: d1b6ddb9a1 user: rkeene tags: trunk
Changes

Modified tcc4tcl.tcl from [a5b9327e8f] to [98a17dca0c].

    42     42   			if {$pkgName == ""} {
    43     43   				set type "exe"
    44     44   			} else {
    45     45   				set type "package"
    46     46   			}
    47     47   		}
    48     48   
    49         -		array set $handle [list code "" type $type filename $output package $pkgName add_inc_path "" add_lib_path "" add_lib ""]
           49  +		array set $handle [list code "" type $type filename $output package $pkgName add_inc_path "" add_lib_path "" add_lib "" add_macros ""]
    50     50   
    51     51   		proc $handle {cmd args} [string map [list @@HANDLE@@ $handle] {
    52     52   			set handle {@@HANDLE@@}
    53     53   
    54     54   			if {$cmd == "go"} {
    55     55   				set args [list 0 {*}$args]
    56     56   			}
................................................................................
    59     59   				set cmd "go"
    60     60   				set args [list 1 {*}$args]
    61     61   			}
    62     62   
    63     63   			set callcmd ::tcc4tcl::_$cmd
    64     64   
    65     65   			if {[info command $callcmd] == ""} {
    66         -				return -code error "unknown or ambiguous subcommand \"$cmd\": must be cwrap, ccode, cproc, ccommand, delete, linktclcommand, code, tk, add_include_path, add_library_path, add_library, or go"
           66  +				return -code error "unknown or ambiguous subcommand \"$cmd\": must be cwrap, ccode, cproc, ccommand, delete, linktclcommand, code, tk, add_include_path, add_library_path, add_library, process_command_line, or go"
    67     67   			}
    68     68   
    69     69   			uplevel 1 [list $callcmd $handle {*}$args]
    70     70   		}]
    71     71   
    72     72   		return $handle
    73     73   	}
................................................................................
   154    154   	}
   155    155   
   156    156   	proc _tk {handle} {
   157    157   		upvar #0 $handle state
   158    158   
   159    159   		set state(tk) 1
   160    160   	}
          161  +
          162  +	proc _process_command_line {handle cmdStr} {
          163  +		# XXX:TODO: This needs to handle shell-quoted arguments
          164  +		upvar #0 $handle state
          165  +		set cmdStr [regsub -all {   *} $cmdStr { }]
          166  +		set work [split $cmdStr " "]
          167  +
          168  +		foreach arg $work {
          169  +			switch -glob -- $arg {
          170  +				"-I*" {
          171  +					set dir [string range $cmd 2 end]
          172  +					_add_include_path $handle $dir
          173  +				}
          174  +				"-D*" {
          175  +					set symbolval [string range $cmd 2 end]
          176  +					set symbolval [split $symbolval =]
          177  +					set symbol [lindex $symbolval 0]
          178  +					set val    [join [lrange $symbolval 1 end] =]
          179  +
          180  +					dict set state(add_macros) $symbol $val
          181  +				}
          182  +				"-U*" {
          183  +					set symbol [string range $cmd 2 end]
          184  +					dict unset state(add_macros) $symbol $val
          185  +				}
          186  +				"-l*" {
          187  +					set library [string range $cmd 2 end]
          188  +					_add_library $handle $library
          189  +				}
          190  +				"-L*" {
          191  +					set libraryDir [string range $cmd 2 end]
          192  +					_add_library_path $handle $libraryDir
          193  +				}
          194  +				"-g" {
          195  +					# Ignored
          196  +				}
          197  +			}
          198  +		}
          199  +	}
   161    200   
   162    201   	proc _delete {handle} {
   163    202   		rename $handle ""
   164    203   		unset $handle
   165    204   	}
   166    205   
   167    206   	proc _proc {handle cname adefs rtype body args} {
................................................................................
   419    458   	}
   420    459   
   421    460   	proc _go {handle {outputOnly 0}} {
   422    461   		variable dir
   423    462   
   424    463   		upvar #0 $handle state
   425    464   
   426         -		set code $state(code)
          465  +		set code ""
          466  +
          467  +		foreach {macroName macroVal} $state(add_macros) {
          468  +			append code "#define [string trim "$macroName $macroVal"]\n"
          469  +		}
          470  +
          471  +		append code $state(code) "\n"
   427    472   
   428    473   		if {$state(type) == "exe" || $state(type) == "dll"} {
   429    474   			if {[info exists state(procs)] && [llength $state(procs)] > 0} {
   430    475   				set code "int _initProcs(Tcl_Interp *interp);\n\n$code"
   431    476   			}
   432    477   		}
   433    478