semantics (test identifier for syntactical validity), not at all
following the completely unrelated Heirloom semantics (define
hyperlink target position).
The main motivation for providing this implementation is to get \A
into the parsing class ESCAPE_EXPAND that corresponds to groff parsing
behaviour, which is quite similar to the \B escape sequence (test
numerical expression for syntactical validity). This is likely
to improve parsing of nested escape sequences in the future.
Validation isn't perfect yet. In particular, this implementation
rejects \A arguments containing some escape sequences that groff
allows to slip through. But that is unlikely to cause trouble even
in documents using \A for non-trivial purposes. Rejecting the nested
escapes in question might even improve robustnest because the rejected
names are unlikely to really be usable for practical purposes - no
matter that groff dubiously considers them syntactically valid.
-.\" $Id: roff.7,v 1.119 2022/05/31 18:09:57 schwarze Exp $
+.\" $Id: roff.7,v 1.120 2022/05/31 20:23:05 schwarze Exp $
.\"
.\" Copyright (c) 2010-2019, 2022 Ingo Schwarze <schwarze@openbsd.org>
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Copyright (c) 2010-2019, 2022 Ingo Schwarze <schwarze@openbsd.org>
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
Paddable non-breaking space character.
.It Ic \e0
Digit width space character.
Paddable non-breaking space character.
.It Ic \e0
Digit width space character.
-.It Ic \eA\(aq Ns Ar string Ns Ic \(aq
-Anchor definition; ignored by
+.It Ic \eA\(aq Ns Ar name Ns Ic \(aq
+Interpolate
+.Sq 1
+if
+.Ar name
+is a syntactically valid identifier that can be used
+as a name for a macro or user-defined string, or
+.Sq 0
+otherwise.
+This is a thoroughly non-portable groff extension.
+Heirloom troff uses the same escape sequence with the same syntax
+for a completely different purpose,
+defining a hyperlink target position, also called an
+.Dq anchor ,
+with the given
+.Ar name .
+The Heirloom semantics is not supported by
.Xr mandoc 1 .
.It Ic \ea
Leader character; ignored by
.Xr mandoc 1 .
.It Ic \ea
Leader character; ignored by
-/* $Id: roff.c,v 1.390 2022/05/31 18:09:57 schwarze Exp $ */
+/* $Id: roff.c,v 1.391 2022/05/31 20:23:05 schwarze Exp $ */
/*
* Copyright (c) 2010-2015, 2017-2022 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
/*
* Copyright (c) 2010-2015, 2017-2022 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
*dst++ = '"';
}
continue;
*dst++ = '"';
}
continue;
+ case 'A':
+ ubuf[0] = iendarg > iarg ? '1' : '0';
+ ubuf[1] = '\0';
+ res = ubuf;
+ break;
case 'B':
npos = 0;
ubuf[0] = iendarg > iarg && iend > iendarg &&
case 'B':
npos = 0;
ubuf[0] = iendarg > iarg && iend > iendarg &&
int maxl; /* expected length of the argument */
int argl; /* actual length of the argument */
int c, i; /* for \[char...] parsing */
int maxl; /* expected length of the argument */
int argl; /* actual length of the argument */
int c, i; /* for \[char...] parsing */
+ int valid_A; /* for \A parsing */
enum mandoc_esc rval; /* return value */
enum mandocerr err; /* diagnostic code */
char esc_name;
enum mandoc_esc rval; /* return value */
enum mandocerr err; /* diagnostic code */
char esc_name;
case 'B':
case 'w':
rval = ESCAPE_EXPAND;
term = '\b';
break;
case 'B':
case 'w':
rval = ESCAPE_EXPAND;
term = '\b';
break;
case 'D':
case 'H':
case 'L':
case 'D':
case 'H':
case 'L':
/* Advance to the end of the argument. */
/* Advance to the end of the argument. */
iendarg = iarg;
while (maxl > 0) {
if (buf[iendarg] == '\0') {
iendarg = iarg;
while (maxl > 0) {
if (buf[iendarg] == '\0') {
break;
}
if (buf[iendarg] == buf[iesc]) {
break;
}
if (buf[iendarg] == buf[iesc]) {
- if (roff_escape(buf, ln, iendarg,
- &sesc, &sarg, &sendarg, &send) == ESCAPE_EXPAND)
+ switch (roff_escape(buf, ln, iendarg,
+ &sesc, &sarg, &sendarg, &send)) {
+ case ESCAPE_EXPAND:
+ case ESCAPE_UNDEF:
+ break;
+ default:
+ valid_A = 0;
+ break;
+ }
iendarg = iend = send;
} else {
iendarg = iend = send;
} else {
+ if (buf[iendarg] == ' ' || buf[iendarg] == '\t')
+ valid_A = 0;
if (maxl != INT_MAX)
maxl--;
iend = ++iendarg;
if (maxl != INT_MAX)
maxl--;
iend = ++iendarg;
buf[iarg] == '.' && buf[iarg + 1] == 'T')
rval = ESCAPE_DEVICE;
break;
buf[iarg] == '.' && buf[iarg + 1] == 'T')
rval = ESCAPE_DEVICE;
break;
+ case 'A':
+ if (valid_A == 0)
+ iendarg = iarg;
+ break;
case 'O':
switch (buf[iarg]) {
case '0':
case 'O':
switch (buf[iarg]) {
case '0':