diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-03-06 14:13:47 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-03-06 14:13:47 +0000 |
commit | bc942b21e65675353944cc575b047c6a80080195 (patch) | |
tree | 1b072ecd73ada8d8dda604f7c050fe83b272dabd | |
parent | c0584f0a6b55bd89fdb730f06598436ff3b2c184 (diff) | |
download | mandoc-bc942b21e65675353944cc575b047c6a80080195.tar.gz |
Strings abstracted into dynamically-created C files.
Added -V option.
Deprecated README files.
-rw-r--r-- | Makefile | 77 | ||||
-rw-r--r-- | README.addescape | 17 | ||||
-rw-r--r-- | README.addmacro | 21 | ||||
-rw-r--r-- | README.addregress | 7 | ||||
-rw-r--r-- | action.c | 202 | ||||
-rw-r--r-- | arch.in | 26 | ||||
-rw-r--r-- | argv.c | 121 | ||||
-rw-r--r-- | att.in | 13 | ||||
-rw-r--r-- | lib.in | 32 | ||||
-rw-r--r-- | macro.c | 71 | ||||
-rw-r--r-- | mdoc.c | 68 | ||||
-rw-r--r-- | mdoc.h | 192 | ||||
-rw-r--r-- | mdoclint.c | 6 | ||||
-rw-r--r-- | mdocterm.1 | 2 | ||||
-rw-r--r-- | mdocterm.c | 76 | ||||
-rw-r--r-- | mdoctree.c | 8 | ||||
-rw-r--r-- | mmain.c | 11 | ||||
-rw-r--r-- | msec.in | 16 | ||||
-rw-r--r-- | private.h | 9 | ||||
-rw-r--r-- | regress/test.prologue.13 | 2 | ||||
-rw-r--r-- | st.in | 37 | ||||
-rw-r--r-- | strings.c | 615 | ||||
-rw-r--r-- | strings.sh | 83 | ||||
-rw-r--r-- | term.c | 36 | ||||
-rw-r--r-- | validate.c | 296 | ||||
-rw-r--r-- | vol.in | 12 | ||||
-rw-r--r-- | xstd.c | 2 |
27 files changed, 779 insertions, 1279 deletions
@@ -1,7 +1,7 @@ .SUFFIXES: .html .sgml -VERSION = 1.3.18 -VDATE = 04 March 2009 +VERSION = 1.3.19 +VDATE = 05 March 2009 BINDIR = $(PREFIX)/bin INCLUDEDIR = $(PREFIX)/include @@ -14,9 +14,11 @@ INSTALL_LIB = install -m 0644 INSTALL_MAN = $(INSTALL_DATA) CFLAGS += -W -Wall -Wstrict-prototypes -Wno-unused-parameter -g +CFLAGS += -DVERSION=\"$(VERSION)\" LIBLNS = macro.ln mdoc.ln hash.ln strings.ln xstd.ln argv.ln \ - validate.ln action.ln + validate.ln action.ln lib.ln att.ln arch.ln vol.ln \ + msec.ln st.ln TREELNS = mdoctree.ln mmain.ln @@ -31,7 +33,8 @@ LLNS = llib-llibmdoc.ln llib-lmdoctree.ln llib-lmdocterm.ln LIBS = libmdoc.a LIBOBJS = macro.o mdoc.o hash.o strings.o xstd.o argv.o \ - validate.o action.o + validate.o action.o lib.o att.o arch.o vol.o msec.o \ + st.o TERMOBJS= mdocterm.o mmain.o term.o @@ -39,11 +42,15 @@ TREEOBJS= mdoctree.o mmain.o LINTOBJS= mdoclint.o mmain.o -OBJS = $(LIBOBJS) $(TERMOBJS) $(TREEOBJS) +OBJS = $(LIBOBJS) $(TERMOBJS) $(TREEOBJS) $(LINTOBJS) SRCS = macro.c mdoc.c hash.c strings.c xstd.c argv.c validate.c \ action.c term.c mdoctree.c mdocterm.c mmain.c mdoclint.c +SCRIPTS = strings.sh + +GEN = lib.c att.c arch.c vol.c msec.c st.c + HEADS = mdoc.h private.h term.h mmain.h SGMLS = index.sgml @@ -60,10 +67,10 @@ MANS = mdoctree.1 mdocterm.1 mdoclint.1 mdoc.3 BINS = mdocterm mdoctree mdoclint CLEAN = $(BINS) $(LNS) $(LLNS) $(LIBS) $(OBJS) $(HTMLS) \ - $(TARGZS) + $(TARGZS) $(GEN) INSTALL = $(SRCS) $(HEADS) Makefile DESCR $(MANS) $(SGMLS) \ - $(STATICS) Makefile.netbsd Makefile.openbsd + $(STATICS) $(SCRIPTS) Makefile.netbsd Makefile.openbsd FAIL = regress/test.empty \ regress/test.prologue.00 \ @@ -72,24 +79,14 @@ FAIL = regress/test.empty \ regress/test.prologue.03 \ regress/test.prologue.04 \ regress/test.prologue.06 \ - regress/test.prologue.13 \ - regress/test.prologue.15 \ - regress/test.prologue.16 \ - regress/test.prologue.18 \ regress/test.prologue.19 \ - regress/test.prologue.21 \ - regress/test.prologue.22 \ regress/test.prologue.23 \ regress/test.prologue.24 \ - regress/test.prologue.25 \ - regress/test.prologue.26 \ regress/test.prologue.27 \ regress/test.prologue.28 \ - regress/test.prologue.29 \ regress/test.prologue.30 \ regress/test.prologue.31 \ regress/test.prologue.32 \ - regress/test.prologue.33 \ regress/test.sh.03 \ regress/test.escape.01 \ regress/test.escape.02 \ @@ -112,9 +109,19 @@ SUCCEED = regress/test.prologue.05 \ regress/test.prologue.10 \ regress/test.prologue.11 \ regress/test.prologue.12 \ + regress/test.prologue.13 \ regress/test.prologue.14 \ + regress/test.prologue.15 \ + regress/test.prologue.16 \ regress/test.prologue.17 \ + regress/test.prologue.18 \ regress/test.prologue.20 \ + regress/test.prologue.21 \ + regress/test.prologue.22 \ + regress/test.prologue.25 \ + regress/test.prologue.26 \ + regress/test.prologue.29 \ + regress/test.prologue.33 \ regress/test.sh.00 \ regress/test.name.00 \ regress/test.name.01 \ @@ -198,6 +205,42 @@ uninstall: rm -f $(LIBDIR)/libmdoc.a rm -f $(INCLUDEDIR)/mdoc.h +lib.ln: lib.c private.h +lib.o: lib.c private.h + +att.ln: att.c private.h +att.o: att.c private.h + +arch.ln: arch.c private.h +arch.o: arch.c private.h + +vol.ln: vol.c private.h +vol.o: vol.c private.h + +msec.ln: msec.c private.h +msec.o: msec.c private.h + +st.ln: st.c private.h +st.o: st.c private.h + +lib.c: lib.in strings.sh + sh strings.sh -o $@ lib lib.in + +st.c: st.in strings.sh + sh strings.sh -o $@ st st.in + +msec.c: msec.in strings.sh + sh strings.sh -o $@ msec msec.in + +att.c: att.in strings.sh + sh strings.sh -o $@ att att.in + +arch.c: arch.in strings.sh + sh strings.sh -o $@ arch arch.in + +vol.c: vol.in strings.sh + sh strings.sh -o $@ vol vol.in + macro.ln: macro.c private.h macro.o: macro.c private.h diff --git a/README.addescape b/README.addescape deleted file mode 100644 index 93231406..00000000 --- a/README.addescape +++ /dev/null @@ -1,17 +0,0 @@ -$Id$ - -This documents adding a new character escape to mdocterm(1). Character -escapes are only syntax-validated in the back-end. - -Character escape may be in the form of \*x, \*(xx, \x, \(xx, \[n] and so -on and so on. All of these are recognised according to their byte -length. - -(1) If the escape is NOT recognised in enum tsym in term.h, add it. - -(2) Modify/create static struct termenc termencN, where N is the number -of characters in the encoding. This is in mdocterm.c. - -(3) Possibly modify nescape() to recognise a new termencN. - -Everything else is automatic. diff --git a/README.addmacro b/README.addmacro deleted file mode 100644 index f60fe98e..00000000 --- a/README.addmacro +++ /dev/null @@ -1,21 +0,0 @@ -$Id$ - -This documents how to go about adding a macro to mdoc.3. - -(1) Add the macro to the #define list in mdoc.h. -(2) Add the macro to __mdoc_macronames in mdoc.c. -(3) Add the macro to __mdoc_macros in mdoc.c. -(4) Add the macro to mdoc_valids in validate.c. -(5) Add the macro to mdoc_actions in action.c. -(6) Add the macro to mdoc_argflags in argv.c. -(7) Modify the hash routine in hash.c (may not be required). - -If the macro has arguments: - -(1) Add arguments to the #define list in mdoc.h. -(2) Add the arguments to __mdoc_argnames in mdoc.c. -(3) Modify parts of argv.c (lookup() and mdoc_args()). - -You'll certainly want to change the front-ends: - -(1) Add the macro to __termacts in term.c. diff --git a/README.addregress b/README.addregress deleted file mode 100644 index 03474041..00000000 --- a/README.addregress +++ /dev/null @@ -1,7 +0,0 @@ -$Id$ - -To add regression tests, name the file according as -regress/test.NAME.NN, where NAME approximately documents the test domain -and NN is a two-digit, zero-padded number for the test index. - -Subsequent that, add the test to either FAIL or SUCCEED in the Makefile. @@ -16,7 +16,10 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/utsname.h> + #include <assert.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -158,6 +161,7 @@ const struct actions mdoc_actions[MDOC_MAX] = { { NULL }, /* Hf */ { NULL }, /* Fr */ { NULL }, /* Ud */ + { NULL }, /* Lb */ }; @@ -192,24 +196,14 @@ post_nm(struct mdoc *mdoc) { char buf[64]; - assert(MDOC_ELEM == mdoc->last->type); - assert(MDOC_Nm == mdoc->last->tok); - - /* - * The `Nm' macro sets the document's name when used the first - * time with an argument. Subsequent calls without a value will - * result in the name value being used. - */ - if (mdoc->meta.name) return(1); - if (xstrlcats(buf, mdoc->last->child, 64)) { - mdoc->meta.name = xstrdup(buf); - return(1); - } + (void)xstrlcpys(buf, mdoc->last->child, sizeof(buf)); + mdoc->meta.name = xstrdup(buf); + mdoc_msg(mdoc, "name: %s", mdoc->meta.name); - return(mdoc_err(mdoc, "macro parameters too long")); + return(1); } @@ -227,23 +221,23 @@ post_sh(struct mdoc *mdoc) if (MDOC_HEAD != mdoc->last->type) return(1); - if (xstrlcats(buf, mdoc->last->child, 64)) { - if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) - mdoc->lastnamed = sec; - mdoc->lastsec = sec; - } else - return(mdoc_err(mdoc, "parameters too long")); + + (void)xstrlcpys(buf, mdoc->last->child, sizeof(buf)); + if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) + mdoc->lastnamed = sec; + + mdoc->lastsec = sec; switch (mdoc->lastsec) { case (SEC_RETURN_VALUES): /* FALLTHROUGH */ case (SEC_ERRORS): switch (mdoc->meta.msec) { - case (MSEC_2): + case (2): /* FALLTHROUGH */ - case (MSEC_3): + case (3): /* FALLTHROUGH */ - case (MSEC_9): + case (9): break; default: return(mdoc_warn(mdoc, WARN_COMPAT, @@ -261,53 +255,99 @@ post_sh(struct mdoc *mdoc) static int post_dt(struct mdoc *mdoc) { - int i; - char *p; struct mdoc_node *n; + const char *cp; + char *ep; + long lval; + + if (mdoc->meta.title) + free(mdoc->meta.title); + if (mdoc->meta.vol) + free(mdoc->meta.vol); + if (mdoc->meta.arch) + free(mdoc->meta.arch); + + mdoc->meta.title = mdoc->meta.vol = mdoc->meta.arch = NULL; + mdoc->meta.msec = 0; + + /* Handles: `.Dt' + * --> title = unknown, volume = local, msec = 0, arch = NULL + */ - /* - * Prologue title must be parsed into document meta-data. + if (NULL == (n = mdoc->last->child)) { + mdoc->meta.title = xstrdup("unknown"); + mdoc->meta.vol = xstrdup("local"); + mdoc_msg(mdoc, "title: %s", mdoc->meta.title); + mdoc_msg(mdoc, "volume: %s", mdoc->meta.vol); + mdoc_msg(mdoc, "arch: <unset>"); + mdoc_msg(mdoc, "msec: <unset>"); + return(post_prologue(mdoc)); + } + + /* Handles: `.Dt TITLE' + * --> title = TITLE, volume = local, msec = 0, arch = NULL */ - assert(MDOC_ELEM == mdoc->last->type); - assert(MDOC_Dt == mdoc->last->tok); + mdoc->meta.title = xstrdup(n->data.text.string); + mdoc_msg(mdoc, "title: %s", mdoc->meta.title); - assert(NULL == mdoc->meta.title); + if (NULL == (n = n->next)) { + mdoc->meta.vol = xstrdup("local"); + mdoc_msg(mdoc, "volume: %s", mdoc->meta.vol); + mdoc_msg(mdoc, "arch: <unset>"); + mdoc_msg(mdoc, "msec: %d", mdoc->meta.msec); + return(post_prologue(mdoc)); + } - /* LINTED */ - for (i = 0, n = mdoc->last->child; n; n = n->next, i++) { - assert(MDOC_TEXT == n->type); - p = n->data.text.string; + /* Handles: `.Dt TITLE SEC' + * --> title = TITLE, volume = SEC is msec ? + * format(msec) : SEC, + * msec = SEC is msec ? atoi(msec) : 0, + * arch = NULL + */ - switch (i) { - case (0): - mdoc->meta.title = xstrdup(p); - break; - case (1): - mdoc->meta.msec = mdoc_atomsec(p); - if (MSEC_DEFAULT != mdoc->meta.msec) - break; - return(mdoc_nerr(mdoc, n, - "invalid parameter syntax")); - case (2): - mdoc->meta.vol = mdoc_atovol(p); - if (VOL_DEFAULT != mdoc->meta.vol) - break; - mdoc->meta.arch = mdoc_atoarch(p); - if (ARCH_DEFAULT != mdoc->meta.arch) - break; - return(mdoc_nerr(mdoc, n, - "invalid parameter syntax")); - default: - return(mdoc_nerr(mdoc, n, - "too many parameters")); - } + if ((cp = mdoc_a2msec(n->data.text.string))) { + mdoc->meta.vol = xstrdup(cp); + errno = 0; + lval = strtol(n->data.text.string, &ep, 10); + if (n->data.text.string[0] != '\0' && *ep == '\0') + mdoc->meta.msec = (int)lval; + } else + mdoc->meta.vol = xstrdup(n->data.text.string); + + if (NULL == (n = n->next)) { + mdoc_msg(mdoc, "volume: %s", mdoc->meta.vol); + mdoc_msg(mdoc, "arch: <unset>"); + mdoc_msg(mdoc, "msec: %d", mdoc->meta.msec); + return(post_prologue(mdoc)); } - if (NULL == mdoc->meta.title) - mdoc->meta.title = xstrdup("UNTITLED"); + /* Handles: `.Dt TITLE SEC VOL' + * --> title = TITLE, volume = VOL is vol ? + * format(VOL) : + * VOL is arch ? format(arch) : + * VOL + */ + + if ((cp = mdoc_a2vol(n->data.text.string))) { + free(mdoc->meta.vol); + mdoc->meta.vol = xstrdup(cp); + n = n->next; + } else { + cp = mdoc_a2arch(n->data.text.string); + if (NULL == cp) { + free(mdoc->meta.vol); + mdoc->meta.vol = xstrdup(n->data.text.string); + } else + mdoc->meta.arch = xstrdup(cp); + } - mdoc_msg(mdoc, "title: %s", mdoc->meta.title); + mdoc_msg(mdoc, "volume: %s", mdoc->meta.vol); + mdoc_msg(mdoc, "arch: %s", mdoc->meta.arch ? + mdoc->meta.arch : "<unset>"); + mdoc_msg(mdoc, "msec: %d", mdoc->meta.msec); + + /* Ignore any subsequent parameters... */ return(post_prologue(mdoc)); } @@ -317,21 +357,25 @@ static int post_os(struct mdoc *mdoc) { char buf[64]; + struct utsname utsname; - /* - * Prologue operating system must be parsed into document - * meta-data. - */ + if (mdoc->meta.os) + free(mdoc->meta.os); - assert(MDOC_ELEM == mdoc->last->type); - assert(MDOC_Os == mdoc->last->tok); - assert(NULL == mdoc->meta.os); + (void)xstrlcpys(buf, mdoc->last->child, sizeof(buf)); - if ( ! xstrlcats(buf, mdoc->last->child, 64)) - return(mdoc_err(mdoc, "macro parameters too long")); + if (0 == buf[0]) { + if (-1 == uname(&utsname)) + return(mdoc_err(mdoc, "utsname")); + (void)xstrlcpy(buf, utsname.sysname, sizeof(buf)); + (void)xstrlcat(buf, " ", sizeof(buf)); + (void)xstrlcat(buf, utsname.release, sizeof(buf)); + } - mdoc->meta.os = xstrdup(buf[0] ? buf : "LOCAL"); - mdoc->lastnamed = SEC_BODY; + mdoc->meta.os = xstrdup(buf); + mdoc_msg(mdoc, "system: %s", mdoc->meta.os); + + mdoc->lastnamed = mdoc->lastsec = SEC_BODY; return(post_prologue(mdoc)); } @@ -508,24 +552,12 @@ post_dd(struct mdoc *mdoc) { char buf[64]; - /* - * Prologue date must be parsed into document meta-data. We - * accept multiple kinds of dates, described mostly in - * mdoc_atotime(). - */ - - assert(MDOC_ELEM == mdoc->last->type); - assert(MDOC_Dd == mdoc->last->tok); + (void)xstrlcpys(buf, mdoc->last->child, sizeof(buf)); - assert(0 == mdoc->meta.date); - - if ( ! xstrlcats(buf, mdoc->last->child, 64)) - return(mdoc_err(mdoc, "macro parameters too long")); if (0 == (mdoc->meta.date = mdoc_atotime(buf))) - return(mdoc_err(mdoc, "invalid parameter syntax")); + return(mdoc_err(mdoc, "invalid date syntax")); mdoc_msg(mdoc, "date: %u", mdoc->meta.date); - return(post_prologue(mdoc)); } diff --git a/arch.in b/arch.in new file mode 100644 index 00000000..0c7d2dac --- /dev/null +++ b/arch.in @@ -0,0 +1,26 @@ +alpha Alpha +amd64 AMD64 +amiga Amiga +arc ARC +arm ARM +armish ARMISH +aviion AViiON +hp300 HP300 +hppa HPPA +hppa64 HPPA64 +i386 i386 +landisk LANDISK +luna88k Luna88k +mac68k Mac68k +macppc MacPPC +mvme68k MVME68k +mvme88k MVME88k +mvmeppc MVMEPPC +pmax PMAX +sgi SGI +socppc SOCPPC +sparc SPARC +sparc64 SPARC64 +sun3 Sun3 +vax VAX +zaurus Zaurus @@ -34,6 +34,7 @@ #define ARGS_QUOTED (1 << 0) #define ARGS_DELIM (1 << 1) #define ARGS_TABSEP (1 << 2) +#define ARGS_ARGVLIKE (1 << 3) #define ARGV_NONE (1 << 0) #define ARGV_SINGLE (1 << 1) @@ -91,43 +92,6 @@ static int mdoc_argvflags[MDOC_ARG_MAX] = { ARGV_SINGLE, /* MDOC_Width */ ARGV_NONE, /* MDOC_Compact */ ARGV_SINGLE, /* MDOC_Std */ - ARGV_NONE, /* MDOC_p1003_1_88 */ - ARGV_NONE, /* MDOC_p1003_1_90 */ - ARGV_NONE, /* MDOC_p1003_1_96 */ - ARGV_NONE, /* MDOC_p1003_1_2001 */ - ARGV_NONE, /* MDOC_p1003_1_2004 */ - ARGV_NONE, /* MDOC_p1003_1 */ - ARGV_NONE, /* MDOC_p1003_1b */ - ARGV_NONE, /* MDOC_p1003_1b_93 */ - ARGV_NONE, /* MDOC_p1003_1c_95 */ - ARGV_NONE, /* MDOC_p1003_1g_2000 */ - ARGV_NONE, /* MDOC_p1003_2_92 */ - ARGV_NONE, /* MDOC_p1387_2_95 */ - ARGV_NONE, /* MDOC_p1003_2 */ - ARGV_NONE, /* MDOC_p1387_2 */ - ARGV_NONE, /* MDOC_isoC_90 */ - ARGV_NONE, /* MDOC_isoC_amd1 */ - ARGV_NONE, /* MDOC_isoC_tcor1 */ - ARGV_NONE, /* MDOC_isoC_tcor2 */ - ARGV_NONE, /* MDOC_isoC_99 */ - ARGV_NONE, /* MDOC_ansiC */ - ARGV_NONE, /* MDOC_ansiC_89 */ - ARGV_NONE, /* MDOC_ansiC_99 */ - ARGV_NONE, /* MDOC_ieee754 */ - ARGV_NONE, /* MDOC_iso8802_3 */ - ARGV_NONE, /* MDOC_xpg3 */ - ARGV_NONE, /* MDOC_xpg4 */ - ARGV_NONE, /* MDOC_xpg4_2 */ - ARGV_NONE, /* MDOC_xpg4_3 */ - ARGV_NONE, /* MDOC_xbd5 */ - ARGV_NONE, /* MDOC_xcu5 */ - ARGV_NONE, /* MDOC_xsh5 */ - ARGV_NONE, /* MDOC_xns5 */ - ARGV_NONE, /* MDOC_xns5_2d2_0 */ - ARGV_NONE, /* MDOC_xcurses4_2 */ - ARGV_NONE, /* MDOC_susv2 */ - ARGV_NONE, /* MDOC_susv3 */ - ARGV_NONE, /* MDOC_svid4 */ ARGV_NONE, /* MDOC_Filled */ ARGV_NONE, /* MDOC_Words */ ARGV_NONE, /* MDOC_Emphasis */ @@ -172,7 +136,7 @@ static int mdoc_argflags[MDOC_MAX] = { 0, /* Ot */ ARGS_DELIM, /* Pa */ 0, /* Rv */ - ARGS_DELIM, /* St */ + ARGS_DELIM | ARGS_ARGVLIKE, /* St */ ARGS_DELIM, /* Va */ ARGS_DELIM, /* Vt */ ARGS_DELIM, /* Xr */ @@ -241,6 +205,7 @@ static int mdoc_argflags[MDOC_MAX] = { 0, /* Hf */ 0, /* Fr */ 0, /* Ud */ + 0, /* Lb */ }; @@ -373,7 +338,7 @@ args(struct mdoc *mdoc, int line, if ( ! pwarn(mdoc, line, *pos, WQUOTPARM)) return(ARGS_ERROR); - if ('-' == buf[*pos]) + if ( ! (fl & ARGS_ARGVLIKE) && '-' == buf[*pos]) if ( ! pwarn(mdoc, line, *pos, WARGVPARM)) return(ARGS_ERROR); @@ -646,84 +611,6 @@ argv_a2arg(int tok, const char *argv) if (xstrcmp(argv, "std")) return(MDOC_Std); break; - - case (MDOC_St): - if (xstrcmp(argv, "p1003.1-88")) - return(MDOC_p1003_1_88); - else if (xstrcmp(argv, "p1003.1-90")) - return(MDOC_p1003_1_90); - else if (xstrcmp(argv, "p1003.1-96")) - return(MDOC_p1003_1_96); - else if (xstrcmp(argv, "p1003.1-2001")) - return(MDOC_p1003_1_2001); - else if (xstrcmp(argv, "p1003.1-2004")) - return(MDOC_p1003_1_2004); - else if (xstrcmp(argv, "p1003.1")) - return(MDOC_p1003_1); - else if (xstrcmp(argv, "p1003.1b")) - return(MDOC_p1003_1b); - else if (xstrcmp(argv, "p1003.1b-93")) - return(MDOC_p1003_1b_93); - else if (xstrcmp(argv, "p1003.1c-95")) - return(MDOC_p1003_1c_95); - else if (xstrcmp(argv, "p1003.1g-2000")) - return(MDOC_p1003_1g_2000); - else if (xstrcmp(argv, "p1003.2-92")) - return(MDOC_p1003_2_92); - else if (xstrcmp(argv, "p1003.2-95")) - return(MDOC_p1387_2_95); - else if (xstrcmp(argv, "p1003.2")) - return(MDOC_p1003_2); - else if (xstrcmp(argv, "p1387.2-95")) - return(MDOC_p1387_2); - else if (xstrcmp(argv, "isoC-90")) - return(MDOC_isoC_90); - else if (xstrcmp(argv, "isoC-amd1")) - return(MDOC_isoC_amd1); - else if (xstrcmp(argv, "isoC-tcor1")) - return(MDOC_isoC_tcor1); - else if (xstrcmp(argv, "isoC-tcor2")) - return(MDOC_isoC_tcor2); - else if (xstrcmp(argv, "isoC-99")) - return(MDOC_isoC_99); - else if (xstrcmp(argv, "ansiC")) - return(MDOC_ansiC); - else if (xstrcmp(argv, "ansiC-89")) - return(MDOC_ansiC_89); - else if (xstrcmp(argv, "ansiC-99")) - return(MDOC_ansiC_99); - else if (xstrcmp(argv, "ieee754")) - return(MDOC_ieee754); - else if (xstrcmp(argv, "iso8802-3")) - return(MDOC_iso8802_3); - else if (xstrcmp(argv, "xpg3")) - return(MDOC_xpg3); - else if (xstrcmp(argv, "xpg4")) - return(MDOC_xpg4); - else if (xstrcmp(argv, "xpg4.2")) - return(MDOC_xpg4_2); - else if (xstrcmp(argv, "xpg4.3")) - return(MDOC_xpg4_3); - else if (xstrcmp(argv, "xbd5")) - return(MDOC_xbd5); - else if (xstrcmp(argv, "xcu5")) - return(MDOC_xcu5); - else if (xstrcmp(argv, "xsh5")) - return(MDOC_xsh5); - else if (xstrcmp(argv, "xns5")) - return(MDOC_xns5); - else if (xstrcmp(argv, "xns5.2d2.0")) - return(MDOC_xns5_2d2_0); - else if (xstrcmp(argv, "xcurses4.2")) - return(MDOC_xcurses4_2); - else if (xstrcmp(argv, "susv2")) - return(MDOC_susv2); - else if (xstrcmp(argv, "susv3")) - return(MDOC_susv3); - else if (xstrcmp(argv, "svid4")) - return(MDOC_svid4); - break; - default: break; } @@ -0,0 +1,13 @@ +v1 Version 1 AT&T UNIX +v2 Version 2 AT&T UNIX +v3 Version 3 AT&T UNIX +v4 Version 4 AT&T UNIX +v5 Version 5 AT&T UNIX +v6 Version 6 AT&T UNIX +v7 Version 7 AT&T UNIX +32v Version 32V AT&T UNIX +V AT&T System V UNIX +V.1 AT&T System V.1 UNIX +V.2 AT&T System V.2 UNIX +V.3 AT&T System V.3 UNIX +V.4 AT&T System V.4 UNIX @@ -0,0 +1,32 @@ +libarm ARM Architecture Library (libarm, -larm) +libarm32 ARM32 Architecture Library (libarm32, -larm32) +libc Standard C Library (libc, -lc) +libcdk Curses Development Kit Library (libcdk, -lcdk) +libcompat Compatibility Library (libcompat, -lcompat) +libcrypt Crypt Library (libcrypt, -lcrypt) +libcurses Curses Library (libcurses, -lcurses) +libedit Command Line Editor Library (libedit, -ledit) +libevent Event Notification Library (libevent, -levent) +libform Curses Form Library (libform, -lform) +libi386 i386 Architecture Library (libi386, -li386) +libintl Internationalized Message Handling Library (libintl, -lintl) +libipsec IPsec Policy Control Library (libipsec, -lipsec) +libkvm Kernel Data Access Library (libkvm, -lkvm) +libm Math Library (libm, -lm) +libm68k m68k Architecture Library (libm68k, -lm68k) +libmagic Magic Number Recognition Library (libmagic, -lmagic) +libmenu Curses Menu Library (libmenu, -lmenu) +libossaudio OSS Audio Emulation Library (libossaudio, -lossaudio) +libpam Pluggable Authentication Module Library (libpam, -lpam) +libpcap Capture Library (libpcap, -lpcap) +libpci PCI Bus Access Library (libpci, -lpci) +libpmc Performance Counters Library (libpmc, -lpmc) +libposix POSIX Compatibility Library (libposix, -lposix) +libpthread POSIX Threads Library (libpthread, -lpthread) +libresolv DNS Resolver Library (libresolv, -lresolv) +librt POSIX Real-time Library (librt, -lrt) +libtermcap Termcap Access Library (libtermcap, -ltermcap) +libusbhid USB Human Interface Devices Library (libusbhid, -lusbhid) +libutil System Utilities Library (libutil, -lutil) +libx86_64 x86_64 Architecture Library (libx86_64, -lx86_64) +libz Compression Library (libz, -lz) @@ -184,6 +184,7 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { macro_constant, 0 }, /* Hf */ { macro_obsolete, 0 }, /* Fr */ { macro_constant, 0 }, /* Ud */ + { macro_constant, 0 }, /* Lb */ }; const struct mdoc_macro * const mdoc_macros = __mdoc_macros; @@ -522,7 +523,9 @@ rewind_subblock(enum mdoc_type type, struct mdoc *mdoc, break; else if (rewind_dobreak(tok, n)) continue; - return(mdoc_perr(mdoc, line, ppos, "scope breaks prior %s", mdoc_node2a(n))); + return(mdoc_perr(mdoc, line, ppos, + "scope breaks %s", MDOC_ROOT == n->type ? + "<root>" : mdoc_macronames[n->tok])); } assert(n); @@ -546,8 +549,8 @@ rewind_expblock(struct mdoc *mdoc, int tok, int line, int ppos) else if (rewind_dobreak(tok, n)) continue; return(mdoc_perr(mdoc, line, ppos, - "scope breaks prior %s", - mdoc_node2a(n))); + "scope breaks %s", MDOC_ROOT == n->type ? + "<root>" : mdoc_macronames[n->tok])); } assert(n); @@ -571,8 +574,8 @@ rewind_impblock(struct mdoc *mdoc, int tok, int line, int ppos) else if (rewind_dobreak(tok, n)) continue; return(mdoc_perr(mdoc, line, ppos, - "scope breaks prior %s", - mdoc_node2a(n))); + "scope breaks %s", MDOC_ROOT == n->type ? + "<root>" : mdoc_macronames[n->tok])); } assert(n); @@ -1183,21 +1186,25 @@ static int macro_constant_delimited(MACRO_PROT_ARGS) { int lastarg, flushed, j, c, maxargs, argc, - igndelim; + igndelim, ignargs; struct mdoc_arg argv[MDOC_LINEARG_MAX]; char *p; lastarg = ppos; flushed = 0; + + /* + * Maximum arguments per macro. Some of these have none and + * exit as soon as they're parsed. + */ + switch (tok) { case (MDOC_No): /* FALLTHROUGH */ case (MDOC_Ns): /* FALLTHROUGH */ case (MDOC_Ux): - /* FALLTHROUGH */ - case (MDOC_St): maxargs = 0; break; default: @@ -1205,6 +1212,12 @@ macro_constant_delimited(MACRO_PROT_ARGS) break; } + /* + * Whether to ignore delimiter characters. `Pf' accepts its + * first token as a parameter no matter what it looks like (if + * it's text). + */ + switch (tok) { case (MDOC_Pf): igndelim = 1; @@ -1214,20 +1227,38 @@ macro_constant_delimited(MACRO_PROT_ARGS) break; } - for (argc = 0; argc < MDOC_LINEARG_MAX; argc++) { - lastarg = *pos; - c = mdoc_argv(mdoc, line, tok, &argv[argc], pos, buf); - if (ARGV_EOLN == c) - break; - if (ARGV_WORD == c) { - *pos = lastarg; - break; - } else if (ARGV_ARG == c) - continue; - mdoc_argv_free(argc, argv); - return(0); + /* + * Whether to ignore arguments: `St', for example, handles its + * argument-like parameters as regular parameters. + */ + + switch (tok) { + case (MDOC_St): + ignargs = 1; + break; + default: + ignargs = 0; + break; } + argc = 0; + + if ( ! ignargs) + for ( ; argc < MDOC_LINEARG_MAX; argc++) { + lastarg = *pos; + c = mdoc_argv(mdoc, line, tok, + &argv[argc], pos, buf); + if (ARGV_EOLN == c) + break; + if (ARGV_WORD == c) { + *pos = lastarg; + break; + } else if (ARGV_ARG == c) + continue; + mdoc_argv_free(argc, argv); + return(0); + } + if (MDOC_LINEARG_MAX == argc) { mdoc_argv_free(argc - 1, argv); return(perr(mdoc, line, ppos, EARGVLIM)); @@ -74,7 +74,7 @@ const char *const __mdoc_macronames[MDOC_MAX] = { "Tn", "Ux", "Xc", "Xo", "Fo", "Fc", "Oo", "Oc", "Bk", "Ek", "Bt", "Hf", - "Fr", "Ud", + "Fr", "Ud", "Lb", }; const char *const __mdoc_argnames[MDOC_ARG_MAX] = { @@ -85,20 +85,8 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = { "tag", "diag", "hang", "ohang", "inset", "column", "width", "compact", "std", - "p1003.1-88", "p1003.1-90", "p1003.1-96", - "p1003.1-2001", "p1003.1-2004", "p1003.1", - "p1003.1b", "p1003.1b-93", "p1003.1c-95", - "p1003.1g-2000", "p1003.2-92", "p1387.2-95", - "p1003.2", "p1387.2", "isoC-90", - "isoC-amd1", "isoC-tcor1", "isoC-tcor2", - "isoC-99", "ansiC", "ansiC-89", - "ansiC-99", "ieee754", "iso8802-3", - "xpg3", "xpg4", "xpg4.2", - "xpg4.3", "xbd5", "xcu5", - "xsh5", "xns5", "xns5.2d2.0", - "xcurses4.2", "susv2", "susv3", - "svid4", "filled", "words", - "emphasis", "symbolic", + "filled", "words", "emphasis", + "symbolic" }; const char * const *mdoc_macronames = __mdoc_macronames; @@ -135,6 +123,10 @@ mdoc_free(struct mdoc *mdoc) free(mdoc->meta.os); if (mdoc->meta.name) free(mdoc->meta.name); + if (mdoc->meta.arch) + free(mdoc->meta.arch); + if (mdoc->meta.vol) + free(mdoc->meta.vol); free(mdoc); } @@ -326,7 +318,6 @@ mdoc_macro(struct mdoc *mdoc, int tok, static int mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p) { - const char *nn, *nt, *on, *ot, *act; assert(mdoc->last); assert(mdoc->first); @@ -353,34 +344,15 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p) MDOC_LINEARG_SOFTMAX, mdoc->linetok)) return(0); - if (MDOC_TEXT == mdoc->last->type) - on = "<text>"; - else if (MDOC_ROOT == mdoc->last->type) - on = "<root>"; - else - on = mdoc_macronames[mdoc->last->tok]; - - if (MDOC_TEXT == p->type) - nn = "<text>"; - else if (MDOC_ROOT == p->type) - nn = "<root>"; - else - nn = mdoc_macronames[p->tok]; - - ot = mdoc_type2a(mdoc->last->type); - nt = mdoc_type2a(p->type); - switch (mdoc->next) { case (MDOC_NEXT_SIBLING): mdoc->last->next = p; p->prev = mdoc->last; p->parent = mdoc->last->parent; - act = "sibling"; break; case (MDOC_NEXT_CHILD): mdoc->last->child = p; p->parent = mdoc->last; - act = "child"; break; default: abort(); @@ -408,8 +380,6 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p) } mdoc->last = p; - mdoc_msg(mdoc, "parse: %s `%s' %s of %s `%s'", - nt, nn, act, ot, on); return(1); } @@ -673,27 +643,3 @@ argdup(size_t argsz, const struct mdoc_arg *args) return(pp); } - -/* FIXME: deprecate. */ -char * -mdoc_node2a(struct mdoc_node *node) -{ - static char buf[64]; - - assert(node); - - buf[0] = 0; - (void)xstrlcat(buf, mdoc_type2a(node->type), 64); - if (MDOC_ROOT == node->type) - return(buf); - (void)xstrlcat(buf, " `", 64); - if (MDOC_TEXT == node->type) - (void)xstrlcat(buf, node->data.text.string, 64); - else - (void)xstrlcat(buf, mdoc_macronames[node->tok], 64); - (void)xstrlcat(buf, "'", 64); - - return(buf); -} - - @@ -135,7 +135,8 @@ #define MDOC_Hf 103 #define MDOC_Fr 104 #define MDOC_Ud 105 -#define MDOC_MAX 106 +#define MDOC_Lb 106 +#define MDOC_MAX 107 /* What follows is a list of ALL possible macro arguments. */ @@ -160,48 +161,11 @@ #define MDOC_Width 18 #define MDOC_Compact 19 #define MDOC_Std 20 -#define MDOC_p1003_1_88 21 -#define MDOC_p1003_1_90 22 -#define MDOC_p1003_1_96 23 -#define MDOC_p1003_1_2001 24 -#define MDOC_p1003_1_2004 25 -#define MDOC_p1003_1 26 -#define MDOC_p1003_1b 27 -#define MDOC_p1003_1b_93 28 -#define MDOC_p1003_1c_95 29 -#define MDOC_p1003_1g_2000 30 -#define MDOC_p1003_2_92 31 -#define MDOC_p1387_2_95 32 -#define MDOC_p1003_2 33 -#define MDOC_p1387_2 34 -#define MDOC_isoC_90 35 -#define MDOC_isoC_amd1 36 -#define MDOC_isoC_tcor1 37 -#define MDOC_isoC_tcor2 38 -#define MDOC_isoC_99 39 -#define MDOC_ansiC 40 -#define MDOC_ansiC_89 41 -#define MDOC_ansiC_99 42 -#define MDOC_ieee754 43 -#define MDOC_iso8802_3 44 -#define MDOC_xpg3 45 -#define MDOC_xpg4 46 -#define MDOC_xpg4_2 47 -#define MDOC_xpg4_3 48 -#define MDOC_xbd5 49 -#define MDOC_xcu5 50 -#define MDOC_xsh5 51 -#define MDOC_xns5 52 -#define MDOC_xns5_2d2_0 53 -#define MDOC_xcurses4_2 54 -#define MDOC_susv2 55 -#define MDOC_susv3 56 -#define MDOC_svid4 57 -#define MDOC_Filled 58 -#define MDOC_Words 59 -#define MDOC_Emphasis 60 -#define MDOC_Symbolic 61 -#define MDOC_ARG_MAX 62 +#define MDOC_Filled 21 +#define MDOC_Words 22 +#define MDOC_Emphasis 23 +#define MDOC_Symbolic 24 +#define MDOC_ARG_MAX 25 /* Warnings are either syntax or groff-compatibility. */ enum mdoc_warn { @@ -209,24 +173,6 @@ enum mdoc_warn { WARN_COMPAT }; -/* Possible values for the `At' macro. */ -enum mdoc_att { - ATT_DEFAULT = 0, - ATT_v1, - ATT_v2, - ATT_v3, - ATT_v4, - ATT_v5, - ATT_v6, - ATT_v7, - ATT_32v, - ATT_V, - ATT_V1, - ATT_V2, - ATT_V3, - ATT_V4 -}; - /* An argument to a macro (multiple values = `It -column'). */ struct mdoc_arg { int arg; @@ -247,101 +193,36 @@ enum mdoc_type { MDOC_ROOT }; -/* Manual section. */ -enum mdoc_msec { - MSEC_DEFAULT = 0, - MSEC_1, - MSEC_2, - MSEC_3, - MSEC_3f, - MSEC_3p, - MSEC_4, - MSEC_5, - MSEC_6, - MSEC_7, - MSEC_8, - MSEC_9, - MSEC_X11, - MSEC_X11R6, - MSEC_local, - MSEC_n, - MSEC_unass, - MSEC_draft, - MSEC_paper -}; - -/* Section (named/unnamed) of `Ss'. */ +/* Section (named/unnamed) of `Sh'. */ enum mdoc_sec { - SEC_PROLOGUE = 0, - SEC_BODY, - SEC_NAME, - SEC_SYNOPSIS, - SEC_DESCRIPTION, - SEC_RETURN_VALUES, - SEC_ENVIRONMENT, - SEC_FILES, - SEC_EXAMPLES, - SEC_DIAGNOSTICS, - SEC_ERRORS, - SEC_SEE_ALSO, - SEC_STANDARDS, - SEC_HISTORY, - SEC_AUTHORS, - SEC_CAVEATS, - SEC_BUGS, + 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 }; -/* Volume of `Dt'. */ -enum mdoc_vol { - VOL_DEFAULT = 0, - VOL_AMD, - VOL_IND, - VOL_KM, - VOL_LOCAL, - VOL_PRM, - VOL_PS1, - VOL_SMM, - VOL_URM, - VOL_USD -}; - -/* Architecture of `Dt'. */ -enum mdoc_arch { - ARCH_DEFAULT = 0, - ARCH_alpha, - ARCH_amd64, - ARCH_amiga, - ARCH_arc, - ARCH_arm, - ARCH_armish, - ARCH_aviion, - ARCH_hp300, - ARCH_hppa, - ARCH_hppa64, - ARCH_i386, - ARCH_landisk, - ARCH_luna88k, - ARCH_mac68k, - ARCH_macppc, - ARCH_mvme68k, - ARCH_mvme88k, - ARCH_mvmeppc, - ARCH_pmax, - ARCH_sgi, - ARCH_socppc, - ARCH_sparc, - ARCH_sparc64, - ARCH_sun3, - ARCH_vax, - ARCH_zaurus -}; - /* Information from prologue. */ struct mdoc_meta { - enum mdoc_msec msec; - enum mdoc_vol vol; - enum mdoc_arch arch; + int msec; + char *vol; + char *arch; time_t date; char *title; char *os; @@ -429,12 +310,11 @@ const struct mdoc_meta *mdoc_meta(const struct mdoc *); int mdoc_endparse(struct mdoc *); /* The following are utility functions. */ -const char *mdoc_arch2a(enum mdoc_arch); -const char *mdoc_vol2a(enum mdoc_vol); -const char *mdoc_msec2a(enum mdoc_msec); -const char *mdoc_att2a(enum mdoc_att); -enum mdoc_att mdoc_atoatt(const char *); -const char *mdoc_st2a(int); + +const char *mdoc_a2att(const char *); +const char *mdoc_a2lib(const char *); +const char *mdoc_a2st(const char *); + int mdoc_isdelim(const char *); __END_DECLS @@ -28,12 +28,14 @@ int main(int argc, char *argv[]) { struct mmain *p; + int c; const struct mdoc *mdoc; p = mmain_alloc(); - if ( ! mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL)) - mmain_exit(p, 1); + c = mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL); + if (1 != c) + mmain_exit(p, -1 == c ? 1 : 0); if (NULL == (mdoc = mmain_mdoc(p))) mmain_exit(p, 1); @@ -17,7 +17,7 @@ .\" PERFORMANCE OF THIS SOFTWARE. .\" .Dd $Mdocdate$ -.Dt mdocmterm 1 +.Dt mdocterm 1 .Os .\" SECTION .Sh NAME @@ -16,8 +16,6 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/utsname.h> - #include <assert.h> #include <ctype.h> #include <err.h> @@ -181,14 +179,16 @@ static struct termsym termstyle_ansi[] = { int main(int argc, char *argv[]) { - struct mmain *p; + struct mmain *p; + int c; const struct mdoc *mdoc; - struct termp termp; + struct termp termp; p = mmain_alloc(); - if ( ! mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL)) - mmain_exit(p, 1); + c = mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL); + if (1 != c) + mmain_exit(p, -1 == c ? 1 : 0); if (NULL == (mdoc = mmain_mdoc(p))) mmain_exit(p, 1); @@ -570,9 +570,7 @@ footer(struct termp *p, const struct mdoc_meta *meta) static void header(struct termp *p, const struct mdoc_meta *meta) { - char *buf, *title, *bufp, *vbuf; - const char *pp; - struct utsname uts; + char *buf, *title, *bufp; p->rmargin = p->maxrmargin; p->offset = 0; @@ -581,48 +579,6 @@ header(struct termp *p, const struct mdoc_meta *meta) err(1, "malloc"); if (NULL == (title = malloc(p->rmargin))) err(1, "malloc"); - if (NULL == (vbuf = malloc(p->rmargin))) - err(1, "malloc"); - - if (NULL == (pp = mdoc_vol2a(meta->vol))) { - switch (meta->msec) { - case (MSEC_1): - /* FALLTHROUGH */ - case (MSEC_6): - /* FALLTHROUGH */ - case (MSEC_7): - pp = mdoc_vol2a(VOL_URM); - break; - case (MSEC_8): - pp = mdoc_vol2a(VOL_SMM); - break; - case (MSEC_2): - /* FALLTHROUGH */ - case (MSEC_3): - /* FALLTHROUGH */ - case (MSEC_4): - /* FALLTHROUGH */ - case (MSEC_5): - pp = mdoc_vol2a(VOL_PRM); - break; - case (MSEC_9): - pp = mdoc_vol2a(VOL_KM); - break; - default: - break; - } - } - vbuf[0] = 0; - - if (pp) { - if (-1 == uname(&uts)) - err(1, "uname"); - (void)strlcat(vbuf, uts.sysname, p->rmargin); - (void)strlcat(vbuf, " ", p->rmargin); - } else if (NULL == (pp = mdoc_msec2a(meta->msec))) - pp = mdoc_msec2a(MSEC_local); - - (void)strlcat(vbuf, pp, p->rmargin); /* * The header is strange. It has three components, which are @@ -637,16 +593,17 @@ header(struct termp *p, const struct mdoc_meta *meta) * switches on the manual section. */ - if (mdoc_arch2a(meta->arch)) - (void)snprintf(buf, p->rmargin, "%s (%s)", - vbuf, mdoc_arch2a(meta->arch)); - else - (void)strlcpy(buf, vbuf, p->rmargin); + assert(meta->vol); + (void)strlcpy(buf, meta->vol, p->rmargin); - pp = mdoc_msec2a(meta->msec); + if (meta->arch) { + (void)strlcat(buf, " (", p->rmargin); + (void)strlcat(buf, meta->arch, p->rmargin); + (void)strlcat(buf, ")", p->rmargin); + } - (void)snprintf(title, p->rmargin, "%s(%s)", - meta->title, pp ? pp : ""); + (void)snprintf(title, p->rmargin, "%s(%d)", + meta->title, meta->msec); for (bufp = title; *bufp; bufp++) *bufp = toupper((u_char)*bufp); @@ -678,7 +635,6 @@ header(struct termp *p, const struct mdoc_meta *meta) p->flags &= ~TERMP_NOSPACE; free(title); - free(vbuf); free(buf); } @@ -31,13 +31,15 @@ static void doprint(const struct mdoc_node *, int); int main(int argc, char *argv[]) { - struct mmain *p; + struct mmain *p; + int c; const struct mdoc *mdoc; p = mmain_alloc(); - if ( ! mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL)) - mmain_exit(p, 1); + c = mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL); + if (1 != c) + mmain_exit(p, -1 == c ? 1 : 0); if (NULL == (mdoc = mmain_mdoc(p))) mmain_exit(p, 1); @@ -109,7 +109,7 @@ mmain_getopt(struct mmain *p, int argc, char *argv[], extern int optind; - sz = strlcpy(opts, "vW:", 32); + sz = strlcpy(opts, "VvW:", 32); assert(sz < 32); if (u) { @@ -125,18 +125,21 @@ mmain_getopt(struct mmain *p, int argc, char *argv[], case ('v'): p->dbg++; break; + case ('V'): + (void)printf("%s %s\n", __progname, VERSION); + return(0); case ('W'): if ( ! getsopts(p, optarg)) - return(0); + return(-1); break; case ('?'): mmain_usage(help); - return(0); + return(-1); default: assert(getopt_cb); if ((*getopt_cb)(arg, c, optarg)) break; - return(0); + return(-1); } argv += optind; diff --git a/msec.in b/msec.in new file mode 100644 index 00000000..9d7c1a96 --- /dev/null +++ b/msec.in @@ -0,0 +1,16 @@ +1 General Commands Manual +2 System Calls Manual +3 Library Functions Manual +3p Perl Library Functions Manual +4 Kernel Interfaces Manual +5 File Formats Manual +6 Games Manual +7 Miscellaneous Information Manual +8 System Manager\'s Manual +9 Kernel Developer\'s Manual +X11 X11 Developer\'s Manual +X11R6 X11 Developer\'s Manual +unass Unassociated +local Local +draft Draft +paper Paper @@ -128,13 +128,12 @@ int mdoc_iscdelim(char); size_t mdoc_isescape(const char *); enum mdoc_sec mdoc_atosec(const char *); enum mdoc_msec mdoc_atomsec(const char *); -enum mdoc_vol mdoc_atovol(const char *); -enum mdoc_arch mdoc_atoarch(const char *); time_t mdoc_atotime(const char *); size_t mdoc_macro2len(int); -char *mdoc_type2a(enum mdoc_type); -char *mdoc_node2a(struct mdoc_node *); +const char *mdoc_a2arch(const char *); +const char *mdoc_a2vol(const char *); +const char *mdoc_a2msec(const char *); int mdoc_valid_pre(struct mdoc *, const struct mdoc_node *); @@ -158,7 +157,7 @@ int mdoc_args(struct mdoc *, int, #define ARGS_QWORD (3) #define ARGS_PHRASE (4) -int xstrlcats(char *, const struct mdoc_node *, size_t); +int xstrlcpys(char *, const struct mdoc_node *, size_t); int xstrlcat(char *, const char *, size_t); int xstrlcpy(char *, const char *, size_t); int xstrcmp(const char *, const char *); diff --git a/regress/test.prologue.13 b/regress/test.prologue.13 index 8ba7f29b..d74e3934 100644 --- a/regress/test.prologue.13 +++ b/regress/test.prologue.13 @@ -1,4 +1,4 @@ .Dd $Mdocdate$ -.Dt test 0 +.Dt test asdf .Os .Sh NAME @@ -0,0 +1,37 @@ +-p1003.1-88 IEEE Std 1003.1-1988 (\\\\(lqPOSIX\\\\(rq) +-p1003.1-90 IEEE Std 1003.1-1990 (\\\\(lqPOSIX\\\\(rq) +-p1003.1-96 ISO/IEC 9945-1:1996 (\\\\(lqPOSIX\\\\(rq) +-p1003.1-2001 IEEE Std 1003.1-2001 (\\\\(lqPOSIX\\\\(rq) +-p1003.1-2004 IEEE Std 1003.1-2004 (\\\\(lqPOSIX\\\\(rq) +-p1003.1 IEEE Std 1003.1 (\\\\(lqPOSIX\\\\(rq) +-p1003.1b IEEE Std 1003.1b (\\\\(lqPOSIX\\\\(rq) +-p1003.1b-93 IEEE Std 1003.1b-1993 (\\\\(lqPOSIX\\\\(rq) +-p1003.1c-95 IEEE Std 1003.1c-1995 (\\\\(lqPOSIX\\\\(rq) +-p1003.1g-2000 IEEE Std 1003.1g-2000 (\\\\(lqPOSIX\\\\(rq) +-p1003.2-92 IEEE Std 1003.2-1992 (\\\\(lqPOSIX.2\\\\(rq) +-p1387.2-95 IEEE Std 1387.2-1995 (\\\\(lqPOSIX.7.2\\\\(rq) +-p1003.2 IEEE Std 1003.2 (\\\\(lqPOSIX.2\\\\(rq) +-p1387.2 IEEE Std 1387.2 (\\\\(lqPOSIX.7.2\\\\(rq) +-isoC-90 ISO/IEC 9899:1990 (\\\\(lqISO C90\\\\(rq) +-isoC-amd1 ISO/IEC 9899/AMD1:1995 (\\\\(lqISO C90\\\\(rq) +-isoC-tcor1 ISO/IEC 9899/TCOR1:1994 (\\\\(lqISO C90\\\\(rq) +-isoC-tcor2 ISO/IEC 9899/TCOR2:1995 (\\\\(lqISO C90\\\\(rq) +-isoC-99 ISO/IEC 9899:1999 (\\\\(lqISO C99\\\\(rq) +-ansiC ANSI X3.159-1989 (\\\\(lqANSI C\\\\(rq) +-ansiC-89 ANSI X3.159-1989 (\\\\(lqANSI C\\\\(rq) +-ansiC-99 ANSI/ISO/IEC 9899-1999 (\\\\(lqANSI C99\\\\(rq) +-ieee754 IEEE Std 754-1985 +-iso8802-3 ISO 8802-3: 1989 +-xpg3 X/Open Portability Guide Issue 3 (\\\\(lqXPG3\\\\(rq) +-xpg4 X/Open Portability Guide Issue 4 (\\\\(lqXPG4\\\\(rq) +-xpg4.2 X/Open Portability Guide Issue 4.2 (\\\\(lqXPG4.2\\\\(rq) +-xpg4.3 X/Open Portability Guide Issue 4.3 (\\\\(lqXPG4.3\\\\(rq) +-xbd5 X/Open System Interface Definitions Issue 5 (\\\\(lqXBD5\\\\(rq) +-xcu5 X/Open Commands and Utilities Issue 5 (\\\\(lqXCU5\\\\(rq) +-xsh5 X/Open System Interfaces and Headers Issue 5 (\\\\(lqXSH5\\\\(rq) +-xns5 X/Open Networking Services Issue 5 (\\\\(lqXNS5\\\\(rq) +-xns5.2d2.0 X/Open Networking Services Issue 5.2 Draft 2.0 (\\\\(lqXNS5.2D2.0\\\\(rq) +-xcurses4.2 X/Open Curses Issue 4 Version 2 (\\\\(lqXCURSES4.2\\\\(rq) +-susv2 Version 2 of the Single UNIX Specification +-susv3 Version 3 of the Single UNIX Specification +-svid4 System V Interface Definition, Fourth Edition (\\\\(lqSVID4\\\\(rq) @@ -25,11 +25,44 @@ #include <time.h> #endif +#include "private.h" + /* - * Convert scalars to and from string format. + * Various string-literal operations: converting scalars to and from + * strings, etc. */ -#include "private.h" +struct mdoc_secname { + const char *name; + int flag; +#define MSECNAME_META (1 << 0) +}; + +/* Section names corresponding to mdoc_sec. */ + +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 } +}; #ifdef __linux__ extern char *strptime(const char *, const char *, struct tm *); @@ -150,38 +183,13 @@ mdoc_isdelim(const char *p) enum mdoc_sec mdoc_atosec(const char *p) { + const struct mdoc_secname *n; + int i; - assert(p); - if (0 == strcmp(p, "NAME")) - return(SEC_NAME); - else if (0 == strcmp(p, "RETURN VALUES")) - return(SEC_RETURN_VALUES); - else if (0 == strcmp(p, "SEE ALSO")) - return(SEC_SEE_ALSO); - else if (0 == strcmp(p, "SYNOPSIS")) - return(SEC_SYNOPSIS); - else if (0 == strcmp(p, "DESCRIPTION")) - return(SEC_DESCRIPTION); - else if (0 == strcmp(p, "ENVIRONMENT")) - return(SEC_ENVIRONMENT); - else if (0 == strcmp(p, "FILES")) - return(SEC_FILES); - else if (0 == strcmp(p, "EXAMPLES")) - return(SEC_EXAMPLES); - else if (0 == strcmp(p, "DIAGNOSTICS")) - return(SEC_DIAGNOSTICS); - else if (0 == strcmp(p, "ERRORS")) - return(SEC_ERRORS); - else if (0 == strcmp(p, "STANDARDS")) - return(SEC_STANDARDS); - else if (0 == strcmp(p, "HISTORY")) - return(SEC_HISTORY); - else if (0 == strcmp(p, "AUTHORS")) - return(SEC_AUTHORS); - else if (0 == strcmp(p, "CAVEATS")) - return(SEC_CAVEATS); - else if (0 == strcmp(p, "BUGS")) - return(SEC_BUGS); + for (i = 0, n = secnames; n->name; n++, i++) + if ( ! (n->flag & MSECNAME_META)) + if (xstrcmp(p, n->name)) + return((enum mdoc_sec)i); return(SEC_CUSTOM); } @@ -209,547 +217,6 @@ mdoc_atotime(const char *p) } -enum mdoc_msec -mdoc_atomsec(const char *p) -{ - - if (0 == strcmp(p, "1")) - return(MSEC_1); - else if (0 == strcmp(p, "2")) - return(MSEC_2); - else if (0 == strcmp(p, "3")) - return(MSEC_3); - else if (0 == strcmp(p, "3f")) - return(MSEC_3f); - else if (0 == strcmp(p, "3p")) - return(MSEC_3p); - else if (0 == strcmp(p, "4")) - return(MSEC_4); - else if (0 == strcmp(p, "5")) - return(MSEC_5); - else if (0 == strcmp(p, "6")) - return(MSEC_6); - else if (0 == strcmp(p, "7")) - return(MSEC_7); - else if (0 == strcmp(p, "8")) - return(MSEC_8); - else if (0 == strcmp(p, "9")) - return(MSEC_9); - else if (0 == strcmp(p, "X11")) - return(MSEC_X11); - else if (0 == strcmp(p, "X11R6")) - return(MSEC_X11R6); - else if (0 == strcmp(p, "local")) - return(MSEC_local); - else if (0 == strcmp(p, "n")) - return(MSEC_n); - else if (0 == strcmp(p, "unass")) - return(MSEC_unass); - else if (0 == strcmp(p, "draft")) - return(MSEC_draft); - else if (0 == strcmp(p, "paper")) - return(MSEC_paper); - - return(MSEC_DEFAULT); -} - - -enum mdoc_vol -mdoc_atovol(const char *p) -{ - - if (0 == strcmp(p, "AMD")) - return(VOL_AMD); - else if (0 == strcmp(p, "IND")) - return(VOL_IND); - else if (0 == strcmp(p, "KM")) - return(VOL_KM); - else if (0 == strcmp(p, "LOCAL")) - return(VOL_LOCAL); - else if (0 == strcmp(p, "PRM")) - return(VOL_PRM); - else if (0 == strcmp(p, "PS1")) - return(VOL_PS1); - else if (0 == strcmp(p, "SMM")) - return(VOL_SMM); - else if (0 == strcmp(p, "URM")) - return(VOL_URM); - else if (0 == strcmp(p, "USD")) - return(VOL_USD); - - return(VOL_DEFAULT); -} - - -enum mdoc_arch -mdoc_atoarch(const char *p) -{ - - if (0 == strcmp(p, "alpha")) - return(ARCH_alpha); - else if (0 == strcmp(p, "amd64")) - return(ARCH_amd64); - else if (0 == strcmp(p, "amiga")) - return(ARCH_amiga); - else if (0 == strcmp(p, "arc")) - return(ARCH_arc); - else if (0 == strcmp(p, "arm")) - return(ARCH_arm); - else if (0 == strcmp(p, "armish")) - return(ARCH_armish); - else if (0 == strcmp(p, "aviion")) - return(ARCH_aviion); - else if (0 == strcmp(p, "hp300")) - return(ARCH_hp300); - else if (0 == strcmp(p, "hppa")) - return(ARCH_hppa); - else if (0 == strcmp(p, "hppa64")) - return(ARCH_hppa64); - else if (0 == strcmp(p, "i386")) - return(ARCH_i386); - else if (0 == strcmp(p, "landisk")) - return(ARCH_landisk); - else if (0 == strcmp(p, "luna88k")) - return(ARCH_luna88k); - else if (0 == strcmp(p, "mac68k")) - return(ARCH_mac68k); - else if (0 == strcmp(p, "macppc")) - return(ARCH_macppc); - else if (0 == strcmp(p, "mvme68k")) - return(ARCH_mvme68k); - else if (0 == strcmp(p, "mvme88k")) - return(ARCH_mvme88k); - else if (0 == strcmp(p, "mvmeppc")) - return(ARCH_mvmeppc); - else if (0 == strcmp(p, "pmax")) - return(ARCH_pmax); - else if (0 == strcmp(p, "sgi")) - return(ARCH_sgi); - else if (0 == strcmp(p, "socppc")) - return(ARCH_socppc); - else if (0 == strcmp(p, "sparc")) - return(ARCH_sparc); - else if (0 == strcmp(p, "sparc64")) - return(ARCH_sparc64); - else if (0 == strcmp(p, "sun3")) - return(ARCH_sun3); - else if (0 == strcmp(p, "vax")) - return(ARCH_vax); - else if (0 == strcmp(p, "zaurus")) - return(ARCH_zaurus); - - return(ARCH_DEFAULT); -} - - -enum mdoc_att -mdoc_atoatt(const char *p) -{ - - assert(p); - if (0 == strcmp(p, "v1")) - return(ATT_v1); - else if (0 == strcmp(p, "v2")) - return(ATT_v2); - else if (0 == strcmp(p, "v3")) - return(ATT_v3); - else if (0 == strcmp(p, "v4")) - return(ATT_v4); - else if (0 == strcmp(p, "v5")) - return(ATT_v5); - else if (0 == strcmp(p, "v6")) - return(ATT_v6); - else if (0 == strcmp(p, "v7")) - return(ATT_v7); - else if (0 == strcmp(p, "32v")) - return(ATT_32v); - else if (0 == strcmp(p, "V")) - return(ATT_V); - else if (0 == strcmp(p, "V.1")) - return(ATT_V1); - else if (0 == strcmp(p, "V.2")) - return(ATT_V2); - else if (0 == strcmp(p, "V.3")) - return(ATT_V3); - else if (0 == strcmp(p, "V.4")) - return(ATT_V4); - - return(ATT_DEFAULT); -} - - -char * -mdoc_type2a(enum mdoc_type type) -{ - switch (type) { - case (MDOC_ROOT): - return("root"); - case (MDOC_BLOCK): - return("block"); - case (MDOC_HEAD): - return("block-head"); - case (MDOC_BODY): - return("block-body"); - case (MDOC_TAIL): - return("block-tail"); - case (MDOC_ELEM): - return("elem"); - case (MDOC_TEXT): - return("text"); - default: - break; - } - - abort(); - /* NOTREACHED */ -} - - -const char * -mdoc_arch2a(enum mdoc_arch arch) -{ - - switch (arch) { - case (ARCH_alpha): - return("Alpha"); - case (ARCH_amd64): - return("AMD64"); - case (ARCH_amiga): - return("Amiga"); - case (ARCH_arc): - return("ARC"); - case (ARCH_arm): - return("ARM"); - case (ARCH_armish): - return("ARMISH"); - case (ARCH_aviion): - return("AViiON"); - case (ARCH_hp300): - return("HP300"); - case (ARCH_hppa): - return("HPPA"); - case (ARCH_hppa64): - return("HPPA64"); - case (ARCH_i386): - return("i386"); - case (ARCH_landisk): - return("LANDISK"); - case (ARCH_luna88k): - return("Luna88k"); - case (ARCH_mac68k): - return("Mac68k"); - case (ARCH_macppc): - return("MacPPC"); - case (ARCH_mvme68k): - return("MVME68k"); - case (ARCH_mvme88k): - return("MVME88k"); - case (ARCH_mvmeppc): - return("MVMEPPC"); - case (ARCH_pmax): - return("PMAX"); - case (ARCH_sgi): - return("SGI"); - case (ARCH_socppc): - return("SOCPPC"); - case (ARCH_sparc): - return("SPARC"); - case (ARCH_sparc64): - return("SPARC64"); - case (ARCH_sun3): - return("Sun3"); - case (ARCH_vax): - return("VAX"); - case (ARCH_zaurus): - return("Zaurus"); - case (ARCH_DEFAULT): - return(NULL); - default: - break; - } - - abort(); - /* NOTREACHED */ -} - - -const char * -mdoc_vol2a(enum mdoc_vol vol) -{ - - switch (vol) { - case (VOL_AMD): - return("Ancestral Manual Documents"); - case (VOL_IND): - return("Manual Master Index"); - case (VOL_KM): - return("Kernel Manual"); - case (VOL_LOCAL): - return("Local Manual"); - case (VOL_PRM): - return("Programmer's Manual"); - case (VOL_PS1): - return("Programmer's Supplementary Documents"); - case (VOL_SMM): - return("System Manager's Manual"); - case (VOL_URM): - return("Reference Manual"); - case (VOL_USD): - return("User's Supplementary Documents"); - case (VOL_DEFAULT): - return(NULL); - default: - break; - } - - abort(); - /* NOTREACHED */ -} - - -const char * -mdoc_msec2a(enum mdoc_msec msec) -{ - - switch (msec) { - case(MSEC_1): - return("1"); - case(MSEC_2): - return("2"); - case(MSEC_3): - return("3"); - case(MSEC_3f): - return("3f"); - case(MSEC_3p): - return("3p"); - case(MSEC_4): - return("4"); - case(MSEC_5): - return("5"); - case(MSEC_6): - return("6"); - case(MSEC_7): - return("7"); - case(MSEC_8): - return("8"); - case(MSEC_9): - return("9"); - case(MSEC_X11): - return("X11"); - case(MSEC_X11R6): - return("X11R6"); - case(MSEC_local): - return("local"); - case(MSEC_n): - return("n"); - case(MSEC_unass): - /* FALLTHROUGH */ - case(MSEC_draft): - return("draft"); - case(MSEC_paper): - return("paper"); - case(MSEC_DEFAULT): - return(NULL); - default: - break; - } - - abort(); - /* NOTREACHED */ -} - - -const char * -mdoc_st2a(int c) -{ - char *p; - - switch (c) { - case(MDOC_p1003_1_88): - p = "IEEE Std 1003.1-1988 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1_90): - p = "IEEE Std 1003.1-1990 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1_96): - p = "ISO/IEC 9945-1:1996 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1_2001): - p = "IEEE Std 1003.1-2001 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1_2004): - p = "IEEE Std 1003.1-2004 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1): - p = "IEEE Std 1003.1 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1b): - p = "IEEE Std 1003.1b (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1b_93): - p = "IEEE Std 1003.1b-1993 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1c_95): - p = "IEEE Std 1003.1c-1995 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_1g_2000): - p = "IEEE Std 1003.1g-2000 (\\(lqPOSIX\\(rq)"; - break; - case(MDOC_p1003_2_92): - p = "IEEE Std 1003.2-1992 (\\(lqPOSIX.2\\(rq)"; - break; - case(MDOC_p1387_2_95): - p = "IEEE Std 1387.2-1995 (\\(lqPOSIX.7.2\\(rq)"; - break; - case(MDOC_p1003_2): - p = "IEEE Std 1003.2 (\\(lqPOSIX.2\\(rq)"; - break; - case(MDOC_p1387_2): - p = "IEEE Std 1387.2 (\\(lqPOSIX.7.2\\(rq)"; - break; - case(MDOC_isoC_90): - p = "ISO/IEC 9899:1990 (\\(lqISO C90\\(rq)"; - break; - case(MDOC_isoC_amd1): - p = "ISO/IEC 9899/AMD1:1995 (\\(lqISO C90\\(rq)"; - break; - case(MDOC_isoC_tcor1): - p = "ISO/IEC 9899/TCOR1:1994 (\\(lqISO C90\\(rq)"; - break; - case(MDOC_isoC_tcor2): - p = "ISO/IEC 9899/TCOR2:1995 (\\(lqISO C90\\(rq)"; - break; - case(MDOC_isoC_99): - p = "ISO/IEC 9899:1999 (\\(lqISO C99\\(rq)"; - break; - case(MDOC_ansiC): - p = "ANSI X3.159-1989 (\\(lqANSI C\\(rq)"; - break; - case(MDOC_ansiC_89): - p = "ANSI X3.159-1989 (\\(lqANSI C\\(rq)"; - break; - case(MDOC_ansiC_99): - p = "ANSI/ISO/IEC 9899-1999 (\\(lqANSI C99\\(rq)"; - break; - case(MDOC_ieee754): - p = "IEEE Std 754-1985"; - break; - case(MDOC_iso8802_3): - p = "ISO 8802-3: 1989"; - break; - case(MDOC_xpg3): - p = "X/Open Portability Guide Issue 3 " - "(\\(lqXPG3\\(rq)"; - break; - case(MDOC_xpg4): - p = "X/Open Portability Guide Issue 4 " - "(\\(lqXPG4\\(rq)"; - break; - case(MDOC_xpg4_2): - p = "X/Open Portability Guide Issue 4.2 " - "(\\(lqXPG4.2\\(rq)"; - break; - case(MDOC_xpg4_3): - p = "X/Open Portability Guide Issue 4.3 " - "(\\(lqXPG4.3\\(rq)"; - break; - case(MDOC_xbd5): - p = "X/Open System Interface Definitions Issue 5 " - "(\\(lqXBD5\\(rq)"; - break; - case(MDOC_xcu5): - p = "X/Open Commands and Utilities Issue 5 " - "(\\(lqXCU5\\(rq)"; - break; - case(MDOC_xsh5): - p = "X/Open System Interfaces and Headers Issue 5 " - "(\\(lqXSH5\\(rq)"; - break; - case(MDOC_xns5): - p = "X/Open Networking Services Issue 5 " - "(\\(lqXNS5\\(rq)"; - break; - case(MDOC_xns5_2d2_0): - p = "X/Open Networking Services Issue 5.2 Draft 2.0 " - "(\\(lqXNS5.2D2.0\\(rq)"; - break; - case(MDOC_xcurses4_2): - p = "X/Open Curses Issue 4 Version 2 " - "(\\(lqXCURSES4.2\\(rq)"; - break; - case(MDOC_susv2): - p = "Version 2 of the Single UNIX Specification"; - break; - case(MDOC_susv3): - p = "Version 3 of the Single UNIX Specification"; - break; - case(MDOC_svid4): - p = "System V Interface Definition, Fourth Edition " - "(\\(lqSVID4\\(rq)"; - break; - default: - p = NULL; - break; - } - - return(p); -} - - -const char * -mdoc_att2a(enum mdoc_att c) -{ - char *p; - - switch (c) { - case(ATT_v1): - p = "Version 1 AT&T UNIX"; - break; - case(ATT_v2): - p = "Version 2 AT&T UNIX"; - break; - case(ATT_v3): - p = "Version 3 AT&T UNIX"; - break; - case(ATT_v4): - p = "Version 4 AT&T UNIX"; - break; - case(ATT_v5): - p = "Version 5 AT&T UNIX"; - break; - case(ATT_v6): - p = "Version 6 AT&T UNIX"; - break; - case(ATT_v7): - p = "Version 7 AT&T UNIX"; - break; - case(ATT_32v): - p = "Version 32V AT&T UNIX"; - break; - case(ATT_V): - p = "AT&T System V UNIX"; - break; - case(ATT_V1): - p = "AT&T System V.1 UNIX"; - break; - case(ATT_V2): - p = "AT&T System V.2 UNIX"; - break; - case(ATT_V3): - p = "AT&T System V.3 UNIX"; - break; - case(ATT_V4): - p = "AT&T System V.4 UNIX"; - break; - default: - p = "AT&T UNIX"; - break; - } - - return(p); -} - - size_t mdoc_macro2len(int macro) { diff --git a/strings.sh b/strings.sh new file mode 100644 index 00000000..3f179c10 --- /dev/null +++ b/strings.sh @@ -0,0 +1,83 @@ +#! /bin/sh +# $Id$ + +# strings.sh [-o output] name input +# +# Generate the file of strings. This will contain the following +# function: +# +# const char * +# mdoc_a2NAME(const char *); +# +# The input file must be tab-delimited as follows: +# +# attnam0 A longer description +# attnam1 Another longer description + +input= +output= +args=`getopt o: $*` + +if [ $? -ne 0 ]; then + echo "usage: $0 [-o output] name input" 1>&2 + exit 1 +fi + +set -- $args + +while [ $# -ge 0 ] +do + case "$1" in + -o) + output="$2" ; shift; shift ;; + --) + shift ; break ;; + esac +done + +name=$1 + +if [ -z "$name" ]; then + echo "usage: $0 [-o output] name input" 1>&2 + exit 1 +fi + +input=$2 + +if [ "$output" ]; then + exec 1<>$output +fi + +if [ "$input" ]; then + exec 0<>$input +fi + +cat <<! +/* + * DO NOT EDIT! Automatically generated by $0. + */ +#include <stdlib.h> + +#include "private.h" + +const char * +mdoc_a2${name}(const char *p) +{ + +! + +while read in ; do + key=`printf "%s\n" "$in" | cut -f 1` + val=`printf "%s\n" "$in" | cut -f 2- | sed 's!^[ ]*!!'` + cat <<! + if (xstrcmp(p, "$key")) + return("$val"); +! +done + +cat <<! + + /* No keys found. */ + return(NULL); +} +! @@ -166,6 +166,7 @@ DECL_PRE(termp_xr); DECL_POST(termp___); DECL_POST(termp_bl); DECL_POST(termp_bx); +DECL_POST(termp_lb); const struct termact __termacts[MDOC_MAX] = { { NULL, NULL }, /* \" */ @@ -274,6 +275,7 @@ const struct termact __termacts[MDOC_MAX] = { { NULL, NULL }, /* Hf */ { NULL, NULL }, /* Fr */ { termp_ud_pre, NULL }, /* Ud */ + { NULL, termp_lb_post }, /* lb */ }; const struct termact *termacts = __termacts; @@ -721,14 +723,13 @@ termp_pp_pre(DECL_ARGS) static int termp_st_pre(DECL_ARGS) { - const char *tp; + const char *cp; - assert(1 == node->data.elem.argc); - - tp = mdoc_st2a(node->data.elem.argv[0].arg); - word(p, tp); - - return(1); + /* XXX - if child isn't text? */ + if (node->child) + if ((cp = mdoc_a2st(node->child->data.text.string))) + word(p, cp); + return(0); } @@ -968,6 +969,15 @@ termp_bt_pre(DECL_ARGS) /* ARGSUSED */ +static void +termp_lb_post(DECL_ARGS) +{ + + newln(p); +} + + +/* ARGSUSED */ static int termp_ud_pre(DECL_ARGS) { @@ -1480,15 +1490,19 @@ termp_in_post(DECL_ARGS) static int termp_at_pre(DECL_ARGS) { - enum mdoc_att c; + const char *att; + + att = NULL; - c = ATT_DEFAULT; if (node->child) { assert(MDOC_TEXT == node->child->type); - c = mdoc_atoatt(node->child->data.text.string); + att = mdoc_a2att(node->child->data.text.string); } - word(p, mdoc_att2a(c)); + if (NULL == att) + att = "AT&T UNIX"; + + word(p, att); return(0); } @@ -18,6 +18,7 @@ */ #include <assert.h> #include <ctype.h> +#include <stdarg.h> #include <stdlib.h> #include "private.h" @@ -48,7 +49,8 @@ struct valids { /* Utility checks. */ static int check_parent(PRE_ARGS, int, enum mdoc_type); -static int check_msec(PRE_ARGS, int, enum mdoc_msec *); +static int check_msec(PRE_ARGS, ...); +static int check_sec(PRE_ARGS, ...); static int check_stdarg(PRE_ARGS); static int check_text(struct mdoc *, @@ -74,21 +76,23 @@ static inline int err_count(struct mdoc *, const char *, /* Specific pre-child-parse routines. */ -static int pre_display(PRE_ARGS); -static int pre_sh(PRE_ARGS); -static int pre_ss(PRE_ARGS); +static int pre_an(PRE_ARGS); static int pre_bd(PRE_ARGS); static int pre_bl(PRE_ARGS); -static int pre_it(PRE_ARGS); static int pre_cd(PRE_ARGS); +static int pre_dd(PRE_ARGS); +static int pre_display(PRE_ARGS); +static int pre_dt(PRE_ARGS); static int pre_er(PRE_ARGS); static int pre_ex(PRE_ARGS); -static int pre_rv(PRE_ARGS); -static int pre_an(PRE_ARGS); -static int pre_st(PRE_ARGS); -static int pre_prologue(PRE_ARGS); -static int pre_prologue(PRE_ARGS); +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); /* Specific post-child-parse routines. */ @@ -107,35 +111,37 @@ static int hwarn_eq1(POST_ARGS); static int ewarn_ge1(POST_ARGS); static int ebool(POST_ARGS); -static int post_sh(POST_ARGS); -static int post_sh_body(POST_ARGS); -static int post_sh_head(POST_ARGS); -static int post_fd(POST_ARGS); -static int post_bl(POST_ARGS); -static int post_it(POST_ARGS); -static int post_ex(POST_ARGS); static int post_an(POST_ARGS); static int post_at(POST_ARGS); -static int post_xr(POST_ARGS); -static int post_nm(POST_ARGS); static int post_bf(POST_ARGS); +static int post_bl(POST_ARGS); +static int post_ex(POST_ARGS); +static int post_it(POST_ARGS); +static int post_nm(POST_ARGS); static int post_root(POST_ARGS); +static int post_sh(POST_ARGS); +static int post_sh_body(POST_ARGS); +static int post_sh_head(POST_ARGS); +static int post_st(POST_ARGS); /* Collections of pre-child-parse routines. */ -static v_pre pres_prologue[] = { pre_prologue, NULL }; -static v_pre pres_d1[] = { pre_display, NULL }; +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_it[] = { pre_it, NULL }; -static v_pre pres_ss[] = { pre_ss, NULL }; -static v_pre pres_sh[] = { pre_sh, NULL }; static v_pre pres_cd[] = { pre_cd, NULL }; +static v_pre pres_dd[] = { pre_prologue, 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_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_rv[] = { pre_rv, NULL }; -static v_pre pres_an[] = { pre_an, NULL }; -static v_pre pres_st[] = { pre_st, NULL }; +static v_pre pres_sh[] = { pre_sh, NULL }; +static v_pre pres_ss[] = { pre_ss, NULL }; /* Collections of post-child-parse routines. */ @@ -151,25 +157,27 @@ static v_post posts_it[] = { post_it, NULL }; static v_post posts_in[] = { ewarn_eq1, NULL }; static v_post posts_ss[] = { herr_ge1, NULL }; static v_post posts_pf[] = { eerr_eq1, NULL }; +static v_post posts_lb[] = { eerr_eq1, NULL }; +static v_post posts_st[] = { eerr_eq1, post_st, NULL }; static v_post posts_pp[] = { ewarn_eq0, NULL }; static v_post posts_ex[] = { eerr_le1, post_ex, NULL }; static v_post posts_an[] = { post_an, NULL }; static v_post posts_at[] = { post_at, NULL }; -static v_post posts_xr[] = { eerr_ge1, eerr_le2, post_xr, NULL }; +static v_post posts_xr[] = { eerr_ge1, eerr_le2, NULL }; static v_post posts_nm[] = { post_nm, NULL }; static v_post posts_bf[] = { hwarn_le1, post_bf, NULL }; static v_post posts_rs[] = { herr_eq0, bwarn_ge1, NULL }; static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL }; static v_post posts_bk[] = { herr_eq0, bwarn_ge1, NULL }; -static v_post posts_fd[] = { ewarn_ge1, post_fd, NULL }; +static v_post posts_fd[] = { ewarn_ge1, NULL }; /* Per-macro pre- and post-child-check routine collections. */ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* \" */ - { pres_prologue, posts_text }, /* Dd */ - { pres_prologue, NULL }, /* Dt */ - { pres_prologue, NULL }, /* Os */ + { pres_dd, posts_text }, /* Dd */ + { pres_dt, NULL }, /* Dt */ + { pres_os, NULL }, /* Os */ { pres_sh, posts_sh }, /* Sh */ { pres_ss, posts_ss }, /* Ss */ { NULL, posts_pp }, /* Pp */ @@ -190,7 +198,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_text }, /* Ev */ { pres_ex, posts_ex }, /* Ex */ { NULL, posts_text }, /* Fa */ - { NULL, posts_fd }, /* Fd */ + { pres_fd, posts_fd }, /* Fd */ { NULL, NULL }, /* Fl */ { NULL, posts_text }, /* Fn */ { NULL, posts_wtext }, /* Ft */ @@ -203,7 +211,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Ot */ { NULL, NULL }, /* Pa */ { pres_rv, posts_notext }, /* Rv */ - { pres_st, posts_notext }, /* St */ + { NULL, posts_st }, /* St */ { NULL, posts_text }, /* Va */ { NULL, posts_text }, /* Vt */ { NULL, posts_xr }, /* Xr */ @@ -272,6 +280,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Hf */ { NULL, NULL }, /* Fr */ { NULL, posts_notext }, /* Ud */ + { pres_lb, posts_lb }, /* Lb */ }; @@ -467,15 +476,47 @@ check_stdarg(PRE_ARGS) static int -check_msec(PRE_ARGS, int sz, enum mdoc_msec *msecs) +check_sec(PRE_ARGS, ...) { - int i; + enum mdoc_sec sec; + va_list ap; - for (i = 0; i < sz; i++) - if (msecs[i] == mdoc->meta.msec) - return(1); + va_start(ap, n); + + for (;;) { + if (SEC_CUSTOM == (sec = va_arg(ap, enum mdoc_sed))) + break; + if (sec != mdoc->lastsec) + continue; + va_end(ap); + return(1); + } + + va_end(ap); return(mdoc_nwarn(mdoc, n, WARN_COMPAT, - "invalid manual section")); + "inappropriate document section for macro")); +} + + +static int +check_msec(PRE_ARGS, ...) +{ + va_list ap; + int msec; + + va_start(ap, n); + for (;;) { + if (0 == (msec = va_arg(ap, int))) + break; + if (msec != mdoc->meta.msec) + continue; + va_end(ap); + return(1); + } + + va_end(ap); + return(mdoc_nwarn(mdoc, n, WARN_COMPAT, + "inappropriate manual section for macro")); } @@ -755,31 +796,28 @@ pre_it(PRE_ARGS) static int -pre_st(PRE_ARGS) +pre_an(PRE_ARGS) { - if (1 == n->data.elem.argc) + if (1 >= n->data.elem.argc) return(1); - return(mdoc_nerr(mdoc, n, "one argument required")); + return(mdoc_nerr(mdoc, n, "one argument allowed")); } static int -pre_an(PRE_ARGS) +pre_lb(PRE_ARGS) { - if (1 >= n->data.elem.argc) - return(1); - return(mdoc_nerr(mdoc, n, "one argument allowed")); + return(check_sec(mdoc, n, SEC_LIBRARY, SEC_CUSTOM)); } static int pre_rv(PRE_ARGS) { - enum mdoc_msec msecs[] = { MSEC_2, MSEC_3 }; - if ( ! check_msec(mdoc, n, 2, msecs)) + if ( ! check_msec(mdoc, n, 2, 3, 0)) return(0); return(check_stdarg(mdoc, n)); } @@ -788,9 +826,8 @@ pre_rv(PRE_ARGS) static int pre_ex(PRE_ARGS) { - enum mdoc_msec msecs[] = { MSEC_1, MSEC_6, MSEC_8 }; - if ( ! check_msec(mdoc, n, 3, msecs)) + if ( ! check_msec(mdoc, n, 1, 6, 8, 0)) return(0); return(check_stdarg(mdoc, n)); } @@ -799,18 +836,16 @@ pre_ex(PRE_ARGS) static int pre_er(PRE_ARGS) { - enum mdoc_msec msecs[] = { MSEC_2 }; - return(check_msec(mdoc, n, 1, msecs)); + return(check_msec(mdoc, n, 2, 0)); } static int pre_cd(PRE_ARGS) { - enum mdoc_msec msecs[] = { MSEC_4 }; - return(check_msec(mdoc, n, 1, msecs)); + return(check_msec(mdoc, n, 4, 0)); } @@ -818,50 +853,55 @@ static int pre_prologue(PRE_ARGS) { - if (SEC_PROLOGUE != mdoc->lastnamed) - return(mdoc_nerr(mdoc, n, "prologue only")); + return(check_sec(mdoc, n, SEC_PROLOGUE, SEC_CUSTOM)); +} - /* Check for ordering. */ - switch (n->tok) { - case (MDOC_Os): - if (mdoc->meta.title && mdoc->meta.date) - break; - return(mdoc_nerr(mdoc, n, "prologue out-of-order")); - case (MDOC_Dt): - if (NULL == mdoc->meta.title && mdoc->meta.date) - break; - return(mdoc_nerr(mdoc, n, "prologue out-of-order")); - case (MDOC_Dd): - if (NULL == mdoc->meta.title && 0 == mdoc->meta.date) - break; - return(mdoc_nerr(mdoc, n, "prologue out-of-order")); - default: - abort(); - /* NOTREACHED */ - } +static int +pre_dt(PRE_ARGS) +{ - /* Check for repetition. */ + if (0 == mdoc->meta.date || mdoc->meta.os) + if ( ! mdoc_nwarn(mdoc, n, WARN_COMPAT, + "out-of-order prologue")) + return(0); + if (mdoc->meta.title) + if ( ! mdoc_nwarn(mdoc, n, WARN_COMPAT, + "prologue re-invoked")) + return(0); + return(1); +} - switch (n->tok) { - case (MDOC_Os): - if (NULL == mdoc->meta.os) - return(1); - break; - case (MDOC_Dd): - if (0 == mdoc->meta.date) - return(1); - break; - case (MDOC_Dt): - if (NULL == mdoc->meta.title) - return(1); - break; - default: - abort(); - /* NOTREACHED */ - } - return(mdoc_nerr(mdoc, n, "prologue repetition")); +static int +pre_os(PRE_ARGS) +{ + + if (NULL == mdoc->meta.title || 0 == mdoc->meta.date) + if ( ! mdoc_nwarn(mdoc, n, WARN_COMPAT, + "out-of-order prologue")) + return(0); + if (mdoc->meta.os) + if ( ! mdoc_nwarn(mdoc, n, WARN_COMPAT, + "prologue re-invoked")) + return(0); + return(1); +} + + +static int +pre_dd(PRE_ARGS) +{ + + if (mdoc->meta.title || mdoc->meta.os) + if ( ! mdoc_nwarn(mdoc, n, WARN_COMPAT, + "out-of-order prologue")) + return(0); + if (mdoc->meta.date) + if ( ! mdoc_nwarn(mdoc, n, WARN_COMPAT, + "prologue re-invoked")) + return(0); + return(1); } @@ -912,27 +952,14 @@ post_nm(POST_ARGS) static int -post_xr(POST_ARGS) -{ - struct mdoc_node *n; - - if (NULL == (n = mdoc->last->child->next)) - return(1); - if (MSEC_DEFAULT != mdoc_atomsec(n->data.text.string)) - return(1); - return(mdoc_nerr(mdoc, n, "invalid manual section")); -} - - -static int post_at(POST_ARGS) { if (NULL == mdoc->last->child) return(1); - if (ATT_DEFAULT != mdoc_atoatt(mdoc->last->child->data.text.string)) + if (mdoc_a2att(mdoc->last->child->data.text.string)) return(1); - return(mdoc_err(mdoc, "require valid symbol")); + return(mdoc_err(mdoc, "require valid AT&T symbol")); } @@ -1161,6 +1188,17 @@ post_root(POST_ARGS) static int +post_st(POST_ARGS) +{ + + if (mdoc_a2st(mdoc->last->child->data.text.string)) + return(1); + + return(mdoc_warn(mdoc, WARN_SYNTAX, "invalid standard")); +} + + +static int post_sh(POST_ARGS) { @@ -1219,35 +1257,61 @@ post_sh_head(POST_ARGS) char buf[64]; enum mdoc_sec sec; + /* + * Process a new section. Sections are either "named" or + * "custom"; custom sections are user-defined, while named ones + * usually follow a conventional order and may only appear in + * certain manual sections. + */ + assert(MDOC_Sh == mdoc->last->tok); - if ( ! xstrlcats(buf, mdoc->last->child, sizeof(buf))) - return(mdoc_err(mdoc, "argument too long")); + (void)xstrlcpys(buf, mdoc->last->child, sizeof(buf)); sec = mdoc_atosec(buf); + /* The NAME section should always be first. */ + if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec) return(mdoc_warn(mdoc, WARN_SYNTAX, "section NAME should be first")); if (SEC_CUSTOM == sec) return(1); + + /* Check for repeated or out-of-order sections. */ + if (sec == mdoc->lastnamed) return(mdoc_warn(mdoc, WARN_SYNTAX, "section repeated")); if (sec < mdoc->lastnamed) return(mdoc_warn(mdoc, WARN_SYNTAX, - "section out of order")); + "section out of conventional order")); + + /* Check particular section/manual section conventions. */ + + switch (sec) { + case (SEC_LIBRARY): + switch (mdoc->meta.msec) { + case (2): + /* FALLTHROUGH */ + case (3): + break; + default: + return(mdoc_warn(mdoc, WARN_COMPAT, + "section in wrong manual section")); + } + break; + default: + break; + } return(1); } static int -post_fd(POST_ARGS) +pre_fd(PRE_ARGS) { - if (SEC_SYNOPSIS == mdoc->last->sec) - return(1); - return(mdoc_warn(mdoc, WARN_COMPAT, - "suggested only in section SYNOPSIS")); + return(check_sec(mdoc, n, SEC_SYNOPSIS, SEC_CUSTOM)); } @@ -0,0 +1,12 @@ +USD User's Supplementary Documents +PS1 Programmer's Supplementary Documents +AMD Ancestral Manual Documents +SMM System Manager's Manual +URM User's Reference Manual +PRM Programmer's Manual +KM Kernel Manual +IND Manual Master Index +MMI Manual Master Index +LOCAL Local Manual +LOC Local Manual +CON Contributed Software Manual @@ -93,7 +93,7 @@ xstrdup(const char *p) } int -xstrlcats(char *buf, const struct mdoc_node *n, size_t sz) +xstrlcpys(char *buf, const struct mdoc_node *n, size_t sz) { char *p; |