gccls.c
Go to the documentation of this file.
00001 /*
00002 /* gccls.c
00003 /*
00004 /*      % gccls lisp-file
00005 /*      Generate-C-Converted-Lisp-Source
00006 /*      convert a lisp source code into C which is interpretedly
00007 /*      executed by Euslisp when it is compiled (by cc) and linked.
00008 /*      Though some lisp source programs, e.g. l/constants.l, must be 
00009 /*      loaded during the make procedure, it is hard to locate the
00010 /*      file since no file handling functions are available.
00011 /*      Genlispexec converts "constants.l" into "constants.l.c"
00012 /*      which should be compiled by 'cc'. The resulted "constants.l.o"
00013 /*      may be linked with eus, which then interprets the same program
00014 /*      as defined in "constants.l".
00015 /*
00016 /*      May 1994, (c) Toshihiro Matsui, Electrotechnical Laboratory
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 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   /* extract basename from lispfn and place it in entryname */
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 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 


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Mar 9 2017 04:57:49