From: Kristaps Dzonsons Date: Thu, 5 Mar 2009 13:12:12 +0000 (+0000) Subject: Cleaned up ctype functions (netbsd). X-Git-Tag: VERSION_1_4_2~18 X-Git-Url: https://git.cameronkatri.com/mandoc.git/commitdiff_plain/74accf0fc23a61d1716812e017394125f5257020?ds=inline Cleaned up ctype functions (netbsd). Fixed .Ex/.Rv -std usage. Made Ar provide default value. --- diff --git a/Makefile b/Makefile index 84d51e65..ffdb6103 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,8 @@ FAIL = regress/test.empty \ regress/test.escape.11 \ regress/test.escape.12 \ regress/test.escape.14 \ - regress/test.argv.01 + regress/test.argv.01 \ + regress/test.argv.02 SUCCEED = regress/test.prologue.05 \ regress/test.prologue.07 \ @@ -162,7 +163,7 @@ installwww: www install -m 0444 mdocml-nport-$(VERSION).tar.gz $(PREFIX)/ports-netbsd/ install -m 0444 mdocml-nport-$(VERSION).tar.gz $(PREFIX)/ports-netbsd/mdocml.tar.gz -regress: mdoclint +regress: mdoclint $(FAIL) $(SUCCEED) @for f in $(FAIL); do \ echo "./mdoclint $$f" ; \ ./mdoclint $$f 2>/dev/null || continue ; exit 1 ; done diff --git a/action.c b/action.c index 1b4f157d..84a3ad8f 100644 --- a/action.c +++ b/action.c @@ -1,4 +1,4 @@ -/* $Id: action.c,v 1.29 2009/03/05 12:08:53 kristaps Exp $ */ +/* $Id: action.c,v 1.30 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -36,15 +36,16 @@ struct actions { /* Per-macro action routines. */ +static int post_ar(struct mdoc *); static int post_bl(struct mdoc *); static int post_bl_width(struct mdoc *); static int post_bl_tagwidth(struct mdoc *); static int post_dd(struct mdoc *); static int post_dt(struct mdoc *); -static int post_ex(struct mdoc *); static int post_nm(struct mdoc *); static int post_os(struct mdoc *); static int post_sh(struct mdoc *); +static int post_ex(struct mdoc *); static int post_prologue(struct mdoc *); @@ -67,7 +68,7 @@ const struct actions mdoc_actions[MDOC_MAX] = { { NULL }, /* It */ { NULL }, /* Ad */ { NULL }, /* An */ - { NULL }, /* Ar */ + { post_ar }, /* Ar */ { NULL }, /* Cd */ { NULL }, /* Cm */ { NULL }, /* Dv */ @@ -171,14 +172,10 @@ post_ex(struct mdoc *mdoc) if (0 == mdoc->last->data.elem.argc) return(1); - - assert(1 == mdoc->last->data.elem.argc); - if (1 == mdoc->last->data.elem.argv[0].sz) + if (mdoc->last->data.elem.argv[0].sz) return(1); - assert(0 == mdoc->last->data.elem.argv[0].sz); - if (NULL == mdoc->meta.name) - return(mdoc_err(mdoc, "default name not yet set")); + assert(mdoc->meta.name); mdoc_msg(mdoc, "writing %s argument: %s", mdoc_argnames[MDOC_Std], mdoc->meta.name); @@ -483,6 +480,29 @@ post_bl(struct mdoc *mdoc) } +static int +post_ar(struct mdoc *mdoc) +{ + struct mdoc_node *n; + + if (mdoc->last->child) + return(1); + + n = mdoc->last; + + mdoc->next = MDOC_NEXT_CHILD; + mdoc_word_alloc(mdoc, mdoc->last->line, + mdoc->last->pos, "file"); + mdoc->next = MDOC_NEXT_SIBLING; + mdoc_word_alloc(mdoc, mdoc->last->line, + mdoc->last->pos, "..."); + + mdoc->last = n; + mdoc->next = MDOC_NEXT_SIBLING; + return(1); +} + + static int post_dd(struct mdoc *mdoc) { diff --git a/argv.c b/argv.c index 261c6b64..3621c673 100644 --- a/argv.c +++ b/argv.c @@ -1,4 +1,4 @@ -/* $Id: argv.c,v 1.36 2009/03/05 12:08:53 kristaps Exp $ */ +/* $Id: argv.c,v 1.37 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -43,7 +43,7 @@ static int argv_a2arg(int, const char *); static int args(struct mdoc *, int, int *, char *, int, char **); -static int argv(struct mdoc *, int, +static int argv(struct mdoc *, int, int, struct mdoc_arg *, int *, char *); static int argv_single(struct mdoc *, int, struct mdoc_arg *, int *, char *); @@ -90,7 +90,7 @@ static int mdoc_argvflags[MDOC_ARG_MAX] = { ARGV_MULTI, /* MDOC_Column */ ARGV_SINGLE, /* MDOC_Width */ ARGV_NONE, /* MDOC_Compact */ - ARGV_OPT_SINGLE, /* MDOC_Std */ + ARGV_SINGLE, /* MDOC_Std */ ARGV_NONE, /* MDOC_p1003_1_88 */ ARGV_NONE, /* MDOC_p1003_1_90 */ ARGV_NONE, /* MDOC_p1003_1_96 */ @@ -389,10 +389,10 @@ args(struct mdoc *mdoc, int line, break; i++; /* There must be at least one space... */ - if (0 == buf[i] || ! isspace((int)buf[i])) + if (0 == buf[i] || ! isspace((u_char)buf[i])) break; i++; - while (buf[i] && isspace((int)buf[i])) + while (buf[i] && isspace((u_char)buf[i])) i++; } if (0 == buf[i]) { @@ -500,7 +500,7 @@ args(struct mdoc *mdoc, int line, if ( ! (ARGS_TABSEP & fl)) while (buf[*pos]) { - if (isspace((int)buf[*pos])) + if (isspace((u_char)buf[*pos])) if ('\\' != buf[*pos - 1]) break; (*pos)++; @@ -515,7 +515,7 @@ args(struct mdoc *mdoc, int line, return(ARGS_WORD); if ( ! (ARGS_TABSEP & fl)) - while (buf[*pos] && isspace((int)buf[*pos])) + while (buf[*pos] && isspace((u_char)buf[*pos])) (*pos)++; if (buf[*pos]) @@ -547,7 +547,7 @@ args(struct mdoc *mdoc, int line, if (0 == buf[*pos]) return(ARGS_QWORD); - while (buf[*pos] && isspace((int)buf[*pos])) + while (buf[*pos] && isspace((u_char)buf[*pos])) (*pos)++; if (buf[*pos]) @@ -823,14 +823,28 @@ argv_single(struct mdoc *mdoc, int line, * multiple parameters. */ static int -argv(struct mdoc *mdoc, int line, +argv(struct mdoc *mdoc, int tok, int line, struct mdoc_arg *v, int *pos, char *buf) { + int fl; v->sz = 0; v->value = NULL; + fl = mdoc_argvflags[v->arg]; - switch (mdoc_argvflags[v->arg]) { + /* + * Override the default per-argument value. + */ + + switch (tok) { + case (MDOC_Ex): + fl = ARGV_OPT_SINGLE; + break; + default: + break; + } + + switch (fl) { case (ARGV_SINGLE): return(argv_single(mdoc, line, v, pos, buf)); case (ARGV_MULTI): @@ -863,7 +877,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, if (0 == buf[*pos]) return(ARGV_EOLN); - assert( ! isspace((int)buf[*pos])); + assert( ! isspace((u_char)buf[*pos])); if ('-' != buf[*pos]) return(ARGV_WORD); @@ -878,7 +892,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, /* LINTED */ while (buf[*pos]) { - if (isspace((int)buf[*pos])) + if (isspace((u_char)buf[*pos])) if ('\\' != buf[*pos - 1]) break; (*pos)++; @@ -899,12 +913,12 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, return(ARGV_WORD); } - while (buf[*pos] && isspace((int)buf[*pos])) + while (buf[*pos] && isspace((u_char)buf[*pos])) (*pos)++; /* FIXME: whitespace if no value. */ - if ( ! argv(mdoc, line, v, pos, buf)) + if ( ! argv(mdoc, tok, line, v, pos, buf)) return(ARGV_ERROR); return(ARGV_ARG); diff --git a/mdoc.c b/mdoc.c index ca3f5752..58ad3874 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.50 2009/03/02 17:14:46 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.51 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -220,7 +220,8 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf) return(1); i = 1; - while (buf[i] && ! isspace((int)buf[i]) && i < (int)sizeof(tmp)) + while (buf[i] && ! isspace((u_char)buf[i]) && + i < (int)sizeof(tmp)) i++; if (i == (int)sizeof(tmp)) { @@ -241,7 +242,7 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf) return(mdoc_perr(mdoc, line, 1, "unknown macro")); } - while (buf[i] && isspace((int)buf[i])) + while (buf[i] && isspace((u_char)buf[i])) i++; if ( ! mdoc_macro(mdoc, c, line, 1, &i, buf)) { diff --git a/mdocterm.c b/mdocterm.c index c873c576..278d224e 100644 --- a/mdocterm.c +++ b/mdocterm.c @@ -1,4 +1,4 @@ -/* $Id: mdocterm.c,v 1.32 2009/03/04 14:41:40 kristaps Exp $ */ +/* $Id: mdocterm.c,v 1.33 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -287,7 +287,7 @@ flushln(struct termp *p) /* LINTED */ for (j = i, vsz = 0; j < p->col; j++) { - if (isspace((int)p->buf[j])) + if (isspace((u_char)p->buf[j])) break; else if (27 == p->buf[j]) { assert(j + 4 <= p->col); @@ -334,7 +334,7 @@ flushln(struct termp *p) */ for ( ; i < p->col; i++) { - if (isspace((int)p->buf[i])) + if (isspace((u_char)p->buf[i])) break; putchar(p->buf[i]); } @@ -437,13 +437,13 @@ word(struct termp *p, const char *word) /* LINTED */ for (j = i = 0; i < len; i++) { - if ( ! isspace((int)word[i])) { + if ( ! isspace((u_char)word[i])) { j++; continue; } /* Escaped spaces don't delimit... */ - if (i > 0 && isspace((int)word[i]) && + if (i > 0 && isspace((u_char)word[i]) && '\\' == word[i - 1]) { j++; continue; @@ -649,7 +649,7 @@ header(struct termp *p, const struct mdoc_meta *meta) meta->title, pp ? pp : ""); for (bufp = title; *bufp; bufp++) - *bufp = toupper(*bufp); + *bufp = toupper((u_char)*bufp); p->offset = 0; p->rmargin = (p->maxrmargin - strlen(buf)) / 2; diff --git a/strings.c b/strings.c index 6d07edea..050c584b 100644 --- a/strings.c +++ b/strings.c @@ -1,4 +1,4 @@ -/* $Id: strings.c,v 1.24 2009/03/02 17:14:46 kristaps Exp $ */ +/* $Id: strings.c,v 1.25 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -62,16 +62,16 @@ mdoc_isescape(const char *p) case ('e'): return(2); case ('*'): - if (0 == *++p || ! isgraph((int)*p)) + if (0 == *++p || ! isgraph((u_char)*p)) return(0); switch (*p) { case ('('): - if (0 == *++p || ! isgraph((int)*p)) + if (0 == *++p || ! isgraph((u_char)*p)) return(0); return(4); case ('['): for (c = 3, p++; *p && ']' != *p; p++, c++) - if ( ! isgraph((int)*p)) + if ( ! isgraph((u_char)*p)) break; return(*p == ']' ? c : 0); default: @@ -79,9 +79,9 @@ mdoc_isescape(const char *p) } return(3); case ('('): - if (0 == *++p || ! isgraph((int)*p)) + if (0 == *++p || ! isgraph((u_char)*p)) return(0); - if (0 == *++p || ! isgraph((int)*p)) + if (0 == *++p || ! isgraph((u_char)*p)) return(0); return(4); case ('['): @@ -91,7 +91,7 @@ mdoc_isescape(const char *p) } for (c = 3, p++; *p && ']' != *p; p++, c++) - if ( ! isgraph((int)*p)) + if ( ! isgraph((u_char)*p)) break; return(*p == ']' ? c : 0); @@ -195,9 +195,9 @@ mdoc_atotime(const char *p) (void)memset(&tm, 0, sizeof(struct tm)); - if (xstrcmp(p, "$Mdocdate: March 2 2009 $")) + if (xstrcmp(p, "$Mdocdate: March 5 2009 $")) return(time(NULL)); - if ((pp = strptime(p, "$Mdocdate: March 2 2009 $", &tm)) && 0 == *pp) + if ((pp = strptime(p, "$Mdocdate: March 5 2009 $", &tm)) && 0 == *pp) return(mktime(&tm)); /* XXX - this matches "June 1999", which is wrong. */ if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp) diff --git a/term.c b/term.c index 76fced1e..bc44fc61 100644 --- a/term.c +++ b/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.41 2009/03/04 14:41:40 kristaps Exp $ */ +/* $Id: term.c,v 1.42 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -295,7 +295,7 @@ arg_width(const struct mdoc_arg *arg) assert(len > 0); for (i = 0; i < len - 1; i++) - if ( ! isdigit((int)(*arg->value)[i])) + if ( ! isdigit((u_char)(*arg->value)[i])) break; if (i == len - 1) { @@ -693,10 +693,6 @@ termp_ar_pre(DECL_ARGS) { TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]); - if (NULL == node->child) { - word(p, "file"); - word(p, "..."); - } return(1); } diff --git a/validate.c b/validate.c index 267e324d..cc680737 100644 --- a/validate.c +++ b/validate.c @@ -1,4 +1,4 @@ -/* $Id: validate.c,v 1.67 2009/03/04 13:57:35 kristaps Exp $ */ +/* $Id: validate.c,v 1.68 2009/03/05 13:12:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -53,6 +53,9 @@ static int check_stdarg(PRE_ARGS); static int check_text(struct mdoc *, int, int, const char *); +static int check_argv(struct mdoc *, + const struct mdoc_node *, + const struct mdoc_arg *); static int err_child_lt(struct mdoc *, const char *, int); static int warn_child_lt(struct mdoc *, const char *, int); @@ -298,8 +301,6 @@ mdoc_valid_pre(struct mdoc *mdoc, node->data.elem.argc; for (i = 0; i < (int)argc; i++) { - if (0 == argv[i].sz) - continue; for (j = 0; j < (int)argv[i].sz; j++) { tp = argv[i].value[j]; line = argv[i].line; @@ -307,6 +308,8 @@ mdoc_valid_pre(struct mdoc *mdoc, if ( ! check_text(mdoc, line, pos, tp)) return(0); } + if ( ! check_argv(mdoc, node, &argv[i])) + return(0); } } @@ -476,6 +479,45 @@ check_msec(PRE_ARGS, int sz, enum mdoc_msec *msecs) } +/* + * Check over an argument. When this has more stuff in it, make this + * into a table-driven function; until then, a switch is fine. + */ +static int +check_argv(struct mdoc *mdoc, + const struct mdoc_node *node, + const struct mdoc_arg *argv) +{ + + + switch (argv->arg) { + case (MDOC_Std): + switch (node->tok) { + case (MDOC_Ex): + /* + * If the -std does not have an argument, then + * set it with the default name (if set). This + * only happens with MDOC_Ex. + */ + if (1 == argv->sz) + return(1); + assert(0 == argv->sz); + if (mdoc->meta.name) + return(1); + return(mdoc_nerr(mdoc, node, + "default name not yet set")); + default: + break; + } + break; + default: + break; + } + + return(1); +} + + static int check_text(struct mdoc *mdoc, int line, int pos, const char *p) { @@ -484,7 +526,7 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p) /* XXX - indicate deprecated escapes \*(xx and \*x. */ for ( ; *p; p++) { - if ( ! isprint((int)*p) && '\t' != *p) + if ( ! isprint((u_char)*p) && '\t' != *p) return(mdoc_perr(mdoc, line, pos, "invalid non-printing characters")); if ('\\' != *p)