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

Diff for /mandoc/roff.c between version 1.132 and 1.139

version 1.132, 2011/04/13 09:57:41 version 1.139, 2011/05/24 14:00:39
Line 20 
Line 20 
 #endif  #endif
   
 #include <assert.h>  #include <assert.h>
 #include <errno.h>  
 #include <ctype.h>  #include <ctype.h>
 #include <limits.h>  
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <stdio.h>  
   
 #include "mandoc.h"  #include "mandoc.h"
 #include "libroff.h"  #include "libroff.h"
Line 206  static void   roffnode_push(struct roff *, enum rofft,
Line 203  static void   roffnode_push(struct roff *, enum rofft,
                                 const char *, int, int);                                  const char *, int, int);
 static  void             roffnode_pop(struct roff *);  static  void             roffnode_pop(struct roff *);
 static  enum rofft       roff_parse(struct roff *, const char *, int *);  static  enum rofft       roff_parse(struct roff *, const char *, int *);
 static  int              roff_parse_nat(const char *, unsigned int *);  
   
 /* See roff_hash_find() */  /* See roff_hash_find() */
 #define ROFF_HASH(p)    (p[0] - ASCII_LO)  #define ROFF_HASH(p)    (p[0] - ASCII_LO)
Line 593  roff_parse(struct roff *r, const char *buf, int *pos)
Line 589  roff_parse(struct roff *r, const char *buf, int *pos)
         return(t);          return(t);
 }  }
   
   
 static int  
 roff_parse_nat(const char *buf, unsigned int *res)  
 {  
         char            *ep;  
         long             lval;  
   
         errno = 0;  
         lval = strtol(buf, &ep, 10);  
         if (buf[0] == '\0' || *ep != '\0')  
                 return(0);  
         if ((errno == ERANGE &&  
                         (lval == LONG_MAX || lval == LONG_MIN)) ||  
                         (lval > INT_MAX || lval < 0))  
                 return(0);  
   
         *res = (unsigned int)lval;  
         return(1);  
 }  
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static enum rofferr  static enum rofferr
 roff_cblock(ROFF_ARGS)  roff_cblock(ROFF_ARGS)
Line 829  roff_block_sub(ROFF_ARGS)
Line 804  roff_block_sub(ROFF_ARGS)
          * pulling it out of the hashtable.           * pulling it out of the hashtable.
          */           */
   
         if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos)))          t = roff_parse(r, *bufp, &pos);
                 return(ROFF_IGN);  
   
         /*          /*
          * Macros other than block-end are only significant           * Macros other than block-end are only significant
Line 866  roff_cond_sub(ROFF_ARGS)
Line 840  roff_cond_sub(ROFF_ARGS)
 {  {
         enum rofft       t;          enum rofft       t;
         enum roffrule    rr;          enum roffrule    rr;
           char            *ep;
   
         rr = r->last->rule;          rr = r->last->rule;
           roffnode_cleanscope(r);
   
         /*          /*
          * Clean out scope.  If we've closed ourselves, then don't           * If the macro is unknown, first check if it contains a closing
          * continue.           * delimiter `\}'.  If it does, close out our scope and return
            * the currently-scoped rule (ignore or continue).  Else, drop
            * into the currently-scoped rule.
          */           */
   
         roffnode_cleanscope(r);  
   
         if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) {          if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) {
                 if ('\\' == (*bufp)[pos] && '}' == (*bufp)[pos + 1])                  /*
                         return(roff_ccond                   * Jump through hoops to detect a \}, because it could
                                 (r, ROFF_ccond, bufp, szp,                   * be (say) \\}, which is something completely
                                  ln, pos, pos + 2, offs));                   * different.
                    */
                   ep = &(*bufp)[pos];
                   for ( ; NULL != (ep = strchr(ep, '\\')); ep++) {
                           ep++;
                           if ('}' != *ep)
                                   continue;
                           *--ep = '\0';
                           roff_ccond(r, ROFF_ccond, bufp, szp,
                                           ln, pos, pos + 2, offs);
                           break;
                   }
                 return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);                  return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
         }          }
   
Line 889  roff_cond_sub(ROFF_ARGS)
Line 876  roff_cond_sub(ROFF_ARGS)
          * if they're either structurally required (such as loops and           * if they're either structurally required (such as loops and
          * conditionals) or a closing macro.           * conditionals) or a closing macro.
          */           */
   
         if (ROFFRULE_DENY == rr)          if (ROFFRULE_DENY == rr)
                 if ( ! (ROFFMAC_STRUCT & roffs[t].flags))                  if ( ! (ROFFMAC_STRUCT & roffs[t].flags))
                         if (ROFF_ccond != t)                          if (ROFF_ccond != t)
Line 1091  roff_nr(ROFF_ARGS)
Line 1079  roff_nr(ROFF_ARGS)
 {  {
         const char      *key;          const char      *key;
         char            *val;          char            *val;
           int              iv;
         struct reg      *rg;          struct reg      *rg;
   
         val = *bufp + pos;          val = *bufp + pos;
Line 1099  roff_nr(ROFF_ARGS)
Line 1088  roff_nr(ROFF_ARGS)
   
         if (0 == strcmp(key, "nS")) {          if (0 == strcmp(key, "nS")) {
                 rg[(int)REG_nS].set = 1;                  rg[(int)REG_nS].set = 1;
                 if ( ! roff_parse_nat(val, &rg[(int)REG_nS].v.u))                  if ((iv = mandoc_strntou(val, strlen(val), 10)) >= 0)
                         rg[(int)REG_nS].v.u = 0;                          rg[REG_nS].v.u = (unsigned)iv;
                   else
                           rg[(int)REG_nS].v.u = 0u;
         }          }
   
         return(ROFF_IGN);          return(ROFF_IGN);

Legend:
Removed from v.1.132  
changed lines
  Added in v.1.139

CVSweb