aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-06-11 10:34:31 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-06-11 10:34:31 +0000
commit7f83f64018902ad39b94705868df283386db95fa (patch)
tree5058a9231aafa949372278a09f5c82e1f4535922
parent4e8530b25c1ddc46a8d4709c6f548e140bd0b27b (diff)
downloadmandoc-7f83f64018902ad39b94705868df283386db95fa.tar.gz
mandoc-7f83f64018902ad39b94705868df283386db95fa.tar.zst
mandoc-7f83f64018902ad39b94705868df283386db95fa.zip
Clean up validation of field widths.
Pushed field-width warn/error into warn/error routine. Removed superfluous space at output eoln. Fixed overzealous line break in lists.
-rw-r--r--mdoc_validate.c85
-rw-r--r--term.c11
2 files changed, 61 insertions, 35 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 9d822632..1da8a28d 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.7 2009/06/10 20:18:43 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.8 2009/06/11 10:34:31 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -50,7 +50,10 @@ enum merr {
enum mwarn {
WPRINT,
+ WNOWIDTH,
+ WMISSWIDTH,
WESCAPE,
+ WDEPCOL,
WWRONGMSEC,
WSECOOO,
WSECREP,
@@ -460,6 +463,16 @@ pwarn(struct mdoc *m, int line, int pos, enum mwarn type)
p = "prologue macros out-of-order";
c = WARN_COMPAT;
break;
+ case (WDEPCOL):
+ p = "deprecated column argument syntax";
+ c = WARN_COMPAT;
+ break;
+ case (WNOWIDTH):
+ p = "superfluous width argument";
+ break;
+ case (WMISSWIDTH):
+ p = "missing width argument";
+ break;
case (WPRINT):
p = "invalid character";
break;
@@ -776,7 +789,7 @@ pre_display(PRE_ARGS)
static int
pre_bl(PRE_ARGS)
{
- int i, type, width, offset;
+ int pos, type, width, offset;
if (MDOC_BLOCK != n->type)
return(1);
@@ -788,8 +801,8 @@ pre_bl(PRE_ARGS)
type = offset = width = -1;
/* LINTED */
- for (i = 0; i < (int)n->args->argc; i++)
- switch (n->args->argv[i].arg) {
+ for (pos = 0; pos < (int)n->args->argc; pos++)
+ switch (n->args->argv[pos].arg) {
case (MDOC_Bullet):
/* FALLTHROUGH */
case (MDOC_Dash):
@@ -811,23 +824,20 @@ pre_bl(PRE_ARGS)
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Column):
- if (-1 == type) {
- type = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EMULTILIST));
+ if (-1 != type)
+ return(nerr(mdoc, n, EMULTILIST));
+ type = n->args->argv[pos].arg;
+ break;
case (MDOC_Width):
- if (-1 == width) {
- width = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EARGREP));
+ if (-1 != width)
+ return(nerr(mdoc, n, EARGREP));
+ width = n->args->argv[pos].arg;
+ break;
case (MDOC_Offset):
- if (-1 == offset) {
- offset = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EARGREP));
+ if (-1 != offset)
+ return(nerr(mdoc, n, EARGREP));
+ offset = n->args->argv[pos].arg;
+ break;
default:
break;
}
@@ -835,7 +845,17 @@ pre_bl(PRE_ARGS)
if (-1 == type)
return(nerr(mdoc, n, ELISTTYPE));
+ /*
+ * Validate the width field. Some list types don't need width
+ * types and should be warned about them. Others should have it
+ * and must also be warned.
+ */
+
switch (type) {
+ case (MDOC_Tag):
+ if (-1 == width && ! nwarn(mdoc, n, WMISSWIDTH))
+ return(0);
+ break;
case (MDOC_Column):
/* FALLTHROUGH */
case (MDOC_Diag):
@@ -843,17 +863,24 @@ pre_bl(PRE_ARGS)
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Item):
- if (-1 == width)
- break;
- return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
- "superfluous %s argument",
- mdoc_argnames[MDOC_Width]));
- case (MDOC_Tag):
- if (-1 != width)
+ if (-1 != width && ! nwarn(mdoc, n, WNOWIDTH))
+ return(0);
+ break;
+ default:
+ break;
+ }
+
+ /*
+ * General validation of fields.
+ */
+
+ switch (type) {
+ case (MDOC_Column):
+ if (0 == n->args->argv[pos].sz)
break;
- return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
- "suggest %s argument",
- mdoc_argnames[MDOC_Width]));
+ if ( ! nwarn(mdoc, n, WDEPCOL))
+ return(0);
+ break;
default:
break;
}
diff --git a/term.c b/term.c
index 814d90f8..3dabeffa 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.77 2009/06/11 07:46:41 kristaps Exp $ */
+/* $Id: term.c,v 1.78 2009/06/11 10:34:32 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -272,10 +272,9 @@ term_flushln(struct termp *p)
vis = p->rmargin - p->offset;
}
- /*
- * Write out the word and a trailing space. Omit the
- * space if we're the last word in the line or beyond
- * our breakpoint.
+ /*
+ * Prepend a space if we're not already at the beginning
+ * of the line, then the word.
*/
if (0 < vis++)
@@ -294,7 +293,7 @@ term_flushln(struct termp *p)
* cause a newline and offset at the right margin.
*/
- if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) {
+ if ((TERMP_NOBREAK & p->flags) && vis > maxvis) {
if ( ! (TERMP_NONOBREAK & p->flags)) {
putchar('\n');
for (i = 0; i < (int)p->rmargin; i++)