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

Diff for /mandoc/roff.c between version 1.207 and 1.219

version 1.207, 2014/04/20 16:46:05 version 1.219, 2014/07/06 19:09:00
Line 187  static int   roff_evalstrcond(const char *, int *);
Line 187  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 *);
 static  void             roff_freestr(struct roffkv *);  static  void             roff_freestr(struct roffkv *);
 static  char            *roff_getname(struct roff *, char **, int, int);  static  size_t           roff_getname(struct roff *, char **, int, int);
 static  int              roff_getnum(const char *, int *, int *);  static  int              roff_getnum(const char *, int *, int *);
 static  int              roff_getop(const char *, int *, char *);  static  int              roff_getop(const char *, int *, char *);
 static  int              roff_getregn(const struct roff *,  static  int              roff_getregn(const struct roff *,
Line 200  static enum rofferr  roff_line_ignore(ROFF_ARGS);
Line 200  static enum rofferr  roff_line_ignore(ROFF_ARGS);
 static  enum rofferr     roff_nr(ROFF_ARGS);  static  enum rofferr     roff_nr(ROFF_ARGS);
 static  void             roff_openeqn(struct roff *, const char *,  static  void             roff_openeqn(struct roff *, const char *,
                                 int, int, const char *);                                  int, int, const char *);
 static  enum rofft       roff_parse(struct roff *, const char *, int *);  static  enum rofft       roff_parse(struct roff *, char *, int *,
                                   int, int);
 static  enum rofferr     roff_parsetext(char **, size_t *, int, int *);  static  enum rofferr     roff_parsetext(char **, size_t *, int, int *);
 static  enum rofferr     roff_res(struct roff *,  static  enum rofferr     roff_res(struct roff *,
                                 char **, size_t *, int, int);                                  char **, size_t *, int, int);
Line 488  roff_alloc(struct mparse *parse, int options)
Line 489  roff_alloc(struct mparse *parse, int options)
 static enum rofferr  static enum rofferr
 roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)  roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)
 {  {
         char             ubuf[12]; /* 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              arg_complete; /* argument not interrupted by eol */
         char             term;  /* character terminating the escape */          char             term;  /* character terminating the escape */
   
         expand_count = 0;          expand_count = 0;
Line 520  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 520  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 542  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 542  roff_res(struct roff *r, char **bufp, size_t *szp, int
                         break;                          break;
                 default:                  default:
                         if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL))                          if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL))
                                 mandoc_msg(MANDOCERR_BADESCAPE, r->parse,                                  mandoc_vmsg(MANDOCERR_ESC_BAD,
                                     ln, (int)(stesc - *bufp), NULL);                                      r->parse, ln, (int)(stesc - *bufp),
                                       "%.*s", (int)(cp - stesc), stesc);
                         continue;                          continue;
                 }                  }
   
