source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: In -Tascii mode, provide approximations even for some Unicode
Date: Sun, 26 Oct 2014 14:07:28 -0400 (EDT)	[thread overview]
Message-ID: <201410261807.s9QI7SQb022282@krisdoz.my.domain> (raw)

Log Message:
-----------
In -Tascii mode, provide approximations even for some Unicode escape
sequences above codepoint 512 by doing a reverse lookup in the
existing mandoc_char(7) character table.

Again, groff isn't smart enough to do this and silently discards such
escape sequences without printing anything.

Modified Files:
--------------
    mdocml:
        chars.c
        mandoc.h
        mchars_alloc.3
        term_ascii.c

Revision Data
-------------
Index: chars.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/chars.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -Lchars.c -Lchars.c -u -p -r1.60 -r1.61
--- chars.c
+++ chars.c
@@ -149,6 +149,17 @@ mchars_spec2str(const struct mchars *arg
 	return(ln->ascii);
 }
 
+const char *
+mchars_uc2str(int uc)
+{
+	int	 i;
+
+	for (i = 0; i < LINES_MAX; i++)
+		if (uc == lines[i].unicode)
+			return(lines[i].ascii);
+	return("<?>");
+}
+
 static const struct ln *
 find(const struct mchars *tab, const char *p, size_t sz)
 {
Index: term_ascii.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ascii.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.34 -r1.35
--- term_ascii.c
+++ term_ascii.c
@@ -236,9 +236,11 @@ ascii_uc2str(int uc)
 	"j",	"DZ",	"D",	"dz",	"G",	"g",	"HV",	"W",
 	"N",	"n",	"A",	"a",	"AE",	"ae",	"O",	"o"};
 
-	if (uc < 0 || (size_t)uc >= sizeof(tab)/sizeof(tab[0]))
+	if (uc < 0)
 		return("<?>");
-	return(tab[uc]);
+	if ((size_t)uc < sizeof(tab)/sizeof(tab[0]))
+		return(tab[uc]);
+	return(mchars_uc2str(uc));
 }
 
 static size_t
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.165
retrieving revision 1.166
diff -Lmandoc.h -Lmandoc.h -u -p -r1.165 -r1.166
--- mandoc.h
+++ mandoc.h
@@ -426,6 +426,7 @@ enum mandoc_esc	  mandoc_escape(const ch
 struct mchars	 *mchars_alloc(void);
 void		  mchars_free(struct mchars *);
 char		  mchars_num2char(const char *, size_t);
+const char	 *mchars_uc2str(int);
 int		  mchars_num2uc(const char *, size_t);
 int		  mchars_spec2cp(const struct mchars *,
 			const char *, size_t);
Index: mchars_alloc.3
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mchars_alloc.3,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lmchars_alloc.3 -Lmchars_alloc.3 -u -p -r1.1 -r1.2
--- mchars_alloc.3
+++ mchars_alloc.3
@@ -59,6 +59,8 @@
 .Fa "size_t sz"
 .Fa "size_t *rsz"
 .Fc
+.Ft "const char *"
+.Fn mchars_uc2str "int codepoint"
 .Sh DESCRIPTION
 These functions translate Unicode character numbers and
 .Xr roff 7
@@ -199,6 +201,14 @@ output module use this function to rende
 and
 .Ic \eC\(aq Ns Ar name Ns Ic \(aq
 escape sequences.
+.Pp
+The function
+.Fn mchars_uc2str
+performs a reverse lookup of the Unicode
+.Fa codepoint
+and returns an ASCII string representation, or the string
+.Qq <?>
+if none is available.
 .Sh FILES
 These funtions are implemented in the file
 .Pa chars.c .
@@ -218,6 +228,7 @@ following mandoc versions:
 .It Fn mchars_num2uc Ta 1.11.3 Ta \(em Ta \(em
 .It Fn mchars_spec2cp Ta 1.11.2 Ta Fn chars_spec2cp Ta 1.10.5
 .It Fn mchars_spec2str Ta 1.11.2 Ta Fn a2ascii Ta 1.5.3
+.It Fn mchars_uc2str Ta 1.13.2 Ta \(em Ta \(em
 .El
 .Sh AUTHORS
 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-10-26 18:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=201410261807.s9QI7SQb022282@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@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).