-/* $OpenBSD: tags.c,v 1.19 2023/03/08 04:43:11 guenther Exp $ */
+/* $OpenBSD: tags.c,v 1.20 2023/03/22 18:10:07 op Exp $ */
/*
* This file is in the public domain.
{
char fname[NFILEN], *bufp, *temp;
struct stat sb;
-
+
if (getbufcwd(fname, sizeof(fname)) == FALSE)
fname[0] = '\0';
-
+
if (strlcat(fname, DEFAULTFN, sizeof(fname)) >= sizeof(fname)) {
dobeep();
ewprintf("Filename too long");
return (FALSE);
}
-
+
bufp = eread("Visit tags table (default %s): ", fname,
NFILEN, EFFILE | EFCR | EFNEW | EFDEF, DEFAULTFN);
if (bufp == NULL)
ewprintf("Cannot access file %s", bufp);
return (FALSE);
}
-
+
if (tagsfn == NULL) {
if (bufp[0] == '\0') {
if ((tagsfn = strdup(fname)) == NULL) {
tok = dtok;
else
tok = utok;
-
+
if (tok[0] == '\0') {
dobeep();
ewprintf("There is no default tag");
return (FALSE);
}
-
+
if (tagsfn == NULL)
if ((ret = tagsvisit(f, n)) != TRUE)
return (ret);
unloadtags(void)
{
struct ctag *var, *nxt;
-
+
for (var = RB_MIN(tagtree, &tags); var != NULL; var = nxt) {
nxt = RB_NEXT(tagtree, &tags, var);
RB_REMOVE(tagtree, &tags, var);
}
/*
- * Lookup tag passed in tree and if found, push current location and
+ * Lookup tag passed in tree and if found, push current location and
* buffername onto stack, load the file with tag definition into a new
* buffer and position dot at the pattern.
*/
struct tagpos *s;
char bname[NFILEN];
int doto, dotline;
-
+
if ((res = searchtag(tok)) == NULL)
return (FALSE);
-
+
doto = curwp->w_doto;
dotline = curwp->w_dotline;
/* record absolute filenames. Fixes issues when mg's cwd is not the
dobeep();
ewprintf("filename too long");
return (FALSE);
- }
+ }
if (loadbuffer(res->fname) == FALSE)
return (FALSE);
-
+
if (searchpat(res->pat) == TRUE) {
if ((s = malloc(sizeof(struct tagpos))) == NULL) {
dobeep();
{
struct line *dotp;
struct tagpos *s;
-
+
if (SLIST_EMPTY(&shead)) {
dobeep();
ewprintf("No previous location for find-tag invocation");
return (FALSE);
curwp->w_dotline = s->dotline;
curwp->w_doto = s->doto;
-
+
/* storing of dotp in tagpos wouldn't work out in cases when
* that buffer is killed by user(dangling pointer). Explicitly
- * traverse till dotline for correct handling.
+ * traverse till dotline for correct handling.
*/
dotp = curwp->w_bufp->b_headp;
while (s->dotline--)
dotp = dotp->l_fp;
-
+
curwp->w_dotp = dotp;
free(s->bname);
free(s);
}
/*
- * Parse the tags file and construct the tags tree. Remove escape
+ * Parse the tags file and construct the tags tree. Remove escape
* characters while parsing the file.
*/
int
{
char *l;
FILE *fd;
-
+
if ((fd = fopen(fn, "r")) == NULL) {
dobeep();
ewprintf("Unable to open tags file: %s", fn);
void
closetags(void)
{
- struct tagpos *s;
-
+ struct tagpos *s;
+
while (!SLIST_EMPTY(&shead)) {
s = SLIST_FIRST(&shead);
SLIST_REMOVE_HEAD(&shead, entry);
/*
* Strip away any special characters in pattern.
* The pattern in ctags isn't a true regular expression. Its of the form
- * /^xxx$/ or ?^xxx$? and in some cases the "$" would be missing. Strip
+ * /^xxx$/ or ?^xxx$? and in some cases the "$" would be missing. Strip
* the leading and trailing special characters so the pattern matching
- * would be a simple string compare. Escape character is taken care by
+ * would be a simple string compare. Escape character is taken care by
* fparseln.
*/
char *
strip(char *s, size_t len)
{
- /* first strip trailing special chars */
+ /* first strip trailing special chars */
s[len - 1] = '\0';
if (s[len - 2] == '$')
s[len - 2] = '\0';
-
+
/* then strip leading special chars */
s++;
if (*s == '^')
s++;
-
+
return s;
}
addctag(char *l)
{
struct ctag *t;
-
+
if ((t = malloc(sizeof(struct ctag))) == NULL) {
dobeep();
ewprintf("Out of memory");
}
/*
- * Return TRUE if dot is at beginning of a word or at beginning
+ * Return TRUE if dot is at beginning of a word or at beginning
* of line, else FALSE.
*/
int
struct line *odotp;
int odoto, tdoto, odotline, size, r;
char c;
-
+
/* Underscore character is to be treated as "inword" while
* processing tokens unlike mg's default word traversal. Save
* and restore its cinfo value so that tag matching works for
*/
c = cinfo['_'];
cinfo['_'] = _MG_W;
-
+
odotp = curwp->w_dotp;
odoto = curwp->w_doto;
odotline = curwp->w_dotline;
-
+
/* Move backward unless we are at the beginning of a word or at
* beginning of line.
*/
if (!atbow())
if ((r = backword(f, n)) == FALSE)
goto cleanup;
-
+
tdoto = curwp->w_doto;
if ((r = forwword(f, n)) == FALSE)
goto cleanup;
-
+
/* strip away leading whitespace if any like emacs. */
- while (ltext(curwp->w_dotp) &&
+ while (ltext(curwp->w_dotp) &&
isspace(lgetc(curwp->w_dotp, tdoto)))
tdoto++;
size = curwp->w_doto - tdoto;
- if (size <= 0 || size >= MAX_TOKEN ||
+ if (size <= 0 || size >= MAX_TOKEN ||
ltext(curwp->w_dotp) == NULL) {
r = FALSE;
goto cleanup;
- }
+ }
strncpy(token, ltext(curwp->w_dotp) + tdoto, size);
token[size] = '\0';
r = TRUE;
-
+
cleanup:
cinfo['_'] = c;
curwp->w_dotp = odotp;
* This is equivalent to filevisit from file.c.
* Look around to see if we can find the file in another buffer; if we
* can't find it, create a new buffer, read in the text, and switch to
- * the new buffer. *scratch*, *grep*, *compile* needs to be handled
+ * the new buffer. *scratch*, *grep*, *compile* needs to be handled
* differently from other buffers which have "filenames".
*/
int
} else {
return (FALSE);
}
- } else {
+ } else {
if ((adjf = adjustname(bname, TRUE)) == NULL)
return (FALSE);
if ((bufp = findbuffer(adjf)) == NULL)