#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <assert.h>
#include <unistd.h>
char const Ccode [] =
"#include <stdio.h>\n"
"#include <stdlib.h>\n"
"#include <math.h>\n"
"#include <tcl.h>\n"
"#include <tk.h>\n"
"\n"
"#define TCLGO TCL_GLOBAL_ONLY\n"
;
char const Cmaincode [] =
" \n"
"main(int argc, char *argv[])\n"
"{\n"
" Tcl_Interp *interp;\n"
" Tk_Window mainWindow;\n"
" Tk_Window tkmain;\n"
" int error;\n"
" char *trace;\n"
" \n"
"/* first we create a Tcl interpreter */\n"
"\n"
" interp = Tcl_CreateInterp();\n"
" \n"
"/* now we create a Tk main window */\n"
" tkmain = Tk_MainWindow(interp); \n"
"\n"
" \n"
"/* now we initialize our interpreter for Tcl,Tk,and our personal\n"
" example C commands */\n"
"\n"
" if(Tcl_Init(interp) != TCL_OK) {\n"
" fprintf(stderr, \"Tcl_Init failed: %s\\n\", interp->result);\n"
" }\n"
" if(Tk_Init(interp) != TCL_OK) {\n"
" fprintf(stderr, \"Tk_Init failed: %s\\n\", interp->result);\n"
" }\n"
"\n"
"/* now we tell the interpreter which Tcl/Tk file to use */\n"
"\n"
" error = Tcl_Eval(interp,tcl_script);\n"
" if(error != TCL_OK) {\n"
" fprintf(stderr, \"%s: %s\\n\", \"tcl_script\", interp->result);\n"
" trace = Tcl_GetVar(interp, \"errorInfo\", TCL_GLOBAL_ONLY);\n"
" if(trace != NULL) {\n"
" fprintf(stderr, \"*** TCL TRACE ***\\n\");\n"
" fprintf(stderr, \"%s\\n\", trace);\n"
" }\n"
" }\n"
"\n"
"/* finally we enter the event loop and wait for user input */\n"
"\n"
" Tk_MainLoop();\n"
"}\n"
"\n"
;
/* process tcl code and store it in const char */
ProcessTCL(const char* filename){
FILE *in;
char buf[1024];
char fix[1024];
char *ptr1, *ptr2;
int xor;
int c;
xor=14;
/* open the file */
in = fopen(filename, "r");
if (!in) {
perror("fopen"); exit(1);
}
printf("/* DO NOT EDIT THIS FILE.. it was generated by tcl2c */\n\n");
printf("static char tcl_script[] =\n");
*buf = 0;
while(fscanf(in, "%[^\n]", buf) != EOF) {
fgetc(in);
ptr1 = buf; ptr2 = fix;
while(*ptr1) {
if (*ptr1 == '\"') {
*ptr2++ = '\\';
*ptr2++ = '\"';
}
else if (*ptr1 == '\\') {
*ptr2++ = '\\';
*ptr2++ = '\\';
}
else {
*ptr2++ = *ptr1;
}
ptr1++;
}
*ptr2 = *ptr1;
*buf = 0;
}
printf(";\n");
}
int main(int argc, char **argv){
char input[200]; /* input tcl filename*/
int shroud = 0; /* True to encrypt the compiled-in TCL */
/* C code to use tcl file */
/* check cmd line parameters */
if ( argc < 2 )
{
printf("USAGE: %s arg1\n",argv[0]);
printf("arg1:input tcl file\n");
exit(1);
}
else
{
printf("%s\n",Ccode);
printf("\n");
/* process the tcl file */
ProcessTCL(argv[1]);
printf("%s\n",Cmaincode);
}
}