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

Diff for /docbook2mdoc/parse.c between version 1.52 and 1.53

version 1.52, 2019/04/25 17:57:59 version 1.53, 2019/04/28 15:03:29
Line 15 
Line 15 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
 #include <errno.h>  #include <errno.h>
Line 26 
Line 28 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
   #include "xmalloc.h"
 #include "node.h"  #include "node.h"
 #include "parse.h"  #include "parse.h"
   
Line 192  static void  parse_fd(struct parse *, int);
Line 195  static void  parse_fd(struct parse *, int);
   
   
 static void  static void
 fatal(struct parse *p)  
 {  
         fprintf(stderr, "%s:%d:%d: FATAL: ", p->fname, p->line, p->col);  
         perror(NULL);  
         exit(6);  
 }  
   
 static void  
 error_msg(struct parse *p, const char *fmt, ...)  error_msg(struct parse *p, const char *fmt, ...)
 {  {
         va_list          ap;          va_list          ap;
Line 257  xml_text(struct parse *p, const char *word, int sz)
Line 252  xml_text(struct parse *p, const char *word, int sz)
                 newsz = oldsz + sz;                  newsz = oldsz + sz;
                 if (oldsz && (p->flags & PFLAG_SPC))                  if (oldsz && (p->flags & PFLAG_SPC))
                         newsz++;                          newsz++;
                 if ((n->b = realloc(n->b, newsz + 1)) == NULL)                  n->b = xrealloc(n->b, newsz + 1);
                         fatal(p);  
                 if (oldsz && (p->flags & PFLAG_SPC))                  if (oldsz && (p->flags & PFLAG_SPC))
                         n->b[oldsz++] = ' ';                          n->b[oldsz++] = ' ';
                 memcpy(n->b + oldsz, word, sz);                  memcpy(n->b + oldsz, word, sz);
Line 272  xml_text(struct parse *p, const char *word, int sz)
Line 266  xml_text(struct parse *p, const char *word, int sz)
   
         /* Create a new text node. */          /* Create a new text node. */
   
         if ((n = pnode_alloc(p->cur)) == NULL)          n = pnode_alloc(p->cur);
                 fatal(p);  
         n->node = NODE_TEXT;          n->node = NODE_TEXT;
         n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |          n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |
             ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0);              ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0);
Line 307  xml_text(struct parse *p, const char *word, int sz)
Line 300  xml_text(struct parse *p, const char *word, int sz)
                 i = 0;                  i = 0;
                 while (i < sz && !isspace((unsigned char)word[i]))                  while (i < sz && !isspace((unsigned char)word[i]))
                         i++;                          i++;
                 if ((n->b = strndup(word, i)) == NULL)                  n->b = xstrndup(word, i);
                         fatal(p);  
                 if (i == sz)                  if (i == sz)
                         return;                          return;
                 while (i < sz && isspace((unsigned char)word[i]))                  while (i < sz && isspace((unsigned char)word[i]))
Line 320  xml_text(struct parse *p, const char *word, int sz)
Line 312  xml_text(struct parse *p, const char *word, int sz)
   
                 /* Put any remaining text into a second node. */                  /* Put any remaining text into a second node. */
   
                 if ((n = pnode_alloc(p->cur)) == NULL)                  n = pnode_alloc(p->cur);
                         fatal(p);  
                 n->node = NODE_TEXT;                  n->node = NODE_TEXT;
                 n->flags |= NFLAG_SPC;                  n->flags |= NFLAG_SPC;
                 word += i;                  word += i;
                 sz -= i;                  sz -= i;
         }          }
         if ((n->b = strndup(word, sz)) == NULL)          n->b = xstrndup(word, sz);
                 fatal(p);  
   
         /* The new node remains open for later pnode_closetext(). */          /* The new node remains open for later pnode_closetext(). */
   
Line 371  pnode_closetext(struct parse *p, int check_last_word)
Line 361  pnode_closetext(struct parse *p, int check_last_word)
   
         /* Move the last word into its own node, for use with .Pf. */          /* Move the last word into its own node, for use with .Pf. */
   
         if ((n = pnode_alloc(p->cur)) == NULL)          n = pnode_alloc(p->cur);
                 fatal(p);  
         n->node = NODE_TEXT;          n->node = NODE_TEXT;
         n->flags |= NFLAG_SPC;          n->flags |= NFLAG_SPC;
         if ((n->b = strdup(last_word)) == NULL)          n->b = xstrdup(last_word);
                 fatal(p);  
 }  }
   
 static void  static void
