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