summaryrefslogtreecommitdiffstats
path: root/mdoc_argv.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-04-19 16:38:48 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-04-19 16:38:48 +0000
commit28f9fee25bc0d8859b0400d14433644687182bfb (patch)
tree5dc36e4ffc02fad26843da2c5000a69caab6f42f /mdoc_argv.c
parent0d4d66664cc5e466a53a90e48693b01d4f071cbc (diff)
downloadmandoc-28f9fee25bc0d8859b0400d14433644687182bfb.tar.gz
Clean up parsing of delimiters in -mdoc. First, remove the "dowarn"
variable from mandoc_getarg() so that it prints the warning every time. Then, remove the warning from args_checkpunct(). This way, warnings are being posted at the correct time. This makes the flag argument to mdoc_zargs() superfluous, so make it be zero when it's invoked. Finally, move the args() flags into mdoc_argv.c and make them enums.
Diffstat (limited to 'mdoc_argv.c')
-rw-r--r--mdoc_argv.c326
1 files changed, 156 insertions, 170 deletions
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]);
}