* Copyright (c) 1988 Mark Nudleman
* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Mark Nudleman and the University of California, Berkeley. The
* name of Mark Nudleman or the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)tags.c 5.3 (Berkeley) %G%";
#define WHITESP(c) ((c)==' ' || (c)=='\t')
static char *tags
= "tags";
* Find a tag in the "tags" file.
* Sets "tagfile" to the name of the file containing the tag,
* and "tagpattern" to the search pattern which should be used
if ((f
= fopen(tags
, "r")) == NULL
)
* Search the tags file for the desired tag.
while (fgets(tline
, sizeof(tline
), f
) != NULL
)
if (strncmp(tag
, tline
, taglen
) != 0 || !WHITESP(tline
[taglen
]))
* The line contains the tag, the filename and the
* pattern, separated by white space.
* The pattern is surrounded by a pair of identical
* Parse the line and extract these parts.
tagfile
= tagpattern
= NULL
;
* Skip over the whitespace after the tag name.
for (p
= tline
; !WHITESP(*p
) && *p
!= '\0'; p
++)
/* File name is missing! */
* Skip over the whitespace after the file name.
while (!WHITESP(*p
) && *p
!= '\0')
/* Pattern is missing! */
* Skip to the end of the pattern.
* Delete the initial "^" and the final "$" from the pattern.
while (*p
!= search_char
&& *p
!= '\0')
error("No such tag in tags file");
* This is a stripped-down version of search().
* We don't use search() for several reasons:
* - We don't want to blow away any search string we may have saved.
* - The various regular-expression functions (from different systems:
* regcmp vs. re_comp) behave differently in the presence of
* parentheses (which are almost always found in a tag).
linenum
= find_linenum(pos
);
* Get lines until we find a matching one or
* until we hit end-of-file.
* Read the next line, and save the
* starting position of that line in linepos.
pos
= forw_raw_line(pos
);
if (pos
== NULL_POSITION
)
* We hit EOF without a match.
* If we're using line numbers, we might as well
* remember the information we have now (the position
* and line number of the current line).
* Test the line to see if we have a match.
if (strcmp(tagpattern
, line
) == 0)