]> git.cameronkatri.com Git - mandoc.git/blobdiff - main.c
Make -T[x]html for tables structure cells with a width. I don't
[mandoc.git] / main.c
diff --git a/main.c b/main.c
index 5468bbc7260723932e70cb2809482ecc32cc3604..2be68a9350b9a64dfbb761eb75061221ed1f3da3 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
-/*     $Id: main.c,v 1.121 2010/12/06 16:55:35 kristaps Exp $ */
+/*     $Id: main.c,v 1.135 2011/01/04 15:02:00 kristaps Exp $ */
 /*
- * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -41,6 +41,7 @@
 #define        MAP_FILE        0
 #endif
 
+#define        REPARSE_LIMIT   1000
 #define        UNCONST(a)      ((void *)(uintptr_t)(const void *)(a))
 
 /* FIXME: Intel's compiler?  LLVM?  pcc?  */
@@ -89,6 +90,7 @@ struct        curparse {
        struct mdoc      *mdoc;         /* mdoc parser */
        struct roff      *roff;         /* roff parser (!NULL) */
        struct regset     regs;         /* roff registers */
+       int               reparse_count; /* finite interpolation stack */
        enum outt         outtype;      /* which output to use */
        out_mdoc          outmdoc;      /* mdoc output ptr */
        out_man           outman;       /* man output ptr */
@@ -151,6 +153,7 @@ static      const char * const      mandocerrs[MANDOCERR_MAX] = {
 
        /* related to missing macro arguments */
        "skipping empty macro",
+       "argument count wrong",
        "missing display type",
        "list type must come first",
        "tag lists require a width argument",
@@ -174,9 +177,22 @@ static     const char * const      mandocerrs[MANDOCERR_MAX] = {
        "bad comment style",
        "unknown escape sequence",
        "unterminated quoted string",
+       
+       /* related to tables */
+       "extra data cells",
 
        "generic error",
 
+       /* related to tables */
+       "bad table syntax",
+       "bad table option",
+       "bad table layout",
+       "no table layout cells specified",
+       "no table data cells specified",
+       "ignore data in cell",
+       "data block still open",
+
+       "input stack limit exceeded, infinite loop?",
        "skipping bad character",
        "skipping text before the first section header",
        "skipping unknown macro",
@@ -386,7 +402,7 @@ static void
 resize_buf(struct buf *buf, size_t initial)
 {
 
-       buf->sz = buf->sz ? 2 * buf->sz : initial;
+       buf->sz = buf->sz > initial/2 ? 2 * buf->sz : initial;
        buf->buf = realloc(buf->buf, buf->sz);
        if (NULL == buf->buf) {
                perror(NULL);
@@ -519,10 +535,7 @@ fdesc(struct curparse *curp)
        }
 
        assert(curp->roff);
-       if ( ! roff_endparse(curp->roff)) {
-               assert(MANDOCLEVEL_FATAL <= file_status);
-               goto cleanup;
-       }
+       roff_endparse(curp->roff);
 
        /*
         * With -Wstop and warnings or errors of at least
@@ -665,8 +678,10 @@ parsebuf(struct curparse *curp, struct buf blk, int start)
                if (0 == pos && '\0' == blk.buf[i])
                        break;
 
-               if (start)
+               if (start) {
                        curp->line = lnn;
+                       curp->reparse_count = 0;
+               }
 
                while (i < (int)blk.sz && (start || '\0' != blk.buf[i])) {
                        if ('\n' == blk.buf[i]) {
@@ -765,7 +780,11 @@ rerun:
 
                switch (rr) {
                case (ROFF_REPARSE):
-                       parsebuf(curp, ln, 0);
+                       if (REPARSE_LIMIT >= ++curp->reparse_count)
+                               parsebuf(curp, ln, 0);
+                       else
+                               mmsg(MANDOCERR_ROFFLOOP, curp, 
+                                   curp->line, pos, NULL);
                        pos = 0;
                        continue;
                case (ROFF_APPEND):
@@ -785,10 +804,18 @@ rerun:
                                continue;
                        } else
                                break;
-               case (ROFF_CONT):
+               default:
                        break;
                }
 
+               /*
+                * If we encounter errors in the recursive parsebuf()
+                * call, make sure we don't continue parsing.
+                */
+
+               if (MANDOCLEVEL_FATAL <= file_status)
+                       break;
+
                /*
                 * If input parsers have not been allocated, do so now.
                 * We keep these instanced betwen parsers, but set them
@@ -803,9 +830,20 @@ rerun:
                 * Lastly, push down into the parsers themselves.  One
                 * of these will have already been set in the pset()
                 * routine.
+                * If libroff returns ROFF_TBL, then add it to the
+                * currently open parse.  Since we only get here if
+                * there does exist data (see tbl_data.c), we're
+                * guaranteed that something's been allocated.
                 */
 
-               if (curp->man || curp->mdoc) {
+               if (ROFF_TBL == rr) {
+                       assert(curp->man || curp->mdoc);
+                       if (curp->man)
+                               man_addspan(curp->man, roff_span(curp->roff));
+                       else
+                               mdoc_addspan(curp->mdoc, roff_span(curp->roff));
+
+               } else if (curp->man || curp->mdoc) {
                        rc = curp->man ?
                                man_parseln(curp->man, 
                                        curp->line, ln.buf, of) :