1 /* program DATABASE.C */
9 static char oline
[256];
11 _PROTOTYPE(void rdupto
, (FILE *, int, int, char *));
12 _PROTOTYPE(void rdskip
, (FILE *, int, int));
15 Function to scan a file up to a specified
16 point and either print or return a string.
18 void rdupto(fdi
, uptoc
, print
, string
)
24 static _CONST
unsigned char key
[4] = {'c' | 0x80, 'L' | 0x80,
25 'y' | 0x80, 'D' | 0x80};
28 while ((c
= getc(fdi
)) != uptoc
&& c
!= EOF
) {
46 Function to read a file skipping
47 a given character a specified number
48 of times, with or without repositioning
51 void rdskip(fdi
, skipc
, n
)
58 while ((c
= getc(fdi
)) != skipc
)
65 Routine to request a yes or no answer to a question.
67 boolean
yes(msg1
, msg2
, msg3
)
70 char answer
[INPUTBUFLEN
];
75 switch (*ask("\n> ", answer
, sizeof(answer
))) {
87 fputs("Please answer Y (yes) or N (no).", stdout
);
93 Print a location description from "advent4.txt"
101 fseek(fd4
, idx4
[msg
- 1], 0);
102 rdupto(fd4
, '#', 1, 0);
108 Print an item message for a given state from "advent3.txt"
110 void pspeak(item
, state
)
113 fseek(fd3
, idx3
[item
- 1], 0);
114 rdskip(fd3
, '/', state
+ 2);
115 rdupto(fd3
, '/', FALSE
, oline
);
116 if (strncmp(oline
, "<$$<", 4) != 0)
122 Print a long location description from "advent1.txt"
127 fseek(fd1
, idx1
[loc
- 1], 0);
128 rdupto(fd1
, '#', 1, 0);
133 Print a short location description from "advent2.txt"
138 fseek(fd2
, idx2
[loc
- 1], 0);
139 rdupto(fd2
, '#', 1, 0);