4 #define WHITESP(c) ((c)==' ' || (c)=='\t')
9 public char *tagpattern;
11 public char *tags = "tags";
15 extern int jump_sline;
18 * Find a tag in the "tags" file.
19 * Sets "tagfile" to the name of the file containing the tag,
20 * and "tagpattern" to the search pattern which should be used
31 static char tline[200];
33 if ((f = fopen(tags, "r")) == NULL)
35 error("No tags file", NULL_PARG);
43 * Search the tags file for the desired tag.
45 while (fgets(tline, sizeof(tline), f) != NULL)
47 if (strncmp(tag, tline, taglen) != 0 || !WHITESP(tline[taglen]))
52 * The line contains the tag, the filename and the
53 * pattern, separated by white space.
54 * The pattern is surrounded by a pair of identical
56 * Parse the line and extract these parts.
58 tagfile = tagpattern = NULL;
61 * Skip over the whitespace after the tag name.
63 for (p = tline; !WHITESP(*p) && *p != '\0'; p++)
68 /* File name is missing! */
73 * Skip over the whitespace after the file name.
76 while (!WHITESP(*p) && *p != '\0')
82 /* Pattern is missing! */
87 * Skip to the end of the pattern.
88 * Delete the initial "^" and the final "$" from the pattern.
94 while (*p != search_char && *p != '\0')
104 error("No such tag in tags file", NULL_PARG);
110 * This is a stripped-down version of search().
111 * We don't use search() for several reasons:
112 * - We don't want to blow away any search string we may have saved.
113 * - The various regular-expression functions (from different systems:
114 * regcmp vs. re_comp) behave differently in the presence of
115 * parentheses (which are almost always found in a tag).
120 POSITION pos, linepos;
125 linenum = find_linenum(pos);
130 * Get lines until we find a matching one or
131 * until we hit end-of-file.
137 * Read the next line, and save the
138 * starting position of that line in linepos.
141 pos = forw_raw_line(pos, &line);
145 if (pos == NULL_POSITION)
148 * We hit EOF without a match.
150 error("Tag not found", NULL_PARG);
155 * If we're using line numbers, we might as well
156 * remember the information we have now (the position
157 * and line number of the current line).
160 add_lnum(linenum, pos);
163 * Test the line to see if we have a match.
164 * Use strncmp because the pattern may be
165 * truncated (in the tags file) if it is too long.
167 if (strncmp(tagpattern, line, strlen(tagpattern)) == 0)
171 jump_loc(linepos, jump_sline);