/[CvsGraph]/cvsgraph/cvsgraph.c
ViewVC logotype

Annotate of /cvsgraph/cvsgraph.c

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


Revision 1.18 - (hide annotations)
Tue Jan 1 21:03:23 2002 UTC (15 years, 9 months ago) by bertho
Branch: MAIN
Changes since 1.17: +290 -94 lines
File MIME type: text/plain
Major code update to enable some more features. The new formatting scheme is
not yet 100%. This should be close to version 1.2.0.
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 bertho 1.14 #include "config.h"
23    
24 bertho 1.1 #include <stdio.h>
25     #include <stdlib.h>
26     #include <unistd.h>
27     #include <string.h>
28     #include <assert.h>
29     #include <sys/types.h>
30     #include <sys/stat.h>
31     #include <sys/wait.h>
32     #include <fcntl.h>
33     #include <regex.h>
34     #include <errno.h>
35 bertho 1.8 #include <ctype.h>
36 bertho 1.9 #include <time.h>
37 bertho 1.18 #include <limits.h>
38 bertho 1.9
39 bertho 1.14 #ifdef HAVE_GETOPT_H
40     # include <getopt.h>
41     #endif
42    
43 bertho 1.1 #include <gd.h>
44     #include <gdfontt.h>
45    
46     #include "cvsgraph.h"
47     #include "utils.h"
48     #include "readconf.h"
49 bertho 1.7 #include "rcs.h"
50 bertho 1.1
51 bertho 1.5 #if !defined(HAVE_IMAGE_GIF) && !defined(HAVE_IMAGE_PNG) && !defined(HAVE_IMAGE_JPEG)
52     # error No image output format available. Check libgd
53     #endif
54    
55    
56 bertho 1.1 /*#define DEBUG 1*/
57    
58     #ifndef MAX
59     # define MAX(a,b) ((a) > (b) ? (a) : (b))
60     #endif
61    
62     #ifndef MIN
63     # define MIN(a,b) ((a) < (b) ? (a) : (b))
64     #endif
65    
66     #define ALIGN_HL 0x00
67     #define ALIGN_HC 0x01
68     #define ALIGN_HR 0x02
69 bertho 1.9 #define ALIGN_HX 0x0f
70 bertho 1.1 #define ALIGN_VT 0x00
71     #define ALIGN_VC 0x10
72     #define ALIGN_VB 0x20
73     #define ALIGN_VX 0xf0
74 bertho 1.9
75 bertho 1.1 /*
76     **************************************************************************
77     * Globals
78     **************************************************************************
79     */
80    
81     config_t conf;
82 bertho 1.7 int debuglevel;
83 bertho 1.9 color_t white_color = {255, 255, 255, 0};
84     color_t black_color = {0, 0, 0, 0};
85    
86 bertho 1.1
87     /*
88     **************************************************************************
89 bertho 1.17 * Debug routines
90 bertho 1.1 **************************************************************************
91     */
92 bertho 1.7 void dump_rev(char *p, rev_t *r)
93 bertho 1.1 {
94 bertho 1.7 printf("%s", p);
95     if(r)
96     printf("'%s', '%s', %d\n", r->rev, r->branch, r->isbranch);
97     else
98     printf("<null>\n");
99 bertho 1.1 }
100    
101 bertho 1.7 void dump_id(char *p, char *d)
102 bertho 1.1 {
103 bertho 1.7 printf("%s", p);
104     if(d)
105     printf("'%s'\n", d);
106     else
107     printf("<null>\n");
108 bertho 1.1 }
109    
110 bertho 1.7 void dump_idrev(char *p, idrev_t *t)
111 bertho 1.1 {
112 bertho 1.7 printf("%s", p);
113     if(t)
114 bertho 1.1 {
115 bertho 1.7 printf("'%s' -> ", t->id);
116     dump_rev("", t->rev);
117 bertho 1.1 }
118     else
119 bertho 1.7 printf("<null>\n");
120 bertho 1.1 }
121    
122 bertho 1.7 void dump_tag(char *p, tag_t *t)
123 bertho 1.1 {
124 bertho 1.7 printf("%s", p);
125     if(t)
126 bertho 1.1 {
127 bertho 1.7 printf("'%s' -> ", t->tag);
128     dump_rev("", t->rev);
129 bertho 1.1 }
130 bertho 1.7 else
131     printf("<null>\n");
132 bertho 1.1 }
133    
134 bertho 1.7 void dump_delta(char *p, delta_t *d)
135 bertho 1.1 {
136 bertho 1.7 int i;
137     printf("%sdelta.rev : ", p);
138     dump_rev("", d->rev);
139     printf("%sdelta.date : %s\n", p, d->date);
140     printf("%sdelta.author: %s\n", p, d->author);
141     printf("%sdelta.state : %s\n", p, d->state);
142     for(i = 0; d->branches && i < d->branches->nrevs; i++)
143 bertho 1.1 {
144 bertho 1.7 printf("%sdelta.branch: ", p);
145     dump_rev("", d->branches->revs[i]);
146 bertho 1.1 }
147 bertho 1.7 printf("%sdelta.next : ", p);
148     dump_rev("", d->next);
149     printf("\n");
150 bertho 1.1 }
151    
152 bertho 1.7 void dump_dtext(char *p, dtext_t *d)
153 bertho 1.1 {
154 bertho 1.7 printf("%sdtext.rev : ", p);
155     dump_rev("", d->rev);
156     printf("%sdtext.log : %d bytes\n", p, d->log ? strlen(d->log) : -1);
157     printf("%sdtext.text : %d bytes\n", p, d->text ? strlen(d->text) : -1);
158     printf("\n");
159 bertho 1.1 }
160    
161 bertho 1.7 void dump_rcsfile(rcsfile_t *rcs)
162 bertho 1.1 {
163 bertho 1.7 int i;
164     printf("root : '%s'\n", rcs->root);
165     printf("module : '%s'\n", rcs->module);
166     printf("file : '%s'\n", rcs->file);
167     dump_rev("head : ", rcs->head);
168     dump_rev("branch : ", rcs->branch);
169     printf("access :\n");
170     for(i = 0; rcs->access && i < rcs->access->nids; i++)
171     dump_id("\t", rcs->access->ids[i]);
172     printf("tags :\n");
173     for(i = 0; rcs->tags && i < rcs->tags->ntags; i++)
174     dump_tag("\t", rcs->tags->tags[i]);
175     printf("locks :%s\n", rcs->strict ? " (strict)" : "");
176     for(i = 0; rcs->locks && i < rcs->locks->nidrevs; i++)
177     dump_idrev("\t", rcs->locks->idrevs[i]);
178     printf("comment: '%s'\n", rcs->comment);
179     printf("expand : '%s'\n", rcs->expand ? rcs->expand : "(default -kv)");
180     printf("deltas :\n");
181     for(i = 0; rcs->deltas && i < rcs->deltas->ndeltas; i++)
182     dump_delta("\t", rcs->deltas->deltas[i]);
183     printf("desc : '%s'\n", rcs->desc);
184     printf("dtexts :\n");
185     for(i = 0; rcs->dtexts && i < rcs->dtexts->ndtexts; i++)
186     dump_dtext("\t", rcs->dtexts->dtexts[i]);
187    
188     fflush(stdout);
189 bertho 1.1 }
190    
191 bertho 1.7 /*
192     **************************************************************************
193     * Read the rcs file
194     **************************************************************************
195     */
196     rcsfile_t *get_rcsfile(const char *cvsroot, const char *module, const char *file)
197 bertho 1.1 {
198 bertho 1.7 char *cmd = NULL;
199     int rv;
200 bertho 1.1
201 bertho 1.18 if(file)
202 bertho 1.9 {
203 bertho 1.18 cmd = xmalloc(strlen(cvsroot) + strlen(module) + strlen(file) + 1);
204     sprintf(cmd, "%s%s%s", cvsroot, module, file);
205     if(!(rcsin = fopen(cmd, "rb")))
206     {
207     perror(cmd);
208     return NULL;
209     }
210     input_file = cmd;
211     }
212     else
213     {
214     rcsin = stdin;
215     input_file = "<stdin>";
216 bertho 1.9 }
217 bertho 1.7 line_number = 1;
218     rv = rcsparse();
219 bertho 1.18 if(file)
220     {
221     fclose(rcsin);
222     xfree(cmd);
223     }
224 bertho 1.7 if(rv)
225 bertho 1.1 return NULL;
226 bertho 1.7 input_file = NULL;
227 bertho 1.18 if(file)
228     {
229     rcsfile->root = xstrdup(cvsroot);
230     rcsfile->module = xstrdup(module);
231     rcsfile->file = xstrdup(file);
232     }
233     else
234     {
235     rcsfile->root = xstrdup("");
236     rcsfile->module = xstrdup("");
237     rcsfile->file = xstrdup("<stdin>");
238     }
239 bertho 1.7 return rcsfile;
240 bertho 1.1 }
241    
242     /*
243     **************************************************************************
244     * Sort and find helpers
245     **************************************************************************
246     */
247 bertho 1.5 int count_dots(const char *s)
248     {
249     int i;
250     for(i = 0; *s; s++)
251     {
252     if(*s == '.')
253     i++;
254     }
255     return i;
256     }
257    
258 bertho 1.7 int compare_rev(int bcmp, const rev_t *r1, const rev_t *r2)
259 bertho 1.5 {
260     int d1, d2;
261 bertho 1.7 char *c1, *c2;
262 bertho 1.5 char *v1, *v2;
263     char *s1, *s2;
264     int retval = 0;
265     assert(r1 != NULL);
266     assert(r2 != NULL);
267 bertho 1.7 if(bcmp)
268     {
269     assert(r1->branch != NULL);
270     assert(r2->branch != NULL);
271     c1 = r1->branch;
272     c2 = r2->branch;
273     }
274     else
275     {
276     assert(r1->rev != NULL);
277     assert(r2->rev != NULL);
278     c1 = r1->rev;
279     c2 = r2->rev;
280     }
281 bertho 1.5
282 bertho 1.7 d1 = count_dots(c1);
283     d2 = count_dots(c2);
284 bertho 1.5 if(d1 != d2)
285     {
286     return d1 - d2;
287     }
288    
289 bertho 1.7 s1 = v1 = xstrdup(c1);
290     s2 = v2 = xstrdup(c2);
291 bertho 1.5 while(1)
292     {
293     char *vc1 = strchr(s1, '.');
294     char *vc2 = strchr(s2, '.');
295     if(vc1 && vc2)
296     *vc1 = *vc2 = '\0';
297     if(*s1 && *s2)
298     {
299     d1 = atoi(s1);
300     d2 = atoi(s2);
301     if(d1 != d2)
302     {
303     retval = d1 - d2;
304     break;
305     }
306     }
307     if(!vc1 || !vc2)
308     break;
309     s1 = vc1 + 1;
310     s2 = vc2 + 1;
311     }
312     xfree(v1);
313     xfree(v2);
314     return retval;
315     }
316    
317 bertho 1.7 /*
318     **************************************************************************
319     * Reorganise the rcsfile for the branches
320     *
321     * Basically, we have a list of deltas (i.e. administrative info on
322     * revisions) and a list of delta text (the actual logs and diffs).
323     * The deltas are linked through the 'next' and the 'branches' fields
324     * which describe the tree-structure of revisions.
325     * The reorganisation means that we put each delta and corresponding
326     * delta text in a revision structure and assign it to a specific
327     * branch. This is required because we want to be able to calculate
328     * the bounding boxes of each branch. The revisions expand vertically
329     * and the branches expand horizontally.
330     * The reorganisation is performed in these steps:
331 bertho 1.17 * 1 - sort deltas and delta text on revision number for quick lookup
332 bertho 1.7 * 2 - start at the denoted head revision:
333     * * create a branch structure and add this revision
334     * * for each 'branches' in the delta do:
335     * - walk all 'branches' of the delta and recursively goto 2
336     * with the denoted branch delta as new head
337     * - backlink the newly create sub-branch to the head revision
338     * so that we can draw them recursively
339     * * set head to the 'next' field and goto 2 until no next is
340     * available
341     * 3 - update the administration
342     **************************************************************************
343     */
344     int sort_delta(const void *d1, const void *d2)
345     {
346     return compare_rev(0, (*(delta_t **)d1)->rev, (*(delta_t **)d2)->rev);
347     }
348    
349     int search_delta(const void *r, const void *d)
350 bertho 1.1 {
351 bertho 1.7 return compare_rev(0, (rev_t *)r, (*(delta_t **)d)->rev);
352 bertho 1.1 }
353    
354 bertho 1.7 delta_t *find_delta(delta_t **dl, int n, rev_t *r)
355 bertho 1.1 {
356 bertho 1.7 delta_t **d;
357     d = bsearch(r, dl, n, sizeof(*dl), search_delta);
358     if(!d)
359     return NULL;
360     return *d;
361 bertho 1.1 }
362    
363 bertho 1.7 int sort_dtext(const void *d1, const void *d2)
364 bertho 1.1 {
365 bertho 1.7 return compare_rev(0, (*(dtext_t **)d1)->rev, (*(dtext_t **)d2)->rev);
366 bertho 1.1 }
367    
368 bertho 1.7 int search_dtext(const void *r, const void *d)
369 bertho 1.1 {
370 bertho 1.7 return compare_rev(0, (rev_t *)r, (*(dtext_t **)d)->rev);
371 bertho 1.1 }
372    
373 bertho 1.7 dtext_t *find_dtext(dtext_t **dl, int n, rev_t *r)
374 bertho 1.1 {
375 bertho 1.7 dtext_t **d;
376     d = bsearch(r, dl, n, sizeof(*dl), search_dtext);
377     if(!d)
378 bertho 1.1 return NULL;
379 bertho 1.7 return *d;
380     }
381    
382     rev_t *dup_rev(const rev_t *r)
383     {
384     rev_t *t = xmalloc(sizeof(*t));
385     t->rev = xstrdup(r->rev);
386     t->branch = xstrdup(r->branch);
387     t->isbranch = r->isbranch;
388     return t;
389     }
390    
391     branch_t *new_branch(delta_t *d, dtext_t *t)
392     {
393     branch_t *b = xmalloc(sizeof(*b));
394     revision_t *r = xmalloc(sizeof(*r));
395     r->delta = d;
396     r->dtext = t;
397     r->rev = d->rev;
398     r->branch = b;
399     b->branch = dup_rev(d->rev);
400     b->branch->isbranch = 1;
401     b->nrevs = 1;
402     b->revs = xmalloc(sizeof(b->revs[0]));
403     b->revs[0] = r;
404     return b;
405     }
406    
407     revision_t *add_to_branch(branch_t *b, delta_t *d, dtext_t *t)
408     {
409     revision_t *r = xmalloc(sizeof(*r));
410     r->delta = d;
411     r->dtext = t;
412     r->rev = d->rev;
413     r->branch = b;
414     b->revs = xrealloc(b->revs, (b->nrevs+1) * sizeof(b->revs[0]));
415     b->revs[b->nrevs] = r;
416     b->nrevs++;
417     return r;
418     }
419    
420     void build_branch(branch_t ***bl, int *nbl, delta_t **sdl, int nsdl, dtext_t **sdt, int nsdt, delta_t *head)
421     {
422     branch_t *b;
423     dtext_t *text;
424     revision_t *currev;
425    
426     assert(head != NULL);
427    
428     if(head->flag)
429     {
430     fprintf(stderr, "Circular reference on '%s' in branchpoint\n", head->rev->rev);
431     return;
432     }
433     head->flag++;
434     text = find_dtext(sdt, nsdt, head->rev);
435    
436     /* Create a new branch for this head */
437     b = new_branch(head, text);
438     *bl = xrealloc(*bl, (*nbl+1)*sizeof((*bl)[0]));
439     (*bl)[*nbl] = b;
440     (*nbl)++;
441     currev = b->revs[0];
442     while(1)
443     {
444     /* Process all sub-branches */
445     if(head->branches)
446     {
447     int i;
448     for(i = 0; i < head->branches->nrevs; i++)
449     {
450     delta_t *d = find_delta(sdl, nsdl, head->branches->revs[i]);
451     int btag = *nbl;
452     if(!d)
453     continue;
454     build_branch(bl, nbl, sdl, nsdl, sdt, nsdt, d);
455    
456     /* Set the new branch's origin */
457     (*bl)[btag]->branchpoint = currev;
458    
459     /* Add branch to this revision */
460     currev->branches = xrealloc(currev->branches, (currev->nbranches+1)*sizeof(currev->branches[0]));
461     currev->branches[currev->nbranches] = (*bl)[btag];
462     currev->nbranches++;
463     }
464     }
465    
466     /* Walk through the next list */
467     if(!head->next)
468     return;
469 bertho 1.9
470 bertho 1.7 head = find_delta(sdl, nsdl, head->next);
471     if(!head)
472     {
473     fprintf(stderr, "Next revision (%s) not found in deltalist\n", head->next->rev);
474     return;
475     }
476     if(head->flag)
477     {
478     fprintf(stderr, "Circular reference on '%s'\n", head->rev->rev);
479     return;
480     }
481     head->flag++;
482     text = find_dtext(sdt, nsdt, head->rev);
483     currev = add_to_branch(b, head, text);
484     }
485     }
486    
487     int reorganise_branches(rcsfile_t *rcs)
488     {
489     delta_t **sdelta;
490     int nsdelta;
491     dtext_t **sdtext;
492     int nsdtext;
493     delta_t *head;
494     branch_t **bl;
495     int nbl;
496     int i;
497    
498     assert(rcs->deltas != NULL);
499     assert(rcs->head != NULL);
500    
501     /* Make a new list for quick lookup */
502     nsdelta = rcs->deltas->ndeltas;
503     sdelta = xmalloc(nsdelta * sizeof(sdelta[0]));
504     memcpy(sdelta, rcs->deltas->deltas, nsdelta * sizeof(sdelta[0]));
505     qsort(sdelta, nsdelta, sizeof(sdelta[0]), sort_delta);
506    
507     /* Do the same for the delta text */
508     nsdtext = rcs->dtexts->ndtexts;
509     sdtext = xmalloc(nsdtext * sizeof(sdtext[0]));
510     memcpy(sdtext, rcs->dtexts->dtexts, nsdtext * sizeof(sdtext[0]));
511     qsort(sdtext, nsdtext, sizeof(sdtext[0]), sort_dtext);
512    
513     /* Start from the head of the trunk */
514     head = find_delta(sdelta, nsdelta, rcs->head);
515     if(!head)
516     {
517     fprintf(stderr, "Head revision (%s) not found in deltalist\n", rcs->head->rev);
518     return 0;
519     }
520     bl = NULL;
521     nbl = 0;
522     build_branch(&bl, &nbl, sdelta, nsdelta, sdtext, nsdtext, head);
523    
524     /* Reverse the head branch */
525     for(i = 0; i < bl[0]->nrevs/2; i++)
526     {
527     revision_t *r;
528     r = bl[0]->revs[i];
529     bl[0]->revs[i] = bl[0]->revs[bl[0]->nrevs-i-1];
530     bl[0]->revs[bl[0]->nrevs-i-1] = r;
531     }
532    
533     /* Update the branch-number of the head because it was reversed */
534     xfree(bl[0]->branch->branch);
535     bl[0]->branch->branch = xstrdup(bl[0]->revs[0]->rev->branch);
536    
537     /* Keep the admin */
538     rcs->branches = bl;
539     rcs->nbranches = nbl;
540     rcs->sdelta = sdelta;
541     rcs->nsdelta = nsdelta;
542     rcs->sdtext = sdtext;
543     rcs->nsdtext = nsdtext;
544     rcs->active = bl[0];
545     return 1;
546     }
547    
548     /*
549     **************************************************************************
550     * Assign the symbolic tags to the revisions and branches
551     *
552     * The tags point to revision numbers somewhere in the tree structure
553     * of branches and revisions. First we make a sorted list of all
554     * revisions and then we assign each tag to the proper revision.
555     **************************************************************************
556     */
557     int sort_revision(const void *r1, const void *r2)
558     {
559     return compare_rev(0, (*(revision_t **)r1)->delta->rev, (*(revision_t **)r2)->delta->rev);
560     }
561    
562     int search_revision(const void *t, const void *r)
563     {
564     return compare_rev(0, (rev_t *)t, (*(revision_t **)r)->delta->rev);
565     }
566    
567     int sort_branch(const void *b1, const void *b2)
568     {
569     return compare_rev(1, (*(branch_t **)b1)->branch, (*(branch_t **)b2)->branch);
570 bertho 1.1 }
571    
572 bertho 1.7 int search_branch(const void *t, const void *b)
573 bertho 1.1 {
574 bertho 1.7 return compare_rev(1, (rev_t *)t, (*(branch_t **)b)->branch);
575 bertho 1.1 }
576    
577 bertho 1.7 char *previous_rev(const char *c)
578 bertho 1.1 {
579 bertho 1.7 int dots = count_dots(c);
580     char *cptr;
581     char *r;
582     if(!dots)
583 bertho 1.9 {
584     fprintf(stderr, "FIXME: previous_rev(\"%s\"): Cannot determine parent branch revision\n", c);
585 bertho 1.7 return xstrdup("1.0"); /* FIXME: don't know what the parent is */
586 bertho 1.9 }
587 bertho 1.7 if(dots & 1)
588     {
589     /* Is is a revision we want the parent of */
590     r = xstrdup(c);
591     cptr = strrchr(r, '.');
592     assert(cptr != NULL);
593     if(dots == 1)
594     {
595 bertho 1.9 fprintf(stderr, "FIXME: previous_rev(\"%s\"): Going beyond top-level?\n", c);
596 bertho 1.7 /* FIXME: What is the parent of 1.1? */
597     cptr[1] = '\0';
598     strcat(r, "0");
599     return r;
600     }
601     /* Here we have a "x.x[.x.x]+" case */
602     *cptr = '\0';
603     cptr = strrchr(r, '.');
604     assert(cptr != NULL);
605     *cptr = '\0';
606     return r;
607     }
608     /* It is a branch we want the parent of */
609     r = xstrdup(c);
610     cptr = strrchr(r, '.');
611     assert(cptr != NULL);
612     *cptr = '\0';
613     return r;
614 bertho 1.1 }
615    
616 bertho 1.7 int assign_tags(rcsfile_t *rcs)
617 bertho 1.1 {
618     int i;
619 bertho 1.7 int nr;
620    
621     for(i = nr = 0; i < rcs->nbranches; i++)
622     nr += rcs->branches[i]->nrevs;
623    
624     rcs->srev = xmalloc(nr * sizeof(rcs->srev[0]));
625     rcs->nsrev = nr;
626     for(i = nr = 0; i < rcs->nbranches; i++)
627     {
628     memcpy(&rcs->srev[nr], rcs->branches[i]->revs, rcs->branches[i]->nrevs * sizeof(rcs->branches[i]->revs[0]));
629     nr += rcs->branches[i]->nrevs;
630     }
631    
632     qsort(rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), sort_revision);
633     qsort(rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), sort_branch);
634    
635     if(!rcs->branch)
636     {
637     /* The main trunk is the active trunk */
638     rcs->tags->tags = xrealloc(rcs->tags->tags, (rcs->tags->ntags+1)*sizeof(rcs->tags->tags[0]));
639     rcs->tags->tags[rcs->tags->ntags] = xmalloc(sizeof(tag_t));
640     rcs->tags->tags[rcs->tags->ntags]->tag = xstrdup("MAIN");
641     rcs->tags->tags[rcs->tags->ntags]->rev = xmalloc(sizeof(rev_t));
642     rcs->tags->tags[rcs->tags->ntags]->rev->rev = xstrdup(rcs->active->branch->rev);
643     rcs->tags->tags[rcs->tags->ntags]->rev->branch = xstrdup(rcs->active->branch->branch);
644     rcs->tags->tags[rcs->tags->ntags]->rev->isbranch = 1;
645     rcs->tags->ntags++;
646     }
647    
648     /* We should have at least two tags (HEAD and MAIN) */
649     assert(rcs->tags != 0);
650    
651     for(i = 0; i < rcs->tags->ntags; i++)
652     {
653     tag_t *t = rcs->tags->tags[i];
654     if(t->rev->isbranch)
655     {
656     branch_t **b;
657     add_btag:
658     b = bsearch(t->rev, rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), search_branch);
659     if(!b)
660     {
661     rev_t rev;
662     revision_t **r;
663     /* This happens for the magic branch numbers if there are
664 bertho 1.12 * no commits within the new branch yet. So, we add the
665     * branch and try to continue.
666 bertho 1.7 */
667     rev.rev = previous_rev(t->rev->branch);
668     rev.branch = NULL;
669     rev.isbranch = 0;
670     r = bsearch(&rev, rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), search_revision);
671     xfree(rev.rev);
672     if(!r)
673     {
674 bertho 1.12 if(!quiet)
675     fprintf(stderr, "No branch found for tag '%s:%s'\n", t->tag, t->rev->branch);
676 bertho 1.7 }
677     else
678     {
679     rcs->branches = xrealloc(rcs->branches, (rcs->nbranches+1)*sizeof(rcs->branches[0]));
680     rcs->branches[rcs->nbranches] = xmalloc(sizeof(branch_t));
681     rcs->branches[rcs->nbranches]->branch = dup_rev(t->rev);
682     rcs->branches[rcs->nbranches]->branchpoint = *r;
683     (*r)->branches = xrealloc((*r)->branches, ((*r)->nbranches+1)*sizeof((*r)->branches[0]));
684     (*r)->branches[(*r)->nbranches] = rcs->branches[rcs->nbranches];
685     (*r)->nbranches++;
686     rcs->nbranches++;
687     /* Resort the branches */
688     qsort(rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), sort_branch);
689     goto add_btag;
690     }
691     }
692     else
693     {
694     branch_t *bb = *b;
695     bb->tags = xrealloc(bb->tags, (bb->ntags+1)*sizeof(bb->tags[0]));
696     bb->tags[bb->ntags] = t;
697     bb->ntags++;
698     }
699     }
700     else
701     {
702     revision_t **r = bsearch(t->rev, rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), search_revision);
703     if(!r)
704 bertho 1.12 {
705     if(!quiet)
706     fprintf(stderr, "No revision found for tag '%s:%s'\n", t->tag, t->rev->rev);
707     }
708 bertho 1.7 else
709     {
710     revision_t *rr = *r;
711     rr->tags = xrealloc(rr->tags, (rr->ntags+1)*sizeof(rr->tags[0]));
712     rr->tags[rr->ntags] = t;
713     rr->ntags++;
714     }
715     }
716     }
717    
718     /* We need to reset the first in the list of branches to the
719     * active branch to ensure the drawing of all
720     */
721     if(rcs->active != rcs->branches[0])
722 bertho 1.1 {
723 bertho 1.7 branch_t **b = bsearch(rcs->active->branch, rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), search_branch);
724     branch_t *t;
725     assert(b != NULL);
726     t = *b;
727     *b = rcs->branches[0];
728     rcs->branches[0] = t;
729 bertho 1.1 }
730 bertho 1.7 return 1;
731 bertho 1.1 }
732    
733     /*
734     **************************************************************************
735 bertho 1.8 * String expansion
736     **************************************************************************
737     */
738     static char *_string;
739     static int _nstring;
740     static int _nastring;
741    
742     void add_string_str(const char *s)
743     {
744     int l = strlen(s) + 1;
745     if(_nstring + l > _nastring)
746     {
747     _nastring += 128;
748     _string = xrealloc(_string, _nastring * sizeof(_string[0]));
749     }
750     memcpy(_string+_nstring, s, l);
751     _nstring += l-1;
752     }
753    
754     void add_string_ch(int ch)
755     {
756     char buf[2];
757     buf[0] = ch;
758     buf[1] = '\0';
759     add_string_str(buf);
760     }
761    
762 bertho 1.9 void add_string_date(const char *d)
763     {
764     struct tm tm, *tmp;
765     int n;
766     time_t t;
767     char *buf;
768     int nbuf;
769    
770     memset(&tm, 0, sizeof(tm));
771     n = sscanf(d, "%d.%d.%d.%d.%d.%d",
772     &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
773     &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
774     tm.tm_mon--;
775     if(tm.tm_year > 1900)
776     tm.tm_year -= 1900;
777     t = mktime(&tm);
778     if(n != 6 || t == (time_t)(-1))
779     {
780     add_string_str("<invalid date>");
781     return;
782     }
783    
784     tmp = localtime(&t);
785     nbuf = strlen(conf.date_format) * 16; /* Should be enough to hold all types of expansions */
786     buf = xmalloc(nbuf);
787     strftime(buf, nbuf, conf.date_format, tmp);
788     add_string_str(buf);
789     xfree(buf);
790     }
791    
792     char *expand_string(const char *s, rcsfile_t *rcs, revision_t *r, rev_t *rev, rev_t *prev, tag_t *tag)
793 bertho 1.8 {
794     char nb[32];
795     char nr[32];
796     char *base;
797    
798     if(!s)
799     return xstrdup("");
800    
801     _nstring = 0;
802     if(_string)
803     _string[0] = '\0';
804    
805     sprintf(nb, "%d", rcs->nbranches);
806     sprintf(nr, "%d", rcs->nsrev);
807     for(; *s; s++)
808     {
809     if(*s == '%')
810     {
811     switch(*++s)
812     {
813 bertho 1.12 case 'c':
814     case 'C':
815     add_string_str(conf.cvsroot);
816     if(*s == 'C' && conf.cvsroot[0] && conf.cvsroot[strlen(conf.cvsroot)-1] == '/')
817     {
818     /* Strip the trailing '/' */
819     _nstring--;
820     _string[_nstring] = '\0';
821     }
822     break;
823 bertho 1.8 case 'f':
824     case 'F':
825     base = strrchr(rcs->file, '/');
826     if(!base)
827     add_string_str(rcs->file);
828     else
829     add_string_str(base+1);
830     if(*s == 'F' && _string[_nstring-1] == 'v' && _string[_nstring-2] == ',')
831     {
832     _nstring -= 2;
833     _string[_nstring] = '\0';
834     }
835     break;
836     case 'p':
837     base = strrchr(rcs->file, '/');
838     if(base)
839     {
840     char *c = xstrdup(rcs->file);
841     base = strrchr(c, '/');
842     assert(base != NULL);
843     base[1] = '\0';
844     add_string_str(c);
845     xfree(c);
846     }
847 bertho 1.9 /*
848     * We should not add anything here because we can encounter
849     * a completely empty path, in which case we do not want
850 bertho 1.17 * to add any slash. This prevents an inadvertent root redirect.
851 bertho 1.9 *
852     * else
853     * add_string_str("/");
854     */
855 bertho 1.8 break;
856 bertho 1.12 case 'm':
857     case 'M':
858     add_string_str(conf.cvsmodule);
859     if(*s == 'M' && conf.cvsmodule[0] && conf.cvsmodule[strlen(conf.cvsmodule)-1] == '/')
860     {
861     /* Strip the trailing '/' */
862     _nstring--;
863     _string[_nstring] = '\0';
864     }
865     break;
866 bertho 1.8 case 'r': add_string_str(nr); break;
867     case 'b': add_string_str(nb); break;
868     case '%': add_string_ch('%'); break;
869     case '0': if(conf.expand[0]) add_string_str(conf.expand[0]); break;
870     case '1': if(conf.expand[1]) add_string_str(conf.expand[1]); break;
871     case '2': if(conf.expand[2]) add_string_str(conf.expand[2]); break;
872     case '3': if(conf.expand[3]) add_string_str(conf.expand[3]); break;
873     case '4': if(conf.expand[4]) add_string_str(conf.expand[4]); break;
874     case '5': if(conf.expand[5]) add_string_str(conf.expand[5]); break;
875     case '6': if(conf.expand[6]) add_string_str(conf.expand[6]); break;
876     case '7': if(conf.expand[7]) add_string_str(conf.expand[7]); break;
877     case '8': if(conf.expand[8]) add_string_str(conf.expand[8]); break;
878     case '9': if(conf.expand[9]) add_string_str(conf.expand[9]); break;
879     case 'R': if(rev && rev->rev) add_string_str(rev->rev); break;
880 bertho 1.9 case 'P': if(prev && prev->rev) add_string_str(prev->rev); break;
881 bertho 1.8 case 'B': if(rev && rev->branch) add_string_str(rev->branch); break;
882     case 't': if(tag && tag->tag) add_string_str(tag->tag); break;
883 bertho 1.9 case 'd': if(r && r->delta && r->delta->date) add_string_date(r->delta->date); break;
884     case 's': if(r && r->delta && r->delta->state) add_string_str(r->delta->state); break;
885     case 'a': if(r && r->delta && r->delta->author) add_string_str(r->delta->author); break;
886 bertho 1.8 default:
887     add_string_ch('%');
888     add_string_ch(*s);
889     break;
890     }
891     }
892     else
893     add_string_ch(*s);
894     }
895     return xstrdup(_string);
896     }
897    
898     /*
899     **************************************************************************
900 bertho 1.1 * Drawing routines
901     **************************************************************************
902     */
903     int get_swidth(const char *s, font_t *f)
904     {
905 bertho 1.9 int n;
906     int m;
907     if(!s || !*s)
908 bertho 1.1 return 0;
909 bertho 1.9 for(n = m = 0; *s; n++, s++)
910     {
911     if(*s == '\n')
912     {
913     if(n > m)
914     m = n;
915     n = 0;
916     }
917     }
918     if(n > m)
919     m = n;
920     return m * (*f)->w;
921 bertho 1.1 }
922    
923     int get_sheight(const char *s, font_t *f)
924     {
925     int nl;
926 bertho 1.9 if(!s || !*s)
927 bertho 1.1 return 0;
928     for(nl = 1; *s; s++)
929     {
930     if(*s == '\n' && s[1])
931     nl++;
932     }
933     return nl * (*f)->h;
934     }
935    
936 bertho 1.9 void draw_rbox(gdImagePtr im, int x1, int y1, int x2, int y2, int r, color_t *color, color_t *bgcolor)
937 bertho 1.1 {
938     int r2 = 2*r;
939     gdImageLine(im, x1+r, y1, x2-r, y1, color->id);
940     gdImageLine(im, x1+r, y2, x2-r, y2, color->id);
941     gdImageLine(im, x1, y1+r, x1, y2-r, color->id);
942     gdImageLine(im, x2, y1+r, x2, y2-r, color->id);
943 bertho 1.9 if(conf.box_shadow)
944     {
945     gdImageLine(im, x1+r+1, y2+1, x2-r, y2+1, black_color.id);
946     gdImageLine(im, x2+1, y1+r+1, x2+1, y2-r, black_color.id);
947     }
948 bertho 1.1 if(r)
949     {
950 bertho 1.18 /* FIXME: Pixelization is not perfect */
951 bertho 1.1 gdImageArc(im, x1+r, y1+r, r2, r2, 180, 270, color->id);
952     gdImageArc(im, x2-r, y1+r, r2, r2, 270, 360, color->id);
953     gdImageArc(im, x1+r, y2-r, r2, r2, 90, 180, color->id);
954 bertho 1.9 if(conf.box_shadow)
955     {
956     gdImageArc(im, x2-r+1, y2-r+1, r2, r2, 0, 90, black_color.id);
957 bertho 1.18 gdImageArc(im, x2-r+1, y2-r, r2, r2, 0, 90, black_color.id);
958     gdImageArc(im, x2-r, y2-r+1, r2, r2, 0, 90, black_color.id);
959 bertho 1.9 }
960 bertho 1.18 gdImageArc(im, x2-r, y2-r, r2, r2, 0, 90, color->id);
961 bertho 1.1 }
962 bertho 1.9 gdImageFillToBorder(im, (x1+x2)/2, (y1+y2)/2, color->id, bgcolor->id);
963 bertho 1.1 }
964    
965     void draw_string(gdImagePtr im, char *s, font_t *f, int x, int y, int align, color_t *c)
966     {
967     int xx, yy;
968     switch(align & ALIGN_HX)
969     {
970     default:
971     case ALIGN_HL: xx = 0; break;
972     case ALIGN_HC: xx = -get_swidth(s, f)/2; break;
973     case ALIGN_HR: xx = -get_swidth(s, f); break;
974     }
975     switch(align & ALIGN_VX)
976     {
977     default:
978     case ALIGN_VT: yy = 0; break;
979     case ALIGN_VC: yy = -get_sheight(s, f)/2; break;
980     case ALIGN_VB: yy = -get_sheight(s, f); break;
981     }
982     gdImageString(im, *f, x+xx+1, y+yy, s, c->id);
983     }
984    
985 bertho 1.9 void draw_stringnl(gdImagePtr im, char *s, font_t *f, int x, int y, int align, color_t *c)
986     {
987     char *t;
988     char *d;
989     d = s = xstrdup(s);
990     do
991     {
992     t = strchr(s, '\n');
993     if(t)
994     *t = '\0';
995     draw_string(im, s, f, x, y, align, c);
996     y += get_sheight(s, f);
997     s = t+1;
998     } while(t);
999     xfree(d);
1000     }
1001    
1002 bertho 1.16 void draw_rev(gdImagePtr im, revision_t *r)
1003 bertho 1.1 {
1004 bertho 1.16 int lx = r->cx - r->w/2;
1005 bertho 1.1 int rx = lx + r->w;
1006     int i;
1007 bertho 1.16 int ty = r->y;
1008 bertho 1.9 draw_rbox(im, lx, ty, rx, ty+r->h, 0, &conf.rev_color, &conf.rev_bgcolor);
1009 bertho 1.1 ty += conf.rev_tspace;
1010 bertho 1.16 draw_string(im, r->rev->rev, &conf.rev_font, r->cx, ty, ALIGN_HC, &conf.rev_color);
1011 bertho 1.1 ty += get_sheight(r->rev->rev, &conf.rev_font);
1012 bertho 1.16 draw_stringnl(im, r->revtext, &conf.rev_text_font, r->cx, ty, ALIGN_HC, &conf.rev_text_color);
1013 bertho 1.9 ty += get_sheight(r->revtext, &conf.rev_text_font);
1014 bertho 1.1 for(i = 0; i < r->ntags; i++)
1015     {
1016 bertho 1.16 draw_string(im, r->tags[i]->tag, &conf.tag_font, r->cx, ty, ALIGN_HC, &conf.tag_color);
1017 bertho 1.1 ty += get_sheight(r->tags[i]->tag, &conf.tag_font);
1018     }
1019     }
1020    
1021 bertho 1.17 void draw_branch_box(gdImagePtr im, branch_t *b, int ypos)
1022 bertho 1.1 {
1023 bertho 1.16 int lx = b->cx - b->w/2;
1024 bertho 1.1 int rx = lx + b->w;
1025 bertho 1.16 int i;
1026 bertho 1.1 int yy;
1027 bertho 1.16
1028 bertho 1.17 draw_rbox(im, lx, ypos, rx, ypos+b->h, 5, &conf.branch_color, &conf.branch_bgcolor);
1029 bertho 1.1 yy = conf.branch_tspace;
1030 bertho 1.17 draw_string(im, b->branch->branch, &conf.branch_font, b->cx, ypos+yy, ALIGN_HC, &conf.branch_color);
1031 bertho 1.7 yy += get_sheight(b->branch->branch, &conf.branch_font);
1032     for(i = 0; i < b->ntags; i++)
1033 bertho 1.1 {
1034 bertho 1.17 draw_string(im, b->tags[i]->tag, &conf.branch_font, b->cx, ypos+yy, ALIGN_HC, &conf.branch_color);
1035 bertho 1.7 yy += get_sheight(b->tags[i]->tag, &conf.branch_font);
1036 bertho 1.1 }
1037 bertho 1.16 }
1038    
1039     void draw_branch(gdImagePtr im, branch_t *b)
1040     {
1041     int yy;
1042     int i;
1043 bertho 1.17 int line[4];
1044    
1045     line[0] = conf.rev_color.id;
1046     line[1] = gdTransparent;
1047     line[1] = gdTransparent;
1048     line[3] = conf.rev_color.id;
1049    
1050     draw_branch_box(im, b, b->y);
1051 bertho 1.1
1052 bertho 1.16 if(conf.upside_down)
1053     {
1054     yy = b->y;
1055     for(i = 0; i < b->nrevs; i++)
1056     {
1057     revision_t *r = b->revs[i];
1058 bertho 1.17 gdImageSetStyle(im, line, r->stripped ? 4 : 1);
1059     gdImageLine(im, r->cx, yy, r->cx, r->y+r->h, gdStyled);
1060 bertho 1.16 draw_rev(im, r);
1061     yy = r->y;
1062     }
1063 bertho 1.17 if(conf.branch_dupbox)
1064 bertho 1.16 {
1065 bertho 1.17 i = b->y - b->th + b->h;
1066     gdImageLine(im, b->cx, yy, b->cx, i, conf.rev_color.id);
1067     draw_branch_box(im, b, i);
1068 bertho 1.16 }
1069     }
1070     else
1071 bertho 1.1 {
1072 bertho 1.16 yy = b->y + b->h;
1073     for(i = 0; i < b->nrevs; i++)
1074     {
1075     revision_t *r = b->revs[i];
1076 bertho 1.17 gdImageSetStyle(im, line, r->stripped ? 4 : 1);
1077     gdImageLine(im, r->cx, yy, r->cx, r->y, gdStyled);
1078 bertho 1.16 draw_rev(im, r);
1079     yy = r->y + r->h;
1080     }
1081 bertho 1.17 if(conf.branch_dupbox)
1082 bertho 1.16 {
1083 bertho 1.17 i = b->y + b->th - b->h;
1084     gdImageLine(im, b->cx, yy, b->cx, i, conf.rev_color.id);
1085     draw_branch_box(im, b, i);
1086 bertho 1.16 }
1087 bertho 1.1 }
1088     }
1089    
1090     void draw_connector(gdImagePtr im, branch_t *b)
1091     {
1092     revision_t *r = b->branchpoint;
1093 bertho 1.7 int x1 = r->cx + r->w/2 + 2;
1094 bertho 1.1 int y1 = r->y + r->h/2;
1095 bertho 1.7 int x2 = b->cx;
1096 bertho 1.1 int y2 = b->y;
1097 bertho 1.16 if(conf.upside_down)
1098     y2 += b->h;
1099 bertho 1.1 gdImageLine(im, x1, y1, x2, y1, conf.branch_color.id);
1100     gdImageLine(im, x2, y1, x2, y2, conf.branch_color.id);
1101     }
1102    
1103 bertho 1.9 void alloc_color(gdImagePtr im, color_t *c)
1104     {
1105     c->id = gdImageColorAllocate(im, c->r, c->g, c->b);
1106     }
1107    
1108 bertho 1.7 gdImagePtr make_image(rcsfile_t *rcs)
1109 bertho 1.1 {
1110     gdImagePtr im;
1111     int i;
1112 bertho 1.8 char *cptr;
1113 bertho 1.1
1114 bertho 1.15 cptr = expand_string(conf.title, rcs, NULL, NULL, NULL, NULL);
1115     i = get_swidth(cptr, &conf.title_font);
1116     if(rcs->tw+conf.margin_left+conf.margin_right > i)
1117     i = rcs->tw+conf.margin_left+conf.margin_right;
1118     im = gdImageCreate(i, rcs->th+conf.margin_top+conf.margin_bottom);
1119 bertho 1.9 alloc_color(im, &conf.color_bg);
1120     alloc_color(im, &conf.tag_color);
1121     alloc_color(im, &conf.rev_color);
1122     alloc_color(im, &conf.rev_bgcolor);
1123     alloc_color(im, &conf.rev_text_color);
1124     alloc_color(im, &conf.branch_color);
1125     alloc_color(im, &conf.branch_bgcolor);
1126     alloc_color(im, &conf.title_color);
1127     alloc_color(im, &black_color);
1128     alloc_color(im, &white_color);
1129 bertho 1.1
1130     for(i = 0; i < rcs->nbranches; i++)
1131 bertho 1.16 draw_branch(im, rcs->branches[i]);
1132 bertho 1.1 for(i = 0; i < rcs->nbranches; i++)
1133     {
1134     if(rcs->branches[i]->branchpoint)
1135     draw_connector(im, rcs->branches[i]);
1136     }
1137 bertho 1.9 draw_stringnl(im, cptr, &conf.title_font, conf.title_x, conf.title_y, conf.title_align, &conf.title_color);
1138 bertho 1.8 xfree(cptr);
1139 bertho 1.1
1140     return im;
1141     }
1142    
1143 bertho 1.7 /*
1144     **************************************************************************
1145     * Layout routines
1146     **************************************************************************
1147     */
1148 bertho 1.1 void move_branch(branch_t *b, int x, int y)
1149     {
1150     int i;
1151 bertho 1.7 b->cx += x;
1152 bertho 1.1 b->y += y;
1153     for(i = 0; i < b->nrevs; i++)
1154     {
1155 bertho 1.7 b->revs[i]->cx += x;
1156 bertho 1.1 b->revs[i]->y += y;
1157     }
1158     }
1159    
1160 bertho 1.18 void initial_reposition_branch(revision_t *r, int *x, int *w)
1161 bertho 1.6 {
1162     int i, j;
1163     for(j = 0; j < r->nbranches; j++)
1164     {
1165     branch_t *b = r->branches[j];
1166 bertho 1.7 *x += *w + conf.rev_minline + b->tw/2 - b->cx;
1167 bertho 1.6 *w = b->tw/2;
1168 bertho 1.7 move_branch(b, *x, r->y + r->h/2 + conf.branch_connect);
1169     *x = b->cx;
1170 bertho 1.6 /* Recurse to move branches of branched revisions */
1171     for(i = b->nrevs-1; i >= 0; i--)
1172     {
1173 bertho 1.18 initial_reposition_branch(b->revs[i], x, w);
1174 bertho 1.6 }
1175     }
1176     }
1177    
1178 bertho 1.1 void rect_union(int *x, int *y, int *w, int *h, branch_t *b)
1179     {
1180     int x1 = *x;
1181     int x2 = x1 + *w;
1182     int y1 = *y;
1183     int y2 = y1 + *h;
1184 bertho 1.7 int xx1 = b->cx - b->tw/2;
1185 bertho 1.1 int xx2 = xx1 + b->tw;
1186     int yy1 = b->y;
1187     int yy2 = yy1 + b->th;
1188     x1 = MIN(x1, xx1);
1189     x2 = MAX(x2, xx2);
1190     y1 = MIN(y1, yy1);
1191     y2 = MAX(y2, yy2);
1192     *x = x1;
1193     *y = y1;
1194     *w = x2 - x1;
1195     *h = y2 - y1;
1196     }
1197    
1198 bertho 1.7 int branch_intersects(int top, int bottom, int left, branch_t *b)
1199     {
1200     int br = b->cx + b->tw/2;
1201     int bt = b->y - conf.branch_connect - conf.branch_margin/2;
1202     int bb = b->y + b->th + conf.branch_margin/2;
1203     return !(bt > bottom || bb < top || br >= left);
1204     }
1205    
1206     int kern_branch(rcsfile_t *rcs, branch_t *b)
1207     {
1208     int left = b->cx - b->tw/2;
1209     int top = b->y - conf.branch_connect - conf.branch_margin/2;
1210     int bottom = b->y + b->th + conf.branch_margin/2;
1211     int i;
1212     int xpos = 0;
1213    
1214     for(i = 0; i < rcs->nbranches; i++)
1215     {
1216     branch_t *bp = rcs->branches[i];
1217     if(bp == b)
1218     continue;
1219     if(branch_intersects(top, bottom, left, bp))
1220     {
1221     int m = bp->cx + bp->tw/2 + conf.branch_margin;
1222     if(m > xpos)
1223     xpos = m;
1224     }
1225     }
1226     if(xpos && (b->cx - b->tw/2) - xpos > 0)
1227     {
1228     move_branch(b, xpos - (b->cx - b->tw/2), 0);
1229     return 1;
1230     }
1231     return 0;
1232     }
1233    
1234 bertho 1.18 void kern_tree(rcsfile_t *rcs)
1235     {
1236     int i;
1237     int moved;
1238     for(moved = 1; moved; )
1239     {
1240     moved = 0;
1241     for(i = 1; i < rcs->nbranches; i++)
1242     {
1243     moved += kern_branch(rcs, rcs->branches[i]);
1244     }
1245     #ifdef DEBUG
1246     fprintf(stderr, "kern_tree: moved=%d\n", moved);
1247     #endif
1248     }
1249     }
1250    
1251     void move_yr_branch(revision_t *r, int dy)
1252     {
1253     int i, j;
1254     #ifdef DEBUG
1255     fprintf(stderr, "move_yr_branch: r=%s, dy=%d\n", r->rev->rev, dy);
1256     #endif
1257     for(i = 0; i < r->nbranches; i++)
1258     {
1259     branch_t *b = r->branches[i];
1260     b->y += dy;
1261     for(j = 0; j < b->nrevs; j++)
1262     {
1263     b->revs[j]->y += dy;
1264     move_yr_branch(b->revs[j], dy);
1265     }
1266     }
1267     }
1268    
1269     int index_of_revision(revision_t *r)
1270     {
1271     branch_t *b = r->branch;
1272     int i;
1273     for(i = 0; i < b->nrevs; i++)
1274     {
1275     if(r == b->revs[i])
1276     return i;
1277     }
1278     fprintf(stderr, "index_of_revision: Cannot find revision in branch\n");
1279     return 0;
1280     }
1281    
1282     int has_space_below(rcsfile_t *rcs, branch_t *b, int recurse)
1283     {
1284     int i;
1285     int space = INT_MAX;
1286     for(i = 0; i < rcs->nbranches; i++)
1287     {
1288     int bl;
1289     int br;
1290     int tbl;
1291     int tbr;
1292     branch_t *tb = rcs->branches[i];
1293     if(tb == b)
1294     continue;
1295     bl = b->cx - b->tw/2;
1296     br = b->cx + b->tw/2;
1297     tbl = tb->cx - tb->tw/2;
1298     tbr = tb->cx + tb->tw/2;
1299     if(b->y < tb->y && ((bl >= tbl && bl <= tbr) || (br <= tbr && br >= tbl)))
1300     {
1301     int s = tb->y - conf.branch_connect - conf.branch_margin - (b->y + b->th);
1302     if(s < space)
1303     space = s;
1304     }
1305     if(recurse)
1306     {
1307     int j, k;
1308     for(j = 0; j < b->nrevs; j++)
1309     {
1310     for(k = 0; k < b->revs[j]->nbranches; k++)
1311     {
1312     int s = has_space_below(rcs, b->revs[j]->branches[k], recurse);
1313     if(s < space)
1314     space = s;
1315     }
1316     }
1317     }
1318     }
1319     return space;
1320     }
1321    
1322     /* Stretch a branch from the top til revision r */
1323     void stretch_branch(rcsfile_t *rcs, revision_t *r, int spaceneeded)
1324     {
1325     branch_t *b = r->branch;
1326     int rtag = index_of_revision(r);
1327     int hasspace = has_space_below(rcs, b, 0);
1328     int i, j;
1329     for(i = rtag; i < b->nrevs; i++)
1330     {
1331     for(j = 0; j < b->revs[i]->nbranches; j++)
1332     {
1333     int s = has_space_below(rcs, b->revs[i]->branches[j], 1);
1334     if(s < hasspace)
1335     hasspace = s;
1336     }
1337     }
1338     if(hasspace >= spaceneeded)
1339     {
1340     int ext = spaceneeded / (rtag + 1);
1341     int rest = spaceneeded - ext * (rtag + 1);
1342     for(i = 0; i < rtag; i++)
1343     {
1344     /* FIXME: conf.rev_maxline */
1345     move_yr_branch(b->revs[i], ext);
1346     }
1347     move_yr_branch(b->revs[rtag], ext+rest);
1348     }
1349     }
1350    
1351     branch_t *get_rightmost_branch(rcsfile_t *rcs)
1352     {
1353     branch_t *b = NULL;
1354     int i;
1355     for(i = 0; i < rcs->nbranches; i++)
1356     {
1357     if(rcs->branches[i]->flag)
1358     continue;
1359     if(!b || rcs->branches[i]->cx > b->cx)
1360     b = rcs->branches[i];
1361     }
1362     if(b)
1363     b->flag = 1;
1364     #ifdef DEBUG
1365     fprintf(stderr, "get_rightmost_branch: %s\n", b ? b->branch->rev : "<none>");
1366     #endif
1367     return b;
1368     }
1369    
1370     branch_t *find_left_colission_branch(rcsfile_t *rcs, branch_t *b)
1371     {
1372     int i;
1373     branch_t *lcb = NULL;
1374     for(i = 0; i < rcs->nbranches; i++)
1375     {
1376     branch_t *tag = rcs->branches[i];
1377     if(tag == b)
1378     continue;
1379     /* FIXME branch_margins */
1380     if((b->y >= tag->y && b->y <= tag->y + tag->th)
1381     || (tag->y >= b->y && tag->y <= b->y + b->th))
1382     {
1383     if(!lcb || lcb->cx < tag->cx)
1384     lcb = tag;
1385     }
1386     }
1387     return lcb;
1388     }
1389    
1390     void auto_kern(rcsfile_t *rcs)
1391     {
1392     /* Initially move branches left if there is room */
1393     kern_tree(rcs);
1394    
1395     if(conf.auto_kern)
1396     {
1397     branch_t *b;
1398     /* Stretch each branch's revision spacing and try to kern more */
1399     while((b = get_rightmost_branch(rcs)))
1400     {
1401     int spaceneeded;
1402     branch_t *lcb = find_left_colission_branch(rcs, b);
1403     if(!lcb || !b->branchpoint || lcb == b->branchpoint->branch)
1404     continue;
1405     spaceneeded = b->y + b->th + conf.branch_margin + conf.branch_connect - lcb->y;
1406     if(spaceneeded)
1407     {
1408     stretch_branch(rcs, lcb->branchpoint, spaceneeded);
1409     kern_tree(rcs);
1410     }
1411     }
1412     }
1413     }
1414    
1415 bertho 1.7 void make_layout(rcsfile_t *rcs)
1416 bertho 1.1 {
1417     int i, j;
1418     int x, y;
1419     int w, h;
1420     int w2;
1421    
1422 bertho 1.16 /* Remove all unwanted revisions */
1423     if(conf.strip_untagged)
1424     {
1425 bertho 1.18 int fr = conf.strip_first_rev ? 1 : 0;
1426 bertho 1.16 for(i = 0; i < rcs->nbranches; i++)
1427     {
1428     branch_t *bp = rcs->branches[i];
1429 bertho 1.18 for(j = fr; j < bp->nrevs-1; j++)
1430 bertho 1.16 {
1431     if(!bp->revs[j]->ntags && !bp->revs[j]->nbranches)
1432     {
1433     memmove(&bp->revs[j], &bp->revs[j+1], (bp->nrevs-j-1) * sizeof(bp->revs[0]));
1434     bp->nrevs--;
1435 bertho 1.17 bp->revs[j]->stripped = 1;
1436 bertho 1.16 j--;
1437     }
1438     }
1439     }
1440     }
1441    
1442 bertho 1.1 /* Calculate the box-sizes of the revisions */
1443 bertho 1.7 for(i = 0; i < rcs->nsrev; i++)
1444 bertho 1.1 {
1445     revision_t *rp;
1446     int w;
1447     int h;
1448 bertho 1.7 rp = rcs->srev[i];
1449 bertho 1.9 rp->revtext = expand_string(conf.rev_text, rcs, rp, rp->rev, NULL, rp->ntags ? rp->tags[0] : NULL);
1450     w = get_swidth(rp->revtext, &conf.rev_text_font);
1451     j = get_swidth(rp->rev->rev, &conf.rev_font);
1452     if(j > w)
1453     w = j;
1454     h = get_sheight(rp->revtext, &conf.rev_text_font) + get_sheight(rp->rev->rev, &conf.rev_font);
1455 bertho 1.1 for(j = 0; j < rp->ntags; j++)
1456     {
1457     int ww = get_swidth(rp->tags[j]->tag, &conf.tag_font);
1458     if(ww > w) w = ww;
1459     h += get_sheight(rp->tags[j]->tag, &conf.tag_font) + conf.rev_separator;
1460     }
1461     rp->w = w + conf.rev_lspace + conf.rev_rspace;
1462     rp->h = h + conf.rev_tspace + conf.rev_bspace;
1463     }
1464    
1465     /* Calculate the box-sizes of the branches */
1466     for(i = 0; i < rcs->nbranches; i++)
1467     {
1468     branch_t *bp = rcs->branches[i];
1469     int w;
1470     int h;
1471 bertho 1.7 w = get_swidth(bp->branch->branch, &conf.branch_font);
1472     h = get_sheight(bp->branch->branch, &conf.branch_font);
1473     for(j = 0; j < bp->ntags; j++)
1474 bertho 1.1 {
1475 bertho 1.7 int ww = get_swidth(bp->tags[j]->tag, &conf.branch_font);
1476 bertho 1.1 if(ww > w) w = ww;
1477 bertho 1.7 h += get_sheight(bp->tags[j]->tag, &conf.branch_font);
1478 bertho 1.1 }
1479     w += conf.branch_lspace + conf.branch_rspace;
1480     h += conf.branch_tspace + conf.branch_bspace;
1481     bp->w = w;
1482     bp->h = h;
1483     for(j = 0; j < bp->nrevs; j++)
1484     {
1485     if(bp->revs[j]->w > w)
1486     w = bp->revs[j]->w;
1487     h += bp->revs[j]->h + conf.rev_minline;
1488     }
1489 bertho 1.17 if(conf.branch_dupbox)
1490 bertho 1.16 h += bp->h + conf.rev_minline;
1491 bertho 1.1 bp->th = h;
1492     bp->tw = w;
1493     }
1494    
1495     /* Calculate the relative positions of revs in a branch */
1496     for(i = 0; i < rcs->nbranches; i++)
1497     {
1498     branch_t *b = rcs->branches[i];
1499     x = b->tw/2;
1500     y = b->h;
1501 bertho 1.7 b->cx = x;
1502 bertho 1.1 b->y = 0;
1503     for(j = 0; j < b->nrevs; j++)
1504     {
1505     y += conf.rev_minline;
1506 bertho 1.7 b->revs[j]->cx = x;
1507 bertho 1.1 b->revs[j]->y = y;
1508     y += b->revs[j]->h;
1509     }
1510     }
1511    
1512 bertho 1.18 /* Initially reposition the branches from bottom to top progressively right */
1513 bertho 1.7 x = rcs->branches[0]->cx;
1514 bertho 1.1 w2 = rcs->branches[0]->tw / 2;
1515     for(i = rcs->branches[0]->nrevs-1; i >= 0; i--)
1516     {
1517 bertho 1.18 initial_reposition_branch(rcs->branches[0]->revs[i], &x, &w2);
1518 bertho 1.1 }
1519    
1520 bertho 1.18 /* Try to kern the branches more by expanding the inter-revision spacing */
1521     auto_kern(rcs);
1522 bertho 1.7
1523     /* Move everything w.r.t. the top-left margin */
1524 bertho 1.1 for(i = 0; i < rcs->nbranches; i++)
1525     move_branch(rcs->branches[i], conf.margin_left, conf.margin_top);
1526    
1527     /* Calculate overall image size */
1528 bertho 1.7 x = rcs->branches[0]->cx - rcs->branches[0]->tw/2;
1529 bertho 1.1 y = rcs->branches[0]->y;
1530     w = rcs->branches[0]->tw;
1531     h = rcs->branches[0]->th;
1532     for(i = 1; i < rcs->nbranches; i++)
1533     rect_union(&x, &y, &w, &h, rcs->branches[i]);
1534     rcs->tw = w;
1535     rcs->th = h;
1536 bertho 1.16
1537     /* Flip the entire tree */
1538     if(conf.upside_down)
1539     {
1540     y += rcs->th;
1541     for(i = 0; i < rcs->nbranches; i++)
1542     {
1543     branch_t *b = rcs->branches[i];
1544     for(j = 0; j < b->nrevs; j++)
1545     {
1546     revision_t *r = b->revs[j];
1547     r->y = y - r->y - r->h + conf.margin_top;
1548     }
1549     b->y = y - b->y - b->h + conf.margin_top;
1550     }
1551     }
1552 bertho 1.1 }
1553    
1554     /*
1555     **************************************************************************
1556 bertho 1.6 * Imagemap functions
1557     **************************************************************************
1558     */
1559 bertho 1.7 void make_imagemap(rcsfile_t *rcs, FILE *fp)
1560 bertho 1.6 {
1561     int i, j;
1562     fprintf(fp, "<map name=\"%s\">\n", conf.map_name);
1563     for(i = 0; i < rcs->nbranches; i++)
1564     {
1565     branch_t *b = rcs->branches[i];
1566 bertho 1.8 tag_t *tag = b->ntags ? b->tags[0] : NULL;
1567 bertho 1.16 char *bhref = expand_string(conf.map_branch_href, rcs, NULL, b->branch, NULL, tag);
1568     char *balt = expand_string(conf.map_branch_alt, rcs, NULL, b->branch, NULL, tag);
1569 bertho 1.8 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s>\n",
1570 bertho 1.16 bhref,
1571 bertho 1.7 b->cx - b->w/2, b->y, b->cx + b->w/2, b->y + b->h,
1572 bertho 1.16 balt);
1573 bertho 1.6 for(j = 0; j < b->nrevs; j++)
1574     {
1575     revision_t *r = b->revs[j];
1576 bertho 1.13 revision_t* r1;
1577     int xoff;
1578     int x1;
1579     int x2;
1580     int y1;
1581 bertho 1.16 int y2;
1582     char *href;
1583     char *alt;
1584 bertho 1.13
1585 bertho 1.8 tag = r->ntags ? r->tags[0] : NULL;
1586 bertho 1.9 href = expand_string(conf.map_rev_href, rcs, r, r->rev, NULL, tag);
1587     alt = expand_string(conf.map_rev_alt, rcs, r, r->rev, NULL, tag);
1588 bertho 1.8 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s>\n",
1589     href,
1590 bertho 1.7 r->cx - r->w/2, r->y, r->cx + r->w/2, r->y + r->h,
1591 bertho 1.8 alt);
1592     xfree(href);
1593     xfree(alt);
1594 bertho 1.16 if(j > 0 || b->branchpoint)
1595 bertho 1.9 {
1596 bertho 1.16 if(j > 0)
1597     {
1598     r1 = b->revs[j-1];
1599     xoff = MIN(r->w, r1->w)/4;
1600     y1 = conf.upside_down ? r1->y : r1->y + r1->h;
1601     }
1602     else
1603     {
1604     r1 = b->branchpoint;
1605     xoff = MIN(r->w, b->w)/4;
1606     y1 = conf.upside_down ? b->y : b->y + b->h;
1607     }
1608     x1 = r->cx - xoff;
1609     x2 = r->cx + xoff;
1610     y2 = conf.upside_down ? r->y + r->h : r->y;
1611     href = expand_string(conf.map_diff_href, rcs, r, r->rev, r1->rev, tag);
1612     alt = expand_string(conf.map_diff_alt, rcs, r, r->rev, r1->rev, tag);
1613     fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s>\n",
1614     href,
1615     x1, y1 + 1, x2, y2 - 1,
1616     alt);
1617     xfree(href);
1618     xfree(alt);
1619 bertho 1.9 }
1620 bertho 1.6 }
1621 bertho 1.17 if(conf.branch_dupbox)
1622 bertho 1.16 {
1623     int y;
1624     if(conf.upside_down)
1625     y = b->y + b->h - b->th;
1626     else
1627     y = b->y - b->h + b->th;
1628     fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s>\n",
1629     bhref,
1630     b->cx - b->w/2, y, b->cx + b->w/2, y + b->h,
1631     balt);
1632     }
1633     xfree(bhref);
1634     xfree(balt);
1635 bertho 1.6 }
1636     fprintf(fp, "</map>\n");
1637     }
1638    
1639     /*
1640     **************************************************************************
1641 bertho 1.1 * Program entry
1642     **************************************************************************
1643     */
1644     static const char usage_str[] =
1645     "Usage: cvsgraph [options] <file>\n"
1646 bertho 1.16 " -b Add a branch box at both sides of the trunk (config value is negated)\n"
1647 bertho 1.8 " -c <file> Read alternative config from <file>\n"
1648     " -d <level> Enable debug mode at <level>\n"
1649     " -h This message\n"
1650     " -i Generate an imagemap instead of image\n"
1651 bertho 1.18 " -I <file> Also write the imagemap to <file>\n"
1652     " -k Autokern the tree (config value is negated)\n"
1653 bertho 1.8 " -M <name> Use <name> as imagemap name\n"
1654     " -m <mod> Use <mod> as cvs module\n"
1655     " -o <file> Output to <file>\n"
1656 bertho 1.18 " -O <opt=val> Set option opt to value val\n"
1657 bertho 1.8 " -q Be quiet (i.e. no warnings)\n"
1658     " -r <path> Use <path> as cvsroot path\n"
1659 bertho 1.16 " -s Strip untagged revisions (config value is negated)\n"
1660 bertho 1.18 " -S Also strip the first revision (config value is negated)\n"
1661 bertho 1.16 " -u Upside down image (mirror vertically; config value is negated)\n"
1662 bertho 1.8 " -V Print version and exit\n"
1663     " -[0-9] <txt> Use <txt> for expansion\n"
1664 bertho 1.1 ;
1665    
1666 bertho 1.18 #define VERSION_STR "1.2.0"
1667     #define NOTICE_STR "Copyright (c) 2001-2002 B.Stultiens"
1668 bertho 1.1
1669 bertho 1.9 void append_slash(char **path)
1670     {
1671     int l;
1672     assert(path != NULL);
1673     assert(*path != NULL);
1674     l = strlen(*path);
1675     if(!l || (*path)[l-1] == '/')
1676     return;
1677     *path = xrealloc(*path, l+2);
1678     strcat(*path, "/");
1679     }
1680    
1681 bertho 1.1 int main(int argc, char *argv[])
1682     {
1683 bertho 1.7 extern int rcs_flex_debug;
1684     extern int rcsdebug;
1685 bertho 1.1 int optc;
1686     char *confpath = NULL;
1687     char *outfile = NULL;
1688     char *cvsroot = NULL;
1689     char *cvsmodule = NULL;
1690 bertho 1.7 int imagemap = 0;
1691 bertho 1.16 int upsidedown = 0;
1692 bertho 1.17 int bdupbox = 0;
1693 bertho 1.16 int stripuntag = 0;
1694 bertho 1.18 int stripfirst = 0;
1695     int autokern = 0;
1696 bertho 1.7 char *imgmapname = NULL;
1697 bertho 1.18 char *imgmapfile = NULL;
1698 bertho 1.1 int lose = 0;
1699     FILE *fp;
1700 bertho 1.18 char *rcsfilename;
1701 bertho 1.7 rcsfile_t *rcs;
1702 bertho 1.1 gdImagePtr im;
1703    
1704 bertho 1.18 while((optc = getopt(argc, argv, "0:1:2:3:4:5:6:7:8:9:bc:d:hI:ikM:m:O:o:qr:SsuV")) != EOF)
1705 bertho 1.1 {
1706     switch(optc)
1707     {
1708 bertho 1.16 case 'b':
1709 bertho 1.17 bdupbox = 1;
1710 bertho 1.16 break;
1711 bertho 1.1 case 'c':
1712     confpath = xstrdup(optarg);
1713     break;
1714 bertho 1.7 case 'd':
1715     debuglevel = strtol(optarg, NULL, 0);
1716     break;
1717 bertho 1.18 case 'I':
1718     imgmapfile = xstrdup(optarg);
1719     break;
1720 bertho 1.6 case 'i':
1721 bertho 1.7 imagemap = 1;
1722     break;
1723 bertho 1.18 case 'k':
1724     autokern = 1;
1725     break;
1726 bertho 1.7 case 'M':
1727     imgmapname = xstrdup(optarg);
1728 bertho 1.6 break;
1729 bertho 1.1 case 'm':
1730     cvsmodule = xstrdup(optarg);
1731     break;
1732 bertho 1.18 case 'O':
1733     stack_option(optarg);
1734     break;
1735 bertho 1.1 case 'o':
1736     outfile = xstrdup(optarg);
1737     break;
1738 bertho 1.7 case 'q':
1739     quiet = 1;
1740     break;
1741 bertho 1.1 case 'r':
1742     cvsroot = xstrdup(optarg);
1743     break;
1744 bertho 1.18 case 'S':
1745     stripfirst = 1;
1746     break;
1747 bertho 1.16 case 's':
1748     stripuntag = 1;
1749     break;
1750     case 'u':
1751     upsidedown = 1;
1752     break;
1753 bertho 1.1 case 'V':
1754     fprintf(stdout, "cvsgraph v%s, %s\n", VERSION_STR, NOTICE_STR);
1755     return 0;
1756     case 'h':
1757     fprintf(stdout, "%s", usage_str);
1758     return 0;
1759     default:
1760 bertho 1.8 if(isdigit(optc))
1761     {
1762     conf.expand[optc-'0'] = xstrdup(optarg);
1763     }
1764     else
1765     lose++;
1766 bertho 1.1 }
1767     }
1768    
1769     if(lose)
1770     {
1771     fprintf(stderr, "%s", usage_str);
1772     return 1;
1773     }
1774    
1775 bertho 1.7 if(debuglevel)
1776     {
1777     setvbuf(stdout, NULL, 0, _IONBF);
1778     setvbuf(stderr, NULL, 0, _IONBF);
1779     }
1780     rcs_flex_debug = (debuglevel & DEBUG_RCS_LEX) != 0;
1781     rcsdebug = (debuglevel & DEBUG_RCS_YACC) != 0;
1782    
1783 bertho 1.1 /* Set defaults */
1784 bertho 1.9 conf.tag_font = gdFontTiny;
1785     conf.rev_font = gdFontTiny;
1786     conf.branch_font = gdFontTiny;
1787     conf.title_font = gdFontTiny;
1788     conf.rev_text_font = gdFontTiny;
1789    
1790     conf.cvsroot = xstrdup("");
1791     conf.cvsmodule = xstrdup("");
1792     conf.date_format = xstrdup("%d-%b-%Y %H:%M:%S");
1793     conf.title = xstrdup("");
1794     conf.map_name = xstrdup("CvsGraphImageMap");
1795     conf.map_branch_href = xstrdup("href=\"unset: conf.map_branch_href\"");
1796     conf.map_branch_alt = xstrdup("alt=\"%B\"");
1797     conf.map_rev_href = xstrdup("href=\"unset: conf.map_rev_href\"");
1798     conf.map_rev_alt = xstrdup("alt=\"%R\"");
1799     conf.map_diff_href = xstrdup("href=\"unset: conf.map_diff_href\"");
1800 bertho 1.12 conf.map_diff_alt = xstrdup("alt=\"%P &lt;-&gt; %R\"");
1801 bertho 1.10 conf.rev_text = xstrdup("%d");
1802 bertho 1.9
1803     conf.color_bg = white_color;
1804     conf.branch_bgcolor = white_color;
1805     conf.branch_color = black_color;
1806     conf.rev_color = black_color;
1807     conf.rev_bgcolor = white_color;
1808     conf.tag_color = black_color;
1809     conf.title_color = black_color;
1810     conf.rev_text_color = black_color;
1811 bertho 1.10
1812     conf.image_quality = 100;
1813 bertho 1.18 conf.rev_maxline = -1; /* Checked later to set to default */
1814    
1815     read_config(confpath);
1816 bertho 1.1
1817 bertho 1.18 if(conf.rev_maxline == -1) conf.rev_maxline = 5 * conf.rev_minline;
1818 bertho 1.1
1819     /* Set overrides */
1820 bertho 1.7 if(cvsroot) conf.cvsroot = cvsroot;
1821     if(cvsmodule) conf.cvsmodule = cvsmodule;
1822     if(imgmapname) conf.map_name = imgmapname;
1823 bertho 1.16 if(upsidedown) conf.upside_down = !conf.upside_down;
1824 bertho 1.17 if(bdupbox) conf.branch_dupbox = !conf.branch_dupbox;
1825 bertho 1.16 if(stripuntag) conf.strip_untagged = !conf.strip_untagged;
1826 bertho 1.18 if(stripfirst) conf.strip_first_rev = !conf.strip_first_rev;
1827     if(autokern) conf.auto_kern = !conf.auto_kern;
1828    
1829     if(conf.rev_minline >= conf.rev_maxline)
1830     {
1831     if(conf.auto_kern && !quiet)
1832     fprintf(stderr, "Autokern is only possible if rev_minline < rev_maxline\n");
1833     conf.auto_kern = 0;
1834     }
1835 bertho 1.1
1836 bertho 1.9 append_slash(&conf.cvsroot);
1837     append_slash(&conf.cvsmodule);
1838    
1839 bertho 1.18 if(optind >= argc)
1840     {
1841     #ifdef __WIN32__
1842     /* Bad hack for DOS/Windows */
1843     if(setmode(fileno(stdin), O_BINARY) == -1)
1844     {
1845     perror("Set binary mode for stdin");
1846     return 1;
1847     }
1848     #endif
1849     rcsfilename = NULL;
1850     }
1851     else
1852     rcsfilename = argv[optind];
1853    
1854     rcs = get_rcsfile(conf.cvsroot, conf.cvsmodule, rcsfilename);
1855 bertho 1.1 if(!rcs)
1856     return 1;
1857    
1858 bertho 1.7 if(debuglevel & DEBUG_RCS_FILE)
1859     dump_rcsfile(rcs);
1860 bertho 1.1
1861 bertho 1.7 if(!reorganise_branches(rcs))
1862     return 1;
1863 bertho 1.1
1864 bertho 1.7 if(!assign_tags(rcs))
1865     return 1;
1866 bertho 1.1
1867     if(outfile)
1868     {
1869 bertho 1.15 if((fp = fopen(outfile, "wb")) == NULL)
1870 bertho 1.1 {
1871     perror(outfile);
1872     return 1;
1873     }
1874     }
1875     else
1876 bertho 1.15 {
1877 bertho 1.1 fp = stdout;
1878 bertho 1.15 #ifdef __WIN32__
1879     /* Bad hack for DOS/Windows */
1880     if(setmode(fileno(fp), O_BINARY) == -1)
1881     {
1882     perror("Set binary mode for stdout");
1883     return 1;
1884     }
1885     #endif
1886     }
1887 bertho 1.5
1888 bertho 1.7 make_layout(rcs);
1889    
1890     if(!imagemap)
1891 bertho 1.5 {
1892 bertho 1.7 /* Create an image */
1893     im = make_image(rcs);
1894    
1895     switch(conf.image_type)
1896     {
1897 bertho 1.5 #ifdef HAVE_IMAGE_GIF
1898 bertho 1.7 # ifndef HAVE_IMAGE_PNG
1899     default:
1900     # endif
1901     case IMAGE_GIF:
1902     gdImageGif(im, fp);
1903     break;
1904 bertho 1.5 #endif
1905     #ifdef HAVE_IMAGE_PNG
1906 bertho 1.7 default:
1907     case IMAGE_PNG:
1908     gdImagePng(im, fp);
1909     break;
1910 bertho 1.5 #endif
1911     #ifdef HAVE_IMAGE_JPEG
1912     # if !defined(HAVE_IMAGE_GIF) && !defined(HAVE_IMAGE_PNG)
1913 bertho 1.7 default:
1914 bertho 1.5 # endif
1915 bertho 1.7 case IMAGE_JPEG:
1916     gdImageJpeg(im, fp, conf.image_quality);
1917     break;
1918 bertho 1.5 #endif
1919 bertho 1.7 }
1920    
1921     gdImageDestroy(im);
1922     }
1923     else
1924     {
1925     /* Create an imagemap */
1926     make_imagemap(rcs, fp);
1927 bertho 1.18 }
1928    
1929     /* Also create imagemap to file if requested */
1930     if(imgmapfile)
1931     {
1932     FILE *ifp = fopen(imgmapfile, "wb");
1933     if(!ifp)
1934     {
1935     perror(imgmapfile);
1936     return 1;
1937     }
1938     make_imagemap(rcs, ifp);
1939     fclose(ifp);
1940 bertho 1.5 }
1941    
1942 bertho 1.1 if(outfile)
1943     fclose(fp);
1944 bertho 1.6
1945 bertho 1.1 return 0;
1946     }
1947    

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0