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

Diff for /mandoc/roff.c between version 1.265 and 1.266

version 1.265, 2015/04/18 17:28:36 version 1.266, 2015/04/19 13:50:26
Line 30 
Line 30 
 #include "mandoc_aux.h"  #include "mandoc_aux.h"
 #include "roff.h"  #include "roff.h"
 #include "libmandoc.h"  #include "libmandoc.h"
   #include "roff_int.h"
 #include "libroff.h"  #include "libroff.h"
   #include "libmdoc.h"
   
 /* Maximum number of nested if-else conditionals. */  /* Maximum number of nested if-else conditionals. */
 #define RSTACK_MAX      128  #define RSTACK_MAX      128
Line 38 
Line 40 
 /* Maximum number of string expansions per line, to break infinite loops. */  /* Maximum number of string expansions per line, to break infinite loops. */
 #define EXPAND_LIMIT    1000  #define EXPAND_LIMIT    1000
   
   /* --- data types --------------------------------------------------------- */
   
 enum    rofft {  enum    rofft {
         ROFF_ab,          ROFF_ab,
         ROFF_ad,          ROFF_ad,
Line 374  struct predef {
Line 378  struct predef {
 #define PREDEF(__name, __str) \  #define PREDEF(__name, __str) \
         { (__name), (__str) },          { (__name), (__str) },
   
   /* --- function prototypes ------------------------------------------------ */
   
 static  enum rofft       roffhash_find(const char *, size_t);  static  enum rofft       roffhash_find(const char *, size_t);
 static  void             roffhash_init(void);  static  void             roffhash_init(void);
 static  void             roffnode_cleanscope(struct roff *);  static  void             roffnode_cleanscope(struct roff *);
Line 438  static enum rofferr  roff_T_(ROFF_ARGS);
Line 444  static enum rofferr  roff_T_(ROFF_ARGS);
 static  enum rofferr     roff_unsupp(ROFF_ARGS);  static  enum rofferr     roff_unsupp(ROFF_ARGS);
 static  enum rofferr     roff_userdef(ROFF_ARGS);  static  enum rofferr     roff_userdef(ROFF_ARGS);
   
   /* --- constant data ------------------------------------------------------ */
   
 /* See roffhash_find() */  /* See roffhash_find() */
   
 #define ASCII_HI         126  #define ASCII_HI         126
Line 734  static int  roffit_lines;  /* number of lines to delay
Line 742  static int  roffit_lines;  /* number of lines to delay
 static  char    *roffit_macro;  /* nil-terminated macro line */  static  char    *roffit_macro;  /* nil-terminated macro line */
   
   
   /* --- request table ------------------------------------------------------ */
   
 static void  static void
 roffhash_init(void)  roffhash_init(void)
 {  {
Line 786  roffhash_find(const char *p, size_t s)
Line 796  roffhash_find(const char *p, size_t s)
         return(ROFF_MAX);          return(ROFF_MAX);
 }  }
   
   /* --- stack of request blocks -------------------------------------------- */
   
 /*  /*
  * Pop the current node off of the stack of roff instructions currently   * Pop the current node off of the stack of roff instructions currently
  * pending.   * pending.
Line 826  roffnode_push(struct roff *r, enum rofft tok, const ch
Line 838  roffnode_push(struct roff *r, enum rofft tok, const ch
         r->last = p;          r->last = p;
 }  }
   
   /* --- roff parser state data management ---------------------------------- */
   
 static void  static void
 roff_free1(struct roff *r)  roff_free1(struct roff *r)
 {  {
Line 901  roff_alloc(struct mparse *parse, const struct mchars *
Line 915  roff_alloc(struct mparse *parse, const struct mchars *
         return(r);          return(r);
 }  }
   
   /* --- syntax tree state data management ---------------------------------- */
   
 static void  static void
 roff_man_free1(struct roff_man *man)  roff_man_free1(struct roff_man *man)
 {  {
   
         if (man->first != NULL) {          if (man->first != NULL)
                 if (man->macroset == MACROSET_MDOC)                  roff_node_delete(man, man->first);
                         mdoc_node_delete(man, man->first);  
                 else  
                         man_node_delete(man, man->first);  
         }  
         free(man->meta.msec);          free(man->meta.msec);
         free(man->meta.vol);          free(man->meta.vol);
         free(man->meta.os);          free(man->meta.os);
Line 966  roff_man_alloc(struct roff *roff, struct mparse *parse
Line 978  roff_man_alloc(struct roff *roff, struct mparse *parse
         return(man);          return(man);
 }  }
   
   /* --- syntax tree handling ----------------------------------------------- */
   
   struct roff_node *
   roff_node_alloc(struct roff_man *man, int line, int pos,
           enum roff_type type, int tok)
   {
           struct roff_node        *n;
   
           n = mandoc_calloc(1, sizeof(*n));
           n->line = line;
           n->pos = pos;
           n->tok = tok;
           n->type = type;
           n->sec = man->lastsec;
   
           if (man->flags & MDOC_SYNOPSIS)
                   n->flags |= MDOC_SYNPRETTY;
           else
                   n->flags &= ~MDOC_SYNPRETTY;
           if (man->flags & MDOC_NEWLINE)
                   n->flags |= MDOC_LINE;
           man->flags &= ~MDOC_NEWLINE;
   
           return(n);
   }
   
   void
   roff_node_append(struct roff_man *man, struct roff_node *n)
   {
   
           switch (man->next) {
           case ROFF_NEXT_SIBLING:
                   man->last->next = n;
                   n->prev = man->last;
                   n->parent = man->last->parent;
                   break;
           case ROFF_NEXT_CHILD:
                   man->last->child = n;
                   n->parent = man->last;
                   break;
           default:
                   abort();
                   /* NOTREACHED */
           }
           n->parent->nchild++;
   
           /*
            * Copy over the normalised-data pointer of our parent.  Not
            * everybody has one, but copying a null pointer is fine.
            */
   
           switch (n->type) {
           case ROFFT_BODY:
                   if (n->end != ENDBODY_NOT)
                           break;
                   /* FALLTHROUGH */
           case ROFFT_TAIL:
                   /* FALLTHROUGH */
           case ROFFT_HEAD:
                   n->norm = n->parent->norm;
                   break;
           default:
                   break;
           }
   
           if (man->macroset == MACROSET_MDOC)
                   mdoc_valid_pre(man, n);
   
           switch (n->type) {
           case ROFFT_HEAD:
                   assert(n->parent->type == ROFFT_BLOCK);
                   n->parent->head = n;
                   break;
           case ROFFT_BODY:
                   if (n->end)
                           break;
                   assert(n->parent->type == ROFFT_BLOCK);
                   n->parent->body = n;
                   break;
           case ROFFT_TAIL:
                   assert(n->parent->type == ROFFT_BLOCK);
                   n->parent->tail = n;
                   break;
           default:
                   break;
           }
           man->last = n;
   }
   
   struct roff_node *
   roff_head_alloc(struct roff_man *man, int line, int pos, int tok)
   {
           struct roff_node        *n;
   
           n = roff_node_alloc(man, line, pos, ROFFT_HEAD, tok);
           roff_node_append(man, n);
           man->next = ROFF_NEXT_CHILD;
           return(n);
   }
   
   struct roff_node *
   roff_body_alloc(struct roff_man *man, int line, int pos, int tok)
   {
           struct roff_node        *n;
   
           n = roff_node_alloc(man, line, pos, ROFFT_BODY, tok);
           roff_node_append(man, n);
           man->next = ROFF_NEXT_CHILD;
           return(n);
   }
   
   void
   roff_node_unlink(struct roff_man *man, 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 != NULL) {
                   n->parent->nchild--;
                   if (n->parent->child == n)
                           n->parent->child = n->next;
                   if (n->parent->last == n)
                           n->parent->last = n->prev;
           }
   
           /* Adjust parse point. */
   
           if (man == NULL)
                   return;
           if (man->last == n) {
                   if (n->prev == NULL) {
                           man->last = n->parent;
                           man->next = ROFF_NEXT_CHILD;
                   } else {
                           man->last = n->prev;
                           man->next = ROFF_NEXT_SIBLING;
                   }
           }
           if (man->first == n)
                   man->first = NULL;
   }
   
   void
   roff_node_free(struct roff_node *n)
   {
   
           if (n->args != NULL)
                   mdoc_argv_free(n->args);
           if (n->type == ROFFT_BLOCK || n->type == ROFFT_ELEM)
                   free(n->norm);
           free(n->string);
           free(n);
   }
   
   void
   roff_node_delete(struct roff_man *man, struct roff_node *n)
   {
   
           while (n->child != NULL)
                   roff_node_delete(man, n->child);
           assert(n->nchild == 0);
           roff_node_unlink(man, n);
           roff_node_free(n);
   }
   
   /* --- main functions of the roff parser ---------------------------------- */
   
 /*  /*
  * In the current line, expand escape sequences that tend to get   * In the current line, expand escape sequences that tend to get
  * used in numerical expressions and conditional requests.   * used in numerical expressions and conditional requests.
Line 1385  roff_parse(struct roff *r, char *buf, int *pos, int ln
Line 1571  roff_parse(struct roff *r, char *buf, int *pos, int ln
         return(t);          return(t);
 }  }
   
   /* --- handling of request blocks ----------------------------------------- */
   
 static enum rofferr  static enum rofferr
 roff_cblock(ROFF_ARGS)  roff_cblock(ROFF_ARGS)
 {  {
Line 1695  roff_cond_text(ROFF_ARGS)
Line 1883  roff_cond_text(ROFF_ARGS)
         return(rr ? ROFF_CONT : ROFF_IGN);          return(rr ? ROFF_CONT : ROFF_IGN);
 }  }
   
   /* --- handling of numeric and conditional expressions -------------------- */
   
 /*  /*
  * Parse a single signed integer number.  Stop at the first non-digit.   * Parse a single signed integer number.  Stop at the first non-digit.
  * If there is at least one digit, return success and advance the   * If there is at least one digit, return success and advance the
Line 2212  roff_evalnum(struct roff *r, int ln, const char *v,
Line 2402  roff_evalnum(struct roff *r, int ln, const char *v,
         return(1);          return(1);
 }  }
   
   /* --- register management ------------------------------------------------ */
   
 void  void
 roff_setreg(struct roff *r, const char *name, int val, char sign)  roff_setreg(struct roff *r, const char *name, int val, char sign)
 {  {
Line 2376  roff_rr(ROFF_ARGS)
Line 2568  roff_rr(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
   /* --- handler functions for roff requests -------------------------------- */
   
 static enum rofferr  static enum rofferr
 roff_rm(ROFF_ARGS)  roff_rm(ROFF_ARGS)
 {  {
Line 2720  roff_so(ROFF_ARGS)
Line 2914  roff_so(ROFF_ARGS)
         return(ROFF_SO);          return(ROFF_SO);
 }  }
   
   /* --- user defined strings and macros ------------------------------------ */
   
 static enum rofferr  static enum rofferr
 roff_userdef(ROFF_ARGS)  roff_userdef(ROFF_ARGS)
 {  {
Line 2987  roff_freestr(struct roffkv *r)
Line 3183  roff_freestr(struct roffkv *r)
                 free(n);                  free(n);
         }          }
 }  }
   
   /* --- accessors and utility functions ------------------------------------ */
   
 const struct tbl_span *  const struct tbl_span *
 roff_span(const struct roff *r)  roff_span(const struct roff *r)

Legend:
Removed from v.1.265  
changed lines
  Added in v.1.266

CVSweb