From a53099a26f8d62f538d37d1e57468dd089af9b38 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 5 Apr 2014 20:34:57 +0000 Subject: Implement the roff(7) .rr (remove register) request. As reported by sthen@, the perl-5.18 pod2man(1) preamble thinks cool kids use that in manuals. I hope *you* know better. --- roff.7 | 20 ++++++++++++-------- roff.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/roff.7 b/roff.7 index 7732e1ac..195aaf79 100644 --- a/roff.7 +++ b/roff.7 @@ -1,4 +1,4 @@ -.\" $Id: roff.7,v 1.51 2014/03/30 21:28:01 schwarze Exp $ +.\" $Id: roff.7,v 1.52 2014/04/05 20:34:57 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons .\" Copyright (c) 2010, 2011, 2013, 2014 Ingo Schwarze @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: March 30 2014 $ +.Dd $Mdocdate: April 5 2014 $ .Dt ROFF 7 .Os .Sh NAME @@ -898,12 +898,6 @@ This line-scoped request is currently ignored. .Ss \&nh Turn off automatic hyphenation mode. This line-scoped request is currently ignored. -.Ss \&rm -Remove a request, macro or string. -This request is intended to have one argument, -the name of the request, macro or string to be undefined. -Currently, it is ignored including its arguments, -and the number of arguments is not checked. .Ss \&nr Define or change a register. A register is an arbitrary string value that defines some sort of state, @@ -949,6 +943,16 @@ Change point size. This line-scoped request is intended to take one numerical argument. Currently, it is ignored including its arguments, and the number of arguments is not checked. +.Ss \&rm +Remove a request, macro or string. +Its syntax is as follows: +.Pp +.D1 Pf \. Cm \&rm Ar name +.Ss \&rr +Remove a register. +Its syntax is as follows: +.Pp +.D1 Pf \. Cm \&rr Ar name .Ss \&so Include a source file. Its syntax is as follows: diff --git a/roff.c b/roff.c index 25ce76e2..1316bfa9 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.202 2014/03/23 12:11:18 schwarze Exp $ */ +/* $Id: roff.c,v 1.203 2014/04/05 20:34:57 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -62,6 +62,7 @@ enum rofft { ROFF_ns, ROFF_ps, ROFF_rm, + ROFF_rr, ROFF_so, ROFF_ta, ROFF_tr, @@ -202,6 +203,7 @@ static enum rofferr roff_parsetext(char **, size_t *, int, int *); static enum rofferr roff_res(struct roff *, char **, size_t *, int, int); static enum rofferr roff_rm(ROFF_ARGS); +static enum rofferr roff_rr(ROFF_ARGS); static void roff_setstr(struct roff *, const char *, const char *, int); static void roff_setstrn(struct roffkv **, const char *, @@ -251,6 +253,7 @@ static struct roffmac roffs[ROFF_MAX] = { { "ns", roff_line_ignore, NULL, NULL, 0, NULL }, { "ps", roff_line_ignore, NULL, NULL, 0, NULL }, { "rm", roff_rm, NULL, NULL, 0, NULL }, + { "rr", roff_rr, NULL, NULL, 0, NULL }, { "so", roff_so, NULL, NULL, 0, NULL }, { "ta", roff_line_ignore, NULL, NULL, 0, NULL }, { "tr", roff_tr, NULL, NULL, 0, NULL }, @@ -1502,6 +1505,31 @@ roff_nr(ROFF_ARGS) return(ROFF_IGN); } +static enum rofferr +roff_rr(ROFF_ARGS) +{ + struct roffreg *reg, **prev; + const char *name; + char *cp; + + cp = *bufp + pos; + name = roff_getname(r, &cp, ln, pos); + + prev = &r->regtab; + while (1) { + reg = *prev; + if (NULL == reg || !strcmp(name, reg->key.p)) + break; + prev = ®->next; + } + if (NULL != reg) { + *prev = reg->next; + free(reg->key.p); + free(reg); + } + return(ROFF_IGN); +} + /* ARGSUSED */ static enum rofferr roff_rm(ROFF_ARGS) -- cgit v1.2.3-56-ge451