-/* $Id: mdoc_argv.c,v 1.72 2011/03/22 14:33:05 kristaps Exp $ */
+/* $Id: mdoc_argv.c,v 1.74 2011/04/07 01:08:42 joerg Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
0, /* 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
* [value0...], which may either have a single mandatory value, at least
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);
}