summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-02-23 12:45:19 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-02-23 12:45:19 +0000
commit04e65faa724cfa1cdd43042086fef4fc4631fa61 (patch)
tree180a68324e70042275571bf03295d5fbc926c12b
parent595003e4db851740b65c179dfac991e6874ef56f (diff)
downloadmandoc-04e65faa724cfa1cdd43042086fef4fc4631fa61.tar.gz
More in-file documentation and Linux-isation.
Moved mdoc_macros table definition into macro.c, where it belongs.
-rw-r--r--READE.addmacro21
-rw-r--r--argv.c7
-rw-r--r--hash.c3
-rw-r--r--macro.c219
-rw-r--r--mdoc.326
-rw-r--r--mdoc.c141
-rw-r--r--mdocterm.c7
-rw-r--r--mdoctree.c3
-rw-r--r--mmain.c5
-rw-r--r--mmain.h9
-rw-r--r--private.h9
-rw-r--r--strings.c6
12 files changed, 229 insertions, 227 deletions
diff --git a/READE.addmacro b/READE.addmacro
new file mode 100644
index 00000000..f60fe98e
--- /dev/null
+++ b/READE.addmacro
@@ -0,0 +1,21 @@
+$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/argv.c b/argv.c
index 43a9d004..1d05b2c9 100644
--- a/argv.c
+++ b/argv.c
@@ -26,10 +26,9 @@
#include "private.h"
/*
- * Parse arguments and parameters of macros. Arguments follow the
- * syntax of `-arg [val [valN...]]', while parameters are free-form text
- * following arguments (if any). This file must correctly handle the
- * strange punctuation rules dictated by groff.
+ * Routines to parse arguments of macros. Arguments follow the syntax
+ * of `-arg [val [valN...]]'. Arguments come in all types: quoted
+ * arguments, multiple arguments per value, no-value arguments, etc.
*/
#define ARGS_QUOTED (1 << 0)
diff --git a/hash.c b/hash.c
index 95a1cce7..1e83cc91 100644
--- a/hash.c
+++ b/hash.c
@@ -28,10 +28,9 @@
/*
* Routines for the perfect-hash hashtable used by the parser to look up
* tokens by their string-ified names (`.Fl' -> MDOC_Fl). The
- * allocation penalty for this is 27 * 26 * sizeof(ptr).
+ * allocation penalty for this is 27 * 26 * sizeof(ptr).
*/
-
void
mdoc_tokhash_free(void *htab)
{
diff --git a/macro.c b/macro.c
index 24262fd3..b05962fb 100644
--- a/macro.c
+++ b/macro.c
@@ -28,55 +28,20 @@
/*
* This has scanning/parsing routines, each of which extract a macro and
* its arguments and parameters, then know how to progress to the next
- * macro. Macros are parsed according as follows:
- *
- * ELEMENT: TEXT | epsilon
- * BLOCK: HEAD PUNCT BODY PUNCT BLOCK_TAIL PUNCT
- * BLOCK_TAIL: TAIL | epsilon
- * HEAD: ELEMENT | TEXT | BLOCK | epsilon
- * BODY: ELEMENT | TEXT | BLOCK | epsilon
- * TAIL: TEXT | epsilon
- * PUNCT: TEXT (delimiters) | epsilon
- *
- * These are arranged into a parse tree, an example of which follows:
- *
- * ROOT
- * BLOCK (.Sh)
- * HEAD
- * TEXT (`NAME')
- * BODY
- * ELEMENT (.Nm)
- * TEXT (`mdocml')
- * ELEMENT (.Nd)
- * TEXT (`mdoc macro compiler')
- * BLOCK (.Op)
- * HEAD
- * ELEMENT (.Fl)
- * TEXT (`v')
- * BLOCK (.Op)
- * HEAD
- * ELEMENT (.Fl)
- * TEXT (`v')
- * ELEMENT (.Fl)
- * TEXT (`W')
- * ELEMENT (.Ns)
- * ELEMENT (.Ar)
- * TEXT (`err...')
- *
- * These types are always per-line except for block bodies, which may
- * span multiple lines. Macros are assigned a parsing routine, which
- * corresponds to the type, in the mdoc_macros table.
- *
- * Note that types are general: there can be several parsing routines
- * corresponding to a single type. The macro_text function, for
- * example, parses an ELEMENT type (see the function definition for
- * details) that may be interrupted by further macros; the
- * macro_constant function, on the other hand, parses an ELEMENT type
- * spanning a single line.
+ * macro.
*/
#include "private.h"
+static int macro_obsolete(MACRO_PROT_ARGS);
+static int macro_constant(MACRO_PROT_ARGS);
+static int macro_constant_scoped(MACRO_PROT_ARGS);
+static int macro_constant_delimited(MACRO_PROT_ARGS);
+static int macro_text(MACRO_PROT_ARGS);
+static int macro_scoped(MACRO_PROT_ARGS);
+static int macro_scoped_close(MACRO_PROT_ARGS);
+static int macro_scoped_line(MACRO_PROT_ARGS);
+
#define REWIND_REWIND (1 << 0)
#define REWIND_NOHALT (1 << 1)
#define REWIND_HALT (1 << 2)
@@ -103,6 +68,122 @@ static int perr(struct mdoc *, int, int, int);
#define ENOPARMS (2)
#define EARGVLIM (3)
+/* Central table of library: who gets parsed how. */
+
+const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
+ { NULL, 0 }, /* \" */
+ { macro_constant, MDOC_PROLOGUE }, /* Dd */
+ { macro_constant, MDOC_PROLOGUE }, /* Dt */
+ { macro_constant, MDOC_PROLOGUE }, /* Os */
+ { macro_scoped, 0 }, /* Sh */
+ { macro_scoped, 0 }, /* Ss */
+ { macro_text, 0 }, /* Pp */
+ { macro_scoped_line, MDOC_PARSED }, /* D1 */
+ { macro_scoped_line, MDOC_PARSED }, /* Dl */
+ { macro_scoped, MDOC_EXPLICIT }, /* Bd */
+ { macro_scoped_close, MDOC_EXPLICIT }, /* Ed */
+ { macro_scoped, MDOC_EXPLICIT }, /* Bl */
+ { macro_scoped_close, MDOC_EXPLICIT }, /* El */
+ { macro_scoped, MDOC_PARSED }, /* It */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */
+ { macro_text, MDOC_PARSED }, /* An */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
+ { macro_constant, 0 }, /* Cd */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Dv */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Er */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ev */
+ { macro_constant, 0 }, /* Ex */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fa */
+ { macro_constant, 0 }, /* Fd */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fn */
+ { macro_text, MDOC_PARSED }, /* Ft */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */
+ { macro_constant, 0 }, /* In */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */
+ { macro_constant, 0 }, /* Nd */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Nm */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Op */
+ { macro_obsolete, 0 }, /* Ot */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Pa */
+ { macro_constant, 0 }, /* Rv */
+ /* XXX - .St supposed to be (but isn't) callable. */
+ { macro_constant_delimited, MDOC_PARSED }, /* St */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Va */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Vt */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Xr */
+ { macro_constant, 0 }, /* %A */
+ { macro_constant, 0 }, /* %B */
+ { macro_constant, 0 }, /* %D */
+ { macro_constant, 0 }, /* %I */
+ { macro_constant, 0 }, /* %J */
+ { macro_constant, 0 }, /* %N */
+ { macro_constant, 0 }, /* %O */
+ { macro_constant, 0 }, /* %P */
+ { macro_constant, 0 }, /* %R */
+ { macro_constant, 0 }, /* %T */
+ { macro_constant, 0 }, /* %V */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ao */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */
+ { macro_constant_delimited, 0 }, /* At */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Bc */
+ { macro_scoped, MDOC_EXPLICIT }, /* Bf */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Bo */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Bq */
+ { macro_constant_delimited, MDOC_PARSED }, /* Bsx */
+ { macro_constant_delimited, MDOC_PARSED }, /* Bx */
+ { macro_constant, 0 }, /* Db */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Dc */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Do */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dq */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ec */
+ { macro_scoped_close, MDOC_EXPLICIT }, /* Ef */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Em */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Eo */
+ { macro_constant_delimited, MDOC_PARSED }, /* Fx */
+ { macro_text, MDOC_PARSED }, /* Ms */
+ { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* No */
+ { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* Ns */
+ { macro_constant_delimited, MDOC_PARSED }, /* Nx */
+ { macro_constant_delimited, MDOC_PARSED }, /* Ox */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */
+ { macro_constant_delimited, MDOC_PARSED }, /* Pf */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Po */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pq */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ql */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Qo */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Qq */
+ { macro_scoped_close, MDOC_EXPLICIT }, /* Re */
+ { macro_scoped, MDOC_EXPLICIT }, /* Rs */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Sc */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* So */
+ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Sq */
+ { macro_constant, 0 }, /* Sm */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sx */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sy */
+ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */
+ { macro_constant_delimited, MDOC_PARSED }, /* Ux */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */
+ /* XXX - .Fo supposed to be (but isn't) callable. */
+ { macro_scoped, MDOC_EXPLICIT }, /* Fo */
+ /* XXX - .Fc supposed to be (but isn't) callable. */
+ { macro_scoped_close, MDOC_EXPLICIT }, /* Fc */
+ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */
+ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */
+ { macro_scoped, MDOC_EXPLICIT }, /* Bk */
+ { macro_scoped_close, MDOC_EXPLICIT }, /* Ek */
+ { macro_constant, 0 }, /* Bt */
+ { macro_constant, 0 }, /* Hf */
+ { macro_obsolete, 0 }, /* Fr */
+ { macro_constant, 0 }, /* Ud */
+};
+
+const struct mdoc_macro * const mdoc_macros = __mdoc_macros;
+
static int
perr(struct mdoc *mdoc, int line, int pos, int type)
@@ -460,7 +541,9 @@ rewind_expblock(struct mdoc *mdoc, int tok, int line, int ppos)
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 prior %s",
+ mdoc_node2a(n)));
}
assert(n);
@@ -483,7 +566,9 @@ rewind_impblock(struct mdoc *mdoc, int tok, int line, int ppos)
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 prior %s",
+ mdoc_node2a(n)));
}
assert(n);
@@ -523,7 +608,7 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
* Close out an explicit scope. This optionally parses a TAIL type with
* a set number of TEXT children.
*/
-int
+static int
macro_scoped_close(MACRO_PROT_ARGS)
{
int tt, j, c, lastarg, maxargs, flushed;
@@ -545,7 +630,8 @@ macro_scoped_close(MACRO_PROT_ARGS)
if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) {
if (0 == buf[*pos]) {
- if ( ! rewind_subblock(MDOC_BODY, mdoc, tok, line, ppos))
+ if ( ! rewind_subblock(MDOC_BODY, mdoc,
+ tok, line, ppos))
return(0);
return(rewind_expblock(mdoc, tok, line, ppos));
}
@@ -587,7 +673,8 @@ macro_scoped_close(MACRO_PROT_ARGS)
return(0);
else if (MDOC_MAX != c) {
if ( ! flushed) {
- if ( ! rewind_expblock(mdoc, tok, line, ppos))
+ if ( ! rewind_expblock(mdoc, tok,
+ line, ppos))
return(0);
flushed = 1;
}
@@ -634,7 +721,7 @@ macro_scoped_close(MACRO_PROT_ARGS)
* TEXT (`;')
* TEXT (`;')
*/
-int
+static int
macro_text(MACRO_PROT_ARGS)
{
int la, lastpunct, c, w, argc;
@@ -765,7 +852,7 @@ macro_text(MACRO_PROT_ARGS)
* Note that the `.It' macro, possibly the most difficult (as it has
* embedded scope, etc.) is handled by this routine.
*/
-int
+static int
macro_scoped(MACRO_PROT_ARGS)
{
int c, lastarg, argc;
@@ -816,7 +903,8 @@ macro_scoped(MACRO_PROT_ARGS)
if (0 == buf[*pos]) {
if ( ! mdoc_head_alloc(mdoc, line, ppos, tok))
return(0);
- if ( ! rewind_subblock(MDOC_HEAD, mdoc, tok, line, ppos))
+ if ( ! rewind_subblock(MDOC_HEAD, mdoc,
+ tok, line, ppos))
return(0);
if ( ! mdoc_body_alloc(mdoc, line, ppos, tok))
return(0);
@@ -897,7 +985,7 @@ macro_scoped(MACRO_PROT_ARGS)
* TEXT (`;')
* TEXT (`;')
*/
-int
+static int
macro_scoped_line(MACRO_PROT_ARGS)
{
int lastarg, c;
@@ -969,7 +1057,7 @@ macro_scoped_line(MACRO_PROT_ARGS)
* TEXT (`b')
* TEXT (';')
*/
-int
+static int
macro_constant_scoped(MACRO_PROT_ARGS)
{
int lastarg, flushed, j, c, maxargs;
@@ -1030,20 +1118,24 @@ macro_constant_scoped(MACRO_PROT_ARGS)
return(0);
else if (MDOC_MAX != c) {
if ( ! flushed) {
- if ( ! rewind_subblock(MDOC_HEAD, mdoc, tok, line, ppos))
+ if ( ! rewind_subblock(MDOC_HEAD, mdoc,
+ tok, line, ppos))
return(0);
flushed = 1;
- if ( ! mdoc_body_alloc(mdoc, line, ppos, tok))
+ if ( ! mdoc_body_alloc(mdoc, line,
+ ppos, tok))
return(0);
mdoc->next = MDOC_NEXT_CHILD;
}
- if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf))
+ if ( ! mdoc_macro(mdoc, c, line, lastarg,
+ pos, buf))
return(0);
break;
}
if ( ! flushed && mdoc_isdelim(p)) {
- if ( ! rewind_subblock(MDOC_HEAD, mdoc, tok, line, ppos))
+ if ( ! rewind_subblock(MDOC_HEAD, mdoc,
+ tok, line, ppos))
return(0);
flushed = 1;
if ( ! mdoc_body_alloc(mdoc, line, ppos, tok))
@@ -1083,7 +1175,7 @@ macro_constant_scoped(MACRO_PROT_ARGS)
* ELEMENT (.No)
* TEXT (`b')
*/
-int
+static int
macro_constant_delimited(MACRO_PROT_ARGS)
{
int lastarg, flushed, j, c, maxargs, argc,
@@ -1199,7 +1291,7 @@ macro_constant_delimited(MACRO_PROT_ARGS)
* A constant macro is the simplest classification. It spans an entire
* line.
*/
-int
+static int
macro_constant(MACRO_PROT_ARGS)
{
int c, w, la, argc;
@@ -1266,7 +1358,7 @@ macro_constant(MACRO_PROT_ARGS)
/* ARGSUSED */
-int
+static int
macro_obsolete(MACRO_PROT_ARGS)
{
@@ -1297,7 +1389,8 @@ macro_end(struct mdoc *mdoc)
continue;
if ( ! (MDOC_EXPLICIT & mdoc_macros[n->tok].flags))
continue;
- return(mdoc_nerr(mdoc, n, "macro scope still open on exit"));
+ return(mdoc_nerr(mdoc, n,
+ "macro scope still open on exit"));
}
return(rewind_last(mdoc, mdoc->first));
diff --git a/mdoc.3 b/mdoc.3
index b7edd312..cbeb67ed 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -238,31 +238,31 @@ where capitalised non-terminals represent nodes.
.Pp
Of note are the TEXT nodes following the HEAD, BODY and TAIL nodes of
the BLOCK production. These refer to punctuation marks. Furthermore,
-although a TEXT node will generally have a non-zero-length string, it
-certain cases, such as
-.Dq \&.Bd \-literal ,
+although a TEXT node will generally have a non-zero-length string, in
+the specific case of
+.Sq \&.Bd \-literal ,
an empty line will produce a zero-length string.
.\" PARAGRAPH
.Pp
-The rule-of-thumb for mapping node types to macros follows: in-line
+The rule-of-thumb for mapping node types to macros follows. In-line
elements, such as
-.Dq \&.Em foo ,
+.Sq \&.Em foo ,
are classified as ELEMENT nodes, which can only contain text.
-Multi-line elements such as
-.Dq \&.Sh
+Multi-line elements, such as
+.Sq \&.Sh ,
are BLOCK elements, where the HEAD constitutes line contents and the
BODY constitutes subsequent lines. In-line elements with matching
pairs, such as
-.Dq \&.So
+.Sq \&.So
and
-.Dq \&.Sc ,
+.Sq \&.Sc ,
are BLOCK elements with no HEAD tag. The only exception to this is
-.Dq \&.Eo
+.Sq \&.Eo
and
-.Dq \&.Ec ,
+.Sq \&.Ec ,
which has a HEAD and TAIL node corresponding to the enclosure string.
-TEXT nodes, obviously, constitute text; the ROOT node is the document's
-root.
+TEXT nodes, obviously, constitute text, and the ROOT node is the
+document's root.
.\" SECTION
.Sh EXAMPLES
The following example reads lines from stdin and parses them, operating
diff --git a/mdoc.c b/mdoc.c
index 497fc7cd..68466d11 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -29,9 +29,21 @@
/*
* Main caller in the libmdoc library. This begins the parsing routine,
* handles allocation of data, and so forth. Most of the "work" is done
- * in macro.c, but this orchestrates who does what, when.
+ * in macro.c and validate.c.
*/
+static struct mdoc_arg *argdup(size_t, const struct mdoc_arg *);
+static void argfree(size_t, struct mdoc_arg *);
+static void argcpy(struct mdoc_arg *,
+ const struct mdoc_arg *);
+
+static struct mdoc_node *mdoc_node_alloc(const struct mdoc *);
+static int mdoc_node_append(struct mdoc *,
+ struct mdoc_node *);
+static void mdoc_elem_free(struct mdoc_elem *);
+static void mdoc_text_free(struct mdoc_text *);
+
+
const char *const __mdoc_macronames[MDOC_MAX] = {
"\\\"", "Dd", "Dt", "Os",
"Sh", "Ss", "Pp", "D1",
@@ -89,135 +101,8 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
"emphasis", "symbolic",
};
-/* Central table of library: who gets parsed how. */
-
-const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
- { NULL, 0 }, /* \" */
- { macro_constant, MDOC_PROLOGUE }, /* Dd */
- { macro_constant, MDOC_PROLOGUE }, /* Dt */
- { macro_constant, MDOC_PROLOGUE }, /* Os */
- { macro_scoped, 0 }, /* Sh */
- { macro_scoped, 0 }, /* Ss */
- { macro_text, 0 }, /* Pp */
- { macro_scoped_line, MDOC_PARSED }, /* D1 */
- { macro_scoped_line, MDOC_PARSED }, /* Dl */
- { macro_scoped, MDOC_EXPLICIT }, /* Bd */
- { macro_scoped_close, MDOC_EXPLICIT }, /* Ed */
- { macro_scoped, MDOC_EXPLICIT }, /* Bl */
- { macro_scoped_close, MDOC_EXPLICIT }, /* El */
- { macro_scoped, MDOC_PARSED }, /* It */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */
- { macro_text, MDOC_PARSED }, /* An */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
- { macro_constant, 0 }, /* Cd */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Dv */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Er */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ev */
- { macro_constant, 0 }, /* Ex */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fa */
- { macro_constant, 0 }, /* Fd */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fn */
- { macro_text, MDOC_PARSED }, /* Ft */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */
- { macro_constant, 0 }, /* In */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */
- { macro_constant, 0 }, /* Nd */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Nm */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Op */
- { macro_obsolete, 0 }, /* Ot */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Pa */
- { macro_constant, 0 }, /* Rv */
- /* XXX - .St supposed to be (but isn't) callable. */
- { macro_constant_delimited, MDOC_PARSED }, /* St */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Va */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Vt */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Xr */
- { macro_constant, 0 }, /* %A */
- { macro_constant, 0 }, /* %B */
- { macro_constant, 0 }, /* %D */
- { macro_constant, 0 }, /* %I */
- { macro_constant, 0 }, /* %J */
- { macro_constant, 0 }, /* %N */
- { macro_constant, 0 }, /* %O */
- { macro_constant, 0 }, /* %P */
- { macro_constant, 0 }, /* %R */
- { macro_constant, 0 }, /* %T */
- { macro_constant, 0 }, /* %V */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ao */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */
- { macro_constant_delimited, 0 }, /* At */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Bc */
- { macro_scoped, MDOC_EXPLICIT }, /* Bf */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Bo */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Bq */
- { macro_constant_delimited, MDOC_PARSED }, /* Bsx */
- { macro_constant_delimited, MDOC_PARSED }, /* Bx */
- { macro_constant, 0 }, /* Db */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Dc */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Do */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dq */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ec */
- { macro_scoped_close, MDOC_EXPLICIT }, /* Ef */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Em */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Eo */
- { macro_constant_delimited, MDOC_PARSED }, /* Fx */
- { macro_text, MDOC_PARSED }, /* Ms */
- { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* No */
- { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* Ns */
- { macro_constant_delimited, MDOC_PARSED }, /* Nx */
- { macro_constant_delimited, MDOC_PARSED }, /* Ox */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */
- { macro_constant_delimited, MDOC_PARSED }, /* Pf */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Po */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pq */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ql */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Qo */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Qq */
- { macro_scoped_close, MDOC_EXPLICIT }, /* Re */
- { macro_scoped, MDOC_EXPLICIT }, /* Rs */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Sc */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* So */
- { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Sq */
- { macro_constant, 0 }, /* Sm */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sx */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sy */
- { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */
- { macro_constant_delimited, MDOC_PARSED }, /* Ux */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */
- /* XXX - .Fo supposed to be (but isn't) callable. */
- { macro_scoped, MDOC_EXPLICIT }, /* Fo */
- /* XXX - .Fc supposed to be (but isn't) callable. */
- { macro_scoped_close, MDOC_EXPLICIT }, /* Fc */
- { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */
- { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */
- { macro_scoped, MDOC_EXPLICIT }, /* Bk */
- { macro_scoped_close, MDOC_EXPLICIT }, /* Ek */
- { macro_constant, 0 }, /* Bt */
- { macro_constant, 0 }, /* Hf */
- { macro_obsolete, 0 }, /* Fr */
- { macro_constant, 0 }, /* Ud */
-};
-
const char * const *mdoc_macronames = __mdoc_macronames;
const char * const *mdoc_argnames = __mdoc_argnames;
-const struct mdoc_macro * const mdoc_macros = __mdoc_macros;
-
-static struct mdoc_arg *argdup(size_t, const struct mdoc_arg *);
-static void argfree(size_t, struct mdoc_arg *);
-static void argcpy(struct mdoc_arg *,
- const struct mdoc_arg *);
-
-static struct mdoc_node *mdoc_node_alloc(const struct mdoc *);
-static int mdoc_node_append(struct mdoc *,
- struct mdoc_node *);
-static void mdoc_elem_free(struct mdoc_elem *);
-static void mdoc_text_free(struct mdoc_text *);
-
const struct mdoc_node *
diff --git a/mdocterm.c b/mdocterm.c
index bffdd1f8..24b4132e 100644
--- a/mdocterm.c
+++ b/mdocterm.c
@@ -24,6 +24,10 @@
#include <stdlib.h>
#include <string.h>
+#ifdef __linux__
+#include <time.h>
+#endif
+
#include "mmain.h"
#include "term.h"
@@ -61,9 +65,6 @@ main(int argc, char *argv[])
const struct mdoc *mdoc;
struct termp termp;
- extern int optreset;
- extern int optind;
-
p = mmain_alloc();
if ( ! mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL))
diff --git a/mdoctree.c b/mdoctree.c
index eff84633..ca15ce75 100644
--- a/mdoctree.c
+++ b/mdoctree.c
@@ -34,9 +34,6 @@ main(int argc, char *argv[])
struct mmain *p;
const struct mdoc *mdoc;
- extern int optreset;
- extern int optind;
-
p = mmain_alloc();
if ( ! mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL))
diff --git a/mmain.c b/mmain.c
index b652b5c1..8ceddb0c 100644
--- a/mmain.c
+++ b/mmain.c
@@ -57,6 +57,8 @@ static int msg_warn(void *, int, int,
#ifdef __linux__
extern int getsubopt(char **, char *const *, char **);
+extern size_t strlcpy(char *, const char *, size_t);
+extern size_t strlcat(char *, const char *, size_t);
#endif
@@ -106,7 +108,6 @@ mmain_getopt(struct mmain *p, int argc, char *argv[],
size_t sz;
extern int optind;
- extern int optreset;
sz = strlcpy(opts, "vW:", 32);
assert(sz < 32);
@@ -116,6 +117,8 @@ mmain_getopt(struct mmain *p, int argc, char *argv[],
assert(sz < 32);
}
+ optind = 1;
+
/* LINTED */
while (-1 != (c = getopt(argc, argv, opts)))
switch (c) {
diff --git a/mmain.h b/mmain.h
index 99206279..4010e0a7 100644
--- a/mmain.h
+++ b/mmain.h
@@ -28,12 +28,21 @@
#include "mdoc.h"
+#ifdef __linux__
+#define __dead /* Nothing */
+#endif
+
__BEGIN_DECLS
struct mmain;
struct mmain *mmain_alloc(void);
+#ifdef __linux__
+void mmain_exit(struct mmain *, int)
+ __attribute__((__noreturn__));
+#else
__dead void mmain_exit(struct mmain *, int);
+#endif
int mmain_getopt(struct mmain *, int, char *[],
const char *, const char *, void *,
int (*)(void *, int, const char *));
diff --git a/private.h b/private.h
index 023f904f..89ac19d4 100644
--- a/private.h
+++ b/private.h
@@ -164,15 +164,6 @@ int xstrncmp(const char *, const char *, size_t);
void *xcalloc(size_t, size_t);
char *xstrdup(const char *);
-int macro_obsolete(MACRO_PROT_ARGS);
-int macro_constant(MACRO_PROT_ARGS);
-int macro_constant_scoped(MACRO_PROT_ARGS);
-int macro_constant_delimited(MACRO_PROT_ARGS);
-int macro_text(MACRO_PROT_ARGS);
-int macro_scoped(MACRO_PROT_ARGS);
-int macro_scoped_close(MACRO_PROT_ARGS);
-int macro_scoped_line(MACRO_PROT_ARGS);
-int macro_prologue(MACRO_PROT_ARGS);
int macro_end(struct mdoc *);
__END_DECLS
diff --git a/strings.c b/strings.c
index 4a63aaf5..210b73ef 100644
--- a/strings.c
+++ b/strings.c
@@ -21,10 +21,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#ifndef __OpenBSD__
+#ifdef __linux__
#include <time.h>
#endif
+/*
+ * Convert scalars to and from string format.
+ */
+
#include "private.h"
#ifdef __linux__