Line 585  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 586  roff_res(struct roff *r, char **bufp, size_t *szp, int
   
                 /* Advance to the end of the name. */                  /* Advance to the end of the name. */
   
                   arg_complete = 1;
                 for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) {                  for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) {
                         if ('\0' == *cp) {                          if ('\0' == *cp) {
                                 mandoc_msg(MANDOCERR_BADESCAPE, r->parse,                                  mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
                                     ln, (int)(stesc - *bufp), NULL);                                      ln, (int)(stesc - *bufp), stesc);
                                   arg_complete = 0;
                                 break;                                  break;
                         }                          }
                         if (0 == maxl && *cp == term) {                          if (0 == maxl && *cp == term) {
Line 604  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 607  roff_res(struct roff *r, char **bufp, size_t *szp, int
   
                 switch (stesc[1]) {                  switch (stesc[1]) {
                 case '*':                  case '*':
                         res = roff_getstrn(r, stnam, naml);                          if (arg_complete)
                                   res = roff_getstrn(r, stnam, naml);
                         break;                          break;
                 case 'B':                  case 'B':
                         npos = 0;                          npos = 0;
                         irc = roff_evalnum(stnam, &npos, NULL, 0);                          ubuf[0] = arg_complete &&
                         ubuf[0] = irc && stnam + npos + 1 == cp                              roff_evalnum(stnam, &npos, NULL, 0) &&
                             ? '1' : '0';                              stnam + npos + 1 == cp ? '1' : '0';
                         ubuf[1] = '\0';                          ubuf[1] = '\0';
                         break;                          break;
                 case 'n':                  case 'n':
                         snprintf(ubuf, sizeof(ubuf), "%d",                          if (arg_complete)
                             roff_getregn(r, stnam, naml));                                  (void)snprintf(ubuf, sizeof(ubuf), "%d",
                                       roff_getregn(r, stnam, naml));
                           else
                                   ubuf[0] = '\0';
                         break;                          break;
                 case 'w':                  case 'w':
                         snprintf(ubuf, sizeof(ubuf), "%d",                          /* use even incomplete args */
                           (void)snprintf(ubuf, sizeof(ubuf), "%d",
                             24 * (int)naml);                              24 * (int)naml);
                         break;                          break;
                 }                  }
   
                 if (NULL == res) {                  if (NULL == res) {
                         mandoc_msg(MANDOCERR_BADESCAPE, r->parse,                          mandoc_vmsg(MANDOCERR_STR_UNDEF,
                             ln, (int)(stesc - *bufp), NULL);                              r->parse, ln, (int)(stesc - *bufp),
                               "%.*s", (int)naml, stnam);
                         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 769  roff_parseln(struct roff *r, int ln, char **bufp,
Line 774  roff_parseln(struct roff *r, int ln, char **bufp,
          * the compilers handle it.           * the compilers handle it.
          */           */
   
         if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos)))          if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos, ln, ppos)))
                 return(ROFF_CONT);                  return(ROFF_CONT);
   
         assert(roffs[t].proc);          assert(roffs[t].proc);
Line 802  roff_endparse(struct roff *r)
Line 807  roff_endparse(struct roff *r)
  * form of ".foo xxx" in the usual way.   * form of ".foo xxx" in the usual way.
  */   */
 static enum rofft  static enum rofft
 roff_parse(struct roff *r, const char *buf, int *pos)  roff_parse(struct roff *r, char *buf, int *pos, int ln, int ppos)
 {  {
           char            *cp;
         const char      *mac;          const char      *mac;
         size_t           maclen;          size_t           maclen;
         enum rofft       t;          enum rofft       t;
   
         if ('\0' == buf[*pos] || '"' == buf[*pos] ||          cp = buf + *pos;
             '\t' == buf[*pos] || ' ' == buf[*pos])  
           if ('\0' == *cp || '"' == *cp || '\t' == *cp || ' ' == *cp)
                 return(ROFF_MAX);                  return(ROFF_MAX);
   
         /* We stop the macro parse at an escape, tab, space, or nil. */          mac = cp;
           maclen = roff_getname(r, &cp, ln, ppos);
   
         mac = buf + *pos;  
         maclen = strcspn(mac, " \\\t\0");  
   
         t = (r->current_string = roff_getstrn(r, mac, maclen))          t = (r->current_string = roff_getstrn(r, mac, maclen))
             ? ROFF_USERDEF : roffhash_find(mac, maclen);              ? ROFF_USERDEF : roffhash_find(mac, maclen);
   
         *pos += (int)maclen;          if (ROFF_MAX != t)
                   *pos = cp - buf;
   
         while (buf[*pos] && ' ' == buf[*pos])  
                 (*pos)++;  
   
         return(t);          return(t);
 }  }
   
Line 862  roff_cblock(ROFF_ARGS)
Line 865  roff_cblock(ROFF_ARGS)
         }          }
   
         if ((*bufp)[pos])          if ((*bufp)[pos])
                 mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL);                  mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
                       ".. %s", *bufp + pos);
   
         roffnode_pop(r);          roffnode_pop(r);
         roffnode_cleanscope(r);          roffnode_cleanscope(r);
