=================================================================== RCS file: /cvs/mandoc/tbl_opts.c,v retrieving revision 1.4 retrieving revision 1.11 diff -u -p -r1.4 -r1.11 --- mandoc/tbl_opts.c 2010/12/29 14:38:14 1.4 +++ mandoc/tbl_opts.c 2011/04/04 23:04:38 1.11 @@ -1,4 +1,4 @@ -/* $Id: tbl_opts.c,v 1.4 2010/12/29 14:38:14 kristaps Exp $ */ +/* $Id: tbl_opts.c,v 1.11 2011/04/04 23:04:38 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -14,12 +14,17 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include #include #include "mandoc.h" +#include "libmandoc.h" #include "libroff.h" enum tbl_ident { @@ -71,11 +76,13 @@ static const struct tbl_phrase keys[KEY_MAXKEYS] = { { "nospaces", TBL_OPT_NOSPACE, KEY_NOSPACE}, }; -static int arg(struct tbl *, int, const char *, int *, int); -static void opt(struct tbl *, int, const char *, int *); +static int arg(struct tbl_node *, int, + const char *, int *, enum tbl_ident); +static void opt(struct tbl_node *, int, + const char *, int *); static int -arg(struct tbl *tbl, int ln, const char *p, int *pos, int key) +arg(struct tbl_node *tbl, int ln, const char *p, int *pos, enum tbl_ident key) { int i; char buf[KEY_MAXNUMSZ]; @@ -86,7 +93,8 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, /* Arguments always begin with a parenthesis. */ if ('(' != p[*pos]) { - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos); + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos, NULL); return(0); } @@ -100,21 +108,24 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, switch (key) { case (KEY_DELIM): - if ('\0' == (tbl->delims[0] = p[(*pos)++])) { - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + if ('\0' == p[(*pos)++]) { + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos - 1, NULL); return(0); } - if ('\0' == (tbl->delims[1] = p[(*pos)++])) { - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + if ('\0' == p[(*pos)++]) { + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos - 1, NULL); return(0); } break; case (KEY_TAB): - if ('\0' != (tbl->tab = p[(*pos)++])) + if ('\0' != (tbl->opts.tab = p[(*pos)++])) break; - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos - 1, NULL); return(0); case (KEY_LINESIZE): for (i = 0; i < KEY_MAXNUMSZ && p[*pos]; i++, (*pos)++) { @@ -125,17 +136,18 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, if (i < KEY_MAXNUMSZ) { buf[i] = '\0'; - tbl->linesize = atoi(buf); + tbl->opts.linesize = atoi(buf); break; } - (*tbl->msg)(MANDOCERR_TBL, tbl->data, ln, *pos, NULL); + mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos, NULL); return(0); case (KEY_DPOINT): - if ('\0' != (tbl->decimal = p[(*pos)++])) + if ('\0' != (tbl->opts.decimal = p[(*pos)++])) break; - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos - 1, NULL); return(0); default: abort(); @@ -147,12 +159,12 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, if (')' == p[(*pos)++]) return(1); - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos - 1, NULL); return(0); } static void -opt(struct tbl *tbl, int ln, const char *p, int *pos) +opt(struct tbl_node *tbl, int ln, const char *p, int *pos) { int i, sv; char buf[KEY_MAXNAME]; @@ -186,7 +198,7 @@ again: /* /* Copy up to first non-alpha character. */ for (sv = *pos, i = 0; i < KEY_MAXNAME; i++, (*pos)++) { - buf[i] = tolower(p[*pos]); + buf[i] = (char)tolower((unsigned char)p[*pos]); if ( ! isalpha((unsigned char)buf[i])) break; } @@ -194,7 +206,7 @@ again: /* /* Exit if buffer is empty (or overrun). */ if (KEY_MAXNAME == i || 0 == i) { - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos); + mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos, NULL); return; } @@ -220,7 +232,7 @@ again: /* */ if (keys[i].key) - tbl->opts |= keys[i].key; + tbl->opts.opts |= keys[i].key; else if ( ! arg(tbl, ln, p, pos, keys[i].ident)) return; @@ -233,14 +245,14 @@ again: /* */ if (KEY_MAXKEYS == i) - TBL_MSG(tbl, MANDOCERR_TBLOPT, ln, sv); + mandoc_msg(MANDOCERR_TBLOPT, tbl->parse, ln, sv, NULL); goto again; /* NOTREACHED */ } int -tbl_option(struct tbl *tbl, int ln, const char *p) +tbl_option(struct tbl_node *tbl, int ln, const char *p) { int pos;