ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/src/vendor/less/dist/tags.c
(Generate patch)

Comparing vendor/less/dist/tags.c (file contents):
Revision 11359 by laffer1, Sun Dec 1 02:26:57 2013 UTC vs.
Revision 11360 by laffer1, Fri Jul 6 12:43:09 2018 UTC

# Line 1 | Line 1
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.
# Line 14 | Line 14
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,
# Line 62 | Line 64 | struct taglist {
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 */
# Line 71 | Line 71 | struct 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) \
# Line 89 | Line 91 | static struct tag *curtag;
91          public void
92   cleantags()
93   {
94 <        register struct tag *tp;
94 >        struct tag *tp;
95  
96          /*
97           * Delete any existing tag list.
# Line 99 | Line 101 | cleantags()
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;
# Line 116 | Line 120 | maketagent(name, file, linenum, pattern, endline)
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));
# Line 169 | Line 173 | gettagtype()
173   */
174          public void
175   findtag(tag)
176 <        register char *tag;
176 >        char *tag;
177   {
178          int type = gettagtype();
179          enum tag_result result;
# Line 265 | Line 269 | curr_tag()
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;
# Line 287 | Line 291 | findctag(tag)
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.
# Line 383 | Line 387 | edit_tagfile()
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().
# Line 397 | Line 421 | ctagsearch()
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
# Line 417 | Line 442 | ctagsearch()
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  
# Line 438 | Line 463 | ctagsearch()
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  
# Line 491 | Line 518 | findgtag(tag, type)
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
# Line 551 | Line 578 | findgtag(tag, type)
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines