=================================================================== RCS file: /cvs/mandoc/tbl_opts.c,v retrieving revision 1.7 retrieving revision 1.16 diff -u -p -r1.7 -r1.16 --- mandoc/tbl_opts.c 2011/01/07 13:20:58 1.7 +++ mandoc/tbl_opts.c 2015/01/14 22:44:55 1.16 @@ -1,6 +1,6 @@ -/* $Id: tbl_opts.c,v 1.7 2011/01/07 13:20:58 kristaps Exp $ */ +/* $Id: tbl_opts.c,v 1.16 2015/01/14 22:44:55 schwarze Exp $ */ /* - * Copyright (c) 2009, 2010 Kristaps Dzonsons + * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -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. */ +#include "config.h" + +#include + #include #include #include #include #include "mandoc.h" +#include "libmandoc.h" #include "libroff.h" enum tbl_ident { @@ -57,10 +62,10 @@ struct tbl_phrase { static const struct tbl_phrase keys[KEY_MAXKEYS] = { { "center", TBL_OPT_CENTRE, KEY_CENTRE}, { "centre", TBL_OPT_CENTRE, KEY_CENTRE}, - { "delim", 0, KEY_DELIM}, + { "delim", 0, KEY_DELIM}, { "expand", TBL_OPT_EXPAND, KEY_EXPAND}, - { "box", TBL_OPT_BOX, KEY_BOX}, - { "doublebox", TBL_OPT_DBOX, KEY_DBOX}, + { "box", TBL_OPT_BOX, KEY_BOX}, + { "doublebox", TBL_OPT_DBOX, KEY_DBOX}, { "allbox", TBL_OPT_ALLBOX, KEY_ALLBOX}, { "frame", TBL_OPT_BOX, KEY_FRAME}, { "doubleframe", TBL_OPT_DBOX, KEY_DFRAME}, @@ -71,11 +76,12 @@ static const struct tbl_phrase keys[KEY_MAXKEYS] = { { "nospaces", TBL_OPT_NOSPACE, KEY_NOSPACE}, }; -static int arg(struct tbl_node *, int, +static int arg(struct tbl_node *, int, const char *, int *, enum tbl_ident); -static void opt(struct tbl_node *, int, +static void opt(struct tbl_node *, int, const char *, int *); + static int arg(struct tbl_node *tbl, int ln, const char *p, int *pos, enum tbl_ident key) { @@ -88,7 +94,8 @@ arg(struct tbl_node *tbl, int ln, const char *p, int * /* 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); } @@ -101,24 +108,27 @@ arg(struct tbl_node *tbl, int ln, const char *p, int * */ switch (key) { - case (KEY_DELIM): + case KEY_DELIM: if ('\0' == p[(*pos)++]) { - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos - 1, NULL); return(0); - } + } if ('\0' == p[(*pos)++]) { - TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1); + mandoc_msg(MANDOCERR_TBL, tbl->parse, + ln, *pos - 1, NULL); return(0); - } + } break; - case (KEY_TAB): + case KEY_TAB: 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): + case KEY_LINESIZE: for (i = 0; i < KEY_MAXNUMSZ && p[*pos]; i++, (*pos)++) { buf[i] = p[*pos]; if ( ! isdigit((unsigned char)buf[i])) @@ -131,13 +141,14 @@ arg(struct tbl_node *tbl, int ln, const char *p, int * break; } - (*tbl->msg)(MANDOCERR_TBL, tbl->data, ln, *pos, NULL); + mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos, NULL); return(0); - case (KEY_DPOINT): + case KEY_DPOINT: 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(); @@ -149,7 +160,7 @@ arg(struct tbl_node *tbl, int ln, const char *p, int * 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); } @@ -171,8 +182,8 @@ again: /* * * options ::= option_list [:space:]* [;][\n] * option_list ::= option option_tail - * option_tail ::= [:space:]+ option_list | - * ::= epsilon + * option_tail ::= [,:space:]+ option_list | + * ::= epsilon * option ::= [:alpha:]+ args * args ::= [:space:]* [(] [:alpha:]+ [)] */ @@ -188,7 +199,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; } @@ -196,16 +207,16 @@ 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; } buf[i] = '\0'; - while (isspace((unsigned char)p[*pos])) + while (isspace((unsigned char)p[*pos]) || p[*pos] == ',') (*pos)++; - /* + /* * Look through all of the available keys to find one that * matches the input. FIXME: hashtable this. */ @@ -221,7 +232,7 @@ again: /* * of the sequence altogether. */ - if (keys[i].key) + if (keys[i].key) tbl->opts.opts |= keys[i].key; else if ( ! arg(tbl, ln, p, pos, keys[i].ident)) return; @@ -229,19 +240,19 @@ again: /* break; } - /* + /* * Allow us to recover from bad options by continuing to another * parse sequence. */ if (KEY_MAXKEYS == i) - TBL_MSG(tbl, MANDOCERR_TBLOPT, ln, sv); + mandoc_msg(MANDOCERR_TBLOPT, tbl->parse, ln, sv, NULL); goto again; /* NOTREACHED */ } -int +void tbl_option(struct tbl_node *tbl, int ln, const char *p) { int pos; @@ -254,7 +265,4 @@ tbl_option(struct tbl_node *tbl, int ln, const char *p pos = 0; opt(tbl, ln, p, &pos); - - /* Always succeed. */ - return(1); }