Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/less/tags.c
Show All 37 Lines | enum { | ||||
T_CTAGS, /* 'tags': standard and extended format (ctags) */ | T_CTAGS, /* 'tags': standard and extended format (ctags) */ | ||||
T_CTAGS_X, /* stdin: cross reference format (ctags) */ | T_CTAGS_X, /* stdin: cross reference format (ctags) */ | ||||
T_GTAGS, /* 'GTAGS': function defenition (global) */ | T_GTAGS, /* 'GTAGS': function defenition (global) */ | ||||
T_GRTAGS, /* 'GRTAGS': function reference (global) */ | T_GRTAGS, /* 'GRTAGS': function reference (global) */ | ||||
T_GSYMS, /* 'GSYMS': other symbols (global) */ | T_GSYMS, /* 'GSYMS': other symbols (global) */ | ||||
T_GPATH /* 'GPATH': path name (global) */ | T_GPATH /* 'GPATH': path name (global) */ | ||||
}; | }; | ||||
static enum tag_result findctag(); | static enum tag_result findctag(char *tag); | ||||
static enum tag_result findgtag(); | static enum tag_result findgtag(char *tag, int type); | ||||
static char *nextgtag(); | static char *nextgtag(void); | ||||
static char *prevgtag(); | static char *prevgtag(void); | ||||
static POSITION ctagsearch(); | static POSITION ctagsearch(void); | ||||
static POSITION gtagsearch(); | static POSITION gtagsearch(void); | ||||
static int getentry(); | static int getentry(char *buf, char **tag, char **file, char **line); | ||||
/* | /* | ||||
* The list of tags generated by the last findgtag() call. | * The list of tags generated by the last findgtag() call. | ||||
* | * | ||||
* Use either pattern or line number. | * Use either pattern or line number. | ||||
* findgtag() always uses line number, so pattern is always NULL. | * findgtag() always uses line number, so pattern is always NULL. | ||||
* findctag() uses either pattern (in which case line number is 0), | * findctag() uses either pattern (in which case line number is 0), | ||||
* or line number (in which case pattern is NULL). | * or line number (in which case pattern is NULL). | ||||
Show All 22 Lines | |||||
#define TAG_RM(tp) \ | #define TAG_RM(tp) \ | ||||
(tp)->next->prev = (tp)->prev; \ | (tp)->next->prev = (tp)->prev; \ | ||||
(tp)->prev->next = (tp)->next; | (tp)->prev->next = (tp)->next; | ||||
/* | /* | ||||
* Delete tag structures. | * Delete tag structures. | ||||
*/ | */ | ||||
public void | public void | ||||
cleantags() | cleantags(void) | ||||
{ | { | ||||
register struct tag *tp; | struct tag *tp; | ||||
/* | /* | ||||
* Delete any existing tag list. | * Delete any existing tag list. | ||||
* {{ Ideally, we wouldn't do this until after we know that we | * {{ Ideally, we wouldn't do this until after we know that we | ||||
* can load some other tag information. }} | * can load some other tag information. }} | ||||
*/ | */ | ||||
while ((tp = taglist.tl_first) != TAG_END) | while ((tp = taglist.tl_first) != TAG_END) | ||||
{ | { | ||||
TAG_RM(tp); | TAG_RM(tp); | ||||
free(tp); | free(tp); | ||||
} | } | ||||
curtag = NULL; | curtag = NULL; | ||||
total = curseq = 0; | total = curseq = 0; | ||||
} | } | ||||
/* | /* | ||||
* Create a new tag entry. | * Create a new tag entry. | ||||
*/ | */ | ||||
static struct tag * | static struct tag * | ||||
maketagent(name, file, linenum, pattern, endline) | maketagent(char *name, char *file, LINENUM linenum, char *pattern, int endline) | ||||
char *name; | |||||
char *file; | |||||
LINENUM linenum; | |||||
char *pattern; | |||||
int endline; | |||||
{ | { | ||||
register struct tag *tp; | struct tag *tp; | ||||
tp = (struct tag *) ecalloc(sizeof(struct tag), 1); | tp = (struct tag *) ecalloc(sizeof(struct tag), 1); | ||||
tp->tag_file = (char *) ecalloc(strlen(file) + 1, sizeof(char)); | tp->tag_file = (char *) ecalloc(strlen(file) + 1, sizeof(char)); | ||||
strcpy(tp->tag_file, file); | strcpy(tp->tag_file, file); | ||||
tp->tag_linenum = linenum; | tp->tag_linenum = linenum; | ||||
tp->tag_endline = endline; | tp->tag_endline = endline; | ||||
if (pattern == NULL) | if (pattern == NULL) | ||||
tp->tag_pattern = NULL; | tp->tag_pattern = NULL; | ||||
else | else | ||||
{ | { | ||||
tp->tag_pattern = (char *) ecalloc(strlen(pattern) + 1, sizeof(char)); | tp->tag_pattern = (char *) ecalloc(strlen(pattern) + 1, sizeof(char)); | ||||
strcpy(tp->tag_pattern, pattern); | strcpy(tp->tag_pattern, pattern); | ||||
} | } | ||||
return (tp); | return (tp); | ||||
} | } | ||||
/* | /* | ||||
* Get tag mode. | * Get tag mode. | ||||
*/ | */ | ||||
public int | public int | ||||
gettagtype() | gettagtype(void) | ||||
{ | { | ||||
int f; | int f; | ||||
if (strcmp(tags, "GTAGS") == 0) | if (strcmp(tags, "GTAGS") == 0) | ||||
return T_GTAGS; | return T_GTAGS; | ||||
if (strcmp(tags, "GRTAGS") == 0) | if (strcmp(tags, "GRTAGS") == 0) | ||||
return T_GRTAGS; | return T_GRTAGS; | ||||
if (strcmp(tags, "GSYMS") == 0) | if (strcmp(tags, "GSYMS") == 0) | ||||
Show All 14 Lines | |||||
/* | /* | ||||
* Find tags in tag file. | * Find tags in tag file. | ||||
* Find a tag in the "tags" file. | * Find a tag in the "tags" file. | ||||
* Sets "tag_file" to the name of the file containing the tag, | * Sets "tag_file" to the name of the file containing the tag, | ||||
* and "tagpattern" to the search pattern which should be used | * and "tagpattern" to the search pattern which should be used | ||||
* to find the tag. | * to find the tag. | ||||
*/ | */ | ||||
public void | public void | ||||
findtag(tag) | findtag(char *tag) | ||||
register char *tag; | |||||
{ | { | ||||
int type = gettagtype(); | int type = gettagtype(); | ||||
enum tag_result result; | enum tag_result result; | ||||
if (type == T_CTAGS) | if (type == T_CTAGS) | ||||
result = findctag(tag); | result = findctag(tag); | ||||
else | else | ||||
result = findgtag(tag, type); | result = findgtag(tag, type); | ||||
Show All 13 Lines | case TAG_NOTYPE: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Search for a tag. | * Search for a tag. | ||||
*/ | */ | ||||
public POSITION | public POSITION | ||||
tagsearch() | tagsearch(void) | ||||
{ | { | ||||
if (curtag == NULL) | if (curtag == NULL) | ||||
return (NULL_POSITION); /* No gtags loaded! */ | return (NULL_POSITION); /* No gtags loaded! */ | ||||
if (curtag->tag_linenum != 0) | if (curtag->tag_linenum != 0) | ||||
return gtagsearch(); | return gtagsearch(); | ||||
else | else | ||||
return ctagsearch(); | return ctagsearch(); | ||||
} | } | ||||
/* | /* | ||||
* Go to the next tag. | * Go to the next tag. | ||||
*/ | */ | ||||
public char * | public char * | ||||
nexttag(n) | nexttag(int n) | ||||
int n; | |||||
{ | { | ||||
char *tagfile = (char *) NULL; | char *tagfile = (char *) NULL; | ||||
while (n-- > 0) | while (n-- > 0) | ||||
tagfile = nextgtag(); | tagfile = nextgtag(); | ||||
return tagfile; | return tagfile; | ||||
} | } | ||||
/* | /* | ||||
* Go to the previous tag. | * Go to the previous tag. | ||||
*/ | */ | ||||
public char * | public char * | ||||
prevtag(n) | prevtag(int n) | ||||
int n; | |||||
{ | { | ||||
char *tagfile = (char *) NULL; | char *tagfile = (char *) NULL; | ||||
while (n-- > 0) | while (n-- > 0) | ||||
tagfile = prevgtag(); | tagfile = prevgtag(); | ||||
return tagfile; | return tagfile; | ||||
} | } | ||||
/* | /* | ||||
* Return the total number of tags. | * Return the total number of tags. | ||||
*/ | */ | ||||
public int | public int | ||||
ntags() | ntags(void) | ||||
{ | { | ||||
return total; | return total; | ||||
} | } | ||||
/* | /* | ||||
* Return the sequence number of current tag. | * Return the sequence number of current tag. | ||||
*/ | */ | ||||
public int | public int | ||||
curr_tag() | curr_tag(void) | ||||
{ | { | ||||
return curseq; | return curseq; | ||||
} | } | ||||
/***************************************************************************** | /***************************************************************************** | ||||
* ctags | * ctags | ||||
*/ | */ | ||||
/* | /* | ||||
* Find tags in the "tags" file. | * Find tags in the "tags" file. | ||||
* Sets curtag to the first tag entry. | * Sets curtag to the first tag entry. | ||||
*/ | */ | ||||
static enum tag_result | static enum tag_result | ||||
findctag(tag) | findctag(char *tag) | ||||
register char *tag; | |||||
{ | { | ||||
char *p; | char *p; | ||||
register FILE *f; | FILE *f; | ||||
register int taglen; | int taglen; | ||||
LINENUM taglinenum; | LINENUM taglinenum; | ||||
char *tagfile; | char *tagfile; | ||||
char *tagpattern; | char *tagpattern; | ||||
int tagendline; | int tagendline; | ||||
int search_char; | int search_char; | ||||
int err; | int err; | ||||
char tline[TAGLINE_SIZE]; | char tline[TAGLINE_SIZE]; | ||||
struct tag *tp; | struct tag *tp; | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | findctag(char *tag) | ||||
curseq = 1; | curseq = 1; | ||||
return TAG_FOUND; | return TAG_FOUND; | ||||
} | } | ||||
/* | /* | ||||
* Edit current tagged file. | * Edit current tagged file. | ||||
*/ | */ | ||||
public int | public int | ||||
edit_tagfile() | edit_tagfile(void) | ||||
{ | { | ||||
if (curtag == NULL) | if (curtag == NULL) | ||||
return (1); | return (1); | ||||
return (edit(curtag->tag_file)); | return (edit(curtag->tag_file)); | ||||
} | } | ||||
/* | /* | ||||
* Search for a tag. | * Search for a tag. | ||||
* This is a stripped-down version of search(). | * This is a stripped-down version of search(). | ||||
* We don't use search() for several reasons: | * We don't use search() for several reasons: | ||||
* - We don't want to blow away any search string we may have saved. | * - We don't want to blow away any search string we may have saved. | ||||
* - The various regular-expression functions (from different systems: | * - The various regular-expression functions (from different systems: | ||||
* regcmp vs. re_comp) behave differently in the presence of | * regcmp vs. re_comp) behave differently in the presence of | ||||
* parentheses (which are almost always found in a tag). | * parentheses (which are almost always found in a tag). | ||||
*/ | */ | ||||
static POSITION | static POSITION | ||||
ctagsearch() | ctagsearch(void) | ||||
{ | { | ||||
POSITION pos, linepos; | POSITION pos, linepos; | ||||
LINENUM linenum; | LINENUM linenum; | ||||
int len; | int len; | ||||
char *line; | char *line; | ||||
pos = ch_zero(); | pos = ch_zero(); | ||||
linenum = find_linenum(pos); | linenum = find_linenum(pos); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Find tags in the GLOBAL's tag file. | * Find tags in the GLOBAL's tag file. | ||||
* The findgtag() will try and load information about the requested tag. | * The findgtag() will try and load information about the requested tag. | ||||
* It does this by calling "global -x tag" and storing the parsed output | * It does this by calling "global -x tag" and storing the parsed output | ||||
* for future use by gtagsearch(). | * for future use by gtagsearch(). | ||||
* Sets curtag to the first tag entry. | * Sets curtag to the first tag entry. | ||||
*/ | */ | ||||
static enum tag_result | static enum tag_result | ||||
findgtag(tag, type) | findgtag(char *tag, int type) | ||||
char *tag; /* tag to load */ | |||||
int type; /* tags type */ | |||||
{ | { | ||||
char buf[256]; | char buf[256]; | ||||
FILE *fp; | FILE *fp; | ||||
struct tag *tp; | struct tag *tp; | ||||
if (type != T_CTAGS_X && tag == NULL) | if (type != T_CTAGS_X && tag == NULL) | ||||
return TAG_NOFILE; | return TAG_NOFILE; | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | |||||
static int circular = 0; /* 1: circular tag structure */ | static int circular = 0; /* 1: circular tag structure */ | ||||
/* | /* | ||||
* Return the filename required for the next gtag in the queue that was setup | * Return the filename required for the next gtag in the queue that was setup | ||||
* by findgtag(). The next call to gtagsearch() will try to position at the | * by findgtag(). The next call to gtagsearch() will try to position at the | ||||
* appropriate tag. | * appropriate tag. | ||||
*/ | */ | ||||
static char * | static char * | ||||
nextgtag() | nextgtag(void) | ||||
{ | { | ||||
struct tag *tp; | struct tag *tp; | ||||
if (curtag == NULL) | if (curtag == NULL) | ||||
/* No tag loaded */ | /* No tag loaded */ | ||||
return NULL; | return NULL; | ||||
tp = curtag->next; | tp = curtag->next; | ||||
Show All 13 Lines | |||||
} | } | ||||
/* | /* | ||||
* Return the filename required for the previous gtag in the queue that was | * Return the filename required for the previous gtag in the queue that was | ||||
* setup by findgtat(). The next call to gtagsearch() will try to position | * setup by findgtat(). The next call to gtagsearch() will try to position | ||||
* at the appropriate tag. | * at the appropriate tag. | ||||
*/ | */ | ||||
static char * | static char * | ||||
prevgtag() | prevgtag(void) | ||||
{ | { | ||||
struct tag *tp; | struct tag *tp; | ||||
if (curtag == NULL) | if (curtag == NULL) | ||||
/* No tag loaded */ | /* No tag loaded */ | ||||
return NULL; | return NULL; | ||||
tp = curtag->prev; | tp = curtag->prev; | ||||
Show All 13 Lines | |||||
} | } | ||||
/* | /* | ||||
* Position the current file at at what is hopefully the tag that was chosen | * Position the current file at at what is hopefully the tag that was chosen | ||||
* using either findtag() or one of nextgtag() and prevgtag(). Returns -1 | * using either findtag() or one of nextgtag() and prevgtag(). Returns -1 | ||||
* if it was unable to position at the tag, 0 if successful. | * if it was unable to position at the tag, 0 if successful. | ||||
*/ | */ | ||||
static POSITION | static POSITION | ||||
gtagsearch() | gtagsearch(void) | ||||
{ | { | ||||
if (curtag == NULL) | if (curtag == NULL) | ||||
return (NULL_POSITION); /* No gtags loaded! */ | return (NULL_POSITION); /* No gtags loaded! */ | ||||
return (find_pos(curtag->tag_linenum)); | return (find_pos(curtag->tag_linenum)); | ||||
} | } | ||||
/* | /* | ||||
* The getentry() parses both standard and extended ctags -x format. | * The getentry() parses both standard and extended ctags -x format. | ||||
Show All 19 Lines | |||||
* o Exuberant Ctags with -x option | * o Exuberant Ctags with -x option | ||||
* See <http://ctags.sourceforge.net> | * See <http://ctags.sourceforge.net> | ||||
* | * | ||||
* Returns 0 on success, -1 on error. | * Returns 0 on success, -1 on error. | ||||
* The tag, file, and line will each be NUL-terminated pointers | * The tag, file, and line will each be NUL-terminated pointers | ||||
* into buf. | * into buf. | ||||
*/ | */ | ||||
static int | static int | ||||
getentry(buf, tag, file, line) | getentry(char *buf, char **tag, char **file, char **line) | ||||
char *buf; /* standard or extended ctags -x format data */ | |||||
char **tag; /* name of the tag we actually found */ | |||||
char **file; /* file in which to find this tag */ | |||||
char **line; /* line number of file where this tag is found */ | |||||
{ | { | ||||
char *p = buf; | char *p = buf; | ||||
for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ | for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ | ||||
; | ; | ||||
if (*p == 0) | if (*p == 0) | ||||
return (-1); | return (-1); | ||||
*p++ = 0; | *p++ = 0; | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |