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

Diff for /mandoc/roff.c between version 1.232 and 1.234

version 1.232, 2014/10/20 02:33:06 version 1.234, 2014/10/20 19:04:45
Line 186  static enum rofferr  roff_cond_sub(ROFF_ARGS);
Line 186  static enum rofferr  roff_cond_sub(ROFF_ARGS);
 static  enum rofferr     roff_ds(ROFF_ARGS);  static  enum rofferr     roff_ds(ROFF_ARGS);
 static  enum rofferr     roff_eqndelim(struct roff *,  static  enum rofferr     roff_eqndelim(struct roff *,
                                 char **, size_t *, int);                                  char **, size_t *, int);
 static  int              roff_evalcond(const char *, int *);  static  int              roff_evalcond(struct roff *r, int,
 static  int              roff_evalnum(const char *, int *, int *, int);                                  const char *, int *);
 static  int              roff_evalpar(const char *, int *, int *);  static  int              roff_evalnum(struct roff *, int,
                                   const char *, int *, int *, int);
   static  int              roff_evalpar(struct roff *, int,
                                   const char *, int *, int *);
 static  int              roff_evalstrcond(const char *, int *);  static  int              roff_evalstrcond(const char *, int *);
 static  void             roff_free1(struct roff *);  static  void             roff_free1(struct roff *);
 static  void             roff_freereg(struct roffreg *);  static  void             roff_freereg(struct roffreg *);
