From 0856de670912912cf1e9fc766ca8b128fc340f4d Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 14 Jun 2017 19:39:05 +0000 Subject: [PATCH] simple implementation of the roff(7) .als (macro alias) request, sufficient for pages using po4a(1) --- share/man/man7/roff.7 | 3 +-- usr.bin/mandoc/roff.c | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index a1934569593..0bdb963f7b7 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.70 2017/06/14 14:01:34 schwarze Exp $ +.\" $OpenBSD: roff.7,v 1.71 2017/06/14 19:39:05 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons .\" Copyright (c) 2010,2011,2013-2015,2017 Ingo Schwarze @@ -410,7 +410,6 @@ Create an alias for a number register. Currently unsupported. .It Ic \&als Ar newname oldname Create an alias for a request, string, macro, or diversion. -Currently unsupported. .It Ic \&am Ar macroname Op Ar endmacro Append to a macro definition. The syntax of this request is the same as that of diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index bc99ae530de..950d0c1435c 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.182 2017/06/14 14:01:34 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.183 2017/06/14 19:39:05 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017 Ingo Schwarze @@ -144,6 +144,7 @@ static void roffnode_cleanscope(struct roff *); static void roffnode_pop(struct roff *); static void roffnode_push(struct roff *, enum roff_tok, const char *, int, int); +static enum rofferr roff_als(ROFF_ARGS); static enum rofferr roff_block(ROFF_ARGS); static enum rofferr roff_block_text(ROFF_ARGS); static enum rofferr roff_block_sub(ROFF_ARGS); @@ -341,7 +342,7 @@ static struct roffmac roffs[TOKEN_NONE] = { { roff_line_ignore, NULL, NULL, 0 }, /* ad */ { roff_line_ignore, NULL, NULL, 0 }, /* af */ { roff_unsupp, NULL, NULL, 0 }, /* aln */ - { roff_unsupp, NULL, NULL, 0 }, /* als */ + { roff_als, NULL, NULL, 0 }, /* als */ { roff_block, roff_block_text, roff_block_sub, 0 }, /* am */ { roff_block, roff_block_text, roff_block_sub, 0 }, /* am1 */ { roff_block, roff_block_text, roff_block_sub, 0 }, /* ami */ @@ -1777,8 +1778,10 @@ roff_block(ROFF_ARGS) * appended from roff_block_text() in multiline mode. */ - if (tok == ROFF_de || tok == ROFF_dei) + if (tok == ROFF_de || tok == ROFF_dei) { roff_setstrn(&r->strtab, name, namesz, "", 0, 0); + roff_setstrn(&r->rentab, name, namesz, NULL, 0, 0); + } if (*cp == '\0') return ROFF_IGN; @@ -2247,6 +2250,7 @@ roff_ds(ROFF_ARGS) /* The rest is the value. */ roff_setstrn(&r->strtab, name, namesz, string, strlen(string), ROFF_as == tok); + roff_setstrn(&r->rentab, name, namesz, NULL, 0, 0); return ROFF_IGN; } @@ -2658,6 +2662,7 @@ roff_rm(ROFF_ARGS) name = cp; namesz = roff_getname(r, &cp, ln, (int)(cp - buf->buf)); roff_setstrn(&r->strtab, name, namesz, NULL, 0, 0); + roff_setstrn(&r->rentab, name, namesz, NULL, 0, 0); if (name[namesz] == '\\') break; } @@ -2955,6 +2960,32 @@ roff_manyarg(ROFF_ARGS) return ROFF_IGN; } +static enum rofferr +roff_als(ROFF_ARGS) +{ + char *oldn, *newn, *end, *value; + size_t oldsz, newsz, valsz; + + newn = oldn = buf->buf + pos; + if (*newn == '\0') + return ROFF_IGN; + + newsz = roff_getname(r, &oldn, ln, pos); + if (newn[newsz] == '\\' || *oldn == '\0') + return ROFF_IGN; + + end = oldn; + oldsz = roff_getname(r, &end, ln, oldn - buf->buf); + if (oldsz == 0) + return ROFF_IGN; + + valsz = mandoc_asprintf(&value, ".%.*s \\$*\n", (int)oldsz, oldn); + roff_setstrn(&r->strtab, newn, newsz, value, valsz, 0); + roff_setstrn(&r->rentab, newn, newsz, NULL, 0, 0); + free(value); + return ROFF_IGN; +} + static enum rofferr roff_br(ROFF_ARGS) { @@ -3160,7 +3191,7 @@ roff_so(ROFF_ARGS) static enum rofferr roff_userdef(ROFF_ARGS) { - const char *arg[9], *ap; + const char *arg[16], *ap; char *cp, *n1, *n2; int expand_count, i, ib, ie; size_t asz, rsz; @@ -3172,7 +3203,7 @@ roff_userdef(ROFF_ARGS) r->argc = 0; cp = buf->buf + pos; - for (i = 0; i < 9; i++) { + for (i = 0; i < 16; i++) { if (*cp == '\0') arg[i] = ""; else { -- 2.20.1