[BACK]Return to tags.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Diff for /src/usr.bin/mg/tags.c between version 1.24 and 1.25

version 1.24, 2023/03/28 21:33:21 version 1.25, 2023/03/29 07:29:17
Line 39 
Line 39 
 #define DEFAULTFN "tags"  #define DEFAULTFN "tags"
   
 char *tagsfn = NULL;  char *tagsfn = NULL;
 int  loaded  = FALSE;  
   
 /* ctags(1) entries are parsed and maintained in a tree. */  /* ctags(1) entries are parsed and maintained in a tree. */
 struct ctag {  struct ctag {
Line 66 
Line 65 
 }  }
   
 /*  /*
  * Record the filename that contain tags to be used while loading them   * Load a tags file.  If a tags file is already loaded, ask the user to
  * on first use. If a filename is already recorded, ask user to retain   * retain loaded tags (i any) and unload them if the user chooses not to.
  * already loaded tags (if any) and unload them if user chooses not to.  
  */   */
 int  int
 tagsvisit(int f, int n)  tagsvisit(int f, int n)
 {  {
         char fname[NFILEN], *bufp, *temp;          char fname[NFILEN], *bufp, *temp;
         struct stat sb;  
   
         if (getbufcwd(fname, sizeof(fname)) == FALSE)          if (getbufcwd(fname, sizeof(fname)) == FALSE)
                 fname[0] = '\0';                  fname[0] = '\0';
Line 90 
Line 87 
         if (bufp == NULL)          if (bufp == NULL)
                 return (ABORT);                  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 (tagsfn == NULL) {
                 if (bufp[0] == '\0') {                  if (bufp[0] == '\0') {
                         if ((tagsfn = strdup(fname)) == NULL) {                          if ((tagsfn = strdup(fname)) == NULL) {
Line 131 
Line 114 
                         ewprintf("Starting a new list of tags table");                          ewprintf("Starting a new list of tags table");
                         unloadtags();                          unloadtags();
                 }                  }
                 loaded = FALSE;  
         }          }
   
           if (loadtags(tagsfn) == FALSE) {
                   free(tagsfn);
                   tagsfn = NULL;
                   return (FALSE);
           }
   
         return (TRUE);          return (TRUE);
 }  }
   
Line 170 
Line 159 
         if (tagsfn == NULL)          if (tagsfn == NULL)
                 if ((ret = tagsvisit(f, n)) != TRUE)                  if ((ret = tagsvisit(f, n)) != TRUE)
                         return (ret);                          return (ret);
         if (!loaded) {  
                 if (loadtags(tagsfn) == FALSE) {  
                         free(tagsfn);  
                         tagsfn = NULL;  
                         return (FALSE);  
                 }  
                 loaded = TRUE;  
         }  
         return pushtag(tok);          return pushtag(tok);
 }  }
   
Line 300 
Line 281 
 int  int
 loadtags(const char *fn)  loadtags(const char *fn)
 {  {
           struct stat sb;
         char *l;          char *l;
         FILE *fd;          FILE *fd;
   
         if ((fd = fopen(fn, "r")) == NULL) {          if ((fd = fopen(fn, "r")) == NULL) {
                 dobeep();                  dobeep();
                 ewprintf("Unable to open tags file: %s", fn);                  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);                  return (FALSE);
         }          }
         while ((l = fparseln(fd, NULL, NULL, "\\\\\0",          while ((l = fparseln(fd, NULL, NULL, "\\\\\0",

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25