1 /* $Id: tbl_opts.c,v 1.24 2018/12/14 05:18:03 schwarze Exp $ */
3 * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
29 #include "libmandoc.h"
34 #define KEY_LINESIZE 2
42 static const struct tbl_phrase keys[] = {
47 {"allbox", TBL_OPT_ALLBOX | TBL_OPT_BOX},
49 {"frame", TBL_OPT_BOX},
50 {"center", TBL_OPT_CENTRE},
51 {"centre", TBL_OPT_CENTRE},
52 {"doublebox", TBL_OPT_DBOX},
53 {"doubleframe", TBL_OPT_DBOX},
54 {"expand", TBL_OPT_EXPAND},
55 {"nokeep", TBL_OPT_NOKEEP},
56 {"nospaces", TBL_OPT_NOSPACE},
57 {"nowarn", TBL_OPT_NOWARN},
60 #define KEY_MAXKEYS ((int)(sizeof(keys)/sizeof(keys[0])))
62 static void arg(struct tbl_node *, int, const char *, int *, int);
66 arg(struct tbl_node *tbl, int ln, const char *p, int *pos, int key)
70 while (p[*pos] == ' ' || p[*pos] == '\t')
73 /* Arguments are enclosed in parentheses. */
78 while (p[*pos + len] != ')')
84 mandoc_msg(MANDOCERR_TBLOPT_EQN,
85 ln, *pos, "%.*s", len, p + *pos);
91 tbl->opts.tab = p[*pos];
99 tbl->opts.decimal = p[*pos];
106 mandoc_msg(MANDOCERR_TBLOPT_NOARG, ln, *pos,
107 "%s", keys[key].name);
108 else if (want && len != want)
109 mandoc_msg(MANDOCERR_TBLOPT_ARGSZ, ln, *pos,
110 "%s want %d have %d", keys[key].name, want, len);
118 * Parse one line of options up to the semicolon.
119 * Each option can be preceded by blanks and/or commas,
120 * and some options are followed by arguments.
123 tbl_option(struct tbl_node *tbl, int ln, const char *p, int *offs)
129 while (p[pos] == ' ' || p[pos] == '\t' || p[pos] == ',')
137 /* Parse one option name. */
140 while (isalpha((unsigned char)p[pos + len]))
144 mandoc_msg(MANDOCERR_TBLOPT_ALPHA,
145 ln, pos, "%c", p[pos]);
150 /* Look up the option name. */
153 while (i < KEY_MAXKEYS &&
154 (strncasecmp(p + pos, keys[i].name, len) ||
155 keys[i].name[len] != '\0'))
158 if (i == KEY_MAXKEYS) {
159 mandoc_msg(MANDOCERR_TBLOPT_BAD,
160 ln, pos, "%.*s", len, p + pos);
165 /* Handle the option. */
169 tbl->opts.opts |= keys[i].key;
171 arg(tbl, ln, p, &pos, i);