1 |
|
/* |
2 |
< |
* Copyright (C) 1984-2012 Mark Nudelman |
2 |
> |
* Copyright (C) 1984-2017 Mark Nudelman |
3 |
|
* |
4 |
|
* You may distribute under the terms of either the GNU General Public |
5 |
|
* License or the Less License, as specified in the README file. |
14 |
|
|
15 |
|
#if TAGS |
16 |
|
|
17 |
< |
public char *tags = "tags"; |
17 |
> |
public char ztags[] = "tags"; |
18 |
> |
public char *tags = ztags; |
19 |
|
|
20 |
|
static int total; |
21 |
|
static int curseq; |
22 |
|
|
23 |
|
extern int linenums; |
24 |
|
extern int sigs; |
25 |
+ |
extern int ctldisp; |
26 |
|
|
27 |
|
enum tag_result { |
28 |
|
TAG_FOUND, |
64 |
|
struct tag *tl_first; |
65 |
|
struct tag *tl_last; |
66 |
|
}; |
65 |
– |
#define TAG_END ((struct tag *) &taglist) |
66 |
– |
static struct taglist taglist = { TAG_END, TAG_END }; |
67 |
|
struct tag { |
68 |
|
struct tag *next, *prev; /* List links */ |
69 |
|
char *tag_file; /* Source file containing the tag */ |
71 |
|
char *tag_pattern; /* Pattern used to find the tag */ |
72 |
|
char tag_endline; /* True if the pattern includes '$' */ |
73 |
|
}; |
74 |
+ |
#define TAG_END ((struct tag *) &taglist) |
75 |
+ |
static struct taglist taglist = { TAG_END, TAG_END }; |
76 |
|
static struct tag *curtag; |
77 |
|
|
78 |
|
#define TAG_INS(tp) \ |
91 |
|
public void |
92 |
|
cleantags() |
93 |
|
{ |
94 |
< |
register struct tag *tp; |
94 |
> |
struct tag *tp; |
95 |
|
|
96 |
|
/* |
97 |
|
* Delete any existing tag list. |
101 |
|
while ((tp = taglist.tl_first) != TAG_END) |
102 |
|
{ |
103 |
|
TAG_RM(tp); |
104 |
+ |
free(tp->tag_file); |
105 |
+ |
free(tp->tag_pattern); |
106 |
|
free(tp); |
107 |
|
} |
108 |
|
curtag = NULL; |
120 |
|
char *pattern; |
121 |
|
int endline; |
122 |
|
{ |
123 |
< |
register struct tag *tp; |
123 |
> |
struct tag *tp; |
124 |
|
|
125 |
|
tp = (struct tag *) ecalloc(sizeof(struct tag), 1); |
126 |
|
tp->tag_file = (char *) ecalloc(strlen(file) + 1, sizeof(char)); |
173 |
|
*/ |
174 |
|
public void |
175 |
|
findtag(tag) |
176 |
< |
register char *tag; |
176 |
> |
char *tag; |
177 |
|
{ |
178 |
|
int type = gettagtype(); |
179 |
|
enum tag_result result; |
269 |
|
*/ |
270 |
|
static enum tag_result |
271 |
|
findctag(tag) |
272 |
< |
register char *tag; |
272 |
> |
char *tag; |
273 |
|
{ |
274 |
|
char *p; |
275 |
< |
register FILE *f; |
276 |
< |
register int taglen; |
275 |
> |
FILE *f; |
276 |
> |
int taglen; |
277 |
|
LINENUM taglinenum; |
278 |
|
char *tagfile; |
279 |
|
char *tagpattern; |
291 |
|
|
292 |
|
cleantags(); |
293 |
|
total = 0; |
294 |
< |
taglen = strlen(tag); |
294 |
> |
taglen = (int) strlen(tag); |
295 |
|
|
296 |
|
/* |
297 |
|
* Search the tags file for the desired tag. |
387 |
|
return (edit(curtag->tag_file)); |
388 |
|
} |
389 |
|
|
390 |
+ |
static int |
391 |
+ |
curtag_match(char const *line, POSITION linepos) |
392 |
+ |
{ |
393 |
+ |
/* |
394 |
+ |
* Test the line to see if we have a match. |
395 |
+ |
* Use strncmp because the pattern may be |
396 |
+ |
* truncated (in the tags file) if it is too long. |
397 |
+ |
* If tagendline is set, make sure we match all |
398 |
+ |
* the way to end of line (no extra chars after the match). |
399 |
+ |
*/ |
400 |
+ |
int len = (int) strlen(curtag->tag_pattern); |
401 |
+ |
if (strncmp(curtag->tag_pattern, line, len) == 0 && |
402 |
+ |
(!curtag->tag_endline || line[len] == '\0' || line[len] == '\r')) |
403 |
+ |
{ |
404 |
+ |
curtag->tag_linenum = find_linenum(linepos); |
405 |
+ |
return 1; |
406 |
+ |
} |
407 |
+ |
return 0; |
408 |
+ |
} |
409 |
+ |
|
410 |
|
/* |
411 |
|
* Search for a tag. |
412 |
|
* This is a stripped-down version of search(). |
421 |
|
{ |
422 |
|
POSITION pos, linepos; |
423 |
|
LINENUM linenum; |
424 |
< |
int len; |
424 |
> |
int line_len; |
425 |
|
char *line; |
426 |
+ |
int found; |
427 |
|
|
428 |
|
pos = ch_zero(); |
429 |
|
linenum = find_linenum(pos); |
430 |
|
|
431 |
< |
for (;;) |
431 |
> |
for (found = 0; !found;) |
432 |
|
{ |
433 |
|
/* |
434 |
|
* Get lines until we find a matching one or |
442 |
|
* starting position of that line in linepos. |
443 |
|
*/ |
444 |
|
linepos = pos; |
445 |
< |
pos = forw_raw_line(pos, &line, (int *)NULL); |
445 |
> |
pos = forw_raw_line(pos, &line, &line_len); |
446 |
|
if (linenum != 0) |
447 |
|
linenum++; |
448 |
|
|
463 |
|
if (linenums) |
464 |
|
add_lnum(linenum, pos); |
465 |
|
|
466 |
< |
/* |
442 |
< |
* Test the line to see if we have a match. |
443 |
< |
* Use strncmp because the pattern may be |
444 |
< |
* truncated (in the tags file) if it is too long. |
445 |
< |
* If tagendline is set, make sure we match all |
446 |
< |
* the way to end of line (no extra chars after the match). |
447 |
< |
*/ |
448 |
< |
len = strlen(curtag->tag_pattern); |
449 |
< |
if (strncmp(curtag->tag_pattern, line, len) == 0 && |
450 |
< |
(!curtag->tag_endline || line[len] == '\0' || line[len] == '\r')) |
466 |
> |
if (ctldisp != OPT_ONPLUS) |
467 |
|
{ |
468 |
< |
curtag->tag_linenum = find_linenum(linepos); |
469 |
< |
break; |
468 |
> |
if (curtag_match(line, linepos)) |
469 |
> |
found = 1; |
470 |
> |
} else |
471 |
> |
{ |
472 |
> |
int cvt_ops = CVT_ANSI; |
473 |
> |
int cvt_len = cvt_length(line_len, cvt_ops); |
474 |
> |
int *chpos = cvt_alloc_chpos(cvt_len); |
475 |
> |
char *cline = (char *) ecalloc(1, cvt_len); |
476 |
> |
cvt_text(cline, line, chpos, &line_len, cvt_ops); |
477 |
> |
if (curtag_match(cline, linepos)) |
478 |
> |
found = 1; |
479 |
> |
free(chpos); |
480 |
> |
free(cline); |
481 |
|
} |
482 |
|
} |
483 |
|
|
518 |
|
{ |
519 |
|
fp = stdin; |
520 |
|
/* Set tag default because we cannot read stdin again. */ |
521 |
< |
tags = "tags"; |
521 |
> |
tags = ztags; |
522 |
|
} else |
523 |
|
{ |
524 |
|
#if !HAVE_POPEN |
578 |
|
#endif |
579 |
|
return TAG_INTR; |
580 |
|
} |
581 |
< |
len = strlen(buf); |
581 |
> |
len = (int) strlen(buf); |
582 |
|
if (len > 0 && buf[len-1] == '\n') |
583 |
|
buf[len-1] = '\0'; |
584 |
|
else |