aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-08-19 17:46:14 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-08-19 17:46:14 +0000
commitef62f27d014f39ece5e16500f0a58cdf13c32030 (patch)
tree2533306af4fe8d2dba7ad5265900817bd690cda4 /roff.c
parent6773fbde9b5bf91ad32caf6aefb8902ba59181fa (diff)
downloadmandoc-ef62f27d014f39ece5e16500f0a58cdf13c32030.tar.gz
mandoc-ef62f27d014f39ece5e16500f0a58cdf13c32030.tar.zst
mandoc-ef62f27d014f39ece5e16500f0a58cdf13c32030.zip
Mostly complete implementation of the 'c' (character available)
roff conditional, except that the .char request still isn't supported and that behaviour differs from groff in many edge cases. But at least valid character names and numbers are now distinguished from invalid ones. This also fixes the bug that parsing of the 'c' conditional was incomplete, which resulted in leaking the tested character to the input parser at the beginning of the body when the condition was inverted.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/roff.c b/roff.c
index 0c733006..9b3002ca 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.335 2018/08/18 22:05:43 schwarze Exp $ */
+/* $Id: roff.c,v 1.336 2018/08/19 17:46:14 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -2168,9 +2168,10 @@ out:
static int
roff_evalcond(struct roff *r, int ln, char *v, int *pos)
{
- char *cp, *name;
- size_t sz;
- int deftype, number, savepos, istrue, wanttrue;
+ const char *start, *end;
+ char *cp, *name;
+ size_t sz;
+ int deftype, len, number, savepos, istrue, wanttrue;
if ('!' == v[*pos]) {
wanttrue = 0;
@@ -2185,12 +2186,50 @@ roff_evalcond(struct roff *r, int ln, char *v, int *pos)
case 'o':
(*pos)++;
return wanttrue;
- case 'c':
case 'e':
case 't':
case 'v':
(*pos)++;
return !wanttrue;
+ case 'c':
+ do {
+ (*pos)++;
+ } while (v[*pos] == ' ');
+
+ /*
+ * Quirk for groff compatibility:
+ * The horizontal tab is neither available nor unavailable.
+ */
+
+ if (v[*pos] == '\t') {
+ (*pos)++;
+ return 0;
+ }
+
+ /* Printable ASCII characters are available. */
+
+ if (v[*pos] != '\\') {
+ (*pos)++;
+ return wanttrue;
+ }
+
+ end = v + ++*pos;
+ switch (mandoc_escape(&end, &start, &len)) {
+ case ESCAPE_SPECIAL:
+ istrue = mchars_spec2cp(start, len) != -1;
+ break;
+ case ESCAPE_UNICODE:
+ istrue = 1;
+ break;
+ case ESCAPE_NUMBERED:
+ istrue = mchars_num2char(start, len) != -1;
+ break;
+ default:
+ istrue = !wanttrue;
+ break;
+ }
+ *pos = end - v;
+ return istrue == wanttrue;
case 'd':
case 'r':
cp = v + *pos + 1;