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

Diff for /mandoc/mandocdb.c between version 1.183 and 1.188

version 1.183, 2015/01/15 04:26:40 version 1.188, 2015/04/02 21:36:50
Line 7 
Line 7 
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
  * copyright notice and this permission notice appear in all copies.   * copyright notice and this permission notice appear in all copies.
  *   *
  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * 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
Line 46 
Line 46 
 #endif  #endif
 #include <sqlite3.h>  #include <sqlite3.h>
   
   #include "mandoc_aux.h"
   #include "mandoc.h"
   #include "roff.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "man.h"  #include "man.h"
 #include "mandoc.h"  #include "manconf.h"
 #include "mandoc_aux.h"  
 #include "manpath.h"  
 #include "mansearch.h"  #include "mansearch.h"
   
 extern int mansearch_keymax;  extern int mansearch_keymax;
Line 338  static const struct mdoc_handler mdocs[MDOC_MAX] = {
Line 339  static const struct mdoc_handler mdocs[MDOC_MAX] = {
 int  int
 mandocdb(int argc, char *argv[])  mandocdb(int argc, char *argv[])
 {  {
         int               ch, i;          struct manconf    conf;
         size_t            j, sz;  
         const char       *path_arg;  
         struct manpaths   dirs;  
         struct mparse    *mp;  
         struct ohash_info mpages_info, mlinks_info;          struct ohash_info mpages_info, mlinks_info;
           struct mparse    *mp;
           const char       *path_arg;
           size_t            j, sz;
           int               ch, i;
   
           memset(&conf, 0, sizeof(conf));
         memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *));          memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *));
         memset(&dirs, 0, sizeof(struct manpaths));  
   
         mpages_info.alloc  = mlinks_info.alloc  = hash_alloc;          mpages_info.alloc  = mlinks_info.alloc  = hash_alloc;
         mpages_info.calloc = mlinks_info.calloc = hash_calloc;          mpages_info.calloc = mlinks_info.calloc = hash_calloc;
Line 485  mandocdb(int argc, char *argv[])
Line 486  mandocdb(int argc, char *argv[])
                 /*                  /*
                  * If we have arguments, use them as our manpaths.                   * If we have arguments, use them as our manpaths.
                  * If we don't, grok from manpath(1) or however else                   * If we don't, grok from manpath(1) or however else
                  * manpath_parse() wants to do it.                   * manconf_parse() wants to do it.
                  */                   */
                 if (argc > 0) {                  if (argc > 0) {
                         dirs.paths = mandoc_reallocarray(NULL,                          conf.manpath.paths = mandoc_reallocarray(NULL,
                             argc, sizeof(char *));                              argc, sizeof(char *));
                         dirs.sz = (size_t)argc;                          conf.manpath.sz = (size_t)argc;
                         for (i = 0; i < argc; i++)                          for (i = 0; i < argc; i++)
                                 dirs.paths[i] = mandoc_strdup(argv[i]);                                  conf.manpath.paths[i] = mandoc_strdup(argv[i]);
                 } else                  } else
                         manpath_parse(&dirs, path_arg, NULL, NULL);                          manconf_parse(&conf, path_arg, NULL, NULL);
   
                 if (0 == dirs.sz) {                  if (conf.manpath.sz == 0) {
                         exitcode = (int)MANDOCLEVEL_BADARG;                          exitcode = (int)MANDOCLEVEL_BADARG;
                         say("", "Empty manpath");                          say("", "Empty manpath");
                 }                  }
