summaryrefslogtreecommitdiffstats
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
commitca0ffe9dcbdc75b372adf897f81053ccd2df605e (patch)
tree9f55cfc1c41bcf64290b9c493f1d4f2403f3780b /chars.c
parentc8b861b7ce8fa5f991be88f5f1b2476c455fe717 (diff)
downloadmandoc-ca0ffe9dcbdc75b372adf897f81053ccd2df605e.tar.gz
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.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/chars.c b/chars.c
index 61569f88..be1077ce 100644
--- a/chars.c
+++ b/chars.c
@@ -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)
{