[BACK]Return to roff.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Diff for /src/usr.bin/mandoc/roff.c between version 1.79 and 1.80

version 1.79, 2014/04/08 01:36:50 version 1.80, 2014/04/20 16:44:44
Line 133 
Line 133 
   
 #define ROFF_ARGS        struct roff *r, /* parse ctx */ \  #define ROFF_ARGS        struct roff *r, /* parse ctx */ \
                          enum rofft tok, /* tok of macro */ \                           enum rofft tok, /* tok of macro */ \
                          char **bufp, /* input buffer */ \                           char **bufp, /* input buffer */ \
                          size_t *szp, /* size of input buffer */ \                           size_t *szp, /* size of input buffer */ \
                          int ln, /* parse line */ \                           int ln, /* parse line */ \
                          int ppos, /* original pos in buffer */ \                           int ppos, /* original pos in buffer */ \
Line 189 
Line 189 
 static  int              roff_getregn(const struct roff *,  static  int              roff_getregn(const struct roff *,
                                 const char *, size_t);                                  const char *, size_t);
 static  int              roff_getregro(const char *name);  static  int              roff_getregro(const char *name);
 static  const char      *roff_getstrn(const struct roff *,  static  const char      *roff_getstrn(const struct roff *,
                                 const char *, size_t);                                  const char *, size_t);
 static  enum rofferr     roff_it(ROFF_ARGS);  static  enum rofferr     roff_it(ROFF_ARGS);
 static  enum rofferr     roff_line_ignore(ROFF_ARGS);  static  enum rofferr     roff_line_ignore(ROFF_ARGS);
Line 198 
Line 198 
                                 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 *, const char *, 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);
 static  enum rofferr     roff_rm(ROFF_ARGS);  static  enum rofferr     roff_rm(ROFF_ARGS);
 static  enum rofferr     roff_rr(ROFF_ARGS);  static  enum rofferr     roff_rr(ROFF_ARGS);
 static  void             roff_setstr(struct roff *,  static  void             roff_setstr(struct roff *,
                                 const char *, const char *, int);                                  const char *, const char *, int);
 static  void             roff_setstrn(struct roffkv **, const char *,  static  void             roff_setstrn(struct roffkv **, const char *,
                                 size_t, const char *, size_t, int);                                  size_t, const char *, size_t, int);
 static  enum rofferr     roff_so(ROFF_ARGS);  static  enum rofferr     roff_so(ROFF_ARGS);
 static  enum rofferr     roff_tr(ROFF_ARGS);  static  enum rofferr     roff_tr(ROFF_ARGS);
