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

Diff for /mandoc/mandocdb.c between version 1.258 and 1.262

version 1.258, 2018/02/23 18:25:57 version 1.262, 2018/12/30 00:49:55
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011-2018 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 52 
Line 52 
 #include "roff.h"  #include "roff.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "man.h"  #include "man.h"
   #include "mandoc_parse.h"
 #include "manconf.h"  #include "manconf.h"
 #include "mansearch.h"  #include "mansearch.h"
 #include "dba_array.h"  #include "dba_array.h"
Line 185  static struct ohash  names; /* table of all names */
Line 186  static struct ohash  names; /* table of all names */
 static  struct ohash     strings; /* table of all strings */  static  struct ohash     strings; /* table of all strings */
 static  uint64_t         name_mask;  static  uint64_t         name_mask;
   
 static  const struct mdoc_handler __mdocs[MDOC_MAX - MDOC_Dd] = {  static  const struct mdoc_handler mdoc_handlers[MDOC_MAX - MDOC_Dd] = {
         { NULL, 0, NODE_NOPRT },  /* Dd */          { NULL, 0, NODE_NOPRT },  /* Dd */
         { NULL, 0, NODE_NOPRT },  /* Dt */          { NULL, 0, NODE_NOPRT },  /* Dt */
         { NULL, 0, NODE_NOPRT },  /* Os */          { NULL, 0, NODE_NOPRT },  /* Os */
Line 307  static const struct mdoc_handler __mdocs[MDOC_MAX - MD
Line 308  static const struct mdoc_handler __mdocs[MDOC_MAX - MD
         { NULL, 0, 0 },  /* %U */          { NULL, 0, 0 },  /* %U */
         { NULL, 0, 0 },  /* Ta */          { NULL, 0, 0 },  /* Ta */
 };  };
 static  const struct mdoc_handler *const mdocs = __mdocs - MDOC_Dd;  
   
   
 int  int
Line 347  mandocdb(int argc, char *argv[])
Line 347  mandocdb(int argc, char *argv[])
                 goto usage; \                  goto usage; \
         } while (/*CONSTCOND*/0)          } while (/*CONSTCOND*/0)
   
           mparse_options = MPARSE_VALIDATE;
         path_arg = NULL;          path_arg = NULL;
         op = OP_DEFAULT;          op = OP_DEFAULT;
   
Line 422  mandocdb(int argc, char *argv[])
Line 423  mandocdb(int argc, char *argv[])
   
         exitcode = (int)MANDOCLEVEL_OK;          exitcode = (int)MANDOCLEVEL_OK;
         mchars_alloc();          mchars_alloc();
         mp = mparse_alloc(mparse_options, MANDOCERR_MAX, NULL,          mp = mparse_alloc(mparse_options, MANDOC_OS_OTHER, NULL);
             MANDOC_OS_OTHER, NULL);  
         mandoc_ohash_init(&mpages, 6, offsetof(struct mpage, inodev));          mandoc_ohash_init(&mpages, 6, offsetof(struct mpage, inodev));
         mandoc_ohash_init(&mlinks, 6, offsetof(struct mlink, file));          mandoc_ohash_init(&mlinks, 6, offsetof(struct mlink, file));
   
