aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/chars.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-04-29 22:18:12 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-04-29 22:18:12 +0000
commit4d1bc0c8c120742600a57c849edf1b2481c45e26 (patch)
treea34e167ede1a560af694e85311e4283146871c92 /chars.c
parent8686868cc9a1d5c5f474b8cdbd718b152b4d6188 (diff)
downloadmandoc-4d1bc0c8c120742600a57c849edf1b2481c45e26.tar.gz
mandoc-4d1bc0c8c120742600a57c849edf1b2481c45e26.tar.zst
mandoc-4d1bc0c8c120742600a57c849edf1b2481c45e26.zip
Move "chars" interface out of out.h and into mandoc.h. This doesn't
change any code but for renaming functions and types to be consistent with other mandoc.h stuff. The reason for moving into libmandoc is that the rendering of special characters is part of mandoc itself---not an external part. From mandoc(1)'s perspective, this changes nothing, but for other utilities, it's important to have these part of libmandoc. Note this isn't documented [yet] in mandoc.3 because there are some parts I'd like to change around beforehand.
Diffstat (limited to 'chars.c')
-rw-r--r--chars.c50
1 files changed, 21 insertions, 29 deletions
diff --git a/chars.c b/chars.c
index 416d95b5..26539832 100644
--- a/chars.c
+++ b/chars.c
@@ -1,4 +1,4 @@
-/* $Id: chars.c,v 1.35 2011/04/20 22:50:22 kristaps Exp $ */
+/* $Id: chars.c,v 1.36 2011/04/29 22:18:12 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -25,7 +25,6 @@
#include <string.h>
#include "mandoc.h"
-#include "out.h"
#define PRINT_HI 126
#define PRINT_LO 32
@@ -55,32 +54,27 @@ struct ln {
#include "chars.in"
-struct ctab {
- enum chars type;
+struct mchars {
+ enum mcharst type;
struct ln **htab;
};
static inline int match(const struct ln *,
const char *, size_t, int);
-static const struct ln *find(struct ctab *, const char *, size_t, int);
-
+static const struct ln *find(struct mchars *, const char *, size_t, int);
void
-chars_free(void *arg)
+mchars_free(struct mchars *arg)
{
- struct ctab *tab;
-
- tab = (struct ctab *)arg;
- free(tab->htab);
- free(tab);
+ free(arg->htab);
+ free(arg);
}
-
-void *
-chars_init(enum chars type)
+struct mchars *
+mchars_init(enum mcharst type)
{
- struct ctab *tab;
+ struct mchars *tab;
struct ln **htab;
struct ln *pp;
int i, hash;
@@ -92,7 +86,7 @@ chars_init(enum chars type)
* (they're in-line re-ordered during lookup).
*/
- tab = mandoc_malloc(sizeof(struct ctab));
+ tab = mandoc_malloc(sizeof(struct mchars));
htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **));
for (i = 0; i < LINES_MAX; i++) {
@@ -118,11 +112,11 @@ chars_init(enum chars type)
* Special character to Unicode codepoint.
*/
int
-chars_spec2cp(void *arg, const char *p, size_t sz)
+mchars_spec2cp(struct mchars *arg, const char *p, size_t sz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_CHAR);
+ ln = find(arg, p, sz, CHARS_CHAR);
if (NULL == ln)
return(-1);
return(ln->unicode);
@@ -133,11 +127,11 @@ chars_spec2cp(void *arg, const char *p, size_t sz)
* Reserved word to Unicode codepoint.
*/
int
-chars_res2cp(void *arg, const char *p, size_t sz)
+mchars_res2cp(struct mchars *arg, const char *p, size_t sz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_STRING);
+ ln = find(arg, p, sz, CHARS_STRING);
if (NULL == ln)
return(-1);
return(ln->unicode);
@@ -149,7 +143,7 @@ chars_res2cp(void *arg, const char *p, size_t sz)
* represented as a null-terminated string for additional safety.
*/
const char *
-chars_num2char(const char *p, size_t sz)
+mchars_num2char(const char *p, size_t sz)
{
int i;
static char c[2];
@@ -169,11 +163,11 @@ chars_num2char(const char *p, size_t sz)
* Special character to string array.
*/
const char *
-chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz)
+mchars_spec2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_CHAR);
+ ln = find(arg, p, sz, CHARS_CHAR);
if (NULL == ln)
return(NULL);
@@ -186,11 +180,11 @@ chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz)
* Reserved word to string array.
*/
const char *
-chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz)
+mchars_res2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_STRING);
+ ln = find(arg, p, sz, CHARS_STRING);
if (NULL == ln)
return(NULL);
@@ -198,9 +192,8 @@ chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz)
return(ln->ascii);
}
-
static const struct ln *
-find(struct ctab *tab, const char *p, size_t sz, int type)
+find(struct mchars *tab, const char *p, size_t sz, int type)
{
struct ln *pp, *prev;
struct ln **htab;
@@ -243,7 +236,6 @@ find(struct ctab *tab, const char *p, size_t sz, int type)
return(NULL);
}
-
static inline int
match(const struct ln *ln, const char *p, size_t sz, int type)
{