summaryrefslogtreecommitdiffstats
path: root/tcl8.6/tools/str2c
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-18 17:31:11 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-18 17:31:11 (GMT)
commit066971b1e6e77991d9161bb0216a63ba94ea04f9 (patch)
tree6de02f79b7a4bb08a329581aa67b444fb9001bfd /tcl8.6/tools/str2c
parentba065c2de121da1c1dfddd0aa587d10e7e150f05 (diff)
parent9966985d896629eede849a84f18e406d1164a16c (diff)
downloadblt-066971b1e6e77991d9161bb0216a63ba94ea04f9.zip
blt-066971b1e6e77991d9161bb0216a63ba94ea04f9.tar.gz
blt-066971b1e6e77991d9161bb0216a63ba94ea04f9.tar.bz2
Merge commit '9966985d896629eede849a84f18e406d1164a16c' as 'tcl8.6'
Diffstat (limited to 'tcl8.6/tools/str2c')
-rw-r--r--tcl8.6/tools/str2c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tcl8.6/tools/str2c b/tcl8.6/tools/str2c
new file mode 100644
index 0000000..cff7ba2
--- /dev/null
+++ b/tcl8.6/tools/str2c
@@ -0,0 +1,59 @@
+#! /bin/sh
+#
+# Transform text (.ps, .tcl,...) into a C string
+#
+# 1997/10 -- dl
+#
+# restart with tclsh \
+exec tclsh "$0" ${1+"$@"}
+
+# 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);
+ }
+*/"
+}
+
+
+