Line 1116  mpages_merge(struct dba *dba, struct mparse *mp)
Line 1116  mpages_merge(struct dba *dba, struct mparse *mp)
 {  {
         struct mpage            *mpage, *mpage_dest;          struct mpage            *mpage, *mpage_dest;
         struct mlink            *mlink, *mlink_dest;          struct mlink            *mlink, *mlink_dest;
         struct roff_man         *man;          struct roff_meta        *meta;
         char                    *sodest;  
         char                    *cp;          char                    *cp;
         int                      fd;          int                      fd;
   
Line 1130  mpages_merge(struct dba *dba, struct mparse *mp)
Line 1129  mpages_merge(struct dba *dba, struct mparse *mp)
                 mandoc_ohash_init(&names, 4, offsetof(struct str, key));                  mandoc_ohash_init(&names, 4, offsetof(struct str, key));
                 mandoc_ohash_init(&strings, 6, offsetof(struct str, key));                  mandoc_ohash_init(&strings, 6, offsetof(struct str, key));
                 mparse_reset(mp);                  mparse_reset(mp);
                 man = NULL;                  meta = NULL;
                 sodest = NULL;  
   
                 if ((fd = mparse_open(mp, mlink->file)) == -1) {                  if ((fd = mparse_open(mp, mlink->file)) == -1) {
                         say(mlink->file, "&open");                          say(mlink->file, "&open");
Line 1146  mpages_merge(struct dba *dba, struct mparse *mp)
Line 1144  mpages_merge(struct dba *dba, struct mparse *mp)
                         mparse_readfd(mp, fd, mlink->file);                          mparse_readfd(mp, fd, mlink->file);
                         close(fd);                          close(fd);
                         fd = -1;                          fd = -1;
                         mparse_result(mp, &man, &sodest);                          meta = mparse_result(mp);
                 }                  }
   
                 if (sodest != NULL) {                  if (meta != NULL && meta->sodest != NULL) {
                         mlink_dest = ohash_find(&mlinks,                          mlink_dest = ohash_find(&mlinks,
                             ohash_qlookup(&mlinks, sodest));                              ohash_qlookup(&mlinks, meta->sodest));
                         if (mlink_dest == NULL) {                          if (mlink_dest == NULL) {
                                 mandoc_asprintf(&cp, "%s.gz", sodest);                                  mandoc_asprintf(&cp, "%s.gz", meta->sodest);
                                 mlink_dest = ohash_find(&mlinks,                                  mlink_dest = ohash_find(&mlinks,
                                     ohash_qlookup(&mlinks, cp));                                      ohash_qlookup(&mlinks, cp));
                                 free(cp);                                  free(cp);
Line 1190  mpages_merge(struct dba *dba, struct mparse *mp)
Line 1188  mpages_merge(struct dba *dba, struct mparse *mp)
                                 mpage->mlinks = NULL;                                  mpage->mlinks = NULL;
                         }                          }
                         goto nextpage;                          goto nextpage;
                 } else if (man != NULL && man->macroset == MACROSET_MDOC) {                  } else if (meta != NULL && meta->macroset == MACROSET_MDOC) {
                         mdoc_validate(man);  
                         mpage->form = FORM_SRC;                          mpage->form = FORM_SRC;
                         mpage->sec = man->meta.msec;                          mpage->sec = meta->msec;
                         mpage->sec = mandoc_strdup(                          mpage->sec = mandoc_strdup(
                             mpage->sec == NULL ? "" : mpage->sec);                              mpage->sec == NULL ? "" : mpage->sec);
                         mpage->arch = man->meta.arch;                          mpage->arch = meta->arch;
                         mpage->arch = mandoc_strdup(                          mpage->arch = mandoc_strdup(
                             mpage->arch == NULL ? "" : mpage->arch);                              mpage->arch == NULL ? "" : mpage->arch);
                         mpage->title = mandoc_strdup(man->meta.title);                          mpage->title = mandoc_strdup(meta->title);
                 } else if (man != NULL && man->macroset == MACROSET_MAN) {                  } else if (meta != NULL && meta->macroset == MACROSET_MAN) {
                         man_validate(man);                          if (*meta->msec != '\0' || *meta->title != '\0') {
                         if (*man->meta.msec != '\0' ||  
                             *man->meta.title != '\0') {  
                                 mpage->form = FORM_SRC;                                  mpage->form = FORM_SRC;
                                 mpage->sec = mandoc_strdup(man->meta.msec);                                  mpage->sec = mandoc_strdup(meta->msec);
                                 mpage->arch = mandoc_strdup(mlink->arch);                                  mpage->arch = mandoc_strdup(mlink->arch);
                                 mpage->title = mandoc_strdup(man->meta.title);                                  mpage->title = mandoc_strdup(meta->title);
                         } else                          } else
                                 man = NULL;                                  meta = NULL;
                 }                  }
   
                 assert(mpage->desc == NULL);                  assert(mpage->desc == NULL);
                 if (man == NULL) {                  if (meta == NULL) {
                         mpage->form = FORM_CAT;                          mpage->form = FORM_CAT;
                         mpage->sec = mandoc_strdup(mlink->dsec);                          mpage->sec = mandoc_strdup(mlink->dsec);
                         mpage->arch = mandoc_strdup(mlink->arch);                          mpage->arch = mandoc_strdup(mlink->arch);
                         mpage->title = mandoc_strdup(mlink->name);                          mpage->title = mandoc_strdup(mlink->name);
                         parse_cat(mpage, fd);                          parse_cat(mpage, fd);
                 } else if (man->macroset == MACROSET_MDOC)                  } else if (meta->macroset == MACROSET_MDOC)
                         parse_mdoc(mpage, &man->meta, man->first);                          parse_mdoc(mpage, meta, meta->first);
                 else                  else
                         parse_man(mpage, &man->meta, man->first);                          parse_man(mpage, meta, meta->first);
                 if (mpage->desc == NULL) {                  if (mpage->desc == NULL) {
                         mpage->desc = mandoc_strdup(mlink->name);                          mpage->desc = mandoc_strdup(mlink->name);
                         if (warnings)                          if (warnings)
Line 1546  static void
Line 1541  static void
 parse_mdoc(struct mpage *mpage, const struct roff_meta *meta,  parse_mdoc(struct mpage *mpage, const struct roff_meta *meta,
         const struct roff_node *n)          const struct roff_node *n)
 {  {
           const struct mdoc_handler *handler;
   
         for (n = n->child; n != NULL; n = n->next) {          for (n = n->child; n != NULL; n = n->next) {
                 if (n->tok == TOKEN_NONE ||                  if (n->tok == TOKEN_NONE || n->tok < ROFF_MAX)
                     n->tok < ROFF_MAX ||  
                     n->flags & mdocs[n->tok].taboo)  
                         continue;                          continue;
                 assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);                  assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
                   handler = mdoc_handlers + (n->tok - MDOC_Dd);
                   if (n->flags & handler->taboo)
                           continue;
   
                 switch (n->type) {                  switch (n->type) {
                 case ROFFT_ELEM:                  case ROFFT_ELEM:
                 case ROFFT_BLOCK:                  case ROFFT_BLOCK:
                 case ROFFT_HEAD:                  case ROFFT_HEAD:
                 case ROFFT_BODY:                  case ROFFT_BODY:
                 case ROFFT_TAIL:                  case ROFFT_TAIL:
                         if (mdocs[n->tok].fp != NULL &&                          if (handler->fp != NULL &&
                             (*mdocs[n->tok].fp)(mpage, meta, n) == 0)                              (*handler->fp)(mpage, meta, n) == 0)
                                 break;                                  break;
                         if (mdocs[n->tok].mask)                          if (handler->mask)
                                 putmdockey(mpage, n->child,                                  putmdockey(mpage, n->child,
                                     mdocs[n->tok].mask, mdocs[n->tok].taboo);                                      handler->mask, handler->taboo);
                         break;                          break;
                 default:                  default:
                         continue;                          continue;

Legend:
Removed from v.1.258  
changed lines
  Added in v.1.262

CVSweb