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

Diff for /mandoc/read.c between version 1.46 and 1.47

version 1.46, 2014/03/23 11:25:26 version 1.47, 2014/04/20 16:46:05
Line 46 
Line 46 
 #define REPARSE_LIMIT   1000  #define REPARSE_LIMIT   1000
   
 struct  buf {  struct  buf {
         char             *buf; /* binary input buffer */          char             *buf; /* binary input buffer */
         size_t            sz; /* size of binary buffer */          size_t            sz; /* size of binary buffer */
 };  };
   
Line 63  struct mparse {
Line 63  struct mparse {
         char             *sodest; /* filename pointed to by .so */          char             *sodest; /* filename pointed to by .so */
         int               reparse_count; /* finite interp. stack */          int               reparse_count; /* finite interp. stack */
         mandocmsg         mmsg; /* warning/error message handler */          mandocmsg         mmsg; /* warning/error message handler */
         const char       *file;          const char       *file;
         struct buf       *secondary;          struct buf       *secondary;
         char             *defos; /* default operating system */          char             *defos; /* default operating system */
 };  };
Line 153  static const char * const mandocerrs[MANDOCERR_MAX] = 
Line 153  static const char * const mandocerrs[MANDOCERR_MAX] = 
   
         /* related to equations */          /* related to equations */
         "unexpected literal in equation",          "unexpected literal in equation",
   
         "generic error",          "generic error",
   
         /* related to equations */          /* related to equations */
Line 224  static const char * const mandoclevels[MANDOCLEVEL_MAX
Line 224  static const char * const mandoclevels[MANDOCLEVEL_MAX
         "SYSERR"          "SYSERR"
 };  };
   
   
 static void  static void
 resize_buf(struct buf *buf, size_t initial)  resize_buf(struct buf *buf, size_t initial)
 {  {
Line 257  pset(const char *buf, int pos, struct mparse *curp)
Line 258  pset(const char *buf, int pos, struct mparse *curp)
         }          }
   
         if (MPARSE_MDOC & curp->options) {          if (MPARSE_MDOC & curp->options) {
                 if (NULL == curp->pmdoc)                  if (NULL == curp->pmdoc)
                         curp->pmdoc = mdoc_alloc(                          curp->pmdoc = mdoc_alloc(
                             curp->roff, curp, curp->defos,                              curp->roff, curp, curp->defos,
                             MPARSE_QUICK & curp->options ? 1 : 0);                              MPARSE_QUICK & curp->options ? 1 : 0);
Line 265  pset(const char *buf, int pos, struct mparse *curp)
Line 266  pset(const char *buf, int pos, struct mparse *curp)
                 curp->mdoc = curp->pmdoc;                  curp->mdoc = curp->pmdoc;
                 return;                  return;
         } else if (MPARSE_MAN & curp->options) {          } else if (MPARSE_MAN & curp->options) {
                 if (NULL == curp->pman)                  if (NULL == curp->pman)
                         curp->pman = man_alloc(curp->roff, curp,                          curp->pman = man_alloc(curp->roff, curp,
                             MPARSE_QUICK & curp->options ? 1 : 0);                              MPARSE_QUICK & curp->options ? 1 : 0);
                 assert(curp->pman);                  assert(curp->pman);
Line 274  pset(const char *buf, int pos, struct mparse *curp)
Line 275  pset(const char *buf, int pos, struct mparse *curp)
         }          }
   
         if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3))  {          if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3))  {
                 if (NULL == curp->pmdoc)                  if (NULL == curp->pmdoc)
                         curp->pmdoc = mdoc_alloc(                          curp->pmdoc = mdoc_alloc(
                             curp->roff, curp, curp->defos,                              curp->roff, curp, curp->defos,
                             MPARSE_QUICK & curp->options ? 1 : 0);                              MPARSE_QUICK & curp->options ? 1 : 0);
                 assert(curp->pmdoc);                  assert(curp->pmdoc);
                 curp->mdoc = curp->pmdoc;                  curp->mdoc = curp->pmdoc;
                 return;                  return;
         }          }
   
         if (NULL == curp->pman)          if (NULL == curp->pman)
                 curp->pman = man_alloc(curp->roff, curp,                  curp->pman = man_alloc(curp->roff, curp,
                     MPARSE_QUICK & curp->options ? 1 : 0);                      MPARSE_QUICK & curp->options ? 1 : 0);
         assert(curp->pman);          assert(curp->pman);
