/[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.8 - (hide annotations)
Tue Dec 18 22:50:12 2001 UTC (15 years, 10 months ago) by bertho
Branch: MAIN
Changes since 1.7: +8 -2 lines
- Added upside-down imaging of the tree
- Added extra branch-box at the bottom/top of the trunk
- Added stripping of untagged revisions
1 bertho 1.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 bertho 1.2 #include <string.h>
26 bertho 1.1
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 bertho 1.5 static const char err_semicolon[] = "Missing ';'";
44     static const char err_assign[] = "Missing '='";
45    
46 bertho 1.1 %}
47    
48     %union{
49     char *str;
50     int num;
51     }
52    
53 bertho 1.5 %token tBRANCH_BGCOLOR tBRANCH_BSPACE tBRANCH_COLOR tBRANCH_FONT tBRANCH_LSPACE tBRANCH_RSPACE tBRANCH_TSPACE
54 bertho 1.8 %token tBRANCH_CONNECT tBRANCH_MARGIN tBRANCH_MIRROR tUPSIDE_DOWN
55     %token tCOLOR_BG tCVSMODULE tCVSROOT tDATE_FORMAT tBOX_SHADOW tSTRIP_UNTAGGED
56 bertho 1.7 %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 bertho 1.1 %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 bertho 1.3 %token tIMAGE_TYPE tIMAGE_QUALITY
62 bertho 1.7 %token tMAP_NAME tMAP_BRANCH_HREF tMAP_BRANCH_ALT tMAP_REV_HREF tMAP_REV_ALT tMAP_DIFF_HREF tMAP_DIFF_ALT
63 bertho 1.5 %token <str> tUNKNOWN
64 bertho 1.1 %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 bertho 1.5 line : ikey '=' tNUMBER ';' { assign_num($1, $3); }
79     | ikey '=' tNUMBER error { yyerror(err_semicolon); }
80 bertho 1.1 | ikey '=' error { yyerror("Number expected"); }
81 bertho 1.5 | ikey error { yyerror(err_assign); }
82     | skey '=' tSTRING ';' { assign_str($1, $3); }
83     | skey '=' tSTRING error { yyerror(err_semicolon); }
84 bertho 1.1 | skey '=' error { yyerror("String expected"); }
85 bertho 1.5 | skey error { yyerror(err_assign); }
86     | ckey '=' tSTRING ';' { assign_color($1, $3); }
87     | ckey '=' tSTRING error { yyerror(err_semicolon); }
88 bertho 1.1 | ckey '=' error { yyerror("Color-string expected"); }
89 bertho 1.5 | 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 bertho 1.1 | error { yyerror("Keyword expected"); }
95     ;
96    
97 bertho 1.5 notsc : tSTRING { xfree($1); }
98     | tNUMBER {}
99     ;
100    
101 bertho 1.1 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 bertho 1.5 | tBRANCH_CONNECT { $$ = tBRANCH_CONNECT; }
107     | tBRANCH_MARGIN { $$ = tBRANCH_MARGIN; }
108 bertho 1.8 | tBRANCH_MIRROR { $$ = tBRANCH_MIRROR; }
109     | tUPSIDE_DOWN { $$ = tUPSIDE_DOWN; }
110     | tSTRIP_UNTAGGED { $$ = tSTRIP_UNTAGGED; }
111 bertho 1.1 | tREV_FONT { $$ = tREV_FONT; }
112     | tREV_SEPARATOR { $$ = tREV_SEPARATOR; }
113     | tREV_MINLINE { $$ = tREV_MINLINE; }
114     | tREV_MAXLINE { $$ = tREV_MAXLINE; }
115     | tREV_LSPACE { $$ = tREV_LSPACE; }
116     | tREV_RSPACE { $$ = tREV_RSPACE; }
117     | tREV_TSPACE { $$ = tREV_TSPACE; }
118     | tREV_BSPACE { $$ = tREV_BSPACE; }
119 bertho 1.7 | tREV_TEXT_FONT { $$ = tREV_TEXT_FONT; }
120 bertho 1.1 | tTAG_FONT { $$ = tTAG_FONT; }
121     | tTITLE_X { $$ = tTITLE_X; }
122     | tTITLE_Y { $$ = tTITLE_Y; }
123     | tTITLE_FONT { $$ = tTITLE_FONT; }
124     | tTITLE_ALIGN { $$ = tTITLE_ALIGN; }
125     | tMARGIN_TOP { $$ = tMARGIN_TOP; }
126     | tMARGIN_BOTTOM { $$ = tMARGIN_BOTTOM; }
127     | tMARGIN_LEFT { $$ = tMARGIN_LEFT; }
128     | tMARGIN_RIGHT { $$ = tMARGIN_RIGHT; }
129 bertho 1.3 | tIMAGE_TYPE { $$ = tIMAGE_TYPE; }
130     | tIMAGE_QUALITY { $$ = tIMAGE_QUALITY; }
131 bertho 1.7 | tBOX_SHADOW { $$ = tBOX_SHADOW; }
132 bertho 1.1 ;
133    
134 bertho 1.5 skey : tCVSMODULE { $$ = tCVSMODULE; }
135 bertho 1.1 | tCVSROOT { $$ = tCVSROOT; }
136     | tTITLE { $$ = tTITLE; }
137 bertho 1.7 | tDATE_FORMAT { $$ = tDATE_FORMAT; }
138 bertho 1.4 | tMAP_NAME { $$ = tMAP_NAME; }
139 bertho 1.6 | tMAP_BRANCH_HREF { $$ = tMAP_BRANCH_HREF; }
140     | tMAP_BRANCH_ALT { $$ = tMAP_BRANCH_ALT; }
141     | tMAP_REV_HREF { $$ = tMAP_REV_HREF; }
142     | tMAP_REV_ALT { $$ = tMAP_REV_ALT; }
143 bertho 1.7 | tMAP_DIFF_HREF { $$ = tMAP_DIFF_HREF; }
144     | tMAP_DIFF_ALT { $$ = tMAP_DIFF_ALT; }
145     | tREV_TEXT { $$ = tREV_TEXT; }
146 bertho 1.1 ;
147    
148     ckey : tCOLOR_BG { $$ = tCOLOR_BG; }
149     | tBRANCH_BGCOLOR { $$ = tBRANCH_BGCOLOR; }
150     | tBRANCH_COLOR { $$ = tBRANCH_COLOR; }
151     | tREV_COLOR { $$ = tREV_COLOR; }
152 bertho 1.7 | tREV_BGCOLOR { $$ = tREV_BGCOLOR; }
153     | tREV_TEXT_COLOR { $$ = tREV_TEXT_COLOR; }
154 bertho 1.1 | tTAG_COLOR { $$ = tTAG_COLOR; }
155     | tTITLE_COLOR { $$ = tTITLE_COLOR; }
156     ;
157    
158     %%
159    
160     static gdFontPtr get_font(int id)
161     {
162     switch(id)
163     {
164     case 0: return gdFontTiny;
165     case 1: return gdFontSmall;
166     default:
167     case 2: return gdFontMediumBold;
168     case 3: return gdFontLarge;
169     case 4: return gdFontGiant;
170     }
171     }
172    
173 bertho 1.3 static int bounds(int val, int mini, int maxi)
174     {
175     if(val < mini || val > maxi)
176     {
177     yywarning("Parameter must be between %d and %d", mini, maxi);
178     val = val < mini ? mini : maxi;
179     }
180     return val;
181     }
182    
183 bertho 1.1 static void assign_num(int key, int val)
184     {
185     switch(key)
186     {
187     case tBRANCH_FONT: conf.branch_font = get_font(val); break;
188     case tBRANCH_LSPACE: conf.branch_lspace = val; break;
189     case tBRANCH_RSPACE: conf.branch_rspace = val; break;
190     case tBRANCH_TSPACE: conf.branch_tspace = val; break;
191     case tBRANCH_BSPACE: conf.branch_bspace = val; break;
192 bertho 1.5 case tBRANCH_CONNECT: conf.branch_connect = val; break;
193     case tBRANCH_MARGIN: conf.branch_margin = val; break;
194 bertho 1.8 case tBRANCH_MIRROR: conf.branch_mirror = val; break;
195     case tUPSIDE_DOWN: conf.upside_down = val; break;
196     case tSTRIP_UNTAGGED: conf.strip_untagged = val; break;
197 bertho 1.1 case tREV_FONT: conf.rev_font = get_font(val); break;
198     case tREV_SEPARATOR: conf.rev_separator = val; break;
199     case tREV_MINLINE: conf.rev_minline = val; break;
200     case tREV_MAXLINE: conf.rev_maxline = val; break;
201     case tREV_LSPACE: conf.rev_lspace = val; break;
202     case tREV_RSPACE: conf.rev_rspace = val; break;
203     case tREV_TSPACE: conf.rev_tspace = val; break;
204     case tREV_BSPACE: conf.rev_bspace = val; break;
205 bertho 1.7 case tREV_TEXT_FONT: conf.rev_text_font = get_font(val); break;
206 bertho 1.1 case tTAG_FONT: conf.tag_font = get_font(val); break;
207     case tTITLE_X: conf.title_x = val; break;
208     case tTITLE_Y: conf.title_y = val; break;
209     case tTITLE_FONT: conf.title_font = get_font(val); break;
210     case tTITLE_ALIGN: conf.title_align = val; break;
211     case tMARGIN_TOP: conf.margin_top = val; break;
212     case tMARGIN_BOTTOM: conf.margin_bottom = val; break;
213     case tMARGIN_LEFT: conf.margin_left = val; break;
214     case tMARGIN_RIGHT: conf.margin_right = val; break;
215 bertho 1.3 case tIMAGE_TYPE: conf.image_type = val; break;
216     case tIMAGE_QUALITY: conf.image_quality = bounds(val, 1, 100); break;
217 bertho 1.7 case tBOX_SHADOW: conf.box_shadow = val; break;
218 bertho 1.1 default:
219     yyerror("internal: Invalid num key %d -> %d", key, val);
220     }
221     }
222    
223     static void assign_str(int key, char *str)
224     {
225     switch(key)
226     {
227     case tCVSMODULE: conf.cvsmodule = str; break;
228     case tCVSROOT: conf.cvsroot = str; break;
229     case tTITLE: conf.title = str; break;
230 bertho 1.7 case tDATE_FORMAT: conf.date_format = str; break;
231 bertho 1.4 case tMAP_NAME: conf.map_name = str; break;
232 bertho 1.6 case tMAP_BRANCH_HREF: conf.map_branch_href = str; break;
233     case tMAP_BRANCH_ALT: conf.map_branch_alt = str; break;
234     case tMAP_REV_HREF: conf.map_rev_href = str; break;
235     case tMAP_REV_ALT: conf.map_rev_alt = str; break;
236 bertho 1.7 case tMAP_DIFF_HREF: conf.map_diff_href = str; break;
237     case tMAP_DIFF_ALT: conf.map_diff_alt = str; break;
238     case tREV_TEXT: conf.rev_text = str; break;
239 bertho 1.1 default:
240     yyerror("internal: Invalid string key %d -> '%s'", key, str);
241     }
242     }
243    
244     static void set_color(color_t *c, char *s)
245     {
246     char *cptr;
247     if(*s != '#' || strlen(s) != 7)
248     {
249     colorerror:
250     yyerror("Invalid color value");
251     }
252     c->b = strtol(s+5, &cptr, 16);
253     if(*cptr)
254     goto colorerror;
255     s[5] = '\0';
256     c->g = strtol(s+3, &cptr, 16);
257     if(*cptr)
258     goto colorerror;
259     s[3] = '\0';
260     c->r = strtol(s+1, &cptr, 16);
261     if(*cptr)
262     goto colorerror;
263     }
264    
265     static void assign_color(int key, char *str)
266     {
267     switch(key)
268     {
269     case tCOLOR_BG: set_color(&conf.color_bg, str); break;
270     case tBRANCH_BGCOLOR: set_color(&conf.branch_bgcolor, str); break;
271     case tBRANCH_COLOR: set_color(&conf.branch_color, str); break;
272     case tREV_COLOR: set_color(&conf.rev_color, str); break;
273 bertho 1.7 case tREV_BGCOLOR: set_color(&conf.rev_bgcolor, str); break;
274     case tREV_TEXT_COLOR: set_color(&conf.rev_text_color, str); break;
275 bertho 1.1 case tTAG_COLOR: set_color(&conf.tag_color, str); break;
276     case tTITLE_COLOR: set_color(&conf.title_color, str); break;
277     default:
278     yyerror("internal: Invalid color key %d -> '%s'", key, str);
279     }
280     xfree(str);
281     }
282    

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0