-/* $Id: mdoc_argv.c,v 1.63 2011/03/16 17:55:39 kristaps Exp $ */
+/* $Id: mdoc_argv.c,v 1.76 2011/04/19 16:38:48 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
#include <stdio.h>
#include <string.h>
+#include "mdoc.h"
#include "mandoc.h"
#include "libmdoc.h"
#include "libmandoc.h"
-/*
- * Routines to parse arguments of macros. Arguments follow the syntax
- * of `-arg [val [valN...]]'. Arguments come in all types: quoted
- * arguments, multiple arguments per value, no-value arguments, etc.
- *
- * There's no limit to the number or arguments that may be allocated.
- */
+#define MULTI_STEP 5 /* pre-allocate argument values */
+#define DELIMSZ 6 /* max possible size of a delimiter */
-#define ARGV_NONE (1 << 0)
-#define ARGV_SINGLE (1 << 1)
-#define ARGV_MULTI (1 << 2)
-#define ARGV_OPT_SINGLE (1 << 3)
+enum argsflag {
+ ARGSFL_NONE = 0,
+ ARGSFL_DELIM, /* handle delimiters of [[::delim::][ ]+]+ */
+ ARGSFL_TABSEP /* handle tab/`Ta' separated phrases */
+};
-#define MULTI_STEP 5
+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);
static int argv(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
static int argv_single(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
static int argv_multi(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
+static void argn_free(struct mdoc_arg *, int);
-/* Per-argument flags. */
-
-static int mdoc_argvflags[MDOC_ARG_MAX] = {
+static const enum argvflag argvflags[MDOC_ARG_MAX] = {
ARGV_NONE, /* MDOC_Split */
ARGV_NONE, /* MDOC_Nosplit */
ARGV_NONE, /* MDOC_Ragged */
ARGV_NONE /* MDOC_Symbolic */
};
-static int mdoc_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[] = {
+ MDOC_Std,
+ MDOC_ARG_MAX
+};
+
+static const enum mdocargt args_An[] = {
+ MDOC_Split,
+ MDOC_Nosplit,
+ MDOC_ARG_MAX
};
+static const enum mdocargt args_Bd[] = {
+ MDOC_Ragged,
+ MDOC_Unfilled,
+ MDOC_Filled,
+ MDOC_Literal,
+ MDOC_File,
+ MDOC_Offset,
+ MDOC_Compact,
+ MDOC_Centred,
+ MDOC_ARG_MAX
+};
+
+static const enum mdocargt args_Bf[] = {
+ MDOC_Emphasis,
+ MDOC_Literal,
+ MDOC_Symbolic,
+ MDOC_ARG_MAX
+};
+
+static const enum mdocargt args_Bk[] = {
+ MDOC_Words,
+ MDOC_ARG_MAX
+};
+
+static const enum mdocargt args_Bl[] = {
+ MDOC_Bullet,
+ MDOC_Dash,
+ MDOC_Hyphen,
+ MDOC_Item,
+ MDOC_Enum,
+ MDOC_Tag,
+ MDOC_Diag,
+ MDOC_Hang,
+ MDOC_Ohang,
+ MDOC_Inset,
+ MDOC_Column,
+ MDOC_Width,
+ MDOC_Offset,
+ MDOC_Compact,
+ MDOC_Nested,
+ MDOC_ARG_MAX
+};
/*
* Parse an argument from line text. This comes in the form of -key
buf[(*pos)++] = '\0';
}
- (void)memset(&tmp, 0, sizeof(struct mdoc_argv));
+ memset(&tmp, 0, sizeof(struct mdoc_argv));
tmp.line = line;
tmp.pos = *pos;
arg->argv = mandoc_realloc
(arg->argv, arg->argc * sizeof(struct mdoc_argv));
- (void)memcpy(&arg->argv[(int)arg->argc - 1],
+ memcpy(&arg->argv[(int)arg->argc - 1],
&tmp, sizeof(struct mdoc_argv));
return(ARGV_ARG);
}
-
void
mdoc_argv_free(struct mdoc_arg *p)
{
assert(p->argc);
for (i = (int)p->argc - 1; i >= 0; i--)
- mdoc_argn_free(p, i);
+ argn_free(p, i);
free(p->argv);
free(p);
}
-
-void
-mdoc_argn_free(struct mdoc_arg *p, int iarg)
+static void
+argn_free(struct mdoc_arg *p, int iarg)
{
struct mdoc_argv *arg;
int j;
p->argv[iarg] = p->argv[iarg+1];
}
-
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 = mdoc_argflags[tok];
+ fl = argflags[tok];
if (MDOC_It != tok)
return(args(m, line, pos, buf, fl, v));
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)
{
- int i;
char *p, *pp;
enum margserr rc;
- enum mdelim d;
-
- /*
- * 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]);
* is unterminated.
*/
if (MDOC_PHRASELIT & m->flags)
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE))
- return(ARGS_ERROR);
+ mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE);
m->flags &= ~MDOC_PHRASELIT;
return(ARGS_EOLN);
}
- /*
- * If the first character is a closing delimiter and we're to
- * look for delimited strings, then pass down the buffer seeing
- * if it follows the pattern of [[::delim::][ ]+]+. Note that
- * we ONLY care about closing delimiters.
- */
-
- if ((fl & ARGS_DELIM) && DELIM_CLOSE == mdoc_iscdelim(buf[*pos])) {
- for (i = *pos; buf[i]; ) {
- d = mdoc_iscdelim(buf[i]);
- if (DELIM_NONE == d || DELIM_OPEN == d)
- break;
- i++;
- if ('\0' == buf[i] || ' ' != buf[i])
- break;
- i++;
- while (buf[i] && ' ' == buf[i])
- i++;
- }
+ *v = &buf[*pos];
- if ('\0' == buf[i]) {
- *v = &buf[*pos];
- if (i && ' ' != buf[i - 1])
- return(ARGS_PUNCT);
- if (ARGS_NOWARN & fl)
- return(ARGS_PUNCT);
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE))
- return(ARGS_ERROR);
+ if (ARGSFL_DELIM == fl)
+ if (args_checkpunct(m, buf, *pos, line))
return(ARGS_PUNCT);
- }
- }
-
- *v = &buf[*pos];
/*
* First handle TABSEP items, restricted to `Bl -column'. This
* 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;
}
/* Whitespace check for eoln case... */
- if ('\0' == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl))
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE))
- return(ARGS_ERROR);
+ if ('\0' == *p && ' ' == *(p - 1))
+ mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
*pos += (int)(p - *v);
}
if ('\0' == buf[*pos]) {
- if (ARGS_NOWARN & fl || MDOC_PPHRASE & m->flags)
+ if (MDOC_PPHRASE & m->flags)
return(ARGS_QWORD);
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE))
- return(ARGS_ERROR);
+ mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE);
return(ARGS_QWORD);
}
while (' ' == buf[*pos])
(*pos)++;
- if (0 == buf[*pos] && ! (ARGS_NOWARN & fl))
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE))
- return(ARGS_ERROR);
+ if ('\0' == buf[*pos])
+ mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
return(ARGS_QWORD);
}
- /*
- * A non-quoted term progresses until either the end of line or
- * a non-escaped whitespace.
- */
+ p = &buf[*pos];
+ *v = mandoc_getarg(m->parse, &p, line, pos);
- for ( ; buf[*pos]; (*pos)++)
- if (*pos && ' ' == buf[*pos] && '\\' != buf[*pos - 1])
- break;
+ return(ARGS_WORD);
+}
- if ('\0' == buf[*pos])
- return(ARGS_WORD);
+/*
+ * Check if the string consists only of space-separated closing
+ * delimiters. This is a bit of a dance: the first must be a close
+ * delimiter, but it may be followed by middle delimiters. Arbitrary
+ * whitespace may separate these tokens.
+ */
+static int
+args_checkpunct(struct mdoc *m, const char *buf, int i, int ln)
+{
+ int j;
+ char dbuf[DELIMSZ];
+ enum mdelim d;
- buf[(*pos)++] = '\0';
+ /* First token must be a close-delimiter. */
- while (' ' == buf[*pos])
- (*pos)++;
+ for (j = 0; buf[i] && ' ' != buf[i] && j < DELIMSZ; j++, i++)
+ dbuf[j] = buf[i];
- if ('\0' == buf[*pos] && ! (ARGS_NOWARN & fl))
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE))
- return(ARGS_ERROR);
+ if (DELIMSZ == j)
+ return(0);
- return(ARGS_WORD);
+ dbuf[j] = '\0';
+ if (DELIM_CLOSE != mdoc_isdelim(dbuf))
+ return(0);
+
+ while (' ' == buf[i])
+ i++;
+
+ /* Remaining must NOT be open/none. */
+
+ while (buf[i]) {
+ j = 0;
+ while (buf[i] && ' ' != buf[i] && j < DELIMSZ)
+ dbuf[j++] = buf[i++];
+
+ if (DELIMSZ == j)
+ return(0);
+
+ dbuf[j] = '\0';
+ d = mdoc_isdelim(dbuf);
+ if (DELIM_NONE == d || DELIM_OPEN == d)
+ return(0);
+
+ while (' ' == buf[i])
+ i++;
+ }
+
+ return('\0' == buf[i]);
}
/*
static enum mdocargt
argv_a2arg(enum mdoct tok, const char *p)
{
- enum mdocargt args[MDOC_ARG_MAX];
- int i, len;
+ const enum mdocargt *argsp;
- len = 0;
+ argsp = NULL;
switch (tok) {
case (MDOC_An):
- args[len++] = MDOC_Split;
- args[len++] = MDOC_Nosplit;
+ argsp = args_An;
break;
case (MDOC_Bd):
- args[len++] = MDOC_Ragged;
- args[len++] = MDOC_Unfilled;
- args[len++] = MDOC_Filled;
- args[len++] = MDOC_Literal;
- args[len++] = MDOC_File;
- args[len++] = MDOC_Offset;
- args[len++] = MDOC_Compact;
- args[len++] = MDOC_Centred;
+ argsp = args_Bd;
break;
case (MDOC_Bf):
- args[len++] = MDOC_Emphasis;
- args[len++] = MDOC_Literal;
- args[len++] = MDOC_Symbolic;
+ argsp = args_Bf;
break;
case (MDOC_Bk):
- args[len++] = MDOC_Words;
+ argsp = args_Bk;
break;
case (MDOC_Bl):
- args[len++] = MDOC_Bullet;
- args[len++] = MDOC_Dash;
- args[len++] = MDOC_Hyphen;
- args[len++] = MDOC_Item;
- args[len++] = MDOC_Enum;
- args[len++] = MDOC_Tag;
- args[len++] = MDOC_Diag;
- args[len++] = MDOC_Hang;
- args[len++] = MDOC_Ohang;
- args[len++] = MDOC_Inset;
- args[len++] = MDOC_Column;
- args[len++] = MDOC_Width;
- args[len++] = MDOC_Offset;
- args[len++] = MDOC_Compact;
- args[len++] = MDOC_Nested;
+ argsp = args_Bl;
break;
case (MDOC_Rv):
/* FALLTHROUGH */
case (MDOC_Ex):
- args[len++] = MDOC_Std;
+ argsp = args_Ex;
break;
default:
- break;
+ return(MDOC_ARG_MAX);
}
- for (i = 0; i < len; i++)
- if (0 == strcmp(p, mdoc_argnames[args[i]]))
- return(args[i]);
+ assert(argsp);
+
+ for ( ; MDOC_ARG_MAX != *argsp ; argsp++)
+ if (0 == strcmp(p, mdoc_argnames[*argsp]))
+ return(*argsp);
return(MDOC_ARG_MAX);
}
-
static int
argv_multi(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
return(1);
}
-
static int
argv_opt_single(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
return(1);
}
-
/*
* Parse a single, mandatory value from the stream.
*/
return(1);
}
-
/*
* Determine rules for parsing arguments. Arguments can either accept
* no parameters, an optional single parameter, one parameter, or
v->sz = 0;
v->value = NULL;
- switch (mdoc_argvflags[v->arg]) {
+ switch (argvflags[v->arg]) {
case (ARGV_SINGLE):
return(argv_single(mdoc, line, v, pos, buf));
case (ARGV_MULTI):
return(argv_multi(mdoc, line, v, pos, buf));
case (ARGV_OPT_SINGLE):
return(argv_opt_single(mdoc, line, v, pos, buf));
- default:
- /* ARGV_NONE */
+ case (ARGV_NONE):
break;
+ default:
+ abort();
+ /* NOTREACHED */
}
return(1);