summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-22 14:56:21 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-22 14:56:21 +0000
commit557eea53236378e26b9f5085251d8c15c8dda4b5 (patch)
tree24ded83d5df411e30318c31126ffcebb5592ca57
parent4b119aaaf1c41e166b4050fc5400bdec6306baef (diff)
downloadmandoc-557eea53236378e26b9f5085251d8c15c8dda4b5.tar.gz
Fix-ups to macro.c.
-rw-r--r--Makefile2
-rw-r--r--argv.c102
-rw-r--r--macro.c98
-rw-r--r--private.h1
4 files changed, 153 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index 9e1c2cec..c559c725 100644
--- a/Makefile
+++ b/Makefile
@@ -96,7 +96,7 @@ dist: mdocml-$(VERSION).tar.gz
port: mdocml-oport-$(VERSION).tar.gz
-regress::
+regress:: mdocml
@for f in $(FAIL); do \
echo "./mdocml $$f" ; \
./mdocml $$f 2>/dev/null || continue ; exit 1 ; done
diff --git a/argv.c b/argv.c
index 2a2d5822..43a9d004 100644
--- a/argv.c
+++ b/argv.c
@@ -37,22 +37,28 @@
#define ARGS_TABSEP (1 << 2)
static int lookup(int, const char *);
-static int parse(struct mdoc *, int,
+static int args(struct mdoc *, int, int *,
+ char *, int, char **);
+static int argv(struct mdoc *, int,
struct mdoc_arg *, int *, char *);
-static int parse_single(struct mdoc *, int,
+static int argv_single(struct mdoc *, int,
struct mdoc_arg *, int *, char *);
-static int parse_multi(struct mdoc *, int,
+static int argv_multi(struct mdoc *, int,
struct mdoc_arg *, int *, char *);
-static int postparse(struct mdoc *, int,
+static int postargv(struct mdoc *, int,
const struct mdoc_arg *, int);
static int pwarn(struct mdoc *, int, int, int);
static int perr(struct mdoc *, int, int, int);
+/* Warning messages. */
+
#define WQUOTPARM (0)
#define WARGVPARM (1)
#define WCOLEMPTY (2)
#define WTAILWS (3)
+/* Error messages. */
+
#define EQUOTTERM (0)
#define EOFFSET (1)
#define EARGVAL (2)
@@ -232,25 +238,11 @@ int
mdoc_args(struct mdoc *mdoc, int line,
int *pos, char *buf, int tok, char **v)
{
- int i, c, fl;
- char *p, *pp;
+ int fl, c, i;
struct mdoc_node *n;
- assert(*pos > 0);
-
- if (0 == buf[*pos])
- return(ARGS_EOLN);
-
fl = (0 == tok) ? 0 : mdoc_argflags[tok];
- if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED))
- if ( ! pwarn(mdoc, line, *pos, WQUOTPARM))
- return(ARGS_ERROR);
-
- if ('-' == buf[*pos])
- if ( ! pwarn(mdoc, line, *pos, WARGVPARM))
- return(ARGS_ERROR);
-
/*
* First see if we should use TABSEP (Bl -column). This
* invalidates the use of ARGS_DELIM.
@@ -264,14 +256,41 @@ mdoc_args(struct mdoc *mdoc, int line,
assert(n);
c = (int)n->data.block.argc;
assert(c > 0);
+
+ /* LINTED */
for (i = 0; i < c; i++) {
if (MDOC_Column != n->data.block.argv[i].arg)
continue;
fl |= ARGS_TABSEP;
fl &= ~ARGS_DELIM;
+ break;
}
}
+ return(args(mdoc, line, pos, buf, fl, v));
+}
+
+
+static int
+args(struct mdoc *mdoc, int line,
+ int *pos, char *buf, int fl, char **v)
+{
+ int i, c;
+ char *p, *pp;
+
+ assert(*pos > 0);
+
+ if (0 == buf[*pos])
+ return(ARGS_EOLN);
+
+ if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED))
+ if ( ! pwarn(mdoc, line, *pos, WQUOTPARM))
+ return(ARGS_ERROR);
+
+ if ('-' == buf[*pos])
+ if ( ! pwarn(mdoc, line, *pos, WARGVPARM))
+ return(ARGS_ERROR);
+
/*
* If the first character is a delimiter and we're to look for
* delimited strings, then pass down the buffer seeing if it
@@ -374,17 +393,18 @@ mdoc_args(struct mdoc *mdoc, int line,
if ( ! pwarn(mdoc, line, *pos, WTAILWS))
return(0);
+ if (p)
+ return(ARGS_WORD);
+
/* Configure the eoln case, too. */
- if (NULL == p) {
- p = strchr(*v, 0);
- assert(p);
+ p = strchr(*v, 0);
+ assert(p);
- if (p > *v && ' ' == *(p - 1))
- if ( ! pwarn(mdoc, line, *pos, WTAILWS))
- return(0);
- *pos += p - *v;
- }
+ if (p > *v && ' ' == *(p - 1))
+ if ( ! pwarn(mdoc, line, *pos, WTAILWS))
+ return(0);
+ *pos += p - *v;
return(ARGS_WORD);
}
@@ -618,7 +638,7 @@ lookup(int tok, const char *argv)
static int
-postparse(struct mdoc *mdoc, int line, const struct mdoc_arg *v, int pos)
+postargv(struct mdoc *mdoc, int line, const struct mdoc_arg *v, int pos)
{
switch (v->arg) {
@@ -645,7 +665,7 @@ postparse(struct mdoc *mdoc, int line, const struct mdoc_arg *v, int pos)
static int
-parse_multi(struct mdoc *mdoc, int line,
+argv_multi(struct mdoc *mdoc, int line,
struct mdoc_arg *v, int *pos, char *buf)
{
int c, ppos;
@@ -659,7 +679,7 @@ parse_multi(struct mdoc *mdoc, int line,
for (v->sz = 0; v->sz < MDOC_LINEARG_MAX; v->sz++) {
if ('-' == buf[*pos])
break;
- c = mdoc_args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
+ c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
if (ARGS_ERROR == c) {
free(v->value);
return(0);
@@ -680,7 +700,7 @@ parse_multi(struct mdoc *mdoc, int line,
static int
-parse_single(struct mdoc *mdoc, int line,
+argv_single(struct mdoc *mdoc, int line,
struct mdoc_arg *v, int *pos, char *buf)
{
int c, ppos;
@@ -688,7 +708,7 @@ parse_single(struct mdoc *mdoc, int line,
ppos = *pos;
- c = mdoc_args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
+ c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
if (ARGS_ERROR == c)
return(0);
if (ARGS_EOLN == c)
@@ -702,7 +722,7 @@ parse_single(struct mdoc *mdoc, int line,
static int
-parse(struct mdoc *mdoc, int line,
+argv(struct mdoc *mdoc, int line,
struct mdoc_arg *v, int *pos, char *buf)
{
@@ -715,9 +735,9 @@ parse(struct mdoc *mdoc, int line,
case(MDOC_Width):
/* FALLTHROUGH */
case(MDOC_Offset):
- return(parse_single(mdoc, line, v, pos, buf));
+ return(argv_single(mdoc, line, v, pos, buf));
case(MDOC_Column):
- return(parse_multi(mdoc, line, v, pos, buf));
+ return(argv_multi(mdoc, line, v, pos, buf));
default:
break;
}
@@ -731,7 +751,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
struct mdoc_arg *v, int *pos, char *buf)
{
int i, ppos;
- char *argv;
+ char *p;
(void)memset(v, 0, sizeof(struct mdoc_arg));
@@ -744,12 +764,14 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
return(ARGV_WORD);
i = *pos;
- argv = &buf[++(*pos)];
+ p = &buf[++(*pos)];
v->line = line;
v->pos = *pos;
assert(*pos > 0);
+
+ /* LINTED */
while (buf[*pos]) {
if (isspace((int)buf[*pos]))
if ('\\' != buf[*pos - 1])
@@ -760,7 +782,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
if (buf[*pos])
buf[(*pos)++] = 0;
- if (MDOC_ARG_MAX == (v->arg = lookup(tok, argv))) {
+ if (MDOC_ARG_MAX == (v->arg = lookup(tok, p))) {
if ( ! pwarn(mdoc, line, i, WARGVPARM))
return(ARGV_ERROR);
return(ARGV_WORD);
@@ -772,9 +794,9 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
/* FIXME: whitespace if no value. */
ppos = *pos;
- if ( ! parse(mdoc, line, v, pos, buf))
+ if ( ! argv(mdoc, line, v, pos, buf))
return(ARGV_ERROR);
- if ( ! postparse(mdoc, line, v, ppos))
+ if ( ! postargv(mdoc, line, v, ppos))
return(ARGV_ERROR);
return(ARGV_ARG);
diff --git a/macro.c b/macro.c
index 95133cad..eaeddee2 100644
--- a/macro.c
+++ b/macro.c
@@ -80,6 +80,7 @@
#define REWIND_REWIND (1 << 0)
#define REWIND_NOHALT (1 << 1)
#define REWIND_HALT (1 << 2)
+
static int rewind_dohalt(int, enum mdoc_type,
const struct mdoc_node *);
static int rewind_alt(int);
@@ -92,6 +93,63 @@ static int rewind_subblock(enum mdoc_type,
static int rewind_last(struct mdoc *, struct mdoc_node *);
static int append_delims(struct mdoc *, int, int *, char *);
static int lookup(struct mdoc *, int, int, int, const char *);
+static int pwarn(struct mdoc *, int, int, int);
+static int perr(struct mdoc *, int, int, int);
+
+#define WMACPARM (1)
+#define WOBS (2)
+
+#define ENOCTX (1)
+#define ENOPARMS (2)
+#define EARGVLIM (3)
+
+
+static int
+perr(struct mdoc *mdoc, int line, int pos, int type)
+{
+ int c;
+
+ switch (type) {
+ case (ENOCTX):
+ c = mdoc_perr(mdoc, line, pos,
+ "closing macro has prior context");
+ break;
+ case (ENOPARMS):
+ c = mdoc_perr(mdoc, line, pos,
+ "macro doesn't expect parameters");
+ break;
+ case (EARGVLIM):
+ c = mdoc_perr(mdoc, line, pos,
+ "argument hard-limit %d reached",
+ MDOC_LINEARG_MAX);
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+ return(c);
+}
+
+static int
+pwarn(struct mdoc *mdoc, int line, int pos, int type)
+{
+ int c;
+
+ switch (type) {
+ case (WMACPARM):
+ c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
+ "macro-like parameter");
+ break;
+ case (WOBS):
+ c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
+ "macro is marked obsolete");
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+ return(c);
+}
static int
@@ -104,7 +162,7 @@ lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p)
return(res);
if (MDOC_MAX == res)
return(res);
- if ( ! mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX, "macro-like parameter"))
+ if ( ! pwarn(mdoc, line, pos, WMACPARM))
return(-1);
return(MDOC_MAX);
}
@@ -117,6 +175,7 @@ rewind_last(struct mdoc *mdoc, struct mdoc_node *to)
assert(to);
mdoc->next = MDOC_NEXT_SIBLING;
+ /* LINTED */
while (mdoc->last != to) {
if ( ! mdoc_valid_post(mdoc))
return(0);
@@ -396,7 +455,7 @@ rewind_expblock(struct mdoc *mdoc, int tok, int line, int ppos)
for (n = mdoc->last; n; n = n->parent) {
c = rewind_dohalt(tok, MDOC_BLOCK, n);
if (REWIND_HALT == c)
- return(mdoc_perr(mdoc, line, ppos, "closing macro has no context"));
+ return(perr(mdoc, line, ppos, ENOCTX));
if (REWIND_REWIND == c)
break;
else if (rewind_dobreak(tok, n))
@@ -444,6 +503,8 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
for (;;) {
lastarg = *pos;
c = mdoc_args(mdoc, line, pos, buf, 0, &p);
+ assert(ARGS_PHRASE != c);
+
if (ARGS_ERROR == c)
return(0);
else if (ARGS_EOLN == c)
@@ -488,7 +549,7 @@ macro_scoped_close(MACRO_PROT_ARGS)
return(0);
return(rewind_expblock(mdoc, tok, line, ppos));
}
- return(mdoc_perr(mdoc, line, ppos, "macro expects no parameters"));
+ return(perr(mdoc, line, ppos, ENOPARMS));
}
if ( ! rewind_subblock(MDOC_BODY, mdoc, tok, line, ppos))
@@ -513,6 +574,8 @@ macro_scoped_close(MACRO_PROT_ARGS)
}
c = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ assert(ARGS_PHRASE != c);
+
if (ARGS_ERROR == c)
return(0);
if (ARGS_PUNCT == c)
@@ -598,7 +661,7 @@ macro_text(MACRO_PROT_ARGS)
if (MDOC_LINEARG_MAX == argc) {
mdoc_argv_free(argc - 1, argv);
- return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));
+ return(perr(mdoc, line, ppos, EARGVLIM));
}
c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);
@@ -614,6 +677,8 @@ macro_text(MACRO_PROT_ARGS)
for (;;) {
la = *pos;
w = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ assert(ARGS_PHRASE != c);
+
if (ARGS_ERROR == w) {
mdoc_argv_free(argc, argv);
return(0);
@@ -736,7 +801,7 @@ macro_scoped(MACRO_PROT_ARGS)
if (MDOC_LINEARG_MAX == argc) {
mdoc_argv_free(argc - 1, argv);
- return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));
+ return(perr(mdoc, line, ppos, EARGVLIM));
}
c = mdoc_block_alloc(mdoc, line, ppos,
@@ -766,7 +831,7 @@ macro_scoped(MACRO_PROT_ARGS)
for (;;) {
lastarg = *pos;
c = mdoc_args(mdoc, line, pos, buf, tok, &p);
-
+
if (ARGS_ERROR == c)
return(0);
if (ARGS_PUNCT == c)
@@ -774,6 +839,14 @@ macro_scoped(MACRO_PROT_ARGS)
if (ARGS_EOLN == c)
break;
+ if (ARGS_PHRASE == c) {
+ /*
+ if ( ! mdoc_phrase(mdoc, line, lastarg, buf))
+ return(0);
+ */
+ continue;
+ }
+
/* FIXME: if .It -column, the lookup must be for a
* sub-line component. BLAH. */
@@ -847,6 +920,7 @@ macro_scoped_line(MACRO_PROT_ARGS)
for (;;) {
lastarg = *pos;
c = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ assert(ARGS_PHRASE != c);
if (ARGS_ERROR == c)
return(0);
@@ -943,6 +1017,8 @@ macro_constant_scoped(MACRO_PROT_ARGS)
}
c = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ assert(ARGS_PHRASE != c);
+
if (ARGS_ERROR == c)
return(0);
if (ARGS_PUNCT == c)
@@ -1050,7 +1126,7 @@ macro_constant_delimited(MACRO_PROT_ARGS)
if (MDOC_LINEARG_MAX == argc) {
mdoc_argv_free(argc - 1, argv);
- return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));
+ return(perr(mdoc, line, ppos, EARGVLIM));
}
c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);
@@ -1071,6 +1147,8 @@ macro_constant_delimited(MACRO_PROT_ARGS)
}
c = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ assert(ARGS_PHRASE != c);
+
if (ARGS_ERROR == c)
return(0);
if (ARGS_PUNCT == c)
@@ -1139,7 +1217,7 @@ macro_constant(MACRO_PROT_ARGS)
if (MDOC_LINEARG_MAX == argc) {
mdoc_argv_free(argc - 1, argv);
- return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));
+ return(perr(mdoc, line, ppos, EARGVLIM));
}
c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);
@@ -1153,6 +1231,8 @@ macro_constant(MACRO_PROT_ARGS)
for (;;) {
la = *pos;
w = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ assert(ARGS_PHRASE != c);
+
if (ARGS_ERROR == w)
return(0);
if (ARGS_EOLN == w)
@@ -1182,7 +1262,7 @@ int
macro_obsolete(MACRO_PROT_ARGS)
{
- return(mdoc_pwarn(mdoc, line, ppos, WARN_SYNTAX, "macro is obsolete"));
+ return(pwarn(mdoc, line, ppos, WOBS));
}
diff --git a/private.h b/private.h
index 498fb1d2..b3ec0fa3 100644
--- a/private.h
+++ b/private.h
@@ -154,6 +154,7 @@ int mdoc_args(struct mdoc *, int,
#define ARGS_WORD (1)
#define ARGS_PUNCT (2)
#define ARGS_QWORD (3)
+#define ARGS_PHRASE (4)
int xstrlcats(char *, const struct mdoc_node *, size_t);
int xstrlcat(char *, const char *, size_t);