summaryrefslogtreecommitdiffstats
path: root/tools/str2c
diff options
context:
space:
mode:
authorstanton <stanton>1999-04-16 00:46:29 (GMT)
committerstanton <stanton>1999-04-16 00:46:29 (GMT)
commit97464e6cba8eb0008cf2727c15718671992b913f (patch)
treece9959f2747257d98d52ec8d18bf3b0de99b9535 /tools/str2c
parenta8c96ddb94d1483a9de5e340b740cb74ef6cafa7 (diff)
downloadtcl-97464e6cba8eb0008cf2727c15718671992b913f.zip
tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.gz
tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.bz2
merged tcl 8.1 branch back into the main trunk
Diffstat (limited to 'tools/str2c')
-rw-r--r--tools/str2c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/str2c b/tools/str2c
new file mode 100644
index 0000000..15cb8e6
--- /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.2 1999/04/16 00:47:40 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);
+ }
+*/"
+}
+
+
+