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

Annotate of /cvsgraph/rcsy.y

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


Revision 1.7 - (hide annotations)
Thu Aug 5 09:48:32 2004 UTC (13 years, 4 months ago) by bertho
Branch: MAIN
CVS Tags: REL_1_5_0
Changes since 1.6: +1 -0 lines
Make sure that the HEAD tag doesn't get zapped by tag_ignore/tag_negate
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 bertho 1.3 #define YYERROR_VERBOSE 1
24    
25 bertho 1.1 #include <stdio.h>
26     #include <stdlib.h>
27     #include <string.h>
28     #include <assert.h>
29    
30 bertho 1.4 #include <gd.h> /* For gdFontPtr in cvsgraph.h */
31     #include "cvsgraph.h"
32 bertho 1.1 #include "utils.h"
33     #include "rcs.h"
34    
35     rcsfile_t *rcsfile;
36    
37     static tag_t *new_tag(char *s, char *r);
38     static tags_t *new_tags(tag_t *s);
39     static tags_t *add_tags(tags_t *s, tag_t *t);
40     static idrev_t *new_idrev(char *s, char *r);
41     static idrevs_t *new_idrevs(idrev_t *s);
42     static idrevs_t *add_idrevs(idrevs_t *s, idrev_t *t);
43     static ids_t *new_ids(char *s);
44     static ids_t *add_ids(ids_t *s, char *t);
45     static revs_t *new_revs(char *s);
46     static revs_t *add_revs(revs_t *s, char *t);
47     static dtext_t *new_dtext(char *n, char *l, char *t);
48     static dtexts_t *add_dtexts(dtexts_t *s, dtext_t *t);
49     static delta_t *new_delta(char *rev, char *date, char *author, char *state, revs_t *branches, char *next);
50     static deltas_t *add_deltas(deltas_t *s, delta_t *t);
51     static rcsfile_t *new_rcsfile(char *head, char *branch, ids_t *access, tags_t *tags,
52     idrevs_t *locks, int strict, char *comment, char *expand);
53    
54     %}
55    
56     %union{
57     int i;
58     char *str;
59     tag_t *tag;
60     tags_t *tags;
61     idrev_t *idrev;
62     idrevs_t *idrevs;
63     ids_t *ids;
64     revs_t *revs;
65     dtext_t *dtext;
66     dtexts_t *dtexts;
67     delta_t *delta;
68     deltas_t *deltas;
69     rcsfile_t *rcsfile;
70     }
71    
72     %token tHEAD tBRANCH tACCESS tSYMBOLS tLOCKS tSTRICT tCOMMENT
73     %token tEXPAND tDATE tAUTHOR tSTATE tBRANCHES tNEXT
74     %token tDESC tLOG tTEXT
75     %token tOWNER tGROUP tPERMISSIONS tSPECIAL tSYMLINK tHARDLINKS
76     %token tNAMESPACE tDEAD
77     %token <str> tNEWPHRASE
78     %token <str> tSTRING tREV tID tSYM
79    
80    
81 bertho 1.5 %type <str> ostr orev oid obranch ocomment oexpand desc idorstr
82 bertho 1.1 %type <tag> tag
83     %type <tags> tags otags
84     %type <idrev> idrev
85     %type <idrevs> idrevs oidrevs
86     %type <ids> ids oids
87     %type <revs> revs orevs
88     %type <i> ostrict
89     %type <dtext> dtext
90     %type <dtexts> dtexts
91     %type <delta> delta
92     %type <deltas> deltas
93     %type <rcsfile> admin
94    
95     %%
96 bertho 1.4 rcsfile : admin deltas desc {
97 bertho 1.1 rcsfile = $1;
98     rcsfile->deltas = $2;
99     rcsfile->desc = $3;
100 bertho 1.4 rcsfile->dtexts = NULL;
101 bertho 1.1 if(rcsfile->head)
102     {
103     char *h = xstrdup("HEAD");
104     char *r = xstrdup(rcsfile->head->rev);
105     tag_t *t = new_tag(h, r);
106 bertho 1.7 t->ignore = -1; /* Make sure it doesn't get zapped */
107 bertho 1.1 rcsfile->tags = add_tags(rcsfile->tags, t);
108     }
109     if(rcsfile->branch)
110     {
111     char *h = xstrdup("MAIN");
112     char *r = xstrdup(rcsfile->branch->rev);
113     tag_t *t = new_tag(h, r);
114     t->rev->isbranch = 1;
115     rcsfile->tags = add_tags(rcsfile->tags, t);
116     }
117     /* Else we need to add the main tag later because the
118     * trunk is reversed in order and the primary revision
119     * numbers can vary.
120     */
121 bertho 1.4 if(!conf.parse_logs)
122     {
123     /* Return from the yyparse() call early to avoid parsing
124     * of the possibly extremely large deltatext. This speeds
125     * up parsing of binary files by a very large factor.
126     */
127     return 0;
128     }
129 bertho 1.1 }
130 bertho 1.4
131     /* This is trailing deltatext context and possibly ignored */
132     dtexts { rcsfile->dtexts = $5; }
133 bertho 1.1 ;
134    
135     admin : tHEAD orev ';'
136     obranch
137     tACCESS { set_id(); } oids ';'
138     tSYMBOLS { set_sym(); } otags ';'
139 bertho 1.2 tLOCKS { set_id(); } oidrevs ';' ostrict
140 bertho 1.1 ocomment
141     oexpand
142 bertho 1.2 ophrases { $$ = new_rcsfile($2, $4, $7, $11, $15, $17, $18, $19); }
143 bertho 1.1 ;
144    
145     ostrict : /* Empty */ { $$ = 0; }
146     | tSTRICT ';' { $$ = 1; }
147     ;
148    
149     obranch : /* Empty */ { $$ = NULL; }
150     | tBRANCH orev ';' { $$ = $2; }
151     ;
152    
153     ocomment: /* Empty */ { $$ = NULL; }
154     | tCOMMENT ostr ';' { $$ = $2; }
155     ;
156    
157     oexpand : /* Empty */ { $$ = NULL; }
158     | tEXPAND ostr ';' { $$ = $2; }
159     ;
160    
161     deltas : /* Empty */ { $$ = NULL; }
162     | deltas delta { $$ = add_deltas($1, $2); }
163     ;
164    
165     delta : tREV
166     tDATE tREV ';'
167 bertho 1.5 tAUTHOR { set_author(); } idorstr ';'
168 bertho 1.1 tSTATE { set_id(); } oid ';'
169     tBRANCHES orevs ';'
170     tNEXT orev ';'
171     ophrases { $$ = new_delta($1, $3, $7, $11, $14, $17); }
172 bertho 1.5 ;
173    
174     idorstr : tID { $$ = $1; }
175     | tSTRING { $$ = $1; }
176 bertho 1.1 ;
177    
178     desc : tDESC tSTRING { $$ = $2; }
179     ;
180    
181     dtexts : /* Empty */ { $$ = NULL; }
182     | dtexts dtext { $$ = add_dtexts($1, $2); }
183     ;
184    
185     dtext : tREV
186     tLOG tSTRING
187     ophrases
188     tTEXT { set_skipstr(); } tSTRING { $$ = new_dtext($1, $3, $7); }
189     ;
190    
191     ophrases: /* Empty */
192     | ophrases phrase
193     ;
194    
195     phrase : tNEWPHRASE { set_skip(); } ';' {
196     yywarning("Unrecognised `newphrase´ keyword '%s' skipped", $1);
197     xfree($1);
198     }
199     | cvskw { set_skip(); } ';' { yywarning("CVS extended keyword skipped"); }
200     | otherkw { set_skip(); } ';' { yywarning("Other extended keyword"); }
201     ;
202    
203     cvskw : tOWNER
204     | tGROUP
205     | tPERMISSIONS
206     | tSPECIAL
207     | tSYMLINK
208     | tHARDLINKS
209     ;
210    
211     otherkw : tNAMESPACE
212     | tDEAD
213     ;
214    
215     ostr : /* Empty */ { $$ = NULL; }
216     | tSTRING { $$ = $1; }
217     ;
218    
219     orev : /* Empty */ { $$ = NULL; }
220     | tREV { $$ = $1; }
221     ;
222    
223     orevs : /* Empty */ { $$ = NULL; }
224     | revs { $$ = $1; }
225     ;
226    
227     revs : tREV { $$ = new_revs($1); }
228     | revs tREV { $$ = add_revs($1, $2); }
229     ;
230    
231     oid : /* Empty */ { $$ = NULL; }
232     | tID { $$ = $1; }
233     ;
234    
235     oids : /* Empty */ { $$ = NULL; }
236     | ids { $$ = $1; }
237     ;
238    
239     ids : tID { $$ = new_ids($1); }
240     | ids tID { set_id(); $$ = add_ids($1, $2); }
241     ;
242    
243     oidrevs : /* Empty */ { $$ = NULL; }
244     | idrevs { $$ = $1; }
245     ;
246    
247     idrevs : idrev { $$ = new_idrevs($1); }
248     | idrevs idrev { $$ = add_idrevs($1, $2); }
249     ;
250    
251     idrev : tID ':' tREV { set_id(); $$ = new_idrev($1, $3); }
252     ;
253    
254     otags : /* Empty */ { $$ = NULL; }
255     | tags { $$ = $1; }
256     ;
257    
258 bertho 1.6 tags : tag { if($1) $$ = new_tags($1); else $$ = NULL; }
259     | tags tag { if($1 && $2) $$ = add_tags($1, $2); else if($2) $$ = new_tags($2); else $$ = $1; }
260 bertho 1.1 ;
261    
262     tag : tSYM ':' tREV { set_sym(); $$ = new_tag($1, $3); }
263 bertho 1.6 /* Zap the additional tag-info from CVSNT */
264     /* This is a bit of a hack, but it is necessary to do like this */
265     /* because the parser is not allowed to do any look-ahead on ':'. */
266     /* Otherwise, we would have a tNEWPHRASE hit because we cannot set */
267     /* set_sym() before the lexer gets the next token. */
268     | ':' tREV ':' tSTRING { set_sym(); $$ = NULL; }
269 bertho 1.1 ;
270    
271     %%
272     static rev_t *make_rev(char *s)
273     {
274     char *cptr;
275     int dots = 0;
276     rev_t *r;
277    
278     if(!s)
279     return NULL;
280    
281     r = xmalloc(sizeof(*r));
282    
283     for(cptr = s; *cptr; cptr++)
284     {
285     if(*cptr == '.')
286     dots++;
287     }
288     if(!dots)
289     {
290     r->rev = xstrdup("");
291     r->branch = xstrdup(s);
292     r->isbranch = 1;
293     }
294     else if(!*s)
295     {
296     r->rev = xstrdup("?.?");
297     r->branch = xstrdup("?");
298     }
299     else if(dots & 1)
300     {
301     char *t;
302     r->rev = s;
303     r->branch = xstrdup(s);
304     cptr = strrchr(r->branch, '.');
305     assert(cptr != NULL);
306     *cptr = '\0';
307     t = strrchr(r->branch, '.');
308     if((t&& !strcmp(t+1, "0")) || (!t && !strcmp(r->branch, "0")))
309     {
310     /* Magic branch numbers "x.x.0.x" */
311     r->isbranch = 1;
312     if(t)
313     strcpy(t+1, cptr+1);
314     else
315     strcpy(r->branch, cptr+1);
316     }
317     }
318     else
319     {
320     r->isbranch = 1;
321     r->branch = s;
322     r->rev = xmalloc(strlen(s) + 3);
323     strcpy(r->rev, s);
324     strcat(r->rev, ".?");
325     }
326     return r;
327     }
328    
329    
330     static tag_t *new_tag(char *s, char *r)
331     {
332     tag_t *t = xmalloc(sizeof(*t));
333     t->tag = s;
334     t->rev = make_rev(r);
335     return t;
336     }
337    
338     static tags_t *new_tags(tag_t *s)
339     {
340     tags_t *t = xmalloc(sizeof(*t));
341     t->ntags = 1;
342     t->tags = xmalloc(sizeof(t->tags[0]));
343     t->tags[0] = s;
344     return t;
345     }
346    
347     static tags_t *add_tags(tags_t *s, tag_t *t)
348     {
349     if(!s)
350     return new_tags(t);
351     s->tags = xrealloc(s->tags, (s->ntags+1) * sizeof(s->tags[0]));
352     s->tags[s->ntags] = t;
353     s->ntags++;
354     return s;
355     }
356    
357     static idrev_t *new_idrev(char *s, char *r)
358     {
359     idrev_t *t = xmalloc(sizeof(*t));
360     t->id = s;
361     t->rev = make_rev(r);
362     return t;
363     }
364    
365     static idrevs_t *new_idrevs(idrev_t *s)
366     {
367     idrevs_t *t = xmalloc(sizeof(*t));
368     t->nidrevs = 1;
369     t->idrevs = xmalloc(sizeof(t->idrevs[0]));
370     t->idrevs[0] = s;
371     return t;
372     }
373    
374     static idrevs_t *add_idrevs(idrevs_t *s, idrev_t *t)
375     {
376     if(!s)
377     return new_idrevs(t);
378     s->idrevs = xrealloc(s->idrevs, (s->nidrevs+1) * sizeof(s->idrevs[0]));
379     s->idrevs[s->nidrevs] = t;
380     s->nidrevs++;
381     return s;
382     }
383    
384     static ids_t *new_ids(char *s)
385     {
386     ids_t *t = xmalloc(sizeof(*t));
387     t->nids = 1;
388     t->ids = xmalloc(sizeof(t->ids[0]));
389     t->ids[0] = s;
390     return t;
391     }
392    
393     static ids_t *add_ids(ids_t *s, char *t)
394     {
395     s->ids = xrealloc(s->ids, (s->nids+1) * sizeof(s->ids[0]));
396     s->ids[s->nids] = t;
397     s->nids++;
398     return s;
399     }
400    
401     static revs_t *new_revs(char *s)
402     {
403     revs_t *t = xmalloc(sizeof(*t));
404     t->nrevs = 1;
405     t->revs = xmalloc(sizeof(t->revs[0]));
406     t->revs[0] = make_rev(s);
407     return t;
408     }
409    
410     static revs_t *add_revs(revs_t *s, char *t)
411     {
412     s->revs = xrealloc(s->revs, (s->nrevs+1) * sizeof(s->revs[0]));
413     s->revs[s->nrevs] = make_rev(t);
414     s->nrevs++;
415     return s;
416     }
417    
418     static dtext_t *new_dtext(char *n, char *l, char *t)
419     {
420     dtext_t *d = xmalloc(sizeof(*d));
421     d->rev = make_rev(n);
422     d->log = l;
423     d->text = t;
424     return d;
425     }
426    
427     static dtexts_t *add_dtexts(dtexts_t *s, dtext_t *t)
428     {
429     if(!s)
430     s = xmalloc(sizeof(*s));
431     s->dtexts = xrealloc(s->dtexts, (s->ndtexts+1) * sizeof(s->dtexts[0]));
432     s->dtexts[s->ndtexts] = t;
433     s->ndtexts++;
434     return s;
435     }
436    
437     static delta_t *new_delta(char *rev, char *date, char *author, char *state, revs_t *branches, char *next)
438     {
439     delta_t *d = xmalloc(sizeof(*d));
440     d->rev = make_rev(rev);
441     d->date = date;
442     d->author = author;
443     d->state = state;
444     d->branches = branches;
445     d->next = make_rev(next);
446     return d;
447     }
448    
449     static deltas_t *add_deltas(deltas_t *s, delta_t *t)
450     {
451     if(!s)
452     s = xmalloc(sizeof(*s));
453     s->deltas = xrealloc(s->deltas, (s->ndeltas+1) * sizeof(s->deltas[0]));
454     s->deltas[s->ndeltas] = t;
455     s->ndeltas++;
456     return s;
457     }
458    
459     static rcsfile_t *new_rcsfile(char *head, char *branch, ids_t *access, tags_t *tags,
460     idrevs_t *locks, int strict, char *comment, char *expand)
461     {
462     rcsfile_t *r = xmalloc(sizeof(*r));
463     r->head = make_rev(head);
464     r->branch = make_rev(branch);
465     r->access = access;
466     r->tags = tags;
467     r->locks = locks;
468     r->strict = strict;
469     r->comment = comment;
470     r->expand = expand;
471     return r;
472     }
473    

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0