Line 311 
Line 311 
 static  int      roffit_lines;  /* number of lines to delay */  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 */
   
   
 static void  static void
 roffhash_init(void)  roffhash_init(void)
 {  {
Line 363 
Line 364 
         return(ROFF_MAX);          return(ROFF_MAX);
 }  }
   
   
 /*  /*
  * 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 374 
Line 374 
         struct roffnode *p;          struct roffnode *p;
   
         assert(r->last);          assert(r->last);
         p = r->last;          p = r->last;
   
         r->last = r->last->parent;          r->last = r->last->parent;
         free(p->name);          free(p->name);
Line 382 
Line 382 
         free(p);          free(p);
 }  }
   
   
 /*  /*
  * Push a roff node onto the instruction stack.  This must later be   * Push a roff node onto the instruction stack.  This must later be
  * removed with roffnode_pop().   * removed with roffnode_pop().
Line 405 
Line 404 
         r->last = p;          r->last = p;
 }  }
   
   
 static void  static void
 roff_free1(struct roff *r)  roff_free1(struct roff *r)
 {  {
Line 455 
Line 453 
         r->control = 0;          r->control = 0;
 }  }
   
   
 void  void
 roff_free(struct roff *r)  roff_free(struct roff *r)
 {  {
Line 464 
Line 461 
         free(r);          free(r);
 }  }
   
   
 struct roff *  struct roff *
 roff_alloc(struct mparse *parse, int options)  roff_alloc(struct mparse *parse, int options)
 {  {
Line 474 
Line 470 
         r->parse = parse;          r->parse = parse;
         r->options = options;          r->options = options;
         r->rstackpos = -1;          r->rstackpos = -1;
   
         roffhash_init();          roffhash_init();
   
         return(r);          return(r);
Line 529 
Line 525 
                 term = '\0';                  term = '\0';
                 cp = stesc + 1;                  cp = stesc + 1;
                 switch (*cp) {                  switch (*cp) {
                 case ('*'):                  case '*':
                         res = NULL;                          res = NULL;
                         break;                          break;
                 case ('B'):                  case 'B':
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case ('w'):                  case 'w':
                         term = cp[1];                          term = cp[1];
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case ('n'):                  case 'n':
                         res = ubuf;                          res = ubuf;
                         break;                          break;
                 default:                  default:
Line 561 
Line 557 
   
                 if ('\0' == term) {                  if ('\0' == term) {
                         switch (*++cp) {                          switch (*++cp) {
                         case ('\0'):                          case '\0':
                                 maxl = 0;                                  maxl = 0;
                                 break;                                  break;
                         case ('('):                          case '(':
                                 cp++;                                  cp++;
                                 maxl = 2;                                  maxl = 2;
                                 break;                                  break;
                         case ('['):                          case '[':
                                 cp++;                                  cp++;
                                 term = ']';                                  term = ']';
                                 maxl = 0;                                  maxl = 0;
Line 587 
Line 583 
   
                 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                                  mandoc_msg(MANDOCERR_BADESCAPE, r->parse,
                                         (MANDOCERR_BADESCAPE,                                      ln, (int)(stesc - *bufp), NULL);
                                          r->parse, ln,  
                                          (int)(stesc - *bufp), NULL);  
                                 break;                                  break;
                         }                          }
                         if (0 == maxl && *cp == term) {                          if (0 == maxl && *cp == term) {
Line 605 
Line 599 
                  */                   */
   
                 switch (stesc[1]) {                  switch (stesc[1]) {
                 case ('*'):                  case '*':
                         res = roff_getstrn(r, stnam, naml);                          res = roff_getstrn(r, stnam, naml);
                         break;                          break;
                 case ('B'):                  case 'B':
                         npos = 0;                          npos = 0;
                         irc = roff_evalnum(stnam, &npos, NULL, 0);                          irc = roff_evalnum(stnam, &npos, NULL, 0);
                         ubuf[0] = irc && stnam + npos + 1 == cp                          ubuf[0] = irc && stnam + npos + 1 == cp
                             ? '1' : '0';                              ? '1' : '0';
                         ubuf[1] = '\0';                          ubuf[1] = '\0';
                         break;                          break;
                 case ('n'):                  case 'n':
                         snprintf(ubuf, sizeof(ubuf), "%d",                          snprintf(ubuf, sizeof(ubuf), "%d",
                             roff_getregn(r, stnam, naml));                              roff_getregn(r, stnam, naml));
                         break;                          break;
                 case ('w'):                  case 'w':
                         snprintf(ubuf, sizeof(ubuf), "%d",                          snprintf(ubuf, sizeof(ubuf), "%d",
                             24 * (int)naml);                              24 * (int)naml);
                         break;                          break;
                 }                  }
   
                 if (NULL == res) {                  if (NULL == res) {
                         mandoc_msg                          mandoc_msg(MANDOCERR_BADESCAPE, r->parse,
                                 (MANDOCERR_BADESCAPE, r->parse,                              ln, (int)(stesc - *bufp), NULL);
                                  ln, (int)(stesc - *bufp), NULL);  
                         res = "";                          res = "";
                 }                  }
                 ressz = strlen(res);                  ressz = strlen(res);
