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

Diff for /mandoc/mandocdb.c between version 1.269 and 1.274

version 1.269, 2021/08/19 16:55:31 version 1.274, 2024/05/14 21:19:12
Line 1 
Line 1 
 /* $Id$ */  /* $Id$ */
 /*  /*
  * Copyright (c) 2011-2020 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011-2021, 2024 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) 2016 Ed Maste <emaste@freebsd.org>   * Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
  *   *
Line 173  static void  say(const char *, const char *, ...)
Line 173  static void  say(const char *, const char *, ...)
                         __attribute__((__format__ (__printf__, 2, 3)));                          __attribute__((__format__ (__printf__, 2, 3)));
 static  int      set_basedir(const char *, int);  static  int      set_basedir(const char *, int);
 static  int      treescan(void);  static  int      treescan(void);
 static  size_t   utf8(unsigned int, char [7]);  static  size_t   utf8(unsigned int, char[5]);
   
 static  int              nodb; /* no database changes */  static  int              nodb; /* no database changes */
 static  int              mparse_options; /* abort the parse early */  static  int              mparse_options; /* abort the parse early */
Line 353  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 532  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 801  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 1904  putkeys(const struct mpage *mpage, char *cp, size_t sz
Line 1907  putkeys(const struct mpage *mpage, char *cp, size_t sz
  * Take a Unicode codepoint and produce its UTF-8 encoding.   * Take a Unicode codepoint and produce its UTF-8 encoding.
  * This isn't the best way to do this, but it works.   * This isn't the best way to do this, but it works.
  * The magic numbers are from the UTF-8 packaging.   * The magic numbers are from the UTF-8 packaging.
  * They're not as scary as they seem: read the UTF-8 spec for details.   * Read the UTF-8 spec or the utf8(7) manual page for details.
  */   */
 static size_t  static size_t
 utf8(unsigned int cp, char out[7])  utf8(unsigned int cp, char out[5])
 {  {
         size_t           rc;          size_t           rc;
   
         rc = 0;          if (cp <= 0x7f) {
         if (cp <= 0x0000007F) {  
                 rc = 1;                  rc = 1;
                 out[0] = (char)cp;                  out[0] = (char)cp;
         } else if (cp <= 0x000007FF) {          } else if (cp <= 0x7ff) {
                 rc = 2;                  rc = 2;
                 out[0] = (cp >> 6  & 31) | 192;                  out[0] = (cp >> 6  & 31) | 192;
                 out[1] = (cp       & 63) | 128;                  out[1] = (cp       & 63) | 128;
         } else if (cp <= 0x0000FFFF) {          } else if (cp >= 0xd800 && cp <= 0xdfff) {
                   rc = 0; /* reject UTF-16 surrogate */
           } else if (cp <= 0xffff) {
                 rc = 3;                  rc = 3;
                 out[0] = (cp >> 12 & 15) | 224;                  out[0] = (cp >> 12 & 15) | 224;
                 out[1] = (cp >> 6  & 63) | 128;                  out[1] = (cp >> 6  & 63) | 128;
                 out[2] = (cp       & 63) | 128;                  out[2] = (cp       & 63) | 128;
         } else if (cp <= 0x001FFFFF) {          } else if (cp <= 0x10ffff) {
                 rc = 4;                  rc = 4;
                 out[0] = (cp >> 18 &  7) | 240;                  out[0] = (cp >> 18 &  7) | 240;
                 out[1] = (cp >> 12 & 63) | 128;                  out[1] = (cp >> 12 & 63) | 128;
                 out[2] = (cp >> 6  & 63) | 128;                  out[2] = (cp >> 6  & 63) | 128;
                 out[3] = (cp       & 63) | 128;                  out[3] = (cp       & 63) | 128;
         } else if (cp <= 0x03FFFFFF) {  
                 rc = 5;  
                 out[0] = (cp >> 24 &  3) | 248;  
                 out[1] = (cp >> 18 & 63) | 128;  
                 out[2] = (cp >> 12 & 63) | 128;  
                 out[3] = (cp >> 6  & 63) | 128;  
                 out[4] = (cp       & 63) | 128;  
         } else if (cp <= 0x7FFFFFFF) {  
                 rc = 6;  
                 out[0] = (cp >> 30 &  1) | 252;  
                 out[1] = (cp >> 24 & 63) | 128;  
                 out[2] = (cp >> 18 & 63) | 128;  
                 out[3] = (cp >> 12 & 63) | 128;  
                 out[4] = (cp >> 6  & 63) | 128;  
                 out[5] = (cp       & 63) | 128;  
         } else          } else
                 return 0;                  rc = 0;
   
         out[rc] = '\0';          out[rc] = '\0';
         return rc;          return rc;
Line 2028  render_string(char **public, size_t *psz)
Line 2017  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 2037  render_string(char **public, size_t *psz)
Line 2040  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 2251  dbwrite(struct dba *dba)
Line 2250  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;
         }          }

Legend:
Removed from v.1.269  
changed lines
  Added in v.1.274

CVSweb