From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Cc: matthieu@openbsd.org
Subject: [PATCH] implement roff N escape (used in Xenocara)
Date: Sat, 29 Jan 2011 11:18:18 +0100 [thread overview]
Message-ID: <20110129101818.GB12351@iris.usta.de> (raw)
Hi,
even though the roff \N character number escape is marked deprecated
and non-portable even in the Heirloom roff manual, Xenocara docs
use it extensively, so we better implement it, if only for backward
compatibility.
OK?
Hm, now that i'm sending the patch, i see that the mandoc_char(7)
manual part is still missing, so i guess i need to add that when
committing.
Yours,
Ingo
Index: usr.bin/mandoc/chars.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/chars.c,v
retrieving revision 1.15
diff -a -u -p -r1.15 chars.c
--- usr.bin/mandoc/chars.c 4 Jan 2011 22:28:17 -0000 1.15
+++ usr.bin/mandoc/chars.c 29 Jan 2011 10:06:07 -0000
@@ -1,6 +1,7 @@
/* $Id: chars.c,v 1.15 2011/01/04 22:28:17 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
@@ -145,6 +146,27 @@ chars_res2cp(void *arg, const char *p, s
if (NULL == ln)
return(-1);
return(ln->unicode);
+}
+
+
+/*
+ * 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);
}
Index: usr.bin/mandoc/chars.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/chars.h,v
retrieving revision 1.5
diff -a -u -p -r1.5 chars.h
--- usr.bin/mandoc/chars.h 25 Jul 2010 18:05:54 -0000 1.5
+++ usr.bin/mandoc/chars.h 29 Jan 2011 10:06:07 -0000
@@ -1,6 +1,7 @@
/* $Id: chars.h,v 1.5 2010/07/25 18:05:54 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 *);
Index: usr.bin/mandoc/html.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/html.c,v
retrieving revision 1.22
diff -a -u -p -r1.22 html.c
--- usr.bin/mandoc/html.c 16 Jan 2011 19:41:16 -0000 1.22
+++ usr.bin/mandoc/html.c 29 Jan 2011 10:06:08 -0000
@@ -1,6 +1,7 @@
/* $Id: html.c,v 1.22 2011/01/16 19:41:16 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_
"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
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;
Index: usr.bin/mandoc/out.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/out.c,v
retrieving revision 1.11
diff -a -u -p -r1.11 out.c
--- usr.bin/mandoc/out.c 25 Jan 2011 12:07:26 -0000 1.11
+++ usr.bin/mandoc/out.c 29 Jan 2011 10:06:08 -0000
@@ -1,6 +1,7 @@
/* $Id: out.c,v 1.11 2011/01/25 12:07:26 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
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'):
Index: usr.bin/mandoc/out.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/out.h,v
retrieving revision 1.7
diff -a -u -p -r1.7 out.h
--- usr.bin/mandoc/out.h 9 Jan 2011 14:30:48 -0000 1.7
+++ usr.bin/mandoc/out.h 29 Jan 2011 10:06:08 -0000
@@ -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 */
Index: usr.bin/mandoc/term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term.c,v
retrieving revision 1.55
diff -a -u -p -r1.55 term.c
--- usr.bin/mandoc/term.c 4 Jan 2011 22:28:17 -0000 1.55
+++ usr.bin/mandoc/term.c 29 Jan 2011 10:06:08 -0000
@@ -1,7 +1,7 @@
/* $Id: term.c,v 1.55 2011/01/04 22:28:17 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 *w
word += a2roffdeco(&deco, &seq, &ssz);
switch (deco) {
+ case (DECO_NUMBERED):
+ numbered(p, seq, ssz);
+ break;
case (DECO_RESERVED):
res(p, seq, ssz);
break;
Index: regress/usr.bin/mandoc/char/Makefile
===================================================================
RCS file: /cvs/src/regress/usr.bin/mandoc/char/Makefile,v
retrieving revision 1.1
diff -a -u -p -r1.1 Makefile
--- regress/usr.bin/mandoc/char/Makefile 23 Dec 2009 23:40:58 -0000 1.1
+++ regress/usr.bin/mandoc/char/Makefile 29 Jan 2011 10:06:08 -0000
@@ -1,6 +1,6 @@
# $OpenBSD: Makefile,v 1.1 2009/12/23 23:40:58 schwarze Exp $
-SUBDIR+= space
+SUBDIR+= space N
groff groff-clean: _SUBDIRUSE
Index: regress/usr.bin/mandoc/char/N/Makefile
===================================================================
RCS file: regress/usr.bin/mandoc/char/N/Makefile
diff -N regress/usr.bin/mandoc/char/N/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/char/N/Makefile 29 Jan 2011 10:06:08 -0000
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.2 2010/01/01 20:08:17 schwarze Exp $
+
+REGRESS_TARGETS=basic
+GROFF_TARGETS=basic
+
+.include <bsd.regress.mk>
Index: regress/usr.bin/mandoc/char/N/basic.in
===================================================================
RCS file: regress/usr.bin/mandoc/char/N/basic.in
diff -N regress/usr.bin/mandoc/char/N/basic.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/char/N/basic.in 29 Jan 2011 10:06:08 -0000
@@ -0,0 +1,23 @@
+.TH N-BASIC 1 "January 29, 2011"
+.SH NAME
+N-basic \- basic handling of character number escapes
+.SH DESCRIPTION
+basic usage: x\N'65'x
+.br
+too large: x\N'259'x
+.br
+much too large: x\N'2259'x
+.br
+null: x\N'0'x
+.br
+non-numerical content: x\N'XX'x
+.br
+mixed content: x\N'65XX'x
+.br
+empty: x\N''x
+.br
+no quoting: x\N65x
+.br
+non-matching quoting characters: x\NX65Yx
+.br
+end of test document
Index: regress/usr.bin/mandoc/char/N/basic.out_ascii
===================================================================
RCS file: regress/usr.bin/mandoc/char/N/basic.out_ascii
diff -N regress/usr.bin/mandoc/char/N/basic.out_ascii
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/usr.bin/mandoc/char/N/basic.out_ascii 29 Jan 2011 10:06:08 -0000
@@ -0,0 +1,21 @@
+N-BASIC(1) N-BASIC(1)
+
+
+
+N\bNA\bAM\bME\bE
+ N-basic - basic handling of character number escapes
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ basic usage: xAx
+ too large: xx
+ much too large: xx
+ null: x\0x
+ non-numerical content: xX'x
+ mixed content: xAX'x
+ empty: xx
+ no quoting: x5x
+ non-matching quoting characters: xAx
+ end of test document
+
+
+
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next reply other threads:[~2011-01-29 10:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-29 10:18 Ingo Schwarze [this message]
[not found] ` <20110129105342.GB20999@bluenote.herrb.net>
2011-01-29 11:06 ` Ingo Schwarze
2011-01-29 11:35 ` Kristaps Dzonsons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110129101818.GB12351@iris.usta.de \
--to=schwarze@usta.de \
--cc=matthieu@openbsd.org \
--cc=tech@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).