summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-03-05 13:12:12 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-03-05 13:12:12 +0000
commitc1fd7f502ac50e13a6185e829bdbd03b7d0a931c (patch)
treefd39f0c38c00a28528f560159ac5f5d2f9542128
parent6936c4e5a0bd4bddcfd7c9d08d801aba0415dbad (diff)
downloadmandoc-c1fd7f502ac50e13a6185e829bdbd03b7d0a931c.tar.gz
Cleaned up ctype functions (netbsd).
Fixed .Ex/.Rv -std usage. Made Ar provide default value.
-rw-r--r--Makefile5
-rw-r--r--action.c36
-rw-r--r--argv.c40
-rw-r--r--mdoc.c5
-rw-r--r--mdocterm.c10
-rw-r--r--strings.c12
-rw-r--r--term.c6
-rw-r--r--validate.c48
8 files changed, 118 insertions, 44 deletions
diff --git a/Makefile b/Makefile
index 84d51e65..ffdb6103 100644
--- a/Makefile
+++ b/Makefile
@@ -102,7 +102,8 @@ FAIL = regress/test.empty \
regress/test.escape.11 \
regress/test.escape.12 \
regress/test.escape.14 \
- regress/test.argv.01
+ regress/test.argv.01 \
+ regress/test.argv.02
SUCCEED = regress/test.prologue.05 \
regress/test.prologue.07 \
@@ -162,7 +163,7 @@ installwww: www
install -m 0444 mdocml-nport-$(VERSION).tar.gz $(PREFIX)/ports-netbsd/
install -m 0444 mdocml-nport-$(VERSION).tar.gz $(PREFIX)/ports-netbsd/mdocml.tar.gz
-regress: mdoclint
+regress: mdoclint $(FAIL) $(SUCCEED)
@for f in $(FAIL); do \
echo "./mdoclint $$f" ; \
./mdoclint $$f 2>/dev/null || continue ; exit 1 ; done
diff --git a/action.c b/action.c
index 06b93509..87f641b0 100644
--- a/action.c
+++ b/action.c
@@ -36,15 +36,16 @@ struct actions {
/* Per-macro action routines. */
+static int post_ar(struct mdoc *);
static int post_bl(struct mdoc *);
static int post_bl_width(struct mdoc *);
static int post_bl_tagwidth(struct mdoc *);
static int post_dd(struct mdoc *);
static int post_dt(struct mdoc *);
-static int post_ex(struct mdoc *);
static int post_nm(struct mdoc *);
static int post_os(struct mdoc *);
static int post_sh(struct mdoc *);
+static int post_ex(struct mdoc *);
static int post_prologue(struct mdoc *);
@@ -67,7 +68,7 @@ const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL }, /* It */
{ NULL }, /* Ad */
{ NULL }, /* An */
- { NULL }, /* Ar */
+ { post_ar }, /* Ar */
{ NULL }, /* Cd */
{ NULL }, /* Cm */
{ NULL }, /* Dv */
@@ -171,14 +172,10 @@ post_ex(struct mdoc *mdoc)
if (0 == mdoc->last->data.elem.argc)
return(1);
-
- assert(1 == mdoc->last->data.elem.argc);
- if (1 == mdoc->last->data.elem.argv[0].sz)
+ if (mdoc->last->data.elem.argv[0].sz)
return(1);
- assert(0 == mdoc->last->data.elem.argv[0].sz);
- if (NULL == mdoc->meta.name)
- return(mdoc_err(mdoc, "default name not yet set"));
+ assert(mdoc->meta.name);
mdoc_msg(mdoc, "writing %s argument: %s",
mdoc_argnames[MDOC_Std], mdoc->meta.name);
@@ -484,6 +481,29 @@ post_bl(struct mdoc *mdoc)
static int
+post_ar(struct mdoc *mdoc)
+{
+ struct mdoc_node *n;
+
+ if (mdoc->last->child)
+ return(1);
+
+ n = mdoc->last;
+
+ mdoc->next = MDOC_NEXT_CHILD;
+ mdoc_word_alloc(mdoc, mdoc->last->line,
+ mdoc->last->pos, "file");
+ mdoc->next = MDOC_NEXT_SIBLING;
+ mdoc_word_alloc(mdoc, mdoc->last->line,
+ mdoc->last->pos, "...");
+
+ mdoc->last = n;
+ mdoc->next = MDOC_NEXT_SIBLING;
+ return(1);
+}
+
+
+static int
post_dd(struct mdoc *mdoc)
{
char buf[64];
diff --git a/argv.c b/argv.c
index 34081a13..b313d943 100644
--- a/argv.c
+++ b/argv.c
@@ -43,7 +43,7 @@
static int argv_a2arg(int, const char *);
static int args(struct mdoc *, int, int *,
char *, int, char **);
-static int argv(struct mdoc *, int,
+static int argv(struct mdoc *, int, int,
struct mdoc_arg *, int *, char *);
static int argv_single(struct mdoc *, int,
struct mdoc_arg *, int *, char *);
@@ -90,7 +90,7 @@ static int mdoc_argvflags[MDOC_ARG_MAX] = {
ARGV_MULTI, /* MDOC_Column */
ARGV_SINGLE, /* MDOC_Width */
ARGV_NONE, /* MDOC_Compact */
- ARGV_OPT_SINGLE, /* MDOC_Std */
+ ARGV_SINGLE, /* MDOC_Std */
ARGV_NONE, /* MDOC_p1003_1_88 */
ARGV_NONE, /* MDOC_p1003_1_90 */
ARGV_NONE, /* MDOC_p1003_1_96 */
@@ -389,10 +389,10 @@ args(struct mdoc *mdoc, int line,
break;
i++;
/* There must be at least one space... */
- if (0 == buf[i] || ! isspace((int)buf[i]))
+ if (0 == buf[i] || ! isspace((u_char)buf[i]))
break;
i++;
- while (buf[i] && isspace((int)buf[i]))
+ while (buf[i] && isspace((u_char)buf[i]))
i++;
}
if (0 == buf[i]) {
@@ -500,7 +500,7 @@ args(struct mdoc *mdoc, int line,
if ( ! (ARGS_TABSEP & fl))
while (buf[*pos]) {
- if (isspace((int)buf[*pos]))
+ if (isspace((u_char)buf[*pos]))
if ('\\' != buf[*pos - 1])
break;
(*pos)++;
@@ -515,7 +515,7 @@ args(struct mdoc *mdoc, int line,
return(ARGS_WORD);
if ( ! (ARGS_TABSEP & fl))
- while (buf[*pos] && isspace((int)buf[*pos]))
+ while (buf[*pos] && isspace((u_char)buf[*pos]))
(*pos)++;
if (buf[*pos])
@@ -547,7 +547,7 @@ args(struct mdoc *mdoc, int line,
if (0 == buf[*pos])
return(ARGS_QWORD);
- while (buf[*pos] && isspace((int)buf[*pos]))
+ while (buf[*pos] && isspace((u_char)buf[*pos]))
(*pos)++;
if (buf[*pos])
@@ -823,14 +823,28 @@ argv_single(struct mdoc *mdoc, int line,
* multiple parameters.
*/
static int
-argv(struct mdoc *mdoc, int line,
+argv(struct mdoc *mdoc, int tok, int line,
struct mdoc_arg *v, int *pos, char *buf)
{
+ int fl;
v->sz = 0;
v->value = NULL;
+ fl = mdoc_argvflags[v->arg];
- switch (mdoc_argvflags[v->arg]) {
+ /*
+ * Override the default per-argument value.
+ */
+
+ switch (tok) {
+ case (MDOC_Ex):
+ fl = ARGV_OPT_SINGLE;
+ break;
+ default:
+ break;
+ }
+
+ switch (fl) {
case (ARGV_SINGLE):
return(argv_single(mdoc, line, v, pos, buf));
case (ARGV_MULTI):
@@ -863,7 +877,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
if (0 == buf[*pos])
return(ARGV_EOLN);
- assert( ! isspace((int)buf[*pos]));
+ assert( ! isspace((u_char)buf[*pos]));
if ('-' != buf[*pos])
return(ARGV_WORD);
@@ -878,7 +892,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
/* LINTED */
while (buf[*pos]) {
- if (isspace((int)buf[*pos]))
+ if (isspace((u_char)buf[*pos]))
if ('\\' != buf[*pos - 1])
break;
(*pos)++;
@@ -899,12 +913,12 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
return(ARGV_WORD);
}
- while (buf[*pos] && isspace((int)buf[*pos]))
+ while (buf[*pos] && isspace((u_char)buf[*pos]))
(*pos)++;
/* FIXME: whitespace if no value. */
- if ( ! argv(mdoc, line, v, pos, buf))
+ if ( ! argv(mdoc, tok, line, v, pos, buf))
return(ARGV_ERROR);
return(ARGV_ARG);
diff --git a/mdoc.c b/mdoc.c
index 7110cdee..a1b7b74e 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -220,7 +220,8 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
return(1);
i = 1;
- while (buf[i] && ! isspace((int)buf[i]) && i < (int)sizeof(tmp))
+ while (buf[i] && ! isspace((u_char)buf[i]) &&
+ i < (int)sizeof(tmp))
i++;
if (i == (int)sizeof(tmp)) {
@@ -241,7 +242,7 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
return(mdoc_perr(mdoc, line, 1, "unknown macro"));
}
- while (buf[i] && isspace((int)buf[i]))
+ while (buf[i] && isspace((u_char)buf[i]))
i++;
if ( ! mdoc_macro(mdoc, c, line, 1, &i, buf)) {
diff --git a/mdocterm.c b/mdocterm.c
index 37f0bd39..660d0661 100644
--- a/mdocterm.c
+++ b/mdocterm.c
@@ -287,7 +287,7 @@ flushln(struct termp *p)
/* LINTED */
for (j = i, vsz = 0; j < p->col; j++) {
- if (isspace((int)p->buf[j]))
+ if (isspace((u_char)p->buf[j]))
break;
else if (27 == p->buf[j]) {
assert(j + 4 <= p->col);
@@ -334,7 +334,7 @@ flushln(struct termp *p)
*/
for ( ; i < p->col; i++) {
- if (isspace((int)p->buf[i]))
+ if (isspace((u_char)p->buf[i]))
break;
putchar(p->buf[i]);
}
@@ -437,13 +437,13 @@ word(struct termp *p, const char *word)
/* LINTED */
for (j = i = 0; i < len; i++) {
- if ( ! isspace((int)word[i])) {
+ if ( ! isspace((u_char)word[i])) {
j++;
continue;
}
/* Escaped spaces don't delimit... */
- if (i > 0 && isspace((int)word[i]) &&
+ if (i > 0 && isspace((u_char)word[i]) &&
'\\' == word[i - 1]) {
j++;
continue;
@@ -649,7 +649,7 @@ header(struct termp *p, const struct mdoc_meta *meta)
meta->title, pp ? pp : "");
for (bufp = title; *bufp; bufp++)
- *bufp = toupper(*bufp);
+ *bufp = toupper((u_char)*bufp);
p->offset = 0;
p->rmargin = (p->maxrmargin - strlen(buf)) / 2;
diff --git a/strings.c b/strings.c
index eb6a8917..55cfe46b 100644
--- a/strings.c
+++ b/strings.c
@@ -62,16 +62,16 @@ mdoc_isescape(const char *p)
case ('e'):
return(2);
case ('*'):
- if (0 == *++p || ! isgraph((int)*p))
+ if (0 == *++p || ! isgraph((u_char)*p))
return(0);
switch (*p) {
case ('('):
- if (0 == *++p || ! isgraph((int)*p))
+ if (0 == *++p || ! isgraph((u_char)*p))
return(0);
return(4);
case ('['):
for (c = 3, p++; *p && ']' != *p; p++, c++)
- if ( ! isgraph((int)*p))
+ if ( ! isgraph((u_char)*p))
break;
return(*p == ']' ? c : 0);
default:
@@ -79,9 +79,9 @@ mdoc_isescape(const char *p)
}
return(3);
case ('('):
- if (0 == *++p || ! isgraph((int)*p))
+ if (0 == *++p || ! isgraph((u_char)*p))
return(0);
- if (0 == *++p || ! isgraph((int)*p))
+ if (0 == *++p || ! isgraph((u_char)*p))
return(0);
return(4);
case ('['):
@@ -91,7 +91,7 @@ mdoc_isescape(const char *p)
}
for (c = 3, p++; *p && ']' != *p; p++, c++)
- if ( ! isgraph((int)*p))
+ if ( ! isgraph((u_char)*p))
break;
return(*p == ']' ? c : 0);
diff --git a/term.c b/term.c
index 6a5c8c19..403b9bb0 100644
--- a/term.c
+++ b/term.c
@@ -295,7 +295,7 @@ arg_width(const struct mdoc_arg *arg)
assert(len > 0);
for (i = 0; i < len - 1; i++)
- if ( ! isdigit((int)(*arg->value)[i]))
+ if ( ! isdigit((u_char)(*arg->value)[i]))
break;
if (i == len - 1) {
@@ -693,10 +693,6 @@ termp_ar_pre(DECL_ARGS)
{
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]);
- if (NULL == node->child) {
- word(p, "file");
- word(p, "...");
- }
return(1);
}
diff --git a/validate.c b/validate.c
index 725041e1..c028b5ab 100644
--- a/validate.c
+++ b/validate.c
@@ -53,6 +53,9 @@ static int check_stdarg(PRE_ARGS);
static int check_text(struct mdoc *,
int, int, const char *);
+static int check_argv(struct mdoc *,
+ const struct mdoc_node *,
+ const struct mdoc_arg *);
static int err_child_lt(struct mdoc *, const char *, int);
static int warn_child_lt(struct mdoc *, const char *, int);
@@ -298,8 +301,6 @@ mdoc_valid_pre(struct mdoc *mdoc,
node->data.elem.argc;
for (i = 0; i < (int)argc; i++) {
- if (0 == argv[i].sz)
- continue;
for (j = 0; j < (int)argv[i].sz; j++) {
tp = argv[i].value[j];
line = argv[i].line;
@@ -307,6 +308,8 @@ mdoc_valid_pre(struct mdoc *mdoc,
if ( ! check_text(mdoc, line, pos, tp))
return(0);
}
+ if ( ! check_argv(mdoc, node, &argv[i]))
+ return(0);
}
}
@@ -476,6 +479,45 @@ check_msec(PRE_ARGS, int sz, enum mdoc_msec *msecs)
}
+/*
+ * Check over an argument. When this has more stuff in it, make this
+ * into a table-driven function; until then, a switch is fine.
+ */
+static int
+check_argv(struct mdoc *mdoc,
+ const struct mdoc_node *node,
+ const struct mdoc_arg *argv)
+{
+
+
+ switch (argv->arg) {
+ case (MDOC_Std):
+ switch (node->tok) {
+ case (MDOC_Ex):
+ /*
+ * If the -std does not have an argument, then
+ * set it with the default name (if set). This
+ * only happens with MDOC_Ex.
+ */
+ if (1 == argv->sz)
+ return(1);
+ assert(0 == argv->sz);
+ if (mdoc->meta.name)
+ return(1);
+ return(mdoc_nerr(mdoc, node,
+ "default name not yet set"));
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return(1);
+}
+
+
static int
check_text(struct mdoc *mdoc, int line, int pos, const char *p)
{
@@ -484,7 +526,7 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p)
/* XXX - indicate deprecated escapes \*(xx and \*x. */
for ( ; *p; p++) {
- if ( ! isprint((int)*p) && '\t' != *p)
+ if ( ! isprint((u_char)*p) && '\t' != *p)
return(mdoc_perr(mdoc, line, pos,
"invalid non-printing characters"));
if ('\\' != *p)