diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-06-19 07:20:20 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-06-19 07:20:20 +0000 |
commit | e6973bd6646ce01967620c0ae2759a96cb5c509d (patch) | |
tree | 1ec39fd3b93cc7f1704890b63b7352fcaf09b7c6 /usr.bin | |
parent | f6bcb5489ed1cef30b0952eab011571043ee7444 (diff) |
sync to 1.7.19: more elegant section handling
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 13 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.h | 43 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_action.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_strings.c | 65 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 47 |
6 files changed, 82 insertions, 97 deletions
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index f9acd9eb29e..02abdc6cd48 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.6 2009/06/18 22:16:56 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.7 2009/06/19 07:20:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -29,8 +29,9 @@ struct mdoc { struct mdoc_cb cb; void *htab; int flags; -#define MDOC_HALT (1 << 0) -#define MDOC_LITERAL (1 << 1) +#define MDOC_HALT (1 << 0) /* Error in parse. Halt. */ +#define MDOC_LITERAL (1 << 1) /* In a literal scope. */ +#define MDOC_PBODY (1 << 2) /* In the document body. */ int pflags; enum mdoc_next next; struct mdoc_node *last; diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 8d8adf023aa..cb2034d7c50 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.8 2009/06/18 23:51:12 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.9 2009/06/19 07:20:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -144,7 +144,7 @@ mdoc_alloc1(struct mdoc *mdoc) bzero(&mdoc->meta, sizeof(struct mdoc_meta)); mdoc->flags = 0; - mdoc->lastnamed = mdoc->lastsec = 0; + mdoc->lastnamed = mdoc->lastsec = SEC_NONE; mdoc->last = calloc(1, sizeof(struct mdoc_node)); if (NULL == mdoc->last) return(0); @@ -371,14 +371,11 @@ mdoc_macro(struct mdoc *m, int tok, int ln, int pp, int *pos, char *buf) { - /* FIXME - these should happen during validation. */ - if (MDOC_PROLOGUE & mdoc_macros[tok].flags && - SEC_PROLOGUE != m->lastnamed) + MDOC_PBODY & m->flags) return(perr(m, ln, pp, EPROLBODY)); - if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && - SEC_PROLOGUE == m->lastnamed) + ! (MDOC_PBODY & m->flags)) return(perr(m, ln, pp, EBODYPROL)); if (1 != pp && ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) @@ -629,7 +626,7 @@ static int parsetext(struct mdoc *m, int line, char *buf) { - if (SEC_PROLOGUE == m->lastnamed) + if (SEC_NONE == m->lastnamed) return(perr(m, line, 0, ETEXTPROL)); if (0 == buf[0] && ! (MDOC_LITERAL & m->flags)) diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index f138c9ec21b..4e7b6831dac 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.4 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: mdoc.h,v 1.5 2009/06/19 07:20:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -198,27 +198,26 @@ enum mdoc_type { /* Section (named/unnamed) of `Sh'. */ enum mdoc_sec { - SEC_PROLOGUE = 0, - SEC_BODY = 1, - SEC_NAME = 2, - SEC_LIBRARY = 3, - SEC_SYNOPSIS = 4, - SEC_DESCRIPTION = 5, - SEC_IMPLEMENTATION = 6, - SEC_RETURN_VALUES = 7, - SEC_ENVIRONMENT = 8, - SEC_FILES = 9, - SEC_EXAMPLES = 10, - SEC_DIAGNOSTICS = 11, - SEC_COMPATIBILITY = 12, - SEC_ERRORS = 13, - SEC_SEE_ALSO = 14, - SEC_STANDARDS = 15, - SEC_HISTORY = 16, - SEC_AUTHORS = 17, - SEC_CAVEATS = 18, - SEC_BUGS = 19, - SEC_CUSTOM + SEC_NONE, /* No section, yet. */ + SEC_NAME, + SEC_LIBRARY, + SEC_SYNOPSIS, + SEC_DESCRIPTION, + SEC_IMPLEMENTATION, + SEC_RETURN_VALUES, + SEC_ENVIRONMENT, + SEC_FILES, + SEC_EXAMPLES, + SEC_DIAGNOSTICS, + SEC_COMPATIBILITY, + SEC_ERRORS, + SEC_SEE_ALSO, + SEC_STANDARDS, + SEC_HISTORY, + SEC_AUTHORS, + SEC_CAVEATS, + SEC_BUGS, + SEC_CUSTOM /* User-defined. */ }; /* Information from prologue. */ diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c index 3e5a7d0ae56..8d94b37efd9 100644 --- a/usr.bin/mandoc/mdoc_action.c +++ b/usr.bin/mandoc/mdoc_action.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.4 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: mdoc_action.c,v 1.5 2009/06/19 07:20:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -510,8 +510,8 @@ post_os(POST_ARGS) if (NULL == (m->meta.os = strdup(buf))) return(verr(m, EMALLOC)); - m->lastnamed = m->lastsec = SEC_BODY; + m->flags |= MDOC_PBODY; return(post_prol(m)); } diff --git a/usr.bin/mandoc/mdoc_strings.c b/usr.bin/mandoc/mdoc_strings.c index 930e48a1831..0c9ffc60b7b 100644 --- a/usr.bin/mandoc/mdoc_strings.c +++ b/usr.bin/mandoc/mdoc_strings.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_strings.c,v 1.5 2009/06/18 01:19:02 schwarze Exp $ */ +/* $Id: mdoc_strings.c,v 1.6 2009/06/19 07:20:19 schwarze Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> * @@ -24,41 +24,34 @@ #include "libmdoc.h" -/* - * Various string-literal operations: converting scalars to and from - * strings, etc. - */ +/* FIXME: this file is poorly named. */ struct mdoc_secname { - const char *name; - int flag; -#define MSECNAME_META (1 << 0) + const char *name; /* Name of section. */ + enum mdoc_sec sec; /* Corresponding section. */ }; -/* Section names corresponding to mdoc_sec. */ +#define SECNAME_MAX (18) -static const struct mdoc_secname secnames[] = { - { "PROLOGUE", MSECNAME_META }, - { "BODY", MSECNAME_META }, - { "NAME", 0 }, - { "LIBRARY", 0 }, - { "SYNOPSIS", 0 }, - { "DESCRIPTION", 0 }, - { "IMPLEMENTATION NOTES", 0 }, - { "RETURN VALUES", 0 }, - { "ENVIRONMENT", 0 }, - { "FILES", 0 }, - { "EXAMPLES", 0 }, - { "DIAGNOSTICS", 0 }, - { "COMPATIBILITY", 0 }, - { "ERRORS", 0 }, - { "SEE ALSO", 0 }, - { "STANDARDS", 0 }, - { "HISTORY", 0 }, - { "AUTHORS", 0 }, - { "CAVEATS", 0 }, - { "BUGS", 0 }, - { NULL, 0 } +static const struct mdoc_secname secnames[SECNAME_MAX] = { + { "NAME", SEC_NAME }, + { "LIBRARY", SEC_LIBRARY }, + { "SYNOPSIS", SEC_SYNOPSIS }, + { "DESCRIPTION", SEC_DESCRIPTION }, + { "IMPLEMENTATION NOTES", SEC_IMPLEMENTATION }, + { "RETURN VALUES", SEC_RETURN_VALUES }, + { "ENVIRONMENT", SEC_ENVIRONMENT }, + { "FILES", SEC_FILES }, + { "EXAMPLES", SEC_EXAMPLES }, + { "DIAGNOSTICS", SEC_DIAGNOSTICS }, + { "COMPATIBILITY", SEC_COMPATIBILITY }, + { "ERRORS", SEC_ERRORS }, + { "SEE ALSO", SEC_SEE_ALSO }, + { "STANDARDS", SEC_STANDARDS }, + { "HISTORY", SEC_HISTORY }, + { "AUTHORS", SEC_AUTHORS }, + { "CAVEATS", SEC_CAVEATS }, + { "BUGS", SEC_BUGS }, }; @@ -192,13 +185,11 @@ mdoc_isdelim(const char *p) enum mdoc_sec mdoc_atosec(const char *p) { - const struct mdoc_secname *n; - int i; + int i; - for (i = 0, n = secnames; n->name; n++, i++) - if ( ! (n->flag & MSECNAME_META)) - if (0 == strcmp(p, n->name)) - return((enum mdoc_sec)i); + for (i = 0; i < SECNAME_MAX; i++) + if (0 == strcmp(p, secnames[i].name)) + return(secnames[i].sec); return(SEC_CUSTOM); } diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index c4447ec44ab..4cf3c36b977 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.8 2009/06/19 00:07:06 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.9 2009/06/19 07:20:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -42,6 +42,7 @@ enum merr { ELISTTYPE, EDISPTYPE, EMULTIDISP, + ESECNAME, EMULTILIST, EARGREP, EBOOL, @@ -116,7 +117,6 @@ static int pre_fd(PRE_ARGS); static int pre_it(PRE_ARGS); static int pre_lb(PRE_ARGS); static int pre_os(PRE_ARGS); -static int pre_prologue(PRE_ARGS); static int pre_rv(PRE_ARGS); static int pre_sh(PRE_ARGS); static int pre_ss(PRE_ARGS); @@ -155,15 +155,15 @@ static v_pre pres_an[] = { pre_an, NULL }; static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; static v_pre pres_bl[] = { pre_bl, NULL }; static v_pre pres_cd[] = { pre_cd, NULL }; -static v_pre pres_dd[] = { pre_prologue, pre_dd, NULL }; +static v_pre pres_dd[] = { pre_dd, NULL }; static v_pre pres_d1[] = { pre_display, NULL }; -static v_pre pres_dt[] = { pre_prologue, pre_dt, NULL }; +static v_pre pres_dt[] = { pre_dt, NULL }; static v_pre pres_er[] = { pre_er, NULL }; static v_pre pres_ex[] = { pre_ex, NULL }; static v_pre pres_fd[] = { pre_fd, NULL }; static v_pre pres_it[] = { pre_it, NULL }; static v_pre pres_lb[] = { pre_lb, NULL }; -static v_pre pres_os[] = { pre_prologue, pre_os, NULL }; +static v_pre pres_os[] = { pre_os, NULL }; static v_pre pres_rv[] = { pre_rv, NULL }; static v_pre pres_sh[] = { pre_sh, NULL }; static v_pre pres_ss[] = { pre_ss, NULL }; @@ -408,6 +408,9 @@ perr(struct mdoc *m, int line, int pos, enum merr type) case (EDISPTYPE): p = "missing display type"; break; + case (ESECNAME): + p = "the NAME section must come first"; + break; case (ELINE): p = "expected line arguments"; break; @@ -1014,14 +1017,6 @@ pre_cd(PRE_ARGS) static int -pre_prologue(PRE_ARGS) -{ - - return(check_sec(mdoc, n, SEC_PROLOGUE, SEC_CUSTOM)); -} - - -static int pre_dt(PRE_ARGS) { @@ -1308,7 +1303,7 @@ post_root(POST_ARGS) if (NULL == mdoc->first->child) return(verr(mdoc, ENODATA)); - if (SEC_PROLOGUE == mdoc->lastnamed) + if ( ! (MDOC_PBODY & mdoc->flags)) return(verr(mdoc, ENOPROLOGUE)); if (MDOC_BLOCK != mdoc->first->child->type) @@ -1389,13 +1384,12 @@ post_sh_head(POST_ARGS) * certain manual sections. */ - assert(MDOC_Sh == mdoc->last->tok); - - /* This is just concat() inlined, which is irritating. */ - buf[0] = 0; + for (n = mdoc->last->child; n; n = n->next) { + /* XXX - copied from compact(). */ assert(MDOC_TEXT == n->type); + if (strlcat(buf, n->string, 64) >= 64) return(nerr(mdoc, n, ETOOLONG)); if (NULL == n->next) @@ -1406,21 +1400,24 @@ post_sh_head(POST_ARGS) sec = mdoc_atosec(buf); - /* The NAME section should always be first. */ + /* + * Check: NAME should always be first, CUSTOM has no roles, + * non-CUSTOM has a conventional order to be followed. + */ - if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec) - return(vwarn(mdoc, WSECOOO)); + if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed) + return(verr(mdoc, ESECNAME)); if (SEC_CUSTOM == sec) return(1); - - /* Check for repeated or out-of-order sections. */ - if (sec == mdoc->lastnamed) return(vwarn(mdoc, WSECREP)); if (sec < mdoc->lastnamed) return(vwarn(mdoc, WSECOOO)); - /* Check particular section/manual section conventions. */ + /* + * Check particular section/manual conventions. LIBRARY can + * only occur in msec 2, 3 (TODO: are there more of these?). + */ switch (sec) { case (SEC_LIBRARY): |