summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2012-11-19 17:57:23 +0000
committerIngo Schwarze <schwarze@openbsd.org>2012-11-19 17:57:23 +0000
commitf54547a9a73ceac08c89c5a0084f6fcb01900892 (patch)
treeee737a5854f581a5c65cd829890445550ad8d671
parent0fa2afa184f53b477014d5e3f914ff27ee06b04d (diff)
downloadmandoc-f54547a9a73ceac08c89c5a0084f6fcb01900892.tar.gz
In groff, trying to redefine standard man(7) macros before .TH has no effect;
after .TH, it works. Trying to redefine standard mdoc(7) macros before .Dd works when calling groff with the -mdoc command line option, but does not when calling groff with -mandoc; after .Dd, it always works. Arguably, one might call that buggy behaviour in groff, but it is very unlikely that anybody will change groff in this respect (certainly, i'm not volunteering). So let's be bug-compatible. This fixes the vertical spacing in sox(1). Merging from OpenBSD libmandoc.h 1.18, read.c 1.8, roff.c 1.47, June 2, 2012.
-rw-r--r--libmandoc.h4
-rw-r--r--read.c2
-rw-r--r--roff.c69
3 files changed, 70 insertions, 5 deletions
diff --git a/libmandoc.h b/libmandoc.h
index 94eae400..8b4ea5e4 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -67,7 +67,7 @@ int man_addspan(struct man *, const struct tbl_span *);
int man_addeqn(struct man *, const struct eqn *);
void roff_free(struct roff *);
-struct roff *roff_alloc(struct mparse *);
+struct roff *roff_alloc(enum mparset, struct mparse *);
void roff_reset(struct roff *);
enum rofferr roff_parseln(struct roff *, int,
char **, size_t *, int, int *);
diff --git a/read.c b/read.c
index 26356239..a553e6f4 100644
--- a/read.c
+++ b/read.c
@@ -740,7 +740,7 @@ mparse_alloc(enum mparset inttype, enum mandoclevel wlevel,
curp->inttype = inttype;
curp->defos = defos;
- curp->roff = roff_alloc(curp);
+ curp->roff = roff_alloc(inttype, curp);
return(curp);
}
diff --git a/roff.c b/roff.c
index 0b33a3dc..231977a2 100644
--- a/roff.c
+++ b/roff.c
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -59,6 +59,8 @@ enum rofft {
ROFF_so,
ROFF_ta,
ROFF_tr,
+ ROFF_Dd,
+ ROFF_TH,
ROFF_TS,
ROFF_TE,
ROFF_T_,
@@ -103,6 +105,7 @@ struct roffkv {
};
struct roff {
+ enum mparset parsetype; /* requested parse type */
struct mparse *parse; /* parse point */
struct roffnode *last; /* leaf of stack */
enum roffrule rstack[RSTACK_MAX]; /* stack of !`ie' rules */
@@ -198,6 +201,8 @@ static void roff_setstrn(struct roffkv **, const char *,
size_t, const char *, size_t, int);
static enum rofferr roff_so(ROFF_ARGS);
static enum rofferr roff_tr(ROFF_ARGS);
+static enum rofferr roff_Dd(ROFF_ARGS);
+static enum rofferr roff_TH(ROFF_ARGS);
static enum rofferr roff_TE(ROFF_ARGS);
static enum rofferr roff_TS(ROFF_ARGS);
static enum rofferr roff_EQ(ROFF_ARGS);
@@ -238,6 +243,8 @@ static struct roffmac roffs[ROFF_MAX] = {
{ "so", roff_so, NULL, NULL, 0, NULL },
{ "ta", roff_line_ignore, NULL, NULL, 0, NULL },
{ "tr", roff_tr, NULL, NULL, 0, NULL },
+ { "Dd", roff_Dd, NULL, NULL, 0, NULL },
+ { "TH", roff_TH, NULL, NULL, 0, NULL },
{ "TS", roff_TS, NULL, NULL, 0, NULL },
{ "TE", roff_TE, NULL, NULL, 0, NULL },
{ "T&", roff_T_, NULL, NULL, 0, NULL },
@@ -248,6 +255,37 @@ static struct roffmac roffs[ROFF_MAX] = {
{ NULL, roff_userdef, NULL, NULL, 0, NULL },
};
+const char *const __mdoc_reserved[] = {
+ "Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At",
+ "Bc", "Bd", "Bf", "Bk", "Bl", "Bo", "Bq",
+ "Brc", "Bro", "Brq", "Bsx", "Bt", "Bx",
+ "Cd", "Cm", "Db", "Dc", "Dd", "Dl", "Do", "Dq",
+ "Ds", "Dt", "Dv", "Dx", "D1",
+ "Ec", "Ed", "Ef", "Ek", "El", "Em", "em",
+ "En", "Eo", "Eq", "Er", "Es", "Ev", "Ex",
+ "Fa", "Fc", "Fd", "Fl", "Fn", "Fo", "Fr", "Ft", "Fx",
+ "Hf", "Ic", "In", "It", "Lb", "Li", "Lk", "Lp", "LP",
+ "Me", "Ms", "Mt", "Nd", "Nm", "No", "Ns", "Nx",
+ "Oc", "Oo", "Op", "Os", "Ot", "Ox",
+ "Pa", "Pc", "Pf", "Po", "Pp", "PP", "pp", "Pq",
+ "Qc", "Ql", "Qo", "Qq", "Or", "Rd", "Re", "Rs", "Rv",
+ "Sc", "Sf", "Sh", "SH", "Sm", "So", "Sq",
+ "Ss", "St", "Sx", "Sy",
+ "Ta", "Tn", "Ud", "Ux", "Va", "Vt", "Xc", "Xo", "Xr",
+ "%A", "%B", "%D", "%I", "%J", "%N", "%O",
+ "%P", "%Q", "%R", "%T", "%U", "%V",
+ NULL
+};
+
+const char *const __man_reserved[] = {
+ "AT", "B", "BI", "BR", "BT", "DE", "DS", "DT",
+ "EE", "EN", "EQ", "EX", "HF", "HP", "I", "IB", "IP", "IR",
+ "LP", "ME", "MT", "OP", "P", "PD", "PP", "PT",
+ "R", "RB", "RE", "RI", "RS", "SB", "SH", "SM", "SS", "SY",
+ "TE", "TH", "TP", "TQ", "TS", "T&", "UC", "UE", "UR", "YS",
+ NULL
+};
+
/* Array of injected predefined strings. */
#define PREDEFS_MAX 38
static const struct predef predefs[PREDEFS_MAX] = {
@@ -414,12 +452,13 @@ roff_free(struct roff *r)
struct roff *
-roff_alloc(struct mparse *parse)
+roff_alloc(enum mparset type, struct mparse *parse)
{
struct roff *r;
int i;
r = mandoc_calloc(1, sizeof(struct roff));
+ r->parsetype = type;
r->parse = parse;
r->rstackpos = -1;
@@ -1270,6 +1309,32 @@ roff_rm(ROFF_ARGS)
/* ARGSUSED */
static enum rofferr
+roff_Dd(ROFF_ARGS)
+{
+ const char *const *cp;
+
+ if (MPARSE_MDOC != r->parsetype)
+ for (cp = __mdoc_reserved; *cp; cp++)
+ roff_setstr(r, *cp, NULL, 0);
+
+ return(ROFF_CONT);
+}
+
+/* ARGSUSED */
+static enum rofferr
+roff_TH(ROFF_ARGS)
+{
+ const char *const *cp;
+
+ if (MPARSE_MDOC != r->parsetype)
+ for (cp = __man_reserved; *cp; cp++)
+ roff_setstr(r, *cp, NULL, 0);
+
+ return(ROFF_CONT);
+}
+
+/* ARGSUSED */
+static enum rofferr
roff_TE(ROFF_ARGS)
{