File: make_string.tcl

package info (click to toggle)
usb-modeswitch 1.2.3%2Brepack0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 304 kB
  • sloc: ansic: 1,616; tcl: 768; sh: 223; makefile: 134
file content (31 lines) | stat: -rwxr-xr-x 738 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env tclsh

# (c) Josua Dietze 2012
#
# Usage: mk_script_string.tcl source.tcl >jim-source.c

# Converts a Tcl source file into C source suitable
# for using as an embedded script.

set source [lindex $argv 0]

if {![string match *.tcl $source]} {
	error "Source $source is not a .tcl file"
}

# Read the Tcl source and convert to C macro
set sourcelines {}
set f [open $source]
while {[gets $f buf] >= 0} {
	# Remove comment lines
	regsub {^[ \t]*#.*$} $buf "" buf
	# Remove leading whitespaces
	set buf [string trimleft $buf]
	# Escape quotes and backlashes
	set buf [string map [list \\ \\\\ \" \\"] $buf]
	if [string length $buf] {
		lappend sourcelines "$buf\\n"
	}
}
close $f
puts "#define RAW \"[join $sourcelines ""]\""