#!/bin/sh # # Convert a tcl script into a C string to be #included # #\ exec tclsh "$0" "$@" if {$argc != 2} { puts "usage: $argv0 file.tclc file.h" exit 1 } set source [lindex $argv 0] set output [lindex $argv 1] proc makeSubs {line} { global strname upvar $line ln regsub -all -- {\\} $ln {\\\\} ln regsub -all -- {\"} $ln \\\" ln } set inf [open $source r] set cstrings [read $inf] close $inf set outf [open $output w] foreach {cs val} $cstrings { puts "translating $cs" flush stdout puts -nonewline $outf "char $cs\[\] = " makeSubs val set nl "" foreach line [split $val \n] { if {($line == "") || [regexp {^#} $line]} { continue } puts -nonewline $outf "$nl\"$line\\n\"" set nl \n } puts $outf ";\n" } close $outf