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

Diff for /mandoc/roff.c between version 1.208 and 1.209

version 1.208, 2014/04/20 19:40:13 version 1.209, 2014/04/23 16:08:33
Line 490  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 490  roff_res(struct roff *r, char **bufp, size_t *szp, int
 {  {
         char             ubuf[24]; /* buffer to print the number */          char             ubuf[24]; /* buffer to print the number */
         const char      *start; /* start of the string to process */          const char      *start; /* start of the string to process */
         const char      *stesc; /* start of an escape sequence ('\\') */          char            *stesc; /* start of an escape sequence ('\\') */
         const char      *stnam; /* start of the name, after "[(*" */          const char      *stnam; /* start of the name, after "[(*" */
         const char      *cp;    /* end of the name, e.g. before ']' */          const char      *cp;    /* end of the name, e.g. before ']' */
         const char      *res;   /* the string to be substituted */          const char      *res;   /* the string to be substituted */
         char            *nbuf;  /* new buffer to copy bufp to */          char            *nbuf;  /* new buffer to copy bufp to */
         size_t           maxl;  /* expected length of the escape name */          size_t           maxl;  /* expected length of the escape name */
         size_t           naml;  /* actual length of the escape name */          size_t           naml;  /* actual length of the escape name */
         size_t           ressz; /* size of the replacement string */  
         int              expand_count;  /* to avoid infinite loops */          int              expand_count;  /* to avoid infinite loops */
         int              npos;  /* position in numeric expression */          int              npos;  /* position in numeric expression */
         int              irc;   /* return code from roff_evalnum() */          int              irc;   /* return code from roff_evalnum() */
Line 520  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 519  roff_res(struct roff *r, char **bufp, size_t *szp, int
                                 break;                                  break;
   
                 if (0 == (stesc - cp) % 2) {                  if (0 == (stesc - cp) % 2) {
                         stesc = cp;                          stesc = (char *)cp;
                         continue;                          continue;
                 }                  }
   
Line 628  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 627  roff_res(struct roff *r, char **bufp, size_t *szp, int
                             ln, (int)(stesc - *bufp), NULL);                              ln, (int)(stesc - *bufp), NULL);
                         res = "";                          res = "";
                 }                  }
                 ressz = strlen(res);  
   
                 /* Replace the escape sequence by the string. */                  /* Replace the escape sequence by the string. */
   
                 *szp += ressz + 1;                  *stesc = '\0';
                 nbuf = mandoc_malloc(*szp);                  *szp = mandoc_asprintf(&nbuf, "%s%s%s",
                       *bufp, res, cp) + 1;
   
                 strlcpy(nbuf, *bufp, (size_t)(stesc - *bufp + 1));  
                 strlcat(nbuf, res, *szp);  
                 strlcat(nbuf, cp, *szp);  
   
                 /* Prepare for the next replacement. */                  /* Prepare for the next replacement. */
   
                 start = nbuf + pos;                  start = nbuf + pos;
                 stesc = nbuf + (stesc - *bufp) + ressz;                  stesc = nbuf + (stesc - *bufp) + strlen(res);
                 free(*bufp);                  free(*bufp);
                 *bufp = nbuf;                  *bufp = nbuf;
         }          }
Line 1990  roff_userdef(ROFF_ARGS)
Line 1985  roff_userdef(ROFF_ARGS)
                         cp += 2;                          cp += 2;
                         continue;                          continue;
                 }                  }
                   *cp = '\0';
                 *szp = strlen(n1) - 3 + strlen(arg[i]) + 1;                  *szp = mandoc_asprintf(&n2, "%s%s%s",
                 n2 = mandoc_malloc(*szp);                      n1, arg[i], cp + 3) + 1;
   
                 strlcpy(n2, n1, (size_t)(cp - n1 + 1));  
                 strlcat(n2, arg[i], *szp);  
                 strlcat(n2, cp + 3, *szp);  
   
                 cp = n2 + (cp - n1);                  cp = n2 + (cp - n1);
                 free(n1);                  free(n1);
                 n1 = n2;                  n1 = n2;

Legend:
Removed from v.1.208  
changed lines
  Added in v.1.209

CVSweb