2 * execution will read the four adventure text files *
3 * files; "advent1.txt", "advent2.txt", "advent3.txt" & *
4 * "advent4.txt". it will create the file "advtext.h" *
5 * which is an Index Sequential Access Method (ISAM) *
6 * header to be #included into "advent.c" before the *
7 * header "advdec.h" is #included. */
14 _PROTOTYPE(int main
, (void));
15 _PROTOTYPE(void file_error
, (char *));
16 _PROTOTYPE(void encode
, (unsigned char *));
21 FILE *isam
, *src
, *dest
;
26 static char *headername
[] = {
27 "idx1[MAXLOC]", "idx2[MAXLOC]", "idx3[MAXOBJ]", "idx4[MAXMSG]",
30 long x29
= (1L << 29), x30
= (1L << 30);
31 if (!(x30
/ 2 == x29
&& 0L < x30
&& x29
< x30
)) {
32 fprintf(stderr
, "Sorry, advent needs 32-bit `long int's.\n");
35 isam
= fopen("advtext.h", "w");
37 fprintf(stderr
, "Sorry, I can't open advtext.h...\n");
40 fprintf(isam
, "\n/*\theader: ADVTEXT.H\t\t\t\t\t*/\n\n\n");
42 for (i
= 1; i
<= 4; i
++) {
45 sprintf(filename
, "advent%d.txt", i
);
46 src
= fopen(filename
, "r");
49 sprintf(filename
, "advent%d.dat", i
);
50 dest
= fopen(filename
, "w");
53 fprintf(isam
, "long\t%s = {\n\t", headername
[i
- 1]);
54 while (fgets(itxt
, 255, src
)) {
55 encode((unsigned char *) itxt
);
56 if (fprintf(dest
, "%s\n", itxt
) == EOF
)
60 fprintf(isam
, "%ld,%s\t", llen
,
61 &"\0\0\0\0\0\0\0\n"[++cnt
& 7]);
64 fprintf(stderr
, "ftell err in %s\n", filename
);
69 if (fprintf(isam
, "%ld\n\t};\n\n", llen
) == EOF
)
70 file_error("advtext.h");
72 if (fclose(dest
) == EOF
)
76 if (fclose(isam
) == EOF
)
77 file_error("advtext.h");
81 void file_error(filename
)
88 _CONST
unsigned char key
[4] = {'c' | 0x80, 'L' | 0x80, 'y' | 0x80, 'D' | 0x80};
95 for (i
= 1; msg
[i
]; i
++)