diff options
author | stanton <stanton> | 1998-09-21 23:39:52 (GMT) |
---|---|---|
committer | stanton <stanton> | 1998-09-21 23:39:52 (GMT) |
commit | 494c2de3a748b449c69ce322a1a741f5a31fd4d5 (patch) | |
tree | c3ece48c0ae3f4ba54787e0e8e729b65752ef3f9 /tools/str2c | |
parent | 7a698c0488d99c0af42022714638ae1ba2afaa49 (diff) | |
download | tcl-494c2de3a748b449c69ce322a1a741f5a31fd4d5.zip tcl-494c2de3a748b449c69ce322a1a741f5a31fd4d5.tar.gz tcl-494c2de3a748b449c69ce322a1a741f5a31fd4d5.tar.bz2 |
Added contents of Tcl 8.1a2
Diffstat (limited to 'tools/str2c')
-rw-r--r-- | tools/str2c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/str2c b/tools/str2c new file mode 100644 index 0000000..bb7464d --- /dev/null +++ b/tools/str2c @@ -0,0 +1,61 @@ +#! /bin/sh +# +# Transform text (.ps, .tcl,...) into a C string +# +# 1997/10 -- dl +# +# $Id: str2c,v 1.1.2.1 1998/09/21 23:40:57 stanton Exp $ +# +# restart with tclsh \ +exec tclsh8.0 "$0" "$@" + +# Max string length +# (some C compiler have a 2048 chars limits (so 2047 real chars with +# the tariling 0) so we use 2000 to make the count nice) +set MAX 2000 + +if {$argc} { + puts stderr "Usage: [file tail [info script]] < text > text.c" + exit 1 +} + +set r [read stdin] + +proc translate {what} { + regsub -all {\\} $what {\\\\} what + regsub -all {"} $what {\\"} what + regsub -all "\n" $what "\\\\n\\\\\n" what; + return $what; +} + +set lg [string length $r] +if {$lg<$MAX} { + puts "/* + * Single part writeable string generated by str2c + */ +static char data\[\]=\"[translate $r]\";" +} else { + puts "/* + * Multi parts read only string generated by str2c + */ +static CONST char * CONST data\[\]= {" + set n 1 + for {set i 0} {$i<$lg} {incr i $MAX} { + set part [string range $r $i [expr $i+$MAX-1]] + set len [string length $part]; + puts "\t/* Start of part $n ($len characters) */" + puts "\t\"[translate $part]\"," + puts "\t/* End of part $n */\n" + incr n + } + puts "\tNULL\t/* End of data marker */\n};" + puts "\n/* use for instance with: + CONST char * CONST *chunk; + for (chunk=data; *chunk; chunk++) { + Tcl_AppendResult(interp, *chunk, (char *) NULL); + } +*/" +} + + + |