summaryrefslogtreecommitdiffstatshomepage
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
commit87afbc0e736c0c51230aed2a74f1f10684872d7e (patch)
tree6a17424d1de64387a59166cd7ba593b96bb279b0
parent7f0efa8fae853b8421869bf16da3d57b9b4d0da0 (diff)
downloadmandoc-87afbc0e736c0c51230aed2a74f1f10684872d7e.tar.gz
mandoc-87afbc0e736c0c51230aed2a74f1f10684872d7e.tar.zst
mandoc-87afbc0e736c0c51230aed2a74f1f10684872d7e.zip
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.c9
-rw-r--r--hash.c5
-rw-r--r--macro.c221
-rw-r--r--mdoc.328
-rw-r--r--mdoc.c143
-rw-r--r--mdocterm.c9
-rw-r--r--mdoctree.c5
-rw-r--r--mmain.c7
-rw-r--r--mmain.h11
-rw-r--r--private.h11
-rw-r--r--strings.c12
12 files changed, 242 insertions, 240 deletions
diff --git a/READE.addmacro b/READE.addmacro
new file mode 100644
index 00000000..b79f90e2
--- /dev/null
+++ b/READE.addmacro
@@ -0,0 +1,21 @@
+$Id: READE.addmacro,v 1.1 2009/02/23 12:45:19 kristaps Exp $
+
+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 5564d867..f26fca0a 100644
--- a/argv.c
+++ b/argv.c
@@ -1,4 +1,4 @@
-/* $Id: argv.c,v 1.26 2009/01/22 14:56:21 kristaps Exp $ */
+/* $Id: argv.c,v 1.27 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 30a01ca8..df0b7c8c 100644
--- a/hash.c
+++ b/hash.c
@@ -1,4 +1,4 @@
-/* $Id: hash.c,v 1.5 2009/01/20 13:44:05 kristaps Exp $ */
+/* $Id: hash.c,v 1.6 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 71955470..acf94fc0 100644
--- a/macro.c
+++ b/macro.c
@@ -1,4 +1,4 @@
-/* $Id: macro.c,v 1.50 2009/02/22 19:23:48 kristaps Exp $ */
+/* $Id: macro.c,v 1.51 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 fbab1706..ae2e12c3 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -1,4 +1,4 @@
-.\" $Id: mdoc.3,v 1.7 2009/02/23 09:46:59 kristaps Exp $
+.\" $Id: mdoc.3,v 1.8 2009/02/23 12:45:19 kristaps Exp $
.\"
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
.\"
@@ -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 62709a00..23f0d7bb 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.47 2009/02/22 22:58:39 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.48 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 46451789..8e5f15d6 100644
--- a/mdocterm.c
+++ b/mdocterm.c
@@ -1,4 +1,4 @@
- /* $Id: mdocterm.c,v 1.4 2009/02/23 09:33:34 kristaps Exp $ */
+ /* $Id: mdocterm.c,v 1.5 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 444dde48..a4147c8b 100644
--- a/mdoctree.c
+++ b/mdoctree.c
@@ -1,4 +1,4 @@
- /* $Id: mdoctree.c,v 1.3 2009/02/23 07:09:13 kristaps Exp $ */
+ /* $Id: mdoctree.c,v 1.4 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 370d23f8..5d2c86ca 100644
--- a/mmain.c
+++ b/mmain.c
@@ -1,4 +1,4 @@
- /* $Id: mmain.c,v 1.2 2009/02/23 07:09:13 kristaps Exp $ */
+ /* $Id: mmain.c,v 1.3 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 af907531..b31020d1 100644
--- a/mmain.h
+++ b/mmain.h
@@ -1,4 +1,4 @@
-/* $Id: mmain.h,v 1.2 2009/02/23 07:09:13 kristaps Exp $ */
+/* $Id: mmain.h,v 1.3 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 1f212548..8e8c41e3 100644
--- a/private.h
+++ b/private.h
@@ -1,4 +1,4 @@
-/* $Id: private.h,v 1.78 2009/02/22 14:31:08 kristaps Exp $ */
+/* $Id: private.h,v 1.79 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 d92f1f29..1d4fd305 100644
--- a/strings.c
+++ b/strings.c
@@ -1,4 +1,4 @@
-/* $Id: strings.c,v 1.13 2009/02/21 21:00:06 kristaps Exp $ */
+/* $Id: strings.c,v 1.14 2009/02/23 12:45:19 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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__
@@ -128,9 +132,9 @@ mdoc_atotime(const char *p)
(void)memset(&tm, 0, sizeof(struct tm));
- if (xstrcmp(p, "$Mdocdate: February 21 2009 $"))
+ if (xstrcmp(p, "$Mdocdate: February 23 2009 $"))
return(time(NULL));
- if ((pp = strptime(p, "$Mdocdate: February 21 2009 $", &tm)) && 0 == *pp)
+ if ((pp = strptime(p, "$Mdocdate: February 23 2009 $", &tm)) && 0 == *pp)
return(mktime(&tm));
/* XXX - this matches "June 1999", which is wrong. */
if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp)