summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-08-24 12:48:43 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-08-24 12:48:43 +0000
commit81374b2c54962e63129d5934a3bc854804cb73c1 (patch)
tree2a2a5927a674e15fc3612c2bd8f4366b4fb59136
parent3734245a5a164c1ba48ac02cb3131143431b996b (diff)
downloadmandoc-81374b2c54962e63129d5934a3bc854804cb73c1.tar.gz
mandoc-81374b2c54962e63129d5934a3bc854804cb73c1.tar.zst
mandoc-81374b2c54962e63129d5934a3bc854804cb73c1.zip
Have the `ds' processor strip out `\\' as stipulated in groff.7. I only
care because pod2man uses this construct.
-rw-r--r--roff.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/roff.c b/roff.c
index cb962277..b111ad23 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.98 2010/08/20 01:02:07 schwarze Exp $ */
+/* $Id: roff.c,v 1.99 2010/08/24 12:48:43 kristaps Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -136,6 +136,7 @@ static int roff_res(struct roff *,
char **, size_t *, int);
static void roff_setstr(struct roff *,
const char *, const char *);
+static char *roff_strdup(const char *);
/* See roff_hash_find() */
@@ -1035,6 +1036,27 @@ roff_nr(ROFF_ARGS)
}
+static char *
+roff_strdup(const char *name)
+{
+ char *namecopy, *sv;
+
+ /*
+ * This isn't a nice simple mandoc_strdup() because we must
+ * handle roff's stupid double-escape rule.
+ */
+ sv = namecopy = mandoc_malloc(strlen(name) + 1);
+ while (*name) {
+ if ('\\' == *name && '\\' == *(name + 1))
+ name++;
+ *namecopy++ = *name++;
+ }
+
+ *namecopy = '\0';
+ return(sv);
+}
+
+
static void
roff_setstr(struct roff *r, const char *name, const char *string)
{
@@ -1054,8 +1076,9 @@ roff_setstr(struct roff *r, const char *name, const char *string)
} else
free(n->string);
- ROFF_DEBUG("roff: new symbol: [%s] = [%s]\n", name, string);
- n->string = string ? strdup(string) : NULL;
+ /* Don't use mandoc_strdup: clean out double-escapes. */
+ n->string = string ? roff_strdup(string) : NULL;
+ ROFF_DEBUG("roff: new symbol: [%s] = [%s]\n", name, n->string);
}