/[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.29 - (show annotations)
Tue Feb 11 10:43:44 2003 UTC (14 years, 9 months ago) by bertho
Branch: MAIN
Changes since 1.28: +46 -13 lines
File MIME type: text/plain
- Implement different HTML levels for imagemaps.
- Add new commandline option for HTML level
- Update docs
1 /*
2 * CvsGraph graphical representation generator of brances and revisions
3 * of a file in cvs/rcs.
4 *
5 * Copyright (C) 2001,2002,2003 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 #include "config.h"
23
24 #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 #include <ctype.h>
36 #include <time.h>
37 #include <limits.h>
38
39 #ifdef HAVE_GETOPT_H
40 # include <getopt.h>
41 #endif
42
43 #include <gd.h>
44 #include <gdfontt.h>
45
46 #include "cvsgraph.h"
47 #include "utils.h"
48 #include "readconf.h"
49 #include "rcs.h"
50
51 #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 /*#define DEBUG 1*/
57 /*#define NOGDFILL 1*/
58 /*#define DEBUG_IMAGEMAP 1*/
59
60 #define LOOPSAFEGUARD 100 /* Max itterations in possible infinite loops */
61
62 #ifndef MAX
63 # define MAX(a,b) ((a) > (b) ? (a) : (b))
64 #endif
65
66 #ifndef MIN
67 # define MIN(a,b) ((a) < (b) ? (a) : (b))
68 #endif
69
70 #define ALIGN_HL 0x00
71 #define ALIGN_HC 0x01
72 #define ALIGN_HR 0x02
73 #define ALIGN_HX 0x0f
74 #define ALIGN_VT 0x00
75 #define ALIGN_VC 0x10
76 #define ALIGN_VB 0x20
77 #define ALIGN_VX 0xf0
78
79 /*
80 **************************************************************************
81 * Globals
82 **************************************************************************
83 */
84
85 config_t conf;
86 int debuglevel;
87 color_t white_color = {255, 255, 255, 0};
88 color_t black_color = {0, 0, 0, 0};
89
90
91 /*
92 **************************************************************************
93 * Debug routines
94 **************************************************************************
95 */
96 static void dump_rev(char *p, rev_t *r)
97 {
98 printf("%s", p);
99 if(r)
100 printf("'%s', '%s', %d\n", r->rev, r->branch, r->isbranch);
101 else
102 printf("<null>\n");
103 }
104
105 static void dump_id(char *p, char *d)
106 {
107 printf("%s", p);
108 if(d)
109 printf("'%s'\n", d);
110 else
111 printf("<null>\n");
112 }
113
114 static void dump_idrev(char *p, idrev_t *t)
115 {
116 printf("%s", p);
117 if(t)
118 {
119 printf("'%s' -> ", t->id);
120 dump_rev("", t->rev);
121 }
122 else
123 printf("<null>\n");
124 }
125
126 static void dump_tag(char *p, tag_t *t)
127 {
128 printf("%s", p);
129 if(t)
130 {
131 printf("'%s' -> ", t->tag);
132 dump_rev("", t->rev);
133 }
134 else
135 printf("<null>\n");
136 }
137
138 static void dump_delta(char *p, delta_t *d)
139 {
140 int i;
141 printf("%sdelta.rev : ", p);
142 dump_rev("", d->rev);
143 printf("%sdelta.date : %s\n", p, d->date);
144 printf("%sdelta.author: %s\n", p, d->author);
145 printf("%sdelta.state : %s\n", p, d->state);
146 for(i = 0; d->branches && i < d->branches->nrevs; i++)
147 {
148 printf("%sdelta.branch: ", p);
149 dump_rev("", d->branches->revs[i]);
150 }
151 printf("%sdelta.next : ", p);
152 dump_rev("", d->next);
153 printf("\n");
154 }
155
156 static void dump_dtext(char *p, dtext_t *d)
157 {
158 printf("%sdtext.rev : ", p);
159 dump_rev("", d->rev);
160 printf("%sdtext.log : %d bytes\n", p, d->log ? strlen(d->log) : -1);
161 printf("%sdtext.text : %d bytes\n", p, d->text ? strlen(d->text) : -1);
162 printf("\n");
163 }
164
165 static void dump_rcsfile(rcsfile_t *rcs)
166 {
167 int i;
168 printf("root : '%s'\n", rcs->root);
169 printf("module : '%s'\n", rcs->module);
170 printf("file : '%s'\n", rcs->file);
171 dump_rev("head : ", rcs->head);
172 dump_rev("branch : ", rcs->branch);
173 printf("access :\n");
174 for(i = 0; rcs->access && i < rcs->access->nids; i++)
175 dump_id("\t", rcs->access->ids[i]);
176 printf("tags :\n");
177 for(i = 0; rcs->tags && i < rcs->tags->ntags; i++)
178 dump_tag("\t", rcs->tags->tags[i]);
179 printf("locks :%s\n", rcs->strict ? " (strict)" : "");
180 for(i = 0; rcs->locks && i < rcs->locks->nidrevs; i++)
181 dump_idrev("\t", rcs->locks->idrevs[i]);
182 printf("comment: '%s'\n", rcs->comment);
183 printf("expand : '%s'\n", rcs->expand ? rcs->expand : "(default -kv)");
184 printf("deltas :\n");
185 for(i = 0; rcs->deltas && i < rcs->deltas->ndeltas; i++)
186 dump_delta("\t", rcs->deltas->deltas[i]);
187 printf("desc : '%s'\n", rcs->desc);
188 printf("dtexts :\n");
189 for(i = 0; rcs->dtexts && i < rcs->dtexts->ndtexts; i++)
190 dump_dtext("\t", rcs->dtexts->dtexts[i]);
191
192 fflush(stdout);
193 }
194
195 /*
196 **************************************************************************
197 * Read the rcs file
198 **************************************************************************
199 */
200 rcsfile_t *get_rcsfile(const char *cvsroot, const char *module, const char *file)
201 {
202 char *cmd = NULL;
203 int rv;
204
205 if(file)
206 {
207 cmd = xmalloc(strlen(cvsroot) + strlen(module) + strlen(file) + 1);
208 sprintf(cmd, "%s%s%s", cvsroot, module, file);
209 if(!(rcsin = fopen(cmd, "rb")))
210 {
211 perror(cmd);
212 return NULL;
213 }
214 input_file = cmd;
215 }
216 else
217 {
218 rcsin = stdin;
219 input_file = "<stdin>";
220 }
221 line_number = 1;
222 rv = rcsparse();
223 if(file)
224 {
225 fclose(rcsin);
226 xfree(cmd);
227 }
228 if(rv)
229 return NULL;
230 input_file = NULL;
231 if(file)
232 {
233 rcsfile->root = xstrdup(cvsroot);
234 rcsfile->module = xstrdup(module);
235 rcsfile->file = xstrdup(file);
236 }
237 else
238 {
239 rcsfile->root = xstrdup("");
240 rcsfile->module = xstrdup("");
241 rcsfile->file = xstrdup("<stdin>");
242 }
243 return rcsfile;
244 }
245
246 /*
247 **************************************************************************
248 * Sort and find helpers
249 **************************************************************************
250 */
251 int count_dots(const char *s)
252 {
253 int i;
254 for(i = 0; *s; s++)
255 {
256 if(*s == '.')
257 i++;
258 }
259 return i;
260 }
261
262 int compare_rev(int bcmp, const rev_t *r1, const rev_t *r2)
263 {
264 int d1, d2;
265 char *c1, *c2;
266 char *v1, *v2;
267 char *s1, *s2;
268 int retval = 0;
269 assert(r1 != NULL);
270 assert(r2 != NULL);
271 if(bcmp)
272 {
273 assert(r1->branch != NULL);
274 assert(r2->branch != NULL);
275 c1 = r1->branch;
276 c2 = r2->branch;
277 }
278 else
279 {
280 assert(r1->rev != NULL);
281 assert(r2->rev != NULL);
282 c1 = r1->rev;
283 c2 = r2->rev;
284 }
285
286 d1 = count_dots(c1);
287 d2 = count_dots(c2);
288 if(d1 != d2)
289 {
290 return d1 - d2;
291 }
292
293 s1 = v1 = xstrdup(c1);
294 s2 = v2 = xstrdup(c2);
295 while(1)
296 {
297 char *vc1 = strchr(s1, '.');
298 char *vc2 = strchr(s2, '.');
299 if(vc1 && vc2)
300 *vc1 = *vc2 = '\0';
301 if(*s1 && *s2)
302 {
303 d1 = atoi(s1);
304 d2 = atoi(s2);
305 if(d1 != d2)
306 {
307 retval = d1 - d2;
308 break;
309 }
310 }
311 if(!vc1 || !vc2)
312 break;
313 s1 = vc1 + 1;
314 s2 = vc2 + 1;
315 }
316 xfree(v1);
317 xfree(v2);
318 return retval;
319 }
320
321 /*
322 **************************************************************************
323 * Reorganise the rcsfile for the branches
324 *
325 * Basically, we have a list of deltas (i.e. administrative info on
326 * revisions) and a list of delta text (the actual logs and diffs).
327 * The deltas are linked through the 'next' and the 'branches' fields
328 * which describe the tree-structure of revisions.
329 * The reorganisation means that we put each delta and corresponding
330 * delta text in a revision structure and assign it to a specific
331 * branch. This is required because we want to be able to calculate
332 * the bounding boxes of each branch. The revisions expand vertically
333 * and the branches expand horizontally.
334 * The reorganisation is performed in these steps:
335 * 1 - sort deltas and delta text on revision number for quick lookup
336 * 2 - start at the denoted head revision:
337 * * create a branch structure and add this revision
338 * * for each 'branches' in the delta do:
339 * - walk all 'branches' of the delta and recursively goto 2
340 * with the denoted branch delta as new head
341 * - backlink the newly create sub-branch to the head revision
342 * so that we can draw them recursively
343 * * set head to the 'next' field and goto 2 until no next is
344 * available
345 * 3 - update the administration
346 **************************************************************************
347 */
348 static int sort_delta(const void *d1, const void *d2)
349 {
350 return compare_rev(0, (*(delta_t **)d1)->rev, (*(delta_t **)d2)->rev);
351 }
352
353 static int search_delta(const void *r, const void *d)
354 {
355 return compare_rev(0, (rev_t *)r, (*(delta_t **)d)->rev);
356 }
357
358 static delta_t *find_delta(delta_t **dl, int n, rev_t *r)
359 {
360 delta_t **d;
361 if(!n)
362 return NULL;
363 d = bsearch(r, dl, n, sizeof(*dl), search_delta);
364 if(!d)
365 return NULL;
366 return *d;
367 }
368
369 static int sort_dtext(const void *d1, const void *d2)
370 {
371 return compare_rev(0, (*(dtext_t **)d1)->rev, (*(dtext_t **)d2)->rev);
372 }
373
374 static int search_dtext(const void *r, const void *d)
375 {
376 return compare_rev(0, (rev_t *)r, (*(dtext_t **)d)->rev);
377 }
378
379 static dtext_t *find_dtext(dtext_t **dl, int n, rev_t *r)
380 {
381 dtext_t **d;
382 if(!n)
383 return NULL;
384 d = bsearch(r, dl, n, sizeof(*dl), search_dtext);
385 if(!d)
386 return NULL;
387 return *d;
388 }
389
390 static rev_t *dup_rev(const rev_t *r)
391 {
392 rev_t *t = xmalloc(sizeof(*t));
393 t->rev = xstrdup(r->rev);
394 t->branch = xstrdup(r->branch);
395 t->isbranch = r->isbranch;
396 return t;
397 }
398
399 static branch_t *new_branch(delta_t *d, dtext_t *t)
400 {
401 branch_t *b = xmalloc(sizeof(*b));
402 revision_t *r = xmalloc(sizeof(*r));
403 r->delta = d;
404 r->dtext = t;
405 r->rev = d->rev;
406 r->branch = b;
407 b->branch = dup_rev(d->rev);
408 b->branch->isbranch = 1;
409 b->nrevs = 1;
410 b->revs = xmalloc(sizeof(b->revs[0]));
411 b->revs[0] = r;
412 return b;
413 }
414
415 static revision_t *add_to_branch(branch_t *b, delta_t *d, dtext_t *t)
416 {
417 revision_t *r = xmalloc(sizeof(*r));
418 r->delta = d;
419 r->dtext = t;
420 r->rev = d->rev;
421 r->branch = b;
422 b->revs = xrealloc(b->revs, (b->nrevs+1) * sizeof(b->revs[0]));
423 b->revs[b->nrevs] = r;
424 b->nrevs++;
425 return r;
426 }
427
428 void build_branch(branch_t ***bl, int *nbl, delta_t **sdl, int nsdl, dtext_t **sdt, int nsdt, delta_t *head)
429 {
430 branch_t *b;
431 dtext_t *text;
432 revision_t *currev;
433
434 assert(head != NULL);
435
436 if(head->flag)
437 {
438 fprintf(stderr, "Circular reference on '%s' in branchpoint\n", head->rev->rev);
439 return;
440 }
441 head->flag++;
442 text = find_dtext(sdt, nsdt, head->rev);
443
444 /* Create a new branch for this head */
445 b = new_branch(head, text);
446 *bl = xrealloc(*bl, (*nbl+1)*sizeof((*bl)[0]));
447 (*bl)[*nbl] = b;
448 (*nbl)++;
449 currev = b->revs[0];
450 while(1)
451 {
452 /* Process all sub-branches */
453 if(head->branches)
454 {
455 int i;
456 for(i = 0; i < head->branches->nrevs; i++)
457 {
458 delta_t *d = find_delta(sdl, nsdl, head->branches->revs[i]);
459 int btag = *nbl;
460 if(!d)
461 continue;
462 build_branch(bl, nbl, sdl, nsdl, sdt, nsdt, d);
463
464 /* Set the new branch's origin */
465 (*bl)[btag]->branchpoint = currev;
466
467 /* Add branch to this revision */
468 currev->branches = xrealloc(currev->branches, (currev->nbranches+1)*sizeof(currev->branches[0]));
469 currev->branches[currev->nbranches] = (*bl)[btag];
470 currev->nbranches++;
471 }
472 }
473
474 /* Walk through the next list */
475 if(!head->next)
476 return;
477
478 head = find_delta(sdl, nsdl, head->next);
479 if(!head)
480 {
481 fprintf(stderr, "Next revision (%s) not found in deltalist\n", head->next->rev);
482 return;
483 }
484 if(head->flag)
485 {
486 fprintf(stderr, "Circular reference on '%s'\n", head->rev->rev);
487 return;
488 }
489 head->flag++;
490 text = find_dtext(sdt, nsdt, head->rev);
491 currev = add_to_branch(b, head, text);
492 }
493 }
494
495 int reorganise_branches(rcsfile_t *rcs)
496 {
497 delta_t **sdelta;
498 int nsdelta;
499 dtext_t **sdtext;
500 int nsdtext;
501 delta_t *head;
502 branch_t **bl;
503 int nbl;
504 int i;
505
506 assert(rcs->deltas != NULL);
507 assert(rcs->head != NULL);
508
509 /* Make a new list for quick lookup */
510 nsdelta = rcs->deltas->ndeltas;
511 sdelta = xmalloc(nsdelta * sizeof(sdelta[0]));
512 memcpy(sdelta, rcs->deltas->deltas, nsdelta * sizeof(sdelta[0]));
513 qsort(sdelta, nsdelta, sizeof(sdelta[0]), sort_delta);
514
515 /* Do the same for the delta text */
516 if(rcs->dtexts)
517 {
518 nsdtext = rcs->dtexts->ndtexts;
519 sdtext = xmalloc(nsdtext * sizeof(sdtext[0]));
520 memcpy(sdtext, rcs->dtexts->dtexts, nsdtext * sizeof(sdtext[0]));
521 qsort(sdtext, nsdtext, sizeof(sdtext[0]), sort_dtext);
522 }
523 else
524 {
525 nsdtext = 0;
526 sdtext = NULL;
527 }
528
529 /* Start from the head of the trunk */
530 head = find_delta(sdelta, nsdelta, rcs->head);
531 if(!head)
532 {
533 fprintf(stderr, "Head revision (%s) not found in deltalist\n", rcs->head->rev);
534 return 0;
535 }
536 bl = NULL;
537 nbl = 0;
538 build_branch(&bl, &nbl, sdelta, nsdelta, sdtext, nsdtext, head);
539
540 /* Reverse the head branch */
541 for(i = 0; i < bl[0]->nrevs/2; i++)
542 {
543 revision_t *r;
544 r = bl[0]->revs[i];
545 bl[0]->revs[i] = bl[0]->revs[bl[0]->nrevs-i-1];
546 bl[0]->revs[bl[0]->nrevs-i-1] = r;
547 }
548
549 /* Update the branch-number of the head because it was reversed */
550 xfree(bl[0]->branch->branch);
551 bl[0]->branch->branch = xstrdup(bl[0]->revs[0]->rev->branch);
552
553 /* Keep the admin */
554 rcs->branches = bl;
555 rcs->nbranches = nbl;
556 rcs->sdelta = sdelta;
557 rcs->nsdelta = nsdelta;
558 rcs->sdtext = sdtext;
559 rcs->nsdtext = nsdtext;
560 rcs->active = bl[0];
561 return 1;
562 }
563
564 /*
565 **************************************************************************
566 * Assign the symbolic tags to the revisions and branches
567 *
568 * The tags point to revision numbers somewhere in the tree structure
569 * of branches and revisions. First we make a sorted list of all
570 * revisions and then we assign each tag to the proper revision.
571 **************************************************************************
572 */
573 static int sort_revision(const void *r1, const void *r2)
574 {
575 return compare_rev(0, (*(revision_t **)r1)->delta->rev, (*(revision_t **)r2)->delta->rev);
576 }
577
578 static int search_revision(const void *t, const void *r)
579 {
580 return compare_rev(0, (rev_t *)t, (*(revision_t **)r)->delta->rev);
581 }
582
583 static int sort_branch(const void *b1, const void *b2)
584 {
585 return compare_rev(1, (*(branch_t **)b1)->branch, (*(branch_t **)b2)->branch);
586 }
587
588 static int search_branch(const void *t, const void *b)
589 {
590 return compare_rev(1, (rev_t *)t, (*(branch_t **)b)->branch);
591 }
592
593 static char *previous_rev(const char *c)
594 {
595 int dots = count_dots(c);
596 char *cptr;
597 char *r;
598 if(!dots)
599 {
600 fprintf(stderr, "FIXME: previous_rev(\"%s\"): Cannot determine parent branch revision\n", c);
601 return xstrdup("1.0"); /* FIXME: don't know what the parent is */
602 }
603 if(dots & 1)
604 {
605 /* Is is a revision we want the parent of */
606 r = xstrdup(c);
607 cptr = strrchr(r, '.');
608 assert(cptr != NULL);
609 if(dots == 1)
610 {
611 fprintf(stderr, "FIXME: previous_rev(\"%s\"): Going beyond top-level?\n", c);
612 /* FIXME: What is the parent of 1.1? */
613 cptr[1] = '\0';
614 strcat(r, "0");
615 return r;
616 }
617 /* Here we have a "x.x[.x.x]+" case */
618 *cptr = '\0';
619 cptr = strrchr(r, '.');
620 assert(cptr != NULL);
621 *cptr = '\0';
622 return r;
623 }
624 /* It is a branch we want the parent of */
625 r = xstrdup(c);
626 cptr = strrchr(r, '.');
627 assert(cptr != NULL);
628 *cptr = '\0';
629 return r;
630 }
631
632 int assign_tags(rcsfile_t *rcs)
633 {
634 int i;
635 int nr;
636
637 for(i = nr = 0; i < rcs->nbranches; i++)
638 nr += rcs->branches[i]->nrevs;
639
640 rcs->srev = xmalloc(nr * sizeof(rcs->srev[0]));
641 rcs->nsrev = nr;
642 for(i = nr = 0; i < rcs->nbranches; i++)
643 {
644 memcpy(&rcs->srev[nr], rcs->branches[i]->revs, rcs->branches[i]->nrevs * sizeof(rcs->branches[i]->revs[0]));
645 nr += rcs->branches[i]->nrevs;
646 }
647
648 qsort(rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), sort_revision);
649 qsort(rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), sort_branch);
650
651 if(!rcs->branch)
652 {
653 /* The main trunk is the active trunk */
654 rcs->tags->tags = xrealloc(rcs->tags->tags, (rcs->tags->ntags+1)*sizeof(rcs->tags->tags[0]));
655 rcs->tags->tags[rcs->tags->ntags] = xmalloc(sizeof(tag_t));
656 rcs->tags->tags[rcs->tags->ntags]->tag = xstrdup("MAIN");
657 rcs->tags->tags[rcs->tags->ntags]->rev = xmalloc(sizeof(rev_t));
658 rcs->tags->tags[rcs->tags->ntags]->rev->rev = xstrdup(rcs->active->branch->rev);
659 rcs->tags->tags[rcs->tags->ntags]->rev->branch = xstrdup(rcs->active->branch->branch);
660 rcs->tags->tags[rcs->tags->ntags]->rev->isbranch = 1;
661 rcs->tags->ntags++;
662 }
663
664 /* We should have at least two tags (HEAD and MAIN) */
665 assert(rcs->tags != 0);
666
667 for(i = 0; i < rcs->tags->ntags; i++)
668 {
669 tag_t *t = rcs->tags->tags[i];
670 if(t->rev->isbranch)
671 {
672 branch_t **b;
673 add_btag:
674 b = bsearch(t->rev, rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), search_branch);
675 if(!b)
676 {
677 rev_t rev;
678 revision_t **r;
679 /* This happens for the magic branch numbers if there are
680 * no commits within the new branch yet. So, we add the
681 * branch and try to continue.
682 */
683 rev.rev = previous_rev(t->rev->branch);
684 rev.branch = NULL;
685 rev.isbranch = 0;
686 r = bsearch(&rev, rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), search_revision);
687 xfree(rev.rev);
688 if(!r)
689 {
690 if(!quiet)
691 fprintf(stderr, "No branch found for tag '%s:%s'\n", t->tag, t->rev->branch);
692 }
693 else
694 {
695 rcs->branches = xrealloc(rcs->branches, (rcs->nbranches+1)*sizeof(rcs->branches[0]));
696 rcs->branches[rcs->nbranches] = xmalloc(sizeof(branch_t));
697 rcs->branches[rcs->nbranches]->branch = dup_rev(t->rev);
698 rcs->branches[rcs->nbranches]->branchpoint = *r;
699 (*r)->branches = xrealloc((*r)->branches, ((*r)->nbranches+1)*sizeof((*r)->branches[0]));
700 (*r)->branches[(*r)->nbranches] = rcs->branches[rcs->nbranches];
701 (*r)->nbranches++;
702 rcs->nbranches++;
703 /* Resort the branches */
704 qsort(rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), sort_branch);
705 goto add_btag;
706 }
707 }
708 else
709 {
710 branch_t *bb = *b;
711 bb->tags = xrealloc(bb->tags, (bb->ntags+1)*sizeof(bb->tags[0]));
712 bb->tags[bb->ntags] = t;
713 bb->ntags++;
714 }
715 }
716 else
717 {
718 revision_t **r = bsearch(t->rev, rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), search_revision);
719 if(!r)
720 {
721 if(!quiet)
722 fprintf(stderr, "No revision found for tag '%s:%s'\n", t->tag, t->rev->rev);
723 }
724 else
725 {
726 revision_t *rr = *r;
727 if(!conf.rev_maxtags || rr->ntags <= conf.rev_maxtags)
728 {
729 rr->tags = xrealloc(rr->tags, (rr->ntags+1)*sizeof(rr->tags[0]));
730 if(conf.rev_maxtags && rr->ntags == conf.rev_maxtags)
731 {
732 rr->tags[rr->ntags] = xmalloc(sizeof(tag_t));
733 rr->tags[rr->ntags]->tag = xstrdup("...");
734 rr->tags[rr->ntags]->rev = t->rev;
735 }
736 else
737 rr->tags[rr->ntags] = t;
738 rr->ntags++;
739 }
740 }
741 }
742 }
743
744 /* We need to reset the first in the list of branches to the
745 * active branch to ensure the drawing of all
746 */
747 if(rcs->active != rcs->branches[0])
748 {
749 branch_t **b = bsearch(rcs->active->branch, rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), search_branch);
750 branch_t *t;
751 assert(b != NULL);
752 t = *b;
753 *b = rcs->branches[0];
754 rcs->branches[0] = t;
755 }
756 return 1;
757 }
758
759 /*
760 **************************************************************************
761 * String expansion
762 **************************************************************************
763 */
764 static char *_string;
765 static int _nstring;
766 static int _nastring;
767
768 static void add_string_str(const char *s)
769 {
770 int l = strlen(s) + 1;
771 if(_nstring + l > _nastring)
772 {
773 _nastring += MAX(128, l);
774 _string = xrealloc(_string, _nastring * sizeof(_string[0]));
775 }
776 memcpy(_string+_nstring, s, l);
777 _nstring += l-1;
778 }
779
780 static void add_string_ch(int ch)
781 {
782 char buf[2];
783 buf[0] = ch;
784 buf[1] = '\0';
785 add_string_str(buf);
786 }
787
788 static void add_string_date(const char *d)
789 {
790 struct tm tm, *tmp;
791 int n;
792 time_t t;
793 char *buf;
794 int nbuf;
795
796 memset(&tm, 0, sizeof(tm));
797 n = sscanf(d, "%d.%d.%d.%d.%d.%d",
798 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
799 &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
800 tm.tm_mon--;
801 if(tm.tm_year > 1900)
802 tm.tm_year -= 1900;
803 t = mktime(&tm);
804 if(n != 6 || t == (time_t)(-1))
805 {
806 add_string_str("<invalid date>");
807 return;
808 }
809
810 tmp = localtime(&t);
811 nbuf = strlen(conf.date_format) * 16; /* Should be enough to hold all types of expansions */
812 buf = xmalloc(nbuf);
813 strftime(buf, nbuf, conf.date_format, tmp);
814 add_string_str(buf);
815 xfree(buf);
816 }
817
818 static void add_string_str_html(const char *s, int maxlen)
819 {
820 int l = 0;
821 char *str = xmalloc(6 * strlen(s) + 1); /* Should hold all char entity-expand */
822 char *cptr = str;
823 for(; *s; s++)
824 {
825 if(maxlen && l > abs(maxlen))
826 {
827 cptr += sprintf(cptr, "...");
828 break;
829 }
830 if(*s < 0x20)
831 {
832 if(*s == '\n')
833 {
834 if(maxlen < 0)
835 *cptr++ = ' ';
836 else
837 cptr += sprintf(cptr, "<br>");
838 }
839 }
840 else if(*s >= 0x7f)
841 cptr += sprintf(cptr, "&#%d;", (int)(unsigned char)*s);
842 else if(*s == '<')
843 cptr += sprintf(cptr, "&lt;");
844 else if(*s == '>')
845 cptr += sprintf(cptr, "&gt;");
846 else
847 *cptr++ = *s;
848 l++;
849 }
850 *cptr = '\0';
851 add_string_str(str);
852 xfree(str);
853 }
854
855 static void add_string_str_len(const char *s, int maxlen)
856 {
857 int l = strlen(s);
858 char *str = xmalloc(l + 1 + 3);
859 strcpy(str, s);
860 if(maxlen < l)
861 sprintf(&str[maxlen], "...");
862 add_string_str(str);
863 xfree(str);
864 }
865
866 char *expand_string(const char *s, rcsfile_t *rcs, revision_t *r, rev_t *rev, rev_t *prev, tag_t *tag)
867 {
868 char nb[32];
869 char nr[32];
870 char *base;
871 int l;
872 char ch;
873
874 if(!s)
875 return xstrdup("");
876
877 _nstring = 0;
878 if(_string)
879 _string[0] = '\0';
880
881 sprintf(nb, "%d", rcs->nbranches);
882 sprintf(nr, "%d", rcs->nsrev);
883 for(; *s; s++)
884 {
885 if(*s == '%')
886 {
887 switch(*++s)
888 {
889 case 'c':
890 case 'C':
891 add_string_str(conf.cvsroot);
892 if(*s == 'C' && conf.cvsroot[0] && conf.cvsroot[strlen(conf.cvsroot)-1] == '/')
893 {
894 /* Strip the trailing '/' */
895 _nstring--;
896 _string[_nstring] = '\0';
897 }
898 break;
899 case 'f':
900 case 'F':
901 base = strrchr(rcs->file, '/');
902 if(!base)
903 add_string_str(rcs->file);
904 else
905 add_string_str(base+1);
906 if(*s == 'F' && _string[_nstring-1] == 'v' && _string[_nstring-2] == ',')
907 {
908 _nstring -= 2;
909 _string[_nstring] = '\0';
910 }
911 break;
912 case 'p':
913 base = strrchr(rcs->file, '/');
914 if(base)
915 {
916 char *c = xstrdup(rcs->file);
917 base = strrchr(c, '/');
918 assert(base != NULL);
919 base[1] = '\0';
920 add_string_str(c);
921 xfree(c);
922 }
923 /*
924 * We should not add anything here because we can encounter
925 * a completely empty path, in which case we do not want
926 * to add any slash. This prevents an inadvertent root redirect.
927 *
928 * else
929 * add_string_str("/");
930 */
931 break;
932 case 'm':
933 case 'M':
934 add_string_str(conf.cvsmodule);
935 if(*s == 'M' && conf.cvsmodule[0] && conf.cvsmodule[strlen(conf.cvsmodule)-1] == '/')
936 {
937 /* Strip the trailing '/' */
938 _nstring--;
939 _string[_nstring] = '\0';
940 }
941 break;
942 case 'r': add_string_str(nr); break;
943 case 'b': add_string_str(nb); break;
944 case '%': add_string_ch('%'); break;
945 case '0': if(conf.expand[0]) add_string_str(conf.expand[0]); break;
946 case '1': if(conf.expand[1]) add_string_str(conf.expand[1]); break;
947 case '2': if(conf.expand[2]) add_string_str(conf.expand[2]); break;
948 case '3': if(conf.expand[3]) add_string_str(conf.expand[3]); break;
949 case '4': if(conf.expand[4]) add_string_str(conf.expand[4]); break;
950 case '5': if(conf.expand[5]) add_string_str(conf.expand[5]); break;
951 case '6': if(conf.expand[6]) add_string_str(conf.expand[6]); break;
952 case '7': if(conf.expand[7]) add_string_str(conf.expand[7]); break;
953 case '8': if(conf.expand[8]) add_string_str(conf.expand[8]); break;
954 case '9': if(conf.expand[9]) add_string_str(conf.expand[9]); break;
955 case 'R': if(rev && rev->rev) add_string_str(rev->rev); break;
956 case 'P': if(prev && prev->rev) add_string_str(prev->rev); break;
957 case 'B': if(rev && rev->branch) add_string_str(rev->branch); break;
958 case 't': if(tag && tag->tag) add_string_str(tag->tag); break;
959 case 'd': if(r && r->delta && r->delta->date) add_string_date(r->delta->date); break;
960 case 's': if(r && r->delta && r->delta->state) add_string_str(r->delta->state); break;
961 case 'a': if(r && r->delta && r->delta->author) add_string_str(r->delta->author); break;
962 case 'L':
963 case 'l':
964 ch = *s;
965 l = 0;
966 if(s[1] == '[')
967 {
968 char *cptr = strchr(s, ']');
969 char *eptr;
970 if(cptr)
971 {
972 l = strtol(&s[2], &eptr, 10);
973 if(eptr != cptr)
974 l = 0;
975 else
976 s = cptr;
977 }
978 }
979 if(!conf.parse_logs)
980 add_string_str("N/A");
981 else if(r && r->dtext && r->dtext->log)
982 {
983 if(ch == 'l')
984 add_string_str_html(r->dtext->log, l);
985 else
986 add_string_str_len(r->dtext->log, abs(l));
987 }
988 break;
989 default:
990 add_string_ch('%');
991 add_string_ch(*s);
992 break;
993 }
994 }
995 else
996 add_string_ch(*s);
997 }
998 return xstrdup(_string);
999 }
1000
1001 /*
1002 **************************************************************************
1003 * Drawing routines
1004 **************************************************************************
1005 */
1006 static int get_swidth(const char *s, font_t *f)
1007 {
1008 int n;
1009 int m;
1010 if(!s || !*s)
1011 return 0;
1012
1013 #if defined(HAVE_GDIMAGESTRINGFT) || defined(HAVE_GDIMAGESTRINGTTF)
1014 if(conf.use_ttf && f->ttfont)
1015 {
1016 int bb[8];
1017 char *e;
1018 #ifdef HAVE_GDIMAGESTRINGFT
1019 e = gdImageStringFT(NULL, bb, 0, f->ttfont, f->ttsize, 0.0, 0, 0, (char *)s);
1020 #else
1021 e = gdImageStringTTF(NULL, bb, 0, f->ttfont, f->ttsize, 0.0, 0, 0, (char *)s);
1022 #endif
1023 if(!e)
1024 return bb[2] - bb[6];
1025 }
1026 #endif
1027 for(n = m = 0; *s; n++, s++)
1028 {
1029 if(*s == '\n')
1030 {
1031 if(n > m)
1032 m = n;
1033 n = 0;
1034 }
1035 }
1036 if(n > m)
1037 m = n;
1038 return f->gdfont ? m * f->gdfont->w : m;
1039 }
1040
1041 static int get_sheight(const char *s, font_t *f)
1042 {
1043 int nl;
1044 if(!s || !*s)
1045 return 0;
1046
1047 #if defined(HAVE_GDIMAGESTRINGFT) || defined(HAVE_GDIMAGESTRINGTTF)
1048 if(conf.use_ttf && f->ttfont)
1049 {
1050 int bb[8];
1051 char *e;
1052 #ifdef HAVE_GDIMAGESTRINGFT
1053 e = gdImageStringFT(NULL, bb, 0, f->ttfont, f->ttsize, 0.0, 0, 0, (char *)s);
1054 #else
1055 e = gdImageStringTTF(NULL, bb, 0, f->ttfont, f->ttsize, 0.0, 0, 0, (char *)s);
1056 #endif
1057 if(!e)
1058 return bb[3] - bb[7] + 4;
1059 }
1060 #endif
1061 for(nl = 1; *s; s++)
1062 {
1063 if(*s == '\n' && s[1])
1064 nl++;
1065 }
1066 return nl * f->gdfont->h;
1067 }
1068
1069 static void draw_rbox(gdImagePtr im, int x1, int y1, int x2, int y2, int r, color_t *color, color_t *bgcolor)
1070 {
1071 int r2 = 2*r;
1072 gdImageLine(im, x1+r, y1, x2-r, y1, color->id);
1073 gdImageLine(im, x1+r, y2, x2-r, y2, color->id);
1074 gdImageLine(im, x1, y1+r, x1, y2-r, color->id);
1075 gdImageLine(im, x2, y1+r, x2, y2-r, color->id);
1076 if(conf.box_shadow)
1077 {
1078 gdImageLine(im, x1+r+1, y2+1, x2-r, y2+1, black_color.id);
1079 gdImageLine(im, x2+1, y1+r+1, x2+1, y2-r, black_color.id);
1080 }
1081 if(r)
1082 {
1083 /* FIXME: Pixelization is not perfect */
1084 gdImageArc(im, x1+r, y1+r, r2, r2, 180, 270, color->id);
1085 gdImageArc(im, x2-r, y1+r, r2, r2, 270, 360, color->id);
1086 gdImageArc(im, x1+r, y2-r, r2, r2, 90, 180, color->id);
1087 if(conf.box_shadow)
1088 {
1089 gdImageArc(im, x2-r+1, y2-r+1, r2, r2, 0, 90, black_color.id);
1090 gdImageArc(im, x2-r+1, y2-r, r2, r2, 0, 90, black_color.id);
1091 gdImageArc(im, x2-r, y2-r+1, r2, r2, 0, 90, black_color.id);
1092 }
1093 gdImageArc(im, x2-r, y2-r, r2, r2, 0, 90, color->id);
1094 }
1095 #ifndef NOGDFILL
1096 gdImageFillToBorder(im, (x1+x2)/2, (y1+y2)/2, color->id, bgcolor->id);
1097 #endif
1098 }
1099
1100 static void draw_string(gdImagePtr im, char *s, font_t *f, int x, int y, int align, color_t *c)
1101 {
1102 int h = get_sheight(s, f);
1103 int xx, yy;
1104 switch(align & ALIGN_HX)
1105 {
1106 default:
1107 case ALIGN_HL: xx = 0; break;
1108 case ALIGN_HC: xx = -get_swidth(s, f)/2; break;
1109 case ALIGN_HR: xx = -get_swidth(s, f); break;
1110 }
1111 switch(align & ALIGN_VX)
1112 {
1113 default:
1114 case ALIGN_VT: yy = 0; break;
1115 case ALIGN_VC: yy = h/2; break;
1116 case ALIGN_VB: yy = h; break;
1117 }
1118 #if defined(HAVE_GDIMAGESTRINGFT) || defined(HAVE_GDIMAGESTRINGTTF)
1119 if(conf.use_ttf && f->ttfont)
1120 {
1121 int bb[8];
1122 char *e;
1123 int cid = conf.anti_alias ? c->id : -c->id;
1124 #ifdef HAVE_GDIMAGESTRINGFT
1125 e = gdImageStringFT(im, bb, cid, f->ttfont, f->ttsize, 0.0, x+xx, y+yy+h-2, (char *)s);
1126 #else
1127 e = gdImageStringTTF(im, bb, cid, f->ttfont, f->ttsize, 0.0, x+xx, y+yy+h-2, (char *)s);
1128 #endif
1129 if(!e)
1130 return;
1131 }
1132 #endif
1133 yy = -yy;
1134 gdImageString(im, f->gdfont, x+xx+1, y+yy, s, c->id);
1135 }
1136
1137 static void draw_stringnl(gdImagePtr im, char *s, font_t *f, int x, int y, int align, color_t *c)
1138 {
1139 char *t;
1140 char *d;
1141 d = s = xstrdup(s);
1142 do
1143 {
1144 t = strchr(s, '\n');
1145 if(t)
1146 *t = '\0';
1147 draw_string(im, s, f, x, y, align, c);
1148 y += get_sheight(s, f);
1149 s = t+1;
1150 } while(t);
1151 xfree(d);
1152 }
1153
1154 static void draw_rev(gdImagePtr im, revision_t *r)
1155 {
1156 int lx;
1157 int rx;
1158 int x2;
1159 int i;
1160 int ty;
1161
1162 if(conf.left_right)
1163 {
1164 lx = r->cx;
1165 rx = r->cx + r->w;
1166 ty = r->y - r->h/2;
1167 x2 = r->cx + r->w/2;
1168 }
1169 else
1170 {
1171 lx = r->cx - r->w/2;
1172 rx = lx + r->w;
1173 ty = r->y;
1174 x2 = r->cx;
1175 }
1176 draw_rbox(im, lx, ty, rx, ty+r->h, 0, &conf.rev_color, &conf.rev_bgcolor);
1177 ty += conf.rev_tspace;
1178 draw_string(im, r->rev->rev, &conf.rev_font, x2, ty, ALIGN_HC, &conf.rev_color);
1179 ty += get_sheight(r->rev->rev, &conf.rev_font);
1180 draw_stringnl(im, r->revtext, &conf.rev_text_font, x2, ty, ALIGN_HC, &conf.rev_text_color);
1181 ty += get_sheight(r->revtext, &conf.rev_text_font);
1182 for(i = 0; i < r->ntags; i++)
1183 {
1184 draw_string(im, r->tags[i]->tag, &conf.tag_font, x2, ty, ALIGN_HC, &conf.tag_color);
1185 ty += get_sheight(r->tags[i]->tag, &conf.tag_font) + conf.rev_separator;
1186 }
1187 }
1188
1189 static void draw_branch_box(gdImagePtr im, branch_t *b, int xp, int yp)
1190 {
1191 int lx;
1192 int rx;
1193 int i;
1194 int yy;
1195 int x2;
1196
1197 if(conf.left_right)
1198 {
1199 lx = b->cx;
1200 rx = lx + b->w;
1201 x2 = b->cx + b->w/2;
1202 }
1203 else
1204 {
1205 lx = b->cx - b->w/2;
1206 rx = lx + b->w;
1207 x2 = b->cx;
1208 }
1209 draw_rbox(im, lx+xp, yp, rx+xp, yp+b->h, 5, &conf.branch_color, &conf.branch_bgcolor);
1210 yy = conf.branch_tspace;
1211 draw_string(im, b->branch->branch, &conf.branch_font, x2+xp, yp+yy, ALIGN_HC, &conf.branch_color);
1212 yy += get_sheight(b->branch->branch, &conf.branch_font);
1213 for(i = 0; i < b->ntags; i++)
1214 {
1215 draw_string(im, b->tags[i]->tag, &conf.branch_tag_font, x2+xp, yp+yy, ALIGN_HC, &conf.branch_tag_color);
1216 yy += get_sheight(b->tags[i]->tag, &conf.branch_font);
1217 }
1218 }
1219
1220 static void draw_branch(gdImagePtr im, branch_t *b)
1221 {
1222 int yy, xx;
1223 int i;
1224 int line[4];
1225 int l;
1226 int sign;
1227
1228 line[0] = conf.rev_color.id;
1229 line[1] = gdTransparent;
1230 line[1] = gdTransparent;
1231 line[3] = conf.rev_color.id;
1232
1233 draw_branch_box(im, b, 0, conf.left_right ? b->y - b->h/2 : b->y);
1234
1235 if(conf.left_right)
1236 {
1237 if(conf.upside_down)
1238 {
1239 xx = b->cx;
1240 for(i = 0; i < b->nrevs; i++)
1241 {
1242 revision_t *r = b->revs[i];
1243 gdImageSetStyle(im, line, r->stripped ? 4 : 1);
1244 gdImageLine(im, xx, r->y, r->cx+r->w, r->y, gdStyled);
1245 for(sign = l = 1; l < conf.thick_lines; l++)
1246 {
1247 int pp = (l+1)/2*sign;
1248 gdImageLine(im, xx, r->y+pp, r->cx+r->w, r->y+pp, gdStyled);
1249 sign *= -1;
1250 }
1251 draw_rev(im, r);
1252 xx = r->cx;
1253 }
1254 if(conf.branch_dupbox)
1255 {
1256 i = b->cx - b->tw + b->w;
1257 gdImageLine(im, xx, b->y, i+b->w, b->y, conf.rev_color.id);
1258 for(sign = l = 1; l < conf.thick_lines; l++)
1259 {
1260 int pp = (l+1)/2*sign;
1261 gdImageLine(im, xx, b->y+pp, i+b->w, b->y+pp, conf.rev_color.id);
1262 sign *= -1;
1263 }
1264 draw_branch_box(im, b, i - b->cx, b->y - b->h/2);
1265 }
1266 }
1267 else
1268 {
1269 xx = b->cx + b->w;
1270 for(i = 0; i < b->nrevs; i++)
1271 {
1272 revision_t *r = b->revs[i];
1273 gdImageSetStyle(im, line, r->stripped ? 4 : 1);
1274 gdImageLine(im, xx, r->y, r->cx, r->y, gdStyled);
1275 for(sign = l = 1; l < conf.thick_lines; l++)
1276 {
1277 int pp = (l+1)/2*sign;
1278 gdImageLine(im, xx, r->y+pp, r->cx, r->y+pp, gdStyled);
1279 sign *= -1;
1280 }
1281 draw_rev(im, r);
1282 xx = r->cx + r->w;
1283 }
1284 if(conf.branch_dupbox)
1285 {
1286 i = b->cx + b->tw - b->w;
1287 gdImageLine(im, xx, b->y, i, b->y, conf.rev_color.id);
1288 for(sign = l = 1; l < conf.thick_lines; l++)
1289 {
1290 int pp = (l+1)/2*sign;
1291 gdImageLine(im, xx, b->y+pp, i, b->y+pp, conf.rev_color.id);
1292 sign *= -1;
1293 }
1294 draw_branch_box(im, b, i - b->cx, b->y - b->h/2);
1295 }
1296 }
1297 }
1298 else
1299 {
1300 if(conf.upside_down)
1301 {
1302 yy = b->y;
1303 for(i = 0; i < b->nrevs; i++)
1304 {
1305 revision_t *r = b->revs[i];
1306 gdImageSetStyle(im, line, r->stripped ? 4 : 1);
1307 gdImageLine(im, r->cx, yy, r->cx, r->y+r->h, gdStyled);
1308 for(sign = l = 1; l < conf.thick_lines; l++)
1309 {
1310 int pp = (l+1)/2*sign;
1311 gdImageLine(im, r->cx+pp, yy, r->cx+pp, r->y+r->h, gdStyled);
1312 sign *= -1;
1313 }
1314 draw_rev(im, r);
1315 yy = r->y;
1316 }
1317 if(conf.branch_dupbox)
1318 {
1319 i = b->y - b->th + b->h;
1320 gdImageLine(im, b->cx, yy, b->cx, i, conf.rev_color.id);
1321 for(sign = l = 1; l < conf.thick_lines; l++)
1322 {
1323 int pp = (l+1)/2*sign;
1324 gdImageLine(im, b->cx+pp, yy, b->cx+pp, i, conf.rev_color.id);
1325 sign *= -1;
1326 }
1327 draw_branch_box(im, b, 0, i);
1328 }
1329 }
1330 else
1331 {
1332 yy = b->y + b->h;
1333 for(i = 0; i < b->nrevs; i++)
1334 {
1335 revision_t *r = b->revs[i];
1336 gdImageSetStyle(im, line, r->stripped ? 4 : 1);
1337 gdImageLine(im, r->cx, yy, r->cx, r->y, gdStyled);
1338 for(sign = l = 1; l < conf.thick_lines; l++)
1339 {
1340 int pp = (l+1)/2*sign;
1341 gdImageLine(im, r->cx+pp, yy, r->cx+pp, r->y, gdStyled);
1342 sign *= -1;
1343 }
1344 draw_rev(im, r);
1345 yy = r->y + r->h;
1346 }
1347 if(conf.branch_dupbox)
1348 {
1349 i = b->y + b->th - b->h;
1350 gdImageLine(im, b->cx, yy, b->cx, i, conf.rev_color.id);
1351 for(sign = l = 1; l < conf.thick_lines; l++)
1352 {
1353 int pp = (l+1)/2*sign;
1354 gdImageLine(im, b->cx+pp, yy, b->cx+pp, i, conf.rev_color.id);
1355 sign *= -1;
1356 }
1357 draw_branch_box(im, b, 0, i);
1358 }
1359 }
1360 }
1361 }
1362
1363 static void draw_connector(gdImagePtr im, branch_t *b)
1364 {
1365 int l;
1366 int sign;
1367 revision_t *r = b->branchpoint;
1368 int x1 = r->cx + r->w/2 + 2;
1369 int y1 = r->y + r->h/2;
1370 int x2 = b->cx;
1371 int y2 = b->y;
1372
1373 if(conf.left_right)
1374 {
1375 x2 = r->cx + r->w/2;
1376 y2 = r->y + r->h/2 + 3;
1377 x1 = b->cx;
1378 y1 = b->y;
1379 if(conf.upside_down)
1380 x1 += b->w;
1381 }
1382 else
1383 {
1384 x1 = r->cx + r->w/2 + 2;
1385 y1 = r->y + r->h/2;
1386 x2 = b->cx;
1387 y2 = b->y;
1388 if(conf.upside_down)
1389 y2 += b->h;
1390 }
1391 gdImageLine(im, x1, y1, x2, y1, conf.branch_color.id);
1392 gdImageLine(im, x2, y1, x2, y2, conf.branch_color.id);
1393 for(sign = l = 1; l < conf.thick_lines; l++)
1394 {
1395 int pp = (l+1)/2*sign;
1396 gdImageLine(im, x1, y1+pp, x2, y1+pp, conf.branch_color.id);
1397 gdImageLine(im, x2+pp, y1, x2+pp, y2, conf.branch_color.id);
1398 sign *= -1;
1399 }
1400 }
1401
1402 static void alloc_color(gdImagePtr im, color_t *c)
1403 {
1404 c->id = gdImageColorAllocate(im, c->r, c->g, c->b);
1405 }
1406
1407 gdImagePtr make_image(rcsfile_t *rcs)
1408 {
1409 gdImagePtr im;
1410 int i;
1411 char *cptr;
1412
1413 cptr = expand_string(conf.title, rcs, NULL, NULL, NULL, NULL);
1414 i = get_swidth(cptr, &conf.title_font);
1415 if(rcs->tw+conf.margin_left+conf.margin_right > i)
1416 i = rcs->tw+conf.margin_left+conf.margin_right;
1417 im = gdImageCreate(i, rcs->th+conf.margin_top+conf.margin_bottom);
1418 alloc_color(im, &conf.color_bg);
1419 alloc_color(im, &conf.tag_color);
1420 alloc_color(im, &conf.rev_color);
1421 alloc_color(im, &conf.rev_bgcolor);
1422 alloc_color(im, &conf.rev_text_color);
1423 alloc_color(im, &conf.branch_color);
1424 alloc_color(im, &conf.branch_tag_color);
1425 alloc_color(im, &conf.branch_bgcolor);
1426 alloc_color(im, &conf.title_color);
1427 alloc_color(im, &black_color);
1428 alloc_color(im, &white_color);
1429
1430 if(conf.transparent_bg)
1431 gdImageColorTransparent(im, conf.color_bg.id);
1432
1433 for(i = 0; i < rcs->nbranches; i++)
1434 draw_branch(im, rcs->branches[i]);
1435 for(i = 0; i < rcs->nbranches; i++)
1436 {
1437 if(rcs->branches[i]->branchpoint)
1438 draw_connector(im, rcs->branches[i]);
1439 }
1440 draw_stringnl(im, cptr, &conf.title_font, conf.title_x, conf.title_y, conf.title_align, &conf.title_color);
1441 xfree(cptr);
1442
1443 return im;
1444 }
1445
1446 /*
1447 **************************************************************************
1448 * Layout routines
1449 *
1450 * Branch BBox:
1451 * left = center_x - total_width / 2 (cx-tw)/2
1452 * right = center_x + total_width / 2 (cx+tw)/2
1453 * top = y_pos (y)
1454 * bottom = y_pos + total_height (y+th)
1455 *
1456 * Margins of branches:
1457 *
1458 * . .
1459 * . .
1460 * +--------------+
1461 * ^
1462 * | branch_margin .
1463 * v .
1464 * ----------------+ .
1465 * | ^ |
1466 * | | branch_connect |
1467 * | v |
1468 *..-+ +t-----+------+ +------+------+
1469 * | l | | |
1470 * | <--> | branch bbox | <--> | branch bbox |
1471 * | | | r | | |
1472 *..-+ | +------------b+ | +-------------+
1473 * | ^ branch_margin
1474 * | | branch_margin
1475 * | v
1476 * | +-------------+
1477 * | . .
1478 * | . .
1479 * |
1480 * branch_margin
1481 *
1482 * FIXME: There are probable som +/-1 errors in the code...
1483 * (notably shadows are not calculated in the margins)
1484 **************************************************************************
1485 */
1486 static void move_branch(branch_t *b, int x, int y)
1487 {
1488 int i;
1489 b->cx += x;
1490 b->y += y;
1491 for(i = 0; i < b->nrevs; i++)
1492 {
1493 b->revs[i]->cx += x;
1494 b->revs[i]->y += y;
1495 }
1496 }
1497
1498 static void initial_reposition_branch(revision_t *r, int *x, int *w)
1499 {
1500 int i, j;
1501 for(j = 0; j < r->nbranches; j++)
1502 {
1503 branch_t *b = r->branches[j];
1504 *x += *w + conf.rev_minline + b->tw/2 - b->cx;
1505 *w = b->tw/2;
1506 move_branch(b, *x, r->y + r->h/2 + conf.branch_connect);
1507 *x = b->cx;
1508 /* Recurse to move branches of branched revisions */
1509 for(i = b->nrevs-1; i >= 0; i--)
1510 {
1511 initial_reposition_branch(b->revs[i], x, w);
1512 }
1513 }
1514 }
1515
1516 static void initial_reposition_branch_lr(revision_t *r, int *y, int *h)
1517 {
1518 int i, j;
1519 for(j = 0; j < r->nbranches; j++)
1520 {
1521 branch_t *b = r->branches[j];
1522 *y += *h + conf.rev_minline + b->th/2 - b->y;
1523 *h = b->th/2;
1524 move_branch(b, r->cx + r->w/2 + conf.branch_connect, *y);
1525 *y = b->y;
1526 /* Recurse to move branches of branched revisions */
1527 for(i = b->nrevs-1; i >= 0; i--)
1528 {
1529 initial_reposition_branch(b->revs[i], y, h);
1530 }
1531 }
1532 }
1533
1534 static void rect_union(int *x, int *y, int *w, int *h, branch_t *b)
1535 {
1536 int x1 = *x;
1537 int x2 = x1 + *w;
1538 int y1 = *y;
1539 int y2 = y1 + *h;
1540 int xx1;
1541 int xx2;
1542 int yy1;
1543 int yy2;
1544
1545 if(conf.left_right)
1546 {
1547 xx1 = b->cx;
1548 yy1 = b->y - b->th/2;
1549 }
1550 else
1551 {
1552 xx1 = b->cx - b->tw/2;
1553 yy1 = b->y;
1554 }
1555 xx2 = xx1 + b->tw;
1556 yy2 = yy1 + b->th;
1557
1558 x1 = MIN(x1, xx1);
1559 x2 = MAX(x2, xx2);
1560 y1 = MIN(y1, yy1);
1561 y2 = MAX(y2, yy2);
1562 *x = x1;
1563 *y = y1;
1564 *w = x2 - x1;
1565 *h = y2 - y1;
1566 }
1567
1568 static int branch_intersects(int top, int bottom, int left, branch_t *b)
1569 {
1570 int br = b->cx + b->tw/2;
1571 int bt = b->y - conf.branch_connect - conf.branch_margin/2;
1572 int bb = b->y + b->th + conf.branch_margin/2;
1573 return !(bt > bottom || bb < top || br >= left);
1574 }
1575
1576 static int branch_intersects_lr(int left, int right, int top, branch_t *b)
1577 {
1578 int bt = b->y + b->th/2;
1579 int bl = b->cx - conf.branch_connect - conf.branch_margin/2;
1580 int br = b->cx + b->tw + conf.branch_margin/2;
1581 return !(bl > right || br < left || bt >= top);
1582 }
1583
1584 static int kern_branch(rcsfile_t *rcs, branch_t *b)
1585 {
1586 int left = b->cx - b->tw/2;
1587 int top = b->y - conf.branch_connect - conf.branch_margin/2;
1588 int bottom = b->y + b->th + conf.branch_margin/2;
1589 int i;
1590 int xpos = 0;
1591
1592 for(i = 0; i < rcs->nbranches; i++)
1593 {
1594 branch_t *bp = rcs->branches[i];
1595 if(bp == b)
1596 continue;
1597 if(branch_intersects(top, bottom, left, bp))
1598 {
1599 int m = bp->cx + bp->tw/2 + conf.branch_margin;
1600 if(m > xpos)
1601 xpos = m;
1602 }
1603 }
1604 if(xpos && (b->cx - b->tw/2) - xpos > 0)
1605 {
1606 move_branch(b, xpos - (b->cx - b->tw/2), 0);
1607 return 1;
1608 }
1609 return 0;
1610 }
1611
1612 static int kern_branch_lr(rcsfile_t *rcs, branch_t *b)
1613 {
1614 int top = b->y - b->th/2;
1615 int left = b->cx - conf.branch_connect - conf.branch_margin/2;
1616 int right = b->cx + b->tw + conf.branch_margin/2;
1617 int i;
1618 int ypos = 0;
1619
1620 for(i = 0; i < rcs->nbranches; i++)
1621 {
1622 branch_t *bp = rcs->branches[i];
1623 if(bp == b)
1624 continue;
1625 if(branch_intersects_lr(left, right, top, bp))
1626 {
1627 int m = bp->y + bp->th/2 + conf.branch_margin;
1628 if(m > ypos)
1629 ypos = m;
1630 }
1631 }
1632 if(ypos && (b->y - b->th/2) - ypos > 0)
1633 {
1634 move_branch(b, 0, ypos - (b->y - b->th/2));
1635 return 1;
1636 }
1637 return 0;
1638 }
1639
1640 static int kern_tree(rcsfile_t *rcs)
1641 {
1642 int i;
1643 int moved;
1644 int safeguard;
1645 int totalmoved = 0;
1646 for(moved = 1, safeguard = LOOPSAFEGUARD; moved && safeguard; safeguard--)
1647 {
1648 moved = 0;
1649 for(i = 1; i < rcs->nbranches; i++)
1650 {
1651 if(conf.left_right)
1652 moved += kern_branch_lr(rcs, rcs->branches[i]);
1653 else
1654 moved += kern_branch(rcs, rcs->branches[i]);
1655 }
1656 totalmoved += moved;
1657 #ifdef DEBUG
1658 fprintf(stderr, "kern_tree: moved=%d\n", moved);
1659 #endif
1660 }
1661 if(!quiet && !safeguard)
1662 fprintf(stderr, "kern_tree: safeguard terminated possible infinite loop; please report.\n");
1663 return totalmoved;
1664 }
1665
1666 static int index_of_revision(revision_t *r)
1667 {
1668 branch_t *b = r->branch;
1669 int i;
1670 for(i = 0; i < b->nrevs; i++)
1671 {
1672 if(r == b->revs[i])
1673 return i;
1674 }
1675 fprintf(stderr, "index_of_revision: Cannot find revision in branch\n");
1676 return 0;
1677 }
1678
1679 static void branch_bbox(branch_t *br, int *l, int *r, int *t, int *b)
1680 {
1681 if(l) *l = br->cx - br->tw/2;
1682 if(r) *r = br->cx + br->tw/2;
1683 if(t) *t = br->y;
1684 if(b) *b = br->y + br->th + (conf.branch_dupbox ? conf.rev_minline + br->h : 0);
1685 }
1686
1687 static void branch_ext_bbox(branch_t *br, int *l, int *r, int *t, int *b)
1688 {
1689 int extra = conf.branch_margin & 1; /* Correct +/-1 error on div 2 */
1690 branch_bbox(br, l, r, t, b);
1691 if(l) *l -= conf.branch_margin/2;
1692 if(r) *r += conf.branch_margin/2 + extra;
1693 if(t) *t -= conf.branch_connect + conf.branch_margin/2;
1694 if(b) *b += conf.branch_margin/2 + extra;
1695 }
1696
1697 static int branch_distance(branch_t *br1, branch_t *br2)
1698 {
1699 int l1, r1, t1, b1;
1700 int l2, r2, t2, b2;
1701 assert(br1 != NULL);
1702 assert(br2 != NULL);
1703 branch_bbox(br1, &l1, &r1, NULL, NULL);
1704 branch_bbox(br2, &l2, &r2, NULL, NULL);
1705 branch_ext_bbox(br1, NULL, NULL, &t1, &b1);
1706 branch_ext_bbox(br2, NULL, NULL, &t2, &b2);
1707 /* Return:
1708 * - 0 if branches have no horizontal overlap
1709 * - positive if b1 is left of b2
1710 * - negative if b2 is left of b1
1711 */
1712 if((t1 > t2 && t1 < b2) || (b1 > t2 && b1 < b2))
1713 return l1 < l2 ? l2 - r1 : -(l1 - r2);
1714 else
1715 return 0;
1716 }
1717
1718 static int space_needed(branch_t *br1, branch_t *br2)
1719 {
1720 int t1, b1;
1721 int t2, b2;
1722 assert(br1 != NULL);
1723 assert(br2 != NULL);
1724 assert(br1->cx < br2->cx); /* br1 must be left of br2 */
1725 branch_ext_bbox(br1, NULL, NULL, &t1, &b1);
1726 branch_ext_bbox(br2, NULL, NULL, &t2, &b2);
1727 /* Return:
1728 * - positive if top br1 is located lower than br2
1729 * - negatve is top br2 is located lower than br1
1730 */
1731 if(t1 > t2)
1732 return -(t1 - b2);
1733 else
1734 return t2 - b1;
1735 }
1736
1737 static void move_yr_branch(branch_t *b, int dy)
1738 {
1739 int i, j;
1740 #ifdef DEBUG
1741 /* fprintf(stderr, "move_yr_branch: b=%s, dy=%d\n", b->branch->branch, dy);*/
1742 #endif
1743 b->y += dy;
1744 for(i = 0; i < b->nrevs; i++)
1745 {
1746 b->revs[i]->y += dy;
1747 for(j = 0; j < b->revs[i]->nbranches; j++)
1748 {
1749 #ifdef DEBUG
1750 /* fprintf(stderr, ".");*/
1751 #endif
1752 move_yr_branch(b->revs[i]->branches[j], dy);
1753 }
1754 }
1755 }
1756
1757 static void move_trunk(revision_t *r, int dy)
1758 {
1759 int i, j;
1760 branch_t *b = r->branch;
1761 b->th += dy;
1762 for(i = index_of_revision(r); i < b->nrevs; i++)
1763 {
1764 #ifdef DEBUG
1765 fprintf(stderr, "move_trunk: start %s, moving %s by %d (b's %d)\n", r->rev->rev, b->revs[i]->rev->rev, dy, b->revs[i]->nbranches);
1766 #endif
1767 b->revs[i]->y += dy;
1768 for(j = 0; j < b->revs[i]->nbranches; j++)
1769 {
1770 move_yr_branch(b->revs[i]->branches[j], dy);
1771 }
1772 }
1773 }
1774
1775 static int space_below(rcsfile_t *rcs, revision_t *r)
1776 {
1777 int i, j;
1778 int bl, br, bb;
1779 int space = INT_MAX;
1780 branch_t *b = r->branch;
1781 branch_t *minb = NULL;
1782
1783 branch_ext_bbox(b, &bl, &br, NULL, &bb);
1784 for(i = 0; i < rcs->nbranches; i++)
1785 {
1786 int tbl, tbr, tbt;
1787 branch_t *tb = rcs->branches[i];
1788 branch_ext_bbox(tb, &tbl, &tbr, &tbt, NULL);
1789 if(tb == b)
1790 continue;
1791 if(tbt > bb) /* Must be below our branch */
1792 {
1793 if(tb->branchpoint) /* Take account for the horiz connector */
1794 tbl = tb->branchpoint->cx + tb->branchpoint->branch->tw/2;
1795 if((bl >= tbl && bl <= tbr) || (br <= tbr && br >= tbl))
1796 {
1797 int s = tbt - bb - conf.branch_connect;
1798 if(s < space)
1799 {
1800 space = s;
1801 minb = tb;
1802 }
1803 }
1804 }
1805 }
1806 if(b->branchpoint)
1807 {
1808 for(i = index_of_revision(r); i < b->nrevs; i++)
1809 {
1810 for(j = 0; j < b->revs[i]->nbranches; j++)
1811 {
1812 int s = space_below(rcs, b->revs[i]->branches[j]->revs[0]);
1813 if(s < space)
1814 space = s;
1815 }
1816 }
1817 }
1818 #ifdef DEBUG
1819 fprintf(stderr, "space_below: from %s have %d to %s\n", b->branch->branch, space, minb ? minb->branch->branch : "<recursed>");
1820 #endif
1821 return space;
1822 }
1823
1824 static int space_available(rcsfile_t *rcs, branch_t *colbr, branch_t *tagbr, int *nl, revision_t **bpcommon)
1825 {
1826 int i;
1827 int space = 0;
1828 int nlinks = 0;
1829 revision_t *r;
1830 branch_t *b;
1831 branch_t *ancestor;
1832 revision_t *branchpoint;
1833
1834 if(!tagbr->branchpoint || !colbr->branchpoint)
1835 {
1836 if(!quiet)
1837 fprintf(stderr, "space_available: Trying to stretch the top?\n");
1838 return 0;
1839 }
1840
1841 r = colbr->branchpoint;
1842 b = r->branch;
1843 branchpoint = tagbr->branchpoint;
1844 ancestor = branchpoint->branch;
1845 assert(b != NULL);
1846 assert(ancestor != NULL);
1847
1848 while(1)
1849 {
1850 int s;
1851 int rtag = b == ancestor ? index_of_revision(branchpoint)+1 : 0;
1852 for(i = index_of_revision(r); i >= rtag; i--)
1853 {
1854 if(i > 0)
1855 s = b->revs[i]->y - (b->revs[i-1]->y + b->revs[i-1]->h);
1856 else
1857 s = b->revs[i]->y - (b->y + b->h);
1858 if(s < conf.rev_maxline)
1859 {
1860 space += conf.rev_maxline - s;
1861 nlinks++;
1862 }
1863 }
1864 s = space_below(rcs, r);
1865 if(s < space)
1866 space = s;
1867 #ifdef DEBUG
1868 if(space < 0)
1869 return -1;
1870 #endif
1871 if(b == ancestor)
1872 break;
1873 r = b->branchpoint;
1874 if(!r)
1875 {
1876 /* Not a common ancestor */
1877 r = colbr->branchpoint;
1878 b = r->branch;
1879 branchpoint = ancestor->branchpoint;
1880 if(!branchpoint)
1881 {
1882 if(!quiet)
1883 fprintf(stderr, "space_available: No common ancestor?\n");
1884 return 0;
1885 }
1886 ancestor = branchpoint->branch;
1887 assert(ancestor != NULL);
1888 nlinks = 0;
1889 space = 0;
1890 continue; /* Restart with a new ancestor */
1891 }
1892 b = r->branch;
1893 }
1894 if(nl)
1895 *nl = nlinks; /* Return the number of links that can stretch */
1896 if(bpcommon)
1897 *bpcommon = branchpoint; /* Return the ancestral branchpoint on the common branch */
1898 return space;
1899 }
1900
1901 static int stretch_branches(rcsfile_t *rcs, branch_t *br1, branch_t *br2, int totalstretch)
1902 {
1903 revision_t *r;
1904 revision_t *bpcommon = NULL;
1905 branch_t *ancestor = NULL;
1906 branch_t *b;
1907 int i;
1908 int space;
1909 int nlinks;
1910 int dy;
1911 int rest;
1912
1913 space = space_available(rcs, br1, br2, &nlinks, &bpcommon);
1914 if(bpcommon)
1915 ancestor = bpcommon->branch;
1916
1917 #ifdef DEBUG
1918 if(space == -1)
1919 return 0;
1920 fprintf(stderr, "stretch_branches: space available %d over %d links common %s\n", space, nlinks, ancestor->branch->branch);
1921 #endif
1922 if(space < totalstretch)
1923 return 0;
1924
1925 dy = totalstretch / nlinks;
1926 rest = totalstretch - dy * nlinks;
1927
1928 r = br1->branchpoint;
1929 b = r->branch;
1930 while(1)
1931 {
1932 int rtag = b == ancestor ? index_of_revision(bpcommon)+1 : 0;
1933 for(i = index_of_revision(r); i >= rtag; i--)
1934 {
1935 int s, q;
1936 if(i > 0)
1937 s = b->revs[i]->y - (b->revs[i-1]->y + b->revs[i-1]->h);
1938 else
1939 s = b->revs[i]->y - (b->y + b->h);
1940 q = conf.rev_maxline - s;
1941 if(q > 0)
1942 {
1943 int d = rest ? rest/nlinks+1 : 0;
1944 if(q >= dy+d)
1945 {
1946 move_trunk(b->revs[i], dy+d);
1947 }
1948 else
1949 {
1950 move_trunk(b->revs[i], q);
1951 rest += dy+d - q;
1952 }
1953 rest -= d;
1954 nlinks--;
1955 }
1956 }
1957 if(b == ancestor)
1958 break;
1959 r = b->branchpoint;
1960 assert(r != NULL); /* else 'space_available' wouldn't have returned positively */
1961 b = r->branch;
1962 }
1963 return 1;
1964 }
1965
1966 static branch_t *find_collision_branch(rcsfile_t *rcs, branch_t *b)
1967 {
1968 int i;
1969 int dist = INT_MAX;
1970 branch_t *col = NULL;
1971
1972 for(i = 0; i < rcs->nbranches; i++)
1973 {
1974 int t = branch_distance(rcs->branches[i], b);
1975 if(t > 0 && t < dist)
1976 {
1977 dist = t;
1978 col = rcs->branches[i];
1979 }
1980 }
1981 return col;
1982 }
1983
1984 void auto_stretch(rcsfile_t *rcs)
1985 {
1986 int i;
1987 int safeguard;
1988
1989 for(i = 0, safeguard = LOOPSAFEGUARD; i < rcs->nbranches && safeguard; i++)
1990 {
1991 int bl, pr;
1992 branch_t *b = rcs->branches[i];
1993 if(!b->branchpoint)
1994 continue;
1995 branch_bbox(b, &bl, NULL, NULL, NULL);
1996 branch_bbox(b->branchpoint->branch, NULL, &pr, NULL, NULL);
1997 if(bl - conf.branch_margin - pr > 0)
1998 {
1999 branch_t *col;
2000 int spaceneeded;
2001 /* There is a potential to move branch b further left.
2002 * All branches obstructing this one from moving further
2003 * left must be originating from revisions below
2004 * b->branchpoint until a common ancester.
2005 * So, we search all branches for a branch that lies left
2006 * of b and is closest to b. This is then the collission
2007 * branch that needs to be moved.
2008 */
2009 col = find_collision_branch(rcs, b);
2010 if(!col)
2011 continue;
2012 spaceneeded = space_needed(col, b);
2013 if(spaceneeded < 0)
2014 continue;
2015 #ifdef DEBUG
2016 fprintf(stderr, "auto_stretch: %s collides %s need %d\n", b->branch->branch, col->branch->branch, spaceneeded);
2017 #endif
2018 /* Trace the collision branch back to find the common ancester
2019 * of both col and b. All revisions encountered while traversing
2020 * backwards must be stretched, including all revisions on the
2021 * common ancester from where the branches sprout.
2022 */
2023 if(stretch_branches(rcs, col, b, spaceneeded))
2024 {
2025 if(kern_tree(rcs))
2026 {
2027 /* Restart the process because movement can
2028 * cause more movement.
2029 */
2030 i = 0 - 1; /* -1 for the i++ of the loop */
2031 safeguard--; /* Prevent infinite loop, just in case */
2032 }
2033 /*return;*/
2034 }
2035 }
2036 }
2037 if(!quiet && !safeguard)
2038 fprintf(stderr, "auto_stretch: safeguard terminated possible infinite loop; please report.\n");
2039 }
2040
2041 void make_layout(rcsfile_t *rcs)
2042 {
2043 int i, j;
2044 int x, y;
2045 int w, h;
2046 int w2;
2047
2048 /* Remove all unwanted revisions */
2049 if(conf.strip_untagged)
2050 {
2051 int fr = conf.strip_first_rev ? 0 : 1;
2052 for(i = 0; i < rcs->nbranches; i++)
2053 {
2054 branch_t *bp = rcs->branches[i];
2055 for(j = fr; j < bp->nrevs-1; j++)
2056 {
2057 if(!bp->revs[j]->ntags && !bp->revs[j]->nbranches)
2058 {
2059 memmove(&bp->revs[j], &bp->revs[j+1], (bp->nrevs-j-1) * sizeof(bp->revs[0]));
2060 bp->nrevs--;
2061 bp->revs[j]->stripped = 1;
2062 j--;
2063 }
2064 }
2065 }
2066 }
2067
2068 /* Calculate the box-sizes of the revisions */
2069 for(i = 0; i < rcs->nsrev; i++)
2070 {
2071 revision_t *rp;
2072 int w;
2073 int h;
2074 rp = rcs->srev[i];
2075 rp->revtext = expand_string(conf.rev_text, rcs, rp, rp->rev, NULL, rp->ntags ? rp->tags[0] : NULL);
2076 w = get_swidth(rp->revtext, &conf.rev_text_font);
2077 j = get_swidth(rp->rev->rev, &conf.rev_font);
2078 if(j > w)
2079 w = j;
2080 h = get_sheight(rp->revtext, &conf.rev_text_font) + get_sheight(rp->rev->rev, &conf.rev_font);
2081 for(j = 0; j < rp->ntags; j++)
2082 {
2083 int ww = get_swidth(rp->tags[j]->tag, &conf.tag_font);
2084 if(ww > w) w = ww;
2085 h += get_sheight(rp->tags[j]->tag, &conf.tag_font) + conf.rev_separator;
2086 }
2087 rp->w = w + conf.rev_lspace + conf.rev_rspace;
2088 rp->h = h + conf.rev_tspace + conf.rev_bspace;
2089 }
2090
2091 /* Calculate the box-sizes of the branches */
2092 for(i = 0; i < rcs->nbranches; i++)
2093 {
2094 branch_t *bp = rcs->branches[i];
2095 int w;
2096 int h;
2097 w = get_swidth(bp->branch->branch, &conf.branch_font);
2098 h = get_sheight(bp->branch->branch, &conf.branch_font);
2099 for(j = 0; j < bp->ntags; j++)
2100 {
2101 int ww = get_swidth(bp->tags[j]->tag, &conf.branch_tag_font);
2102 if(ww > w) w = ww;
2103 h += get_sheight(bp->tags[j]->tag, &conf.branch_tag_font);
2104 }
2105 w += conf.branch_lspace + conf.branch_rspace;
2106 h += conf.branch_tspace + conf.branch_bspace;
2107 bp->w = w;
2108 bp->h = h;
2109 if(conf.left_right)
2110 {
2111 for(j = 0; j < bp->nrevs; j++)
2112 {
2113 if(bp->revs[j]->h > h)
2114 h = bp->revs[j]->h;
2115 w += bp->revs[j]->w + conf.rev_minline;
2116 }
2117 if(conf.branch_dupbox)
2118 w += bp->w + conf.rev_minline;
2119 }
2120 else
2121 {
2122 for(j = 0; j < bp->nrevs; j++)
2123 {
2124 if(bp->revs[j]->w > w)
2125 w = bp->revs[j]->w;
2126 h += bp->revs[j]->h + conf.rev_minline;
2127 }
2128 if(conf.branch_dupbox)
2129 h += bp->h + conf.rev_minline;
2130 }
2131 bp->th = h;
2132 bp->tw = w;
2133 }
2134
2135 /* Calculate the relative positions of revs in a branch */
2136 if(conf.left_right)
2137 {
2138 for(i = 0; i < rcs->nbranches; i++)
2139 {
2140 branch_t *b = rcs->branches[i];
2141 y = b->th/2;
2142 x = b->w;
2143 b->y = y;
2144 b->cx = 0;
2145 for(j = 0; j < b->nrevs; j++)
2146 {
2147 x += conf.rev_minline;
2148 b->revs[j]->y = y;
2149 b->revs[j]->cx = x;
2150 x += b->revs[j]->w;
2151 }
2152 }
2153 }
2154 else
2155 {
2156 for(i = 0; i < rcs->nbranches; i++)
2157 {
2158 branch_t *b = rcs->branches[i];
2159 x = b->tw/2;
2160 y = b->h;
2161 b->cx = x;
2162 b->y = 0;
2163 for(j = 0; j < b->nrevs; j++)
2164 {
2165 y += conf.rev_minline;
2166 b->revs[j]->cx = x;
2167 b->revs[j]->y = y;
2168 y += b->revs[j]->h;
2169 }
2170 }
2171 }
2172
2173 /* Initially reposition the branches from bottom to top progressively right */
2174 if(conf.left_right)
2175 {
2176 x = rcs->branches[0]->y;
2177 w2 = rcs->branches[0]->th / 2;
2178 for(i = rcs->branches[0]->nrevs-1; i >= 0; i--)
2179 {
2180 initial_reposition_branch_lr(rcs->branches[0]->revs[i], &x, &w2);
2181 }
2182 }
2183 else
2184 {
2185 x = rcs->branches[0]->cx;
2186 w2 = rcs->branches[0]->tw / 2;
2187 for(i = rcs->branches[0]->nrevs-1; i >= 0; i--)
2188 {
2189 initial_reposition_branch(rcs->branches[0]->revs[i], &x, &w2);
2190 }
2191 }
2192
2193 /* Initially move branches left if there is room */
2194 kern_tree(rcs);
2195
2196 /* Try to kern the branches more by expanding the inter-revision spacing */
2197 if(conf.auto_stretch && !conf.left_right)
2198 auto_stretch(rcs);
2199
2200 /* Move everything w.r.t. the top-left margin */
2201 for(i = 0; i < rcs->nbranches; i++)
2202 move_branch(rcs->branches[i], conf.margin_left, conf.margin_top);
2203
2204 /* Calculate overall image size */
2205 if(conf.left_right)
2206 {
2207 x = rcs->branches[0]->cx;
2208 y = rcs->branches[0]->y - rcs->branches[0]->th/2;
2209 }
2210 else
2211 {
2212 x = rcs->branches[0]->cx - rcs->branches[0]->tw/2;
2213 y = rcs->branches[0]->y;
2214 }
2215 w = rcs->branches[0]->tw;
2216 h = rcs->branches[0]->th;
2217 for(i = 1; i < rcs->nbranches; i++)
2218 rect_union(&x, &y, &w, &h, rcs->branches[i]);
2219 rcs->tw = w;
2220 rcs->th = h;
2221
2222 /* Flip the entire tree */
2223 if(conf.upside_down)
2224 {
2225 if(conf.left_right)
2226 {
2227 x += rcs->tw;
2228 for(i = 0; i < rcs->nbranches; i++)
2229 {
2230 branch_t *b = rcs->branches[i];
2231 for(j = 0; j < b->nrevs; j++)
2232 {
2233 revision_t *r = b->revs[j];
2234 r->cx = x - r->cx - r->w + conf.margin_left;
2235 }
2236 b->cx = x - b->cx - b->w + conf.margin_left;
2237 }
2238 }
2239 else
2240 {
2241 y += rcs->th;
2242 for(i = 0; i < rcs->nbranches; i++)
2243 {
2244 branch_t *b = rcs->branches[i];
2245 for(j = 0; j < b->nrevs; j++)
2246 {
2247 revision_t *r = b->revs[j];
2248 r->y = y - r->y - r->h + conf.margin_top;
2249 }
2250 b->y = y - b->y - b->h + conf.margin_top;
2251 }
2252 }
2253 }
2254 }
2255
2256 /*
2257 **************************************************************************
2258 * Imagemap functions
2259 **************************************************************************
2260 */
2261 void make_imagemap(rcsfile_t *rcs, FILE *fp, gdImagePtr im)
2262 {
2263 int i, j;
2264 const char *htp = conf.html_level == HTMLLEVEL_X ? " /" : "";
2265
2266 switch(conf.html_level)
2267 {
2268 case HTMLLEVEL_4:
2269 fprintf(fp, "<map name=\"%s\" id=\"%s\">\n", conf.map_name, conf.map_name);
2270 break;
2271 case HTMLLEVEL_X:
2272 fprintf(fp, "<map id=\"%s\">\n", conf.map_name);
2273 break;
2274 default:
2275 fprintf(fp, "<map name=\"%s\">\n", conf.map_name);
2276 }
2277
2278 for(i = 0; i < rcs->nbranches; i++)
2279 {
2280 branch_t *b = rcs->branches[i];
2281 tag_t *tag = b->ntags ? b->tags[0] : NULL;
2282 char *bhref = expand_string(conf.map_branch_href, rcs, NULL, b->branch, NULL, tag);
2283 char *balt = expand_string(conf.map_branch_alt, rcs, NULL, b->branch, NULL, tag);
2284 int x1;
2285 int x2;
2286 int y1;
2287 int y2;
2288
2289 if(conf.left_right)
2290 {
2291 x1 = b->cx;
2292 y1 = b->y - b->h/2;
2293 x2 = b->cx + b->w;
2294 y2 = b->y + b->h/2;
2295 }
2296 else
2297 {
2298 x1 = b->cx - b->w/2;
2299 y1 = b->y;
2300 x2 = b->cx + b->w/2;
2301 y2 = b->y + b->h;
2302 }
2303 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s%s>\n",
2304 bhref, x1, y1, x2, y2, balt, htp);
2305 if(im)
2306 {
2307 gdImageFilledRectangle(im, x1-2, y1-2, x1+2, y1+2, conf.title_color.id);
2308 gdImageFilledRectangle(im, x2-2, y2-2, x2+2, y2+2, conf.tag_color.id);
2309 gdImageLine(im, x1, y1, x2, y2, conf.title_color.id);
2310 }
2311 for(j = 0; j < b->nrevs; j++)
2312 {
2313 revision_t *r = b->revs[j];
2314 revision_t* r1;
2315 int xoff = 1;
2316 int yoff = 1;
2317 char *href;
2318 char *alt;
2319
2320 tag = r->ntags ? r->tags[0] : NULL;
2321 href = expand_string(conf.map_rev_href, rcs, r, r->rev, NULL, tag);
2322 alt = expand_string(conf.map_rev_alt, rcs, r, r->rev, NULL, tag);
2323 if(conf.left_right)
2324 {
2325 x1 = r->cx;
2326 y1 = r->y - r->h/2;
2327 x2 = r->cx + r->w;
2328 y2 = r->y + r->h/2;
2329 }
2330 else
2331 {
2332 x1 = r->cx - r->w/2;
2333 y1 = r->y;
2334 x2 = r->cx + r->w/2;
2335 y2 = r->y + r->h;
2336 }
2337 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s%s>\n",
2338 href, x1, y1, x2, y2, alt, htp);
2339 if(im)
2340 {
2341 gdImageFilledRectangle(im, x1-2, y1-2, x1+2, y1+2, conf.title_color.id);
2342 gdImageFilledRectangle(im, x2-2, y2-2, x2+2, y2+2, conf.tag_color.id);
2343 gdImageLine(im, x1, y1, x2, y2, conf.title_color.id);
2344 }
2345 xfree(href);
2346 xfree(alt);
2347 if(j > 0 || b->branchpoint)
2348 {
2349 if(j > 0)
2350 {
2351 r1 = b->revs[j-1];
2352 if(conf.left_right)
2353 {
2354 yoff = MIN(r->h, r1->h)/4;
2355 x1 = conf.upside_down ? r1->cx : r1->cx + r1->w;
2356 }
2357 else
2358 {
2359 xoff = MIN(r->w, r1->w)/4;
2360 y1 = conf.upside_down ? r1->y : r1->y + r1->h;
2361 }
2362 }
2363 else
2364 {
2365 r1 = b->branchpoint;
2366 if(conf.left_right)
2367 {
2368 yoff = MIN(r->h, b->h)/4;
2369 x1 = conf.upside_down ? b->cx : b->cx + b->w;
2370 }
2371 else
2372 {
2373 xoff = MIN(r->w, b->w)/4;
2374 y1 = conf.upside_down ? b->y : b->y + b->h;
2375 }
2376 }
2377 if(conf.left_right)
2378 {
2379 y1 = r->y - yoff;
2380 y2 = r->y + yoff;
2381 x2 = conf.upside_down ? r->cx + r->w : r->cx;
2382 yoff = 0;
2383 }
2384 else
2385 {
2386 x1 = r->cx - xoff;
2387 x2 = r->cx + xoff;
2388 y2 = conf.upside_down ? r->y + r->h : r->y;
2389 xoff = 0;
2390 }
2391 if(x1 > x2)
2392 {
2393 int tt = x1;
2394 x1 = x2;
2395 x2 = tt;
2396 }
2397 if(y1 > y2)
2398 {
2399 int tt = y1;
2400 y1 = y2;
2401 y2 = tt;
2402 }
2403 href = expand_string(conf.map_diff_href, rcs, r, r->rev, r1->rev, tag);
2404 alt = expand_string(conf.map_diff_alt, rcs, r, r->rev, r1->rev, tag);
2405 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s%s>\n",
2406 href,
2407 x1+xoff, y1+yoff, x2-xoff, y2-yoff,
2408 alt, htp);
2409 if(im)
2410 {
2411 gdImageFilledRectangle(im, x1-2, y1-2, x1+2, y1+2, conf.title_color.id);
2412 gdImageFilledRectangle(im, x2-2, y2-2, x2+2, y2+2, conf.tag_color.id);
2413 gdImageLine(im, x1, y1, x2, y2, conf.title_color.id);
2414 }
2415 xfree(href);
2416 xfree(alt);
2417 }
2418 }
2419 if(conf.branch_dupbox)
2420 {
2421 if(conf.left_right)
2422 {
2423 x1 = conf.upside_down ? b->cx + b->w - b->tw : b->cx - b->w + b->tw;
2424 y1 = b->y - b->h/2;
2425 x2 = x1 + b->w;
2426 y2 = b->y + b->h/2;
2427 }
2428 else
2429 {
2430 x1 = b->cx - b->w/2;
2431 y1 = conf.upside_down ? b->y + b->h - b->th : b->y - b->h + b->th;
2432 x2 = b->cx + b->w/2;
2433 y2 = y1 + b->h;
2434 }
2435 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s%s>\n",
2436 bhref, x1, y1, x2, y2, balt, htp);
2437 if(im)
2438 {
2439 gdImageFilledRectangle(im, x1-2, y1-2, x1+2, y1+2, conf.title_color.id);
2440 gdImageFilledRectangle(im, x2-2, y2-2, x2+2, y2+2, conf.tag_color.id);
2441 gdImageLine(im, x1, y1, x2, y2, conf.title_color.id);
2442 }
2443 }
2444 xfree(bhref);
2445 xfree(balt);
2446 }
2447 fprintf(fp, "</map>\n");
2448 }
2449
2450 /*
2451 **************************************************************************
2452 * Program entry
2453 **************************************************************************
2454 */
2455 static const char usage_str[] =
2456 "Usage: cvsgraph [options] <file>\n"
2457 " -b Add a branch box at both sides of the trunk (config value is negated)\n"
2458 " -c <file> Read alternative config from <file>\n"
2459 " -d <level> Enable debug mode at <level>\n"
2460 " -h This message\n"
2461 " -i Generate an imagemap instead of image\n"
2462 " -I <file> Also write the imagemap to <file>\n"
2463 " -k Auto stretch the tree (config value is negated)\n"
2464 " -M <name> Use <name> as imagemap name\n"
2465 " -m <mod> Use <mod> as cvs module\n"
2466 " -o <file> Output to <file>\n"
2467 " -O <opt=val> Set option opt to value val\n"
2468 " -q Be quiet (i.e. no warnings)\n"
2469 " -r <path> Use <path> as cvsroot path\n"
2470 " -s Strip untagged revisions (config value is negated)\n"
2471 " -S Also strip the first revision (config value is negated)\n"
2472 " -u Upside down image (mirror vertically; config value is negated)\n"
2473 " -V Print version and exit\n"
2474 " -x [34x] Specify level of HTML 3.2 (default), 4.0 or XHTML\n"
2475 " -[0-9] <txt> Use <txt> for expansion\n"
2476 ;
2477
2478 #define VERSION_STR "1.3.1"
2479 #define NOTICE_STR "Copyright (c) 2001,2002,2003 B.Stultiens"
2480
2481 static void append_slash(char **path)
2482 {
2483 int l;
2484 assert(path != NULL);
2485 assert(*path != NULL);
2486 l = strlen(*path);
2487 if(!l || (*path)[l-1] == '/')
2488 return;
2489 *path = xrealloc(*path, l+2);
2490 strcat(*path, "/");
2491 }
2492
2493 int main(int argc, char *argv[])
2494 {
2495 extern int rcs_flex_debug;
2496 extern int rcsdebug;
2497 int optc;
2498 char *confpath = NULL;
2499 char *outfile = NULL;
2500 char *cvsroot = NULL;
2501 char *cvsmodule = NULL;
2502 int imagemap = 0;
2503 int upsidedown = 0;
2504 int bdupbox = 0;
2505 int stripuntag = 0;
2506 int stripfirst = 0;
2507 int autostretch = 0;
2508 int htmllevel = 0;
2509 char *imgmapname = NULL;
2510 char *imgmapfile = NULL;
2511 int lose = 0;
2512 FILE *fp;
2513 char *rcsfilename;
2514 rcsfile_t *rcs;
2515 gdImagePtr im;
2516
2517 while((optc = getopt(argc, argv, "0:1:2:3:4:5:6:7:8:9:bc:d:hI:ikM:m:O:o:qr:SsuVx:")) != EOF)
2518 {
2519 switch(optc)
2520 {
2521 case 'b':
2522 bdupbox = 1;
2523 break;
2524 case 'c':
2525 confpath = xstrdup(optarg);
2526 break;
2527 case 'd':
2528 debuglevel = strtol(optarg, NULL, 0);
2529 break;
2530 case 'I':
2531 imgmapfile = xstrdup(optarg);
2532 break;
2533 case 'i':
2534 imagemap = 1;
2535 break;
2536 case 'k':
2537 autostretch = 1;
2538 break;
2539 case 'M':
2540 imgmapname = xstrdup(optarg);
2541 break;
2542 case 'm':
2543 cvsmodule = xstrdup(optarg);
2544 break;
2545 case 'O':
2546 stack_option(optarg);
2547 break;
2548 case 'o':
2549 outfile = xstrdup(optarg);
2550 break;
2551 case 'q':
2552 quiet = 1;
2553 break;
2554 case 'r':
2555 cvsroot = xstrdup(optarg);
2556 break;
2557 case 'S':
2558 stripfirst = 1;
2559 break;
2560 case 's':
2561 stripuntag = 1;
2562 break;
2563 case 'u':
2564 upsidedown = 1;
2565 break;
2566 case 'V':
2567 fprintf(stdout, "cvsgraph v%s, %s\n", VERSION_STR, NOTICE_STR);
2568 return 0;
2569 case 'x':
2570 switch(optarg[0])
2571 {
2572 case '3':
2573 htmllevel = HTMLLEVEL_3;
2574 break;
2575 case '4':
2576 htmllevel = HTMLLEVEL_4;
2577 break;
2578 case 'x':
2579 htmllevel = HTMLLEVEL_X;
2580 break;
2581 default:
2582 fprintf(stderr, "Invalid HTML level in -x\n");
2583 lose++;
2584 }
2585 break;
2586 case 'h':
2587 fprintf(stdout, "%s", usage_str);
2588 return 0;
2589 default:
2590 if(isdigit(optc))
2591 {
2592 conf.expand[optc-'0'] = xstrdup(optarg);
2593 }
2594 else
2595 lose++;
2596 }
2597 }
2598
2599 if(lose)
2600 {
2601 fprintf(stderr, "%s", usage_str);
2602 return 1;
2603 }
2604
2605 if(debuglevel)
2606 {
2607 setvbuf(stdout, NULL, 0, _IONBF);
2608 setvbuf(stderr, NULL, 0, _IONBF);
2609 }
2610 rcs_flex_debug = (debuglevel & DEBUG_RCS_LEX) != 0;
2611 rcsdebug = (debuglevel & DEBUG_RCS_YACC) != 0;
2612
2613 /* Set defaults */
2614 conf.tag_font.gdfont = gdFontTiny;
2615 conf.rev_font.gdfont = gdFontTiny;
2616 conf.branch_font.gdfont = gdFontTiny;
2617 conf.branch_tag_font.gdfont = gdFontTiny;
2618 conf.title_font.gdfont = gdFontTiny;
2619 conf.rev_text_font.gdfont = gdFontTiny;
2620
2621 conf.anti_alias = 1;
2622 conf.thick_lines = 1;
2623
2624 conf.cvsroot = xstrdup("");
2625 conf.cvsmodule = xstrdup("");
2626 conf.date_format = xstrdup("%d-%b-%Y %H:%M:%S");
2627 conf.title = xstrdup("");
2628 conf.map_name = xstrdup("CvsGraphImageMap");
2629 conf.map_branch_href = xstrdup("href=\"unset: conf.map_branch_href\"");
2630 conf.map_branch_alt = xstrdup("alt=\"%B\"");
2631 conf.map_rev_href = xstrdup("href=\"unset: conf.map_rev_href\"");
2632 conf.map_rev_alt = xstrdup("alt=\"%R\"");
2633 conf.map_diff_href = xstrdup("href=\"unset: conf.map_diff_href\"");
2634 conf.map_diff_alt = xstrdup("alt=\"%P &lt;-&gt; %R\"");
2635 conf.rev_text = xstrdup("%d");
2636
2637 conf.color_bg = white_color;
2638 conf.branch_bgcolor = white_color;
2639 conf.branch_color = black_color;
2640 conf.branch_tag_color = black_color;
2641 conf.rev_color = black_color;
2642 conf.rev_bgcolor = white_color;
2643 conf.tag_color = black_color;
2644 conf.title_color = black_color;
2645 conf.rev_text_color = black_color;
2646
2647 conf.image_quality = 100;
2648 conf.rev_maxline = -1; /* Checked later to set to default */
2649
2650 read_config(confpath);
2651
2652 if(conf.rev_maxline == -1) conf.rev_maxline = 5 * conf.rev_minline;
2653
2654 /* Set overrides */
2655 if(cvsroot) conf.cvsroot = cvsroot;
2656 if(cvsmodule) conf.cvsmodule = cvsmodule;
2657 if(imgmapname) conf.map_name = imgmapname;
2658 if(upsidedown) conf.upside_down = !conf.upside_down;
2659 if(bdupbox) conf.branch_dupbox = !conf.branch_dupbox;
2660 if(stripuntag) conf.strip_untagged = !conf.strip_untagged;
2661 if(stripfirst) conf.strip_first_rev = !conf.strip_first_rev;
2662 if(autostretch) conf.auto_stretch = !conf.auto_stretch;
2663 if(htmllevel) conf.html_level = htmllevel;
2664
2665 if(conf.rev_minline >= conf.rev_maxline)
2666 {
2667 if(conf.auto_stretch && !quiet)
2668 fprintf(stderr, "Auto stretch is only possible if rev_minline < rev_maxline\n");
2669 conf.auto_stretch = 0;
2670 }
2671
2672 if(conf.thick_lines < 1)
2673 conf.thick_lines = 1;
2674 if(conf.thick_lines > 11)
2675 conf.thick_lines = 11;
2676
2677 append_slash(&conf.cvsroot);
2678 append_slash(&conf.cvsmodule);
2679
2680 if(optind >= argc)
2681 {
2682 #ifdef __WIN32__
2683 /* Bad hack for DOS/Windows */
2684 if(setmode(fileno(stdin), O_BINARY) == -1)
2685 {
2686 perror("Set binary mode for stdin");
2687 return 1;
2688 }
2689 #endif
2690 rcsfilename = NULL;
2691 }
2692 else
2693 rcsfilename = argv[optind];
2694
2695 rcs = get_rcsfile(conf.cvsroot, conf.cvsmodule, rcsfilename);
2696 if(!rcs)
2697 return 1;
2698
2699 if(debuglevel & DEBUG_RCS_FILE)
2700 dump_rcsfile(rcs);
2701
2702 if(!reorganise_branches(rcs))
2703 return 1;
2704
2705 if(!assign_tags(rcs))
2706 return 1;
2707
2708 if(outfile)
2709 {
2710 if((fp = fopen(outfile, "wb")) == NULL)
2711 {
2712 perror(outfile);
2713 return 1;
2714 }
2715 }
2716 else
2717 {
2718 fp = stdout;
2719 #ifdef __WIN32__
2720 /* Bad hack for DOS/Windows */
2721 if(setmode(fileno(fp), O_BINARY) == -1)
2722 {
2723 perror("Set binary mode for stdout");
2724 return 1;
2725 }
2726 #endif
2727 }
2728
2729 make_layout(rcs);
2730
2731 if(!imagemap)
2732 {
2733 /* Create an image */
2734 im = make_image(rcs);
2735 #ifdef DEBUG_IMAGEMAP
2736 {
2737 FILE *nulfile = fopen("/dev/null", "w");
2738 make_imagemap(rcs, nulfile, im);
2739 fclose(nulfile);
2740 }
2741 #endif
2742 switch(conf.image_type)
2743 {
2744 #ifdef HAVE_IMAGE_GIF
2745 # ifndef HAVE_IMAGE_PNG
2746 default:
2747 # endif
2748 case IMAGE_GIF:
2749 gdImageGif(im, fp);
2750 break;
2751 #endif
2752 #ifdef HAVE_IMAGE_PNG
2753 default:
2754 case IMAGE_PNG:
2755 gdImagePng(im, fp);
2756 break;
2757 #endif
2758 #ifdef HAVE_IMAGE_JPEG
2759 # if !defined(HAVE_IMAGE_GIF) && !defined(HAVE_IMAGE_PNG)
2760 default:
2761 # endif
2762 case IMAGE_JPEG:
2763 gdImageJpeg(im, fp, conf.image_quality);
2764 break;
2765 #endif
2766 }
2767
2768 gdImageDestroy(im);
2769 }
2770 else
2771 {
2772 /* Create an imagemap */
2773 make_imagemap(rcs, fp, NULL);
2774 }
2775
2776 /* Also create imagemap to file if requested */
2777 if(imgmapfile)
2778 {
2779 FILE *ifp = fopen(imgmapfile, "wb");
2780 if(!ifp)
2781 {
2782 perror(imgmapfile);
2783 return 1;
2784 }
2785 make_imagemap(rcs, ifp, NULL);
2786 fclose(ifp);
2787 }
2788
2789 if(outfile)
2790 fclose(fp);
2791
2792 return 0;
2793 }

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0