/[CvsGraph]/cvsgraph/readconf.c
ViewVC logotype

Annotate of /cvsgraph/readconf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.24.4.1 - (show annotations)
Mon Nov 13 20:42:23 2006 UTC (11 years, 1 month ago) by bertho
Branch: automake-dev1
Changes since 1.24: +18 -18 lines
File MIME type: text/plain
Changes to use automake
1 /*
2 * CvsGraph graphical representation generator of brances and revisions
3 * of a file in cvs/rcs.
4 *
5 * Copyright (C) 2001,2002 B. Stultiens
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 /*#define DEBUG 1*/
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <ctype.h>
28 #include <assert.h>
29
30 #include <gd.h>
31 #include <gdfontt.h>
32 #include <gdfonts.h>
33 #include <gdfontmb.h>
34 #include <gdfontl.h>
35 #include <gdfontg.h>
36
37 #include "utils.h"
38 #include "cvsgraph.h"
39 #include "readconf.h"
40
41 int line_number;
42
43 typedef struct
44 {
45 const char *keyword;
46 int type;
47 union {
48 void *v; /* join of other values */
49 int *i;
50 font_t *f;
51 char **s;
52 color_t *c;
53 double *d;
54 stringlist_t *sl;
55 condstring_t *cs;
56 colorlist_t *cl;
57 int val;
58 } confref;
59 } keyword_t;
60
61 typedef union {
62 keyword_t *kw;
63 int i;
64 double d;
65 char *str;
66 } YYSTYPE;
67
68 static YYSTYPE yylval;
69
70 static int nstacked_opts;
71 static char **stacked_opts;
72
73 static keyword_t keywords[] = {
74 { "branch_bgcolor", TYPE_COLOR, { &conf.branch_bgcolor } },
75 { "branch_bspace", TYPE_NUMBER, { &conf.branch_bspace } },
76 { "branch_color", TYPE_COLOR, { &conf.branch_color } },
77 { "branch_font", TYPE_FONT, { &conf.branch_font.gdfont } },
78 { "branch_ttfont", TYPE_STRING, { &conf.branch_font.ttfont } },
79 { "branch_ttsize", TYPE_DOUBLE, { &conf.branch_font.ttsize } },
80 { "branch_tag_color", TYPE_COLOR, { &conf.branch_tag_color } },
81 { "branch_tag_font", TYPE_FONT, { &conf.branch_tag_font.gdfont } },
82 { "branch_tag_ttfont", TYPE_STRING, { &conf.branch_tag_font.ttfont } },
83 { "branch_tag_ttsize", TYPE_DOUBLE, { &conf.branch_tag_font.ttsize } },
84 { "branch_lspace", TYPE_NUMBER, { &conf.branch_lspace } },
85 { "branch_rspace", TYPE_NUMBER, { &conf.branch_rspace } },
86 { "branch_tspace", TYPE_NUMBER, { &conf.branch_tspace } },
87 { "branch_connect", TYPE_NUMBER, { &conf.branch_connect } },
88 { "branch_margin", TYPE_NUMBER, { &conf.branch_margin } },
89 { "branch_dupbox", TYPE_BOOLEAN, { &conf.branch_dupbox } },
90 { "branch_fold", TYPE_BOOLEAN, { &conf.branch_fold } },
91 { "branch_foldall", TYPE_BOOLEAN, { &conf.branch_foldall } },
92 { "branch_resort", TYPE_BOOLEAN, { &conf.branch_resort } },
93 { "branch_subtree", TYPE_STRING, { &conf.branch_subtree } },
94 { "upside_down", TYPE_BOOLEAN, { &conf.upside_down } },
95 { "left_right", TYPE_BOOLEAN, { &conf.left_right } },
96 { "auto_stretch", TYPE_BOOLEAN, { &conf.auto_stretch } },
97 { "color_bg", TYPE_COLOR, { &conf.color_bg } },
98 { "transparent_bg", TYPE_BOOLEAN, { &conf.transparent_bg } },
99 { "cvsmodule", TYPE_STRING, { &conf.cvsmodule } },
100 { "cvsroot", TYPE_STRING, { &conf.cvsroot } },
101 { "date_format", TYPE_STRING, { &conf.date_format } },
102 { "box_shadow", TYPE_BOOLEAN, { &conf.box_shadow } },
103 { "strip_untagged", TYPE_BOOLEAN, { &conf.strip_untagged } },
104 { "strip_first_rev", TYPE_BOOLEAN, { &conf.strip_first_rev } },
105 { "anti_alias", TYPE_BOOLEAN, { &conf.anti_alias } },
106 { "use_ttf", TYPE_BOOLEAN, { &conf.use_ttf } },
107 { "parse_logs", TYPE_BOOLEAN, { &conf.parse_logs } },
108 { "html_level", TYPE_NUMBER, { &conf.html_level } },
109 { "thick_lines", TYPE_NUMBER, { &conf.thick_lines } },
110 { "msg_color", TYPE_COLOR, { &conf.msg_color } },
111 { "msg_font", TYPE_FONT, { &conf.msg_font.gdfont } },
112 { "msg_ttfont", TYPE_STRING, { &conf.msg_font.ttfont } },
113 { "msg_ttsize", TYPE_DOUBLE, { &conf.msg_font.ttsize } },
114 { "rev_hidenumber", TYPE_BOOLEAN, { &conf.rev_hidenumber } },
115 { "rev_color", TYPE_COLOR, { &conf.rev_color } },
116 { "rev_bgcolor", TYPE_COLOR, { &conf.rev_bgcolor } },
117 { "rev_font", TYPE_FONT, { &conf.rev_font.gdfont } },
118 { "rev_ttfont", TYPE_STRING, { &conf.rev_font.ttfont } },
119 { "rev_ttsize", TYPE_DOUBLE, { &conf.rev_font.ttsize } },
120 { "rev_separator", TYPE_NUMBER, { &conf.rev_separator } },
121 { "rev_minline", TYPE_NUMBER, { &conf.rev_minline } },
122 { "rev_maxline", TYPE_NUMBER, { &conf.rev_maxline } },
123 { "rev_lspace", TYPE_NUMBER, { &conf.rev_lspace } },
124 { "rev_rspace", TYPE_NUMBER, { &conf.rev_rspace } },
125 { "rev_tspace", TYPE_NUMBER, { &conf.rev_tspace } },
126 { "rev_bspace", TYPE_NUMBER, { &conf.rev_bspace } },
127 { "rev_text", TYPE_CSTRING, { &conf.rev_text } },
128 { "rev_idtext", TYPE_CSTRING, { &conf.rev_idtext } },
129 { "rev_text_color", TYPE_COLOR, { &conf.rev_text_color } },
130 { "rev_text_font", TYPE_FONT, { &conf.rev_text_font.gdfont } },
131 { "rev_text_ttfont", TYPE_STRING, { &conf.rev_text_font.ttfont } },
132 { "rev_text_ttsize", TYPE_DOUBLE, { &conf.rev_text_font.ttsize } },
133 { "rev_maxtags", TYPE_NUMBER, { &conf.rev_maxtags } },
134 { "merge_color", TYPE_COLORLIST, { &conf.merge_color } },
135 { "merge_from", TYPE_STRINGLIST, { &conf.merge_from } },
136 { "merge_to", TYPE_STRINGLIST, { &conf.merge_to } },
137 { "merge_findall", TYPE_BOOLEAN, { &conf.merge_findall } },
138 { "merge_front", TYPE_BOOLEAN, { &conf.merge_front } },
139 { "merge_nocase", TYPE_BOOLEAN, { &conf.merge_nocase } },
140 { "merge_arrows", TYPE_BOOLEAN, { &conf.merge_arrows } },
141 { "merge_cvsnt", TYPE_BOOLEAN, { &conf.merge_cvsnt } },
142 { "merge_cvsnt_color", TYPE_COLOR, { &conf.merge_cvsnt_color } },
143 { "arrow_width", TYPE_NUMBER, { &conf.arrow_width } },
144 { "arrow_length", TYPE_NUMBER, { &conf.arrow_length } },
145 { "tag_color", TYPE_COLOR, { &conf.tag_color } },
146 { "tag_font", TYPE_FONT, { &conf.tag_font.gdfont } },
147 { "tag_ttfont", TYPE_STRING, { &conf.tag_font.ttfont } },
148 { "tag_ttsize", TYPE_DOUBLE, { &conf.tag_font.ttsize } },
149 { "tag_ignore", TYPE_STRING, { &conf.tag_ignore } },
150 { "tag_ignore_merge", TYPE_BOOLEAN, { &conf.tag_ignore_merge } },
151 { "tag_nocase", TYPE_BOOLEAN, { &conf.tag_nocase } },
152 { "tag_negate", TYPE_BOOLEAN, { &conf.tag_negate } },
153 { "title", TYPE_STRING, { &conf.title } },
154 { "title_x", TYPE_NUMBER, { &conf.title_x } },
155 { "title_y", TYPE_NUMBER, { &conf.title_y } },
156 { "title_font", TYPE_FONT, { &conf.title_font.gdfont } },
157 { "title_ttfont", TYPE_STRING, { &conf.title_font.ttfont } },
158 { "title_ttsize", TYPE_DOUBLE, { &conf.title_font.ttsize } },
159 { "title_align", TYPE_NUMBER, { &conf.title_align } },
160 { "title_color", TYPE_COLOR, { &conf.title_color } },
161 { "margin_top", TYPE_NUMBER, { &conf.margin_top } },
162 { "margin_bottom", TYPE_NUMBER, { &conf.margin_bottom } },
163 { "margin_left", TYPE_NUMBER, { &conf.margin_left } },
164 { "margin_right", TYPE_NUMBER, { &conf.margin_right } },
165 { "image_type", TYPE_NUMBER, { &conf.image_type } },
166 { "image_quality", TYPE_NUMBER, { &conf.image_quality } },
167 { "image_compress", TYPE_NUMBER, { &conf.image_compress } },
168 { "image_interlace", TYPE_BOOLEAN, { &conf.image_interlace } },
169 { "map_name", TYPE_STRING, { &conf.map_name } },
170 { "map_branch_href", TYPE_STRING, { &conf.map_branch_href } },
171 { "map_branch_alt", TYPE_STRING, { &conf.map_branch_alt } },
172 { "map_rev_href", TYPE_STRING, { &conf.map_rev_href } },
173 { "map_rev_alt", TYPE_STRING, { &conf.map_rev_alt } },
174 { "map_diff_href", TYPE_STRING, { &conf.map_diff_href } },
175 { "map_diff_alt", TYPE_STRING, { &conf.map_diff_alt } },
176 { "map_merge_href", TYPE_STRING, { &conf.map_merge_href } },
177 { "map_merge_alt", TYPE_STRING, { &conf.map_merge_alt } },
178 { "jpeg", TYPE_VALUE, { val: IMAGE_JPEG } },
179 { "png", TYPE_VALUE, { val: IMAGE_PNG } },
180 { "gif", TYPE_VALUE, { val: IMAGE_GIF } },
181 { "true", TYPE_VALUE, { val: 1 } },
182 { "false", TYPE_VALUE, { val: 0 } },
183 { "not", TYPE_VALUE, { val: -1 } },
184 { "left", TYPE_VALUE, { val: 0 } },
185 { "center", TYPE_VALUE, { val: 1 } },
186 { "right", TYPE_VALUE, { val: 2 } },
187 { "tiny", TYPE_VALUE, { val: 0 } },
188 { "small", TYPE_VALUE, { val: 1 } },
189 { "medium", TYPE_VALUE, { val: 2 } },
190 { "large", TYPE_VALUE, { val: 3 } },
191 { "giant", TYPE_VALUE, { val: 4 } },
192 { "HTML3", TYPE_VALUE, { val: 1 } },
193 { "HTML4", TYPE_VALUE, { val: 2 } },
194 { "XHTML", TYPE_VALUE, { val: 3 } },
195 };
196
197 #define NKEYWORDS (sizeof(keywords) / sizeof(keywords[0]))
198
199 static int cmp_kw(const void *k1, const void *k2)
200 {
201 return strcmp(((keyword_t *)k1)->keyword, ((keyword_t *)k2)->keyword);
202 }
203
204 /*
205 **************************************************************************
206 * Debug routines
207 **************************************************************************
208 */
209 #ifdef DEBUG
210 #define DEBUGSTREAM stdout
211 static void debug_pname(const char *n)
212 {
213 fprintf(DEBUGSTREAM, "%-16s: ", n);
214 }
215
216 static void debug_pstring(const char *n, const char *a)
217 {
218 debug_pname(n);
219 if(!a)
220 fprintf(DEBUGSTREAM, "<not-set>\n");
221 else
222 {
223 fputc('\'', DEBUGSTREAM);
224 for(; *a; a++)
225 {
226 if(isprint(*a))
227 fputc(*a, DEBUGSTREAM);
228 else
229 {
230 fputc('\\', DEBUGSTREAM);
231 switch(*a)
232 {
233 case '\a': fputc('a', DEBUGSTREAM); break;
234 case '\b': fputc('b', DEBUGSTREAM); break;
235 case '\f': fputc('f', DEBUGSTREAM); break;
236 case '\n': fputc('n', DEBUGSTREAM); break;
237 case '\r': fputc('r', DEBUGSTREAM); break;
238 case '\t': fputc('t', DEBUGSTREAM); break;
239 case '\v': fputc('v', DEBUGSTREAM); break;
240 default:
241 fprintf(DEBUGSTREAM, "x%02x", (unsigned char)*a);
242 }
243 }
244 }
245 fprintf(DEBUGSTREAM, "'\n");
246 }
247 }
248
249 static void debug_pbool(const char *n, int b)
250 {
251 debug_pname(n);
252 fprintf(DEBUGSTREAM, "%s\n", b ? "true" : "false");
253 }
254
255 static void debug_pint(const char *n, int i)
256 {
257 debug_pname(n);
258 fprintf(DEBUGSTREAM, "%i\n", i);
259 }
260
261 static void debug_pdouble(const char *n, double d)
262 {
263 debug_pname(n);
264 fprintf(DEBUGSTREAM, "%g\n", d);
265 }
266
267 static void debug_pfont(const char *n, gdFontPtr f)
268 {
269 const char *s = "<Unknown font>";
270 debug_pname(n);
271 if(f == gdFontTiny)
272 s = "gdFontTiny";
273 else if(f == gdFontSmall)
274 s = "gdFontSmall";
275 else if(f == gdFontMediumBold)
276 s = "gdFontMediumBold";
277 else if(f == gdFontLarge)
278 s = "gdFontLarge";
279 else if(f == gdFontGiant)
280 s = "gdFontGiant";
281 fprintf(DEBUGSTREAM, "%s\n", s);
282 }
283
284 static char *debug_op[] = { "=~", "=*", "!~", "!*", "==", "!_", ">=", ">", "<=", "<" };
285
286 static void debug_pcolornode(node_t *n)
287 {
288 if(!n)
289 return;
290 if(n->op == TYPE_STRING)
291 fprintf(DEBUGSTREAM, "%s ", n->value.str);
292 else if(n->op == TYPE_COLOR)
293 fprintf(DEBUGSTREAM, "#%02x%02x%02x ", n->value.clr.r, n->value.clr.g, n->value.clr.b);
294 else
295 {
296 char *key;
297 fprintf(DEBUGSTREAM, "[ ");
298 switch(n->key)
299 {
300 case KEY_STATE: key = "state"; break;
301 case KEY_AUTHOR: key = "author"; break;
302 case KEY_TAG: key = "tag"; break;
303 case KEY_DATE: key = "date"; break;
304 case KEY_REV: key = "rev"; break;
305 case KEY_UNKNOWN: key = "unknown"; break;
306 default: key = "<undefined>"; break;
307 }
308 fprintf(DEBUGSTREAM, "%s ", key);
309 if(n->op > OP_FIRST && n->op < OP_LAST)
310 fprintf(DEBUGSTREAM, "%s ", debug_op[n->op - OP_FIRST - 1]);
311 else
312 fprintf(DEBUGSTREAM, "op(-?-) ");
313 fprintf(DEBUGSTREAM, "%s ", n->content);
314 debug_pcolornode(n->tcase);
315 debug_pcolornode(n->fcase);
316 fprintf(DEBUGSTREAM, "]");
317 }
318 }
319
320 static void debug_pcolor(const char *n, color_t *c)
321 {
322 debug_pname(n);
323 if(c->node)
324 {
325 debug_pcolornode(c->node);
326 fprintf(DEBUGSTREAM, "\n");
327 }
328 else
329 fprintf(DEBUGSTREAM, "#%02x%02x%02x\n", c->r, c->g, c->b);
330 }
331
332 static void debug_pcolorlist(const char *n, colorlist_t *cl)
333 {
334 int i;
335 char buf[128];
336 for(i = 0; i < cl->n; i++)
337 {
338 sprintf(buf, "%s{%d}", n, i);
339 debug_pcolor(buf, &cl->clrs[i]);
340 }
341 }
342
343 static void debug_pstringlist(const char *n, stringlist_t *sl)
344 {
345 int i;
346 char buf[128];
347 for(i = 0; i < sl->n; i++)
348 {
349 sprintf(buf, "%s{%d}", n, i);
350 debug_pstring(buf, sl->strs[i]);
351 }
352 }
353
354 void dump_config(void)
355 {
356 debug_pstring("cvsroot", conf.cvsroot);
357 debug_pstring("cvsmodule", conf.cvsmodule);
358 debug_pstring("date_format", conf.date_format);
359
360 debug_pcolor("color_bg", &conf.color_bg);
361 debug_pbool("box_shadow", conf.box_shadow);
362 debug_pbool("upside_down", conf.upside_down);
363 debug_pbool("left_right", conf.left_right);
364 debug_pbool("strip_untagged", conf.strip_untagged);
365 debug_pbool("strip_first_rev", conf.strip_first_rev);
366 debug_pbool("auto_stretch", conf.auto_stretch);
367 debug_pbool("anti_alias", conf.anti_alias);
368 debug_pbool("use_ttf", conf.use_ttf);
369 debug_pint("thick_lines", conf.thick_lines);
370 debug_pint("html_level", conf.html_level);
371 debug_pbool("parse_logs", conf.parse_logs);
372 debug_pbool("transparent_bg", conf.transparent_bg);
373
374 debug_pint("arrow_length", conf.arrow_length);
375 debug_pint("arrow_width", conf.arrow_width);
376
377 debug_pbool("merge_arrows", conf.merge_arrows);
378 debug_pcolor("merge_cvsnt_color", &conf.merge_cvsnt_color);
379 debug_pbool("merge_cvsnt", conf.merge_cvsnt);
380 debug_pbool("merge_findall", conf.merge_findall);
381 debug_pcolorlist("merge_color", &conf.merge_color);
382 debug_pstringlist("merge_from", &conf.merge_from);
383 debug_pstringlist("merge_to", &conf.merge_to);
384 debug_pbool("merge_front", conf.merge_front);
385 debug_pbool("merge_nocase", conf.merge_nocase);
386
387 debug_pcolor("msg_color", &conf.msg_color);
388 debug_pfont("msg_font", conf.msg_font.gdfont);
389 debug_pstring("msg_ttfont", conf.msg_font.ttfont);
390 debug_pdouble("msg_ttsize", conf.msg_font.ttsize);
391
392 debug_pfont("tag_font", conf.tag_font.gdfont);
393 debug_pstring("tag_ttfont", conf.tag_font.ttfont);
394 debug_pdouble("tag_ttsize", conf.tag_font.ttsize);
395 debug_pcolor("tag_color", &conf.tag_color);
396 debug_pbool("tag_ignore_merge", conf.tag_ignore_merge);
397 debug_pstring("tag_ignore", conf.tag_ignore);
398 debug_pbool("tag_negate", conf.tag_negate);
399 debug_pbool("tag_nocase", conf.tag_nocase);
400
401 debug_pfont("rev_font", conf.rev_font.gdfont);
402 debug_pstring("rev_ttfont", conf.rev_font.ttfont);
403 debug_pdouble("rev_ttsize", conf.rev_font.ttsize);
404 debug_pcolor("rev_color", &conf.rev_color);
405 debug_pcolor("rev_bgcolor", &conf.rev_bgcolor);
406 debug_pint("rev_separator", conf.rev_separator);
407 debug_pint("rev_minline", conf.rev_minline);
408 debug_pint("rev_maxline", conf.rev_maxline);
409 debug_pint("rev_maxtags", conf.rev_maxtags);
410 debug_pint("rev_lspace", conf.rev_lspace);
411 debug_pint("rev_rspace", conf.rev_rspace);
412 debug_pint("rev_tspace", conf.rev_tspace);
413 debug_pint("rev_bspace", conf.rev_bspace);
414 debug_pcstring("rev_text", conf.rev_text);
415 debug_pcolor("rev_text_color", &conf.rev_text_color);
416 debug_pfont("rev_text_font", conf.rev_text_font.gdfont);
417 debug_pstring("rev_text_ttfont", conf.rev_text_font.ttfont);
418 debug_pdouble("rev_text_ttsize", conf.rev_text_font.ttsize);
419 debug_pbool("rev_hidenumber", conf.rev_hidenumber);
420
421 debug_pfont("branch_font", conf.branch_font.gdfont);
422 debug_pstring("branch_ttfont", conf.branch_font.ttfont);
423 debug_pdouble("branch_ttsize", conf.branch_font.ttsize);
424 debug_pcolor("branch_color", &conf.branch_color);
425 debug_pfont("branch_tag_font", conf.branch_tag_font.gdfont);
426 debug_pstring("branch_tag_ttfont", conf.branch_tag_font.ttfont);
427 debug_pdouble("branch_tag_ttsize", conf.branch_tag_font.ttsize);
428 debug_pcolor("branch_tag_color", &conf.branch_tag_color);
429 debug_pcolor("branch_bgcolor", &conf.branch_bgcolor);
430 debug_pint("branch_lspace", conf.branch_lspace);
431 debug_pint("branch_rspace", conf.branch_rspace);
432 debug_pint("branch_tspace", conf.branch_tspace);
433 debug_pint("branch_bspace", conf.branch_bspace);
434 debug_pint("branch_connect", conf.branch_connect);
435 debug_pint("branch_margin", conf.branch_margin);
436 debug_pint("branch_dupbox", conf.branch_dupbox);
437 debug_pbool("branch_fold", conf.branch_fold);
438 debug_pbool("branch_foldall", conf.branch_foldall);
439 debug_pbool("branch_resort", conf.branch_resort);
440 debug_pstring("branch_subtree", conf.branch_subtree);
441
442 debug_pstring("title", conf.title);
443 debug_pint("title_x", conf.title_x);
444 debug_pint("title_y", conf.title_y);
445 debug_pfont("title_font", conf.title_font.gdfont);
446 debug_pstring("title_ttfont", conf.title_font.ttfont);
447 debug_pdouble("title_ttsize", conf.title_font.ttsize);
448 debug_pint("title_align", conf.title_align);
449 debug_pcolor("title_color", &conf.title_color);
450
451 debug_pint("margin_top", conf.margin_top);
452 debug_pint("margin_bottom", conf.margin_bottom);
453 debug_pint("margin_left", conf.margin_left);
454 debug_pint("margin_right", conf.margin_right);
455
456 debug_pint("image_type", conf.image_type);
457 debug_pint("image_quality", conf.image_quality);
458 debug_pint("image_compress", conf.image_compress);
459 debug_pbool("image_interlace", conf.image_interlace);
460
461 debug_pstring("map_name", conf.map_name);
462 debug_pstring("map_branch_href", conf.map_branch_href);
463 debug_pstring("map_branch_alt", conf.map_branch_alt);
464 debug_pstring("map_rev_href", conf.map_rev_href);
465 debug_pstring("map_rev_alt", conf.map_rev_alt);
466 debug_pstring("map_diff_href", conf.map_diff_href);
467 debug_pstring("map_diff_alt", conf.map_diff_alt);
468 debug_pstring("map_merge_href", conf.map_merge_href);
469 debug_pstring("map_merge_alt", conf.map_merge_alt);
470
471 debug_pstring("expand[0]", conf.expand[0]);
472 debug_pstring("expand[1]", conf.expand[1]);
473 debug_pstring("expand[2]", conf.expand[2]);
474 debug_pstring("expand[3]", conf.expand[3]);
475 debug_pstring("expand[4]", conf.expand[4]);
476 debug_pstring("expand[5]", conf.expand[5]);
477 debug_pstring("expand[6]", conf.expand[6]);
478 debug_pstring("expand[7]", conf.expand[7]);
479 debug_pstring("expand[8]", conf.expand[8]);
480 debug_pstring("expand[9]", conf.expand[9]);
481 }
482 #endif
483
484 /*
485 **************************************************************************
486 * String collection routines
487 **************************************************************************
488 */
489 #define STRALLOCSIZE 128
490 static char *str;
491 static int nstr;
492 static int nastr;
493
494 static void reset_str(void)
495 {
496 nstr = 0;
497 }
498
499 static void add_str(int c)
500 {
501 if(nstr + 1 + 1 > nastr)
502 {
503 str = xrealloc(str, nastr+STRALLOCSIZE);
504 nastr += STRALLOCSIZE;
505 }
506 str[nstr++] = c;
507 }
508
509 static char *get_str(void)
510 {
511 if(!str)
512 return xstrdup("");
513
514 str[nstr] = '\0';
515 return xstrdup(str);
516 }
517
518 /*
519 **************************************************************************
520 * Input routines
521 **************************************************************************
522 */
523 static char *buf = NULL;
524 static int bufsize = 0;
525 static int bufalloc = 0;
526 static int bufpos = 0;
527 static int bufunput = -1;
528 static FILE *buffp;
529
530 static void set_input(FILE *fp, char *s)
531 {
532 assert((fp == NULL && s != NULL) || (fp != NULL && s == NULL));
533 buffp = fp;
534 bufsize = bufpos = 0;
535 if(s)
536 {
537 if(!buf)
538 {
539 bufalloc = 8192;
540 buf = xmalloc(bufalloc * sizeof(*buf));
541 }
542 bufsize = strlen(s);
543 assert(bufsize < bufalloc);
544 strcpy(buf, s);
545 }
546 }
547
548 static int get_input(void)
549 {
550 if(bufunput != -1)
551 {
552 int c = bufunput;
553 bufunput = -1;
554 return c;
555 }
556
557 if(bufpos < bufsize)
558 {
559 assert(buf != NULL);
560 retry_input:
561 return (int)((unsigned char)buf[bufpos++]);
562 }
563
564 if(!buf)
565 {
566 bufalloc = 8192;
567 buf = xmalloc(bufalloc * sizeof(*buf));
568 bufsize = bufpos = 0;
569 }
570 if(buffp)
571 {
572 bufsize = fread(buf, 1, bufalloc, buffp);
573 bufpos = 0;
574 if(!bufsize)
575 return EOF;
576 goto retry_input;
577 }
578 return EOF;
579 }
580
581 static void unget_input(int c)
582 {
583 bufunput = c;
584 }
585
586 /*
587 **************************************************************************
588 * Lexical scanner
589 **************************************************************************
590 */
591 static int config_lex(void)
592 {
593 int ch;
594 while(1)
595 {
596 ch = get_input();
597 if(ch == '\n')
598 line_number++;
599
600 if(isspace(ch))
601 continue;
602
603 switch(ch)
604 {
605 case '=':
606 ch = get_input();
607 switch(ch)
608 {
609 case '~': return OP_CONTAINED;
610 case '*': return OP_CONTAINEDI;
611 case '=': return OP_EQ;
612 default:
613 unget_input(ch);
614 return '=';
615 }
616 break;
617
618 case '!':
619 ch = get_input();
620 switch(ch)
621 {
622 case '~': return OP_NCONTAINED;
623 case '*': return OP_NCONTAINEDI;
624 case '=': return OP_NE;
625 default:
626 stack_msg(MSG_ERR, "config: %d: Invalid operator", line_number);
627 unget_input(ch);
628 return '!';
629 }
630 break;
631
632 case '>':
633 ch = get_input();
634 if(ch == '=')
635 return OP_GE;
636 unget_input(ch);
637 return OP_GT;
638
639 case '<':
640 ch = get_input();
641 if(ch == '=')
642 return OP_LE;
643 unget_input(ch);
644 return OP_LT;
645
646 case EOF:
647 case ';':
648 case '[':
649 case ']':
650 return ch;
651
652 case '#': /* Comment */
653 while((ch = get_input()) != '\n' && ch != EOF)
654 ;
655 if(ch != EOF)
656 unget_input(ch);
657 break;
658
659 case '"':
660 reset_str();
661 while(1)
662 {
663 char c[4];
664 ch = get_input();
665 switch(ch)
666 {
667 case '\\': /* Start an escape sequence */
668 switch(ch = get_input())
669 {
670 default: /* This includes '\\', '"' and embedded newlines */
671 add_str(ch);
672 break;
673 case 'a': add_str('\a'); break;
674 case 'b': add_str('\b'); break;
675 case 'f': add_str('\f'); break;
676 case 'n': add_str('\n'); break;
677 case 'r': add_str('\r'); break;
678 case 't': add_str('\t'); break;
679 case 'v': add_str('\v'); break;
680 case 'x':
681 case 'X': /* Hex escape */
682 c[0] = get_input();
683 c[1] = get_input();
684 c[2] = '\0';
685 if(!isxdigit((int)(unsigned char)c[0]) || !isxdigit((int)(unsigned char)c[1]))
686 stack_msg(MSG_ERR, "config: %d: Invalid hex escape", line_number);
687 add_str((int)strtol(c, NULL, 16));
688 break;
689 case '0':
690 case '1':
691 case '2': /* Octal escape */
692 c[0] = ch;
693 c[1] = c[2] = c[3] = '\0';
694 if((ch = get_input()) >= '0' && ch <= '7')
695 c[1] = ch;
696 else
697 unget_input(ch);
698 if((ch = get_input()) >= '0' && ch <= '7')
699 c[2] = ch;
700 else
701 unget_input(ch);
702 add_str((int)strtol(c, NULL, 8));
703 break;
704 case EOF:
705 yyerror("Unexpected EOF in escape");
706 break;
707 }
708 break;
709 case '"':
710 yylval.str = get_str();
711 return TYPE_STRING;
712 case '\n':
713 yyerror("Newline in string");
714 break;
715 case EOF:
716 yyerror("Unexpected EOF in string");
717 break;
718 default:
719 add_str(ch);
720 break;
721 }
722 }
723 break;
724
725 default:
726 if(isalpha(ch) || ch == '_')
727 {
728 keyword_t skw;
729 keyword_t *kw;
730 /* Collect keyword */
731 reset_str();
732 add_str(ch);
733 while(1)
734 {
735 ch = get_input();
736 if(isalnum(ch) || ch == '_')
737 add_str(ch);
738 else
739 {
740 unget_input(ch);
741 break;
742 }
743 }
744 skw.keyword = get_str();
745 kw = bsearch(&skw, keywords, NKEYWORDS, sizeof(keywords[0]), cmp_kw);
746 if(!kw)
747 {
748 stack_msg(MSG_ERR, "config: %d: Unknown keyword '%s'", line_number, skw.keyword);
749 yylval.kw = NULL;
750 return TYPE_KEYWORD;
751 }
752 xfree((void *)skw.keyword);
753 if(kw->type == TYPE_VALUE)
754 {
755 yylval.i = (int)kw->confref.val;
756 return TYPE_NUMBER;
757 }
758 yylval.kw = kw;
759 return TYPE_KEYWORD;
760 }
761 else if(isdigit(ch) || ch == '+' || ch == '-')
762 {
763 char *s;
764 char *eptr;
765 int type = TYPE_NUMBER;
766 /* Collect number */
767 reset_str();
768 add_str(ch);
769 while(1)
770 {
771 ch = get_input();
772 if(isxdigit(ch) || ch == 'x' || ch == 'X' || ch == '.') /* Not exact, but close enough */
773 add_str(ch);
774 else
775 {
776 unget_input(ch);
777 break;
778 }
779 if(ch == '.')
780 type = TYPE_DOUBLE;
781 }
782 s = get_str();
783 if(type == TYPE_DOUBLE)
784 {
785 yylval.d = strtod(s, &eptr);
786 if(*eptr)
787 stack_msg(MSG_ERR, "config: %d: Invalid floating point number", line_number);
788 }
789 else
790 {
791 yylval.i = strtol(s, &eptr, 0);
792 if(*eptr)
793 stack_msg(MSG_ERR, "config: %d: Invalid number", line_number);
794 }
795 xfree(s);
796 return type;
797 }
798 else
799 yyerror("Unmatched text '%c' (0x%02x)", isprint(ch) ? ch : ' ', ch);
800 break;
801 }
802 }
803 }
804
805 static void set_color(color_t *c, char *s)
806 {
807 char *cptr;
808 c->node = NULL;
809 if(*s != '#' || strlen(s) != 7)
810 {
811 colorerror:
812 stack_msg(MSG_ERR, "config: %d: Invalid color value '%s'", line_number, s);
813 return;
814 }
815 c->b = strtol(s+5, &cptr, 16);
816 if(*cptr)
817 goto colorerror;
818 s[5] = '\0';
819 c->g = strtol(s+3, &cptr, 16);
820 if(*cptr)
821 goto colorerror;
822 s[3] = '\0';
823 c->r = strtol(s+1, &cptr, 16);
824 if(*cptr)
825 goto colorerror;
826 }
827
828 static gdFontPtr get_font(int id)
829 {
830 switch(id)
831 {
832 case 0: return gdFontTiny;
833 case 1: return gdFontSmall;
834 default:
835 case 2: return gdFontMediumBold;
836 case 3: return gdFontLarge;
837 case 4: return gdFontGiant;
838 }
839 }
840
841 /*
842 **************************************************************************
843 * The config parser
844 * Grammar:
845 * file : <Empty>
846 * | lines
847 * ;
848 *
849 * lines : line
850 * | lines line
851 * ;
852 *
853 * line : <keyword> '=' <value> ';'
854 * | <keyword> '=' expr ';'
855 * | ';'
856 *
857 * expr : '[' <kw> <op> <value> expr expr ']'
858 * | <value>
859 * ;
860 **************************************************************************
861 */
862 static int skip_to_semicolon(int state)
863 {
864 int token;
865 while(1)
866 {
867 token = config_lex();
868 if(token == ';')
869 return 0;
870 else if(token == EOF)
871 return state;
872 }
873 }
874
875 static node_t *new_node(char *val)
876 {
877 node_t *n = xmalloc(sizeof(*n));
878 if(!strcmp(val, "state"))
879 n->key = KEY_STATE;
880 else if(!strcmp(val, "author"))
881 n->key = KEY_AUTHOR;
882 else if(!strcmp(val, "tag"))
883 n->key = KEY_TAG;
884 else if(!strcmp(val, "date"))
885 n->key = KEY_DATE;
886 else if(!strcmp(val, "rev"))
887 n->key = KEY_REV;
888 else
889 {
890 n->key = KEY_UNKNOWN;
891 stack_msg(MSG_ERR, "config: %d: Unknown key '%s'", line_number, val);
892 }
893 return n;
894 }
895
896 typedef struct __statestack_t
897 {
898 int state;
899 node_t *node;
900 } statestack_t;
901
902 static int nstatestack = 0;
903 static int nastatestack;
904 static statestack_t *statestack = NULL;
905
906 static void push_state(node_t *node, int state)
907 {
908 if(!statestack)
909 {
910 statestack = xmalloc(4 * sizeof(*statestack));
911 nastatestack = 4;
912 nstatestack = 0;
913 }
914 else if(nstatestack >= nastatestack)
915 {
916 nastatestack *= 2;
917 statestack = xrealloc(statestack, nastatestack * sizeof(*statestack));
918 }
919 statestack[nstatestack].node = node;
920 statestack[nstatestack].state = state;
921 nstatestack++;
922 }
923
924 static int pop_state(node_t **node, int *state)
925 {
926 if(nstatestack <= 0)
927 {
928 *state = 3;
929 return 0;
930 }
931 assert(*node != NULL);
932 if(statestack[nstatestack-1].state == 8)
933 statestack[nstatestack-1].node->tcase = *node;
934 else if(statestack[nstatestack-1].state == 9)
935 statestack[nstatestack-1].node->fcase = *node;
936 *state = statestack[nstatestack-1].state;
937 *node = statestack[nstatestack-1].node;
938 return nstatestack--;
939 }
940
941 /* YYYY.MM.DD.hh.mm.ss */
942 /* 0123456789012345678 */
943 /* 111111111 */
944 static char *fixup_date(const char *str)
945 {
946 int i;
947 int y=1970, m=1, d=1, h=0, mi=0, s=0;
948 int l = strlen(str);
949 char date[6*16]; /* Should be wildly enough to hold 19 chars from 6 numbers with all possible errors */
950 if(l < 4 || l > 19)
951 {
952 date_err:
953 stack_msg(MSG_ERR, "config: %d: Invalid date string '%s'", line_number, str);
954 return "1970.01.01.00.00.00";
955 }
956 for(i = 0; i < l; i++)
957 {
958 if(!strchr("0123456789.", str[i]))
959 goto date_err;
960 }
961 i = sscanf(str, "%d.%d.%d.%d.%d.%d", &y, &m, &d, &h, &mi, &s);
962 if(i == EOF || i < 0 || i > 6)
963 goto date_err;
964 if(i >= 1 && (y < 1970 || y > 2037))
965 goto date_err;
966 if(i >= 2 && (m < 1 || m > 12))
967 goto date_err;
968 if(i >= 3 && (d < 1 || d > 31))
969 goto date_err;
970 if(i >= 4 && (h < 0 || h > 23))
971 goto date_err;
972 if(i >= 5 && (mi < 0 || mi > 59))
973 goto date_err;
974 if(i >= 6 && (s < 0 || s > 59))
975 goto date_err;
976 sprintf(date, "%04d.%02d.%02d.%02d.%02d.%02d", y, m, d, h, mi, s);
977 return strdup(date);
978 }
979
980 static void config_parse(void)
981 {
982 int state = 0;
983 int token;
984 int t;
985 keyword_t *kw = NULL;
986 node_t *node = NULL;
987
988 while(1)
989 {
990 token = config_lex();
991 if(token == EOF)
992 {
993 if(state)
994 stack_msg(MSG_ERR, "config: %d: Unexpected EOF", line_number);
995 break;
996 }
997
998 switch(state)
999 {
1000 case 0:
1001 if(token == TYPE_KEYWORD)
1002 {
1003 kw = yylval.kw;
1004 state = 1;
1005 }
1006 else if(token != ';')
1007 stack_msg(MSG_ERR, "config: %d: Keyword expected", line_number);
1008 break;
1009 case 1:
1010 if(token != '=')
1011 {
1012 stack_msg(MSG_ERR, "config: %d: '=' expected", line_number);
1013 state = skip_to_semicolon(state);
1014 break;
1015 }
1016 else
1017 state = 2;
1018 break;
1019 case 2:
1020 if(!kw)
1021 {
1022 /* Error recovery of failed keyword */
1023 state = 3;
1024 break;
1025 }
1026 if(token == '[')
1027 {
1028 if(kw->type != TYPE_COLOR && kw->type != TYPE_CSTRING)
1029 {
1030 stack_msg(MSG_ERR, "config: %d: Conditional expression not allowed for keyword", line_number);
1031 state = skip_to_semicolon(state);
1032 break;
1033 }
1034 state = 4;
1035 break;
1036 }
1037 if(kw->type == TYPE_FONT || kw->type == TYPE_BOOLEAN)
1038 t = TYPE_NUMBER;
1039 else if(kw->type == TYPE_COLOR || kw->type == TYPE_COLORLIST || kw->type == TYPE_STRINGLIST || kw->type == TYPE_CSTRING)
1040 t = TYPE_STRING;
1041 else
1042 t = kw->type;
1043
1044 if(token == TYPE_NUMBER && kw->type == TYPE_DOUBLE)
1045 {
1046 /* Auto promote numbers to doubles if required */
1047 yylval.d = (double)yylval.i;
1048 token = TYPE_DOUBLE;
1049 }
1050
1051 if(token != t)
1052 {
1053 char *e;
1054 switch(kw->type)
1055 {
1056 case TYPE_STRING: e = "String"; yylval.str = xstrdup("error recovery"); break;
1057 case TYPE_STRINGLIST: e = "StringL"; yylval.str = xstrdup("error recovery"); break;
1058 case TYPE_CSTRING: e = "CString"; yylval.str = xstrdup("error recovery"); break;
1059 case TYPE_NUMBER: e = "Number"; yylval.i = 0; break;
1060 case TYPE_COLOR: e = "Color"; yylval.str = xstrdup("#123456"); break;
1061 case TYPE_COLORLIST: e = "ColorL"; yylval.str = xstrdup("#123456"); break;
1062 case TYPE_FONT: e = "Font"; yylval.i = 0; break;
1063 case TYPE_BOOLEAN: e = "Boolean"; yylval.i = 0; break;
1064 case TYPE_DOUBLE: e = "Double"; yylval.d = 0.0; break;
1065 default: e = "Internal error: Unknown type"; yylval.i = 0; break;
1066 }
1067 stack_msg(MSG_ERR, "config: %d: %s expected", line_number, e);
1068 }
1069 #ifdef DEBUG
1070 printf("processing: '%s'\n", kw->keyword);
1071 #endif
1072 switch(kw->type)
1073 {
1074 case TYPE_STRING:
1075 *kw->confref.s = yylval.str;
1076 break;
1077 case TYPE_STRINGLIST:
1078 kw->confref.sl->strs = xrealloc(kw->confref.sl->strs, sizeof(*kw->confref.sl->strs) * (kw->confref.sl->n + 1));
1079 kw->confref.sl->strs[kw->confref.sl->n] = yylval.str;
1080 kw->confref.sl->n++;
1081 break;
1082 case TYPE_CSTRING:
1083 kw->confref.cs->str = yylval.str;
1084 break;
1085 case TYPE_NUMBER:
1086 *kw->confref.i = yylval.i;
1087 break;
1088 case TYPE_BOOLEAN:
1089 if(yylval.i == -1)
1090 *kw->confref.i = !*kw->confref.i;
1091 else
1092 *kw->confref.i = yylval.i != 0;
1093 break;
1094 case TYPE_COLOR:
1095 set_color(kw->confref.c, yylval.str);
1096 break;
1097 case TYPE_COLORLIST:
1098 kw->confref.cl->clrs = xrealloc(kw->confref.cl->clrs, sizeof(*kw->confref.cl->clrs) * (kw->confref.cl->n + 1));
1099 set_color(&kw->confref.cl->clrs[kw->confref.cl->n], yylval.str);
1100 kw->confref.cl->n++;
1101 break;
1102 case TYPE_FONT:
1103 kw->confref.f->gdfont = get_font(yylval.i);
1104 break;
1105 case TYPE_DOUBLE:
1106 *kw->confref.d = yylval.d;
1107 break;
1108 default:
1109 yyerror("Internal error: Unknown type passed %d", kw->type);
1110 break;
1111 }
1112 kw = NULL;
1113 state = 3;
1114 break;
1115 case 3:
1116 if(token != ';')
1117 stack_msg(MSG_ERR, "config: %d: ';' expected", line_number);
1118 state = 0;
1119 break;
1120 case 4:
1121 if(token != TYPE_STRING)
1122 {
1123 stack_msg(MSG_ERR, "config: %d: String expected (condition key)", line_number);
1124 state = skip_to_semicolon(state);
1125 break;
1126 }
1127 node = new_node(yylval.str);
1128 state = 5;
1129 break;
1130 case 5:
1131 if(token <= OP_FIRST || token >= OP_LAST)
1132 {
1133 stack_msg(MSG_ERR, "config: %d: Operator expected", line_number);
1134 state = skip_to_semicolon(state);
1135 break;
1136 }
1137 node->op = token;
1138 state = 6;
1139 break;
1140 case 6:
1141 if(token != TYPE_STRING)
1142 {
1143 stack_msg(MSG_ERR, "config: %d: String expected (condition)", line_number);
1144 state = skip_to_semicolon(state);
1145 break;
1146 }
1147 if(node->key == KEY_DATE)
1148 node->content = fixup_date(yylval.str);
1149 else
1150 node->content = yylval.str;
1151 state = 7;
1152 break;
1153 case 7:
1154 if(token == '[')
1155 {
1156 push_state(node, 8);
1157 node = NULL;
1158 state = 4;
1159 break;
1160 }
1161 if(token != TYPE_STRING)
1162 {
1163 stack_msg(MSG_ERR, "config: %d: String or '[' expected (true case)", line_number);
1164 state = skip_to_semicolon(state);
1165 break;
1166 }
1167 node->tcase = xmalloc(sizeof(*node->tcase));
1168 if(kw->type == TYPE_COLOR || kw->type == TYPE_COLORLIST)
1169 {
1170 node->tcase->key = TYPE_COLOR;
1171 set_color(&node->tcase->value.clr, yylval.str);
1172 }
1173 else
1174 {
1175 node->tcase->key = TYPE_STRING;
1176 node->tcase->value.str = yylval.str;
1177 }
1178 state = 8;
1179 break;
1180 case 8:
1181 if(token == '[')
1182 {
1183 push_state(node, 9);
1184 node = NULL;
1185 state = 4;
1186 break;
1187 }
1188 if(token != TYPE_STRING)
1189 {
1190 stack_msg(MSG_ERR, "config: %d: String or '[' expected (false case)", line_number);
1191 state = skip_to_semicolon(state);
1192 break;
1193 }
1194 node->fcase = xmalloc(sizeof(*node->fcase));
1195 if(kw->type == TYPE_COLOR || kw->type == TYPE_COLORLIST)
1196 {
1197 node->fcase->key = TYPE_COLOR;
1198 set_color(&node->fcase->value.clr, yylval.str);
1199 }
1200 else
1201 {
1202 node->fcase->key = TYPE_STRING;
1203 node->fcase->value.str = yylval.str;
1204 }
1205 state = 9;
1206 break;
1207 case 9:
1208 if(token != ']')
1209 {
1210 stack_msg(MSG_ERR, "config: %d: ']' expected", line_number);
1211 state = skip_to_semicolon(state);
1212 break;
1213 }
1214 if(!pop_state(&node, &state))
1215 {
1216 if(kw->type == TYPE_COLOR)
1217 kw->confref.c->node = node;
1218 else if(kw->type == TYPE_CSTRING)
1219 kw->confref.cs->node = node;
1220 else
1221 stack_msg(MSG_ERR, "config: %d: Color or conditional string keyword expected", line_number);
1222 node = NULL;
1223 kw = NULL;
1224 }
1225 break;
1226 default:
1227 yyerror("Internal error: invalid state %d", state);
1228 break;
1229 }
1230 }
1231 }
1232
1233 /*
1234 **************************************************************************
1235 * Configuration
1236 **************************************************************************
1237 */
1238 void stack_option(const char *opt)
1239 {
1240 stacked_opts = xrealloc(stacked_opts, sizeof(*stacked_opts) * (nstacked_opts + 1));
1241 stacked_opts[nstacked_opts] = xmalloc(strlen(opt) + 2);
1242 strcpy(stacked_opts[nstacked_opts], opt);
1243 strcat(stacked_opts[nstacked_opts], ";");
1244 nstacked_opts++;
1245 #ifdef DEBUG
1246 printf("stacking option: '%s'\n", stacked_opts[nstacked_opts-1]);
1247 #endif
1248 }
1249
1250 void read_config(const char *path)
1251 {
1252 FILE *fp;
1253
1254 /* Make sure we have them sorted for bsearch */
1255 qsort(keywords, NKEYWORDS, sizeof(keywords[0]), cmp_kw);
1256
1257 if(path)
1258 {
1259 if((fp = fopen(path, "r")) != NULL)
1260 input_file = path;
1261 }
1262 else
1263 {
1264 if((fp = fopen("./" CONFFILENAME, "r")) == NULL)
1265 {
1266 if((fp = fopen(ETCDIR "/" CONFFILENAME, "r")) != NULL)
1267 input_file = ETCDIR "/" CONFFILENAME;
1268 }
1269 else
1270 input_file = "./" CONFFILENAME;
1271 }
1272
1273 if(fp)
1274 {
1275 line_number = 1;
1276 set_input(fp, NULL);
1277 config_parse();
1278 fclose(fp);
1279 input_file = NULL;
1280 }
1281
1282 if(nstacked_opts)
1283 {
1284 int i;
1285 for(i = 0; i < nstacked_opts; i++)
1286 {
1287 line_number = 0;
1288 set_input(NULL, stacked_opts[i]);
1289 input_file = stacked_opts[i];
1290 #ifdef DEBUG
1291 printf("parsing stacked option: '%s'\n", stacked_opts[i]);
1292 #endif
1293 config_parse();
1294 }
1295 input_file = NULL;
1296 }
1297
1298 if(conf.merge_from.n != conf.merge_to.n)
1299 {
1300 int x = conf.merge_from.n < conf.merge_to.n ? conf.merge_from.n : conf.merge_to.n;
1301 stack_msg(MSG_ERR, "config: merge_from(n=%d) does not match merge_to(n=%d)", conf.merge_from.n, conf.merge_to.n);
1302 conf.merge_from.n = x;
1303 conf.merge_to.n = x;
1304 }
1305 if(conf.merge_color.n < conf.merge_from.n)
1306 {
1307 /* Silently extend missing merge_color statements with black */
1308 int x;
1309 char c[] = "#000000";
1310 for(x = conf.merge_color.n; x < conf.merge_from.n; x++)
1311 {
1312 conf.merge_color.clrs = xrealloc(conf.merge_color.clrs, sizeof(*conf.merge_color.clrs) * (conf.merge_color.n + 1));
1313 set_color(&conf.merge_color.clrs[conf.merge_color.n], c);
1314 conf.merge_color.n++;
1315 }
1316 }
1317
1318 #ifdef DEBUG
1319 dump_config();
1320 #endif
1321 }
1322
1323 /*
1324 **************************************************************************
1325 * Color reference by name for late-binding color allocation
1326 **************************************************************************
1327 */
1328 color_t *get_colorref(const char *confcolor, int idx)
1329 {
1330 keyword_t skw;
1331 keyword_t *kw;
1332
1333 if(!confcolor)
1334 return NULL;
1335
1336 skw.keyword = confcolor;
1337 kw = bsearch(&skw, keywords, NKEYWORDS, sizeof(keywords[0]), cmp_kw);
1338 if(!kw || (kw->type != TYPE_COLOR && kw->type != TYPE_COLORLIST))
1339 return NULL;
1340 if(kw->type == TYPE_COLORLIST)
1341 {
1342 if(idx >= kw->confref.cl->n)
1343 return NULL;
1344 return &kw->confref.cl->clrs[idx];
1345 }
1346 return kw->confref.c;
1347 }

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0