Menu

[7c54b3]: / joe / stringify.c  Maximize  Restore  History

Download this file

83 lines (80 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Convert files into a C strings */
/* Use to create built in rc and .jsf files in JOE with: ./stringify ../rc/ *rc ../syntax/ *.jsf >builtins.c */
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int x;
int first_file = 1;
printf("/* Built-in files */\n");
printf("\n");
printf("#include \"types.h\"\n");
printf("\n");
printf("char *builtins[]=\n");
printf("{\n");
for (x = 1; argv[x]; ++x) {
int c;
int instring = 0;
int first_string = 1;
size_t z;
int type;
FILE *f;
f = fopen(argv[x], "r");
if (!f) {
fprintf(stderr, "Couldn't open file '%s'\n", argv[x]);
return -1;
}
for (z = strlen(argv[x]); z && argv[x][z - 1] != '/'; --z);
if (first_file) {
printf(" \"%s\",\n", argv[x] + z);
first_file = 0;
} else
printf(", \"%s\",\n", argv[x] + z);
if (strstr(argv[x] + z, ".jsf"))
type = 1; /* .jsf file: delete # comments */
else
type = 0; /* rc file: delete SPACE comments */
while ((c = fgetc(f)) != -1) {
if (!instring) {
if ((type && c == '#') || (!type && (c == ' ' || c == '\t' || c == '\n'))) {
do
if (c == '\n')
break;
while ((c = fgetc(f)) != -1);
continue;
}
if (first_string) {
printf(" \"");
first_string = 0;
} else
printf(" \"");
instring = 1;
}
if (c == '"')
printf("\\\"");
else if (c == '\\')
printf("\\\\");
else if (c == '\n')
printf("\\n");
else if ((c >= 32 && c <= 126) || c == '\t')
putchar(c);
else
printf("\\x%2.2x", c);
if (c == '\n') {
printf("\"\n");
instring = 0;
}
}
if (instring) {
printf("\"\n");
instring = 0;
}
fclose(f);
}
if (first_file)
printf(" NULL\n");
else
printf(", NULL\n");
printf("};\n");
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.