/[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.3 - (hide annotations)
Sat Feb 24 00:35:13 2001 UTC (16 years, 7 months ago) by bertho
Branch: MAIN
CVS Tags: REL_1_0_1
Changes since 1.2: +15 -0 lines
Fixed the soring of revisions permanently. All sections of the revision
numbers are important.
Implemented better control over libgd with autoconf and added support
for generation of png and jpeg from the configuration file (thanks to
Kurt L. Sussman for a patch, although I modified it a bit).
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     %}
44    
45     %union{
46     char *str;
47     int num;
48     }
49    
50     %token tBRANCH_BGCOLOR tBRANCH_BSPACE tBRANCH_COLOR tBRANCH_FONT tBRANCH_LSPACE tBRANCH_RSPACE tBRANCH_TSPACE tBRANCH_SEPARATOR
51     %token tCMD_RLOG tCOLOR_BG tCVSMODULE tCVSROOT
52     %token tREV_COLOR tREV_FONT tREV_SEPARATOR tREV_MINLINE tREV_MAXLINE tREV_LSPACE tREV_RSPACE tREV_TSPACE tREV_BSPACE
53     %token tTAG_COLOR tTAG_FONT
54     %token tTITLE tTITLE_X tTITLE_Y tTITLE_FONT tTITLE_ALIGN tTITLE_COLOR
55     %token tMARGIN_TOP tMARGIN_BOTTOM tMARGIN_LEFT tMARGIN_RIGHT
56 bertho 1.3 %token tIMAGE_TYPE tIMAGE_QUALITY
57 bertho 1.1 %token <str> tSTRING
58     %token <num> tNUMBER
59    
60     %type <num> ikey skey ckey
61    
62     %%
63     conffile: /* Empty */
64     | lines
65     ;
66    
67     lines : line
68     | lines line
69     ;
70    
71     line : ikey '=' tNUMBER ';' {
72     assign_num($1, $3);
73     }
74     | ikey '=' tNUMBER error { yyerror("Missing ';'"); }
75     | ikey '=' error { yyerror("Number expected"); }
76     | ikey error { yyerror("Missing '='"); }
77     | skey '=' tSTRING ';' {
78     assign_str($1, $3);
79     }
80     | skey '=' tSTRING error { yyerror("Missing ';'"); }
81     | skey '=' error { yyerror("String expected"); }
82     | skey error { yyerror("Missing '='"); }
83     | ckey '=' tSTRING ';' {
84     assign_color($1, $3);
85     }
86     | ckey '=' tSTRING error { yyerror("Missing ';'"); }
87     | ckey '=' error { yyerror("Color-string expected"); }
88     | ckey error { yyerror("Missing '='"); }
89     | error { yyerror("Keyword expected"); }
90     ;
91    
92     ikey : tBRANCH_FONT { $$ = tBRANCH_FONT; }
93     | tBRANCH_LSPACE { $$ = tBRANCH_LSPACE; }
94     | tBRANCH_RSPACE { $$ = tBRANCH_RSPACE; }
95     | tBRANCH_TSPACE { $$ = tBRANCH_TSPACE; }
96     | tBRANCH_BSPACE { $$ = tBRANCH_BSPACE; }
97     | tBRANCH_SEPARATOR { $$ = tBRANCH_SEPARATOR; }
98     | tREV_FONT { $$ = tREV_FONT; }
99     | tREV_SEPARATOR { $$ = tREV_SEPARATOR; }
100     | tREV_MINLINE { $$ = tREV_MINLINE; }
101     | tREV_MAXLINE { $$ = tREV_MAXLINE; }
102     | tREV_LSPACE { $$ = tREV_LSPACE; }
103     | tREV_RSPACE { $$ = tREV_RSPACE; }
104     | tREV_TSPACE { $$ = tREV_TSPACE; }
105     | tREV_BSPACE { $$ = tREV_BSPACE; }
106     | tTAG_FONT { $$ = tTAG_FONT; }
107     | tTITLE_X { $$ = tTITLE_X; }
108     | tTITLE_Y { $$ = tTITLE_Y; }
109     | tTITLE_FONT { $$ = tTITLE_FONT; }
110     | tTITLE_ALIGN { $$ = tTITLE_ALIGN; }
111     | tMARGIN_TOP { $$ = tMARGIN_TOP; }
112     | tMARGIN_BOTTOM { $$ = tMARGIN_BOTTOM; }
113     | tMARGIN_LEFT { $$ = tMARGIN_LEFT; }
114     | tMARGIN_RIGHT { $$ = tMARGIN_RIGHT; }
115 bertho 1.3 | tIMAGE_TYPE { $$ = tIMAGE_TYPE; }
116     | tIMAGE_QUALITY { $$ = tIMAGE_QUALITY; }
117 bertho 1.1 ;
118    
119     skey : tCMD_RLOG { $$ = tCMD_RLOG; }
120     | tCVSMODULE { $$ = tCVSMODULE; }
121     | tCVSROOT { $$ = tCVSROOT; }
122     | tTITLE { $$ = tTITLE; }
123     ;
124    
125     ckey : tCOLOR_BG { $$ = tCOLOR_BG; }
126     | tBRANCH_BGCOLOR { $$ = tBRANCH_BGCOLOR; }
127     | tBRANCH_COLOR { $$ = tBRANCH_COLOR; }
128     | tREV_COLOR { $$ = tREV_COLOR; }
129     | tTAG_COLOR { $$ = tTAG_COLOR; }
130     | tTITLE_COLOR { $$ = tTITLE_COLOR; }
131     ;
132    
133     %%
134    
135     static gdFontPtr get_font(int id)
136     {
137     switch(id)
138     {
139     case 0: return gdFontTiny;
140     case 1: return gdFontSmall;
141     default:
142     case 2: return gdFontMediumBold;
143     case 3: return gdFontLarge;
144     case 4: return gdFontGiant;
145     }
146     }
147    
148 bertho 1.3 static int bounds(int val, int mini, int maxi)
149     {
150     if(val < mini || val > maxi)
151     {
152     yywarning("Parameter must be between %d and %d", mini, maxi);
153     val = val < mini ? mini : maxi;
154     }
155     return val;
156     }
157    
158 bertho 1.1 static void assign_num(int key, int val)
159     {
160     switch(key)
161     {
162     case tBRANCH_FONT: conf.branch_font = get_font(val); break;
163     case tBRANCH_LSPACE: conf.branch_lspace = val; break;
164     case tBRANCH_RSPACE: conf.branch_rspace = val; break;
165     case tBRANCH_TSPACE: conf.branch_tspace = val; break;
166     case tBRANCH_BSPACE: conf.branch_bspace = val; break;
167     case tBRANCH_SEPARATOR: conf.branch_separator = val; break;
168     case tREV_FONT: conf.rev_font = get_font(val); break;
169     case tREV_SEPARATOR: conf.rev_separator = val; break;
170     case tREV_MINLINE: conf.rev_minline = val; break;
171     case tREV_MAXLINE: conf.rev_maxline = val; break;
172     case tREV_LSPACE: conf.rev_lspace = val; break;
173     case tREV_RSPACE: conf.rev_rspace = val; break;
174     case tREV_TSPACE: conf.rev_tspace = val; break;
175     case tREV_BSPACE: conf.rev_bspace = val; break;
176     case tTAG_FONT: conf.tag_font = get_font(val); break;
177     case tTITLE_X: conf.title_x = val; break;
178     case tTITLE_Y: conf.title_y = val; break;
179     case tTITLE_FONT: conf.title_font = get_font(val); break;
180     case tTITLE_ALIGN: conf.title_align = val; break;
181     case tMARGIN_TOP: conf.margin_top = val; break;
182     case tMARGIN_BOTTOM: conf.margin_bottom = val; break;
183     case tMARGIN_LEFT: conf.margin_left = val; break;
184     case tMARGIN_RIGHT: conf.margin_right = val; break;
185 bertho 1.3 case tIMAGE_TYPE: conf.image_type = val; break;
186     case tIMAGE_QUALITY: conf.image_quality = bounds(val, 1, 100); break;
187 bertho 1.1 default:
188     yyerror("internal: Invalid num key %d -> %d", key, val);
189     }
190     }
191    
192     static void assign_str(int key, char *str)
193     {
194     switch(key)
195     {
196     case tCMD_RLOG: conf.cmd_rlog = str; break;
197     case tCVSMODULE: conf.cvsmodule = str; break;
198     case tCVSROOT: conf.cvsroot = str; break;
199     case tTITLE: conf.title = str; break;
200     default:
201     yyerror("internal: Invalid string key %d -> '%s'", key, str);
202     }
203     }
204    
205     static void set_color(color_t *c, char *s)
206     {
207     char *cptr;
208     if(*s != '#' || strlen(s) != 7)
209     {
210     colorerror:
211     yyerror("Invalid color value");
212     }
213     c->b = strtol(s+5, &cptr, 16);
214     if(*cptr)
215     goto colorerror;
216     s[5] = '\0';
217     c->g = strtol(s+3, &cptr, 16);
218     if(*cptr)
219     goto colorerror;
220     s[3] = '\0';
221     c->r = strtol(s+1, &cptr, 16);
222     if(*cptr)
223     goto colorerror;
224     }
225    
226     static void assign_color(int key, char *str)
227     {
228     switch(key)
229     {
230     case tCOLOR_BG: set_color(&conf.color_bg, str); break;
231     case tBRANCH_BGCOLOR: set_color(&conf.branch_bgcolor, str); break;
232     case tBRANCH_COLOR: set_color(&conf.branch_color, str); break;
233     case tREV_COLOR: set_color(&conf.rev_color, str); break;
234     case tTAG_COLOR: set_color(&conf.tag_color, str); break;
235     case tTITLE_COLOR: set_color(&conf.title_color, str); break;
236     default:
237     yyerror("internal: Invalid color key %d -> '%s'", key, str);
238     }
239     xfree(str);
240     }
241    

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0