Line 507  mandocdb(int argc, char *argv[])
Line 508  mandocdb(int argc, char *argv[])
                  * Ignore zero-length directories and strip trailing                   * Ignore zero-length directories and strip trailing
                  * slashes.                   * slashes.
                  */                   */
                 for (j = 0; j < dirs.sz; j++) {                  for (j = 0; j < conf.manpath.sz; j++) {
                         sz = strlen(dirs.paths[j]);                          sz = strlen(conf.manpath.paths[j]);
                         if (sz && '/' == dirs.paths[j][sz - 1])                          if (sz && conf.manpath.paths[j][sz - 1] == '/')
                                 dirs.paths[j][--sz] = '\0';                                  conf.manpath.paths[j][--sz] = '\0';
                         if (0 == sz)                          if (0 == sz)
                                 continue;                                  continue;
   
Line 519  mandocdb(int argc, char *argv[])
Line 520  mandocdb(int argc, char *argv[])
                                 ohash_init(&mlinks, 6, &mlinks_info);                                  ohash_init(&mlinks, 6, &mlinks_info);
                         }                          }
   
                         if (0 == set_basedir(dirs.paths[j], argc > 0))                          if ( ! set_basedir(conf.manpath.paths[j], argc > 0))
                                 continue;                                  continue;
                         if (0 == treescan())                          if (0 == treescan())
                                 continue;                                  continue;
Line 532  mandocdb(int argc, char *argv[])
Line 533  mandocdb(int argc, char *argv[])
                                 names_check();                                  names_check();
                         dbclose(0);                          dbclose(0);
   
                         if (j + 1 < dirs.sz) {                          if (j + 1 < conf.manpath.sz) {
                                 mpages_free();                                  mpages_free();
                                 ohash_delete(&mpages);                                  ohash_delete(&mpages);
                                 ohash_delete(&mlinks);                                  ohash_delete(&mlinks);
Line 540  mandocdb(int argc, char *argv[])
Line 541  mandocdb(int argc, char *argv[])
                 }                  }
         }          }
 out:  out:
         manpath_free(&dirs);          manconf_free(&conf);
         mparse_free(mp);          mparse_free(mp);
         mchars_free(mchars);          mchars_free(mchars);
         mpages_free();          mpages_free();
