summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmandoc.h3
-rw-r--r--libmdoc.h8
-rw-r--r--man_macro.c2
-rw-r--r--mandoc.c16
-rw-r--r--mdoc_argv.c326
-rw-r--r--mdoc_macro.c6
-rw-r--r--roff.c2
7 files changed, 166 insertions, 197 deletions
diff --git a/libmandoc.h b/libmandoc.h
index e78c5494..cdfa2c6e 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -74,8 +74,7 @@ void mandoc_msg(enum mandocerr, struct mparse *,
void mandoc_vmsg(enum mandocerr, struct mparse *,
int, int, const char *, ...);
char *mandoc_strdup(const char *);
-char *mandoc_getarg(struct mparse *,
- char **, int, int, int *);
+char *mandoc_getarg(struct mparse *, char **, int, int *);
char *mandoc_normdate(struct mparse *, char *, int, int);
int mandoc_eos(const char *, size_t, int);
int mandoc_hyph(const char *, const char *);
diff --git a/libmdoc.h b/libmdoc.h
index 2b4b2b70..9cdf598b 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -133,14 +133,8 @@ void mdoc_argv_free(struct mdoc_arg *);
enum margserr mdoc_args(struct mdoc *, int,
int *, char *, enum mdoct, char **);
enum margserr mdoc_zargs(struct mdoc *, int,
- int *, char *, int, char **);
-#define ARGS_DELIM (1 << 1)
-#define ARGS_TABSEP (1 << 2)
-#define ARGS_NOWARN (1 << 3)
-
+ int *, char *, char **);
int mdoc_macroend(struct mdoc *);
-
-#define DELIMSZ 6 /* hint: max possible size of a delimiter */
enum mdelim mdoc_isdelim(const char *);
__END_DECLS
diff --git a/man_macro.c b/man_macro.c
index cab56cf1..aff3fb00 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -484,6 +484,6 @@ man_args(struct man *m, int line, int *pos, char *buf, char **v)
if ('\0' == *start)
return(0);
- *v = mandoc_getarg(m->parse, v, line, 1, pos);
+ *v = mandoc_getarg(m->parse, v, line, pos);
return(1);
}
diff --git a/mandoc.c b/mandoc.c
index 6ca21577..86000415 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -95,15 +95,6 @@ numescape(const char *start)
return(++i);
}
-/*
- * Handle an escaped sequeence. This should be called with any
- * string subsequent a `\'. Pass a pointer to this substring as "end";
- * it will be set to the supremum of the parsed escape sequence. If
- * this returns ESCAPE_ERROR, the string is bogus and should be thrown
- * away. If not ESCAPE_ERROR or ESCAPE_IGNORE, "start" is set to the
- * first relevant character of the substring (font, glyph, whatever) of
- * length sz. Both "start" and "sz" may be NULL.
- */
enum mandoc_esc
mandoc_escape(const char **end, const char **start, int *sz)
{
@@ -460,8 +451,7 @@ mandoc_strdup(const char *ptr)
* or to the null byte terminating the argument line.
*/
char *
-mandoc_getarg(struct mparse *parse,
- char **cpp, int ln, int dowarn, int *pos)
+mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos)
{
char *start, *cp;
int quoted, pairs, white;
@@ -508,7 +498,7 @@ mandoc_getarg(struct mparse *parse,
}
/* Quoted argument without a closing quote. */
- if (dowarn && 1 == quoted)
+ if (1 == quoted)
mandoc_msg(MANDOCERR_BADQUOTE, parse, ln, *pos, NULL);
/* Null-terminate this argument and move to the next one. */
@@ -522,7 +512,7 @@ mandoc_getarg(struct mparse *parse,
*pos += (int)(cp - start) + (quoted ? 1 : 0);
*cpp = cp;
- if (dowarn && '\0' == *cp && (white || ' ' == cp[-1]))
+ if ('\0' == *cp && (white || ' ' == cp[-1]))
mandoc_msg(MANDOCERR_EOLNSPACE, parse, ln, *pos, NULL);
return(start);
diff --git a/mdoc_argv.c b/mdoc_argv.c
index 3c1484ef..e6f105e1 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -32,12 +32,26 @@
#include "libmandoc.h"
#define MULTI_STEP 5 /* pre-allocate argument values */
+#define DELIMSZ 6 /* max possible size of a delimiter */
+
+enum argsflag {
+ ARGSFL_NONE = 0,
+ ARGSFL_DELIM, /* handle delimiters of [[::delim::][ ]+]+ */
+ ARGSFL_TABSEP /* handle tab/`Ta' separated phrases */
+};
+
+enum argvflag {
+ ARGV_NONE, /* no args to flag (e.g., -split) */
+ ARGV_SINGLE, /* one arg to flag (e.g., -file xxx) */
+ ARGV_MULTI, /* multiple args (e.g., -column xxx yyy) */
+ ARGV_OPT_SINGLE /* optional arg (e.g., -offset [xxx]) */
+};
static enum mdocargt argv_a2arg(enum mdoct, const char *);
static enum margserr args(struct mdoc *, int, int *,
- char *, int, char **);
+ char *, enum argsflag, char **);
static int args_checkpunct(struct mdoc *,
- const char *, int, int, int);
+ const char *, int, int);
static int argv(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
static int argv_single(struct mdoc *, int,
@@ -48,13 +62,6 @@ static int argv_multi(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
static void argn_free(struct mdoc_arg *, int);
-enum argvflag {
- ARGV_NONE, /* no args to flag (e.g., -split) */
- ARGV_SINGLE, /* one arg to flag (e.g., -file xxx) */
- ARGV_MULTI, /* multiple args (e.g., -column xxx yyy) */
- ARGV_OPT_SINGLE /* optional arg (e.g., -offset [xxx]) */
-};
-
static const enum argvflag argvflags[MDOC_ARG_MAX] = {
ARGV_NONE, /* MDOC_Split */
ARGV_NONE, /* MDOC_Nosplit */
@@ -84,129 +91,129 @@ static const enum argvflag argvflags[MDOC_ARG_MAX] = {
ARGV_NONE /* MDOC_Symbolic */
};
-static const int argflags[MDOC_MAX] = {
- 0, /* Ap */
- 0, /* Dd */
- 0, /* Dt */
- 0, /* Os */
- 0, /* Sh */
- 0, /* Ss */
- 0, /* Pp */
- ARGS_DELIM, /* D1 */
- ARGS_DELIM, /* Dl */
- 0, /* Bd */
- 0, /* Ed */
- 0, /* Bl */
- 0, /* El */
- 0, /* It */
- ARGS_DELIM, /* Ad */
- ARGS_DELIM, /* An */
- ARGS_DELIM, /* Ar */
- 0, /* Cd */
- ARGS_DELIM, /* Cm */
- ARGS_DELIM, /* Dv */
- ARGS_DELIM, /* Er */
- ARGS_DELIM, /* Ev */
- 0, /* Ex */
- ARGS_DELIM, /* Fa */
- 0, /* Fd */
- ARGS_DELIM, /* Fl */
- ARGS_DELIM, /* Fn */
- ARGS_DELIM, /* Ft */
- ARGS_DELIM, /* Ic */
- 0, /* In */
- ARGS_DELIM, /* Li */
- 0, /* Nd */
- ARGS_DELIM, /* Nm */
- ARGS_DELIM, /* Op */
- 0, /* Ot */
- ARGS_DELIM, /* Pa */
- 0, /* Rv */
- ARGS_DELIM, /* St */
- ARGS_DELIM, /* Va */
- ARGS_DELIM, /* Vt */
- ARGS_DELIM, /* Xr */
- 0, /* %A */
- 0, /* %B */
- 0, /* %D */
- 0, /* %I */
- 0, /* %J */
- 0, /* %N */
- 0, /* %O */
- 0, /* %P */
- 0, /* %R */
- 0, /* %T */
- 0, /* %V */
- ARGS_DELIM, /* Ac */
- 0, /* Ao */
- ARGS_DELIM, /* Aq */
- ARGS_DELIM, /* At */
- ARGS_DELIM, /* Bc */
- 0, /* Bf */
- 0, /* Bo */
- ARGS_DELIM, /* Bq */
- ARGS_DELIM, /* Bsx */
- ARGS_DELIM, /* Bx */
- 0, /* Db */
- ARGS_DELIM, /* Dc */
- 0, /* Do */
- ARGS_DELIM, /* Dq */
- ARGS_DELIM, /* Ec */
- 0, /* Ef */
- ARGS_DELIM, /* Em */
- 0, /* Eo */
- ARGS_DELIM, /* Fx */
- ARGS_DELIM, /* Ms */
- ARGS_DELIM, /* No */
- ARGS_DELIM, /* Ns */
- ARGS_DELIM, /* Nx */
- ARGS_DELIM, /* Ox */
- ARGS_DELIM, /* Pc */
- ARGS_DELIM, /* Pf */
- 0, /* Po */
- ARGS_DELIM, /* Pq */
- ARGS_DELIM, /* Qc */
- ARGS_DELIM, /* Ql */
- 0, /* Qo */
- ARGS_DELIM, /* Qq */
- 0, /* Re */
- 0, /* Rs */
- ARGS_DELIM, /* Sc */
- 0, /* So */
- ARGS_DELIM, /* Sq */
- 0, /* Sm */
- ARGS_DELIM, /* Sx */
- ARGS_DELIM, /* Sy */
- ARGS_DELIM, /* Tn */
- ARGS_DELIM, /* Ux */
- ARGS_DELIM, /* Xc */
- 0, /* Xo */
- 0, /* Fo */
- 0, /* Fc */
- 0, /* Oo */
- ARGS_DELIM, /* Oc */
- 0, /* Bk */
- 0, /* Ek */
- 0, /* Bt */
- 0, /* Hf */
- 0, /* Fr */
- 0, /* Ud */
- 0, /* Lb */
- 0, /* Lp */
- ARGS_DELIM, /* Lk */
- ARGS_DELIM, /* Mt */
- ARGS_DELIM, /* Brq */
- 0, /* Bro */
- ARGS_DELIM, /* Brc */
- 0, /* %C */
- 0, /* Es */
- 0, /* En */
- 0, /* Dx */
- 0, /* %Q */
- 0, /* br */
- 0, /* sp */
- 0, /* %U */
- 0, /* Ta */
+static const enum argsflag argflags[MDOC_MAX] = {
+ ARGSFL_NONE, /* Ap */
+ ARGSFL_NONE, /* Dd */
+ ARGSFL_NONE, /* Dt */
+ ARGSFL_NONE, /* Os */
+ ARGSFL_NONE, /* Sh */
+ ARGSFL_NONE, /* Ss */
+ ARGSFL_NONE, /* Pp */
+ ARGSFL_DELIM, /* D1 */
+ ARGSFL_DELIM, /* Dl */
+ ARGSFL_NONE, /* Bd */
+ ARGSFL_NONE, /* Ed */
+ ARGSFL_NONE, /* Bl */
+ ARGSFL_NONE, /* El */
+ ARGSFL_NONE, /* It */
+ ARGSFL_DELIM, /* Ad */
+ ARGSFL_DELIM, /* An */
+ ARGSFL_DELIM, /* Ar */
+ ARGSFL_NONE, /* Cd */
+ ARGSFL_DELIM, /* Cm */
+ ARGSFL_DELIM, /* Dv */
+ ARGSFL_DELIM, /* Er */
+ ARGSFL_DELIM, /* Ev */
+ ARGSFL_NONE, /* Ex */
+ ARGSFL_DELIM, /* Fa */
+ ARGSFL_NONE, /* Fd */
+ ARGSFL_DELIM, /* Fl */
+ ARGSFL_DELIM, /* Fn */
+ ARGSFL_DELIM, /* Ft */
+ ARGSFL_DELIM, /* Ic */
+ ARGSFL_NONE, /* In */
+ ARGSFL_DELIM, /* Li */
+ ARGSFL_NONE, /* Nd */
+ ARGSFL_DELIM, /* Nm */
+ ARGSFL_DELIM, /* Op */
+ ARGSFL_NONE, /* Ot */
+ ARGSFL_DELIM, /* Pa */
+ ARGSFL_NONE, /* Rv */
+ ARGSFL_DELIM, /* St */
+ ARGSFL_DELIM, /* Va */
+ ARGSFL_DELIM, /* Vt */
+ ARGSFL_DELIM, /* Xr */
+ ARGSFL_NONE, /* %A */
+ ARGSFL_NONE, /* %B */
+ ARGSFL_NONE, /* %D */
+ ARGSFL_NONE, /* %I */
+ ARGSFL_NONE, /* %J */
+ ARGSFL_NONE, /* %N */
+ ARGSFL_NONE, /* %O */
+ ARGSFL_NONE, /* %P */
+ ARGSFL_NONE, /* %R */
+ ARGSFL_NONE, /* %T */
+ ARGSFL_NONE, /* %V */
+ ARGSFL_DELIM, /* Ac */
+ ARGSFL_NONE, /* Ao */
+ ARGSFL_DELIM, /* Aq */
+ ARGSFL_DELIM, /* At */
+ ARGSFL_DELIM, /* Bc */
+ ARGSFL_NONE, /* Bf */
+ ARGSFL_NONE, /* Bo */
+ ARGSFL_DELIM, /* Bq */
+ ARGSFL_DELIM, /* Bsx */
+ ARGSFL_DELIM, /* Bx */
+ ARGSFL_NONE, /* Db */
+ ARGSFL_DELIM, /* Dc */
+ ARGSFL_NONE, /* Do */
+ ARGSFL_DELIM, /* Dq */
+ ARGSFL_DELIM, /* Ec */
+ ARGSFL_NONE, /* Ef */
+ ARGSFL_DELIM, /* Em */
+ ARGSFL_NONE, /* Eo */
+ ARGSFL_DELIM, /* Fx */
+ ARGSFL_DELIM, /* Ms */
+ ARGSFL_DELIM, /* No */
+ ARGSFL_DELIM, /* Ns */
+ ARGSFL_DELIM, /* Nx */
+ ARGSFL_DELIM, /* Ox */
+ ARGSFL_DELIM, /* Pc */
+ ARGSFL_DELIM, /* Pf */
+ ARGSFL_NONE, /* Po */
+ ARGSFL_DELIM, /* Pq */
+ ARGSFL_DELIM, /* Qc */
+ ARGSFL_DELIM, /* Ql */
+ ARGSFL_NONE, /* Qo */
+ ARGSFL_DELIM, /* Qq */
+ ARGSFL_NONE, /* Re */
+ ARGSFL_NONE, /* Rs */
+ ARGSFL_DELIM, /* Sc */
+ ARGSFL_NONE, /* So */
+ ARGSFL_DELIM, /* Sq */
+ ARGSFL_NONE, /* Sm */
+ ARGSFL_DELIM, /* Sx */
+ ARGSFL_DELIM, /* Sy */
+ ARGSFL_DELIM, /* Tn */
+ ARGSFL_DELIM, /* Ux */
+ ARGSFL_DELIM, /* Xc */
+ ARGSFL_NONE, /* Xo */
+ ARGSFL_NONE, /* Fo */
+ ARGSFL_NONE, /* Fc */
+ ARGSFL_NONE, /* Oo */
+ ARGSFL_DELIM, /* Oc */
+ ARGSFL_NONE, /* Bk */
+ ARGSFL_NONE, /* Ek */
+ ARGSFL_NONE, /* Bt */
+ ARGSFL_NONE, /* Hf */
+ ARGSFL_NONE, /* Fr */
+ ARGSFL_NONE, /* Ud */
+ ARGSFL_NONE, /* Lb */
+ ARGSFL_NONE, /* Lp */
+ ARGSFL_DELIM, /* Lk */
+ ARGSFL_DELIM, /* Mt */
+ ARGSFL_DELIM, /* Brq */
+ ARGSFL_NONE, /* Bro */
+ ARGSFL_DELIM, /* Brc */
+ ARGSFL_NONE, /* %C */
+ ARGSFL_NONE, /* Es */
+ ARGSFL_NONE, /* En */
+ ARGSFL_NONE, /* Dx */
+ ARGSFL_NONE, /* %Q */
+ ARGSFL_NONE, /* br */
+ ARGSFL_NONE, /* sp */
+ ARGSFL_NONE, /* %U */
+ ARGSFL_NONE, /* Ta */
};
static const enum mdocargt args_Ex[] = {
@@ -376,18 +383,17 @@ argn_free(struct mdoc_arg *p, int iarg)
}
enum margserr
-mdoc_zargs(struct mdoc *m, int line, int *pos,
- char *buf, int flags, char **v)
+mdoc_zargs(struct mdoc *m, int line, int *pos, char *buf, char **v)
{
- return(args(m, line, pos, buf, flags, v));
+ return(args(m, line, pos, buf, ARGSFL_NONE, v));
}
enum margserr
mdoc_args(struct mdoc *m, int line, int *pos,
char *buf, enum mdoct tok, char **v)
{
- int fl;
+ enum argsflag fl;
struct mdoc_node *n;
fl = argflags[tok];
@@ -404,38 +410,21 @@ mdoc_args(struct mdoc *m, int line, int *pos,
for (n = m->last; n; n = n->parent)
if (MDOC_Bl == n->tok)
- break;
-
- if (n && LIST_column == n->norm->Bl.type) {
- fl |= ARGS_TABSEP;
- fl &= ~ARGS_DELIM;
- }
+ if (LIST_column == n->norm->Bl.type) {
+ fl = ARGSFL_TABSEP;
+ break;
+ }
return(args(m, line, pos, buf, fl, v));
}
static enum margserr
args(struct mdoc *m, int line, int *pos,
- char *buf, int fl, char **v)
+ char *buf, enum argsflag fl, char **v)
{
char *p, *pp;
enum margserr rc;
- /*
- * Parse out the terms (like `val' in `.Xx -arg val' or simply
- * `.Xx val'), which can have all sorts of properties:
- *
- * ARGS_DELIM: use special handling if encountering trailing
- * delimiters in the form of [[::delim::][ ]+]+.
- *
- * ARGS_NOWARN: don't post warnings. This is only used when
- * re-parsing delimiters, as the warnings have already been
- * posted.
- *
- * ARGS_TABSEP: use special handling for tab/`Ta' separated
- * phrases like in `Bl -column'.
- */
-
assert(' ' != buf[*pos]);
if ('\0' == buf[*pos]) {
@@ -455,8 +444,9 @@ args(struct mdoc *m, int line, int *pos,
*v = &buf[*pos];
- if (ARGS_DELIM & fl && args_checkpunct(m, buf, *pos, line, fl))
- return(ARGS_PUNCT);
+ if (ARGSFL_DELIM == fl)
+ if (args_checkpunct(m, buf, *pos, line))
+ return(ARGS_PUNCT);
/*
* First handle TABSEP items, restricted to `Bl -column'. This
@@ -465,7 +455,7 @@ args(struct mdoc *m, int line, int *pos,
* for arguments at a later phase.
*/
- if (ARGS_TABSEP & fl) {
+ if (ARGSFL_TABSEP == fl) {
/* Scan ahead to tab (can't be escaped). */
p = strchr(*v, '\t');
pp = NULL;
@@ -504,7 +494,7 @@ args(struct mdoc *m, int line, int *pos,
}
/* Whitespace check for eoln case... */
- if ('\0' == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl))
+ if ('\0' == *p && ' ' == *(p - 1))
mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
*pos += (int)(p - *v);
@@ -547,7 +537,7 @@ args(struct mdoc *m, int line, int *pos,
}
if ('\0' == buf[*pos]) {
- if (ARGS_NOWARN & fl || MDOC_PPHRASE & m->flags)
+ if (MDOC_PPHRASE & m->flags)
return(ARGS_QWORD);
mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE);
return(ARGS_QWORD);
@@ -562,15 +552,14 @@ args(struct mdoc *m, int line, int *pos,
while (' ' == buf[*pos])
(*pos)++;
- if (0 == buf[*pos] && ! (ARGS_NOWARN & fl))
+ if ('\0' == buf[*pos])
mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
return(ARGS_QWORD);
}
p = &buf[*pos];
- *v = mandoc_getarg(m->parse, &p, line,
- ! (ARGS_NOWARN & fl), pos);
+ *v = mandoc_getarg(m->parse, &p, line, pos);
return(ARGS_WORD);
}
@@ -582,7 +571,7 @@ args(struct mdoc *m, int line, int *pos,
* whitespace may separate these tokens.
*/
static int
-args_checkpunct(struct mdoc *m, const char *buf, int i, int ln, int fl)
+args_checkpunct(struct mdoc *m, const char *buf, int i, int ln)
{
int j;
char dbuf[DELIMSZ];
@@ -622,9 +611,6 @@ args_checkpunct(struct mdoc *m, const char *buf, int i, int ln, int fl)
i++;
}
- if ( ! (ARGS_NOWARN & fl) && i && ' ' == buf[i - 1])
- mdoc_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE);
-
return('\0' == buf[i]);
}
diff --git a/mdoc_macro.c b/mdoc_macro.c
index a6c1d91d..5fc88916 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -618,7 +618,7 @@ append_delims(struct mdoc *m, int line, int *pos, char *buf)
for (;;) {
la = *pos;
- ac = mdoc_zargs(m, line, pos, buf, ARGS_NOWARN, &p);
+ ac = mdoc_zargs(m, line, pos, buf, &p);
if (ARGS_ERROR == ac)
return(0);
@@ -1717,7 +1717,7 @@ phrase(struct mdoc *m, int line, int ppos, char *buf)
for (pos = ppos; ; ) {
la = pos;
- ac = mdoc_zargs(m, line, &pos, buf, 0, &p);
+ ac = mdoc_zargs(m, line, &pos, buf, &p);
if (ARGS_ERROR == ac)
return(0);
@@ -1762,7 +1762,7 @@ phrase_ta(MACRO_PROT_ARGS)
for (;;) {
la = *pos;
- ac = mdoc_zargs(m, line, pos, buf, 0, &p);
+ ac = mdoc_zargs(m, line, pos, buf, &p);
if (ARGS_ERROR == ac)
return(0);
diff --git a/roff.c b/roff.c
index 9955fe92..c86bb31a 100644
--- a/roff.c
+++ b/roff.c
@@ -1238,7 +1238,7 @@ roff_userdef(ROFF_ARGS)
cp = *bufp + pos;
for (i = 0; i < 9; i++)
arg[i] = '\0' == *cp ? "" :
- mandoc_getarg(r->parse, &cp, ln, 1, &pos);
+ mandoc_getarg(r->parse, &cp, ln, &pos);
/*
* Expand macro arguments.