gccls.c
Go to the documentation of this file.
1 /*
2 /* gccls.c
3 /*
4 /* % gccls lisp-file
5 /* Generate-C-Converted-Lisp-Source
6 /* convert a lisp source code into C which is interpretedly
7 /* executed by Euslisp when it is compiled (by cc) and linked.
8 /* Though some lisp source programs, e.g. l/constants.l, must be
9 /* loaded during the make procedure, it is hard to locate the
10 /* file since no file handling functions are available.
11 /* Genlispexec converts "constants.l" into "constants.l.c"
12 /* which should be compiled by 'cc'. The resulted "constants.l.o"
13 /* may be linked with eus, which then interprets the same program
14 /* as defined in "constants.l".
15 /*
16 /* May 1994, (c) Toshihiro Matsui, Electrotechnical Laboratory
17 */
18 
19 #include <stdio.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #define MAX_LINE_SIZE 256
25 
26 static char buf[MAX_LINE_SIZE];
27 
28 int main(argc,argv)
29 int argc;
30 char *argv[];
31 {
32  char *lispfn, cfn[128], hfn[128], tempfn[128], catcom[256], entryname[128];
33  FILE *in, *out;
34  char *s, *d, ch;
35  int i,j,k, string_count;
36 
37  lispfn=argv[1];
38  sprintf(tempfn, "/tmp/%s.c.%d", lispfn, getpid());
39  sprintf(cfn, "%s.c", lispfn);
40  sprintf(hfn, "/tmp/%s.h.%d", lispfn, getpid());
41  in=fopen(lispfn, "r");
42  out=fopen(tempfn, "w");
43 
44  /* extract basename from lispfn and place it in entryname */
45  s=lispfn; d=entryname;
46  while (*s != '.' && *s != 0) *d++ = *s++;
47  *d = 0;
48 
49  fprintf(out, "/* %s: c-converted lisp source of %s */\n", lispfn, cfn);
50  fprintf(out, "#include \"eus.h\"\n");
51 #ifndef alpha
52  fprintf(out, "#pragma init (init_object_module)\n");
53 #endif
54 #if 0
55  fprintf(out, "extern void eval_c_strings();\n");
56  fprintf(out, "extern void add_module_initializer();\n");
57 #endif
58  fprintf(out, "extern void %s();\n", entryname);
59  fprintf(out, "static void init_object_module()\n");
60  fprintf(out, " {add_module_initializer(\"%s\", (pointer (*)())%s);}\n", entryname, entryname);
61  fprintf(out, "const static char *sexp_strings[NUM_LINES]={\n");
62 
63  string_count=1;
64 
65  s=(char *)fgets(buf, MAX_LINE_SIZE, in);
66  while (s!=NULL) {
67  k=strlen(s);
68  fputc('\"', out);
69  while (ch= *s++) {
70  if (ch=='\n') fputc(' ', out);
71  else {
72  if (ch=='\"' || ch=='\\') fputc('\\', out);
73  fputc(ch, out);}
74  }
75  fprintf(out, "\",\n");
76  s=fgets(buf, MAX_LINE_SIZE, in);
77  string_count++;}
78  fprintf(out, "\"\" };\n\n");
79  fprintf(out, "void %s(ctx)\n", entryname);
80  fprintf(out, "context *ctx;\n");
81  fprintf(out, "{ eval_c_strings(ctx, NUM_LINES, sexp_strings);}\n");
82 
83  fclose(in);
84  fclose(out);
85  out=fopen(hfn, "w");
86  fprintf(out, "#define NUM_LINES %d\n", string_count);
87  fclose(out);
88  sprintf(catcom, "cat %s %s >%s ", hfn, tempfn, cfn);
89  system(catcom);
90  unlink(hfn); unlink(tempfn);
91  exit(0);
92  }
93 
d
int ch[MAXTHREAD]
Definition: eusstream.c:23
int main(int argc, argv)
Definition: gccls.c:28
static int argc
Definition: transargv.c:56
#define MAX_LINE_SIZE
Definition: gccls.c:24
static char buf[MAX_LINE_SIZE]
Definition: gccls.c:26
short s
Definition: structsize.c:2
#define NULL
Definition: transargv.c:8


euslisp
Author(s): Toshihiro Matsui
autogenerated on Fri Feb 21 2020 03:20:54