/[CvsGraph]/cvsgraph/confy.y
ViewVC logotype

Annotate of /cvsgraph/confy.y

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


Revision 1.10 - (show annotations)
Tue Jan 1 21:03:23 2002 UTC (15 years, 9 months ago) by bertho
Branch: MAIN
Changes since 1.9: +6 -2 lines
Major code update to enable some more features. The new formatting scheme is
not yet 100%. This should be close to version 1.2.0.
1 /*
2 * CvsGraph graphical representation generator of brances and revisions
3 * of a file in cvs/rcs.
4 *
5 * Copyright (C) 2001 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 %{
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include <gd.h>
28 #include <gdfontt.h>
29 #include <gdfonts.h>
30 #include <gdfontmb.h>
31 #include <gdfontl.h>
32 #include <gdfontg.h>
33
34 #include "cvsgraph.h"
35 #include "utils.h"
36 #include "readconf.h"
37
38
39 static void assign_num(int key, int val);
40 static void assign_str(int key, char *str);
41 static void assign_color(int key, char *str);
42
43 static const char err_semicolon[] = "Missing ';'";
44 static const char err_assign[] = "Missing '='";
45
46 %}
47
48 %union{
49 char *str;
50 int num;
51 }
52
53 %token tBRANCH_BGCOLOR tBRANCH_BSPACE tBRANCH_COLOR tBRANCH_FONT tBRANCH_LSPACE tBRANCH_RSPACE tBRANCH_TSPACE
54 %token tBRANCH_CONNECT tBRANCH_MARGIN tBRANCH_DUPBOX tUPSIDE_DOWN tAUTO_KERN
55 %token tCOLOR_BG tCVSMODULE tCVSROOT tDATE_FORMAT tBOX_SHADOW tSTRIP_UNTAGGED tSTRIP_FIRST_REV
56 %token tREV_COLOR tREV_BGCOLOR tREV_FONT tREV_SEPARATOR tREV_MINLINE tREV_MAXLINE tREV_LSPACE
57 %token tREV_RSPACE tREV_TSPACE tREV_BSPACE tREV_TEXT tREV_TEXT_COLOR tREV_TEXT_FONT
58 %token tTAG_COLOR tTAG_FONT
59 %token tTITLE tTITLE_X tTITLE_Y tTITLE_FONT tTITLE_ALIGN tTITLE_COLOR
60 %token tMARGIN_TOP tMARGIN_BOTTOM tMARGIN_LEFT tMARGIN_RIGHT
61 %token tIMAGE_TYPE tIMAGE_QUALITY
62 %token tMAP_NAME tMAP_BRANCH_HREF tMAP_BRANCH_ALT tMAP_REV_HREF tMAP_REV_ALT tMAP_DIFF_HREF tMAP_DIFF_ALT
63 %token <str> tUNKNOWN
64 %token <str> tSTRING
65 %token <num> tNUMBER
66
67 %type <num> ikey skey ckey
68
69 %%
70 conffile: /* Empty */
71 | lines
72 ;
73
74 lines : line
75 | lines line
76 ;
77
78 line : ikey '=' tNUMBER ';' { assign_num($1, $3); }
79 | ikey '=' tNUMBER error { yyerror(err_semicolon); }
80 | ikey '=' error { yyerror("Number expected"); }
81 | ikey error { yyerror(err_assign); }
82 | skey '=' tSTRING ';' { assign_str($1, $3); }
83 | skey '=' tSTRING error { yyerror(err_semicolon); }
84 | skey '=' error { yyerror("String expected"); }
85 | skey error { yyerror(err_assign); }
86 | ckey '=' tSTRING ';' { assign_color($1, $3); }
87 | ckey '=' tSTRING error { yyerror(err_semicolon); }
88 | ckey '=' error { yyerror("Color-string expected"); }
89 | ckey error { yyerror(err_assign); }
90 | tUNKNOWN '=' notsc ';' { yywarning("Unknown config parameter '%s' ignored", $1); xfree($1); }
91 | tUNKNOWN '=' notsc error { yyerror(err_semicolon); }
92 | tUNKNOWN '=' error { yyerror("String or number expected"); }
93 | tUNKNOWN error { yyerror(err_assign); }
94 | error { yyerror("Keyword expected"); }
95 ;
96
97 notsc : tSTRING { xfree($1); }
98 | tNUMBER {}
99 ;
100
101 ikey : tBRANCH_FONT { $$ = tBRANCH_FONT; }
102 | tBRANCH_LSPACE { $$ = tBRANCH_LSPACE; }
103 | tBRANCH_RSPACE { $$ = tBRANCH_RSPACE; }
104 | tBRANCH_TSPACE { $$ = tBRANCH_TSPACE; }
105 | tBRANCH_BSPACE { $$ = tBRANCH_BSPACE; }
106 | tBRANCH_CONNECT { $$ = tBRANCH_CONNECT; }
107 | tBRANCH_MARGIN { $$ = tBRANCH_MARGIN; }
108 | tBRANCH_DUPBOX { $$ = tBRANCH_DUPBOX; }
109 | tUPSIDE_DOWN { $$ = tUPSIDE_DOWN; }
110 | tSTRIP_UNTAGGED { $$ = tSTRIP_UNTAGGED; }
111 | tSTRIP_FIRST_REV { $$ = tSTRIP_FIRST_REV; }
112 | tAUTO_KERN { $$ = tAUTO_KERN; }
113 | tREV_FONT { $$ = tREV_FONT; }
114 | tREV_SEPARATOR { $$ = tREV_SEPARATOR; }
115 | tREV_MINLINE { $$ = tREV_MINLINE; }
116 | tREV_MAXLINE { $$ = tREV_MAXLINE; }
117 | tREV_LSPACE { $$ = tREV_LSPACE; }
118 | tREV_RSPACE { $$ = tREV_RSPACE; }
119 | tREV_TSPACE { $$ = tREV_TSPACE; }
120 | tREV_BSPACE { $$ = tREV_BSPACE; }
121 | tREV_TEXT_FONT { $$ = tREV_TEXT_FONT; }
122 | tTAG_FONT { $$ = tTAG_FONT; }
123 | tTITLE_X { $$ = tTITLE_X; }
124 | tTITLE_Y { $$ = tTITLE_Y; }
125 | tTITLE_FONT { $$ = tTITLE_FONT; }
126 | tTITLE_ALIGN { $$ = tTITLE_ALIGN; }
127 | tMARGIN_TOP { $$ = tMARGIN_TOP; }
128 | tMARGIN_BOTTOM { $$ = tMARGIN_BOTTOM; }
129 | tMARGIN_LEFT { $$ = tMARGIN_LEFT; }
130 | tMARGIN_RIGHT { $$ = tMARGIN_RIGHT; }
131 | tIMAGE_TYPE { $$ = tIMAGE_TYPE; }
132 | tIMAGE_QUALITY { $$ = tIMAGE_QUALITY; }
133 | tBOX_SHADOW { $$ = tBOX_SHADOW; }
134 ;
135
136 skey : tCVSMODULE { $$ = tCVSMODULE; }
137 | tCVSROOT { $$ = tCVSROOT; }
138 | tTITLE { $$ = tTITLE; }
139 | tDATE_FORMAT { $$ = tDATE_FORMAT; }
140 | tMAP_NAME { $$ = tMAP_NAME; }
141 | tMAP_BRANCH_HREF { $$ = tMAP_BRANCH_HREF; }
142 | tMAP_BRANCH_ALT { $$ = tMAP_BRANCH_ALT; }
143 | tMAP_REV_HREF { $$ = tMAP_REV_HREF; }
144 | tMAP_REV_ALT { $$ = tMAP_REV_ALT; }
145 | tMAP_DIFF_HREF { $$ = tMAP_DIFF_HREF; }
146 | tMAP_DIFF_ALT { $$ = tMAP_DIFF_ALT; }
147 | tREV_TEXT { $$ = tREV_TEXT; }
148 ;
149
150 ckey : tCOLOR_BG { $$ = tCOLOR_BG; }
151 | tBRANCH_BGCOLOR { $$ = tBRANCH_BGCOLOR; }
152 | tBRANCH_COLOR { $$ = tBRANCH_COLOR; }
153 | tREV_COLOR { $$ = tREV_COLOR; }
154 | tREV_BGCOLOR { $$ = tREV_BGCOLOR; }
155 | tREV_TEXT_COLOR { $$ = tREV_TEXT_COLOR; }
156 | tTAG_COLOR { $$ = tTAG_COLOR; }
157 | tTITLE_COLOR { $$ = tTITLE_COLOR; }
158 ;
159
160 %%
161
162 static gdFontPtr get_font(int id)
163 {
164 switch(id)
165 {
166 case 0: return gdFontTiny;
167 case 1: return gdFontSmall;
168 default:
169 case 2: return gdFontMediumBold;
170 case 3: return gdFontLarge;
171 case 4: return gdFontGiant;
172 }
173 }
174
175 static int bounds(int val, int mini, int maxi)
176 {
177 if(val < mini || val > maxi)
178 {
179 yywarning("Parameter must be between %d and %d", mini, maxi);
180 val = val < mini ? mini : maxi;
181 }
182 return val;
183 }
184
185 static void assign_num(int key, int val)
186 {
187 switch(key)
188 {
189 case tBRANCH_FONT: conf.branch_font = get_font(val); break;
190 case tBRANCH_LSPACE: conf.branch_lspace = val; break;
191 case tBRANCH_RSPACE: conf.branch_rspace = val; break;
192 case tBRANCH_TSPACE: conf.branch_tspace = val; break;
193 case tBRANCH_BSPACE: conf.branch_bspace = val; break;
194 case tBRANCH_CONNECT: conf.branch_connect = val; break;
195 case tBRANCH_MARGIN: conf.branch_margin = val; break;
196 case tBRANCH_DUPBOX: conf.branch_dupbox = val; break;
197 case tUPSIDE_DOWN: conf.upside_down = val; break;
198 case tSTRIP_UNTAGGED: conf.strip_untagged = val; break;
199 case tSTRIP_FIRST_REV: conf.strip_first_rev = val; break;
200 case tAUTO_KERN: conf.auto_kern = val; break;
201 case tREV_FONT: conf.rev_font = get_font(val); break;
202 case tREV_SEPARATOR: conf.rev_separator = val; break;
203 case tREV_MINLINE: conf.rev_minline = val; break;
204 case tREV_MAXLINE: conf.rev_maxline = val; break;
205 case tREV_LSPACE: conf.rev_lspace = val; break;
206 case tREV_RSPACE: conf.rev_rspace = val; break;
207 case tREV_TSPACE: conf.rev_tspace = val; break;
208 case tREV_BSPACE: conf.rev_bspace = val; break;
209 case tREV_TEXT_FONT: conf.rev_text_font = get_font(val); break;
210 case tTAG_FONT: conf.tag_font = get_font(val); break;
211 case tTITLE_X: conf.title_x = val; break;
212 case tTITLE_Y: conf.title_y = val; break;
213 case tTITLE_FONT: conf.title_font = get_font(val); break;
214 case tTITLE_ALIGN: conf.title_align = val; break;
215 case tMARGIN_TOP: conf.margin_top = val; break;
216 case tMARGIN_BOTTOM: conf.margin_bottom = val; break;
217 case tMARGIN_LEFT: conf.margin_left = val; break;
218 case tMARGIN_RIGHT: conf.margin_right = val; break;
219 case tIMAGE_TYPE: conf.image_type = val; break;
220 case tIMAGE_QUALITY: conf.image_quality = bounds(val, 1, 100); break;
221 case tBOX_SHADOW: conf.box_shadow = val; break;
222 default:
223 yyerror("internal: Invalid num key %d -> %d", key, val);
224 }
225 }
226
227 static void assign_str(int key, char *str)
228 {
229 switch(key)
230 {
231 case tCVSMODULE: conf.cvsmodule = str; break;
232 case tCVSROOT: conf.cvsroot = str; break;
233 case tTITLE: conf.title = str; break;
234 case tDATE_FORMAT: conf.date_format = str; break;
235 case tMAP_NAME: conf.map_name = str; break;
236 case tMAP_BRANCH_HREF: conf.map_branch_href = str; break;
237 case tMAP_BRANCH_ALT: conf.map_branch_alt = str; break;
238 case tMAP_REV_HREF: conf.map_rev_href = str; break;
239 case tMAP_REV_ALT: conf.map_rev_alt = str; break;
240 case tMAP_DIFF_HREF: conf.map_diff_href = str; break;
241 case tMAP_DIFF_ALT: conf.map_diff_alt = str; break;
242 case tREV_TEXT: conf.rev_text = str; break;
243 default:
244 yyerror("internal: Invalid string key %d -> '%s'", key, str);
245 }
246 }
247
248 static void set_color(color_t *c, char *s)
249 {
250 char *cptr;
251 if(*s != '#' || strlen(s) != 7)
252 {
253 colorerror:
254 yyerror("Invalid color value");
255 }
256 c->b = strtol(s+5, &cptr, 16);
257 if(*cptr)
258 goto colorerror;
259 s[5] = '\0';
260 c->g = strtol(s+3, &cptr, 16);
261 if(*cptr)
262 goto colorerror;
263 s[3] = '\0';
264 c->r = strtol(s+1, &cptr, 16);
265 if(*cptr)
266 goto colorerror;
267 }
268
269 static void assign_color(int key, char *str)
270 {
271 switch(key)
272 {
273 case tCOLOR_BG: set_color(&conf.color_bg, str); break;
274 case tBRANCH_BGCOLOR: set_color(&conf.branch_bgcolor, str); break;
275 case tBRANCH_COLOR: set_color(&conf.branch_color, str); break;
276 case tREV_COLOR: set_color(&conf.rev_color, str); break;
277 case tREV_BGCOLOR: set_color(&conf.rev_bgcolor, str); break;
278 case tREV_TEXT_COLOR: set_color(&conf.rev_text_color, str); break;
279 case tTAG_COLOR: set_color(&conf.tag_color, str); break;
280 case tTITLE_COLOR: set_color(&conf.title_color, str); break;
281 default:
282 yyerror("internal: Invalid color key %d -> '%s'", key, str);
283 }
284 xfree(str);
285 }
286

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0