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

Diff for /mandoc/mandocdb.c between version 1.118 and 1.122

version 1.118, 2014/03/19 22:33:09 version 1.122, 2014/03/23 12:44:56
Line 46 
Line 46 
 #include "mdoc.h"  #include "mdoc.h"
 #include "man.h"  #include "man.h"
 #include "mandoc.h"  #include "mandoc.h"
   #include "mandoc_aux.h"
 #include "manpath.h"  #include "manpath.h"
 #include "mansearch.h"  #include "mansearch.h"
   
Line 1262  static void
Line 1263  static void
 parse_man(struct mpage *mpage, const struct man_node *n)  parse_man(struct mpage *mpage, const struct man_node *n)
 {  {
         const struct man_node *head, *body;          const struct man_node *head, *body;
         char            *start, *sv, *title;          char            *start, *title;
         char             byte;          char             byte;
         size_t           sz, titlesz;          size_t           sz;
   
         if (NULL == n)          if (NULL == n)
                 return;                  return;
Line 1284  parse_man(struct mpage *mpage, const struct man_node *
Line 1285  parse_man(struct mpage *mpage, const struct man_node *
                                 NULL != (head = (head->child)) &&                                  NULL != (head = (head->child)) &&
                                 MAN_TEXT == head->type &&                                  MAN_TEXT == head->type &&
                                 0 == strcmp(head->string, "NAME") &&                                  0 == strcmp(head->string, "NAME") &&
                                 NULL != (body = body->child) &&                                  NULL != body->child) {
                                 MAN_TEXT == body->type) {  
   
                         title = NULL;  
                         titlesz = 0;  
   
                         /*                          /*
                          * Suck the entire NAME section into memory.                           * Suck the entire NAME section into memory.
                          * Yes, we might run away.                           * Yes, we might run away.
Line 1297  parse_man(struct mpage *mpage, const struct man_node *
Line 1294  parse_man(struct mpage *mpage, const struct man_node *
                          * NAME sections over many lines.                           * NAME sections over many lines.
                          */                           */
   
                         for ( ; NULL != body; body = body->next) {                          title = NULL;
                                 if (MAN_TEXT != body->type)                          man_deroff(&title, body);
                                         break;  
                                 if (0 == (sz = strlen(body->string)))  
                                         continue;  
                                 title = mandoc_realloc  
                                         (title, titlesz + sz + 1);  
                                 memcpy(title + titlesz, body->string, sz);  
                                 titlesz += sz + 1;  
                                 title[titlesz - 1] = ' ';  
                         }  
                         if (NULL == title)                          if (NULL == title)
                                 return;                                  return;
   
                         title = mandoc_realloc(title, titlesz + 1);  
                         title[titlesz] = '\0';  
   
                         /* Skip leading space.  */  
   
                         sv = title;  
                         while (isspace((unsigned char)*sv))  
                                 sv++;  
   
                         if (0 == (sz = strlen(sv))) {  
                                 free(title);  
                                 return;  
                         }  
   
                         /* Erase trailing space. */  
   
                         start = &sv[sz - 1];  
                         while (start > sv && isspace((unsigned char)*start))  
                                 *start-- = '\0';  
   
                         if (start == sv) {  
                                 free(title);  
                                 return;  
                         }  
   
                         start = sv;  
   
                         /*                          /*
                          * Go through a special heuristic dance here.                           * Go through a special heuristic dance here.
                          * Conventionally, one or more manual names are                           * Conventionally, one or more manual names are
Line 1346  parse_man(struct mpage *mpage, const struct man_node *
Line 1307  parse_man(struct mpage *mpage, const struct man_node *
                          * the name parts here.                           * the name parts here.
                          */                           */
   
                           start = title;
                         for ( ;; ) {                          for ( ;; ) {
                                 sz = strcspn(start, " ,");                                  sz = strcspn(start, " ,");
                                 if ('\0' == start[sz])                                  if ('\0' == start[sz])
Line 1376  parse_man(struct mpage *mpage, const struct man_node *
Line 1338  parse_man(struct mpage *mpage, const struct man_node *
                                         start++;                                          start++;
                         }                          }
   
                         if (sv == start) {                          if (start == title) {
                                 putkey(mpage, start, TYPE_Nm);                                  putkey(mpage, start, TYPE_Nm);
                                 free(title);                                  free(title);
                                 return;                                  return;
Line 1535  parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_n
Line 1497  parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_n
                 return(0);                  return(0);
         }          }
   
         if (-1 == asprintf(&cp, "%s(%s)", n->string, n->next->string)) {          mandoc_asprintf(&cp, "%s(%s)", n->string, n->next->string);
                 perror(NULL);  
                 exit((int)MANDOCLEVEL_SYSERR);  
         }  
         putkey(mpage, cp, TYPE_Xr);          putkey(mpage, cp, TYPE_Xr);
         free(cp);          free(cp);
         return(0);          return(0);
Line 1547  parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_n
Line 1506  parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_n
 static int  static int
 parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n)  parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n)
 {  {
         size_t           sz;  
   
         if (MDOC_BODY != n->type)          if (MDOC_BODY == n->type)
                 return(0);                  mdoc_deroff(&mpage->desc, n);
           return(0);
         /*  
          * Special-case the `Nd' because we need to put the description  
          * into the document table.  
          */  
   
         for (n = n->child; NULL != n; n = n->next) {  
                 if (MDOC_TEXT == n->type) {  
                         if (NULL != mpage->desc) {  
                                 sz = strlen(mpage->desc) +  
                                      strlen(n->string) + 2;  
                                 mpage->desc = mandoc_realloc(  
                                     mpage->desc, sz);  
                                 strlcat(mpage->desc, " ", sz);  
                                 strlcat(mpage->desc, n->string, sz);  
                         } else  
                                 mpage->desc = mandoc_strdup(n->string);  
                 }  
                 if (NULL != n->child)  
                         parse_mdoc_Nd(mpage, n);  
         }  
         return(1);  
 }  }
   
 static int  static int

Legend:
Removed from v.1.118  
changed lines
  Added in v.1.122

CVSweb