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

Diff for /mandoc/mandocdb.c between version 1.176 and 1.184

version 1.176, 2014/12/05 14:26:40 version 1.184, 2015/01/21 22:41:49
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, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 165  static int  parse_mdoc_head(struct mpage *, const stru
Line 165  static int  parse_mdoc_head(struct mpage *, const stru
                         const struct mdoc_node *);                          const struct mdoc_node *);
 static  int      parse_mdoc_Fd(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Fd(struct mpage *, const struct mdoc_meta *,
                         const struct mdoc_node *);                          const struct mdoc_node *);
   static  void     parse_mdoc_fname(struct mpage *, const struct mdoc_node *);
 static  int      parse_mdoc_Fn(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Fn(struct mpage *, const struct mdoc_meta *,
                         const struct mdoc_node *);                          const struct mdoc_node *);
 static  int      parse_mdoc_Fo(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Fo(struct mpage *, const struct mdoc_meta *,
Line 335  static const struct mdoc_handler mdocs[MDOC_MAX] = {
Line 336  static const struct mdoc_handler mdocs[MDOC_MAX] = {
   
   
 int  int
 main(int argc, char *argv[])  mandocdb(int argc, char *argv[])
 {  {
         int               ch, i;          int               ch, i;
         size_t            j, sz;          size_t            j, sz;
Line 349  main(int argc, char *argv[])
Line 350  main(int argc, char *argv[])
   
         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;
         mpages_info.free  = mlinks_info.free  = hash_free;          mpages_info.free   = mlinks_info.free   = hash_free;
           mpages_info.data   = mlinks_info.data   = NULL;
   
         mpages_info.key_offset = offsetof(struct mpage, inodev);          mpages_info.key_offset = offsetof(struct mpage, inodev);
         mlinks_info.key_offset = offsetof(struct mlink, file);          mlinks_info.key_offset = offsetof(struct mlink, file);
Line 440  main(int argc, char *argv[])
Line 442  main(int argc, char *argv[])
   
         exitcode = (int)MANDOCLEVEL_OK;          exitcode = (int)MANDOCLEVEL_OK;
         mchars = mchars_alloc();          mchars = mchars_alloc();
         mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL,          mp = mparse_alloc(mparse_options, MANDOCLEVEL_BADARG, NULL,
             mchars, NULL);              mchars, NULL);
         ohash_init(&mpages, 6, &mpages_info);          ohash_init(&mpages, 6, &mpages_info);
         ohash_init(&mlinks, 6, &mlinks_info);          ohash_init(&mlinks, 6, &mlinks_info);
Line 611  treescan(void)
Line 613  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 816  filescan(const char *file)
Line 822  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 851  filescan(const char *file)
Line 861  filescan(const char *file)
         if (strlcpy(mlink->file, start, sizeof(mlink->file)) >=          if (strlcpy(mlink->file, start, sizeof(mlink->file)) >=
             sizeof(mlink->file)) {              sizeof(mlink->file)) {
                 say(start, "Filename too long");                  say(start, "Filename too long");
                   free(mlink);
                 return;                  return;
         }          }
   
Line 1099  mpages_merge(struct mparse *mp)
Line 1110  mpages_merge(struct mparse *mp)
         char                    *cp;          char                    *cp;
         int                      fd;          int                      fd;
         unsigned int             pslot;          unsigned int             pslot;
         enum mandoclevel         lvl;  
   
         str_info.alloc = hash_alloc;          str_info.alloc = hash_alloc;
         str_info.calloc = hash_calloc;          str_info.calloc = hash_calloc;
         str_info.free = hash_free;          str_info.free = hash_free;
           str_info.data = NULL;
         str_info.key_offset = offsetof(struct str, key);          str_info.key_offset = offsetof(struct str, key);
   
         if ( ! nodb)          if ( ! nodb)
Line 1112  mpages_merge(struct mparse *mp)
Line 1123  mpages_merge(struct mparse *mp)
         mpage = ohash_first(&mpages, &pslot);          mpage = ohash_first(&mpages, &pslot);
         while (mpage != NULL) {          while (mpage != NULL) {
                 mlinks_undupe(mpage);                  mlinks_undupe(mpage);
                 if (mpage->mlinks == NULL) {                  if ((mlink = mpage->mlinks) == NULL) {
                         mpage = ohash_next(&mpages, &pslot);                          mpage = ohash_next(&mpages, &pslot);
                         continue;                          continue;
                 }                  }
Line 1125  mpages_merge(struct mparse *mp)
Line 1136  mpages_merge(struct mparse *mp)
                 man = NULL;                  man = NULL;
                 sodest = NULL;                  sodest = NULL;
   
                 mparse_open(mp, &fd, mpage->mlinks->file);                  mparse_open(mp, &fd, mlink->file);
                 if (fd == -1) {                  if (fd == -1) {
                         say(mpage->mlinks->file, "&open");                          say(mlink->file, "&open");
                         goto nextpage;                          goto nextpage;
                 }                  }
   
                 /*                  /*
                  * Try interpreting the file as mdoc(7) or man(7)                   * Interpret the file as mdoc(7) or man(7) source
                  * source code, unless it is already known to be                   * code, unless it is known to be formatted.
                  * formatted.  Fall back to formatted mode.  
                  */                   */
                 if (mpage->mlinks->dform != FORM_CAT ||                  if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) {
                     mpage->mlinks->fform != FORM_CAT) {                          mparse_readfd(mp, fd, mlink->file);
                         lvl = mparse_readfd(mp, fd, mpage->mlinks->file);                          mparse_result(mp, &mdoc, &man, &sodest);
                         if (lvl < MANDOCLEVEL_FATAL)  
                                 mparse_result(mp, &mdoc, &man, &sodest);  
                 }                  }
   
                 if (sodest != NULL) {                  if (sodest != NULL) {
Line 1157  mpages_merge(struct mparse *mp)
Line 1165  mpages_merge(struct mparse *mp)
                                 /* The .so target exists. */                                  /* The .so target exists. */
   
                                 mpage_dest = mlink_dest->mpage;                                  mpage_dest = mlink_dest->mpage;
                                 mlink = mpage->mlinks;  
                                 while (1) {                                  while (1) {
                                         mlink->mpage = mpage_dest;                                          mlink->mpage = mpage_dest;
   
Line 1197  mpages_merge(struct mparse *mp)
Line 1204  mpages_merge(struct mparse *mp)
                             mandoc_strdup(mdoc_meta(mdoc)->title);                              mandoc_strdup(mdoc_meta(mdoc)->title);
                 } else if (man != NULL) {                  } else if (man != NULL) {
                         mpage->form = FORM_SRC;                          mpage->form = FORM_SRC;
                         mpage->sec =                          mpage->sec = mandoc_strdup(man_meta(man)->msec);
                             mandoc_strdup(man_meta(man)->msec);                          mpage->arch = mandoc_strdup(mlink->arch);
                         mpage->arch =                          mpage->title = mandoc_strdup(man_meta(man)->title);
                             mandoc_strdup(mpage->mlinks->arch);  
                         mpage->title =  
                             mandoc_strdup(man_meta(man)->title);  
                 } else {                  } else {
                         mpage->form = FORM_CAT;                          mpage->form = FORM_CAT;
                         mpage->sec =                          mpage->sec = mandoc_strdup(mlink->dsec);
                             mandoc_strdup(mpage->mlinks->dsec);                          mpage->arch = mandoc_strdup(mlink->arch);
                         mpage->arch =                          mpage->title = mandoc_strdup(mlink->name);
                             mandoc_strdup(mpage->mlinks->arch);  
                         mpage->title =  
                             mandoc_strdup(mpage->mlinks->name);  
                 }                  }
                 putkey(mpage, mpage->sec, TYPE_sec);                  putkey(mpage, mpage->sec, TYPE_sec);
                 if (*mpage->arch != '\0')                  if (*mpage->arch != '\0')
                         putkey(mpage, mpage->arch, TYPE_arch);                          putkey(mpage, mpage->arch, TYPE_arch);
   
                 for (mlink = mpage->mlinks; mlink; mlink = mlink->next) {                  for ( ; mlink != NULL; mlink = mlink->next) {
                         if ('\0' != *mlink->dsec)                          if ('\0' != *mlink->dsec)
                                 putkey(mpage, mlink->dsec, TYPE_sec);                                  putkey(mpage, mlink->dsec, TYPE_sec);
                         if ('\0' != *mlink->fsec)                          if ('\0' != *mlink->fsec)
Line 1242  mpages_merge(struct mparse *mp)
Line 1243  mpages_merge(struct mparse *mp)
                                 mlink_check(mpage, mlink);                                  mlink_check(mpage, mlink);
   
                 dbadd(mpage);                  dbadd(mpage);
                   mlink = mpage->mlinks;
   
 nextpage:  nextpage:
                 if (mparse_wait(mp) != MANDOCLEVEL_OK) {                  if (mparse_wait(mp) != MANDOCLEVEL_OK) {
                         exitcode = (int)MANDOCLEVEL_SYSERR;                          exitcode = (int)MANDOCLEVEL_SYSERR;
                         say(mpage->mlinks->file, "&wait gunzip");                          say(mlink->file, "&wait gunzip");
                 }                  }
                 ohash_delete(&strings);                  ohash_delete(&strings);
                 ohash_delete(&names);                  ohash_delete(&names);
Line 1640  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
Line 1642  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
         return(0);          return(0);
 }  }
   
 static int  static void
 parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_fname(struct mpage *mpage, const struct mdoc_node *n)
         const struct mdoc_node *n)  
 {  {
         char    *cp;          char    *cp;
           size_t   sz;
   
         if (NULL == (n = n->child) || MDOC_TEXT != n->type)          if (n->type != MDOC_TEXT)
                 return(0);                  return;
   
         /*          /* Skip function pointer punctuation. */
          * Parse: .Fn "struct type *name" "char *arg".  
          * First strip away pointer symbol.  
          * Then store the function name, then type.  
          * Finally, store the arguments.  
          */  
   
         if (NULL == (cp = strrchr(n->string, ' ')))          cp = n->string;
                 cp = n->string;          while (*cp == '(' || *cp == '*')
   
         while ('*' == *cp)  
                 cp++;                  cp++;
           sz = strcspn(cp, "()");
   
         putkey(mpage, cp, TYPE_Fn);          putkeys(mpage, cp, sz, TYPE_Fn);
         if (n->sec == SEC_SYNOPSIS)          if (n->sec == SEC_SYNOPSIS)
                 putkey(mpage, cp, NAME_SYN);                  putkeys(mpage, cp, sz, NAME_SYN);
   }
   
         if (n->string < cp)  static int
                 putkeys(mpage, n->string, cp - n->string, TYPE_Ft);  parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta,
           const struct mdoc_node *n)
   {
   
         for (n = n->next; NULL != n; n = n->next)          if (n->child == NULL)
                 if (MDOC_TEXT == n->type)                  return(0);
   
           parse_mdoc_fname(mpage, n->child);
   
           for (n = n->child->next; n != NULL; n = n->next)
                   if (n->type == MDOC_TEXT)
                         putkey(mpage, n->string, TYPE_Fa);                          putkey(mpage, n->string, TYPE_Fa);
   
         return(0);          return(0);
Line 1681  parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_m
Line 1685  parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_m
         const struct mdoc_node *n)          const struct mdoc_node *n)
 {  {
   
         putmdockey(mpage, n->child, TYPE_Fn);          if (n->type != MDOC_HEAD)
         if (n->sec == SEC_SYNOPSIS)                  return(1);
                 putmdockey(mpage, n->child, NAME_SYN);  
           if (n->child != NULL)
                   parse_mdoc_fname(mpage, n->child);
   
         return(0);          return(0);
 }  }
   

Legend:
Removed from v.1.176  
changed lines
  Added in v.1.184

CVSweb