Line 613  treescan(void)
Line 614  treescan(void)
                                         say(path, "&realpath");                                          say(path, "&realpath");
                                 continue;                                  continue;
                         }                          }
                         if (strstr(buf, basedir) != buf) {                          if (strstr(buf, basedir) != buf
   #ifdef HOMEBREWDIR
                               && strstr(buf, HOMEBREWDIR) != buf
   #endif
                           ) {
                                 if (warnings) say("",                                  if (warnings) say("",
                                     "%s: outside base directory", buf);                                      "%s: outside base directory", buf);
                                 continue;                                  continue;
Line 668  treescan(void)
Line 673  treescan(void)
                                         say(path, "Skip pdf");                                          say(path, "Skip pdf");
                                 continue;                                  continue;
                         } else if ( ! use_all &&                          } else if ( ! use_all &&
                             ((FORM_SRC == dform && strcmp(fsec, dsec)) ||                              ((FORM_SRC == dform &&
                                 strncmp(fsec, dsec, strlen(dsec))) ||
                              (FORM_CAT == dform && strcmp(fsec, "0")))) {                               (FORM_CAT == dform && strcmp(fsec, "0")))) {
                                 if (warnings)                                  if (warnings)
                                         say(path, "Wrong filename suffix");                                          say(path, "Wrong filename suffix");
Line 818  filescan(const char *file)
Line 824  filescan(const char *file)
                 start = buf;                  start = buf;
         else if (strstr(buf, basedir) == buf)          else if (strstr(buf, basedir) == buf)
                 start = buf + strlen(basedir);                  start = buf + strlen(basedir);
   #ifdef HOMEBREWDIR
           else if (strstr(buf, HOMEBREWDIR) == buf)
                   start = buf;
   #endif
         else {          else {
                 exitcode = (int)MANDOCLEVEL_BADARG;                  exitcode = (int)MANDOCLEVEL_BADARG;
                 say("", "%s: outside base directory", buf);                  say("", "%s: outside base directory", buf);
Line 933  mlink_add(struct mlink *mlink, const struct stat *st)
Line 943  mlink_add(struct mlink *mlink, const struct stat *st)
         assert(NULL == ohash_find(&mlinks, slot));          assert(NULL == ohash_find(&mlinks, slot));
         ohash_insert(&mlinks, slot, mlink);          ohash_insert(&mlinks, slot, mlink);
   
           memset(&inodev, 0, sizeof(inodev));  /* Clear padding. */
         inodev.st_ino = st->st_ino;          inodev.st_ino = st->st_ino;
         inodev.st_dev = st->st_dev;          inodev.st_dev = st->st_dev;
         slot = ohash_lookup_memory(&mpages, (char *)&inodev,          slot = ohash_lookup_memory(&mpages, (char *)&inodev,
Line 1426  putmdockey(const struct mpage *mpage,
Line 1437  putmdockey(const struct mpage *mpage,
         for ( ; NULL != n; n = n->next) {          for ( ; NULL != n; n = n->next) {
                 if (NULL != n->child)                  if (NULL != n->child)
                         putmdockey(mpage, n->child, m);                          putmdockey(mpage, n->child, m);
                 if (MDOC_TEXT == n->type)                  if (n->type == ROFFT_TEXT)
                         putkey(mpage, n->string, m);                          putkey(mpage, n->string, m);
         }          }
 }  }
Line 1450  parse_man(struct mpage *mpage, const struct man_meta *
Line 1461  parse_man(struct mpage *mpage, const struct man_meta *
          * the correct section or not.           * the correct section or not.
          */           */
   
         if (MAN_BODY == n->type && MAN_SH == n->tok) {          if (n->type == ROFFT_BODY && n->tok == MAN_SH) {
                 body = n;                  body = n;
                 assert(body->parent);                  assert(body->parent);
                 if (NULL != (head = body->parent->head) &&                  if (NULL != (head = body->parent->head) &&
                     1 == head->nchild &&                      1 == head->nchild &&
                     NULL != (head = (head->child)) &&                      NULL != (head = (head->child)) &&
                     MAN_TEXT == head->type &&                      head->type == ROFFT_TEXT &&
                     0 == strcmp(head->string, "NAME") &&                      0 == strcmp(head->string, "NAME") &&
                     NULL != body->child) {                      NULL != body->child) {
   
Line 1565  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
Line 1576  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
         assert(NULL != n);          assert(NULL != n);
         for (n = n->child; NULL != n; n = n->next) {          for (n = n->child; NULL != n; n = n->next) {
                 switch (n->type) {                  switch (n->type) {
                 case MDOC_ELEM:                  case ROFFT_ELEM:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case MDOC_BLOCK:                  case ROFFT_BLOCK:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case MDOC_HEAD:                  case ROFFT_HEAD:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case MDOC_BODY:                  case ROFFT_BODY:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case MDOC_TAIL:                  case ROFFT_TAIL:
                         if (NULL != mdocs[n->tok].fp)                          if (NULL != mdocs[n->tok].fp)
                                if (0 == (*mdocs[n->tok].fp)(mpage, meta, n))                                 if (0 == (*mdocs[n->tok].fp)(mpage, meta, n))
                                        break;                                         break;
Line 1582  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
Line 1593  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
                                     mdocs[n->tok].mask);                                      mdocs[n->tok].mask);
                         break;                          break;
                 default:                  default:
                         assert(MDOC_ROOT != n->type);                          assert(n->type != ROFFT_ROOT);
                         continue;                          continue;
                 }                  }
                 if (NULL != n->child)                  if (NULL != n->child)
Line 1599  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
Line 1610  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
   
         if (SEC_SYNOPSIS != n->sec ||          if (SEC_SYNOPSIS != n->sec ||
             NULL == (n = n->child) ||              NULL == (n = n->child) ||
             MDOC_TEXT != n->type)              n->type != ROFFT_TEXT)
                 return(0);                  return(0);
   
         /*          /*
Line 1610  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
Line 1621  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
         if (strcmp("#include", n->string))          if (strcmp("#include", n->string))
                 return(0);                  return(0);
   
         if (NULL == (n = n->next) || MDOC_TEXT != n->type)          if ((n = n->next) == NULL || n->type != ROFFT_TEXT)
                 return(0);                  return(0);
   
         /*          /*
Line 1640  parse_mdoc_fname(struct mpage *mpage, const struct mdo
Line 1651  parse_mdoc_fname(struct mpage *mpage, const struct mdo
         char    *cp;          char    *cp;
         size_t   sz;          size_t   sz;
   
         if (n->type != MDOC_TEXT)          if (n->type != ROFFT_TEXT)
                 return;                  return;
   
         /* Skip function pointer punctuation. */          /* Skip function pointer punctuation. */
Line 1666  parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_m
Line 1677  parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_m
         parse_mdoc_fname(mpage, n->child);          parse_mdoc_fname(mpage, n->child);
   
         for (n = n->child->next; n != NULL; n = n->next)          for (n = n->child->next; n != NULL; n = n->next)
                 if (n->type == MDOC_TEXT)                  if (n->type == ROFFT_TEXT)
                         putkey(mpage, n->string, TYPE_Fa);                          putkey(mpage, n->string, TYPE_Fa);
   
         return(0);          return(0);
Line 1677  parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_m
Line 1688  parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_m
         const struct mdoc_node *n)          const struct mdoc_node *n)
 {  {
   
         if (n->type != MDOC_HEAD)          if (n->type != ROFFT_HEAD)
                 return(1);                  return(1);
   
         if (n->child != NULL)          if (n->child != NULL)
Line 1711  parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_m
Line 1722  parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_m
         const struct mdoc_node *n)          const struct mdoc_node *n)
 {  {
   
         if (MDOC_BODY == n->type)          if (n->type == ROFFT_BODY)
                 mdoc_deroff(&mpage->desc, n);                  mdoc_deroff(&mpage->desc, n);
         return(0);          return(0);
 }  }
Line 1723  parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_m
Line 1734  parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_m
   
         if (SEC_NAME == n->sec)          if (SEC_NAME == n->sec)
                 putmdockey(mpage, n->child, NAME_TITLE);                  putmdockey(mpage, n->child, NAME_TITLE);
         else if (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type) {          else if (n->sec == SEC_SYNOPSIS && n->type == ROFFT_HEAD) {
                 if (n->child == NULL)                  if (n->child == NULL)
                         putkey(mpage, meta->name, NAME_SYN);                          putkey(mpage, meta->name, NAME_SYN);
                 else                  else
Line 1732  parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_m
Line 1743  parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_m
         if ( ! (mpage->name_head_done ||          if ( ! (mpage->name_head_done ||
             n->child == NULL || n->child->string == NULL ||              n->child == NULL || n->child->string == NULL ||
             strcasecmp(n->child->string, meta->title))) {              strcasecmp(n->child->string, meta->title))) {
                 putkey(mpage, n->child->string, NAME_HEAD);                  putkey(mpage, n->child->string, ROFFT_HEAD);
                 mpage->name_head_done = 1;                  mpage->name_head_done = 1;
         }          }
         return(0);          return(0);
Line 1743  parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_m
Line 1754  parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_m
         const struct mdoc_node *n)          const struct mdoc_node *n)
 {  {
   
         return(SEC_CUSTOM == n->sec && MDOC_HEAD == n->type);          return(n->sec == SEC_CUSTOM && n->type == ROFFT_HEAD);
 }  }
   
 static int  static int
Line 1751  parse_mdoc_head(struct mpage *mpage, const struct mdoc
Line 1762  parse_mdoc_head(struct mpage *mpage, const struct mdoc
         const struct mdoc_node *n)          const struct mdoc_node *n)
 {  {
   
         return(MDOC_HEAD == n->type);          return(n->type == ROFFT_HEAD);
 }  }
   
 static int  static int
Line 1759  parse_mdoc_body(struct mpage *mpage, const struct mdoc
Line 1770  parse_mdoc_body(struct mpage *mpage, const struct mdoc
         const struct mdoc_node *n)          const struct mdoc_node *n)
 {  {
   
         return(MDOC_BODY == n->type);          return(n->type == ROFFT_BODY);
 }  }
   
 /*  /*

Legend:
Removed from v.1.183  
changed lines
  Added in v.1.188

CVSweb