Commit | Line | Data |
---|---|---|
70f42695 | 1 | /* |
374464e3 KB |
2 | * Copyright (c) 1987, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
ffa8a268 | 4 | * |
a3bb5b82 | 5 | * %sccs.include.redist.c% |
70f42695 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
d3acad8d | 9 | static char sccsid[] = "@(#)print.c 8.2 (Berkeley) %G%"; |
ffa8a268 | 10 | #endif /* not lint */ |
70f42695 | 11 | |
d3acad8d | 12 | #include <limits.h> |
6c2ce1d3 KB |
13 | #include <stdio.h> |
14 | #include <stdlib.h> | |
15 | #include <string.h> | |
d3acad8d | 16 | #include <unistd.h> |
70f42695 | 17 | |
d3acad8d | 18 | #include "ctags.h" |
70f42695 KB |
19 | |
20 | /* | |
21 | * getline -- | |
22 | * get the line the token of interest occurred on, | |
23 | * prepare it for printing. | |
24 | */ | |
d3acad8d | 25 | void |
70f42695 KB |
26 | getline() |
27 | { | |
d3acad8d JSP |
28 | long saveftell; |
29 | int c; | |
30 | int cnt; | |
31 | char *cp; | |
70f42695 KB |
32 | |
33 | saveftell = ftell(inf); | |
d3acad8d | 34 | (void)fseek(inf, lineftell, L_SET); |
70f42695 | 35 | if (xflag) |
d3acad8d JSP |
36 | for (cp = lbuf; GETC(!=, '\n'); *cp++ = c) |
37 | continue; | |
70f42695 KB |
38 | /* |
39 | * do all processing here, so we don't step through the | |
40 | * line more than once; means you don't call this routine | |
41 | * unless you're sure you've got a keeper. | |
42 | */ | |
d3acad8d JSP |
43 | else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) { |
44 | if (c == '\\') { /* backslashes */ | |
70f42695 KB |
45 | if (cnt > ENDLINE - 2) |
46 | break; | |
47 | *cp++ = '\\'; *cp++ = '\\'; | |
48 | ++cnt; | |
49 | } | |
50 | else if (c == (int)searchar) { /* search character */ | |
51 | if (cnt > ENDLINE - 2) | |
52 | break; | |
53 | *cp++ = '\\'; *cp++ = c; | |
54 | ++cnt; | |
55 | } | |
d3acad8d | 56 | else if (c == '\n') { /* end of keep */ |
70f42695 KB |
57 | *cp++ = '$'; /* can find whole line */ |
58 | break; | |
59 | } | |
60 | else | |
61 | *cp++ = c; | |
62 | } | |
63 | *cp = EOS; | |
d3acad8d | 64 | (void)fseek(inf, saveftell, L_SET); |
70f42695 KB |
65 | } |
66 | ||
67 | /* | |
68 | * put_entries -- | |
69 | * write out the tags | |
70 | */ | |
d3acad8d | 71 | void |
70f42695 | 72 | put_entries(node) |
d3acad8d | 73 | NODE *node; |
70f42695 | 74 | { |
70f42695 KB |
75 | |
76 | if (node->left) | |
77 | put_entries(node->left); | |
78 | if (vflag) | |
79 | printf("%s %s %d\n", | |
d3acad8d | 80 | node->entry, node->file, (node->lno + 63) / 64); |
70f42695 KB |
81 | else if (xflag) |
82 | printf("%-16s%4d %-16s %s\n", | |
d3acad8d | 83 | node->entry, node->lno, node->file, node->pat); |
70f42695 | 84 | else |
d3acad8d JSP |
85 | fprintf(outf, "%s\t%s\t%c^%s%c\n", |
86 | node->entry, node->file, searchar, node->pat, searchar); | |
70f42695 KB |
87 | if (node->right) |
88 | put_entries(node->right); | |
89 | } |