/[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.6 - (show annotations)
Sun Mar 4 03:19:18 2001 UTC (16 years, 8 months ago) by bertho
Branch: MAIN
CVS Tags: REL_1_1_0
Changes since 1.5: +9 -5 lines
Basic imagemap stuff done. The expansion code needs some work to allow
for conditional expansion.
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
55 %token tCOLOR_BG tCVSMODULE tCVSROOT
56 %token tREV_COLOR tREV_FONT tREV_SEPARATOR tREV_MINLINE tREV_MAXLINE tREV_LSPACE tREV_RSPACE tREV_TSPACE tREV_BSPACE
57 %token tTAG_COLOR tTAG_FONT
58 %token tTITLE tTITLE_X tTITLE_Y tTITLE_FONT tTITLE_ALIGN tTITLE_COLOR
59 %token tMARGIN_TOP tMARGIN_BOTTOM tMARGIN_LEFT tMARGIN_RIGHT
60 %token tIMAGE_TYPE tIMAGE_QUALITY
61 %token tMAP_NAME tMAP_BRANCH_HREF tMAP_BRANCH_ALT tMAP_REV_HREF tMAP_REV_ALT
62 %token <str> tUNKNOWN
63 %token <str> tSTRING
64 %token <num> tNUMBER
65
66 %type <num> ikey skey ckey
67
68 %%
69 conffile: /* Empty */
70 | lines
71 ;
72
73 lines : line
74 | lines line
75 ;
76
77 line : ikey '=' tNUMBER ';' { assign_num($1, $3); }
78 | ikey '=' tNUMBER error { yyerror(err_semicolon); }
79 | ikey '=' error { yyerror("Number expected"); }
80 | ikey error { yyerror(err_assign); }
81 | skey '=' tSTRING ';' { assign_str($1, $3); }
82 | skey '=' tSTRING error { yyerror(err_semicolon); }
83 | skey '=' error { yyerror("String expected"); }
84 | skey error { yyerror(err_assign); }
85 | ckey '=' tSTRING ';' { assign_color($1, $3); }
86 | ckey '=' tSTRING error { yyerror(err_semicolon); }
87 | ckey '=' error { yyerror("Color-string expected"); }
88 | ckey error { yyerror(err_assign); }
89 | tUNKNOWN '=' notsc ';' { yywarning("Unknown config parameter '%s' ignored", $1); xfree($1); }
90 | tUNKNOWN '=' notsc error { yyerror(err_semicolon); }
91 | tUNKNOWN '=' error { yyerror("String or number expected"); }
92 | tUNKNOWN error { yyerror(err_assign); }
93 | error { yyerror("Keyword expected"); }
94 ;
95
96 notsc : tSTRING { xfree($1); }
97 | tNUMBER {}
98 ;
99
100 ikey : tBRANCH_FONT { $$ = tBRANCH_FONT; }
101 | tBRANCH_LSPACE { $$ = tBRANCH_LSPACE; }
102 | tBRANCH_RSPACE { $$ = tBRANCH_RSPACE; }
103 | tBRANCH_TSPACE { $$ = tBRANCH_TSPACE; }
104 | tBRANCH_BSPACE { $$ = tBRANCH_BSPACE; }
105 | tBRANCH_CONNECT { $$ = tBRANCH_CONNECT; }
106 | tBRANCH_MARGIN { $$ = tBRANCH_MARGIN; }
107 | tREV_FONT { $$ = tREV_FONT; }
108 | tREV_SEPARATOR { $$ = tREV_SEPARATOR; }
109 | tREV_MINLINE { $$ = tREV_MINLINE; }
110 | tREV_MAXLINE { $$ = tREV_MAXLINE; }
111 | tREV_LSPACE { $$ = tREV_LSPACE; }
112 | tREV_RSPACE { $$ = tREV_RSPACE; }
113 | tREV_TSPACE { $$ = tREV_TSPACE; }
114 | tREV_BSPACE { $$ = tREV_BSPACE; }
115 | tTAG_FONT { $$ = tTAG_FONT; }
116 | tTITLE_X { $$ = tTITLE_X; }
117 | tTITLE_Y { $$ = tTITLE_Y; }
118 | tTITLE_FONT { $$ = tTITLE_FONT; }
119 | tTITLE_ALIGN { $$ = tTITLE_ALIGN; }
120 | tMARGIN_TOP { $$ = tMARGIN_TOP; }
121 | tMARGIN_BOTTOM { $$ = tMARGIN_BOTTOM; }
122 | tMARGIN_LEFT { $$ = tMARGIN_LEFT; }
123 | tMARGIN_RIGHT { $$ = tMARGIN_RIGHT; }
124 | tIMAGE_TYPE { $$ = tIMAGE_TYPE; }
125 | tIMAGE_QUALITY { $$ = tIMAGE_QUALITY; }
126 ;
127
128 skey : tCVSMODULE { $$ = tCVSMODULE; }
129 | tCVSROOT { $$ = tCVSROOT; }
130 | tTITLE { $$ = tTITLE; }
131 | tMAP_NAME { $$ = tMAP_NAME; }
132 | tMAP_BRANCH_HREF { $$ = tMAP_BRANCH_HREF; }
133 | tMAP_BRANCH_ALT { $$ = tMAP_BRANCH_ALT; }
134 | tMAP_REV_HREF { $$ = tMAP_REV_HREF; }
135 | tMAP_REV_ALT { $$ = tMAP_REV_ALT; }
136 ;
137
138 ckey : tCOLOR_BG { $$ = tCOLOR_BG; }
139 | tBRANCH_BGCOLOR { $$ = tBRANCH_BGCOLOR; }
140 | tBRANCH_COLOR { $$ = tBRANCH_COLOR; }
141 | tREV_COLOR { $$ = tREV_COLOR; }
142 | tTAG_COLOR { $$ = tTAG_COLOR; }
143 | tTITLE_COLOR { $$ = tTITLE_COLOR; }
144 ;
145
146 %%
147
148 static gdFontPtr get_font(int id)
149 {
150 switch(id)
151 {
152 case 0: return gdFontTiny;
153 case 1: return gdFontSmall;
154 default:
155 case 2: return gdFontMediumBold;
156 case 3: return gdFontLarge;
157 case 4: return gdFontGiant;
158 }
159 }
160
161 static int bounds(int val, int mini, int maxi)
162 {
163 if(val < mini || val > maxi)
164 {
165 yywarning("Parameter must be between %d and %d", mini, maxi);
166 val = val < mini ? mini : maxi;
167 }
168 return val;
169 }
170
171 static void assign_num(int key, int val)
172 {
173 switch(key)
174 {
175 case tBRANCH_FONT: conf.branch_font = get_font(val); break;
176 case tBRANCH_LSPACE: conf.branch_lspace = val; break;
177 case tBRANCH_RSPACE: conf.branch_rspace = val; break;
178 case tBRANCH_TSPACE: conf.branch_tspace = val; break;
179 case tBRANCH_BSPACE: conf.branch_bspace = val; break;
180 case tBRANCH_CONNECT: conf.branch_connect = val; break;
181 case tBRANCH_MARGIN: conf.branch_margin = val; break;
182 case tREV_FONT: conf.rev_font = get_font(val); break;
183 case tREV_SEPARATOR: conf.rev_separator = val; break;
184 case tREV_MINLINE: conf.rev_minline = val; break;
185 case tREV_MAXLINE: conf.rev_maxline = val; break;
186 case tREV_LSPACE: conf.rev_lspace = val; break;
187 case tREV_RSPACE: conf.rev_rspace = val; break;
188 case tREV_TSPACE: conf.rev_tspace = val; break;
189 case tREV_BSPACE: conf.rev_bspace = val; break;
190 case tTAG_FONT: conf.tag_font = get_font(val); break;
191 case tTITLE_X: conf.title_x = val; break;
192 case tTITLE_Y: conf.title_y = val; break;
193 case tTITLE_FONT: conf.title_font = get_font(val); break;
194 case tTITLE_ALIGN: conf.title_align = val; break;
195 case tMARGIN_TOP: conf.margin_top = val; break;
196 case tMARGIN_BOTTOM: conf.margin_bottom = val; break;
197 case tMARGIN_LEFT: conf.margin_left = val; break;
198 case tMARGIN_RIGHT: conf.margin_right = val; break;
199 case tIMAGE_TYPE: conf.image_type = val; break;
200 case tIMAGE_QUALITY: conf.image_quality = bounds(val, 1, 100); break;
201 default:
202 yyerror("internal: Invalid num key %d -> %d", key, val);
203 }
204 }
205
206 static void assign_str(int key, char *str)
207 {
208 switch(key)
209 {
210 case tCVSMODULE: conf.cvsmodule = str; break;
211 case tCVSROOT: conf.cvsroot = str; break;
212 case tTITLE: conf.title = str; break;
213 case tMAP_NAME: conf.map_name = str; break;
214 case tMAP_BRANCH_HREF: conf.map_branch_href = str; break;
215 case tMAP_BRANCH_ALT: conf.map_branch_alt = str; break;
216 case tMAP_REV_HREF: conf.map_rev_href = str; break;
217 case tMAP_REV_ALT: conf.map_rev_alt = str; break;
218 default:
219 yyerror("internal: Invalid string key %d -> '%s'", key, str);
220 }
221 }
222
223 static void set_color(color_t *c, char *s)
224 {
225 char *cptr;
226 if(*s != '#' || strlen(s) != 7)
227 {
228 colorerror:
229 yyerror("Invalid color value");
230 }
231 c->b = strtol(s+5, &cptr, 16);
232 if(*cptr)
233 goto colorerror;
234 s[5] = '\0';
235 c->g = strtol(s+3, &cptr, 16);
236 if(*cptr)
237 goto colorerror;
238 s[3] = '\0';
239 c->r = strtol(s+1, &cptr, 16);
240 if(*cptr)
241 goto colorerror;
242 }
243
244 static void assign_color(int key, char *str)
245 {
246 switch(key)
247 {
248 case tCOLOR_BG: set_color(&conf.color_bg, str); break;
249 case tBRANCH_BGCOLOR: set_color(&conf.branch_bgcolor, str); break;
250 case tBRANCH_COLOR: set_color(&conf.branch_color, str); break;
251 case tREV_COLOR: set_color(&conf.rev_color, str); break;
252 case tTAG_COLOR: set_color(&conf.tag_color, str); break;
253 case tTITLE_COLOR: set_color(&conf.title_color, str); break;
254 default:
255 yyerror("internal: Invalid color key %d -> '%s'", key, str);
256 }
257 xfree(str);
258 }
259

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0