#!/bin/sh
# convert a wish script to an initialized C string
# Modified 10/1/93 by sau@bellcore.com
# Modified 10/2/94 by jn@berlin.snafu.de

case $# in 
    0)	echo "usage: $0 c_variable_name file1 ..." 1>&2 ; exit 1 ;;
esac

var="initCmd"

echo /\* This file has been generated from the following Tcl source file\(s\): `echo $*`
echo ' * on '"`date` by $USER"
echo ' */'
echo '#include <tcl.h>'
echo 'static char initCmd[] = '

# Transformations applied to each line of the file:
#       eliminate lines that are only comments
#       Convert preexisting backslash into double backslash.
#       Precede preexisting double quote (") with backslash.
#	Add double quote to the beginning of the line.
#       Add backslash, n, double quote to the end of the line.
    
cat $* |
sed -e '/^[ 	]*#/d'	\
    -e 's/\\/\\\\/g'	\
    -e 's/"/\\\"/g'	\
    -e 's/$/\\n/'	\
    -e 's/^\(.*\)$/    "\1"/'
# Final line of transformed file:

echo '    ;
/* End of Tcl code */'

echo '/* Init routine to drag this code into our program...*/'
echo int `echo $* | sed 's/\.tcl/_Init/'` \(Tcl_Interp *interp\)
echo '{'
echo '    if (Tcl_Eval(interp,initCmd) != 0) {'
echo '    char *val;'
echo '    fprintf (stderr, "ERROR:\\n      %s\\n", interp->result);'
echo '    val = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);'
echo '    fprintf (stderr, "TclStack:\\n      %s\\n",val);'
echo '       return TCL_ERROR;'
echo '    }'
echo '    return TCL_OK;'
echo '}'
echo '/* End of C code */'
# We don't remove blank lines anymore, because this changes embedded
# text strings.

# EOF
