libsodium: updated to 1.0.10
[tomato.git] / release / src / router / usbmodeswitch / make_string.tcl
blob5a1b5ff18b21f97395e6cf19fe0e6f0a180f1789
1 #!/usr/bin/env tclsh
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
17 set sourcelines {}
18 set f [open $source]
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"
30 close $f
31 puts "#define RAW \"[join $sourcelines ""]\""