summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2011-01-30 16:05:30 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2011-01-30 16:05:30 +0000
commit3346ee504d87b690135176bebeecf513a150d2a5 (patch)
tree0cd93d66b729a045304560fe34aa9039541c79ba /usr.bin
parent110382a22b114cad0f9431e25d6699be6f8b4f74 (diff)
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@ matthieu@ jmc@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/chars.c24
-rw-r--r--usr.bin/mandoc/chars.h4
-rw-r--r--usr.bin/mandoc/html.c18
-rw-r--r--usr.bin/mandoc/out.c46
-rw-r--r--usr.bin/mandoc/out.h3
-rw-r--r--usr.bin/mandoc/term.c18
6 files changed, 106 insertions, 7 deletions
diff --git a/usr.bin/mandoc/chars.c b/usr.bin/mandoc/chars.c
index e3b192e6d70..0c5a33d8b1b 100644
--- a/usr.bin/mandoc/chars.c
+++ b/usr.bin/mandoc/chars.c
@@ -1,6 +1,7 @@
-/* $Id: chars.c,v 1.15 2011/01/04 22:28:17 schwarze Exp $ */
+/* $Id: chars.c,v 1.16 2011/01/30 16:05:29 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
@@ -148,6 +149,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/usr.bin/mandoc/chars.h b/usr.bin/mandoc/chars.h
index b050994b65c..43ec349332e 100644
--- a/usr.bin/mandoc/chars.h
+++ b/usr.bin/mandoc/chars.h
@@ -1,6 +1,7 @@
-/* $Id: chars.h,v 1.5 2010/07/25 18:05:54 schwarze Exp $ */
+/* $Id: chars.h,v 1.6 2011/01/30 16:05:29 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/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index ae78c352b02..b0261514a8f 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,6 +1,7 @@
-/* $Id: html.c,v 1.22 2011/01/16 19:41:16 schwarze Exp $ */
+/* $Id: html.c,v 1.23 2011/01/30 16:05:29 schwarze Exp $ */
/*
* 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
@@ -89,6 +90,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);
@@ -210,6 +212,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;
@@ -329,6 +342,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/usr.bin/mandoc/out.c b/usr.bin/mandoc/out.c
index 24f215792ff..7f2344adf1a 100644
--- a/usr.bin/mandoc/out.c
+++ b/usr.bin/mandoc/out.c
@@ -1,6 +1,7 @@
-/* $Id: out.c,v 1.11 2011/01/25 12:07:26 schwarze Exp $ */
+/* $Id: out.c,v 1.12 2011/01/30 16:05:29 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
@@ -247,6 +248,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/usr.bin/mandoc/out.h b/usr.bin/mandoc/out.h
index bdf04e69fe9..de7021c7f37 100644
--- a/usr.bin/mandoc/out.h
+++ b/usr.bin/mandoc/out.h
@@ -1,4 +1,4 @@
-/* $Id: out.h,v 1.7 2011/01/09 14:30:48 schwarze Exp $ */
+/* $Id: out.h,v 1.8 2011/01/30 16:05:29 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index e2d136a1cca..3544fd4d603 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,7 +1,7 @@
-/* $Id: term.c,v 1.55 2011/01/04 22:28:17 schwarze Exp $ */
+/* $Id: term.c,v 1.56 2011/01/30 16:05:29 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
@@ -349,6 +349,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;
@@ -507,6 +518,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;