00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <sys/types.h>
00021 #include <unistd.h>
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #define MAX_LINE_SIZE 256
00025
00026 static char buf[MAX_LINE_SIZE];
00027
00028 int main(argc,argv)
00029 int argc;
00030 char *argv[];
00031 {
00032 char *lispfn, cfn[128], hfn[128], tempfn[128], catcom[256], entryname[128];
00033 FILE *in, *out;
00034 char *s, *d, ch;
00035 int i,j,k, string_count;
00036
00037 lispfn=argv[1];
00038 sprintf(tempfn, "/tmp/%s.c.%d", lispfn, getpid());
00039 sprintf(cfn, "%s.c", lispfn);
00040 sprintf(hfn, "/tmp/%s.h.%d", lispfn, getpid());
00041 in=fopen(lispfn, "r");
00042 out=fopen(tempfn, "w");
00043
00044
00045 s=lispfn; d=entryname;
00046 while (*s != '.' && *s != 0) *d++ = *s++;
00047 *d = 0;
00048
00049 fprintf(out, "/* %s: c-converted lisp source of %s */\n", lispfn, cfn);
00050 fprintf(out, "#include \"eus.h\"\n");
00051 #ifndef alpha
00052 fprintf(out, "#pragma init (init_object_module)\n");
00053 #endif
00054 #if 0
00055 fprintf(out, "extern void eval_c_strings();\n");
00056 fprintf(out, "extern void add_module_initializer();\n");
00057 #endif
00058 fprintf(out, "extern void %s();\n", entryname);
00059 fprintf(out, "static void init_object_module()\n");
00060 fprintf(out, " {add_module_initializer(\"%s\", (pointer (*)())%s);}\n", entryname, entryname);
00061 fprintf(out, "const static char *sexp_strings[NUM_LINES]={\n");
00062
00063 string_count=1;
00064
00065 s=(char *)fgets(buf, MAX_LINE_SIZE, in);
00066 while (s!=NULL) {
00067 k=strlen(s);
00068 fputc('\"', out);
00069 while (ch= *s++) {
00070 if (ch=='\n') fputc(' ', out);
00071 else {
00072 if (ch=='\"' || ch=='\\') fputc('\\', out);
00073 fputc(ch, out);}
00074 }
00075 fprintf(out, "\",\n");
00076 s=fgets(buf, MAX_LINE_SIZE, in);
00077 string_count++;}
00078 fprintf(out, "\"\" };\n\n");
00079 fprintf(out, "void %s(ctx)\n", entryname);
00080 fprintf(out, "context *ctx;\n");
00081 fprintf(out, "{ eval_c_strings(ctx, NUM_LINES, sexp_strings);}\n");
00082
00083 fclose(in);
00084 fclose(out);
00085 out=fopen(hfn, "w");
00086 fprintf(out, "#define NUM_LINES %d\n", string_count);
00087 fclose(out);
00088 sprintf(catcom, "cat %s %s >%s ", hfn, tempfn, cfn);
00089 system(catcom);
00090 unlink(hfn); unlink(tempfn);
00091 exit(0);
00092 }
00093