beta-0.89.2
[luatex.git] / source / texk / web2c / web2c / makecpool.c
blobbf401c3ee72980c3dc50cd496f43be6799b99c05
1 /* Copyright 2007, 2008 Taco Hoekwater.
2 You may freely use, modify and/or distribute this file. */
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
8 #ifdef WIN32
9 #include <io.h>
10 #include <fcntl.h>
11 #endif
13 static const char __svn_version[] =
14 "$Id: makecpool.c 1230 2008-05-03 11:11:32Z oneiros $ $URL: svn://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/makecpool.c $";
16 int main(int argc, char *argv[])
18 char filename[20];
19 FILE *fh;
20 char data[1024];
21 int is_metafont = 0;
22 int is_luatex = 0;
24 #ifdef WIN32
25 setmode(fileno(stdout), _O_BINARY);
26 #endif
27 if (argc != 2) {
28 fprintf(stderr,
29 "%s: need exactly one argument (base name).\n",
30 argv[0]);
31 exit(EXIT_FAILURE);
33 strcpy(filename, argv[1]);
34 strcat(filename, ".pool");
35 fh = fopen(filename, "r");
36 if (!fh) {
37 fprintf(stderr, "%s: can't open %s for reading.\n", argv[0], filename);
38 exit(EXIT_FAILURE);
40 if (strstr(filename, "luatex.pool") != NULL)
41 is_luatex = 1;
42 else if (strstr(filename, "mf.pool") != NULL)
43 is_metafont = 1;
44 printf("/*\n"
45 " * This file is auto-generated by makecpool.\n"
46 " * %s %s\n"
47 " */\n"
48 "\n"
49 "#define EXTERN extern\n"
50 "#include \"%sd.h\"\n"
51 "#include <stdio.h>\n"
52 "#include <string.h>\n"
53 "\n"
54 "static const char *poolfilearr[] = {\n", argv[0], argv[1], argv[1]);
55 while (fgets(data, 1024, fh)) {
56 int i;
57 int len = strlen(data);
58 int o = 0; /* skip first bytes */
59 if (data[len - 1] == '\n') {
60 data[len - 1] = 0;
61 len--;
63 if (data[0] == '*')
64 break;
65 if (data[0] >= '0' && data[0] <= '9' && data[1] >= '0'
66 && data[1] <= '9') {
67 o = 2;
69 printf(" \"");
70 for (i = o; i < len; i++) {
71 if (data[i] == '"' || data[i] == '\\')
72 putchar('\\');
73 if (data[i] == '?')
74 printf("\" \""); /* suppress trigraphs */
75 putchar(data[i]);
77 printf("\",\n");
79 fclose(fh);
80 printf(" NULL };\n"
81 "int loadpoolstrings (integer spare_size) {\n"
82 " const char *s;\n"
83 " strnumber g=0;\n"
84 " int i=0,j=0;\n"
85 " while ((s = poolfilearr[j++])) {\n"
86 " int l = strlen (s);\n"
87 " i += l;\n" " if (i>=spare_size) return 0;\n");
88 if (is_luatex)
89 printf(" while (l-- > 0) str_pool[pool_ptr++] = *s++;\n"
90 " g = make_string();\n");
91 else
92 printf(" while (l-- > 0) strpool[poolptr++] = *s++;\n"
93 " g = makestring();\n");
94 if (is_metafont)
95 printf(" strref[g]= 127;\n");
96 printf(" }\n" " return g;\n" "}\n");
97 return EXIT_SUCCESS;