[BACK]Return to mandocdb.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/mandocdb.c between version 1.266 and 1.273

version 1.266, 2020/01/26 21:25:41 version 1.273, 2024/05/14 18:52:31
Line 1 
Line 1 
 /*      $Id$ */  /* $Id$ */
 /*  /*
    * Copyright (c) 2011-2021 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011-2020 Ingo Schwarze <schwarze@openbsd.org>  
  * Copyright (c) 2016 Ed Maste <emaste@freebsd.org>   * Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
Line 15 
Line 15 
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    *
    * Implementation of the makewhatis(8) program.
  */   */
 #include "config.h"  #include "config.h"
   
Line 118  struct mdoc_handler {
Line 120  struct mdoc_handler {
 int              mandocdb(int, char *[]);  int              mandocdb(int, char *[]);
   
 static  void     dbadd(struct dba *, struct mpage *);  static  void     dbadd(struct dba *, struct mpage *);
 static  void     dbadd_mlink(const struct mlink *mlink);  static  void     dbadd_mlink(const struct mlink *);
 static  void     dbprune(struct dba *);  static  void     dbprune(struct dba *);
 static  void     dbwrite(struct dba *);  static  void     dbwrite(struct dba *);
 static  void     filescan(const char *);  static  void     filescan(const char *);
Line 163  static void  putkey(const struct mpage *, char *, uint
Line 165  static void  putkey(const struct mpage *, char *, uint
 static  void     putkeys(const struct mpage *, char *, size_t, uint64_t);  static  void     putkeys(const struct mpage *, char *, size_t, uint64_t);
 static  void     putmdockey(const struct mpage *,  static  void     putmdockey(const struct mpage *,
                         const struct roff_node *, uint64_t, int);                          const struct roff_node *, uint64_t, int);
   #ifdef READ_ALLOWED_PATH
   static  int      read_allowed(const char *);
   #endif
 static  int      render_string(char **, size_t *);  static  int      render_string(char **, size_t *);
 static  void     say(const char *, const char *, ...)  static  void     say(const char *, const char *, ...)
                         __attribute__((__format__ (__printf__, 2, 3)));                          __attribute__((__format__ (__printf__, 2, 3)));
Line 348  mandocdb(int argc, char *argv[])
Line 353  mandocdb(int argc, char *argv[])
                 goto usage; \                  goto usage; \
         } while (/*CONSTCOND*/0)          } while (/*CONSTCOND*/0)
   
         mparse_options = MPARSE_VALIDATE;          mparse_options = MPARSE_UTF8 | MPARSE_LATIN1 | MPARSE_VALIDATE;
         path_arg = NULL;          path_arg = NULL;
         op = OP_DEFAULT;          op = OP_DEFAULT;
   
Line 527  out:
Line 532  out:
         mpages_free();          mpages_free();
         ohash_delete(&mpages);          ohash_delete(&mpages);
         ohash_delete(&mlinks);          ohash_delete(&mlinks);
   #if DEBUG_MEMORY
           mandoc_dbg_finish();
   #endif
         return exitcode;          return exitcode;
 usage:  usage:
         progname = getprogname();          progname = getprogname();
Line 610  treescan(void)
Line 618  treescan(void)
                                 continue;                                  continue;
                         }                          }
                         if (strncmp(buf, basedir, basedir_len) != 0                          if (strncmp(buf, basedir, basedir_len) != 0
 #ifdef HOMEBREWDIR  #ifdef READ_ALLOWED_PATH
                             && strncmp(buf, HOMEBREWDIR, strlen(HOMEBREWDIR))                              && !read_allowed(buf)
 #endif  #endif
                         ) {                          ) {
                                 if (warnings) say("",                                  if (warnings) say("",
Line 624  treescan(void)
Line 632  treescan(void)
                                         say(path, "&stat");                                          say(path, "&stat");
                                 continue;                                  continue;
                         }                          }
                           if ((ff->fts_statp->st_mode & S_IFMT) != S_IFREG)
                                   continue;
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
   
                 /*                  /*
Line 794  filescan(const char *infile)
Line 804  filescan(const char *infile)
          * We have to do lstat(2) before realpath(3) loses           * We have to do lstat(2) before realpath(3) loses
          * the information whether this is a symbolic link.           * the information whether this is a symbolic link.
          * We need to know that because for symbolic links,           * We need to know that because for symbolic links,
          * we want to use the orginal file name, while for           * we want to use the original file name, while for
          * regular files, we want to use the real path.           * regular files, we want to use the real path.
          */           */
         if (lstat(infile, &st) == -1) {          if (lstat(infile, &st) == -1) {
Line 821  filescan(const char *infile)
Line 831  filescan(const char *infile)
                 start = usefile;                  start = usefile;
         else if (strncmp(usefile, basedir, basedir_len) == 0)          else if (strncmp(usefile, basedir, basedir_len) == 0)
                 start = usefile + basedir_len;                  start = usefile + basedir_len;
 #ifdef HOMEBREWDIR  #ifdef READ_ALLOWED_PATH
         else if (strncmp(usefile, HOMEBREWDIR, strlen(HOMEBREWDIR)) == 0)          else if (read_allowed(usefile))
                 start = usefile;                  start = usefile;
 #endif  #endif
         else {          else {
Line 2021  render_string(char **public, size_t *psz)
Line 2031  render_string(char **public, size_t *psz)
                  */                   */
   
                 scp++;                  scp++;
                 if (mandoc_escape(&scp, &seq, &seqlen) != ESCAPE_SPECIAL)                  switch (mandoc_escape(&scp, &seq, &seqlen)) {
                   case ESCAPE_UNICODE:
                           unicode = mchars_num2uc(seq + 1, seqlen - 1);
                           break;
                   case ESCAPE_NUMBERED:
                           unicode = mchars_num2char(seq, seqlen);
                           break;
                   case ESCAPE_SPECIAL:
                           unicode = mchars_spec2cp(seq, seqlen);
                           break;
                   default:
                           unicode = -1;
                           break;
                   }
                   if (unicode <= 0)
                         continue;                          continue;
   
                 /*                  /*
Line 2030  render_string(char **public, size_t *psz)
Line 2054  render_string(char **public, size_t *psz)
                  */                   */
   
                 if (write_utf8) {                  if (write_utf8) {
                         unicode = mchars_spec2cp(seq, seqlen);  
                         if (unicode <= 0)  
                                 continue;  
                         addsz = utf8(unicode, utfbuf);                          addsz = utf8(unicode, utfbuf);
                         if (addsz == 0)                          if (addsz == 0)
                                 continue;                                  continue;
                         addcp = utfbuf;                          addcp = utfbuf;
                 } else {                  } else {
                         addcp = mchars_spec2str(seq, seqlen, &addsz);                          addcp = mchars_uc2str(unicode);
                         if (addcp == NULL)                          if (addcp == NULL)
                                 continue;                                  continue;
                         if (*addcp == ASCII_NBRSP) {                          if (*addcp == ASCII_NBRSP)
                                 addcp = " ";                                  addcp = " ";
                                 addsz = 1;                          addsz = strlen(addcp);
                         }  
                 }                  }
   
                 /* Copy the rendered glyph into the stream. */                  /* Copy the rendered glyph into the stream. */
Line 2244  dbwrite(struct dba *dba)
Line 2264  dbwrite(struct dba *dba)
                 say(tfn, "&dba_write");                  say(tfn, "&dba_write");
                 goto err;                  goto err;
         }          }
         if ((fd1 = open(MANDOC_DB, O_RDONLY, 0)) == -1) {          if ((fd1 = open(MANDOC_DB, O_RDONLY)) == -1) {
                 say(MANDOC_DB, "&open");                  say(MANDOC_DB, "&open");
                 goto err;                  goto err;
         }          }
         if ((fd2 = open(tfn, O_RDONLY, 0)) == -1) {          if ((fd2 = open(tfn, O_RDONLY)) == -1) {
                 say(tfn, "&open");                  say(tfn, "&open");
                 goto err;                  goto err;
         }          }
Line 2378  set_basedir(const char *targetdir, int report_baddir)
Line 2398  set_basedir(const char *targetdir, int report_baddir)
         }          }
         return 1;          return 1;
 }  }
   
   #ifdef READ_ALLOWED_PATH
   static int
   read_allowed(const char *candidate)
   {
           const char      *cp;
           size_t           len;
   
           for (cp = READ_ALLOWED_PATH;; cp += len) {
                   while (*cp == ':')
                           cp++;
                   if (*cp == '\0')
                           return 0;
                   len = strcspn(cp, ":");
                   if (strncmp(candidate, cp, len) == 0)
                           return 1;
           }
   }
   #endif
   
 static void  static void
 say(const char *file, const char *format, ...)  say(const char *file, const char *format, ...)

Legend:
Removed from v.1.266  
changed lines
  Added in v.1.273

CVSweb