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

Diff for /docbook2mdoc/parse.c between version 1.32 and 1.35

version 1.32, 2019/04/11 04:23:22 version 1.35, 2019/04/12 06:46:45
Line 322  warn_msg(struct parse *p, const char *fmt, ...)
Line 322  warn_msg(struct parse *p, const char *fmt, ...)
  * Otherwise, create a new one as a child of the current node.   * Otherwise, create a new one as a child of the current node.
  */   */
 static void  static void
 xml_char(struct parse *p, const char *word, int sz)  xml_text(struct parse *p, const char *word, int sz)
 {  {
         struct pnode    *n;          struct pnode    *n, *np;
         size_t           oldsz, newsz;          size_t           oldsz, newsz;
           int              i;
   
         assert(sz > 0);          assert(sz > 0);
         if (p->del > 0)          if (p->del > 0)
                 return;                  return;
   
         if ((n = p->cur) == NULL) {          if ((n = p->cur) == NULL) {
                 error_msg(p, "discarding text before document: %.*s", sz, word);                  error_msg(p, "discarding text before document: %.*s",
                       sz, word);
                 return;                  return;
         }          }
   
         if (n->node != NODE_TEXT) {          /* Append to the current text node, if one is open. */
                 if ((n = calloc(1, sizeof(*n))) == NULL)  
           if (n->node == NODE_TEXT) {
                   oldsz = strlen(n->b);
                   newsz = oldsz + sz;
                   if (oldsz && (p->flags & PFLAG_SPC))
                           newsz++;
                   if ((n->b = realloc(n->b, newsz + 1)) == NULL)
                         fatal(p);                          fatal(p);
                 n->node = NODE_TEXT;                  if (oldsz && (p->flags & PFLAG_SPC))
                 n->spc = (p->flags & PFLAG_SPC) != 0;                          n->b[oldsz++] = ' ';
                 n->parent = p->cur;                  memcpy(n->b + oldsz, word, sz);
                 TAILQ_INIT(&n->childq);                  n->b[newsz] = '\0';
                 TAILQ_INIT(&n->attrq);                  p->flags &= ~PFLAG_SPC;
                 TAILQ_INSERT_TAIL(&p->cur->childq, n, child);                  return;
                 p->cur = n;  
         }          }
   
         if (p->tree->flags & TREE_CLOSED && n->parent == p->tree->root)          if (p->tree->flags & TREE_CLOSED && n == p->tree->root)
                 warn_msg(p, "text after end of document: %.*s", sz, word);                  warn_msg(p, "text after end of document: %.*s", sz, word);
   
         /* Append to the current text node. */          /* Create a new text node. */
   
         oldsz = n->b == NULL ? 0 : strlen(n->b);          if ((n = pnode_alloc(p->cur)) == NULL)
         newsz = oldsz + sz;  
         if (oldsz && (p->flags & PFLAG_SPC))  
                 newsz++;  
         if ((n->b = realloc(n->b, newsz + 1)) == NULL)  
                 fatal(p);                  fatal(p);
         if (oldsz && (p->flags & PFLAG_SPC))          n->node = NODE_TEXT;
                 n->b[oldsz++] = ' ';          n->spc = (p->flags & PFLAG_SPC) != 0;
         memcpy(n->b + oldsz, word, sz);  
         n->b[newsz] = '\0';  
         p->flags &= ~PFLAG_SPC;          p->flags &= ~PFLAG_SPC;
   
           /*
            * If this node follows a non-text node without intervening
            * whitespace, keep the text in it as short as possible,
            * and do not keep it open.
            */
   
           if (n->spc == 0 &&
               (np = TAILQ_PREV(n, pnodeq, child)) != NULL &&
               np->node != NODE_TEXT && np->node != NODE_ESCAPE) {
                   i = 0;
                   while (i < sz && !isspace((unsigned char)word[i]))
                           i++;
                   if ((n->b = strndup(word, i)) == NULL)
                           fatal(p);
                   if (i == sz)
                           return;
                   while (i < sz && isspace((unsigned char)word[i]))
                           i++;
                   if (i == sz) {
                           p->flags |= PFLAG_SPC;
                           return;
                   }
   
                   /* Put any remaining text into a second node. */
   
                   if ((n = pnode_alloc(p->cur)) == NULL)
                           fatal(p);
                   n->node = NODE_TEXT;
                   n->spc = 1;
                   word += i;
                   sz -= i;
           }
           if ((n->b = strndup(word, sz)) == NULL)
                   fatal(p);
   
           /* The new node remains open for later pnode_closetext(). */
   
           p->cur = n;
 }  }
   
 /*  /*
Line 440  xml_entity(struct parse *p, const char *name)
Line 480  xml_entity(struct parse *p, const char *name)
         }          }
   
         /* Create, append, and close out an entity node. */          /* Create, append, and close out an entity node. */
         if ((n = calloc(1, sizeof(*n))) == NULL ||          if ((n = pnode_alloc(p->cur)) == NULL ||
             (n->b = strdup(entity->roff)) == NULL)              (n->b = strdup(entity->roff)) == NULL)
                 fatal(p);                  fatal(p);
         n->node = NODE_ESCAPE;          n->node = NODE_ESCAPE;
         n->spc = (p->flags & PFLAG_SPC) != 0;          n->spc = (p->flags & PFLAG_SPC) != 0;
         n->parent = p->cur;  
         TAILQ_INIT(&n->childq);  
         TAILQ_INIT(&n->attrq);  
         TAILQ_INSERT_TAIL(&p->cur->childq, n, child);  
         p->flags &= ~PFLAG_SPC;          p->flags &= ~PFLAG_SPC;
 }  }
   
