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

Diff for /mandoc/mdoc.c between version 1.68 and 1.72

version 1.68, 2009/03/20 15:14:01 version 1.72, 2009/03/23 15:41:09
Line 24 
Line 24 
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
   
 #include "private.h"  #include "libmdoc.h"
   
 /*  /*
  * Main caller in the libmdoc library.  This begins the parsing routine,   * Main caller in the libmdoc library.  This begins the parsing routine,
Line 32 
Line 32 
  * in macro.c, validate.c and action.c.   * in macro.c, validate.c and action.c.
  */   */
   
 static  struct mdoc_node *mdoc_node_alloc(const struct mdoc *);  
 static  int               mdoc_node_append(struct mdoc *,  
                                 struct mdoc_node *);  
   
 static  int               parsetext(struct mdoc *, int, char *);  
 static  int               parsemacro(struct mdoc *, int, char *);  
 static  int               macrowarn(struct mdoc *, int, const char *);  
   
   
 const   char *const __mdoc_macronames[MDOC_MAX] = {  const   char *const __mdoc_macronames[MDOC_MAX] = {
         "\\\"",         "Dd",           "Dt",           "Os",          "\\\"",         "Dd",           "Dt",           "Os",
         "Sh",           "Ss",           "Pp",           "D1",          "Sh",           "Ss",           "Pp",           "D1",
Line 75  const char *const __mdoc_macronames[MDOC_MAX] = {   
Line 66  const char *const __mdoc_macronames[MDOC_MAX] = {   
         "Lp",           "Lk",           "Mt",           "Brq",          "Lp",           "Lk",           "Mt",           "Brq",
         /* LINTED */          /* LINTED */
         "Bro",          "Brc",          "\%C",          "Es",          "Bro",          "Brc",          "\%C",          "Es",
         "En",           "Dx"          /* LINTED */
           "En",           "Dx",           "\%Q"
         };          };
   
 const   char *const __mdoc_argnames[MDOC_ARG_MAX] = {  const   char *const __mdoc_argnames[MDOC_ARG_MAX] = {
Line 93  const char *const __mdoc_argnames[MDOC_ARG_MAX] = {   
Line 85  const char *const __mdoc_argnames[MDOC_ARG_MAX] = {   
 const   char * const *mdoc_macronames = __mdoc_macronames;  const   char * const *mdoc_macronames = __mdoc_macronames;
 const   char * const *mdoc_argnames = __mdoc_argnames;  const   char * const *mdoc_argnames = __mdoc_argnames;
   
   /* FIXME: have this accept line/pos/tok. */
   /* FIXME: mdoc_alloc1 and mdoc_free1 like in man.c. */
   static  struct mdoc_node *mdoc_node_alloc(const struct mdoc *);
   static  int               mdoc_node_append(struct mdoc *,
                                   struct mdoc_node *);
   
   static  int               parsetext(struct mdoc *, int, char *);
   static  int               parsemacro(struct mdoc *, int, char *);
   static  int               macrowarn(struct mdoc *, int, const char *);
   
   
 /*  /*
  * Get the first (root) node of the parse tree.   * Get the first (root) node of the parse tree.
  */   */
 const struct mdoc_node *  const struct mdoc_node *
 mdoc_node(const struct mdoc *mdoc)  mdoc_node(const struct mdoc *m)
 {  {
   
         if (MDOC_HALT & mdoc->flags)          return(MDOC_HALT & m->flags ? NULL : m->first);
                 return(NULL);  
         if (mdoc->first)  
                 assert(MDOC_ROOT == mdoc->first->type);  
         return(mdoc->first);  
 }  }
   
   
 const struct mdoc_meta *  const struct mdoc_meta *
 mdoc_meta(const struct mdoc *mdoc)  mdoc_meta(const struct mdoc *m)
 {  {
   
         if (MDOC_HALT & mdoc->flags)          return(MDOC_HALT & m->flags ? NULL : &m->meta);
                 return(NULL);  
         return(&mdoc->meta);  
 }  }
   
   
 /*  /*
  * Free up all resources contributed by a parse:  the node tree, meta-data and   * Free up all resources contributed by a parse:  the node tree,
  * so on.  Then reallocate the root node for another parse.   * meta-data and so on.  Then reallocate the root node for another
    * parse.
  */   */
 void  void
 mdoc_reset(struct mdoc *mdoc)  mdoc_reset(struct mdoc *mdoc)
Line 143  mdoc_reset(struct mdoc *mdoc)
Line 140  mdoc_reset(struct mdoc *mdoc)
         bzero(&mdoc->meta, sizeof(struct mdoc_meta));          bzero(&mdoc->meta, sizeof(struct mdoc_meta));
         mdoc->flags = 0;          mdoc->flags = 0;
         mdoc->lastnamed = mdoc->lastsec = 0;          mdoc->lastnamed = mdoc->lastsec = 0;
           mdoc->last = calloc(1, sizeof(struct mdoc_node));
         mdoc->first = mdoc->last =          if (NULL == mdoc->last)
                 xcalloc(1, sizeof(struct mdoc_node));                  err(1, "calloc");
           mdoc->first = mdoc->last;
         mdoc->last->type = MDOC_ROOT;          mdoc->last->type = MDOC_ROOT;
         mdoc->next = MDOC_NEXT_CHILD;          mdoc->next = MDOC_NEXT_CHILD;
 }  }
Line 183  mdoc_alloc(void *data, int pflags, const struct mdoc_c
Line 181  mdoc_alloc(void *data, int pflags, const struct mdoc_c
 {  {
         struct mdoc     *p;          struct mdoc     *p;
   
         p = xcalloc(1, sizeof(struct mdoc));          if (NULL == (p = calloc(1, sizeof(struct mdoc))))
                   err(1, "calloc");
   
         p->data = data;          p->data = data;
         if (cb)          if (cb)
                 (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));                  (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
   
         p->last = p->first =          if (NULL == (p->first = calloc(1, sizeof(struct mdoc_node))))
                 xcalloc(1, sizeof(struct mdoc_node));                  err(1, "calloc");
           p->last = p->first;
         p->last->type = MDOC_ROOT;          p->last->type = MDOC_ROOT;
         p->pflags = pflags;          p->pflags = pflags;
         p->next = MDOC_NEXT_CHILD;          p->next = MDOC_NEXT_CHILD;
Line 204  mdoc_alloc(void *data, int pflags, const struct mdoc_c
Line 204  mdoc_alloc(void *data, int pflags, const struct mdoc_c
  * through to macro_end in macro.c.   * through to macro_end in macro.c.
  */   */
 int  int
 mdoc_endparse(struct mdoc *mdoc)  mdoc_endparse(struct mdoc *m)
 {  {
   
         if (MDOC_HALT & mdoc->flags)          if (MDOC_HALT & m->flags)
                 return(0);                  return(0);
         if (NULL == mdoc->first)          else if (mdoc_macroend(m))
                 return(1);                  return(1);
           m->flags |= MDOC_HALT;
         assert(mdoc->last);          return(0);
         if ( ! macro_end(mdoc)) {  
                 mdoc->flags |= MDOC_HALT;  
                 return(0);  
         }  
         return(1);  
 }  }
   
   
Line 360  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 355  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
         }          }
   
         mdoc->last = p;          mdoc->last = p;
   
           switch (p->type) {
           case (MDOC_TEXT):
                   if ( ! mdoc_valid_post(mdoc))
                           return(0);
                   if ( ! mdoc_action_post(mdoc))
                           return(0);
                   break;
           default:
                   break;
           }
   
         return(1);          return(1);
 }  }
   
Line 369  mdoc_node_alloc(const struct mdoc *mdoc)
Line 376  mdoc_node_alloc(const struct mdoc *mdoc)
 {  {
         struct mdoc_node *p;          struct mdoc_node *p;
   
         p = xcalloc(1, sizeof(struct mdoc_node));          if (NULL == (p = calloc(1, sizeof(struct mdoc_node))))
                   err(1, "calloc");
         p->sec = mdoc->lastsec;          p->sec = mdoc->lastsec;
   
         return(p);          return(p);
Line 434  mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, 
Line 442  mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, 
   
   
 int  int
 mdoc_root_alloc(struct mdoc *mdoc)  
 {  
         struct mdoc_node *p;  
   
         p = mdoc_node_alloc(mdoc);  
   
         p->type = MDOC_ROOT;  
   
         return(mdoc_node_append(mdoc, p));  
 }  
   
   
 int  
 mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,  mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
                 int tok, struct mdoc_arg *args)                  int tok, struct mdoc_arg *args)
 {  {
Line 499  mdoc_word_alloc(struct mdoc *mdoc, 
Line 494  mdoc_word_alloc(struct mdoc *mdoc, 
         p->line = line;          p->line = line;
         p->pos = pos;          p->pos = pos;
         p->type = MDOC_TEXT;          p->type = MDOC_TEXT;
         p->string = xstrdup(word);          if (NULL == (p->string = strdup(word)))
                   err(1, "strdup");
   
         return(mdoc_node_append(mdoc, p));          return(mdoc_node_append(mdoc, p));
 }  }
Line 627  parsemacro(struct mdoc *m, int ln, char *buf)
Line 623  parsemacro(struct mdoc *m, int ln, char *buf)
   
         if ( ! mdoc_macro(m, c, ln, 1, &i, buf))          if ( ! mdoc_macro(m, c, ln, 1, &i, buf))
                 goto err;                  goto err;
   
         /*  
          * If we're in literal mode, then add a newline to the end of  
          * macro lines.  Our frontends will interpret this correctly  
          * (it's documented in mdoc.3).  
          */  
   
         return(1);          return(1);
   

Legend:
Removed from v.1.68  
changed lines
  Added in v.1.72

CVSweb