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