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

Diff for /mandoc/mandocdb.c between version 1.187 and 1.194

version 1.187, 2015/03/27 17:37:25 version 1.194, 2015/04/23 16:17:44
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 "mandoc_aux.h"  
 #include "manconf.h"  #include "manconf.h"
 #include "mansearch.h"  #include "mansearch.h"
   
Line 129  enum stmt {
Line 130  enum stmt {
         STMT__MAX          STMT__MAX
 };  };
   
 typedef int (*mdoc_fp)(struct mpage *, const struct mdoc_meta *,  typedef int (*mdoc_fp)(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
   
 struct  mdoc_handler {  struct  mdoc_handler {
         mdoc_fp          fp; /* optional handler */          mdoc_fp          fp; /* optional handler */
Line 155  static void  mpages_free(void);
Line 156  static void  mpages_free(void);
 static  void     mpages_merge(struct mparse *);  static  void     mpages_merge(struct mparse *);
 static  void     names_check(void);  static  void     names_check(void);
 static  void     parse_cat(struct mpage *, int);  static  void     parse_cat(struct mpage *, int);
 static  void     parse_man(struct mpage *, const struct man_meta *,  static  void     parse_man(struct mpage *, const struct roff_meta *,
                         const struct man_node *);                          const struct roff_node *);
 static  void     parse_mdoc(struct mpage *, const struct mdoc_meta *,  static  void     parse_mdoc(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_body(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_body(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_head(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_head(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_Fd(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Fd(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  void     parse_mdoc_fname(struct mpage *, const struct mdoc_node *);  static  void     parse_mdoc_fname(struct mpage *, const struct roff_node *);
 static  int      parse_mdoc_Fn(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Fn(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_Fo(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Fo(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_Nd(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Nd(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_Nm(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Nm(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_Sh(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Sh(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  int      parse_mdoc_Xr(struct mpage *, const struct mdoc_meta *,  static  int      parse_mdoc_Xr(struct mpage *, const struct roff_meta *,
                         const struct mdoc_node *);                          const struct roff_node *);
 static  void     putkey(const struct mpage *, char *, uint64_t);  static  void     putkey(const struct mpage *, char *, uint64_t);
 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 mdoc_node *, uint64_t);                          const struct roff_node *, uint64_t);
 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 *, ...);
 static  int      set_basedir(const char *, int);  static  int      set_basedir(const char *, int);
Line 1106  mpages_merge(struct mparse *mp)
Line 1107  mpages_merge(struct mparse *mp)
         struct ohash_info        str_info;          struct ohash_info        str_info;
         struct mpage            *mpage, *mpage_dest;          struct mpage            *mpage, *mpage_dest;
         struct mlink            *mlink, *mlink_dest;          struct mlink            *mlink, *mlink_dest;
         struct mdoc             *mdoc;          struct roff_man         *man;
         struct man              *man;  
         char                    *sodest;          char                    *sodest;
         char                    *cp;          char                    *cp;
         int                      fd;          int                      fd;
Line 1134  mpages_merge(struct mparse *mp)
Line 1134  mpages_merge(struct mparse *mp)
                 ohash_init(&names, 4, &str_info);                  ohash_init(&names, 4, &str_info);
                 ohash_init(&strings, 6, &str_info);                  ohash_init(&strings, 6, &str_info);
                 mparse_reset(mp);                  mparse_reset(mp);
                 mdoc = NULL;  
                 man = NULL;                  man = NULL;
                 sodest = NULL;                  sodest = NULL;
   
Line 1150  mpages_merge(struct mparse *mp)
Line 1149  mpages_merge(struct mparse *mp)
                  */                   */
                 if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) {                  if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) {
                         mparse_readfd(mp, fd, mlink->file);                          mparse_readfd(mp, fd, mlink->file);
                         mparse_result(mp, &mdoc, &man, &sodest);                          mparse_result(mp, &man, &sodest);
                 }                  }
   
                 if (sodest != NULL) {                  if (sodest != NULL) {
Line 1194  mpages_merge(struct mparse *mp)
Line 1193  mpages_merge(struct mparse *mp)
                                 mpage->mlinks = NULL;                                  mpage->mlinks = NULL;
                         }                          }
                         goto nextpage;                          goto nextpage;
                 } else if (mdoc != NULL) {                  } else if (man != NULL && man->macroset == MACROSET_MDOC) {
                         mpage->form = FORM_SRC;                          mpage->form = FORM_SRC;
                         mpage->sec = mdoc_meta(mdoc)->msec;                          mpage->sec = man->meta.msec;
                         mpage->sec = mandoc_strdup(                          mpage->sec = mandoc_strdup(
                             mpage->sec == NULL ? "" : mpage->sec);                              mpage->sec == NULL ? "" : mpage->sec);
                         mpage->arch = mdoc_meta(mdoc)->arch;                          mpage->arch = man->meta.arch;
                         mpage->arch = mandoc_strdup(                          mpage->arch = mandoc_strdup(
                             mpage->arch == NULL ? "" : mpage->arch);                              mpage->arch == NULL ? "" : mpage->arch);
                         mpage->title =                          mpage->title = mandoc_strdup(man->meta.title);
                             mandoc_strdup(mdoc_meta(mdoc)->title);                  } else if (man != NULL && man->macroset == MACROSET_MAN) {
                 } else if (man != NULL) {  
                         mpage->form = FORM_SRC;                          mpage->form = FORM_SRC;
                         mpage->sec = mandoc_strdup(man_meta(man)->msec);                          mpage->sec = mandoc_strdup(man->meta.msec);
                         mpage->arch = mandoc_strdup(mlink->arch);                          mpage->arch = mandoc_strdup(mlink->arch);
                         mpage->title = mandoc_strdup(man_meta(man)->title);                          mpage->title = mandoc_strdup(man->meta.title);
                 } else {                  } else {
                         mpage->form = FORM_CAT;                          mpage->form = FORM_CAT;
                         mpage->sec = mandoc_strdup(mlink->dsec);                          mpage->sec = mandoc_strdup(mlink->dsec);
Line 1230  mpages_merge(struct mparse *mp)
Line 1228  mpages_merge(struct mparse *mp)
                 }                  }
   
                 assert(mpage->desc == NULL);                  assert(mpage->desc == NULL);
                 if (mdoc != NULL)                  if (man != NULL && man->macroset == MACROSET_MDOC)
                         parse_mdoc(mpage, mdoc_meta(mdoc), mdoc_node(mdoc));                          parse_mdoc(mpage, &man->meta, man->first);
                 else if (man != NULL)                  else if (man != NULL)
                         parse_man(mpage, man_meta(man), man_node(man));                          parse_man(mpage, &man->meta, man->first);
                 else                  else
                         parse_cat(mpage, fd);                          parse_cat(mpage, fd);
                 if (mpage->desc == NULL)                  if (mpage->desc == NULL)
Line 1430  putkey(const struct mpage *mpage, char *value, uint64_
Line 1428  putkey(const struct mpage *mpage, char *value, uint64_
  */   */
 static void  static void
 putmdockey(const struct mpage *mpage,  putmdockey(const struct mpage *mpage,
         const struct mdoc_node *n, uint64_t m)          const struct roff_node *n, uint64_t m)
 {  {
   
         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);
         }          }
 }  }
   
 static void  static void
 parse_man(struct mpage *mpage, const struct man_meta *meta,  parse_man(struct mpage *mpage, const struct roff_meta *meta,
         const struct man_node *n)          const struct roff_node *n)
 {  {
         const struct man_node *head, *body;          const struct roff_node *head, *body;
         char            *start, *title;          char            *start, *title;
         char             byte;          char             byte;
         size_t           sz;          size_t           sz;
Line 1460  parse_man(struct mpage *mpage, const struct man_meta *
Line 1458  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 1478  parse_man(struct mpage *mpage, const struct man_meta *
Line 1476  parse_man(struct mpage *mpage, const struct man_meta *
                          */                           */
   
                         title = NULL;                          title = NULL;
                         man_deroff(&title, body);                          deroff(&title, body);
                         if (NULL == title)                          if (NULL == title)
                                 return;                                  return;
   
Line 1568  parse_man(struct mpage *mpage, const struct man_meta *
Line 1566  parse_man(struct mpage *mpage, const struct man_meta *
 }  }
   
 static void  static void
 parse_mdoc(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         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 1592  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
Line 1590  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 1601  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
Line 1599  parse_mdoc(struct mpage *mpage, const struct mdoc_meta
 }  }
   
 static int  static int
 parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Fd(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
         char            *start, *end;          char            *start, *end;
         size_t           sz;          size_t           sz;
   
         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 1620  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
Line 1618  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 1645  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
Line 1643  parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_m
 }  }
   
 static void  static void
 parse_mdoc_fname(struct mpage *mpage, const struct mdoc_node *n)  parse_mdoc_fname(struct mpage *mpage, const struct roff_node *n)
 {  {
         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_fname(struct mpage *mpage, const struct mdo
Line 1664  parse_mdoc_fname(struct mpage *mpage, const struct mdo
 }  }
   
 static int  static int
 parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Fn(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         if (n->child == NULL)          if (n->child == NULL)
Line 1676  parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_m
Line 1674  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);
 }  }
   
 static int  static int
 parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Fo(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_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 1697  parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_m
Line 1695  parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_m
 }  }
   
 static int  static int
 parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Xr(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
         char    *cp;          char    *cp;
   
Line 1717  parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_m
Line 1715  parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_m
 }  }
   
 static int  static int
 parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Nd(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         if (MDOC_BODY == n->type)          if (n->type == ROFFT_BODY)
                 mdoc_deroff(&mpage->desc, n);                  deroff(&mpage->desc, n);
         return(0);          return(0);
 }  }
   
 static int  static int
 parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Nm(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         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 1742  parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_m
Line 1740  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);
 }  }
   
 static int  static int
 parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_Sh(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         return(SEC_CUSTOM == n->sec && MDOC_HEAD == n->type);          return(n->sec == SEC_CUSTOM && n->type == ROFFT_HEAD);
 }  }
   
 static int  static int
 parse_mdoc_head(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_head(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         return(MDOC_HEAD == n->type);          return(n->type == ROFFT_HEAD);
 }  }
   
 static int  static int
 parse_mdoc_body(struct mpage *mpage, const struct mdoc_meta *meta,  parse_mdoc_body(struct mpage *mpage, const struct roff_meta *meta,
         const struct mdoc_node *n)          const struct roff_node *n)
 {  {
   
         return(MDOC_BODY == n->type);          return(n->type == ROFFT_BODY);
 }  }
   
 /*  /*

Legend:
Removed from v.1.187  
changed lines
  Added in v.1.194

CVSweb