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

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

version 1.206, 2014/04/08 01:37:27 version 1.207, 2014/04/20 16:46:05
Line 137  struct roffnode {
Line 137  struct roffnode {
   
 #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 193  static int   roff_getop(const char *, int *, char *);
Line 193  static int   roff_getop(const char *, int *, char *);
 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 202  static void   roff_openeqn(struct roff *, const char *
Line 202  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 *, 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 315  static const struct predef predefs[PREDEFS_MAX] = {
Line 315  static const struct predef predefs[PREDEFS_MAX] = {
 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 367  roffhash_find(const char *p, size_t s)
Line 368  roffhash_find(const char *p, size_t s)
         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 378  roffnode_pop(struct roff *r)
Line 378  roffnode_pop(struct roff *r)
         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 386  roffnode_pop(struct roff *r)
Line 386  roffnode_pop(struct roff *r)
         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 409  roffnode_push(struct roff *r, enum rofft tok, const ch
Line 408  roffnode_push(struct roff *r, enum rofft tok, const ch
         r->last = p;          r->last = p;
 }  }
   
   
 static void  static void
 roff_free1(struct roff *r)  roff_free1(struct roff *r)
 {  {
Line 459  roff_reset(struct roff *r)
Line 457  roff_reset(struct roff *r)
         r->control = 0;          r->control = 0;
 }  }
   
   
 void  void
 roff_free(struct roff *r)  roff_free(struct roff *r)
 {  {
Line 468  roff_free(struct roff *r)
Line 465  roff_free(struct roff *r)
         free(r);          free(r);
 }  }
   
   
 struct roff *  struct roff *
 roff_alloc(struct mparse *parse, int options)  roff_alloc(struct mparse *parse, int options)
 {  {
Line 478  roff_alloc(struct mparse *parse, int options)
Line 474  roff_alloc(struct mparse *parse, int options)
         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 533  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 529  roff_res(struct roff *r, char **bufp, size_t *szp, int
                 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 565  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 561  roff_res(struct roff *r, char **bufp, size_t *szp, int
   
                 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 591  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 587  roff_res(struct roff *r, char **bufp, size_t *szp, int
   
                 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 609  roff_res(struct roff *r, char **bufp, size_t *szp, int
Line 603  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);                          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 713  roff_parsetext(char **bufp, size_t *szp, int pos, int 
Line 706  roff_parsetext(char **bufp, size_t *szp, int pos, int 
 }  }
   
 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 744  roff_parseln(struct roff *r, int ln, char **bufp, 
Line 737  roff_parseln(struct roff *r, int ln, char **bufp, 
         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 767  roff_parseln(struct roff *r, int ln, char **bufp, 
Line 759  roff_parseln(struct roff *r, int ln, char **bufp, 
         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 782  roff_parseln(struct roff *r, int ln, char **bufp, 
Line 773  roff_parseln(struct roff *r, int ln, char **bufp, 
                 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 820  roff_parse(struct roff *r, const char *buf, int *pos)
Line 808  roff_parse(struct roff *r, const char *buf, int *pos)
         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 840  roff_parse(struct roff *r, const char *buf, int *pos)
Line 828  roff_parse(struct roff *r, const char *buf, int *pos)
         return(t);          return(t);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cblock(ROFF_ARGS)  roff_cblock(ROFF_ARGS)
 {  {
Line 856  roff_cblock(ROFF_ARGS)
Line 843  roff_cblock(ROFF_ARGS)
         }          }
   
         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 883  roff_cblock(ROFF_ARGS)
Line 870  roff_cblock(ROFF_ARGS)
   
 }  }
   
   
 static void  static void
 roffnode_cleanscope(struct roff *r)  roffnode_cleanscope(struct roff *r)
 {  {
Line 895  roffnode_cleanscope(struct roff *r)
Line 881  roffnode_cleanscope(struct roff *r)
         }          }
 }  }
   
   
 static void  static void
 roff_ccond(struct roff *r, int ln, int ppos)  roff_ccond(struct roff *r, int ln, int ppos)
 {  {
Line 906  roff_ccond(struct roff *r, int ln, int ppos)
Line 891  roff_ccond(struct roff *r, int ln, int ppos)
         }          }
   
         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 927  roff_ccond(struct roff *r, int ln, int ppos)
Line 912  roff_ccond(struct roff *r, int ln, int ppos)
         return;          return;
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_block(ROFF_ARGS)  roff_block(ROFF_ARGS)
 {  {
Line 1007  roff_block(ROFF_ARGS)
Line 990  roff_block(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_block_sub(ROFF_ARGS)  roff_block_sub(ROFF_ARGS)
 {  {
Line 1029  roff_block_sub(ROFF_ARGS)
Line 1010  roff_block_sub(ROFF_ARGS)
                         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 1064  roff_block_sub(ROFF_ARGS)
Line 1045  roff_block_sub(ROFF_ARGS)
         }          }
   
         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 1080  roff_block_text(ROFF_ARGS)
Line 1058  roff_block_text(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cond_sub(ROFF_ARGS)  roff_cond_sub(ROFF_ARGS)
 {  {
Line 1102  roff_cond_sub(ROFF_ARGS)
Line 1078  roff_cond_sub(ROFF_ARGS)
             (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 1126  roff_cond_sub(ROFF_ARGS)
Line 1102  roff_cond_sub(ROFF_ARGS)
         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 1237  roff_evalcond(const char *v, int *pos)
Line 1212  roff_evalcond(const char *v, int *pos)
                 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 1263  roff_evalcond(const char *v, int *pos)
Line 1238  roff_evalcond(const char *v, int *pos)
                 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 1271  roff_line_ignore(ROFF_ARGS)
Line 1245  roff_line_ignore(ROFF_ARGS)
         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 1297  roff_cond(ROFF_ARGS)
Line 1270  roff_cond(ROFF_ARGS)
   
         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 1329  roff_cond(ROFF_ARGS)
Line 1302  roff_cond(ROFF_ARGS)
                 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 1347  out:
Line 1320  out:
         return(ROFF_RERUN);          return(ROFF_RERUN);
 }  }
   
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_ds(ROFF_ARGS)  roff_ds(ROFF_ARGS)
 {  {
Line 1390  roff_getop(const char *v, int *pos, char *res)
Line 1361  roff_getop(const char *v, int *pos, char *res)
         *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 1424  roff_getop(const char *v, int *pos, char *res)
Line 1395  roff_getop(const char *v, int *pos, char *res)
                 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 1522  roff_evalnum(const char *v, int *pos, int *res, int sk
Line 1493  roff_evalnum(const char *v, int *pos, int *res, int sk
                         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 1616  roff_getregro(const char *name)
Line 1587  roff_getregro(const char *name)
 {  {
   
         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 1731  roff_rr(ROFF_ARGS)
Line 1702  roff_rr(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_rm(ROFF_ARGS)  roff_rm(ROFF_ARGS)
 {  {
Line 1747  roff_rm(ROFF_ARGS)
Line 1717  roff_rm(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_it(ROFF_ARGS)  roff_it(ROFF_ARGS)
 {  {
Line 1761  roff_it(ROFF_ARGS)
Line 1730  roff_it(ROFF_ARGS)
         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 1772  roff_it(ROFF_ARGS)
Line 1741  roff_it(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_Dd(ROFF_ARGS)  roff_Dd(ROFF_ARGS)
 {  {
Line 1785  roff_Dd(ROFF_ARGS)
Line 1753  roff_Dd(ROFF_ARGS)
         return(ROFF_CONT);          return(ROFF_CONT);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_TH(ROFF_ARGS)  roff_TH(ROFF_ARGS)
 {  {
Line 1798  roff_TH(ROFF_ARGS)
Line 1765  roff_TH(ROFF_ARGS)
         return(ROFF_CONT);          return(ROFF_CONT);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_TE(ROFF_ARGS)  roff_TE(ROFF_ARGS)
 {  {
Line 1811  roff_TE(ROFF_ARGS)
Line 1777  roff_TE(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_T_(ROFF_ARGS)  roff_T_(ROFF_ARGS)
 {  {
Line 1834  roff_closeeqn(struct roff *r)
Line 1799  roff_closeeqn(struct roff *r)
 #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 1856  roff_openeqn(struct roff *r, const char *name, int lin
Line 1821  roff_openeqn(struct roff *r, const char *name, int lin
         }          }
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_EQ(ROFF_ARGS)  roff_EQ(ROFF_ARGS)
 {  {
Line 1865  roff_EQ(ROFF_ARGS)
Line 1829  roff_EQ(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_EN(ROFF_ARGS)  roff_EN(ROFF_ARGS)
 {  {
Line 1874  roff_EN(ROFF_ARGS)
Line 1837  roff_EN(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_TS(ROFF_ARGS)  roff_TS(ROFF_ARGS)
 {  {
Line 1896  roff_TS(ROFF_ARGS)
Line 1858  roff_TS(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_cc(ROFF_ARGS)  roff_cc(ROFF_ARGS)
 {  {
Line 1913  roff_cc(ROFF_ARGS)
Line 1874  roff_cc(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_tr(ROFF_ARGS)  roff_tr(ROFF_ARGS)
 {  {
Line 1935  roff_tr(ROFF_ARGS)
Line 1895  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                                  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 1947  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                                  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 1978  roff_tr(ROFF_ARGS)
Line 1938  roff_tr(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_so(ROFF_ARGS)  roff_so(ROFF_ARGS)
 {  {
Line 2003  roff_so(ROFF_ARGS)
Line 1962  roff_so(ROFF_ARGS)
         return(ROFF_SO);          return(ROFF_SO);
 }  }
   
 /* ARGSUSED */  
 static enum rofferr  static enum rofferr
 roff_userdef(ROFF_ARGS)  roff_userdef(ROFF_ARGS)
 {  {
Line 2104  roff_setstr(struct roff *r, const char *name, const ch
Line 2062  roff_setstr(struct roff *r, const char *name, const ch
 {  {
   
         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 2185  roff_getstrn(const struct roff *r, const char *name, s
Line 2143  roff_getstrn(const struct roff *r, const char *name, s
         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 2213  roff_freestr(struct roffkv *r)
Line 2171  roff_freestr(struct roffkv *r)
 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 2279  roff_strdup(const struct roff *r, const char *p)
Line 2237  roff_strdup(const struct roff *r, const char *p)
                          * 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 2301  roff_strdup(const struct roff *r, const char *p)
Line 2259  roff_strdup(const struct roff *r, const char *p)
                         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 2317  roff_strdup(const struct roff *r, const char *p)
Line 2275  roff_strdup(const struct roff *r, const char *p)
 }  }
   
 /*  /*
  * 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.206  
changed lines
  Added in v.1.207

CVSweb