summaryrefslogtreecommitdiffstatshomepage
path: root/ascii.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-07-27 12:02:49 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-07-27 12:02:49 +0000
commit0441b4f4454e1e8fa3005d8b12b9731e24099509 (patch)
treefa9722aef313d84823a932a823613cff4c0b0fb3 /ascii.c
parent34c551bdd57e92ced941777217596e44b5b428c6 (diff)
downloadmandoc-0441b4f4454e1e8fa3005d8b12b9731e24099509.tar.gz
mandoc-0441b4f4454e1e8fa3005d8b12b9731e24099509.tar.zst
mandoc-0441b4f4454e1e8fa3005d8b12b9731e24099509.zip
Correct handling of \*(xx, \*[xxx], \*x versus \x, \(xx, \([xxx]: predefined strings and escape characters, respectively.
Diffstat (limited to 'ascii.c')
-rw-r--r--ascii.c51
1 files changed, 39 insertions, 12 deletions
diff --git a/ascii.c b/ascii.c
index 00ca4d39..60698339 100644
--- a/ascii.c
+++ b/ascii.c
@@ -1,4 +1,4 @@
-/* $Id: ascii.c,v 1.8 2009/06/10 20:18:43 kristaps Exp $ */
+/* $Id: ascii.c,v 1.9 2009/07/27 12:02:49 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -27,9 +27,12 @@
struct line {
const char *code;
const char *out;
- /* 32- and 64-bit alignment safe. */
size_t codesz;
size_t outsz;
+ int type;
+#define ASCII_CHAR (1 << 0)
+#define ASCII_STRING (1 << 1)
+#define ASCII_BOTH (0x03)
};
struct linep {
@@ -37,8 +40,12 @@ struct linep {
struct linep *next;
};
-#define LINE(w, x, y, z) \
- { (w), (y), (x), (z) },
+#define CHAR(w, x, y, z) \
+ { (w), (y), (x), (z), ASCII_CHAR },
+#define STRING(w, x, y, z) \
+ { (w), (y), (x), (z), ASCII_STRING },
+#define BOTH(w, x, y, z) \
+ { (w), (y), (x), (z), ASCII_BOTH },
static const struct line lines[] = {
#include "ascii.in"
};
@@ -50,7 +57,9 @@ struct asciitab {
static inline int match(const struct line *,
- const char *, size_t);
+ const char *, size_t, int);
+static const char * lookup(struct asciitab *, const char *,
+ size_t, size_t *, int);
void
@@ -125,14 +134,29 @@ term_ascii2htab(void)
const char *
term_a2ascii(void *arg, const char *p, size_t sz, size_t *rsz)
{
- struct asciitab *tab;
+
+ return(lookup((struct asciitab *)arg, p,
+ sz, rsz, ASCII_CHAR));
+}
+
+
+const char *
+term_a2res(void *arg, const char *p, size_t sz, size_t *rsz)
+{
+
+ return(lookup((struct asciitab *)arg, p,
+ sz, rsz, ASCII_STRING));
+}
+
+
+static const char *
+lookup(struct asciitab *tab, const char *p,
+ size_t sz, size_t *rsz, int type)
+{
struct linep *pp, *prev;
void **htab;
int hash;
- tab = (struct asciitab *)arg;
- htab = tab->htab;
-
assert(p);
assert(sz > 0);
@@ -147,19 +171,20 @@ term_a2ascii(void *arg, const char *p, size_t sz, size_t *rsz)
*/
hash = (int)p[0] - ASCII_PRINT_LO;
+ htab = tab->htab;
if (NULL == (pp = ((struct linep **)htab)[hash]))
return(NULL);
if (NULL == pp->next) {
- if ( ! match(pp->line, p, sz))
+ if ( ! match(pp->line, p, sz, type))
return(NULL);
*rsz = pp->line->outsz;
return(pp->line->out);
}
for (prev = NULL; pp; pp = pp->next) {
- if ( ! match(pp->line, p, sz)) {
+ if ( ! match(pp->line, p, sz, type)) {
prev = pp;
continue;
}
@@ -181,9 +206,11 @@ term_a2ascii(void *arg, const char *p, size_t sz, size_t *rsz)
static inline int
-match(const struct line *line, const char *p, size_t sz)
+match(const struct line *line, const char *p, size_t sz, int type)
{
+ if ( ! (line->type & type))
+ return(0);
if (line->codesz != sz)
return(0);
return(0 == strncmp(line->code, p, sz));