210 |
return strbuf_value(sb); |
return strbuf_value(sb); |
211 |
} |
} |
212 |
/* |
/* |
213 |
|
* Load text from file with replacing @PARENT_DIR@ macro. |
214 |
|
* Macro @PARENT_DIR@ is replaced with the parent directory |
215 |
|
* of the 'HTML' directory. |
216 |
|
*/ |
217 |
|
static const char * |
218 |
|
sed(ip, place) |
219 |
|
FILE *ip; |
220 |
|
int place; |
221 |
|
{ |
222 |
|
STATIC_STRBUF(sb); |
223 |
|
const char *parent_dir = (place == SUBDIR) ? "../.." : ".."; |
224 |
|
int c, start_position = -1; |
225 |
|
|
226 |
|
strbuf_clear(sb); |
227 |
|
while ((c = fgetc(ip)) != EOF) { |
228 |
|
strbuf_putc(sb, c); |
229 |
|
if (c == '@') { |
230 |
|
int curpos = strbuf_getlen(sb); |
231 |
|
if (start_position == -1) { |
232 |
|
start_position = curpos - 1; |
233 |
|
} else { |
234 |
|
if (!strncmp("@PARENT_DIR@", |
235 |
|
strbuf_value(sb) + start_position, |
236 |
|
curpos - start_position)) |
237 |
|
{ |
238 |
|
strbuf_setlen(sb, start_position); |
239 |
|
strbuf_puts(sb, parent_dir); |
240 |
|
start_position = -1; |
241 |
|
} else { |
242 |
|
start_position = curpos - 1; |
243 |
|
} |
244 |
|
} |
245 |
|
} else if (!isalpha(c) && c != '_') { |
246 |
|
if (start_position != -1) |
247 |
|
start_position = -1; |
248 |
|
} |
249 |
|
} |
250 |
|
return strbuf_value(sb); |
251 |
|
} |
252 |
|
/* |
253 |
|
* Generate custom header. |
254 |
|
*/ |
255 |
|
const char * |
256 |
|
gen_insert_header(place) |
257 |
|
int place; |
258 |
|
{ |
259 |
|
static FILE *ip; |
260 |
|
|
261 |
|
if (ip != NULL) { |
262 |
|
rewind(ip); |
263 |
|
} else { |
264 |
|
ip = fopen(insert_header, "r"); |
265 |
|
if (ip == NULL) |
266 |
|
die("cannot open include header file '%s'.", insert_header); |
267 |
|
} |
268 |
|
return sed(ip, place); |
269 |
|
} |
270 |
|
/* |
271 |
|
* Generate custom footer. |
272 |
|
*/ |
273 |
|
const char * |
274 |
|
gen_insert_footer(place) |
275 |
|
int place; |
276 |
|
{ |
277 |
|
static FILE *ip; |
278 |
|
|
279 |
|
if (ip != NULL) { |
280 |
|
rewind(ip); |
281 |
|
} else { |
282 |
|
ip = fopen(insert_footer, "r"); |
283 |
|
if (ip == NULL) |
284 |
|
die("cannot open include footer file '%s'.", insert_footer); |
285 |
|
} |
286 |
|
return sed(ip, place); |
287 |
|
} |
288 |
|
/* |
289 |
* Generate beginning of page |
* Generate beginning of page |
290 |
* |
* |
291 |
* i) title title of this page |
* i) title title of this page |