From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout.scc.kit.edu (mailout.scc.kit.edu [129.13.185.202]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id q52NbRH3004847 for ; Sat, 2 Jun 2012 19:37:28 -0400 (EDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-02.scc.kit.edu with esmtp (Exim 4.72 #1) id 1Saxss-00008u-BI; Sun, 03 Jun 2012 01:37:26 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1Saxss-0007o8-9d for tech@mdocml.bsd.lv; Sun, 03 Jun 2012 01:37:26 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1Saxss-0002mj-6U for tech@mdocml.bsd.lv; Sun, 03 Jun 2012 01:37:26 +0200 Received: from schwarze by usta.de with local (Exim 4.77) (envelope-from ) id 1Saxsr-0001qf-QP for tech@mdocml.bsd.lv; Sun, 03 Jun 2012 01:37:25 +0200 Date: Sun, 3 Jun 2012 01:37:25 +0200 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: redefining standard macros Message-ID: <20120602233725.GA24919@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by krisdoz.my.domain id q52NbRH3004847 Hi Kristaps, even though you invited me to just go ahead with usual patches, this one is somewhat unusual, so i'm giving you a chance to comment on it before merging to bsd.lv. What happens is that in andoc.tmac, groff sources an-old.tmac when finding .TH (clobbering previous redefinitions of standard macros), and sources doc.tmac when finding .Dd (clobbering in a similar way). On top of that, an.tmac merely sources andoc.tmac, so stuff before .TH gets clobbered even when explicitely calling groff -man. Fixing that in groff would require to re-architecture the basic way groff handles mdoc(7)/man(7) autodetection; i have no idea how to do that. Besides, many real-world manuals do define macros at the very beginning of the file, so "fixing" this quirk will likely upset some authors of manuals relying on the bug. Yours, Ingo ----- Forwarded message from Ingo Schwarze ----- From: Ingo Schwarze Date: Sat, 2 Jun 2012 17:18:31 -0600 (MDT) To: source-changes@cvs.openbsd.org CVSROOT: /cvs Module name: src Changes by: schwarze@cvs.openbsd.org 2012/06/02 17:18:31 Modified files: usr.bin/mandoc : libmandoc.h read.c roff.c regress/usr.bin/mandoc/roff: Makefile Added files: regress/usr.bin/mandoc/roff/de: Dd.in Dd.out_ascii Dd.out_ascii_opt Makefile TH.in TH.out_ascii TH.out_ascii_opt Log message: 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). ----- End forwarded message ----- Index: usr.bin/mandoc/libmandoc.h =================================================================== RCS file: /cvs/src/usr.bin/mandoc/libmandoc.h,v retrieving revision 1.17 diff -u -p -r1.17 libmandoc.h --- usr.bin/mandoc/libmandoc.h 24 May 2012 23:33:23 -0000 1.17 +++ usr.bin/mandoc/libmandoc.h 2 Jun 2012 22:56:18 -0000 @@ -68,7 +68,7 @@ int man_addspan(struct man *, const st 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 *); Index: usr.bin/mandoc/read.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/read.c,v retrieving revision 1.7 diff -u -p -r1.7 read.c --- usr.bin/mandoc/read.c 24 May 2012 23:33:23 -0000 1.7 +++ usr.bin/mandoc/read.c 2 Jun 2012 22:56:19 -0000 @@ -712,7 +712,7 @@ mparse_alloc(enum mparset inttype, enum curp->inttype = inttype; curp->defos = defos; - curp->roff = roff_alloc(curp); + curp->roff = roff_alloc(inttype, curp); return(curp); } Index: usr.bin/mandoc/roff.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/roff.c,v retrieving revision 1.46 diff -u -p -r1.46 roff.c --- usr.bin/mandoc/roff.c 31 May 2012 01:36:56 -0000 1.46 +++ usr.bin/mandoc/roff.c 2 Jun 2012 22:56:19 -0000 @@ -54,6 +54,8 @@ enum rofft { ROFF_so, ROFF_ta, ROFF_tr, + ROFF_Dd, + ROFF_TH, ROFF_TS, ROFF_TE, ROFF_T_, @@ -98,6 +100,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 */ @@ -191,6 +194,8 @@ static void roff_setstrn(struct roffkv 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); @@ -230,6 +235,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 }, @@ -240,6 +247,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] = { @@ -405,12 +443,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; @@ -1257,6 +1296,32 @@ roff_rm(ROFF_ARGS) roff_setstr(r, name, NULL, 0); } return(ROFF_IGN); +} + +/* 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 */ Index: regress/usr.bin/mandoc/roff/Makefile =================================================================== RCS file: /cvs/src/regress/usr.bin/mandoc/roff/Makefile,v retrieving revision 1.9 diff -u -p -r1.9 Makefile --- regress/usr.bin/mandoc/roff/Makefile 28 May 2012 13:00:51 -0000 1.9 +++ regress/usr.bin/mandoc/roff/Makefile 2 Jun 2012 22:56:19 -0000 @@ -1,6 +1,6 @@ # $OpenBSD: Makefile,v 1.9 2012/05/28 13:00:51 schwarze Exp $ -SUBDIR+= args esc cond string br na ps rm sp +SUBDIR+= args esc cond string br de na ps rm sp ascii groff groff-clean obj-clean tman: _SUBDIRUSE Index: regress/usr.bin/mandoc/roff/de/Dd.in =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/Dd.in diff -N regress/usr.bin/mandoc/roff/de/Dd.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/Dd.in 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,11 @@ +.de At +BSD +.. +.Dd June 3, 2012 +.Dt DE-DD 1 +.Os OpenBSD +.Sh NAME +.Nm de-Dd +.Nd interaction of the Dd macro with de requests +.Sh DESCRIPTION +.At Index: regress/usr.bin/mandoc/roff/de/Dd.out_ascii =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/Dd.out_ascii diff -N regress/usr.bin/mandoc/roff/de/Dd.out_ascii --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/Dd.out_ascii 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,9 @@ +DE-DD(1) OpenBSD Reference Manual DE-DD(1) + +NNAAMMEE + ddee--DDdd - interaction of the Dd macro with de requests + +DDEESSCCRRIIPPTTIIOONN + AT&T UNIX + +OpenBSD June 3, 2012 OpenBSD Index: regress/usr.bin/mandoc/roff/de/Dd.out_ascii_opt =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/Dd.out_ascii_opt diff -N regress/usr.bin/mandoc/roff/de/Dd.out_ascii_opt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/Dd.out_ascii_opt 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,9 @@ +DE-DD(1) OpenBSD Reference Manual DE-DD(1) + +NNAAMMEE + ddee--DDdd - interaction of the Dd macro with de requests + +DDEESSCCRRIIPPTTIIOONN + BSD + +OpenBSD June 3, 2012 OpenBSD Index: regress/usr.bin/mandoc/roff/de/Makefile =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/Makefile diff -N regress/usr.bin/mandoc/roff/de/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/Makefile 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,41 @@ +# $OpenBSD: Makefile,v 1.2 2011/11/17 16:28:46 schwarze Exp $ + +REGRESS_TARGETS=TH Dd + +.include + + +# --- additions to public targets --- + +all ascii: ascii-diff-opt + +ascii-clean: ascii-clean-opt + +groff: TH.out_ascii_opt Dd.out_ascii_opt + +groff-clean: groff-clean-opt + + +# --- local rules --- + +ascii-diff-opt: TH.mandoc_ascii_opt Dd.mandoc_ascii_opt + ${DIFF} ${.CURDIR}/TH.out_ascii_opt TH.mandoc_ascii_opt + ${DIFF} ${.CURDIR}/Dd.out_ascii_opt Dd.mandoc_ascii_opt + +TH.mandoc_ascii_opt: TH.in + ${MANDOC} -man ${.ALLSRC} > ${.TARGET} + +Dd.mandoc_ascii_opt: Dd.in + ${MANDOC} -mdoc ${.ALLSRC} > ${.TARGET} + +ascii-clean-opt: + rm -f TH.mandoc_ascii_opt Dd.mandoc_ascii_opt + +TH.out_ascii_opt: TH.in + /usr/local/bin/nroff -c -man -Tascii ${.ALLSRC} > ${.TARGET} + +Dd.out_ascii_opt: Dd.in + /usr/local/bin/nroff -c -mdoc -Tascii ${.ALLSRC} > ${.TARGET} + +groff-clean-opt: + rm -f TH.out_ascii_opt Dd.out_ascii_opt Index: regress/usr.bin/mandoc/roff/de/TH.in =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/TH.in diff -N regress/usr.bin/mandoc/roff/de/TH.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/TH.in 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,8 @@ +.de BI +.IB \\$1 \\$2 \\$3 +.. +.TH DE-TH 1 "June 3, 2012" OpenBSD +.SH NAME +de-TH - interaction of the TH macro with de requests +.SH DESCRIPTION +.BI bold italic bold Index: regress/usr.bin/mandoc/roff/de/TH.out_ascii =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/TH.out_ascii diff -N regress/usr.bin/mandoc/roff/de/TH.out_ascii --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/TH.out_ascii 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,13 @@ +DE-TH(1) OpenBSD Reference Manual DE-TH(1) + + + +NNAAMMEE + de-TH - interaction of the TH macro with de requests + +DDEESSCCRRIIPPTTIIOONN + bboolldd_i_t_a_l_i_cbboolldd + + + +OpenBSD June 3, 2012 DE-TH(1) Index: regress/usr.bin/mandoc/roff/de/TH.out_ascii_opt =================================================================== RCS file: regress/usr.bin/mandoc/roff/de/TH.out_ascii_opt diff -N regress/usr.bin/mandoc/roff/de/TH.out_ascii_opt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ regress/usr.bin/mandoc/roff/de/TH.out_ascii_opt 2 Jun 2012 22:56:19 -0000 @@ -0,0 +1,13 @@ +DE-TH(1) OpenBSD Reference Manual DE-TH(1) + + + +NNAAMMEE + de-TH - interaction of the TH macro with de requests + +DDEESSCCRRIIPPTTIIOONN + bboolldd_i_t_a_l_i_cbboolldd + + + +OpenBSD June 3, 2012 DE-TH(1) -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv