]>
git.cameronkatri.com Git - mandoc.git/blob - tbl_opts.c
1 /* $Id: tbl_opts.c,v 1.22 2018/12/12 21:54:35 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_vmsg(MANDOCERR_TBLOPT_EQN
, tbl
->parse
,
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
,
107 tbl
->parse
, ln
, *pos
, keys
[key
].name
);
108 else if (want
&& len
!= want
)
109 mandoc_vmsg(MANDOCERR_TBLOPT_ARGSZ
,
110 tbl
->parse
, ln
, *pos
, "%s want %d have %d",
111 keys
[key
].name
, want
, len
);
119 * Parse one line of options up to the semicolon.
120 * Each option can be preceded by blanks and/or commas,
121 * and some options are followed by arguments.
124 tbl_option(struct tbl_node
*tbl
, int ln
, const char *p
, int *offs
)
130 while (p
[pos
] == ' ' || p
[pos
] == '\t' || p
[pos
] == ',')
138 /* Parse one option name. */
141 while (isalpha((unsigned char)p
[pos
+ len
]))
145 mandoc_vmsg(MANDOCERR_TBLOPT_ALPHA
,
146 tbl
->parse
, ln
, pos
, "%c", p
[pos
]);
151 /* Look up the option name. */
154 while (i
< KEY_MAXKEYS
&&
155 (strncasecmp(p
+ pos
, keys
[i
].name
, len
) ||
156 keys
[i
].name
[len
] != '\0'))
159 if (i
== KEY_MAXKEYS
) {
160 mandoc_vmsg(MANDOCERR_TBLOPT_BAD
, tbl
->parse
,
161 ln
, pos
, "%.*s", len
, p
+ pos
);
166 /* Handle the option. */
170 tbl
->opts
.opts
|= keys
[i
].key
;
172 arg(tbl
, ln
, p
, &pos
, i
);