-.\" $OpenBSD: mg.1,v 1.127 2022/10/20 18:59:24 op Exp $
+.\" $OpenBSD: mg.1,v 1.128 2023/03/29 07:29:17 op Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: October 20 2022 $
+.Dd $Mdocdate: March 29 2023 $
.Dt MG 1
.Os
.Sh NAME
Toggle the visible bell.
If this toggle is on, the modeline will flash.
.It visit-tags-table
-Record name of the tags file to be used for subsequent find-tag.
+Load tags file to be used for subsequent find-tag.
.It what-cursor-position
Display a bunch of useful information about the current location of
dot.
-/* $OpenBSD: tags.c,v 1.24 2023/03/28 21:33:21 tb Exp $ */
+/* $OpenBSD: tags.c,v 1.25 2023/03/29 07:29:17 op Exp $ */
/*
* This file is in the public domain.
#define DEFAULTFN "tags"
char *tagsfn = NULL;
-int loaded = FALSE;
/* ctags(1) entries are parsed and maintained in a tree. */
struct ctag {
}
/*
- * Record the filename that contain tags to be used while loading them
- * on first use. If a filename is already recorded, ask user to retain
- * already loaded tags (if any) and unload them if user chooses not to.
+ * Load a tags file. If a tags file is already loaded, ask the user to
+ * retain loaded tags (i any) and unload them if the user chooses not to.
*/
int
tagsvisit(int f, int n)
{
char fname[NFILEN], *bufp, *temp;
- struct stat sb;
if (getbufcwd(fname, sizeof(fname)) == FALSE)
fname[0] = '\0';
if (bufp == NULL)
return (ABORT);
- if (stat(bufp, &sb) == -1) {
- dobeep();
- ewprintf("stat: %s", strerror(errno));
- return (FALSE);
- } else if (S_ISREG(sb.st_mode) == 0) {
- dobeep();
- ewprintf("Not a regular file");
- return (FALSE);
- } else if (access(bufp, R_OK) == -1) {
- dobeep();
- ewprintf("Cannot access file %s", bufp);
- return (FALSE);
- }
-
if (tagsfn == NULL) {
if (bufp[0] == '\0') {
if ((tagsfn = strdup(fname)) == NULL) {
ewprintf("Starting a new list of tags table");
unloadtags();
}
- loaded = FALSE;
}
+
+ if (loadtags(tagsfn) == FALSE) {
+ free(tagsfn);
+ tagsfn = NULL;
+ return (FALSE);
+ }
+
return (TRUE);
}
if (tagsfn == NULL)
if ((ret = tagsvisit(f, n)) != TRUE)
return (ret);
- if (!loaded) {
- if (loadtags(tagsfn) == FALSE) {
- free(tagsfn);
- tagsfn = NULL;
- return (FALSE);
- }
- loaded = TRUE;
- }
return pushtag(tok);
}
int
loadtags(const char *fn)
{
+ struct stat sb;
char *l;
FILE *fd;
ewprintf("Unable to open tags file: %s", fn);
return (FALSE);
}
+ if (fstat(fileno(fd), &sb) == -1) {
+ dobeep();
+ ewprintf("fstat: %s", strerror(errno));
+ fclose(fd);
+ return (FALSE);
+ }
+ if (!S_ISREG(sb.st_mode)) {
+ dobeep();
+ ewprintf("Not a regular file");
+ fclose(fd);
+ return (FALSE);
+ }
while ((l = fparseln(fd, NULL, NULL, "\\\\\0",
FPARSELN_UNESCCONT | FPARSELN_UNESCREST)) != NULL) {
if (addctag(l) == FALSE) {