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

Diff for /mandoc/main.c between version 1.5 and 1.9

version 1.5, 2009/03/20 19:56:25 version 1.9, 2009/03/22 19:10:48
Line 86  static int    fdesc(struct buf *, struct buf *,
Line 86  static int    fdesc(struct buf *, struct buf *,
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
         int              c, rc, fflags, wflags;          int              c, rc, fflags;
         struct mdoc_cb   cb;          struct mdoc_cb   cb;
         struct mdoc     *mdoc;          struct mdoc     *mdoc;
         void            *outdata;          void            *outdata;
Line 96  main(int argc, char *argv[])
Line 96  main(int argc, char *argv[])
         out_free         outfree;          out_free         outfree;
         struct curparse  curp;          struct curparse  curp;
   
         fflags = wflags = 0;          fflags = 0;
         outtype = OUTT_ASCII;          outtype = OUTT_ASCII;
   
         bzero(&curp, sizeof(struct curparse));          bzero(&curp, sizeof(struct curparse));
Line 264  fdesc(struct buf *blk, struct buf *ln,
Line 264  fdesc(struct buf *blk, struct buf *ln,
         ssize_t          ssz;          ssize_t          ssz;
         struct stat      st;          struct stat      st;
         int              j, i, pos, lnn;          int              j, i, pos, lnn;
   #ifdef  STRIP_XO
           int              macro, xo, xeoln;
   #endif
   
         /*          /*
          * Two buffers: ln and buf.  buf is the input buffer, optimised           * Two buffers: ln and buf.  buf is the input buffer, optimised
Line 271  fdesc(struct buf *blk, struct buf *ln,
Line 274  fdesc(struct buf *blk, struct buf *ln,
          * growable, hence passed in by ptr-ptr.           * growable, hence passed in by ptr-ptr.
          */           */
   
         if (-1 == fstat(fd, &st)) {          sz = BUFSIZ;
   
           if (-1 == fstat(fd, &st))
                 warnx("%s", f);                  warnx("%s", f);
                 sz = BUFSIZ;          else if ((size_t)st.st_blksize > sz)
         } else                  sz = st.st_blksize;
                 sz = (unsigned)BUFSIZ > st.st_blksize ?  
                         (size_t)BUFSIZ : st.st_blksize;  
   
         if (sz > blk->sz) {          if (sz > blk->sz) {
                 blk->buf = realloc(blk->buf, sz);                  blk->buf = realloc(blk->buf, sz);
Line 288  fdesc(struct buf *blk, struct buf *ln,
Line 291  fdesc(struct buf *blk, struct buf *ln,
         /*          /*
          * Fill buf with file blocksize and parse newlines into ln.           * Fill buf with file blocksize and parse newlines into ln.
          */           */
   #ifdef  STRIP_XO
           macro = xo = xeoln = 0;
   #endif
   
         for (lnn = 1, pos = 0; ; ) {          for (lnn = 1, pos = 0; ; ) {
                 if (-1 == (ssz = read(fd, blk->buf, sz))) {                  if (-1 == (ssz = read(fd, blk->buf, sz))) {
Line 305  fdesc(struct buf *blk, struct buf *ln,
Line 311  fdesc(struct buf *blk, struct buf *ln,
                         }                          }
   
                         if ('\n' != blk->buf[i]) {                          if ('\n' != blk->buf[i]) {
                                   /*
                                    * Ugly of uglies.  Here we handle the
                                    * dreaded `Xo/Xc' scoping.  Cover the
                                    * eyes of any nearby children.  This
                                    * makes `Xo/Xc' enclosures look like
                                    * one huge line.
                                    */
   #ifdef  STRIP_XO
                                   /*
                                    * First, note whether we're in a macro
                                    * line.
                                    */
                                   if (0 == pos && '.' == blk->buf[i])
                                           macro = 1;
   
                                   /*
                                    * If we're in an `Xo' context and just
                                    * nixed a newline, remove the control
                                    * character for new macro lines:
                                    * they're going to show up as all part
                                    * of the same line.
                                    */
                                   if (xo && xeoln && '.' == blk->buf[i]) {
                                           xeoln = 0;
                                           continue;
                                   }
                                   xeoln = 0;
   
                                   /*
                                    * If we've parsed `Xo', enter an xo
                                    * context.  `Xo' must be in a parsable
                                    * state.  This is the ugly part.  IT IS
                                    * NOT SMART ENOUGH TO HANDLE ESCAPED
                                    * WHITESPACE.
                                    */
                                   if (macro && pos && 'o' == blk->buf[i]) {
                                           if (xo && 'X' == ln->buf[pos - 1])  {
                                                   if (' ' == ln->buf[pos - 2])
                                                           xo++;
                                           } else if ('X' == ln->buf[pos - 1]) {
                                                   if (2 == pos && '.' == ln->buf[pos - 2])
                                                           xo++;
                                                   else if (' ' == ln->buf[pos - 2])
                                                           xo++;
                                           }
                                   }
   
                                   /*
                                    * If we're parsed `Xc', leave an xo
                                    * context if one's already pending.
                                    * `Xc' must be in a parsable state.
                                    * THIS IS NOT SMART ENOUGH TO HANDLE
                                    * ESCAPED WHITESPACE.
                                    */
                                   if (macro && pos && 'c' == blk->buf[i])
                                           if (xo && 'X' == ln->buf[pos - 1])
                                                   if (' ' == ln->buf[pos - 2])
                                                           xo--;
   #endif  /* STRIP_XO */
   
                                 ln->buf[pos++] = blk->buf[i];                                  ln->buf[pos++] = blk->buf[i];
                                 continue;                                  continue;
                         }                          }
Line 322  fdesc(struct buf *blk, struct buf *ln,
Line 388  fdesc(struct buf *blk, struct buf *ln,
                                         continue;                                          continue;
                                 }                                  }
                         }                          }
   
   #ifdef  STRIP_XO
                           /*
                            * If we're in an xo context, put a space in
                            * place of the newline and continue parsing.
                            * Mark that we just did a newline.
                            */
                           if (xo) {
                                   xeoln = 1;
                                   ln->buf[pos++] = ' ';
                                   lnn++;
                                   continue;
                           }
                           macro = 0;
   #endif  /* STRIP_XO */
   
                         ln->buf[pos] = 0;                          ln->buf[pos] = 0;
                         if ( ! mdoc_parseln(mdoc, lnn, ln->buf))                          if ( ! mdoc_parseln(mdoc, lnn, ln->buf))

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.9

CVSweb