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

Diff for /mandoc/mdoc.c between version 1.246 and 1.247

version 1.246, 2015/04/18 17:53:21 version 1.247, 2015/04/19 13:50:26
Line 32 
Line 32 
 #include "roff.h"  #include "roff.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "libmandoc.h"  #include "libmandoc.h"
   #include "roff_int.h"
 #include "libmdoc.h"  #include "libmdoc.h"
   
 const   char *const __mdoc_macronames[MDOC_MAX + 1] = {  const   char *const __mdoc_macronames[MDOC_MAX + 1] = {
Line 83  const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
Line 84  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;
   
 static  void              mdoc_node_free(struct roff_node *);  
 static  void              mdoc_node_unlink(struct roff_man *,  
                                 struct roff_node *);  
 static  struct roff_node *node_alloc(struct roff_man *, int, int,  
                                 int, enum roff_type);  
 static  void              node_append(struct roff_man *, struct roff_node *);  
 static  int               mdoc_ptext(struct roff_man *, int, char *, int);  static  int               mdoc_ptext(struct roff_man *, int, char *, int);
 static  int               mdoc_pmacro(struct roff_man *, int, char *, int);  static  int               mdoc_pmacro(struct roff_man *, int, char *, int);
   
Line 105  mdoc_addeqn(struct roff_man *mdoc, const struct eqn *e
Line 100  mdoc_addeqn(struct roff_man *mdoc, const struct eqn *e
 {  {
         struct roff_node *n;          struct roff_node *n;
   
         n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, ROFFT_EQN);          n = roff_node_alloc(mdoc, ep->ln, ep->pos, ROFFT_EQN, MDOC_MAX);
         n->eqn = ep;          n->eqn = ep;
         if (ep->ln > mdoc->last->line)          if (ep->ln > mdoc->last->line)
                 n->flags |= MDOC_LINE;                  n->flags |= MDOC_LINE;
         node_append(mdoc, n);          roff_node_append(mdoc, n);
         mdoc->next = ROFF_NEXT_SIBLING;          mdoc->next = ROFF_NEXT_SIBLING;
 }  }
   
Line 118  mdoc_addspan(struct roff_man *mdoc, const struct tbl_s
Line 113  mdoc_addspan(struct roff_man *mdoc, const struct tbl_s
 {  {
         struct roff_node *n;          struct roff_node *n;
   
         n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, ROFFT_TBL);          n = roff_node_alloc(mdoc, sp->line, 0, ROFFT_TBL, MDOC_MAX);
         n->span = sp;          n->span = sp;
         node_append(mdoc, n);          roff_node_append(mdoc, n);
           mdoc_valid_post(mdoc);
         mdoc->next = ROFF_NEXT_SIBLING;          mdoc->next = ROFF_NEXT_SIBLING;
 }  }
   
Line 177  mdoc_macro(MACRO_PROT_ARGS)
Line 173  mdoc_macro(MACRO_PROT_ARGS)
         (*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf);          (*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf);
 }  }
   
   
 static void  
 node_append(struct roff_man *mdoc, struct roff_node *p)  
 {  
   
         assert(mdoc->last);  
         assert(mdoc->first);  
         assert(p->type != ROFFT_ROOT);  
   
         switch (mdoc->next) {  
         case ROFF_NEXT_SIBLING:  
                 mdoc->last->next = p;  
                 p->prev = mdoc->last;  
                 p->parent = mdoc->last->parent;  
                 break;  
         case ROFF_NEXT_CHILD:  
                 mdoc->last->child = p;  
                 p->parent = mdoc->last;  
                 break;  
         default:  
                 abort();  
                 /* NOTREACHED */  
         }  
   
         p->parent->nchild++;  
   
         /*  
          * Copy over the normalised-data pointer of our parent.  Not  
          * everybody has one, but copying a null pointer is fine.  
          */  
   
         switch (p->type) {  
         case ROFFT_BODY:  
                 if (ENDBODY_NOT != p->end)  
                         break;  
                 /* FALLTHROUGH */  
         case ROFFT_TAIL:  
                 /* FALLTHROUGH */  
         case ROFFT_HEAD:  
                 p->norm = p->parent->norm;  
                 break;  
         default:  
                 break;  
         }  
   
         mdoc_valid_pre(mdoc, p);  
   
         switch (p->type) {  
         case ROFFT_HEAD:  
                 assert(p->parent->type == ROFFT_BLOCK);  
                 p->parent->head = p;  
                 break;  
         case ROFFT_TAIL:  
                 assert(p->parent->type == ROFFT_BLOCK);  
                 p->parent->tail = p;  
                 break;  
         case ROFFT_BODY:  
                 if (p->end)  
                         break;  
                 assert(p->parent->type == ROFFT_BLOCK);  
                 p->parent->body = p;  
                 break;  
         default:  
                 break;  
         }  
   
         mdoc->last = p;  
   
         switch (p->type) {  
         case ROFFT_TBL:  
                 /* FALLTHROUGH */  
         case ROFFT_TEXT:  
                 mdoc_valid_post(mdoc);  
                 break;  
         default:  
                 break;  
         }  
 }  
   
 static struct roff_node *  
 node_alloc(struct roff_man *mdoc, int line, int pos,  
         int tok, enum roff_type type)  
 {  
         struct roff_node *p;  
   
         p = mandoc_calloc(1, sizeof(*p));  
         p->sec = mdoc->lastsec;  
         p->line = line;  
         p->pos = pos;  
         p->tok = tok;  
         p->type = type;  
   
         /* Flag analysis. */  
   
         if (MDOC_SYNOPSIS & mdoc->flags)  
                 p->flags |= MDOC_SYNPRETTY;  
         else  
                 p->flags &= ~MDOC_SYNPRETTY;  
         if (MDOC_NEWLINE & mdoc->flags)  
                 p->flags |= MDOC_LINE;  
         mdoc->flags &= ~MDOC_NEWLINE;  
   
         return(p);  
 }  
   
 void  void
 mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, int tok)  mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, int tok)
 {  {
         struct roff_node *p;          struct roff_node *p;
   
         p = node_alloc(mdoc, line, pos, tok, ROFFT_TAIL);          p = roff_node_alloc(mdoc, line, pos, ROFFT_TAIL, tok);
         node_append(mdoc, p);          roff_node_append(mdoc, p);
         mdoc->next = ROFF_NEXT_CHILD;          mdoc->next = ROFF_NEXT_CHILD;
 }  }
   
 struct roff_node *  struct roff_node *
 mdoc_head_alloc(struct roff_man *mdoc, int line, int pos, int tok)  
 {  
         struct roff_node *p;  
   
         assert(mdoc->first);  
         assert(mdoc->last);  
         p = node_alloc(mdoc, line, pos, tok, ROFFT_HEAD);  
         node_append(mdoc, p);  
         mdoc->next = ROFF_NEXT_CHILD;  
         return(p);  
 }  
   
 struct roff_node *  
 mdoc_body_alloc(struct roff_man *mdoc, int line, int pos, int tok)  
 {  
         struct roff_node *p;  
   
         p = node_alloc(mdoc, line, pos, tok, ROFFT_BODY);  
         node_append(mdoc, p);  
         mdoc->next = ROFF_NEXT_CHILD;  
         return(p);  
 }  
   
 struct roff_node *  
 mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos, int tok,  mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos, int tok,
                 struct roff_node *body, enum mdoc_endbody end)                  struct roff_node *body, enum mdoc_endbody end)
 {  {
Line 324  mdoc_endbody_alloc(struct roff_man *mdoc, int line, in
Line 191  mdoc_endbody_alloc(struct roff_man *mdoc, int line, in
   
         body->flags |= MDOC_ENDED;          body->flags |= MDOC_ENDED;
         body->parent->flags |= MDOC_ENDED;          body->parent->flags |= MDOC_ENDED;
         p = node_alloc(mdoc, line, pos, tok, ROFFT_BODY);          p = roff_node_alloc(mdoc, line, pos, ROFFT_BODY, tok);
         p->body = body;          p->body = body;
         p->norm = body->norm;          p->norm = body->norm;
         p->end = end;          p->end = end;
         node_append(mdoc, p);          roff_node_append(mdoc, p);
         mdoc->next = ROFF_NEXT_SIBLING;          mdoc->next = ROFF_NEXT_SIBLING;
         return(p);          return(p);
 }  }
Line 339  mdoc_block_alloc(struct roff_man *mdoc, int line, int 
Line 206  mdoc_block_alloc(struct roff_man *mdoc, int line, int 
 {  {
         struct roff_node *p;          struct roff_node *p;
   
         p = node_alloc(mdoc, line, pos, tok, ROFFT_BLOCK);          p = roff_node_alloc(mdoc, line, pos, ROFFT_BLOCK, tok);
         p->args = args;          p->args = args;
         if (p->args)          if (p->args)
                 (args->refcnt)++;                  (args->refcnt)++;
Line 359  mdoc_block_alloc(struct roff_man *mdoc, int line, int 
Line 226  mdoc_block_alloc(struct roff_man *mdoc, int line, int 
         default:          default:
                 break;                  break;
         }          }
         node_append(mdoc, p);          roff_node_append(mdoc, p);
         mdoc->next = ROFF_NEXT_CHILD;          mdoc->next = ROFF_NEXT_CHILD;
         return(p);          return(p);
 }  }
Line 370  mdoc_elem_alloc(struct roff_man *mdoc, int line, int p
Line 237  mdoc_elem_alloc(struct roff_man *mdoc, int line, int p
 {  {
         struct roff_node *p;          struct roff_node *p;
   
         p = node_alloc(mdoc, line, pos, tok, ROFFT_ELEM);          p = roff_node_alloc(mdoc, line, pos, ROFFT_ELEM, tok);
         p->args = args;          p->args = args;
         if (p->args)          if (p->args)
                 (args->refcnt)++;                  (args->refcnt)++;
Line 382  mdoc_elem_alloc(struct roff_man *mdoc, int line, int p
Line 249  mdoc_elem_alloc(struct roff_man *mdoc, int line, int p
         default:          default:
                 break;                  break;
         }          }
         node_append(mdoc, p);          roff_node_append(mdoc, p);
         mdoc->next = ROFF_NEXT_CHILD;          mdoc->next = ROFF_NEXT_CHILD;
 }  }
   
Line 391  mdoc_word_alloc(struct roff_man *mdoc, int line, int p
Line 258  mdoc_word_alloc(struct roff_man *mdoc, int line, int p
 {  {
         struct roff_node *n;          struct roff_node *n;
   
         n = node_alloc(mdoc, line, pos, MDOC_MAX, ROFFT_TEXT);          n = roff_node_alloc(mdoc, line, pos, ROFFT_TEXT, MDOC_MAX);
         n->string = roff_strdup(mdoc->roff, p);          n->string = roff_strdup(mdoc->roff, p);
         node_append(mdoc, n);          roff_node_append(mdoc, n);
           mdoc_valid_post(mdoc);
         mdoc->next = ROFF_NEXT_SIBLING;          mdoc->next = ROFF_NEXT_SIBLING;
 }  }
   
Line 412  mdoc_word_append(struct roff_man *mdoc, const char *p)
Line 280  mdoc_word_append(struct roff_man *mdoc, const char *p)
         mdoc->next = ROFF_NEXT_SIBLING;          mdoc->next = ROFF_NEXT_SIBLING;
 }  }
   
 static void  
 mdoc_node_free(struct roff_node *p)  
 {  
   
         if (p->type == ROFFT_BLOCK || p->type == ROFFT_ELEM)  
                 free(p->norm);  
         if (p->string)  
                 free(p->string);  
         if (p->args)  
                 mdoc_argv_free(p->args);  
         free(p);  
 }  
   
 static void  
 mdoc_node_unlink(struct roff_man *mdoc, struct roff_node *n)  
 {  
   
         /* Adjust siblings. */  
   
         if (n->prev)  
                 n->prev->next = n->next;  
         if (n->next)  
                 n->next->prev = n->prev;  
   
         /* Adjust parent. */  
   
         if (n->parent) {  
                 n->parent->nchild--;  
                 if (n->parent->child == n)  
                         n->parent->child = n->prev ? n->prev : n->next;  
                 if (n->parent->last == n)  
                         n->parent->last = n->prev ? n->prev : NULL;  
         }  
   
         /* Adjust parse point, if applicable. */  
   
         if (mdoc && mdoc->last == n) {  
                 if (n->prev) {  
                         mdoc->last = n->prev;  
                         mdoc->next = ROFF_NEXT_SIBLING;  
                 } else {  
                         mdoc->last = n->parent;  
                         mdoc->next = ROFF_NEXT_CHILD;  
                 }  
         }  
   
         if (mdoc && mdoc->first == n)  
                 mdoc->first = NULL;  
 }  
   
 void  void
 mdoc_node_delete(struct roff_man *mdoc, struct roff_node *p)  
 {  
   
         while (p->child) {  
                 assert(p->nchild);  
                 mdoc_node_delete(mdoc, p->child);  
         }  
         assert(0 == p->nchild);  
   
         mdoc_node_unlink(mdoc, p);  
         mdoc_node_free(p);  
 }  
   
 void  
 mdoc_node_relink(struct roff_man *mdoc, struct roff_node *p)  mdoc_node_relink(struct roff_man *mdoc, struct roff_node *p)
 {  {
   
         mdoc_node_unlink(mdoc, p);          roff_node_unlink(mdoc, p);
         node_append(mdoc, p);          roff_node_append(mdoc, p);
 }  }
   
 /*  /*

Legend:
Removed from v.1.246  
changed lines
  Added in v.1.247

CVSweb