summaryrefslogtreecommitdiffstats
path: root/tcl8.6/tools/str2c
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2017-09-22 18:57:19 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2017-09-22 18:57:19 (GMT)
commit2aff4a96fa0286d875bddec0019648e2c6431cbc (patch)
treef7a9a4800a3f3ad4b77470b8383529176d8b7181 /tcl8.6/tools/str2c
parent3fa8e6dc88e8041b6cb88d1b1e9c05676d3346b7 (diff)
parent29ccecd87709feda60d191f6aaba324ccad91f55 (diff)
downloadblt-2aff4a96fa0286d875bddec0019648e2c6431cbc.zip
blt-2aff4a96fa0286d875bddec0019648e2c6431cbc.tar.gz
blt-2aff4a96fa0286d875bddec0019648e2c6431cbc.tar.bz2
Merge commit '29ccecd87709feda60d191f6aaba324ccad91f55' 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);
+ }
+*/"
+}
+
+
+