Line 422  xml_entity(struct parse *p, const char *name)
Line 410  xml_entity(struct parse *p, const char *name)
                                 if ((ccp = pnode_getattr_raw(n,                                  if ((ccp = pnode_getattr_raw(n,
                                      ATTRKEY_DEFINITION, NULL)) == NULL)                                       ATTRKEY_DEFINITION, NULL)) == NULL)
                                         continue;                                          continue;
                                 if ((cp = strdup(ccp)) == NULL)                                  cp = xstrdup(ccp);
                                         fatal(p);  
                                 pstate = PARSE_ELEM;                                  pstate = PARSE_ELEM;
                                 parse_string(p, cp, strlen(cp), &pstate, 0);                                  parse_string(p, cp, strlen(cp), &pstate, 0);
                                 p->flags &= ~(PFLAG_LINE | PFLAG_SPC);                                  p->flags &= ~(PFLAG_LINE | PFLAG_SPC);
Line 434  xml_entity(struct parse *p, const char *name)
Line 421  xml_entity(struct parse *p, const char *name)
                 if (*name == '#') {                  if (*name == '#') {
                         codepoint = strtonum(name + 1, 0, 0x10ffff, &ccp);                          codepoint = strtonum(name + 1, 0, 0x10ffff, &ccp);
                         if (ccp == NULL) {                          if (ccp == NULL) {
                                 if ((n = pnode_alloc(p->cur)) == NULL ||                                  n = pnode_alloc(p->cur);
                                     asprintf(&n->b, "\\[u%4.4X]",                                  xasprintf(&n->b, "\\[u%4.4X]", codepoint);
                                     codepoint) < 0)  
                                         fatal(p);  
                                 goto done;                                  goto done;
                         }                          }
                 }                  }
Line 446  xml_entity(struct parse *p, const char *name)
Line 431  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 = pnode_alloc(p->cur)) == NULL ||          n = pnode_alloc(p->cur);
             (n->b = strdup(entity->roff)) == NULL)          n->b = xstrdup(entity->roff);
                 fatal(p);  
 done:  done:
         n->node = NODE_ESCAPE;          n->node = NODE_ESCAPE;
         n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |          n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |
Line 523  xml_elem_start(struct parse *p, const char *name)
Line 507  xml_elem_start(struct parse *p, const char *name)
                 break;                  break;
         }          }
   
         if ((n = pnode_alloc(p->cur)) == NULL)          n = pnode_alloc(p->cur);
                 fatal(p);  
   
         /*          /*
          * Some elements are self-closing.           * Some elements are self-closing.
Line 586  xml_attrkey(struct parse *p, const char *name)
Line 569  xml_attrkey(struct parse *p, const char *name)
                 p->flags &= ~PFLAG_ATTR;                  p->flags &= ~PFLAG_ATTR;
                 return;                  return;
         }          }
         if ((a = calloc(1, sizeof(*a))) == NULL)          a = xcalloc(1, sizeof(*a));
                 fatal(p);  
   
         a->key = key;          a->key = key;
         a->val = ATTRVAL__MAX;          a->val = ATTRVAL__MAX;
         if (value == NULL) {          if (value == NULL) {
                 a->rawval = NULL;                  a->rawval = NULL;
                 p->flags |= PFLAG_ATTR;                  p->flags |= PFLAG_ATTR;
         } else {          } else {
                 if ((a->rawval = strdup(value)) == NULL)                  a->rawval = xstrdup(value);
                         fatal(p);  
                 p->flags &= ~PFLAG_ATTR;                  p->flags &= ~PFLAG_ATTR;
         }          }
         TAILQ_INSERT_TAIL(&p->cur->attrq, a, child);          TAILQ_INSERT_TAIL(&p->cur->attrq, a, child);
Line 614  xml_attrval(struct parse *p, const char *name)
Line 594  xml_attrval(struct parse *p, const char *name)
                 return;                  return;
         if ((a = TAILQ_LAST(&p->cur->attrq, pattrq)) == NULL)          if ((a = TAILQ_LAST(&p->cur->attrq, pattrq)) == NULL)
                 return;                  return;
         if ((a->val = attrval_parse(name)) == ATTRVAL__MAX &&          if ((a->val = attrval_parse(name)) == ATTRVAL__MAX)
             (a->rawval = strdup(name)) == NULL)                  a->rawval = xstrdup(name);
                 fatal(p);  
         p->flags &= ~PFLAG_ATTR;          p->flags &= ~PFLAG_ATTR;
 }  }
   
Line 711  parse_alloc(int warn)
Line 690  parse_alloc(int warn)
 {  {
         struct parse    *p;          struct parse    *p;
   
         if ((p = calloc(1, sizeof(*p))) == NULL)          p = xcalloc(1, sizeof(*p));
                 return NULL;          p->tree = xcalloc(1, sizeof(*p->tree));
   
         if ((p->tree = calloc(1, sizeof(*p->tree))) == NULL) {  
                 free(p);  
                 return NULL;  
         }  
         if (warn)          if (warn)
                 p->flags |= PFLAG_WARN;                  p->flags |= PFLAG_WARN;
         else          else

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.53

CVSweb