aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/chars.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-09-17 08:21:42 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-09-17 08:21:42 +0000
commita2d8a3c6fa626ad4db1bdf75c3eff1b3916d15e9 (patch)
tree928ab960e9fd1846468051a52255f25cc63b7cdd /chars.c
parent3f648213cd789e9c307f834875f09da5e1d86ab1 (diff)
downloadmandoc-a2d8a3c6fa626ad4db1bdf75c3eff1b3916d15e9.tar.gz
mandoc-a2d8a3c6fa626ad4db1bdf75c3eff1b3916d15e9.tar.zst
mandoc-a2d8a3c6fa626ad4db1bdf75c3eff1b3916d15e9.zip
More html.
Initial html encodings in chars.in.
Diffstat (limited to 'chars.c')
-rw-r--r--chars.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/chars.c b/chars.c
index 6c2298f0..eed57247 100644
--- a/chars.c
+++ b/chars.c
@@ -1,4 +1,4 @@
-/* $Id: chars.c,v 1.1 2009/09/17 07:41:28 kristaps Exp $ */
+/* $Id: chars.c,v 1.2 2009/09/17 08:21:42 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -21,15 +21,17 @@
#include "chars.h"
-#define ASCII_PRINT_HI 126
-#define ASCII_PRINT_LO 32
+#define PRINT_HI 126
+#define PRINT_LO 32
struct ln {
struct ln *next;
const char *code;
- const char *out;
+ const char *ascii;
+ const char *html;
size_t codesz;
- size_t outsz;
+ size_t asciisz;
+ size_t htmlsz;
int type;
#define CHARS_CHAR (1 << 0)
#define CHARS_STRING (1 << 1)
@@ -38,18 +40,19 @@ struct ln {
#define LINES_MAX 266
-#define CHAR(w, x, y, z) \
- { NULL, (w), (y), (x), (z), CHARS_CHAR },
-#define STRING(w, x, y, z) \
- { NULL, (w), (y), (x), (z), CHARS_STRING },
-#define BOTH(w, x, y, z) \
- { NULL, (w), (y), (x), (z), CHARS_BOTH },
+#define CHAR(w, x, y, z, a, b) \
+ { NULL, (w), (y), (a), (x), (z), (b), CHARS_CHAR },
+#define STRING(w, x, y, z, a, b) \
+ { NULL, (w), (y), (a), (x), (z), (b), CHARS_STRING },
+#define BOTH(w, x, y, z, a, b) \
+ { NULL, (w), (y), (a), (x), (z), (b), CHARS_BOTH },
static struct ln lines[LINES_MAX] = {
#include "chars.in"
};
struct tbl {
+ enum chars type;
struct ln **htab;
};
@@ -71,7 +74,6 @@ chars_free(void *arg)
}
-/* ARGSUSED */
void *
chars_init(enum chars type)
{
@@ -89,19 +91,14 @@ chars_init(enum chars type)
if (NULL == (tab = malloc(sizeof(struct tbl))))
err(1, "malloc");
+ tab->type = type;
- htab = calloc(ASCII_PRINT_HI - ASCII_PRINT_LO + 1,
- sizeof(struct ln **));
-
+ htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **));
if (NULL == htab)
err(1, "malloc");
for (i = 0; i < LINES_MAX; i++) {
- assert(lines[i].codesz > 0);
- assert(lines[i].code);
- assert(lines[i].out);
-
- hash = (int)lines[i].code[0] - ASCII_PRINT_LO;
+ hash = (int)lines[i].code[0] - PRINT_LO;
if (NULL == (pp = htab[hash])) {
htab[hash] = &lines[i];
@@ -110,7 +107,6 @@ chars_init(enum chars type)
for ( ; pp->next; pp = pp->next)
/* Scan ahead. */ ;
-
pp->next = &lines[i];
}
@@ -145,7 +141,7 @@ find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type)
assert(p);
assert(sz > 0);
- if (p[0] < ASCII_PRINT_LO || p[0] > ASCII_PRINT_HI)
+ if (p[0] < PRINT_LO || p[0] > PRINT_HI)
return(NULL);
/*
@@ -154,7 +150,7 @@ find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type)
* to optimise for repeat hits.
*/
- hash = (int)p[0] - ASCII_PRINT_LO;
+ hash = (int)p[0] - PRINT_LO;
htab = tab->htab;
if (NULL == (pp = htab[hash]))
@@ -163,8 +159,13 @@ find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type)
if (NULL == pp->next) {
if ( ! match(pp, p, sz, type))
return(NULL);
- *rsz = pp->outsz;
- return(pp->out);
+
+ if (CHARS_HTML == tab->type) {
+ *rsz = pp->htmlsz;
+ return(pp->html);
+ }
+ *rsz = pp->asciisz;
+ return(pp->ascii);
}
for (prev = NULL; pp; pp = pp->next) {
@@ -173,16 +174,18 @@ find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type)
continue;
}
- /* Re-order the hash chain. */
-
if (prev) {
prev->next = pp->next;
pp->next = htab[hash];
htab[hash] = pp;
}
- *rsz = pp->outsz;
- return(pp->out);
+ if (CHARS_HTML == tab->type) {
+ *rsz = pp->htmlsz;
+ return(pp->html);
+ }
+ *rsz = pp->asciisz;
+ return(pp->ascii);
}
return(NULL);