3 # (c) Josua Dietze 2012
5 # Usage: make_string.tcl source.tcl >jim-source.c
7 # Converts a Tcl source file into C source suitable
8 # for using as an embedded script.
10 set source [lindex $argv 0]
12 if {![string match
*.tcl
$source]} {
13 error "Source $source is not a .tcl file"
16 # Read the Tcl source and convert to C macro
19 while {[gets $f buf
] >= 0} {
20 # Remove comment lines
21 regsub {^
[ \t]*#.*$} $buf "" buf
22 # Remove leading whitespaces
23 set buf
[string trimleft
$buf]
24 # Escape quotes and backlashes
25 set buf
[string map
[list \\ \\\\ \" \\"] $buf]
26 if [string length $buf] {
27 lappend sourcelines "$buf\\n
"
31 puts "#define RAW \"[join $sourcelines ""]\""