Line 504  xml_elem_start(struct parse *p, const char *name)
Line 540  xml_elem_start(struct parse *p, const char *name)
         if (p->tree->flags & TREE_CLOSED && p->cur->parent == NULL)          if (p->tree->flags & TREE_CLOSED && p->cur->parent == NULL)
                 warn_msg(p, "element after end of document: <%s>", name);                  warn_msg(p, "element after end of document: <%s>", name);
   
         if ((n = calloc(1, sizeof(*n))) == NULL)          if ((n = pnode_alloc(p->cur)) == NULL)
                 fatal(p);                  fatal(p);
   
         /*          /*
Line 556  xml_elem_start(struct parse *p, const char *name)
Line 592  xml_elem_start(struct parse *p, const char *name)
                 n->spc = (p->flags & PFLAG_SPC) != 0;                  n->spc = (p->flags & PFLAG_SPC) != 0;
                 break;                  break;
         }          }
         n->parent = p->cur;  
         TAILQ_INIT(&n->childq);  
         TAILQ_INIT(&n->attrq);  
   
         if (p->cur != NULL)  
                 TAILQ_INSERT_TAIL(&p->cur->childq, n, child);  
   
         p->cur = n;          p->cur = n;
         if (n->node == NODE_DOCTYPE) {          if (n->node == NODE_DOCTYPE) {
                 if (p->doctype == NULL)                  if (p->doctype == NULL)
Line 972  parse_string(struct parse *p, char *b, size_t rlen,
Line 1001  parse_string(struct parse *p, char *b, size_t rlen,
   
                 } else {                  } else {
                         advance(p, b, rlen, &pend,                          advance(p, b, rlen, &pend,
                             p->ncur == NODE_DOCTYPE ? "<&]" : "<&",                              p->ncur == NODE_DOCTYPE ? "<&]\n" : "<&\n",
                             refill);                              refill);
                         xml_char(p, b + poff, pend - poff);                          xml_text(p, b + poff, pend - poff);
                           if (b[pend] == '\n')
                                   pnode_closetext(p);
                 }                  }
         }          }
         return poff;          return poff;

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.35

CVSweb