Line 308  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 309  mparse_buf_r(struct mparse *curp, struct buf blk, int 
   
         memset(&ln, 0, sizeof(struct buf));          memset(&ln, 0, sizeof(struct buf));
   
         lnn = curp->line;          lnn = curp->line;
         pos = 0;          pos = 0;
   
         for (i = 0; i < (int)blk.sz; ) {          for (i = 0; i < (int)blk.sz; ) {
                 if (0 == pos && '\0' == blk.buf[i])                  if (0 == pos && '\0' == blk.buf[i])
Line 346  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 347  mparse_buf_r(struct mparse *curp, struct buf blk, int 
                         if (pos + 2 >= (int)ln.sz)                          if (pos + 2 >= (int)ln.sz)
                                 resize_buf(&ln, 256);                                  resize_buf(&ln, 256);
   
                         /*                          /*
                          * Warn about bogus characters.  If you're using                           * Warn about bogus characters.  If you're using
                          * non-ASCII encoding, you're screwing your                           * non-ASCII encoding, you're screwing your
                          * readers.  Since I'd rather this not happen,                           * readers.  Since I'd rather this not happen,
Line 357  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 358  mparse_buf_r(struct mparse *curp, struct buf blk, int 
   
                         c = (unsigned char) blk.buf[i];                          c = (unsigned char) blk.buf[i];
   
                         if ( ! (isascii(c) &&                          if ( ! (isascii(c) &&
                                         (isgraph(c) || isblank(c)))) {                              (isgraph(c) || isblank(c)))) {
                                 mandoc_msg(MANDOCERR_BADCHAR, curp,                                  mandoc_msg(MANDOCERR_BADCHAR, curp,
                                                 curp->line, pos, NULL);                                      curp->line, pos, NULL);
                                 i++;                                  i++;
                                 ln.buf[pos++] = '?';                                  ln.buf[pos++] = '?';
                                 continue;                                  continue;
Line 414  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 415  mparse_buf_r(struct mparse *curp, struct buf blk, int 
   
                         c = (unsigned char) blk.buf[i+1];                          c = (unsigned char) blk.buf[i+1];
   
                         if ( ! (isascii(c) &&                          if ( ! (isascii(c) &&
                                         (isgraph(c) || isblank(c)))) {                              (isgraph(c) || isblank(c)))) {
                                 mandoc_msg(MANDOCERR_BADCHAR, curp,                                  mandoc_msg(MANDOCERR_BADCHAR, curp,
                                                 curp->line, pos, NULL);                                      curp->line, pos, NULL);
                                 i += 2;                                  i += 2;
                                 ln.buf[pos++] = '?';                                  ln.buf[pos++] = '?';
                                 continue;                                  continue;
Line 429  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 430  mparse_buf_r(struct mparse *curp, struct buf blk, int 
                         ln.buf[pos++] = blk.buf[i++];                          ln.buf[pos++] = blk.buf[i++];
                 }                  }
   
                 if (pos >= (int)ln.sz)                  if (pos >= (int)ln.sz)
                         resize_buf(&ln, 256);                          resize_buf(&ln, 256);
   
                 ln.buf[pos] = '\0';                  ln.buf[pos] = '\0';
Line 452  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 453  mparse_buf_r(struct mparse *curp, struct buf blk, int 
                  */                   */
   
                 if (curp->secondary) {                  if (curp->secondary) {
                         curp->secondary->buf =                          curp->secondary->buf = mandoc_realloc(
                                 mandoc_realloc                              curp->secondary->buf,
                                 (curp->secondary->buf,                              curp->secondary->sz + pos + 2);
                                  curp->secondary->sz + pos + 2);                          memcpy(curp->secondary->buf +
                         memcpy(curp->secondary->buf +                              curp->secondary->sz,
                                         curp->secondary->sz,                              ln.buf, pos);
                                         ln.buf, pos);  
                         curp->secondary->sz += pos;                          curp->secondary->sz += pos;
                         curp->secondary->buf                          curp->secondary->buf
                                 [curp->secondary->sz] = '\n';                                  [curp->secondary->sz] = '\n';
Line 467  mparse_buf_r(struct mparse *curp, struct buf blk, int 
Line 467  mparse_buf_r(struct mparse *curp, struct buf blk, int 
                                 [curp->secondary->sz] = '\0';                                  [curp->secondary->sz] = '\0';
                 }                  }
 rerun:  rerun:
                 rr = roff_parseln                  rr = roff_parseln(curp->roff, curp->line,
                         (curp->roff, curp->line,                      &ln.buf, &ln.sz, of, &of);
                          &ln.buf, &ln.sz, of, &of);  
   
                 switch (rr) {                  switch (rr) {
                 case (ROFF_REPARSE):                  case ROFF_REPARSE:
                         if (REPARSE_LIMIT >= ++curp->reparse_count)                          if (REPARSE_LIMIT >= ++curp->reparse_count)
                                 mparse_buf_r(curp, ln, 0);                                  mparse_buf_r(curp, ln, 0);
                         else                          else
                                 mandoc_msg(MANDOCERR_ROFFLOOP, curp,                                  mandoc_msg(MANDOCERR_ROFFLOOP, curp,
                                         curp->line, pos, NULL);                                      curp->line, pos, NULL);
                         pos = 0;                          pos = 0;
                         continue;                          continue;
                 case (ROFF_APPEND):                  case ROFF_APPEND:
                         pos = (int)strlen(ln.buf);                          pos = (int)strlen(ln.buf);
                         continue;                          continue;
                 case (ROFF_RERUN):                  case ROFF_RERUN:
                         goto rerun;                          goto rerun;
                 case (ROFF_IGN):                  case ROFF_IGN:
                         pos = 0;                          pos = 0;
                         continue;                          continue;
                 case (ROFF_ERR):                  case ROFF_ERR:
                         assert(MANDOCLEVEL_FATAL <= curp->file_status);                          assert(MANDOCLEVEL_FATAL <= curp->file_status);
                         break;                          break;
                 case (ROFF_SO):                  case ROFF_SO:
                         if (0 == (MPARSE_SO & curp->options) &&                          if (0 == (MPARSE_SO & curp->options) &&
                             (i >= (int)blk.sz || '\0' == blk.buf[i])) {                              (i >= (int)blk.sz || '\0' == blk.buf[i])) {
                                 curp->sodest = mandoc_strdup(ln.buf + of);                                  curp->sodest = mandoc_strdup(ln.buf + of);
Line 503  rerun:
Line 502  rerun:
                          * buffer because we're going to descend into                           * buffer because we're going to descend into
                          * the file recursively.                           * the file recursively.
                          */                           */
                         if (curp->secondary)                          if (curp->secondary)
                                 curp->secondary->sz -= pos + 1;                                  curp->secondary->sz -= pos + 1;
                         mparse_readfd(curp, -1, ln.buf + of);                          mparse_readfd(curp, -1, ln.buf + of);
                         if (MANDOCLEVEL_FATAL <= curp->file_status)                          if (MANDOCLEVEL_FATAL <= curp->file_status)
Line 532  rerun:
Line 531  rerun:
                 if ( ! (curp->man || curp->mdoc))                  if ( ! (curp->man || curp->mdoc))
                         pset(ln.buf + of, pos - of, curp);                          pset(ln.buf + of, pos - of, curp);
   
                 /*                  /*
                  * Lastly, push down into the parsers themselves.  One                   * Lastly, push down into the parsers themselves.  One
                  * of these will have already been set in the pset()                   * of these will have already been set in the pset()
                  * routine.                   * routine.
Line 548  rerun:
Line 547  rerun:
                 if (ROFF_TBL == rr)                  if (ROFF_TBL == rr)
                         while (NULL != (span = roff_span(curp->roff))) {                          while (NULL != (span = roff_span(curp->roff))) {
                                 rc = curp->man ?                                  rc = curp->man ?
                                         man_addspan(curp->man, span) :                                      man_addspan(curp->man, span) :
                                         mdoc_addspan(curp->mdoc, span);                                      mdoc_addspan(curp->mdoc, span);
                                 if (0 == rc)                                  if (0 == rc)
                                         break;                                          break;
                         }                          }
                 else if (ROFF_EQN == rr)                  else if (ROFF_EQN == rr)
                         rc = curp->mdoc ?                          rc = curp->mdoc ?
                                 mdoc_addeqn(curp->mdoc,                              mdoc_addeqn(curp->mdoc,
                                         roff_eqn(curp->roff)) :                                  roff_eqn(curp->roff)) :
                                 man_addeqn(curp->man,                              man_addeqn(curp->man,
                                         roff_eqn(curp->roff));                                  roff_eqn(curp->roff));
                 else if (curp->man || curp->mdoc)                  else if (curp->man || curp->mdoc)
                         rc = curp->man ?                          rc = curp->man ?
                                 man_parseln(curp->man,                              man_parseln(curp->man,
                                         curp->line, ln.buf, of) :                                  curp->line, ln.buf, of) :
                                 mdoc_parseln(curp->mdoc,                              mdoc_parseln(curp->mdoc,
                                         curp->line, ln.buf, of);                                  curp->line, ln.buf, of);
   
                 if (0 == rc) {                  if (0 == rc) {
                         assert(MANDOCLEVEL_FATAL <= curp->file_status);                          assert(MANDOCLEVEL_FATAL <= curp->file_status);
Line 860  mandoc_vmsg(enum mandocerr t, struct mparse *m,
Line 859  mandoc_vmsg(enum mandocerr t, struct mparse *m,
 }  }
   
 void  void
 mandoc_msg(enum mandocerr er, struct mparse *m,  mandoc_msg(enum mandocerr er, struct mparse *m,
                 int ln, int col, const char *msg)                  int ln, int col, const char *msg)
 {  {
         enum mandoclevel level;          enum mandoclevel level;

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.47

CVSweb