Line 709 
Line 702 
 }  }
   
 enum rofferr  enum rofferr
 roff_parseln(struct roff *r, int ln, char **bufp,  roff_parseln(struct roff *r, int ln, char **bufp,
                 size_t *szp, int pos, int *offs)                  size_t *szp, int pos, int *offs)
 {  {
         enum rofft       t;          enum rofft       t;
Line 740 
Line 733 
         if (r->last && ! ctl) {          if (r->last && ! ctl) {
                 t = r->last->tok;                  t = r->last->tok;
                 assert(roffs[t].text);                  assert(roffs[t].text);
                 e = (*roffs[t].text)                  e = (*roffs[t].text)(r, t, bufp, szp, ln, pos, pos, offs);
                         (r, t, bufp, szp, ln, pos, pos, offs);  
                 assert(ROFF_IGN == e || ROFF_CONT == e);                  assert(ROFF_IGN == e || ROFF_CONT == e);
                 if (ROFF_CONT != e)                  if (ROFF_CONT != e)
                         return(e);                          return(e);
Line 763 
Line 755 
         if (r->last) {          if (r->last) {
                 t = r->last->tok;                  t = r->last->tok;
                 assert(roffs[t].sub);                  assert(roffs[t].sub);
                 return((*roffs[t].sub)                  return((*roffs[t].sub)(r, t, bufp, szp,
                                 (r, t, bufp, szp,                      ln, ppos, pos, offs));
                                  ln, ppos, pos, offs));  
         }          }
   
         /*          /*
Line 778 
Line 769 
                 return(ROFF_CONT);                  return(ROFF_CONT);
   
         assert(roffs[t].proc);          assert(roffs[t].proc);
         return((*roffs[t].proc)          return((*roffs[t].proc)(r, t, bufp, szp, ln, ppos, pos, offs));
                         (r, t, bufp, szp,  
                          ln, ppos, pos, offs));  
 }  }
   
   
 void  void
 roff_endparse(struct roff *r)  roff_endparse(struct roff *r)
 {  {
   
         if (r->last)          if (r->last)
                 mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse,                  mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse,
                                 r->last->line, r->last->col, NULL);                      r->last->line, r->last->col, NULL);
   
         if (r->eqn) {          if (r->eqn) {
                 mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse,                  mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse,
                                 r->eqn->eqn.ln, r->eqn->eqn.pos, NULL);                      r->eqn->eqn.ln, r->eqn->eqn.pos, NULL);
                 eqn_end(&r->eqn);                  eqn_end(&r->eqn);
         }          }
   
         if (r->tbl) {          if (r->tbl) {
                 mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse,                  mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse,
                                 r->tbl->line, r->tbl->pos, NULL);                      r->tbl->line, r->tbl->pos, NULL);
                 tbl_end(&r->tbl);                  tbl_end(&r->tbl);
         }          }
 }  }
Line 816 
Line 804 
         size_t           maclen;          size_t           maclen;
         enum rofft       t;          enum rofft       t;
   
         if ('\0' == buf[*pos] || '"' == buf[*pos] ||          if ('\0' == buf[*pos] || '"' == buf[*pos] ||
                         '\t' == buf[*pos] || ' ' == buf[*pos])              '\t' == buf[*pos] || ' ' == buf[*pos])
                 return(ROFF_MAX);                  return(ROFF_MAX);
   
         /* We stop the macro parse at an escape, tab, space, or nil. */          /* We stop the macro parse at an escape, tab, space, or nil. */
Line 836 
Line 824 
         return(t);          return(t);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cblock(ROFF_ARGS)  roff_cblock(ROFF_ARGS)
 {  {
Line 852 
Line 839 
         }          }
   
         switch (r->last->tok) {          switch (r->last->tok) {
         case (ROFF_am):          case ROFF_am:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_ami):          case ROFF_ami:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_am1):          case ROFF_am1:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_de):          case ROFF_de:
                 /* ROFF_de1 is remapped to ROFF_de in roff_block(). */                  /* ROFF_de1 is remapped to ROFF_de in roff_block(). */
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_dei):          case ROFF_dei:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_ig):          case ROFF_ig:
                 break;                  break;
         default:          default:
                 mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL);                  mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL);
Line 879 
Line 866 
   
 }  }
   
   
 static void  static void
 roffnode_cleanscope(struct roff *r)  roffnode_cleanscope(struct roff *r)
 {  {
Line 891 
Line 877 
         }          }
 }  }
   
   
 static void  static void
 roff_ccond(struct roff *r, int ln, int ppos)  roff_ccond(struct roff *r, int ln, int ppos)
 {  {
Line 902 
Line 887 
         }          }
   
         switch (r->last->tok) {          switch (r->last->tok) {
         case (ROFF_el):          case ROFF_el:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_ie):          case ROFF_ie:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ROFF_if):          case ROFF_if:
                 break;                  break;
         default:          default:
                 mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL);                  mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL);
