/[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.5 - (hide annotations)
Sun Mar 4 01:38:23 2001 UTC (16 years, 9 months ago) by bertho
Branch: MAIN
Changes since 1.4: +29 -22 lines
Major update of the code.
- Complete new method of getting the revision structure by directly
  reading the rcs/cvs file. This should also speed things a bit
  because no external program needs to be called anymore.
  This also means that "remote-graphs" are no longer a possible
  extension of the program. But, who cares.
- Implemented branch-kerning to save place. The images are now
  much smaller in width, dependent on the settings of the exterior
  margins.
- Fixed disjoint braches by reading the structure direct from the
  rcs/cvs file. The revision/branch structure is no longer determined
  from the revision numbers, but solely from the rcs/cvs file structure.
- Fixed display of branches with no revisions attached to them. These
  only have a tag describing the new branch.
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     %token tBRANCH_CONNECT tBRANCH_MARGIN
55     %token tCOLOR_BG tCVSMODULE tCVSROOT
56 bertho 1.1 %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 bertho 1.3 %token tIMAGE_TYPE tIMAGE_QUALITY
61 bertho 1.4 %token tMAP_NAME tMAP_BRANCH tMAP_REV
62 bertho 1.5 %token <str> tUNKNOWN
63 bertho 1.1 %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 bertho 1.5 line : ikey '=' tNUMBER ';' { assign_num($1, $3); }
78     | ikey '=' tNUMBER error { yyerror(err_semicolon); }
79 bertho 1.1 | ikey '=' error { yyerror("Number expected"); }
80 bertho 1.5 | ikey error { yyerror(err_assign); }
81     | skey '=' tSTRING ';' { assign_str($1, $3); }
82     | skey '=' tSTRING error { yyerror(err_semicolon); }
83 bertho 1.1 | skey '=' error { yyerror("String expected"); }
84 bertho 1.5 | skey error { yyerror(err_assign); }
85     | ckey '=' tSTRING ';' { assign_color($1, $3); }
86     | ckey '=' tSTRING error { yyerror(err_semicolon); }
87 bertho 1.1 | ckey '=' error { yyerror("Color-string expected"); }
88 bertho 1.5 | 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 bertho 1.1 | error { yyerror("Keyword expected"); }
94     ;
95    
96 bertho 1.5 notsc : tSTRING { xfree($1); }
97     | tNUMBER {}
98     ;
99    
100 bertho 1.1 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 bertho 1.5 | tBRANCH_CONNECT { $$ = tBRANCH_CONNECT; }
106     | tBRANCH_MARGIN { $$ = tBRANCH_MARGIN; }
107 bertho 1.1 | 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 bertho 1.3 | tIMAGE_TYPE { $$ = tIMAGE_TYPE; }
125     | tIMAGE_QUALITY { $$ = tIMAGE_QUALITY; }
126 bertho 1.1 ;
127    
128 bertho 1.5 skey : tCVSMODULE { $$ = tCVSMODULE; }
129 bertho 1.1 | tCVSROOT { $$ = tCVSROOT; }
130     | tTITLE { $$ = tTITLE; }
131 bertho 1.4 | tMAP_NAME { $$ = tMAP_NAME; }
132     | tMAP_BRANCH { $$ = tMAP_BRANCH; }
133     | tMAP_REV { $$ = tMAP_REV; }
134 bertho 1.1 ;
135    
136     ckey : tCOLOR_BG { $$ = tCOLOR_BG; }
137     | tBRANCH_BGCOLOR { $$ = tBRANCH_BGCOLOR; }
138     | tBRANCH_COLOR { $$ = tBRANCH_COLOR; }
139     | tREV_COLOR { $$ = tREV_COLOR; }
140     | tTAG_COLOR { $$ = tTAG_COLOR; }
141     | tTITLE_COLOR { $$ = tTITLE_COLOR; }
142     ;
143    
144     %%
145    
146     static gdFontPtr get_font(int id)
147     {
148     switch(id)
149     {
150     case 0: return gdFontTiny;
151     case 1: return gdFontSmall;
152     default:
153     case 2: return gdFontMediumBold;
154     case 3: return gdFontLarge;
155     case 4: return gdFontGiant;
156     }
157     }
158    
159 bertho 1.3 static int bounds(int val, int mini, int maxi)
160     {
161     if(val < mini || val > maxi)
162     {
163     yywarning("Parameter must be between %d and %d", mini, maxi);
164     val = val < mini ? mini : maxi;
165     }
166     return val;
167     }
168    
169 bertho 1.1 static void assign_num(int key, int val)
170     {
171     switch(key)
172     {
173     case tBRANCH_FONT: conf.branch_font = get_font(val); break;
174     case tBRANCH_LSPACE: conf.branch_lspace = val; break;
175     case tBRANCH_RSPACE: conf.branch_rspace = val; break;
176     case tBRANCH_TSPACE: conf.branch_tspace = val; break;
177     case tBRANCH_BSPACE: conf.branch_bspace = val; break;
178 bertho 1.5 case tBRANCH_CONNECT: conf.branch_connect = val; break;
179     case tBRANCH_MARGIN: conf.branch_margin = val; break;
180 bertho 1.1 case tREV_FONT: conf.rev_font = get_font(val); break;
181     case tREV_SEPARATOR: conf.rev_separator = val; break;
182     case tREV_MINLINE: conf.rev_minline = val; break;
183     case tREV_MAXLINE: conf.rev_maxline = val; break;
184     case tREV_LSPACE: conf.rev_lspace = val; break;
185     case tREV_RSPACE: conf.rev_rspace = val; break;
186     case tREV_TSPACE: conf.rev_tspace = val; break;
187     case tREV_BSPACE: conf.rev_bspace = val; break;
188     case tTAG_FONT: conf.tag_font = get_font(val); break;
189     case tTITLE_X: conf.title_x = val; break;
190     case tTITLE_Y: conf.title_y = val; break;
191     case tTITLE_FONT: conf.title_font = get_font(val); break;
192     case tTITLE_ALIGN: conf.title_align = val; break;
193     case tMARGIN_TOP: conf.margin_top = val; break;
194     case tMARGIN_BOTTOM: conf.margin_bottom = val; break;
195     case tMARGIN_LEFT: conf.margin_left = val; break;
196     case tMARGIN_RIGHT: conf.margin_right = val; break;
197 bertho 1.3 case tIMAGE_TYPE: conf.image_type = val; break;
198     case tIMAGE_QUALITY: conf.image_quality = bounds(val, 1, 100); break;
199 bertho 1.1 default:
200     yyerror("internal: Invalid num key %d -> %d", key, val);
201     }
202     }
203    
204     static void assign_str(int key, char *str)
205     {
206     switch(key)
207     {
208     case tCVSMODULE: conf.cvsmodule = str; break;
209     case tCVSROOT: conf.cvsroot = str; break;
210     case tTITLE: conf.title = str; break;
211 bertho 1.4 case tMAP_NAME: conf.map_name = str; break;
212     case tMAP_BRANCH: conf.map_branch = str; break;
213     case tMAP_REV: conf.map_rev = str; break;
214 bertho 1.1 default:
215     yyerror("internal: Invalid string key %d -> '%s'", key, str);
216     }
217     }
218    
219     static void set_color(color_t *c, char *s)
220     {
221     char *cptr;
222     if(*s != '#' || strlen(s) != 7)
223     {
224     colorerror:
225     yyerror("Invalid color value");
226     }
227     c->b = strtol(s+5, &cptr, 16);
228     if(*cptr)
229     goto colorerror;
230     s[5] = '\0';
231     c->g = strtol(s+3, &cptr, 16);
232     if(*cptr)
233     goto colorerror;
234     s[3] = '\0';
235     c->r = strtol(s+1, &cptr, 16);
236     if(*cptr)
237     goto colorerror;
238     }
239    
240     static void assign_color(int key, char *str)
241     {
242     switch(key)
243     {
244     case tCOLOR_BG: set_color(&conf.color_bg, str); break;
245     case tBRANCH_BGCOLOR: set_color(&conf.branch_bgcolor, str); break;
246     case tBRANCH_COLOR: set_color(&conf.branch_color, str); break;
247     case tREV_COLOR: set_color(&conf.rev_color, str); break;
248     case tTAG_COLOR: set_color(&conf.tag_color, str); break;
249     case tTITLE_COLOR: set_color(&conf.title_color, str); break;
250     default:
251     yyerror("internal: Invalid color key %d -> '%s'", key, str);
252     }
253     xfree(str);
254     }
255    

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0