Line 915  roff_ccond(struct roff *r, int ln, int ppos)
Line 919  roff_ccond(struct roff *r, int ln, int ppos)
 static enum rofferr  static enum rofferr
 roff_block(ROFF_ARGS)  roff_block(ROFF_ARGS)
 {  {
         int             sv;          char            *name, *cp;
         size_t          sz;          size_t           namesz;
         char            *name;  
   
         name = NULL;          name = cp = *bufp + pos;
           namesz = 0;
   
         if (ROFF_ig != tok) {          if (ROFF_ig != tok) {
                 if ('\0' == (*bufp)[pos]) {                  if ('\0' == *cp) {
                         mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL);                          mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse,
                               ln, ppos, roffs[tok].name);
                         return(ROFF_IGN);                          return(ROFF_IGN);
                 }                  }
   
Line 934  roff_block(ROFF_ARGS)
Line 939  roff_block(ROFF_ARGS)
   
                 if (ROFF_de1 == tok)                  if (ROFF_de1 == tok)
                         tok = ROFF_de;                          tok = ROFF_de;
                 if (ROFF_de == tok)                  else if (ROFF_de != tok)
                         name = *bufp + pos;  
                 else  
                         mandoc_msg(MANDOCERR_REQUEST, r->parse, ln, ppos,                          mandoc_msg(MANDOCERR_REQUEST, r->parse, ln, ppos,
                             roffs[tok].name);                              roffs[tok].name);
   
                 while ((*bufp)[pos] && ! isspace((unsigned char)(*bufp)[pos]))                  namesz = roff_getname(r, &cp, ln, ppos);
                         pos++;                  name[namesz] = '\0';
           } else
                   name = NULL;
   
                 while (isspace((unsigned char)(*bufp)[pos]))  
                         (*bufp)[pos++] = '\0';  
         }  
   
         roffnode_push(r, tok, name, ln, ppos);          roffnode_push(r, tok, name, ln, ppos);
   
         /*          /*
Line 955  roff_block(ROFF_ARGS)
Line 956  roff_block(ROFF_ARGS)
          * appended from roff_block_text() in multiline mode.           * appended from roff_block_text() in multiline mode.
          */           */
   
         if (ROFF_de == tok)          if (namesz && ROFF_de == tok)
                 roff_setstr(r, name, "", 0);                  roff_setstrn(&r->strtab, name, namesz, "", 0, 0);
   
         if ('\0' == (*bufp)[pos])          if ('\0' == *cp)
                 return(ROFF_IGN);                  return(ROFF_IGN);
   
         /* If present, process the custom end-of-line marker. */          /* If present, process the custom end-of-line marker. */
   
         sv = pos;          name = cp;
         while ((*bufp)[pos] && ! isspace((unsigned char)(*bufp)[pos]))          namesz = roff_getname(r, &cp, ln, ppos);
                 pos++;          if (namesz)
                   r->last->end = mandoc_strndup(name, namesz);
   
         /*          if ('\0' != *cp)
          * Note: groff does NOT like escape characters in the input.                  mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
          * Instead of detecting this, we're just going to let it fly and                      ln, pos, ".%s ... %s", roffs[tok].name, cp);
          * to hell with it.  
          */  
   
         assert(pos > sv);  
         sz = (size_t)(pos - sv);  
   
         if (1 == sz && '.' == (*bufp)[sv])  
                 return(ROFF_IGN);  
   
         r->last->end = mandoc_malloc(sz + 1);  
   
         memcpy(r->last->end, *bufp + sv, sz);  
         r->last->end[(int)sz] = '\0';  
   
         if ((*bufp)[pos])  
                 mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL);  
   
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
Line 1021  roff_block_sub(ROFF_ARGS)
Line 1007  roff_block_sub(ROFF_ARGS)
                                 i++;                                  i++;
   
                         pos = i;                          pos = i;
                         if (ROFF_MAX != roff_parse(r, *bufp, &pos))                          if (ROFF_MAX != roff_parse(r, *bufp, &pos, ln, ppos))
                                 return(ROFF_RERUN);                                  return(ROFF_RERUN);
                         return(ROFF_IGN);                          return(ROFF_IGN);
                 }                  }
Line 1032  roff_block_sub(ROFF_ARGS)
Line 1018  roff_block_sub(ROFF_ARGS)
          * pulling it out of the hashtable.           * pulling it out of the hashtable.
          */           */
   
         t = roff_parse(r, *bufp, &pos);          t = roff_parse(r, *bufp, &pos, ln, ppos);
   
         /*          /*
          * Macros other than block-end are only significant           * Macros other than block-end are only significant
Line 1067  roff_cond_sub(ROFF_ARGS)
Line 1053  roff_cond_sub(ROFF_ARGS)
   
         rr = r->last->rule;          rr = r->last->rule;
         roffnode_cleanscope(r);          roffnode_cleanscope(r);
         t = roff_parse(r, *bufp, &pos);          t = roff_parse(r, *bufp, &pos, ln, ppos);
   
         /*          /*
          * Fully handle known macros when they are structurally           * Fully handle known macros when they are structurally
Line 1311  roff_cond(ROFF_ARGS)
Line 1297  roff_cond(ROFF_ARGS)
          */           */
   
         if ('\0' == (*bufp)[pos])          if ('\0' == (*bufp)[pos])
                 mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL);                  mandoc_msg(MANDOCERR_COND_EMPTY, r->parse,
                       ln, ppos, roffs[tok].name);
   
         r->last->endspan = 1;          r->last->endspan = 1;
   
