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

Diff for /mandoc/roff.c between version 1.302 and 1.303

version 1.302, 2017/05/08 20:33:53 version 1.303, 2017/06/04 00:13:15
Line 99  struct roff {
Line 99  struct roff {
         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 */          int              argc; /* number of args of the last macro */
         char             control; /* control character */          char             control; /* control character */
           char             escape; /* escape character */
 };  };
   
 struct  roffnode {  struct  roffnode {
Line 155  static enum rofferr  roff_cond(ROFF_ARGS);
Line 156  static enum rofferr  roff_cond(ROFF_ARGS);
 static  enum rofferr     roff_cond_text(ROFF_ARGS);  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_ec(ROFF_ARGS);
   static  enum rofferr     roff_eo(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, char *, int *);  static  int              roff_evalcond(struct roff *r, int, char *, int *);
 static  int              roff_evalnum(struct roff *, int,  static  int              roff_evalnum(struct roff *, int,
Line 385  static struct roffmac  roffs[TOKEN_NONE] = {
Line 388  static struct roffmac  roffs[TOKEN_NONE] = {
         { roff_ds, NULL, NULL, 0 },  /* ds1 */          { roff_ds, NULL, NULL, 0 },  /* ds1 */
         { roff_unsupp, NULL, NULL, 0 },  /* dwh */          { roff_unsupp, NULL, NULL, 0 },  /* dwh */
         { roff_unsupp, NULL, NULL, 0 },  /* dt */          { roff_unsupp, NULL, NULL, 0 },  /* dt */
         { roff_unsupp, NULL, NULL, 0 },  /* ec */          { roff_ec, NULL, NULL, 0 },  /* ec */
         { roff_unsupp, NULL, NULL, 0 },  /* ecr */          { roff_unsupp, NULL, NULL, 0 },  /* ecr */
         { roff_unsupp, NULL, NULL, 0 },  /* ecs */          { roff_unsupp, NULL, NULL, 0 },  /* ecs */
         { roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT },  /* el */          { roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT },  /* el */
         { roff_unsupp, NULL, NULL, 0 },  /* em */          { roff_unsupp, NULL, NULL, 0 },  /* em */
         { roff_EN, NULL, NULL, 0 },  /* EN */          { roff_EN, NULL, NULL, 0 },  /* EN */
         { roff_unsupp, NULL, NULL, 0 },  /* eo */          { roff_eo, NULL, NULL, 0 },  /* eo */
         { roff_unsupp, NULL, NULL, 0 },  /* EP */          { roff_unsupp, NULL, NULL, 0 },  /* EP */
         { roff_EQ, NULL, NULL, 0 },  /* EQ */          { roff_EQ, NULL, NULL, 0 },  /* EQ */
         { roff_line_ignore, NULL, NULL, 0 },  /* errprint */          { roff_line_ignore, NULL, NULL, 0 },  /* errprint */
Line 751  roff_reset(struct roff *r)
Line 754  roff_reset(struct roff *r)
 {  {
         roff_free1(r);          roff_free1(r);
         r->format = r->options & (MPARSE_MDOC | MPARSE_MAN);          r->format = r->options & (MPARSE_MDOC | MPARSE_MAN);
         r->control = 0;          r->control = '\0';
           r->escape = '\\';
 }  }
   
 void  void
Line 773  roff_alloc(struct mparse *parse, int options)
Line 777  roff_alloc(struct mparse *parse, int options)
         r->options = options;          r->options = options;
         r->format = options & (MPARSE_MDOC | MPARSE_MAN);          r->format = options & (MPARSE_MDOC | MPARSE_MAN);
         r->rstackpos = -1;          r->rstackpos = -1;
           r->escape = '\\';
         return r;          return r;
 }  }
   
Line 1149  roff_res(struct roff *r, struct buf *buf, int ln, int 
Line 1154  roff_res(struct roff *r, struct buf *buf, int ln, int 
         int              expand_count;  /* to avoid infinite loops */          int              expand_count;  /* to avoid infinite loops */
         int              npos;  /* position in numeric expression */          int              npos;  /* position in numeric expression */
         int              arg_complete; /* argument not interrupted by eol */          int              arg_complete; /* argument not interrupted by eol */
           int              done;  /* no more input available */
         char             term;  /* character terminating the escape */          char             term;  /* character terminating the escape */
   
         expand_count = 0;          /* Search forward for comments. */
   
           done = 0;
         start = buf->buf + pos;          start = buf->buf + pos;
         stesc = strchr(start, '\0') - 1;          for (stesc = buf->buf + pos; *stesc != '\0'; stesc++) {
         while (stesc-- > start) {                  if (stesc[0] != r->escape || stesc[1] == '\0')
                           continue;
                   stesc++;
                   if (*stesc != '"' && *stesc != '#')
                           continue;
                   cp = strchr(stesc--, '\0') - 1;
                   if (*cp == '\n') {
                           done = 1;
                           cp--;
                   }
                   if (*cp == ' ' || *cp == '\t')
                           mandoc_msg(MANDOCERR_SPACE_EOL, r->parse,
                               ln, cp - buf->buf, NULL);
                   while (stesc > start && stesc[-1] == ' ')
                           stesc--;
                   *stesc = '\0';
                   break;
           }
           if (stesc == start)
                   return ROFF_CONT;
           stesc--;
   
           /* Notice the end of the input. */
   
           if (*stesc == '\n') {
                   *stesc-- = '\0';
                   done = 1;
           }
   
           expand_count = 0;
           while (stesc >= start) {
   
                 /* Search backwards for the next backslash. */                  /* Search backwards for the next backslash. */
   
                 if (*stesc != '\\')                  if (*stesc != r->escape) {
                           if (*stesc == '\\') {
                                   *stesc = '\0';
                                   buf->sz = mandoc_asprintf(&nbuf, "%s\\e%s",
                                       buf->buf, stesc + 1) + 1;
                                   start = nbuf + pos;
                                   stesc = nbuf + (stesc - buf->buf);
                                   free(buf->buf);
                                   buf->buf = nbuf;
                           }
                           stesc--;
                         continue;                          continue;
                   }
   
                 /* If it is escaped, skip it. */                  /* If it is escaped, skip it. */
   
                 for (cp = stesc - 1; cp >= start; cp--)                  for (cp = stesc - 1; cp >= start; cp--)
                         if (*cp != '\\')                          if (*cp != r->escape)
                                 break;                                  break;
   
                 if ((stesc - cp) % 2 == 0) {                  if ((stesc - cp) % 2 == 0) {
                         stesc = (char *)cp;                          while (stesc > cp)
                                   *stesc-- = '\\';
                         continue;                          continue;
                   } else if (stesc[1] != '\0') {
                           *stesc = '\\';
                   } else {
                           *stesc-- = '\0';
                           if (done)
                                   continue;
                           else
                                   return ROFF_APPEND;
                 }                  }
   
                 /* Decide whether to expand or to check only. */                  /* Decide whether to expand or to check only. */
Line 1195  roff_res(struct roff *r, struct buf *buf, int ln, int 
Line 1253  roff_res(struct roff *r, struct buf *buf, int ln, int 
                                 mandoc_vmsg(MANDOCERR_ESC_BAD,                                  mandoc_vmsg(MANDOCERR_ESC_BAD,
                                     r->parse, ln, (int)(stesc - buf->buf),                                      r->parse, ln, (int)(stesc - buf->buf),
                                     "%.*s", (int)(cp - stesc), stesc);                                      "%.*s", (int)(cp - stesc), stesc);
                           stesc--;
                         continue;                          continue;
                 }                  }
   
Line 1409  roff_parseln(struct roff *r, int ln, struct buf *buf, 
Line 1468  roff_parseln(struct roff *r, int ln, struct buf *buf, 
         /* Expand some escape sequences. */          /* Expand some escape sequences. */
   
         e = roff_res(r, buf, ln, pos);          e = roff_res(r, buf, ln, pos);
         if (e == ROFF_IGN)          if (e == ROFF_IGN || e == ROFF_APPEND)
                 return e;                  return e;
         assert(e == ROFF_CONT);          assert(e == ROFF_CONT);
   
Line 2849  roff_cc(ROFF_ARGS)
Line 2908  roff_cc(ROFF_ARGS)
         p = buf->buf + pos;          p = buf->buf + pos;
   
         if (*p == '\0' || (r->control = *p++) == '.')          if (*p == '\0' || (r->control = *p++) == '.')
                 r->control = 0;                  r->control = '\0';
   
         if (*p != '\0')          if (*p != '\0')
                 mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,                  mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
Line 2859  roff_cc(ROFF_ARGS)
Line 2918  roff_cc(ROFF_ARGS)
 }  }
   
 static enum rofferr  static enum rofferr
   roff_ec(ROFF_ARGS)
   {
           const char      *p;
   
           p = buf->buf + pos;
           if (*p == '\0')
                   r->escape = '\\';
           else {
                   r->escape = *p;
                   if (*++p != '\0')
                           mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
                               ln, p - buf->buf, "ec ... %s", p);
           }
           return ROFF_IGN;
   }
   
   static enum rofferr
   roff_eo(ROFF_ARGS)
   {
           r->escape = '\0';
           if (buf->buf[pos] != '\0')
                   mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse,
                       ln, pos, "eo %s", buf->buf + pos);
           return ROFF_IGN;
   }
   
   static enum rofferr
 roff_tr(ROFF_ARGS)  roff_tr(ROFF_ARGS)
 {  {
         const char      *p, *first, *second;          const char      *p, *first, *second;
Line 3385  roff_getcontrol(const struct roff *r, const char *cp, 
Line 3471  roff_getcontrol(const struct roff *r, const char *cp, 
   
         pos = *ppos;          pos = *ppos;
   
         if (0 != r->control && cp[pos] == r->control)          if (r->control != '\0' && cp[pos] == r->control)
                 pos++;                  pos++;
         else if (0 != r->control)          else if (r->control != '\0')
                 return 0;                  return 0;
         else if ('\\' == cp[pos] && '.' == cp[pos + 1])          else if ('\\' == cp[pos] && '.' == cp[pos + 1])
                 pos += 2;                  pos += 2;

Legend:
Removed from v.1.302  
changed lines
  Added in v.1.303

CVSweb