summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chars.c22
-rw-r--r--chars.h2
-rw-r--r--html.c18
-rw-r--r--mandoc_char.715
-rw-r--r--out.c44
-rw-r--r--out.h3
-rw-r--r--term.c16
7 files changed, 117 insertions, 3 deletions
diff --git a/chars.c b/chars.c
index b9f4b4fd..ae478800 100644
--- a/chars.c
+++ b/chars.c
@@ -1,6 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -152,6 +153,27 @@ chars_res2cp(void *arg, const char *p, size_t sz)
}
+/*
+ * Numbered character to literal character,
+ * represented as a null-terminated string for additional safety.
+ */
+const char *
+chars_num2char(const char *p, size_t sz)
+{
+ int i;
+ static char c[2];
+
+ if (sz > 3)
+ return(NULL);
+ i = atoi(p);
+ if (i < 0 || i > 255)
+ return(NULL);
+ c[0] = (char)i;
+ c[1] = '\0';
+ return(c);
+}
+
+
/*
* Special character to string array.
*/
diff --git a/chars.h b/chars.h
index 52271f24..70abd3b2 100644
--- a/chars.h
+++ b/chars.h
@@ -1,6 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -25,6 +26,7 @@ enum chars {
};
void *chars_init(enum chars);
+const char *chars_num2char(const char *, size_t);
const char *chars_spec2str(void *, const char *, size_t, size_t *);
int chars_spec2cp(void *, const char *, size_t);
const char *chars_res2str(void *, const char *, size_t, size_t *);
diff --git a/html.c b/html.c
index 846d98ef..af9fdb1a 100644
--- a/html.c
+++ b/html.c
@@ -1,6 +1,7 @@
/* $Id$ */
/*
- * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -93,6 +94,7 @@ static const char *const htmlattrs[ATTR_MAX] = {
"colspan", /* ATTR_COLSPAN */
};
+static void print_num(struct html *, const char *, size_t);
static void print_spec(struct html *, enum roffdeco,
const char *, size_t);
static void print_res(struct html *, const char *, size_t);
@@ -214,6 +216,17 @@ print_gen_head(struct html *h)
static void
+print_num(struct html *h, const char *p, size_t len)
+{
+ const char *rhs;
+
+ rhs = chars_num2char(p, len);
+ if (rhs)
+ putchar((int)*rhs);
+}
+
+
+static void
print_spec(struct html *h, enum roffdeco d, const char *p, size_t len)
{
int cp;
@@ -333,6 +346,9 @@ print_encode(struct html *h, const char *p, int norecurse)
len = a2roffdeco(&deco, &seq, &sz);
switch (deco) {
+ case (DECO_NUMBERED):
+ print_num(h, seq, sz);
+ break;
case (DECO_RESERVED):
print_res(h, seq, sz);
break;
diff --git a/mandoc_char.7 b/mandoc_char.7
index a2fc091a..b7372d26 100644
--- a/mandoc_char.7
+++ b/mandoc_char.7
@@ -513,6 +513,21 @@ implementations:
.It \e*(aa Ta \*(aa Ta acute
.It \e*(ga Ta \*(ga Ta grave
.El
+.Sh NUMBERED CHARACTERS
+For backward compatibility with existing manuals,
+.Xr mandoc 1
+also supports the
+.Pp
+.Dl \eN\(aq Ns Ar number Ns \(aq
+.Pp
+escape sequence, inserting the character
+.Ar number
+from the current character set into the output.
+Of course, this is inherently non-portable and is already marked
+as deprecated in the Heirloom roff manual.
+For example, do not use \eN'34', use \e(dq, or even the plain
+.Sq \(dq
+character where possible.
.Sh COMPATIBILITY
This section documents compatibility of
.Nm
diff --git a/out.c b/out.c
index d76a9702..be54abcd 100644
--- a/out.c
+++ b/out.c
@@ -1,6 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -251,6 +252,49 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz)
break;
}
break;
+
+ case ('N'):
+
+ /*
+ * Sequence of characters: backslash, 'N' (i = 0),
+ * starting delimiter (i = 1), character number (i = 2).
+ */
+
+ *word = wp + 2;
+ *sz = 0;
+
+ /*
+ * Cannot use a digit as a starting delimiter;
+ * but skip the digit anyway.
+ */
+
+ if (isdigit((int)wp[1]))
+ return(2);
+
+ /*
+ * Any non-digit terminates the character number.
+ * That is, the terminating delimiter need not
+ * match the starting delimiter.
+ */
+
+ for (i = 2; isdigit((int)wp[i]); i++)
+ (*sz)++;
+
+ /*
+ * This is only a numbered character
+ * if the character number has at least one digit.
+ */
+
+ if (*sz)
+ *d = DECO_NUMBERED;
+
+ /*
+ * Skip the terminating delimiter, even if it does not
+ * match, and even if there is no character number.
+ */
+
+ return(++i);
+
case ('h'):
/* FALLTHROUGH */
case ('v'):
diff --git a/out.h b/out.h
index 9802389f..f18e42e7 100644
--- a/out.h
+++ b/out.h
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -52,6 +52,7 @@ enum roffscale {
enum roffdeco {
DECO_NONE,
+ DECO_NUMBERED, /* numbered character */
DECO_SPECIAL, /* special character */
DECO_SSPECIAL, /* single-char special */
DECO_RESERVED, /* reserved word */
diff --git a/term.c b/term.c
index 5d18a69d..0ffdedd7 100644
--- a/term.c
+++ b/term.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -353,6 +353,17 @@ term_vspace(struct termp *p)
static void
+numbered(struct termp *p, const char *word, size_t len)
+{
+ const char *rhs;
+
+ rhs = chars_num2char(word, len);
+ if (rhs)
+ encode(p, rhs, 1);
+}
+
+
+static void
spec(struct termp *p, enum roffdeco d, const char *word, size_t len)
{
const char *rhs;
@@ -511,6 +522,9 @@ term_word(struct termp *p, const char *word)
word += a2roffdeco(&deco, &seq, &ssz);
switch (deco) {
+ case (DECO_NUMBERED):
+ numbered(p, seq, ssz);
+ break;
case (DECO_RESERVED):
res(p, seq, ssz);
break;