Line 1323  out:
Line 1310  out:
 static enum rofferr  static enum rofferr
 roff_ds(ROFF_ARGS)  roff_ds(ROFF_ARGS)
 {  {
         char            *name, *string;          char            *string;
           const char      *name;
           size_t           namesz;
   
         /*          /*
          * A symbol is named by the first word following the macro           * The first word is the name of the string.
          * invocation up to a space.  Its value is anything after the           * If it is empty or terminated by an escape sequence,
          * name's trailing whitespace and optional double-quote.  Thus,           * abort the `ds' request without defining anything.
          *  
          *  [.ds foo "bar  "     ]  
          *  
          * will have `bar  "     ' as its value.  
          */           */
   
         string = *bufp + pos;          name = string = *bufp + pos;
         name = roff_getname(r, &string, ln, pos);  
         if ('\0' == *name)          if ('\0' == *name)
                 return(ROFF_IGN);                  return(ROFF_IGN);
   
         /* Read past initial double-quote. */          namesz = roff_getname(r, &string, ln, pos);
           if ('\\' == name[namesz])
                   return(ROFF_IGN);
   
           /* Read past the initial double-quote, if any. */
         if ('"' == *string)          if ('"' == *string)
                 string++;                  string++;
   
         /* The rest is the value. */          /* The rest is the value. */
         roff_setstr(r, name, string, ROFF_as == tok);          roff_setstrn(&r->strtab, name, namesz, string, strlen(string),
               ROFF_as == tok);
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
Line 1659  roff_freereg(struct roffreg *reg)
Line 1648  roff_freereg(struct roffreg *reg)
 static enum rofferr  static enum rofferr
 roff_nr(ROFF_ARGS)  roff_nr(ROFF_ARGS)
 {  {
         const char      *key;          char            *key, *val;
         char            *val;          size_t           keysz;
         int              iv;          int              iv;
         char             sign;          char             sign;
   
         val = *bufp + pos;          key = val = *bufp + pos;
         key = roff_getname(r, &val, ln, pos);          if ('\0' == *key)
                   return(ROFF_IGN);
   
           keysz = roff_getname(r, &val, ln, pos);
           if ('\\' == key[keysz])
                   return(ROFF_IGN);
           key[keysz] = '\0';
   
         sign = *val;          sign = *val;
         if ('+' == sign || '-' == sign)          if ('+' == sign || '-' == sign)
                 val++;                  val++;
Line 1681  static enum rofferr
Line 1676  static enum rofferr
 roff_rr(ROFF_ARGS)  roff_rr(ROFF_ARGS)
 {  {
         struct roffreg  *reg, **prev;          struct roffreg  *reg, **prev;
         const char      *name;          char            *name, *cp;
         char            *cp;          size_t           namesz;
   
         cp = *bufp + pos;          name = cp = *bufp + pos;
         name = roff_getname(r, &cp, ln, pos);          if ('\0' == *name)
                   return(ROFF_IGN);
           namesz = roff_getname(r, &cp, ln, pos);
           name[namesz] = '\0';
   
         prev = &r->regtab;          prev = &r->regtab;
         while (1) {          while (1) {
Line 1707  roff_rm(ROFF_ARGS)
Line 1705  roff_rm(ROFF_ARGS)
 {  {
         const char       *name;          const char       *name;
         char             *cp;          char             *cp;
           size_t            namesz;
   
         cp = *bufp + pos;          cp = *bufp + pos;
         while ('\0' != *cp) {          while ('\0' != *cp) {
                 name = roff_getname(r, &cp, ln, (int)(cp - *bufp));                  name = cp;
                 if ('\0' != *name)                  namesz = roff_getname(r, &cp, ln, (int)(cp - *bufp));
                         roff_setstr(r, name, NULL, 0);                  roff_setstrn(&r->strtab, name, namesz, NULL, 0, 0);
                   if ('\\' == name[namesz])
                           break;
         }          }
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
Line 1895  roff_tr(ROFF_ARGS)
Line 1896  roff_tr(ROFF_ARGS)
                 if ('\\' == *first) {                  if ('\\' == *first) {
                         esc = mandoc_escape(&p, NULL, NULL);                          esc = mandoc_escape(&p, NULL, NULL);
                         if (ESCAPE_ERROR == esc) {                          if (ESCAPE_ERROR == esc) {
                                 mandoc_msg(MANDOCERR_BADESCAPE,                                  mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
                                     r->parse, ln,                                      ln, (int)(p - *bufp), first);
                                     (int)(p - *bufp), NULL);  
                                 return(ROFF_IGN);                                  return(ROFF_IGN);
                         }                          }
                         fsz = (size_t)(p - first);                          fsz = (size_t)(p - first);
Line 1907  roff_tr(ROFF_ARGS)
Line 1907  roff_tr(ROFF_ARGS)
                 if ('\\' == *second) {                  if ('\\' == *second) {
                         esc = mandoc_escape(&p, NULL, NULL);                          esc = mandoc_escape(&p, NULL, NULL);
                         if (ESCAPE_ERROR == esc) {                          if (ESCAPE_ERROR == esc) {
                                 mandoc_msg(MANDOCERR_BADESCAPE,                                  mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
                                     r->parse, ln,                                      ln, (int)(p - *bufp), second);
                                     (int)(p - *bufp), NULL);  
                                 return(ROFF_IGN);                                  return(ROFF_IGN);
                         }                          }
                         ssz = (size_t)(p - second);                          ssz = (size_t)(p - second);
Line 1943  roff_so(ROFF_ARGS)
Line 1942  roff_so(ROFF_ARGS)
 {  {
         char *name;          char *name;
   
         mandoc_msg(MANDOCERR_SO, r->parse, ln, ppos, NULL);          name = *bufp + pos;
           mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, ".so %s", name);
   
         /*          /*
          * Handle `so'.  Be EXTREMELY careful, as we shouldn't be           * Handle `so'.  Be EXTREMELY careful, as we shouldn't be
Line 1952  roff_so(ROFF_ARGS)
Line 1952  roff_so(ROFF_ARGS)
          * or using absolute paths.           * or using absolute paths.
          */           */
   
         name = *bufp + pos;  
         if ('/' == *name || strstr(name, "../") || strstr(name, "/..")) {          if ('/' == *name || strstr(name, "../") || strstr(name, "/..")) {
                 mandoc_msg(MANDOCERR_SOPATH, r->parse, ln, pos, NULL);                  mandoc_vmsg(MANDOCERR_SO_PATH, r->parse, ln, ppos,
                       ".so %s", name);
                 return(ROFF_ERR);                  return(ROFF_ERR);
         }          }
   
Line 1990  roff_userdef(ROFF_ARGS)
Line 1990  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;
Line 2016  roff_userdef(ROFF_ARGS)
Line 2011  roff_userdef(ROFF_ARGS)
            ROFF_REPARSE : ROFF_APPEND);             ROFF_REPARSE : ROFF_APPEND);
 }  }
   
 static char *  static size_t
 roff_getname(struct roff *r, char **cpp, int ln, int pos)  roff_getname(struct roff *r, char **cpp, int ln, int pos)
 {  {
         char     *name, *cp;          char     *name, *cp;
           size_t    namesz;
   
         name = *cpp;          name = *cpp;
         if ('\0' == *name)          if ('\0' == *name)
                 return(name);                  return(0);
   
         /* Read until end of name. */          /* Read until end of name and terminate it with NUL. */
         for (cp = name; '\0' != *cp && ' ' != *cp; cp++) {          for (cp = name; 1; cp++) {
                   if ('\0' == *cp || ' ' == *cp) {
                           namesz = cp - name;
                           break;
                   }
                 if ('\\' != *cp)                  if ('\\' != *cp)
                         continue;                          continue;
                   namesz = cp - name;
                   if ('{' == cp[1] || '}' == cp[1])
                           break;
                 cp++;                  cp++;
                 if ('\\' == *cp)                  if ('\\' == *cp)
                         continue;                          continue;
                 mandoc_msg(MANDOCERR_NAMESC, r->parse, ln, pos, NULL);                  mandoc_msg(MANDOCERR_NAMESC, r->parse, ln, pos, NULL);
                 *cp = '\0';                  mandoc_escape((const char **)&cp, NULL, NULL);
                 name = cp;                  break;
         }          }
   
         /* Nil-terminate name. */  
         if ('\0' != *cp)  
                 *(cp++) = '\0';  
   
         /* Read past spaces. */          /* Read past spaces. */
         while (' ' == *cp)          while (' ' == *cp)
                 cp++;                  cp++;
   
         *cpp = cp;          *cpp = cp;
         return(name);          return(namesz);
 }  }
   
 /*  /*
Line 2077  roff_setstrn(struct roffkv **r, const char *name, size
Line 2076  roff_setstrn(struct roffkv **r, const char *name, size
         /* Search for an existing string with the same name. */          /* Search for an existing string with the same name. */
         n = *r;          n = *r;
   
         while (n && strcmp(name, n->key.p))          while (n && (namesz != n->key.sz ||
                           strncmp(n->key.p, name, namesz)))
                 n = n->next;                  n = n->next;
   
         if (NULL == n) {          if (NULL == n) {

Legend:
Removed from v.1.207  
changed lines
  Added in v.1.219

CVSweb