Line 622  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 625  roff_res(struct roff *r, char **bufp, size_t *szp, int
                 case 'B':                  case 'B':
                         npos = 0;                          npos = 0;
                         ubuf[0] = arg_complete &&                          ubuf[0] = arg_complete &&
                             roff_evalnum(stnam, &npos, NULL, 0) &&                              roff_evalnum(r, ln, stnam, &npos, NULL, 0) &&
                             stnam + npos + 1 == cp ? '1' : '0';                              stnam + npos + 1 == cp ? '1' : '0';
                         ubuf[1] = '\0';                          ubuf[1] = '\0';
                         break;                          break;
Line 1240  out:
Line 1243  out:
  * or string condition.   * or string condition.
  */   */
 static int  static int
 roff_evalcond(const char *v, int *pos)  roff_evalcond(struct roff *r, int ln, const char *v, int *pos)
 {  {
         int      wanttrue, number;          int      wanttrue, number;
   
Line 1271  roff_evalcond(const char *v, int *pos)
Line 1274  roff_evalcond(const char *v, int *pos)
                 break;                  break;
         }          }
   
         if (roff_evalnum(v, pos, &number, 0))          if (roff_evalnum(r, ln, v, pos, &number, 0))
                 return((number > 0) == wanttrue);                  return((number > 0) == wanttrue);
         else          else
                 return(roff_evalstrcond(v, pos) == wanttrue);                  return(roff_evalstrcond(v, pos) == wanttrue);
Line 1300  roff_cond(ROFF_ARGS)
Line 1303  roff_cond(ROFF_ARGS)
   
         r->last->rule = ROFF_el == tok ?          r->last->rule = ROFF_el == tok ?
             (r->rstackpos < 0 ? 0 : r->rstack[r->rstackpos--]) :              (r->rstackpos < 0 ? 0 : r->rstack[r->rstackpos--]) :
             roff_evalcond(*bufp, &pos);              roff_evalcond(r, ln, *bufp, &pos);
   
         /*          /*
          * An if-else will put the NEGATION of the current evaluated           * An if-else will put the NEGATION of the current evaluated
Line 1466  roff_getop(const char *v, int *pos, char *res)
Line 1469  roff_getop(const char *v, int *pos, char *res)
  * or a single signed integer number.   * or a single signed integer number.
  */   */
 static int  static int
 roff_evalpar(const char *v, int *pos, int *res)  roff_evalpar(struct roff *r, int ln,
           const char *v, int *pos, int *res)
 {  {
   
         if ('(' != v[*pos])          if ('(' != v[*pos])
                 return(roff_getnum(v, pos, res));                  return(roff_getnum(v, pos, res));
   
         (*pos)++;          (*pos)++;
         if ( ! roff_evalnum(v, pos, res, 1))          if ( ! roff_evalnum(r, ln, v, pos, res, 1))
                 return(0);                  return(0);
   
         /*          /*
Line 1495  roff_evalpar(const char *v, int *pos, int *res)
Line 1499  roff_evalpar(const char *v, int *pos, int *res)
  * Proceed left to right, there is no concept of precedence.   * Proceed left to right, there is no concept of precedence.
  */   */
 static int  static int
 roff_evalnum(const char *v, int *pos, int *res, int skipwhite)  roff_evalnum(struct roff *r, int ln, const char *v,
           int *pos, int *res, int skipwhite)
 {  {
         int              mypos, operand2;          int              mypos, operand2;
         char             operator;          char             operator;
Line 1509  roff_evalnum(const char *v, int *pos, int *res, int sk
Line 1514  roff_evalnum(const char *v, int *pos, int *res, int sk
                 while (isspace((unsigned char)v[*pos]))                  while (isspace((unsigned char)v[*pos]))
                         (*pos)++;                          (*pos)++;
   
         if ( ! roff_evalpar(v, pos, res))          if ( ! roff_evalpar(r, ln, v, pos, res))
                 return(0);                  return(0);
   
         while (1) {          while (1) {
Line 1524  roff_evalnum(const char *v, int *pos, int *res, int sk
Line 1529  roff_evalnum(const char *v, int *pos, int *res, int sk
                         while (isspace((unsigned char)v[*pos]))                          while (isspace((unsigned char)v[*pos]))
                                 (*pos)++;                                  (*pos)++;
   
                 if ( ! roff_evalpar(v, pos, &operand2))                  if ( ! roff_evalpar(r, ln, v, pos, &operand2))
                         return(0);                          return(0);
   
                 if (skipwhite)                  if (skipwhite)
Line 1545  roff_evalnum(const char *v, int *pos, int *res, int sk
Line 1550  roff_evalnum(const char *v, int *pos, int *res, int sk
                         *res *= operand2;                          *res *= operand2;
                         break;                          break;
                 case '/':                  case '/':
                           if (0 == operand2) {
                                   mandoc_msg(MANDOCERR_DIVZERO,
                                           r->parse, ln, *pos, v);
                                   *res = 0;
                                   break;
                           }
                         *res /= operand2;                          *res /= operand2;
                         break;                          break;
                 case '%':                  case '%':
Line 1719  roff_nr(ROFF_ARGS)
Line 1730  roff_nr(ROFF_ARGS)
         if ('+' == sign || '-' == sign)          if ('+' == sign || '-' == sign)
                 val++;                  val++;
   
         if (roff_evalnum(val, NULL, &iv, 0))          if (roff_evalnum(r, ln, val, NULL, &iv, 0))
                 roff_setreg(r, key, iv, sign);                  roff_setreg(r, key, iv, sign);
   
         return(ROFF_IGN);          return(ROFF_IGN);
Line 1857  roff_T_(ROFF_ARGS)
Line 1868  roff_T_(ROFF_ARGS)
 static enum rofferr  static enum rofferr
 roff_eqndelim(struct roff *r, char **bufp, size_t *szp, int pos)  roff_eqndelim(struct roff *r, char **bufp, size_t *szp, int pos)
 {  {
         char    *cp1, *cp2;          char            *cp1, *cp2;
           const char      *bef_pr, *bef_nl, *mac, *aft_nl, *aft_pr;
   
         /*          /*
          * Outside equations, look for an opening delimiter.           * Outside equations, look for an opening delimiter.
Line 1872  roff_eqndelim(struct roff *r, char **bufp, size_t *szp
Line 1884  roff_eqndelim(struct roff *r, char **bufp, size_t *szp
         if (cp2 == NULL)          if (cp2 == NULL)
                 return(ROFF_CONT);                  return(ROFF_CONT);
   
         /* Replace the delimiter with an equation macro. */  
   
         *cp2++ = '\0';          *cp2++ = '\0';
         *szp = mandoc_asprintf(&cp1, "%s%s%s", *bufp,          bef_pr = bef_nl = aft_nl = aft_pr = "";
             r->eqn == NULL ? "\\&\n.EQ\n" : "\n.EN\n\\&", cp2) + 1;  
           /* Handle preceding text, protecting whitespace. */
   
           if (**bufp != '\0') {
                   if (r->eqn == NULL)
                           bef_pr = "\\&";
                   bef_nl = "\n";
           }
   
           /*
            * Prepare replacing the delimiter with an equation macro
            * and drop leading white space from the equation.
            */
   
           if (r->eqn == NULL) {
                   while (*cp2 == ' ')
                           cp2++;
                   mac = ".EQ";
           } else
                   mac = ".EN";
   
           /* Handle following text, protecting whitespace. */
   
           if (*cp2 != '\0') {
                   aft_nl = "\n";
                   if (r->eqn != NULL)
                           aft_pr = "\\&";
           }
   
           /* Do the actual replacement. */
   
           *szp = mandoc_asprintf(&cp1, "%s%s%s%s%s%s%s", *bufp,
               bef_pr, bef_nl, mac, aft_nl, aft_pr, cp2) + 1;
         free(*bufp);          free(*bufp);
         *bufp = cp1;          *bufp = cp1;
   

Legend:
Removed from v.1.232  
changed lines
  Added in v.1.234

CVSweb