• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/usb-modeswitch-2.2.3/
1#!/usr/bin/env tclsh
2
3# (c) Josua Dietze 2012
4#
5# Usage: make_string.tcl source.tcl >jim-source.c
6
7# Converts a Tcl source file into C source suitable
8# for using as an embedded script.
9
10set source [lindex $argv 0]
11
12if {![string match *.tcl $source]} {
13	error "Source $source is not a .tcl file"
14}
15
16# Read the Tcl source and convert to C macro
17set sourcelines {}
18set f [open $source]
19while {[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"
28	}
29}
30close $f
31puts "#define RAW \"[join $sourcelines ""]\""
32