| 1 |
void _remakebuiltins(list files, string builtinsDef) |
| 2 |
{ |
| 3 |
string file; |
| 4 |
string dest; |
| 5 |
int cid; |
| 6 |
int idx; |
| 7 |
string gramH; |
| 8 |
|
| 9 |
gramH = g_wip + "/gram.h"; |
| 10 |
|
| 11 |
printf("rebuilding " + builtinsDef + " and " + gramH + "\n"); |
| 12 |
|
| 13 |
run("rm -f " + gramH + " " + builtinsDef); |
| 14 |
|
| 15 |
fprintf(gramH, |
| 16 |
"#ifndef GRAM_H_\n", |
| 17 |
"#define GRAM_H_\n" |
| 18 |
"/*\n" |
| 19 |
" Automatically generated by build\n" |
| 20 |
" Do not edit\n" |
| 21 |
"*/\n" |
| 22 |
); |
| 23 |
|
| 24 |
fprintf(builtinsDef, |
| 25 |
"/*\n" |
| 26 |
" Automatically generated by build\n" |
| 27 |
" Do not edit\n" |
| 28 |
"*/\n" |
| 29 |
"#include \"gram.h\"\n" |
| 30 |
"Builtin builtin_array[] = \n" |
| 31 |
"{\n" |
| 32 |
); |
| 33 |
|
| 34 |
for (idx = 0; idx < listlen(files); idx++) |
| 35 |
{ |
| 36 |
dest = ""; |
| 37 |
file = change_ext(files[idx], ""); |
| 38 |
for (cid = 4; cid < strlen(file); cid++) |
| 39 |
dest += file[cid]; |
| 40 |
dest = strupr(dest); |
| 41 |
|
| 42 |
fprintf(gramH, " void gram_", dest, "(void);\n"); |
| 43 |
fprintf(builtinsDef, |
| 44 |
" {\"", dest, "\", gram_", dest, " },\n"); |
| 45 |
} |
| 46 |
|
| 47 |
fprintf(gramH, "#endif\n"); |
| 48 |
fprintf(builtinsDef, |
| 49 |
" { 0, 0 }\n" |
| 50 |
"};\n"); |
| 51 |
} |
| 52 |
|
| 53 |
void buildBuiltins() |
| 54 |
{ |
| 55 |
string file; |
| 56 |
list files; |
| 57 |
int idx; |
| 58 |
string builtinsDef; |
| 59 |
|
| 60 |
builtinsDef = g_wip + "/builtins.def"; |
| 61 |
|
| 62 |
chdir("yodl"); |
| 63 |
files = makelist("gram*.c"); |
| 64 |
chdir(g_cwd); |
| 65 |
|
| 66 |
for (idx = 0; idx < listlen(files); idx++) |
| 67 |
{ |
| 68 |
file = files[idx]; |
| 69 |
if ("yodl/" + file younger builtinsDef) |
| 70 |
{ |
| 71 |
_remakebuiltins(files, builtinsDef); |
| 72 |
break; |
| 73 |
} |
| 74 |
} |
| 75 |
} |