]> git.cameronkatri.com Git - mandoc.git/blobdiff - tbl_layout.c
Break schwarze@'s release notes into sections. Ok schwarze@.
[mandoc.git] / tbl_layout.c
index b3e814670371428370426c25fb16b565e4f48d69..7601f146cad60fd627cc7fcb69d4cbf2e070d590 100644 (file)
@@ -1,6 +1,6 @@
-/*     $Id: tbl_layout.c,v 1.15 2011/01/10 15:31:00 kristaps Exp $ */
+/*     $Id: tbl_layout.c,v 1.22 2011/09/18 14:14:15 schwarze Exp $ */
 /*
- * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <assert.h>
 #include <ctype.h>
 #include <stdlib.h>
@@ -68,6 +72,23 @@ mods(struct tbl_node *tbl, struct tbl_cell *cp,
        char             buf[5];
        int              i;
 
+       /* Not all types accept modifiers. */
+
+       switch (cp->pos) {
+       case (TBL_CELL_DOWN):
+               /* FALLTHROUGH */
+       case (TBL_CELL_HORIZ):
+               /* FALLTHROUGH */
+       case (TBL_CELL_DHORIZ):
+               /* FALLTHROUGH */
+       case (TBL_CELL_VERT):
+               /* FALLTHROUGH */
+       case (TBL_CELL_DVERT):
+               return(1);
+       default:
+               break;
+       }
+
 mod:
        /* 
         * XXX: since, at least for now, modifiers are non-conflicting
@@ -100,7 +121,8 @@ mod:
                        (*pos)++;
                        goto mod;
                }
-               TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos);
+               mandoc_msg(MANDOCERR_TBLLAYOUT, 
+                               tbl->parse, ln, *pos, NULL);
                return(0);
        }
 
@@ -117,7 +139,8 @@ mod:
                /* No greater than 4 digits. */
 
                if (4 == i) {
-                       TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos);
+                       mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse,
+                                       ln, *pos, NULL);
                        return(0);
                }
 
@@ -150,28 +173,40 @@ mod:
                goto mod;
        case ('f'):
                break;
+       case ('r'):
+               /* FALLTHROUGH */
        case ('b'):
                /* FALLTHROUGH */
        case ('i'):
                (*pos)--;
                break;
        default:
-               TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos - 1);
+               mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse,
+                               ln, *pos - 1, NULL);
                return(0);
        }
 
        switch (tolower((unsigned char)p[(*pos)++])) {
+       case ('3'):
+               /* FALLTHROUGH */
        case ('b'):
                cp->flags |= TBL_CELL_BOLD;
                goto mod;
+       case ('2'):
+               /* FALLTHROUGH */
        case ('i'):
                cp->flags |= TBL_CELL_ITALIC;
                goto mod;
+       case ('1'):
+               /* FALLTHROUGH */
+       case ('r'):
+               goto mod;
        default:
                break;
        }
 
-       TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos - 1);
+       mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse,
+                       ln, *pos - 1, NULL);
        return(0);
 }
 
@@ -189,7 +224,8 @@ cell(struct tbl_node *tbl, struct tbl_row *rp,
                        break;
 
        if (KEYS_MAX == i) {
-               TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos);
+               mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse, 
+                               ln, *pos, NULL);
                return(0);
        }
 
@@ -205,7 +241,8 @@ cell(struct tbl_node *tbl, struct tbl_row *rp,
 
        if (TBL_CELL_SPAN == c) {
                if (NULL == rp->first) {
-                       TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos);
+                       mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse,
+                                       ln, *pos, NULL);
                        return(0);
                } else if (rp->last)
                        switch (rp->last->pos) {
@@ -213,13 +250,24 @@ cell(struct tbl_node *tbl, struct tbl_row *rp,
                        case (TBL_CELL_DVERT):
                        case (TBL_CELL_HORIZ):
                        case (TBL_CELL_DHORIZ):
-                               TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos);
+                               mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse,
+                                               ln, *pos, NULL);
                                return(0);
                        default:
                                break;
                        }
        }
 
+       /*
+        * If a vertical spanner is found, we may not be in the first
+        * row.
+        */
+
+       if (TBL_CELL_DOWN == c && rp == tbl->first_row) {
+               mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse, ln, *pos, NULL);
+               return(0);
+       }
+
        (*pos)++;
 
        /* Extra check for the double-vertical. */
@@ -234,7 +282,7 @@ cell(struct tbl_node *tbl, struct tbl_row *rp,
        if (rp->last && (TBL_CELL_VERT == c || TBL_CELL_DVERT == c) &&
                        (TBL_CELL_VERT == rp->last->pos || 
                         TBL_CELL_DVERT == rp->last->pos)) {
-               TBL_MSG(tbl, MANDOCERR_TBLLAYOUT, ln, *pos - 1);
+               mandoc_msg(MANDOCERR_TBLLAYOUT, tbl->parse, ln, *pos - 1, NULL);
                return(0);
        }
 
@@ -275,7 +323,8 @@ cell:
        if ('.' == p[*pos]) {
                tbl->part = TBL_PART_DATA;
                if (NULL == tbl->first_row) 
-                       TBL_MSG(tbl, MANDOCERR_TBLNOLAYOUT, ln, *pos);
+                       mandoc_msg(MANDOCERR_TBLNOLAYOUT, tbl->parse, 
+                                       ln, *pos, NULL);
                (*pos)++;
                return;
        }
@@ -405,19 +454,19 @@ cell_alloc(struct tbl_node *tbl, struct tbl_row *rp, enum tbl_cellt pos)
 }
 
 static void
-head_adjust(const struct tbl_cell *cell, struct tbl_head *head)
+head_adjust(const struct tbl_cell *cellp, struct tbl_head *head)
 {
-       if (TBL_CELL_VERT != cell->pos &&
-                       TBL_CELL_DVERT != cell->pos) {
+       if (TBL_CELL_VERT != cellp->pos &&
+                       TBL_CELL_DVERT != cellp->pos) {
                head->pos = TBL_HEAD_DATA;
                return;
        }
 
-       if (TBL_CELL_VERT == cell->pos)
+       if (TBL_CELL_VERT == cellp->pos)
                if (TBL_HEAD_DVERT != head->pos)
                        head->pos = TBL_HEAD_VERT;
 
-       if (TBL_CELL_DVERT == cell->pos)
+       if (TBL_CELL_DVERT == cellp->pos)
                head->pos = TBL_HEAD_DVERT;
 }