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

Diff for /mandoc/roff.c between version 1.267 and 1.273

version 1.267, 2015/04/19 14:25:41 version 1.273, 2015/08/29 20:26:04
Line 335  struct roff {
Line 335  struct roff {
         int              rstacksz; /* current size limit of rstack */          int              rstacksz; /* current size limit of rstack */
         int              rstackpos; /* position in rstack */          int              rstackpos; /* position in rstack */
         int              format; /* current file in mdoc or man format */          int              format; /* current file in mdoc or man format */
           int              argc; /* number of args of the last macro */
         char             control; /* control character */          char             control; /* control character */
 };  };
   
Line 397  static enum rofferr  roff_cond_text(ROFF_ARGS);
Line 398  static enum rofferr  roff_cond_text(ROFF_ARGS);
 static  enum rofferr     roff_cond_sub(ROFF_ARGS);  static  enum rofferr     roff_cond_sub(ROFF_ARGS);
 static  enum rofferr     roff_ds(ROFF_ARGS);  static  enum rofferr     roff_ds(ROFF_ARGS);
 static  enum rofferr     roff_eqndelim(struct roff *, struct buf *, int);  static  enum rofferr     roff_eqndelim(struct roff *, struct buf *, int);
 static  int              roff_evalcond(struct roff *r, int,  static  int              roff_evalcond(struct roff *r, int, char *, int *);
                                 const char *, int *);  
 static  int              roff_evalnum(struct roff *, int,  static  int              roff_evalnum(struct roff *, int,
                                 const char *, int *, int *, int);                                  const char *, int *, int *, int);
 static  int              roff_evalpar(struct roff *, int,  static  int              roff_evalpar(struct roff *, int,
Line 412  static int   roff_getnum(const char *, int *, int *, i
Line 412  static int   roff_getnum(const char *, int *, int *, i
 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 *,
                                 const char *, size_t);                                  const char *, size_t);
 static  int              roff_getregro(const char *name);  static  int              roff_getregro(const struct roff *,
                                   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  int              roff_hasregn(const struct roff *,
                                   const char *, size_t);
 static  enum rofferr     roff_insec(ROFF_ARGS);  static  enum rofferr     roff_insec(ROFF_ARGS);
 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 1022  roff_node_append(struct roff_man *man, struct roff_nod
Line 1025  roff_node_append(struct roff_man *man, struct roff_nod
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
         n->parent->nchild++;          n->parent->nchild++;
           n->parent->last = n;
   
         /*          /*
          * Copy over the normalised-data pointer of our parent.  Not           * Copy over the normalised-data pointer of our parent.  Not
Line 1096  roff_word_append(struct roff_man *man, const char *wor
Line 1100  roff_word_append(struct roff_man *man, const char *wor
         man->next = ROFF_NEXT_SIBLING;          man->next = ROFF_NEXT_SIBLING;
 }  }
   
   void
   roff_elem_alloc(struct roff_man *man, int line, int pos, int tok)
   {
           struct roff_node        *n;
   
           n = roff_node_alloc(man, line, pos, ROFFT_ELEM, tok);
           roff_node_append(man, n);
           man->next = ROFF_NEXT_CHILD;
   }
   
 struct roff_node *  struct roff_node *
   roff_block_alloc(struct roff_man *man, int line, int pos, int tok)
   {
           struct roff_node        *n;
   
           n = roff_node_alloc(man, line, pos, ROFFT_BLOCK, tok);
           roff_node_append(man, n);
           man->next = ROFF_NEXT_CHILD;
           return(n);
   }
   
   struct roff_node *
 roff_head_alloc(struct roff_man *man, int line, int pos, int tok)  roff_head_alloc(struct roff_man *man, int line, int pos, int tok)
 {  {
         struct roff_node        *n;          struct roff_node        *n;
Line 1209  roff_node_delete(struct roff_man *man, struct roff_nod
Line 1234  roff_node_delete(struct roff_man *man, struct roff_nod
         roff_node_free(n);          roff_node_free(n);
 }  }
   
   void
   deroff(char **dest, const struct roff_node *n)
   {
           char    *cp;
           size_t   sz;
   
           if (n->type != ROFFT_TEXT) {
                   for (n = n->child; n != NULL; n = n->next)
                           deroff(dest, n);
                   return;
           }
   
           /* Skip leading whitespace and escape sequences. */
   
           cp = n->string;
           while (*cp != '\0') {
                   if ('\\' == *cp) {
                           cp++;
                           mandoc_escape((const char **)&cp, NULL, NULL);
                   } else if (isspace((unsigned char)*cp))
                           cp++;
                   else
                           break;
           }
   
           /* Skip trailing whitespace. */
   
           for (sz = strlen(cp); sz; sz--)
                   if ( ! isspace((unsigned char)cp[sz-1]))
                           break;
   
           /* Skip empty strings. */
   
           if (sz == 0)
                   return;
   
           if (*dest == NULL) {
                   *dest = mandoc_strndup(cp, sz);
                   return;
           }
   
           mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
           free(*dest);
           *dest = cp;
   }
   
 /* --- main functions of the roff parser ---------------------------------- */  /* --- main functions of the roff parser ---------------------------------- */
   
 /*  /*
Line 2066  out:
Line 2137  out:
  * or string condition.   * or string condition.
  */   */
 static int  static int
 roff_evalcond(struct roff *r, int ln, const char *v, int *pos)  roff_evalcond(struct roff *r, int ln, char *v, int *pos)
 {  {
           char    *cp, *name;
           size_t   sz;
         int      number, savepos, wanttrue;          int      number, savepos, wanttrue;
   
         if ('!' == v[*pos]) {          if ('!' == v[*pos]) {
Line 2090  roff_evalcond(struct roff *r, int ln, const char *v, i
Line 2163  roff_evalcond(struct roff *r, int ln, const char *v, i
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case 'e':          case 'e':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case 'r':  
                 /* FALLTHROUGH */  
         case 't':          case 't':
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case 'v':          case 'v':
                 (*pos)++;                  (*pos)++;
                 return(!wanttrue);                  return(!wanttrue);
           case 'r':
                   cp = name = v + ++*pos;
                   sz = roff_getname(r, &cp, ln, *pos);
                   *pos = cp - v;
                   return((sz && roff_hasregn(r, name, sz)) == wanttrue);
         default:          default:
                 break;                  break;
         }          }
Line 2191  roff_cond(ROFF_ARGS)
Line 2267  roff_cond(ROFF_ARGS)
         if (buf->buf[pos] == '\\' && buf->buf[pos + 1] == '{') {          if (buf->buf[pos] == '\\' && buf->buf[pos + 1] == '{') {
                 r->last->endspan = -1;                  r->last->endspan = -1;
                 pos += 2;                  pos += 2;
                   while (buf->buf[pos] == ' ')
                           pos++;
                 goto out;                  goto out;
         }          }
   
Line 2499  roff_setreg(struct roff *r, const char *name, int val,
Line 2577  roff_setreg(struct roff *r, const char *name, int val,
  * were to turn up, another special value would have to be chosen.   * were to turn up, another special value would have to be chosen.
  */   */
 static int  static int
 roff_getregro(const char *name)  roff_getregro(const struct roff *r, const char *name)
 {  {
   
         switch (*name) {          switch (*name) {
           case '$':  /* Number of arguments of the last macro evaluated. */
                   return(r->argc);
         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. */
Line 2527  roff_getreg(const struct roff *r, const char *name)
Line 2607  roff_getreg(const struct roff *r, const char *name)
         int              val;          int              val;
   
         if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) {          if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) {
                 val = roff_getregro(name + 1);                  val = roff_getregro(r, name + 1);
                 if (-1 != val)                  if (-1 != val)
                         return (val);                          return (val);
         }          }
Line 2546  roff_getregn(const struct roff *r, const char *name, s
Line 2626  roff_getregn(const struct roff *r, const char *name, s
         int              val;          int              val;
   
         if ('.' == name[0] && 2 == len) {          if ('.' == name[0] && 2 == len) {
                 val = roff_getregro(name + 1);                  val = roff_getregro(r, name + 1);
                 if (-1 != val)                  if (-1 != val)
                         return (val);                          return (val);
         }          }
Line 2559  roff_getregn(const struct roff *r, const char *name, s
Line 2639  roff_getregn(const struct roff *r, const char *name, s
         return(0);          return(0);
 }  }
   
   static int
   roff_hasregn(const struct roff *r, const char *name, size_t len)
   {
           struct roffreg  *reg;
           int              val;
   
           if ('.' == name[0] && 2 == len) {
                   val = roff_getregro(r, name + 1);
                   if (-1 != val)
                           return(1);
           }
   
           for (reg = r->regtab; reg; reg = reg->next)
                   if (len == reg->key.sz &&
                       0 == strncmp(name, reg->key.p, len))
                           return(1);
   
           return(0);
   }
   
 static void  static void
 roff_freereg(struct roffreg *reg)  roff_freereg(struct roffreg *reg)
 {  {
Line 2988  roff_userdef(ROFF_ARGS)
Line 3088  roff_userdef(ROFF_ARGS)
          * and NUL-terminate them.           * and NUL-terminate them.
          */           */
   
           r->argc = 0;
         cp = buf->buf + pos;          cp = buf->buf + pos;
         for (i = 0; i < 9; i++)          for (i = 0; i < 9; i++) {
                 arg[i] = *cp == '\0' ? "" :                  if (*cp == '\0')
                     mandoc_getarg(r->parse, &cp, ln, &pos);                          arg[i] = "";
                   else {
                           arg[i] = mandoc_getarg(r->parse, &cp, ln, &pos);
                           r->argc = i + 1;
                   }
           }
   
         /*          /*
          * Expand macro arguments.           * Expand macro arguments.

Legend:
Removed from v.1.267  
changed lines
  Added in v.1.273

CVSweb