Line 923 
Line 908 
         return;          return;
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_block(ROFF_ARGS)  roff_block(ROFF_ARGS)
 {  {
Line 1003 
Line 986 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_block_sub(ROFF_ARGS)  roff_block_sub(ROFF_ARGS)
 {  {
Line 1025 
Line 1006 
                         if ((*bufp)[i] != r->last->end[j])                          if ((*bufp)[i] != r->last->end[j])
                                 break;                                  break;
   
                 if ('\0' == r->last->end[j] &&                  if ('\0' == r->last->end[j] &&
                                 ('\0' == (*bufp)[i] ||                      ('\0' == (*bufp)[i] ||
                                  ' ' == (*bufp)[i] ||                       ' '  == (*bufp)[i] ||
                                  '\t' == (*bufp)[i])) {                       '\t' == (*bufp)[i])) {
                         roffnode_pop(r);                          roffnode_pop(r);
                         roffnode_cleanscope(r);                          roffnode_cleanscope(r);
   
Line 1060 
Line 1041 
         }          }
   
         assert(roffs[t].proc);          assert(roffs[t].proc);
         return((*roffs[t].proc)(r, t, bufp, szp,          return((*roffs[t].proc)(r, t, bufp, szp, ln, ppos, pos, offs));
                                 ln, ppos, pos, offs));  
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_block_text(ROFF_ARGS)  roff_block_text(ROFF_ARGS)
 {  {
Line 1076 
Line 1054 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cond_sub(ROFF_ARGS)  roff_cond_sub(ROFF_ARGS)
 {  {
Line 1098 
Line 1074 
             (rr || ROFFMAC_STRUCT & roffs[t].flags)) {              (rr || ROFFMAC_STRUCT & roffs[t].flags)) {
                 assert(roffs[t].proc);                  assert(roffs[t].proc);
                 return((*roffs[t].proc)(r, t, bufp, szp,                  return((*roffs[t].proc)(r, t, bufp, szp,
                                         ln, ppos, pos, offs));                      ln, ppos, pos, offs));
         }          }
   
         /*          /*
Line 1122 
Line 1098 
         return(rr ? ROFF_CONT : ROFF_IGN);          return(rr ? ROFF_CONT : ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cond_text(ROFF_ARGS)  roff_cond_text(ROFF_ARGS)
 {  {
Line 1233 
Line 1208 
                 wanttrue = 1;                  wanttrue = 1;
   
         switch (v[*pos]) {          switch (v[*pos]) {
         case ('n'):          case 'n':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('o'):          case 'o':
                 (*pos)++;                  (*pos)++;
                 return(wanttrue);                  return(wanttrue);
         case ('c'):          case 'c':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('d'):          case 'd':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('e'):          case 'e':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('r'):          case 'r':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('t'):          case 't':
                 (*pos)++;                  (*pos)++;
                 return(!wanttrue);                  return(!wanttrue);
         default:          default:
Line 1259 
Line 1234 
                 return(roff_evalstrcond(v, pos) == wanttrue);                  return(roff_evalstrcond(v, pos) == wanttrue);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_line_ignore(ROFF_ARGS)  roff_line_ignore(ROFF_ARGS)
 {  {
Line 1267 
Line 1241 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cond(ROFF_ARGS)  roff_cond(ROFF_ARGS)
 {  {
   
         roffnode_push(r, tok, NULL, ln, ppos);          roffnode_push(r, tok, NULL, ln, ppos);
   
         /*          /*
          * An `.el' has no conditional body: it will consume the value           * An `.el' has no conditional body: it will consume the value
          * of the current rstack entry set in prior `ie' calls or           * of the current rstack entry set in prior `ie' calls or
          * defaults to DENY.           * defaults to DENY.
          *           *
          * If we're not an `el', however, then evaluate the conditional.           * If we're not an `el', however, then evaluate the conditional.
          */           */
   
         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(*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 1293 
Line 1266 
   
         if (ROFF_ie == tok) {          if (ROFF_ie == tok) {
                 if (r->rstackpos == RSTACK_MAX - 1) {                  if (r->rstackpos == RSTACK_MAX - 1) {
                         mandoc_msg(MANDOCERR_MEM,                          mandoc_msg(MANDOCERR_MEM,
                                 r->parse, ln, ppos, NULL);                              r->parse, ln, ppos, NULL);
                         return(ROFF_ERR);                          return(ROFF_ERR);
                 }                  }
                 r->rstack[++r->rstackpos] = !r->last->rule;                  r->rstack[++r->rstackpos] = !r->last->rule;
Line 1325 
Line 1298 
                 r->last->endspan = -1;                  r->last->endspan = -1;
                 pos += 2;                  pos += 2;
                 goto out;                  goto out;
         }          }
   
         /*          /*
          * Anything else following the conditional causes           * Anything else following the conditional causes
Line 1343 
Line 1316 
         return(ROFF_RERUN);          return(ROFF_RERUN);
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_ds(ROFF_ARGS)  roff_ds(ROFF_ARGS)
 {  {
Line 1386 
Line 1357 
         *res = v[*pos];          *res = v[*pos];
   
         switch (*res) {          switch (*res) {
         case ('+'):          case '+':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('-'):          case '-':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('*'):          case '*':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('/'):          case '/':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('%'):          case '%':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case ('&'):          case '&':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (':'):          case ':':
                 break;                  break;
         case '<':          case '<':
                 switch (v[*pos + 1]) {                  switch (v[*pos + 1]) {
                 case ('='):                  case '=':
                         *res = 'l';                          *res = 'l';
                         (*pos)++;                          (*pos)++;
                         break;                          break;
                 case ('>'):                  case '>':
                         *res = '!';                          *res = '!';
                         (*pos)++;                          (*pos)++;
                         break;                          break;
                 case ('?'):                  case '?':
                         *res = 'i';                          *res = 'i';
                         (*pos)++;                          (*pos)++;
                         break;                          break;
Line 1420 
Line 1391 
                 break;                  break;
         case '>':          case '>':
                 switch (v[*pos + 1]) {                  switch (v[*pos + 1]) {
                 case ('='):                  case '=':
                         *res = 'g';                          *res = 'g';
                         (*pos)++;                          (*pos)++;
                         break;                          break;
                 case ('?'):                  case '?':
                         *res = 'a';                          *res = 'a';
                         (*pos)++;                          (*pos)++;
                         break;                          break;
Line 1518 
Line 1489 
                         continue;                          continue;
   
                 switch (operator) {                  switch (operator) {
                 case ('+'):                  case '+':
                         *res += operand2;                          *res += operand2;
                         break;                          break;
                 case ('-'):                  case '-':
                         *res -= operand2;                          *res -= operand2;
                         break;                          break;
                 case ('*'):                  case '*':
                         *res *= operand2;                          *res *= operand2;
                         break;                          break;
                 case ('/'):                  case '/':
                         *res /= operand2;                          *res /= operand2;
                         break;                          break;
                 case ('%'):                  case '%':
                         *res %= operand2;                          *res %= operand2;
                         break;                          break;
                 case ('<'):                  case '<':
                         *res = *res < operand2;                          *res = *res < operand2;
                         break;                          break;
                 case ('>'):                  case '>':
                         *res = *res > operand2;                          *res = *res > operand2;
                         break;                          break;
                 case ('l'):                  case 'l':
                         *res = *res <= operand2;                          *res = *res <= operand2;
                         break;                          break;
                 case ('g'):                  case 'g':
                         *res = *res >= operand2;                          *res = *res >= operand2;
                         break;                          break;
                 case ('='):                  case '=':
                         *res = *res == operand2;                          *res = *res == operand2;
                         break;                          break;
                 case ('!'):                  case '!':
                         *res = *res != operand2;                          *res = *res != operand2;
                         break;                          break;
                 case ('&'):                  case '&':
                         *res = *res && operand2;                          *res = *res && operand2;
                         break;                          break;
                 case (':'):                  case ':':
                         *res = *res || operand2;                          *res = *res || operand2;
                         break;                          break;
                 case ('i'):                  case 'i':
                         if (operand2 < *res)                          if (operand2 < *res)
                                 *res = operand2;                                  *res = operand2;
                         break;                          break;
                 case ('a'):                  case 'a':
                         if (operand2 > *res)                          if (operand2 > *res)
                                 *res = operand2;                                  *res = operand2;
                         break;                          break;
Line 1612 
Line 1583 
 {  {
   
         switch (*name) {          switch (*name) {
         case ('A'):  /* ASCII approximation mode is always off. */          case 'A':  /* ASCII approximation mode is always off. */
                 return(0);                  return(0);
         case ('g'):  /* Groff compatibility mode is always on. */          case 'g':  /* Groff compatibility mode is always on. */
                 return(1);                  return(1);
         case ('H'):  /* Fixed horizontal resolution. */          case 'H':  /* Fixed horizontal resolution. */
                 return (24);                  return (24);
         case ('j'):  /* Always adjust left margin only. */          case 'j':  /* Always adjust left margin only. */
                 return(0);                  return(0);
         case ('T'):  /* Some output device is always defined. */          case 'T':  /* Some output device is always defined. */
                 return(1);                  return(1);
         case ('V'):  /* Fixed vertical resolution. */          case 'V':  /* Fixed vertical resolution. */
                 return (40);                  return (40);
         default:          default:
                 return (-1);                  return (-1);
Line 1727 
Line 1698 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_rm(ROFF_ARGS)  roff_rm(ROFF_ARGS)
 {  {
Line 1743 
Line 1713 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_it(ROFF_ARGS)  roff_it(ROFF_ARGS)
 {  {
Line 1757 
Line 1726 
         cp[len] = '\0';          cp[len] = '\0';
         if ((iv = mandoc_strntoi(cp, len, 10)) <= 0) {          if ((iv = mandoc_strntoi(cp, len, 10)) <= 0) {
                 mandoc_msg(MANDOCERR_NUMERIC, r->parse,                  mandoc_msg(MANDOCERR_NUMERIC, r->parse,
                                 ln, ppos, *bufp + 1);                      ln, ppos, *bufp + 1);
                 return(ROFF_IGN);                  return(ROFF_IGN);
         }          }
         cp += len + 1;          cp += len + 1;
Line 1768 
Line 1737 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_Dd(ROFF_ARGS)  roff_Dd(ROFF_ARGS)
 {  {
Line 1781 
Line 1749 
         return(ROFF_CONT);          return(ROFF_CONT);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_TH(ROFF_ARGS)  roff_TH(ROFF_ARGS)
 {  {
Line 1794 
Line 1761 
         return(ROFF_CONT);          return(ROFF_CONT);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_TE(ROFF_ARGS)  roff_TE(ROFF_ARGS)
 {  {
Line 1807 
Line 1773 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_T_(ROFF_ARGS)  roff_T_(ROFF_ARGS)
 {  {
Line 1830 
Line 1795 
 #endif  #endif
   
 static void  static void
 roff_openeqn(struct roff *r, const char *name, int line,  roff_openeqn(struct roff *r, const char *name, int line,
                 int offs, const char *buf)                  int offs, const char *buf)
 {  {
         struct eqn_node *e;          struct eqn_node *e;
Line 1852 
Line 1817 
         }          }
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_EQ(ROFF_ARGS)  roff_EQ(ROFF_ARGS)
 {  {
Line 1861 
Line 1825 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_EN(ROFF_ARGS)  roff_EN(ROFF_ARGS)
 {  {
Line 1870 
Line 1833 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_TS(ROFF_ARGS)  roff_TS(ROFF_ARGS)
 {  {
Line 1892 
Line 1854 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cc(ROFF_ARGS)  roff_cc(ROFF_ARGS)
 {  {
Line 1909 
Line 1870 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_tr(ROFF_ARGS)  roff_tr(ROFF_ARGS)
 {  {
Line 1931 
Line 1891 
                 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                                  mandoc_msg(MANDOCERR_BADESCAPE,
                                         (MANDOCERR_BADESCAPE, r->parse,                                      r->parse, ln,
                                          ln, (int)(p - *bufp), NULL);                                      (int)(p - *bufp), NULL);
                                 return(ROFF_IGN);                                  return(ROFF_IGN);
                         }                          }
                         fsz = (size_t)(p - first);                          fsz = (size_t)(p - first);
Line 1943 
Line 1903 
                 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                                  mandoc_msg(MANDOCERR_BADESCAPE,
                                         (MANDOCERR_BADESCAPE, r->parse,                                      r->parse, ln,
                                          ln, (int)(p - *bufp), NULL);                                      (int)(p - *bufp), NULL);
                                 return(ROFF_IGN);                                  return(ROFF_IGN);
                         }                          }
                         ssz = (size_t)(p - second);                          ssz = (size_t)(p - second);
                 } else if ('\0' == *second) {                  } else if ('\0' == *second) {
                         mandoc_msg(MANDOCERR_ARGCOUNT, r->parse,                          mandoc_msg(MANDOCERR_ARGCOUNT, r->parse,
                                         ln, (int)(p - *bufp), NULL);                              ln, (int)(p - *bufp), NULL);
                         second = " ";                          second = " ";
                         p--;                          p--;
                 }                  }
   
                 if (fsz > 1) {                  if (fsz > 1) {
                         roff_setstrn(&r->xmbtab, first,                          roff_setstrn(&r->xmbtab, first, fsz,
                                         fsz, second, ssz, 0);                              second, ssz, 0);
                         continue;                          continue;
                 }                  }
   
                 if (NULL == r->xtab)                  if (NULL == r->xtab)
                         r->xtab = mandoc_calloc                          r->xtab = mandoc_calloc(128,
                                 (128, sizeof(struct roffstr));                              sizeof(struct roffstr));
   
                 free(r->xtab[(int)*first].p);                  free(r->xtab[(int)*first].p);
                 r->xtab[(int)*first].p = mandoc_strndup(second, ssz);                  r->xtab[(int)*first].p = mandoc_strndup(second, ssz);
Line 1974 
Line 1934 
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_so(ROFF_ARGS)  roff_so(ROFF_ARGS)
 {  {
Line 1999 
Line 1958 
         return(ROFF_SO);          return(ROFF_SO);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_userdef(ROFF_ARGS)  roff_userdef(ROFF_ARGS)
 {  {
Line 2100 
Line 2058 
 {  {
   
         roff_setstrn(&r->strtab, name, strlen(name), string,          roff_setstrn(&r->strtab, name, strlen(name), string,
                         string ? strlen(string) : 0, append);              string ? strlen(string) : 0, append);
 }  }
   
 static void  static void
Line 2181 
Line 2139 
         int i;          int i;
   
         for (n = r->strtab; n; n = n->next)          for (n = r->strtab; n; n = n->next)
                 if (0 == strncmp(name, n->key.p, len) &&                  if (0 == strncmp(name, n->key.p, len) &&
                                 '\0' == n->key.p[(int)len])                      '\0' == n->key.p[(int)len])
                         return(n->val.p);                          return(n->val.p);
   
         for (i = 0; i < PREDEFS_MAX; i++)          for (i = 0; i < PREDEFS_MAX; i++)
Line 2209 
Line 2167 
 const struct tbl_span *  const struct tbl_span *
 roff_span(const struct roff *r)  roff_span(const struct roff *r)
 {  {
   
         return(r->tbl ? tbl_span(r->tbl) : NULL);          return(r->tbl ? tbl_span(r->tbl) : NULL);
 }  }
   
 const struct eqn *  const struct eqn *
 roff_eqn(const struct roff *r)  roff_eqn(const struct roff *r)
 {  {
   
         return(r->last_eqn ? &r->last_eqn->eqn : NULL);          return(r->last_eqn ? &r->last_eqn->eqn : NULL);
 }  }
   
Line 2275 
Line 2233 
                          * Append the match to the array and move                           * Append the match to the array and move
                          * forward by its keysize.                           * forward by its keysize.
                          */                           */
                         res = mandoc_realloc                          res = mandoc_realloc(res,
                                 (res, ssz + cp->val.sz + 1);                              ssz + cp->val.sz + 1);
                         memcpy(res + ssz, cp->val.p, cp->val.sz);                          memcpy(res + ssz, cp->val.p, cp->val.sz);
                         ssz += cp->val.sz;                          ssz += cp->val.sz;
                         p += (int)cp->key.sz;                          p += (int)cp->key.sz;
Line 2297 
Line 2255 
                         memcpy(res + ssz, pp, sz);                          memcpy(res + ssz, pp, sz);
                         break;                          break;
                 }                  }
                 /*                  /*
                  * We bail out on bad escapes.                   * We bail out on bad escapes.
                  * No need to warn: we already did so when                   * No need to warn: we already did so when
                  * roff_res() was called.                   * roff_res() was called.
                  */                   */
Line 2313 
Line 2271 
 }  }
   
 /*  /*
  * Find out whether a line is a macro line or not.   * Find out whether a line is a macro line or not.
  * If it is, adjust the current position and return one; if it isn't,   * If it is, adjust the current position and return one; if it isn't,
  * return zero and don't change the current position.   * return zero and don't change the current position.
  * If the control character has been set with `.cc', then let that grain   * If the control character has been set with `.cc', then let that grain

Legend:
Removed from v.1.79  
changed lines
  Added in v.1.80