summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-06-29 23:23:16 +0000
committerschwarze <schwarze@openbsd.org>2014-06-29 23:23:16 +0000
commit7963e2c1fb5aee02810e891cd5a8ec981d7732dd (patch)
tree1940aecec291a15bcdf4eaead648a29eab3a6672
parentdelete a #ifdef _KERNEL chunk protecting userland from an #if 0 chunk (diff)
downloadwireguard-openbsd-7963e2c1fb5aee02810e891cd5a8ec981d7732dd.tar.xz
wireguard-openbsd-7963e2c1fb5aee02810e891cd5a8ec981d7732dd.zip
Use the freshly improved roff_getname() function
for the main roff request parsing routine, roff_parse(). In request or macro invocations, escape sequences now terminate the request or macro name; what follows is treated as arguments. Besides, the names of user-defined macros can now contain backslashes (eek!).
-rw-r--r--regress/usr.bin/mandoc/roff/de/Makefile4
-rw-r--r--regress/usr.bin/mandoc/roff/de/escname.in42
-rw-r--r--regress/usr.bin/mandoc/roff/de/escname.out_ascii23
-rw-r--r--usr.bin/mandoc/roff.c33
4 files changed, 83 insertions, 19 deletions
diff --git a/regress/usr.bin/mandoc/roff/de/Makefile b/regress/usr.bin/mandoc/roff/de/Makefile
index 72c0788535f..390c004849c 100644
--- a/regress/usr.bin/mandoc/roff/de/Makefile
+++ b/regress/usr.bin/mandoc/roff/de/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.2 2014/03/30 19:43:19 schwarze Exp $
+# $OpenBSD: Makefile,v 1.3 2014/06/29 23:23:16 schwarze Exp $
-REGRESS_TARGETS=TH Dd
+REGRESS_TARGETS = escname TH Dd
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/roff/de/escname.in b/regress/usr.bin/mandoc/roff/de/escname.in
new file mode 100644
index 00000000000..db5b0506254
--- /dev/null
+++ b/regress/usr.bin/mandoc/roff/de/escname.in
@@ -0,0 +1,42 @@
+.Dd June 29, 2014
+.Dt DE-ESCNAME 1
+.Os OpenBSD
+.Sh NAME
+.Nm de-escname
+.Nd escape sequences in macro names
+.Sh DESCRIPTION
+initial text
+.Pp
+define second = val2
+.de second
+val2
+..
+.Pp
+define first\esecond = val3
+.de first\\second end3
+val3
+.end3
+.Pp
+define first = val1
+.de first\esecond
+val1
+..
+.Pp
+Values (first, second, first\esecond):
+.first
+.second
+.first\\second
+.Pp
+Remove all but second:
+.rm first\\second first\esecond second
+.first
+.second
+.first\\second
+.Pp
+macro seperated from argument by an escape sequence:
+.de witharg
+.Dq \\$1
+..
+.witharg\(enargument
+.Pp
+final text
diff --git a/regress/usr.bin/mandoc/roff/de/escname.out_ascii b/regress/usr.bin/mandoc/roff/de/escname.out_ascii
new file mode 100644
index 00000000000..d4a08f59253
--- /dev/null
+++ b/regress/usr.bin/mandoc/roff/de/escname.out_ascii
@@ -0,0 +1,23 @@
+DE-ESCNAME(1) OpenBSD Reference Manual DE-ESCNAME(1)
+
+NNAAMMEE
+ ddee--eessccnnaammee - escape sequences in macro names
+
+DDEESSCCRRIIPPTTIIOONN
+ initial text
+
+ define second = val2
+
+ define first\second = val3
+
+ define first = val1
+
+ Values (first, second, first\second): val1 val2 val3
+
+ Remove all but second: val2
+
+ macro seperated from argument by an escape sequence: ``argument''
+
+ final text
+
+OpenBSD June 29, 2014 OpenBSD
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 79e771780d4..707efed3332 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.86 2014/06/29 22:38:41 schwarze Exp $ */
+/* $Id: roff.c,v 1.87 2014/06/29 23:23:16 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -196,7 +196,8 @@ static enum rofferr roff_line_ignore(ROFF_ARGS);
static enum rofferr roff_nr(ROFF_ARGS);
static void roff_openeqn(struct roff *, const char *,
int, int, const char *);
-static enum rofft roff_parse(struct roff *, const char *, int *);
+static enum rofft roff_parse(struct roff *, char *, int *,
+ int, int);
static enum rofferr roff_parsetext(char **, size_t *, int, int *);
static enum rofferr roff_res(struct roff *,
char **, size_t *, int, int);
@@ -760,7 +761,7 @@ roff_parseln(struct roff *r, int ln, char **bufp,
* the compilers handle it.
*/
- if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos)))
+ if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos, ln, ppos)))
return(ROFF_CONT);
assert(roffs[t].proc);
@@ -793,28 +794,26 @@ roff_endparse(struct roff *r)
* form of ".foo xxx" in the usual way.
*/
static enum rofft
-roff_parse(struct roff *r, const char *buf, int *pos)
+roff_parse(struct roff *r, char *buf, int *pos, int ln, int ppos)
{
+ char *cp;
const char *mac;
size_t maclen;
enum rofft t;
- if ('\0' == buf[*pos] || '"' == buf[*pos] ||
- '\t' == buf[*pos] || ' ' == buf[*pos])
- return(ROFF_MAX);
+ cp = buf + *pos;
- /* We stop the macro parse at an escape, tab, space, or nil. */
+ if ('\0' == *cp || '"' == *cp || '\t' == *cp || ' ' == *cp)
+ return(ROFF_MAX);
- mac = buf + *pos;
- maclen = strcspn(mac, " \\\t\0");
+ mac = cp;
+ maclen = roff_getname(r, &cp, ln, ppos);
t = (r->current_string = roff_getstrn(r, mac, maclen))
? ROFF_USERDEF : roffhash_find(mac, maclen);
- *pos += (int)maclen;
-
- while (buf[*pos] && ' ' == buf[*pos])
- (*pos)++;
+ if (ROFF_MAX != t)
+ *pos = cp - buf;
return(t);
}
@@ -992,7 +991,7 @@ roff_block_sub(ROFF_ARGS)
i++;
pos = i;
- if (ROFF_MAX != roff_parse(r, *bufp, &pos))
+ if (ROFF_MAX != roff_parse(r, *bufp, &pos, ln, ppos))
return(ROFF_RERUN);
return(ROFF_IGN);
}
@@ -1003,7 +1002,7 @@ roff_block_sub(ROFF_ARGS)
* pulling it out of the hashtable.
*/
- t = roff_parse(r, *bufp, &pos);
+ t = roff_parse(r, *bufp, &pos, ln, ppos);
/*
* Macros other than block-end are only significant
@@ -1038,7 +1037,7 @@ roff_cond_sub(ROFF_ARGS)
rr = r->last->rule;
roffnode_cleanscope(r);
- t = roff_parse(r, *bufp, &pos);
+ t = roff_parse(r, *bufp, &pos, ln, ppos);
/*
* Fully handle known macros when they are structurally