aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2011-01-30 16:05:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2011-01-30 16:05:37 +0000
commitb60f8021eeb3855308829414f20eca4897096fa7 (patch)
treefde633a186759120328c6e6ae9c0e5f2bd8fbe5a
parent739c1eaf9cb6f5ff01a9c080620dfb1542000215 (diff)
downloadmandoc-b60f8021eeb3855308829414f20eca4897096fa7.tar.gz
mandoc-b60f8021eeb3855308829414f20eca4897096fa7.tar.zst
mandoc-b60f8021eeb3855308829414f20eca4897096fa7.zip
Implement the \N'number' (numbered character) roff escape sequence.
Don't use it in new manuals, it is inherently non-portable, but we need it for backward-compatibility with existing manuals, for example in Xenocara driver pages. ok kristaps@ jmc@ and tested by Matthieu Herrb (matthieu at openbsd dot org)
-rw-r--r--chars.c24
-rw-r--r--chars.h4
-rw-r--r--html.c20
-rw-r--r--mandoc_char.719
-rw-r--r--out.c46
-rw-r--r--out.h5
-rw-r--r--term.c18
7 files changed, 125 insertions, 11 deletions
diff --git a/chars.c b/chars.c
index 5edf947a..18bd209b 100644
--- a/chars.c
+++ b/chars.c
@@ -1,6 +1,7 @@
-/* $Id: chars.c,v 1.31 2011/01/02 10:10:57 kristaps Exp $ */
+/* $Id: chars.c,v 1.32 2011/01/30 16:05:37 schwarze Exp $ */
/*
* 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 894008b6..28f48b33 100644
--- a/chars.h
+++ b/chars.h
@@ -1,6 +1,7 @@
-/* $Id: chars.h,v 1.6 2010/07/31 23:52:58 schwarze Exp $ */
+/* $Id: chars.h,v 1.7 2011/01/30 16:05:37 schwarze Exp $ */
/*
* 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 b884dab1..7eba86dd 100644
--- a/html.c
+++ b/html.c
@@ -1,6 +1,7 @@
-/* $Id: html.c,v 1.125 2011/01/13 14:30:13 kristaps Exp $ */
+/* $Id: html.c,v 1.126 2011/01/30 16:05:37 schwarze Exp $ */
/*
- * 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 ff693d77..2bc9baa4 100644
--- a/mandoc_char.7
+++ b/mandoc_char.7
@@ -1,4 +1,4 @@
-.\" $Id: mandoc_char.7,v 1.40 2010/10/29 00:05:53 schwarze Exp $
+.\" $Id: mandoc_char.7,v 1.41 2011/01/30 16:05:37 schwarze Exp $
.\"
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: October 29 2010 $
+.Dd $Mdocdate: January 30 2011 $
.Dt MANDOC_CHAR 7
.Os
.Sh NAME
@@ -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 9a08f6ec..2f006c89 100644
--- a/out.c
+++ b/out.c
@@ -1,6 +1,7 @@
-/* $Id: out.c,v 1.36 2011/01/25 12:07:30 schwarze Exp $ */
+/* $Id: out.c,v 1.37 2011/01/30 16:05:37 schwarze Exp $ */
/*
* 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 f544b8e3..ebd70188 100644
--- a/out.h
+++ b/out.h
@@ -1,6 +1,6 @@
-/* $Id: out.h,v 1.15 2011/01/05 15:37:23 kristaps Exp $ */
+/* $Id: out.h,v 1.16 2011/01/30 16:05:37 schwarze Exp $ */
/*
- * 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 ba54c31d..2116639f 100644
--- a/term.c
+++ b/term.c
@@ -1,7 +1,7 @@
-/* $Id: term.c,v 1.176 2011/01/04 13:14:26 kristaps Exp $ */
+/* $Id: term.c,v 1.177 2011/01/30 16:05:37 schwarze Exp $ */
/*
* 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;