/[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.8 - (show annotations)
Sun Mar 4 03:19:18 2001 UTC (16 years, 7 months ago) by bertho
Branch: MAIN
CVS Tags: REL_1_1_0
Changes since 1.7: +148 -75 lines
File MIME type: text/plain
Basic imagemap stuff done. The expansion code needs some work to allow
for conditional expansion.
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 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <assert.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <sys/wait.h>
30 #include <fcntl.h>
31 #include <regex.h>
32 #include <errno.h>
33 #include <getopt.h>
34 #include <ctype.h>
35
36 #include <gd.h>
37 #include <gdfontt.h>
38
39 #include "config.h"
40 #include "cvsgraph.h"
41 #include "utils.h"
42 #include "readconf.h"
43 #include "rcs.h"
44
45 #if !defined(HAVE_IMAGE_GIF) && !defined(HAVE_IMAGE_PNG) && !defined(HAVE_IMAGE_JPEG)
46 # error No image output format available. Check libgd
47 #endif
48
49
50 /*#define DEBUG 1*/
51
52 #define CONFFILENAME "cvsgraph.conf"
53
54 #ifndef ETCDIR
55 # define ETCDIR "/usr/local/etc"
56 #endif
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 #define ALIGN_HX 0x0f
70 #define ALIGN_VT 0x00
71 #define ALIGN_VC 0x10
72 #define ALIGN_VB 0x20
73 #define ALIGN_VX 0xf0
74
75 /*
76 **************************************************************************
77 * Globals
78 **************************************************************************
79 */
80
81 config_t conf;
82 int debuglevel;
83
84 /*
85 **************************************************************************
86 * Dubug routines
87 **************************************************************************
88 */
89 void dump_rev(char *p, rev_t *r)
90 {
91 printf("%s", p);
92 if(r)
93 printf("'%s', '%s', %d\n", r->rev, r->branch, r->isbranch);
94 else
95 printf("<null>\n");
96 }
97
98 void dump_id(char *p, char *d)
99 {
100 printf("%s", p);
101 if(d)
102 printf("'%s'\n", d);
103 else
104 printf("<null>\n");
105 }
106
107 void dump_idrev(char *p, idrev_t *t)
108 {
109 printf("%s", p);
110 if(t)
111 {
112 printf("'%s' -> ", t->id);
113 dump_rev("", t->rev);
114 }
115 else
116 printf("<null>\n");
117 }
118
119 void dump_tag(char *p, tag_t *t)
120 {
121 printf("%s", p);
122 if(t)
123 {
124 printf("'%s' -> ", t->tag);
125 dump_rev("", t->rev);
126 }
127 else
128 printf("<null>\n");
129 }
130
131 void dump_delta(char *p, delta_t *d)
132 {
133 int i;
134 printf("%sdelta.rev : ", p);
135 dump_rev("", d->rev);
136 printf("%sdelta.date : %s\n", p, d->date);
137 printf("%sdelta.author: %s\n", p, d->author);
138 printf("%sdelta.state : %s\n", p, d->state);
139 for(i = 0; d->branches && i < d->branches->nrevs; i++)
140 {
141 printf("%sdelta.branch: ", p);
142 dump_rev("", d->branches->revs[i]);
143 }
144 printf("%sdelta.next : ", p);
145 dump_rev("", d->next);
146 printf("\n");
147 }
148
149 void dump_dtext(char *p, dtext_t *d)
150 {
151 printf("%sdtext.rev : ", p);
152 dump_rev("", d->rev);
153 printf("%sdtext.log : %d bytes\n", p, d->log ? strlen(d->log) : -1);
154 printf("%sdtext.text : %d bytes\n", p, d->text ? strlen(d->text) : -1);
155 printf("\n");
156 }
157
158 void dump_rcsfile(rcsfile_t *rcs)
159 {
160 int i;
161 printf("root : '%s'\n", rcs->root);
162 printf("module : '%s'\n", rcs->module);
163 printf("file : '%s'\n", rcs->file);
164 dump_rev("head : ", rcs->head);
165 dump_rev("branch : ", rcs->branch);
166 printf("access :\n");
167 for(i = 0; rcs->access && i < rcs->access->nids; i++)
168 dump_id("\t", rcs->access->ids[i]);
169 printf("tags :\n");
170 for(i = 0; rcs->tags && i < rcs->tags->ntags; i++)
171 dump_tag("\t", rcs->tags->tags[i]);
172 printf("locks :%s\n", rcs->strict ? " (strict)" : "");
173 for(i = 0; rcs->locks && i < rcs->locks->nidrevs; i++)
174 dump_idrev("\t", rcs->locks->idrevs[i]);
175 printf("comment: '%s'\n", rcs->comment);
176 printf("expand : '%s'\n", rcs->expand ? rcs->expand : "(default -kv)");
177 printf("deltas :\n");
178 for(i = 0; rcs->deltas && i < rcs->deltas->ndeltas; i++)
179 dump_delta("\t", rcs->deltas->deltas[i]);
180 printf("desc : '%s'\n", rcs->desc);
181 printf("dtexts :\n");
182 for(i = 0; rcs->dtexts && i < rcs->dtexts->ndtexts; i++)
183 dump_dtext("\t", rcs->dtexts->dtexts[i]);
184
185 fflush(stdout);
186 }
187
188 /*
189 **************************************************************************
190 * Read the rcs file
191 **************************************************************************
192 */
193 rcsfile_t *get_rcsfile(const char *cvsroot, const char *module, const char *file)
194 {
195 char *cmd = NULL;
196 int rv;
197
198 cmd = xmalloc(strlen(cvsroot) + strlen(module) + strlen(file) + 2 + 1);
199 sprintf(cmd, "%s/%s/%s", cvsroot, module, file);
200 if(!(rcsin = fopen(cmd, "r")))
201 return NULL;
202 input_file = cmd;
203 line_number = 1;
204 rv = rcsparse();
205 fclose(rcsin);
206 if(rv)
207 return NULL;
208 xfree(cmd);
209 input_file = NULL;
210 rcsfile->root = xstrdup(cvsroot);
211 rcsfile->module = xstrdup(module);
212 rcsfile->file = xstrdup(file);
213 return rcsfile;
214 }
215
216 /*
217 **************************************************************************
218 * Sort and find helpers
219 **************************************************************************
220 */
221 int count_dots(const char *s)
222 {
223 int i;
224 for(i = 0; *s; s++)
225 {
226 if(*s == '.')
227 i++;
228 }
229 return i;
230 }
231
232 int compare_rev(int bcmp, const rev_t *r1, const rev_t *r2)
233 {
234 int d1, d2;
235 char *c1, *c2;
236 char *v1, *v2;
237 char *s1, *s2;
238 int retval = 0;
239 assert(r1 != NULL);
240 assert(r2 != NULL);
241 if(bcmp)
242 {
243 assert(r1->branch != NULL);
244 assert(r2->branch != NULL);
245 c1 = r1->branch;
246 c2 = r2->branch;
247 }
248 else
249 {
250 assert(r1->rev != NULL);
251 assert(r2->rev != NULL);
252 c1 = r1->rev;
253 c2 = r2->rev;
254 }
255
256 d1 = count_dots(c1);
257 d2 = count_dots(c2);
258 if(d1 != d2)
259 {
260 return d1 - d2;
261 }
262
263 s1 = v1 = xstrdup(c1);
264 s2 = v2 = xstrdup(c2);
265 while(1)
266 {
267 char *vc1 = strchr(s1, '.');
268 char *vc2 = strchr(s2, '.');
269 if(vc1 && vc2)
270 *vc1 = *vc2 = '\0';
271 if(*s1 && *s2)
272 {
273 d1 = atoi(s1);
274 d2 = atoi(s2);
275 if(d1 != d2)
276 {
277 retval = d1 - d2;
278 break;
279 }
280 }
281 if(!vc1 || !vc2)
282 break;
283 s1 = vc1 + 1;
284 s2 = vc2 + 1;
285 }
286 xfree(v1);
287 xfree(v2);
288 return retval;
289 }
290
291 /*
292 **************************************************************************
293 * Reorganise the rcsfile for the branches
294 *
295 * Basically, we have a list of deltas (i.e. administrative info on
296 * revisions) and a list of delta text (the actual logs and diffs).
297 * The deltas are linked through the 'next' and the 'branches' fields
298 * which describe the tree-structure of revisions.
299 * The reorganisation means that we put each delta and corresponding
300 * delta text in a revision structure and assign it to a specific
301 * branch. This is required because we want to be able to calculate
302 * the bounding boxes of each branch. The revisions expand vertically
303 * and the branches expand horizontally.
304 * The reorganisation is performed in these steps:
305 * 1 - sort deltas and detla text on revision number for quick lookup
306 * 2 - start at the denoted head revision:
307 * * create a branch structure and add this revision
308 * * for each 'branches' in the delta do:
309 * - walk all 'branches' of the delta and recursively goto 2
310 * with the denoted branch delta as new head
311 * - backlink the newly create sub-branch to the head revision
312 * so that we can draw them recursively
313 * * set head to the 'next' field and goto 2 until no next is
314 * available
315 * 3 - update the administration
316 **************************************************************************
317 */
318 int sort_delta(const void *d1, const void *d2)
319 {
320 return compare_rev(0, (*(delta_t **)d1)->rev, (*(delta_t **)d2)->rev);
321 }
322
323 int search_delta(const void *r, const void *d)
324 {
325 return compare_rev(0, (rev_t *)r, (*(delta_t **)d)->rev);
326 }
327
328 delta_t *find_delta(delta_t **dl, int n, rev_t *r)
329 {
330 delta_t **d;
331 d = bsearch(r, dl, n, sizeof(*dl), search_delta);
332 if(!d)
333 return NULL;
334 return *d;
335 }
336
337 int sort_dtext(const void *d1, const void *d2)
338 {
339 return compare_rev(0, (*(dtext_t **)d1)->rev, (*(dtext_t **)d2)->rev);
340 }
341
342 int search_dtext(const void *r, const void *d)
343 {
344 return compare_rev(0, (rev_t *)r, (*(dtext_t **)d)->rev);
345 }
346
347 dtext_t *find_dtext(dtext_t **dl, int n, rev_t *r)
348 {
349 dtext_t **d;
350 d = bsearch(r, dl, n, sizeof(*dl), search_dtext);
351 if(!d)
352 return NULL;
353 return *d;
354 }
355
356 rev_t *dup_rev(const rev_t *r)
357 {
358 rev_t *t = xmalloc(sizeof(*t));
359 t->rev = xstrdup(r->rev);
360 t->branch = xstrdup(r->branch);
361 t->isbranch = r->isbranch;
362 return t;
363 }
364
365 branch_t *new_branch(delta_t *d, dtext_t *t)
366 {
367 branch_t *b = xmalloc(sizeof(*b));
368 revision_t *r = xmalloc(sizeof(*r));
369 r->delta = d;
370 r->dtext = t;
371 r->rev = d->rev;
372 r->branch = b;
373 b->branch = dup_rev(d->rev);
374 b->branch->isbranch = 1;
375 b->nrevs = 1;
376 b->revs = xmalloc(sizeof(b->revs[0]));
377 b->revs[0] = r;
378 return b;
379 }
380
381 revision_t *add_to_branch(branch_t *b, delta_t *d, dtext_t *t)
382 {
383 revision_t *r = xmalloc(sizeof(*r));
384 r->delta = d;
385 r->dtext = t;
386 r->rev = d->rev;
387 r->branch = b;
388 b->revs = xrealloc(b->revs, (b->nrevs+1) * sizeof(b->revs[0]));
389 b->revs[b->nrevs] = r;
390 b->nrevs++;
391 return r;
392 }
393
394 void build_branch(branch_t ***bl, int *nbl, delta_t **sdl, int nsdl, dtext_t **sdt, int nsdt, delta_t *head)
395 {
396 branch_t *b;
397 dtext_t *text;
398 revision_t *currev;
399
400 assert(head != NULL);
401
402 if(head->flag)
403 {
404 fprintf(stderr, "Circular reference on '%s' in branchpoint\n", head->rev->rev);
405 return;
406 }
407 head->flag++;
408 text = find_dtext(sdt, nsdt, head->rev);
409
410 /* Create a new branch for this head */
411 b = new_branch(head, text);
412 *bl = xrealloc(*bl, (*nbl+1)*sizeof((*bl)[0]));
413 (*bl)[*nbl] = b;
414 (*nbl)++;
415 currev = b->revs[0];
416 while(1)
417 {
418 /* Process all sub-branches */
419 if(head->branches)
420 {
421 int i;
422 for(i = 0; i < head->branches->nrevs; i++)
423 {
424 delta_t *d = find_delta(sdl, nsdl, head->branches->revs[i]);
425 int btag = *nbl;
426 if(!d)
427 continue;
428 build_branch(bl, nbl, sdl, nsdl, sdt, nsdt, d);
429
430 /* Set the new branch's origin */
431 (*bl)[btag]->branchpoint = currev;
432
433 /* Add branch to this revision */
434 currev->branches = xrealloc(currev->branches, (currev->nbranches+1)*sizeof(currev->branches[0]));
435 currev->branches[currev->nbranches] = (*bl)[btag];
436 currev->nbranches++;
437 }
438 }
439
440 /* Walk through the next list */
441 if(!head->next)
442 return;
443
444 head = find_delta(sdl, nsdl, head->next);
445 if(!head)
446 {
447 fprintf(stderr, "Next revision (%s) not found in deltalist\n", head->next->rev);
448 return;
449 }
450 if(head->flag)
451 {
452 fprintf(stderr, "Circular reference on '%s'\n", head->rev->rev);
453 return;
454 }
455 head->flag++;
456 text = find_dtext(sdt, nsdt, head->rev);
457 currev = add_to_branch(b, head, text);
458 }
459 }
460
461 int reorganise_branches(rcsfile_t *rcs)
462 {
463 delta_t **sdelta;
464 int nsdelta;
465 dtext_t **sdtext;
466 int nsdtext;
467 delta_t *head;
468 branch_t **bl;
469 int nbl;
470 int i;
471
472 assert(rcs->deltas != NULL);
473 assert(rcs->head != NULL);
474
475 /* Make a new list for quick lookup */
476 nsdelta = rcs->deltas->ndeltas;
477 sdelta = xmalloc(nsdelta * sizeof(sdelta[0]));
478 memcpy(sdelta, rcs->deltas->deltas, nsdelta * sizeof(sdelta[0]));
479 qsort(sdelta, nsdelta, sizeof(sdelta[0]), sort_delta);
480
481 /* Do the same for the delta text */
482 nsdtext = rcs->dtexts->ndtexts;
483 sdtext = xmalloc(nsdtext * sizeof(sdtext[0]));
484 memcpy(sdtext, rcs->dtexts->dtexts, nsdtext * sizeof(sdtext[0]));
485 qsort(sdtext, nsdtext, sizeof(sdtext[0]), sort_dtext);
486
487 /* Start from the head of the trunk */
488 head = find_delta(sdelta, nsdelta, rcs->head);
489 if(!head)
490 {
491 fprintf(stderr, "Head revision (%s) not found in deltalist\n", rcs->head->rev);
492 return 0;
493 }
494 bl = NULL;
495 nbl = 0;
496 build_branch(&bl, &nbl, sdelta, nsdelta, sdtext, nsdtext, head);
497
498 /* Reverse the head branch */
499 for(i = 0; i < bl[0]->nrevs/2; i++)
500 {
501 revision_t *r;
502 r = bl[0]->revs[i];
503 bl[0]->revs[i] = bl[0]->revs[bl[0]->nrevs-i-1];
504 bl[0]->revs[bl[0]->nrevs-i-1] = r;
505 }
506
507 /* Update the branch-number of the head because it was reversed */
508 xfree(bl[0]->branch->branch);
509 bl[0]->branch->branch = xstrdup(bl[0]->revs[0]->rev->branch);
510
511 /* Keep the admin */
512 rcs->branches = bl;
513 rcs->nbranches = nbl;
514 rcs->sdelta = sdelta;
515 rcs->nsdelta = nsdelta;
516 rcs->sdtext = sdtext;
517 rcs->nsdtext = nsdtext;
518 rcs->active = bl[0];
519 return 1;
520 }
521
522 /*
523 **************************************************************************
524 * Assign the symbolic tags to the revisions and branches
525 *
526 * The tags point to revision numbers somewhere in the tree structure
527 * of branches and revisions. First we make a sorted list of all
528 * revisions and then we assign each tag to the proper revision.
529 **************************************************************************
530 */
531 int sort_revision(const void *r1, const void *r2)
532 {
533 return compare_rev(0, (*(revision_t **)r1)->delta->rev, (*(revision_t **)r2)->delta->rev);
534 }
535
536 int search_revision(const void *t, const void *r)
537 {
538 return compare_rev(0, (rev_t *)t, (*(revision_t **)r)->delta->rev);
539 }
540
541 int sort_branch(const void *b1, const void *b2)
542 {
543 return compare_rev(1, (*(branch_t **)b1)->branch, (*(branch_t **)b2)->branch);
544 }
545
546 int search_branch(const void *t, const void *b)
547 {
548 return compare_rev(1, (rev_t *)t, (*(branch_t **)b)->branch);
549 }
550
551 char *previous_rev(const char *c)
552 {
553 int dots = count_dots(c);
554 char *cptr;
555 char *r;
556 if(!dots)
557 return xstrdup("1.0"); /* FIXME: don't know what the parent is */
558 if(dots & 1)
559 {
560 /* Is is a revision we want the parent of */
561 r = xstrdup(c);
562 cptr = strrchr(r, '.');
563 assert(cptr != NULL);
564 if(dots == 1)
565 {
566 /* FIXME: What is the parent of 1.1? */
567 cptr[1] = '\0';
568 strcat(r, "0");
569 return r;
570 }
571 /* Here we have a "x.x[.x.x]+" case */
572 *cptr = '\0';
573 cptr = strrchr(r, '.');
574 assert(cptr != NULL);
575 *cptr = '\0';
576 return r;
577 }
578 /* It is a branch we want the parent of */
579 r = xstrdup(c);
580 cptr = strrchr(r, '.');
581 assert(cptr != NULL);
582 *cptr = '\0';
583 return r;
584 }
585
586 int assign_tags(rcsfile_t *rcs)
587 {
588 int i;
589 int nr;
590
591 for(i = nr = 0; i < rcs->nbranches; i++)
592 nr += rcs->branches[i]->nrevs;
593
594 rcs->srev = xmalloc(nr * sizeof(rcs->srev[0]));
595 rcs->nsrev = nr;
596 for(i = nr = 0; i < rcs->nbranches; i++)
597 {
598 memcpy(&rcs->srev[nr], rcs->branches[i]->revs, rcs->branches[i]->nrevs * sizeof(rcs->branches[i]->revs[0]));
599 nr += rcs->branches[i]->nrevs;
600 }
601
602 qsort(rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), sort_revision);
603 qsort(rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), sort_branch);
604
605 if(!rcs->branch)
606 {
607 /* The main trunk is the active trunk */
608 rcs->tags->tags = xrealloc(rcs->tags->tags, (rcs->tags->ntags+1)*sizeof(rcs->tags->tags[0]));
609 rcs->tags->tags[rcs->tags->ntags] = xmalloc(sizeof(tag_t));
610 rcs->tags->tags[rcs->tags->ntags]->tag = xstrdup("MAIN");
611 rcs->tags->tags[rcs->tags->ntags]->rev = xmalloc(sizeof(rev_t));
612 rcs->tags->tags[rcs->tags->ntags]->rev->rev = xstrdup(rcs->active->branch->rev);
613 rcs->tags->tags[rcs->tags->ntags]->rev->branch = xstrdup(rcs->active->branch->branch);
614 rcs->tags->tags[rcs->tags->ntags]->rev->isbranch = 1;
615 rcs->tags->ntags++;
616 }
617
618 /* We should have at least two tags (HEAD and MAIN) */
619 assert(rcs->tags != 0);
620
621 for(i = 0; i < rcs->tags->ntags; i++)
622 {
623 tag_t *t = rcs->tags->tags[i];
624 if(t->rev->isbranch)
625 {
626 branch_t **b;
627 add_btag:
628 b = bsearch(t->rev, rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), search_branch);
629 if(!b)
630 {
631 rev_t rev;
632 revision_t **r;
633 /* This happens for the magic branch numbers if there are
634 * no commits withing the new branch yet. So, we add the
635 * branch and try continue.
636 */
637 rev.rev = previous_rev(t->rev->branch);
638 rev.branch = NULL;
639 rev.isbranch = 0;
640 r = bsearch(&rev, rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), search_revision);
641 xfree(rev.rev);
642 if(!r)
643 {
644 fprintf(stderr, "No branch found for tag '%s:%s'\n", t->tag, t->rev->branch);
645 }
646 else
647 {
648 rcs->branches = xrealloc(rcs->branches, (rcs->nbranches+1)*sizeof(rcs->branches[0]));
649 rcs->branches[rcs->nbranches] = xmalloc(sizeof(branch_t));
650 rcs->branches[rcs->nbranches]->branch = dup_rev(t->rev);
651 rcs->branches[rcs->nbranches]->branchpoint = *r;
652 (*r)->branches = xrealloc((*r)->branches, ((*r)->nbranches+1)*sizeof((*r)->branches[0]));
653 (*r)->branches[(*r)->nbranches] = rcs->branches[rcs->nbranches];
654 (*r)->nbranches++;
655 rcs->nbranches++;
656 /* Resort the branches */
657 qsort(rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), sort_branch);
658 goto add_btag;
659 }
660 }
661 else
662 {
663 branch_t *bb = *b;
664 bb->tags = xrealloc(bb->tags, (bb->ntags+1)*sizeof(bb->tags[0]));
665 bb->tags[bb->ntags] = t;
666 bb->ntags++;
667 }
668 }
669 else
670 {
671 revision_t **r = bsearch(t->rev, rcs->srev, rcs->nsrev, sizeof(rcs->srev[0]), search_revision);
672 if(!r)
673 fprintf(stderr, "No revision found for tag '%s:%s'\n", t->tag, t->rev->rev);
674 else
675 {
676 revision_t *rr = *r;
677 rr->tags = xrealloc(rr->tags, (rr->ntags+1)*sizeof(rr->tags[0]));
678 rr->tags[rr->ntags] = t;
679 rr->ntags++;
680 }
681 }
682 }
683
684 /* We need to reset the first in the list of branches to the
685 * active branch to ensure the drawing of all
686 */
687 if(rcs->active != rcs->branches[0])
688 {
689 branch_t **b = bsearch(rcs->active->branch, rcs->branches, rcs->nbranches, sizeof(rcs->branches[0]), search_branch);
690 branch_t *t;
691 assert(b != NULL);
692 t = *b;
693 *b = rcs->branches[0];
694 rcs->branches[0] = t;
695 }
696 return 1;
697 }
698
699 /*
700 **************************************************************************
701 * String expansion
702 **************************************************************************
703 */
704 static char *_string;
705 static int _nstring;
706 static int _nastring;
707
708 void add_string_str(const char *s)
709 {
710 int l = strlen(s) + 1;
711 if(_nstring + l > _nastring)
712 {
713 _nastring += 128;
714 _string = xrealloc(_string, _nastring * sizeof(_string[0]));
715 }
716 memcpy(_string+_nstring, s, l);
717 _nstring += l-1;
718 }
719
720 void add_string_ch(int ch)
721 {
722 char buf[2];
723 buf[0] = ch;
724 buf[1] = '\0';
725 add_string_str(buf);
726 }
727
728 char *expand_string(const char *s, rcsfile_t *rcs, rev_t *rev, tag_t *tag)
729 {
730 char nb[32];
731 char nr[32];
732 char *base;
733
734 if(!s)
735 return xstrdup("");
736
737 _nstring = 0;
738 if(_string)
739 _string[0] = '\0';
740
741 sprintf(nb, "%d", rcs->nbranches);
742 sprintf(nr, "%d", rcs->nsrev);
743 for(; *s; s++)
744 {
745 if(*s == '%')
746 {
747 switch(*++s)
748 {
749 case 'c': add_string_str(conf.cvsroot); break;
750 case 'f':
751 case 'F':
752 base = strrchr(rcs->file, '/');
753 if(!base)
754 add_string_str(rcs->file);
755 else
756 add_string_str(base+1);
757 if(*s == 'F' && _string[_nstring-1] == 'v' && _string[_nstring-2] == ',')
758 {
759 _nstring -= 2;
760 _string[_nstring] = '\0';
761 }
762 break;
763 case 'p':
764 base = strrchr(rcs->file, '/');
765 if(base)
766 {
767 char *c = xstrdup(rcs->file);
768 base = strrchr(c, '/');
769 assert(base != NULL);
770 base[1] = '\0';
771 add_string_str(c);
772 xfree(c);
773 }
774 else
775 add_string_str("/");
776 break;
777 case 'm': add_string_str(conf.cvsmodule); break;
778 case 'r': add_string_str(nr); break;
779 case 'b': add_string_str(nb); break;
780 case '%': add_string_ch('%'); break;
781 case '0': if(conf.expand[0]) add_string_str(conf.expand[0]); break;
782 case '1': if(conf.expand[1]) add_string_str(conf.expand[1]); break;
783 case '2': if(conf.expand[2]) add_string_str(conf.expand[2]); break;
784 case '3': if(conf.expand[3]) add_string_str(conf.expand[3]); break;
785 case '4': if(conf.expand[4]) add_string_str(conf.expand[4]); break;
786 case '5': if(conf.expand[5]) add_string_str(conf.expand[5]); break;
787 case '6': if(conf.expand[6]) add_string_str(conf.expand[6]); break;
788 case '7': if(conf.expand[7]) add_string_str(conf.expand[7]); break;
789 case '8': if(conf.expand[8]) add_string_str(conf.expand[8]); break;
790 case '9': if(conf.expand[9]) add_string_str(conf.expand[9]); break;
791 case 'R': if(rev && rev->rev) add_string_str(rev->rev); break;
792 case 'B': if(rev && rev->branch) add_string_str(rev->branch); break;
793 case 't': if(tag && tag->tag) add_string_str(tag->tag); break;
794 default:
795 add_string_ch('%');
796 add_string_ch(*s);
797 break;
798 }
799 }
800 else
801 add_string_ch(*s);
802 }
803 return xstrdup(_string);
804 }
805
806 /*
807 **************************************************************************
808 * Drawing routines
809 **************************************************************************
810 */
811 int get_swidth(const char *s, font_t *f)
812 {
813 if(!s)
814 return 0;
815 return strlen(s) * (*f)->w;
816 }
817
818 int get_sheight(const char *s, font_t *f)
819 {
820 int nl;
821 if(!s)
822 return 0;
823 for(nl = 1; *s; s++)
824 {
825 if(*s == '\n' && s[1])
826 nl++;
827 }
828 return nl * (*f)->h;
829 }
830
831 void draw_rbox(gdImagePtr im, int x1, int y1, int x2, int y2, int r, color_t *color)
832 {
833 int r2 = 2*r;
834 gdImageLine(im, x1+r, y1, x2-r, y1, color->id);
835 gdImageLine(im, x1+r, y2, x2-r, y2, color->id);
836 gdImageLine(im, x1, y1+r, x1, y2-r, color->id);
837 gdImageLine(im, x2, y1+r, x2, y2-r, color->id);
838 if(r)
839 {
840 gdImageArc(im, x1+r, y1+r, r2, r2, 180, 270, color->id);
841 gdImageArc(im, x2-r, y1+r, r2, r2, 270, 360, color->id);
842 gdImageArc(im, x1+r, y2-r, r2, r2, 90, 180, color->id);
843 gdImageArc(im, x2-r, y2-r, r2, r2, 0, 90, color->id);
844 }
845 }
846
847 void draw_string(gdImagePtr im, char *s, font_t *f, int x, int y, int align, color_t *c)
848 {
849 int xx, yy;
850 switch(align & ALIGN_HX)
851 {
852 default:
853 case ALIGN_HL: xx = 0; break;
854 case ALIGN_HC: xx = -get_swidth(s, f)/2; break;
855 case ALIGN_HR: xx = -get_swidth(s, f); break;
856 }
857 switch(align & ALIGN_VX)
858 {
859 default:
860 case ALIGN_VT: yy = 0; break;
861 case ALIGN_VC: yy = -get_sheight(s, f)/2; break;
862 case ALIGN_VB: yy = -get_sheight(s, f); break;
863 }
864 gdImageString(im, *f, x+xx+1, y+yy, s, c->id);
865 }
866
867 void draw_rev(gdImagePtr im, int cx, int ty, revision_t *r)
868 {
869 int lx = cx - r->w/2;
870 int rx = lx + r->w;
871 int i;
872 draw_rbox(im, lx, ty, rx, ty+r->h, 0, &conf.rev_color);
873 ty += conf.rev_tspace;
874 draw_string(im, r->rev->rev, &conf.rev_font, cx, ty, ALIGN_HC, &conf.rev_color);
875 ty += get_sheight(r->rev->rev, &conf.rev_font);
876 for(i = 0; i < r->ntags; i++)
877 {
878 draw_string(im, r->tags[i]->tag, &conf.tag_font, cx, ty, ALIGN_HC, &conf.tag_color);
879 ty += get_sheight(r->tags[i]->tag, &conf.tag_font);
880 }
881 }
882
883 void draw_branch(gdImagePtr im, int cx, int ty, branch_t *b)
884 {
885 int lx = cx - b->w/2;
886 int rx = lx + b->w;
887 int yy;
888 int i;
889 /*draw_rbox(im, cx-b->tw/2-1, ty-1, cx+b->tw/2+1, ty+b->th+1, 0, &conf.title_color);*/
890 draw_rbox(im, lx, ty, rx, ty+b->h, 5, &conf.branch_color);
891 yy = conf.branch_tspace;
892 draw_string(im, b->branch->branch, &conf.branch_font, cx, ty+yy, ALIGN_HC, &conf.branch_color);
893 yy += get_sheight(b->branch->branch, &conf.branch_font);
894 for(i = 0; i < b->ntags; i++)
895 {
896 draw_string(im, b->tags[i]->tag, &conf.branch_font, cx, ty+yy, ALIGN_HC, &conf.branch_color);
897 yy += get_sheight(b->tags[i]->tag, &conf.branch_font);
898 }
899
900 ty += b->h;
901 for(i = 0; i < b->nrevs; i++)
902 {
903 gdImageLine(im, cx, ty, cx, ty+conf.rev_minline, conf.rev_color.id);
904 ty += conf.rev_minline;
905 draw_rev(im, cx, ty, b->revs[i]);
906 ty += b->revs[i]->h;
907 }
908 }
909
910 void draw_title(gdImagePtr im, char *title)
911 {
912 char *t;
913 char *s = title;
914 int x = conf.title_x;
915 int y = conf.title_y;
916 do
917 {
918 t = strchr(s, '\n');
919 if(t)
920 *t = '\0';
921 draw_string(im, s, &conf.title_font, x, y, conf.title_align, &conf.title_color);
922 y += get_sheight(s, &conf.title_font);
923 s = t+1;
924 } while(t);
925 }
926
927 void draw_connector(gdImagePtr im, branch_t *b)
928 {
929 revision_t *r = b->branchpoint;
930 int x1 = r->cx + r->w/2 + 2;
931 int y1 = r->y + r->h/2;
932 int x2 = b->cx;
933 int y2 = b->y;
934 gdImageLine(im, x1, y1, x2, y1, conf.branch_color.id);
935 gdImageLine(im, x2, y1, x2, y2, conf.branch_color.id);
936 }
937
938 gdImagePtr make_image(rcsfile_t *rcs)
939 {
940 gdImagePtr im;
941 int i;
942 char *cptr;
943
944 im = gdImageCreate(rcs->tw+conf.margin_left+conf.margin_right, rcs->th+conf.margin_top+conf.margin_bottom);
945 conf.color_bg.id = gdImageColorAllocate(im, conf.color_bg.r, conf.color_bg.g, conf.color_bg.b);
946 conf.tag_color.id = gdImageColorAllocate(im, conf.tag_color.r, conf.tag_color.g, conf.tag_color.b);
947 conf.rev_color.id = gdImageColorAllocate(im, conf.rev_color.r, conf.rev_color.g, conf.rev_color.b);
948 conf.branch_color.id = gdImageColorAllocate(im, conf.branch_color.r, conf.branch_color.g, conf.branch_color.b);
949 conf.branch_bgcolor.id = gdImageColorAllocate(im, conf.branch_bgcolor.r, conf.branch_bgcolor.g, conf.branch_bgcolor.b);
950 conf.title_color.id = gdImageColorAllocate(im, conf.title_color.r, conf.title_color.g, conf.title_color.b);
951
952 for(i = 0; i < rcs->nbranches; i++)
953 draw_branch(im, rcs->branches[i]->cx, rcs->branches[i]->y, rcs->branches[i]);
954 for(i = 0; i < rcs->nbranches; i++)
955 {
956 if(rcs->branches[i]->branchpoint)
957 draw_connector(im, rcs->branches[i]);
958 }
959 cptr = expand_string(conf.title, rcs, NULL, NULL);
960 draw_title(im, cptr);
961 xfree(cptr);
962
963 return im;
964 }
965
966 /*
967 **************************************************************************
968 * Layout routines
969 **************************************************************************
970 */
971 void move_branch(branch_t *b, int x, int y)
972 {
973 int i;
974 b->cx += x;
975 b->y += y;
976 for(i = 0; i < b->nrevs; i++)
977 {
978 b->revs[i]->cx += x;
979 b->revs[i]->y += y;
980 }
981 }
982
983 void reposition_branch(revision_t *r, int *x, int *w)
984 {
985 int i, j;
986 for(j = 0; j < r->nbranches; j++)
987 {
988 branch_t *b = r->branches[j];
989 *x += *w + conf.rev_minline + b->tw/2 - b->cx;
990 *w = b->tw/2;
991 move_branch(b, *x, r->y + r->h/2 + conf.branch_connect);
992 *x = b->cx;
993 /* Recurse to move branches of branched revisions */
994 for(i = b->nrevs-1; i >= 0; i--)
995 {
996 reposition_branch(b->revs[i], x, w);
997 }
998 }
999 }
1000
1001 void rect_union(int *x, int *y, int *w, int *h, branch_t *b)
1002 {
1003 int x1 = *x;
1004 int x2 = x1 + *w;
1005 int y1 = *y;
1006 int y2 = y1 + *h;
1007 int xx1 = b->cx - b->tw/2;
1008 int xx2 = xx1 + b->tw;
1009 int yy1 = b->y;
1010 int yy2 = yy1 + b->th;
1011 x1 = MIN(x1, xx1);
1012 x2 = MAX(x2, xx2);
1013 y1 = MIN(y1, yy1);
1014 y2 = MAX(y2, yy2);
1015 *x = x1;
1016 *y = y1;
1017 *w = x2 - x1;
1018 *h = y2 - y1;
1019 }
1020
1021 int branch_intersects(int top, int bottom, int left, branch_t *b)
1022 {
1023 int br = b->cx + b->tw/2;
1024 int bt = b->y - conf.branch_connect - conf.branch_margin/2;
1025 int bb = b->y + b->th + conf.branch_margin/2;
1026 return !(bt > bottom || bb < top || br >= left);
1027 }
1028
1029 int kern_branch(rcsfile_t *rcs, branch_t *b)
1030 {
1031 int left = b->cx - b->tw/2;
1032 int top = b->y - conf.branch_connect - conf.branch_margin/2;
1033 int bottom = b->y + b->th + conf.branch_margin/2;
1034 int i;
1035 int xpos = 0;
1036
1037 for(i = 0; i < rcs->nbranches; i++)
1038 {
1039 branch_t *bp = rcs->branches[i];
1040 if(bp == b)
1041 continue;
1042 if(branch_intersects(top, bottom, left, bp))
1043 {
1044 int m = bp->cx + bp->tw/2 + conf.branch_margin;
1045 if(m > xpos)
1046 xpos = m;
1047 }
1048 }
1049 if(xpos && (b->cx - b->tw/2) - xpos > 0)
1050 {
1051 move_branch(b, xpos - (b->cx - b->tw/2), 0);
1052 return 1;
1053 }
1054 return 0;
1055 }
1056
1057 void make_layout(rcsfile_t *rcs)
1058 {
1059 int i, j;
1060 int x, y;
1061 int w, h;
1062 int w2;
1063 int moved;
1064
1065 /* Calculate the box-sizes of the revisions */
1066 for(i = 0; i < rcs->nsrev; i++)
1067 {
1068 revision_t *rp;
1069 int w;
1070 int h;
1071 rp = rcs->srev[i];
1072 w = get_swidth(rp->rev->rev, &conf.rev_font);
1073 h = get_sheight(rp->rev->rev, &conf.rev_font);
1074 for(j = 0; j < rp->ntags; j++)
1075 {
1076 int ww = get_swidth(rp->tags[j]->tag, &conf.tag_font);
1077 if(ww > w) w = ww;
1078 h += get_sheight(rp->tags[j]->tag, &conf.tag_font) + conf.rev_separator;
1079 }
1080 rp->w = w + conf.rev_lspace + conf.rev_rspace;
1081 rp->h = h + conf.rev_tspace + conf.rev_bspace;
1082 }
1083
1084 /* Calculate the box-sizes of the branches */
1085 for(i = 0; i < rcs->nbranches; i++)
1086 {
1087 branch_t *bp = rcs->branches[i];
1088 int w;
1089 int h;
1090 w = get_swidth(bp->branch->branch, &conf.branch_font);
1091 h = get_sheight(bp->branch->branch, &conf.branch_font);
1092 for(j = 0; j < bp->ntags; j++)
1093 {
1094 int ww = get_swidth(bp->tags[j]->tag, &conf.branch_font);
1095 if(ww > w) w = ww;
1096 h += get_sheight(bp->tags[j]->tag, &conf.branch_font);
1097 }
1098 w += conf.branch_lspace + conf.branch_rspace;
1099 h += conf.branch_tspace + conf.branch_bspace;
1100 bp->w = w;
1101 bp->h = h;
1102 for(j = 0; j < bp->nrevs; j++)
1103 {
1104 if(bp->revs[j]->w > w)
1105 w = bp->revs[j]->w;
1106 h += bp->revs[j]->h + conf.rev_minline;
1107 }
1108 bp->th = h;
1109 bp->tw = w;
1110 }
1111
1112 /* Calculate the relative positions of revs in a branch */
1113 for(i = 0; i < rcs->nbranches; i++)
1114 {
1115 branch_t *b = rcs->branches[i];
1116 x = b->tw/2;
1117 y = b->h;
1118 b->cx = x;
1119 b->y = 0;
1120 for(j = 0; j < b->nrevs; j++)
1121 {
1122 y += conf.rev_minline;
1123 b->revs[j]->cx = x;
1124 b->revs[j]->y = y;
1125 y += b->revs[j]->h;
1126 }
1127 }
1128
1129 /* Reposition the branches */
1130 x = rcs->branches[0]->cx;
1131 w2 = rcs->branches[0]->tw / 2;
1132 for(i = rcs->branches[0]->nrevs-1; i >= 0; i--)
1133 {
1134 reposition_branch(rcs->branches[0]->revs[i], &x, &w2);
1135 }
1136
1137 /* Try to move branches left if there is room (kerning) */
1138 for(moved = 1; moved; )
1139 {
1140 moved = 0;
1141 for(i = 1; i < rcs->nbranches; i++)
1142 {
1143 moved += kern_branch(rcs, rcs->branches[i]);
1144 }
1145 }
1146
1147 /* Move everything w.r.t. the top-left margin */
1148 for(i = 0; i < rcs->nbranches; i++)
1149 move_branch(rcs->branches[i], conf.margin_left, conf.margin_top);
1150
1151 /* Calculate overall image size */
1152 x = rcs->branches[0]->cx - rcs->branches[0]->tw/2;
1153 y = rcs->branches[0]->y;
1154 w = rcs->branches[0]->tw;
1155 h = rcs->branches[0]->th;
1156 for(i = 1; i < rcs->nbranches; i++)
1157 rect_union(&x, &y, &w, &h, rcs->branches[i]);
1158 rcs->tw = w;
1159 rcs->th = h;
1160 }
1161
1162 /*
1163 **************************************************************************
1164 * Imagemap functions
1165 **************************************************************************
1166 */
1167 void make_imagemap(rcsfile_t *rcs, FILE *fp)
1168 {
1169 int i, j;
1170 char *href;
1171 char *alt;
1172 fprintf(fp, "<map name=\"%s\">\n", conf.map_name);
1173 for(i = 0; i < rcs->nbranches; i++)
1174 {
1175 branch_t *b = rcs->branches[i];
1176 tag_t *tag = b->ntags ? b->tags[0] : NULL;
1177 href = expand_string(conf.map_branch_href, rcs, b->branch, tag);
1178 alt = expand_string(conf.map_branch_alt, rcs, b->branch, tag);
1179 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s>\n",
1180 href,
1181 b->cx - b->w/2, b->y, b->cx + b->w/2, b->y + b->h,
1182 alt);
1183 xfree(href);
1184 xfree(alt);
1185 for(j = 0; j < b->nrevs; j++)
1186 {
1187 revision_t *r = b->revs[j];
1188 tag = r->ntags ? r->tags[0] : NULL;
1189 href = expand_string(conf.map_rev_href, rcs, r->rev, tag);
1190 alt = expand_string(conf.map_rev_alt, rcs, r->rev, tag);
1191 fprintf(fp, "\t<area shape=\"rect\" %s coords=\"%d,%d,%d,%d\" %s>\n",
1192 href,
1193 r->cx - r->w/2, r->y, r->cx + r->w/2, r->y + r->h,
1194 alt);
1195 xfree(href);
1196 xfree(alt);
1197 }
1198 }
1199 fprintf(fp, "</map>\n");
1200 }
1201
1202 /*
1203 **************************************************************************
1204 * Configuration
1205 **************************************************************************
1206 */
1207 int read_config(const char *path)
1208 {
1209 FILE *fp;
1210 int r;
1211
1212 if(path)
1213 {
1214 if((fp = fopen(path, "r")) == NULL)
1215 {
1216 return 0;
1217 }
1218 else
1219 input_file = path;
1220 }
1221 else
1222 {
1223 if((fp = fopen("./" CONFFILENAME, "r")) == NULL)
1224 {
1225 if((fp = fopen(ETCDIR "/" CONFFILENAME, "r")) == NULL)
1226 {
1227 return 0;
1228 }
1229 else
1230 input_file = ETCDIR "/" CONFFILENAME;
1231 }
1232 else
1233 input_file = "./" CONFFILENAME;
1234 }
1235
1236 yyin = fp;
1237 r = yyparse();
1238 fclose(fp);
1239 input_file = NULL;
1240 return r == 0;
1241 }
1242
1243 /*
1244 **************************************************************************
1245 * Program entry
1246 **************************************************************************
1247 */
1248 static const char usage_str[] =
1249 "Usage: cvsgraph [options] <file>\n"
1250 " -c <file> Read alternative config from <file>\n"
1251 " -d <level> Enable debug mode at <level>\n"
1252 " -h This message\n"
1253 " -i Generate an imagemap instead of image\n"
1254 " -M <name> Use <name> as imagemap name\n"
1255 " -m <mod> Use <mod> as cvs module\n"
1256 " -o <file> Output to <file>\n"
1257 " -q Be quiet (i.e. no warnings)\n"
1258 " -r <path> Use <path> as cvsroot path\n"
1259 " -V Print version and exit\n"
1260 " -[0-9] <txt> Use <txt> for expansion\n"
1261 ;
1262
1263 #define VERSION_STR "1.1.0"
1264 #define NOTICE_STR "Copyright (c) 2001 B.Stultiens"
1265
1266 int main(int argc, char *argv[])
1267 {
1268 extern int yy_flex_debug;
1269 extern int rcs_flex_debug;
1270 extern int yydebug;
1271 extern int rcsdebug;
1272 int optc;
1273 char *confpath = NULL;
1274 char *outfile = NULL;
1275 char *cvsroot = NULL;
1276 char *cvsmodule = NULL;
1277 int imagemap = 0;
1278 char *imgmapname = NULL;
1279 int lose = 0;
1280 FILE *fp;
1281 rcsfile_t *rcs;
1282 gdImagePtr im;
1283
1284 while((optc = getopt(argc, argv, "0:1:2:3:4:5:6:7:8:9:c:d:hiM:m:o:qr:V")) != EOF)
1285 {
1286 switch(optc)
1287 {
1288 case 'c':
1289 confpath = xstrdup(optarg);
1290 break;
1291 case 'd':
1292 debuglevel = strtol(optarg, NULL, 0);
1293 break;
1294 case 'i':
1295 imagemap = 1;
1296 break;
1297 case 'M':
1298 imgmapname = xstrdup(optarg);
1299 break;
1300 case 'm':
1301 cvsmodule = xstrdup(optarg);
1302 break;
1303 case 'o':
1304 outfile = xstrdup(optarg);
1305 break;
1306 case 'q':
1307 quiet = 1;
1308 break;
1309 case 'r':
1310 cvsroot = xstrdup(optarg);
1311 break;
1312 case 'V':
1313 fprintf(stdout, "cvsgraph v%s, %s\n", VERSION_STR, NOTICE_STR);
1314 return 0;
1315 case 'h':
1316 fprintf(stdout, "%s", usage_str);
1317 return 0;
1318 default:
1319 if(isdigit(optc))
1320 {
1321 conf.expand[optc-'0'] = xstrdup(optarg);
1322 }
1323 else
1324 lose++;
1325 }
1326 }
1327
1328 if(optind >= argc)
1329 {
1330 fprintf(stderr, "Missing inputfile\n");
1331 lose++;
1332 }
1333
1334 if(lose)
1335 {
1336 fprintf(stderr, "%s", usage_str);
1337 return 1;
1338 }
1339
1340 if(debuglevel)
1341 {
1342 setvbuf(stdout, NULL, 0, _IONBF);
1343 setvbuf(stderr, NULL, 0, _IONBF);
1344 }
1345 yy_flex_debug = (debuglevel & DEBUG_CONF_LEX) != 0;
1346 rcs_flex_debug = (debuglevel & DEBUG_RCS_LEX) != 0;
1347 yydebug = (debuglevel & DEBUG_CONF_YACC) != 0;
1348 rcsdebug = (debuglevel & DEBUG_RCS_YACC) != 0;
1349
1350 /* Set defaults */
1351 if(!conf.tag_font) conf.tag_font = gdFontTiny;
1352 if(!conf.rev_font) conf.rev_font = gdFontTiny;
1353 if(!conf.branch_font) conf.branch_font = gdFontTiny;
1354 if(!conf.title_font) conf.title_font = gdFontTiny;
1355
1356 if(!read_config(confpath))
1357 {
1358 fprintf(stderr, "Error reading config file\n");
1359 return 1;
1360 }
1361
1362 /* Set overrides */
1363 if(cvsroot) conf.cvsroot = cvsroot;
1364 if(cvsmodule) conf.cvsmodule = cvsmodule;
1365 if(imgmapname) conf.map_name = imgmapname;
1366
1367 rcs = get_rcsfile(conf.cvsroot, conf.cvsmodule, argv[optind]);
1368 if(!rcs)
1369 {
1370 fprintf(stderr, "Error reading rcs-file\n");
1371 return 1;
1372 }
1373
1374 if(debuglevel & DEBUG_RCS_FILE)
1375 dump_rcsfile(rcs);
1376
1377 if(!reorganise_branches(rcs))
1378 return 1;
1379
1380 if(!assign_tags(rcs))
1381 return 1;
1382
1383 if(outfile)
1384 {
1385 if((fp = fopen(outfile, "w")) == NULL)
1386 {
1387 perror(outfile);
1388 return 1;
1389 }
1390 }
1391 else
1392 fp = stdout;
1393
1394 make_layout(rcs);
1395
1396 if(!imagemap)
1397 {
1398 /* Create an image */
1399 im = make_image(rcs);
1400
1401 switch(conf.image_type)
1402 {
1403 #ifdef HAVE_IMAGE_GIF
1404 # ifndef HAVE_IMAGE_PNG
1405 default:
1406 # endif
1407 case IMAGE_GIF:
1408 gdImageGif(im, fp);
1409 break;
1410 #endif
1411 #ifdef HAVE_IMAGE_PNG
1412 default:
1413 case IMAGE_PNG:
1414 gdImagePng(im, fp);
1415 break;
1416 #endif
1417 #ifdef HAVE_IMAGE_JPEG
1418 # if !defined(HAVE_IMAGE_GIF) && !defined(HAVE_IMAGE_PNG)
1419 default:
1420 # endif
1421 case IMAGE_JPEG:
1422 gdImageJpeg(im, fp, conf.image_quality);
1423 break;
1424 #endif
1425 }
1426
1427 gdImageDestroy(im);
1428 }
1429 else
1430 {
1431 /* Create an imagemap */
1432 make_imagemap(rcs, fp);
1433 }
1434
1435 if(outfile)
1436 fclose(fp);
1437
1438 return 0;
1439 }

  ViewVC Help
Powered by ViewVC 1.1.0 with CvsGraph 1.7.0