diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-07-27 12:02:49 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-07-27 12:02:49 +0000 |
commit | 61fb396c8d05a2962048d0555165f4958be68c85 (patch) | |
tree | 825cade74aa48439c8233a309810779b3cca1b33 | |
parent | 8864a7d6aa589a8b74c798ad8866a7b71e812a78 (diff) | |
download | mandoc-61fb396c8d05a2962048d0555165f4958be68c85.tar.gz |
Correct handling of \*(xx, \*[xxx], \*x versus \x, \(xx, \([xxx]: predefined strings and escape characters, respectively.
-rw-r--r-- | ascii.c | 49 | ||||
-rw-r--r-- | ascii.in | 420 | ||||
-rw-r--r-- | mandoc_char.7 | 44 | ||||
-rw-r--r-- | term.c | 29 | ||||
-rw-r--r-- | term.h | 1 |
5 files changed, 299 insertions, 244 deletions
@@ -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)); @@ -16,205 +16,227 @@ */ /* - * The ASCII translation table. The left-hand side corresponds to the - * escape sequence (\x, \(xx and so on) whose length is listed second - * element. The right-hand side is what's produced by the front-end, - * with the fourth element being its length. + * The ASCII translation tables. STRING corresponds to predefined + * strings (cf. mdoc_samples.7 and tmac/mdoc/doc-nroff). CHAR + * corresponds to special characters (cf. groff_char.7). BOTH contains + * sequences that are equivalent in both STRING and CHAR. * - * Be sure to escape strings. + * Either way, the left-hand side corresponds to the input sequence (\x, + * \(xx, \*(xx and so on) whose length is listed second element. The + * right-hand side is what's produced by the front-end, with the fourth + * element being its length. + * + * Be sure to C-escape strings! */ -LINE("\\", 1, "\\", 1) -LINE("\'", 1, "\'", 1) -LINE("`", 1, "`", 1) -LINE("%", 1, "", 0) -LINE("-", 1, "-", 1) -LINE(" ", 1, " ", 1) -LINE("~", 1, " ", 1) -LINE("^", 1, "", 0) -LINE("0", 1, " ", 1) -LINE(".", 1, ".", 1) -LINE("&", 1, "", 0) -LINE("e", 1, "\\", 1) -LINE("q", 1, "\"", 1) -LINE("|", 1, "", 0) -LINE("rC", 2, "}", 1) -LINE("lC", 2, "{", 1) -LINE("rB", 2, "]", 1) -LINE("lB", 2, "[", 1) -LINE("ra", 2, ">", 1) -LINE("la", 2, "<", 1) -LINE("Lq", 2, "``", 2) -LINE("lq", 2, "``", 2) -LINE("Rq", 2, "\'\'", 2) -LINE("rq", 2, "\'\'", 2) -LINE("oq", 2, "`", 1) -LINE("aq", 2, "\'", 1) -LINE("Bq", 2, ",,", 2) -LINE("bq", 2, ",,", 2) -LINE("<-", 2, "<-", 2) -LINE("->", 2, "->", 2) -LINE("<>", 2, "<>", 2) -LINE("ua", 2, "^", 1) -LINE("da", 2, "v", 1) -LINE("bu", 2, "o", 1) -LINE("ci", 2, "O", 1) -LINE("Ba", 2, "|", 1) -LINE("ba", 2, "|", 1) -LINE("bb", 2, "|", 1) -LINE("co", 2, "(C)", 3) -LINE("rg", 2, "(R)", 3) -LINE("tm", 2, "tm", 2) -LINE("Am", 2, "&", 1) -LINE("Le", 2, "<=", 2) -LINE("<=", 2, "<=", 2) -LINE("Ge", 2, ">=", 2) -LINE(">=", 2, ">=", 2) -LINE("==", 2, "==", 2) -LINE("Ne", 2, "!=", 2) -LINE("!=", 2, "!=", 2) -LINE("Pm", 2, "+-", 2) -LINE("+-", 2, "+-", 2) -LINE("If", 2, "infinity", 8) -LINE("if", 2, "oo", 2) -LINE("Na", 2, "NaN", 3) -LINE("na", 2, "NaN", 3) -LINE("**", 2, "*", 1) -LINE("Gt", 2, ">", 1) -LINE("Lt", 2, "<", 1) -LINE("aa", 2, "\'", 1) -LINE("a~", 2, "~", 1) -LINE("ga", 2, "`", 1) -LINE("en", 2, "-", 1) -LINE("em", 2, "--", 2) -LINE("hy", 2, "-", 1) -LINE("Pi", 2, "pi", 2) -LINE("Fo", 2, "<<", 2) -LINE("Fc", 2, ">>", 2) -LINE("fo", 2, "<", 1) -LINE("fc", 2, ">", 1) -LINE("lh", 2, "<=", 2) -LINE("rh", 2, "=>", 2) -LINE("ae", 2, "ae", 2) -LINE("AE", 2, "AE", 2) -LINE("oe", 2, "oe", 2) -LINE("OE", 2, "OE", 2) -LINE("ss", 2, "ss", 2) -LINE("\'A", 2, "A", 1) -LINE("\'E", 2, "E", 1) -LINE("\'I", 2, "I", 1) -LINE("\'O", 2, "O", 1) -LINE("\'U", 2, "U", 1) -LINE("\'a", 2, "a", 1) -LINE("\'e", 2, "e", 1) -LINE("\'i", 2, "i", 1) -LINE("\'o", 2, "o", 1) -LINE("\'u", 2, "u", 1) -LINE("`A", 2, "A", 1) -LINE("`E", 2, "E", 1) -LINE("`I", 2, "I", 1) -LINE("`O", 2, "O", 1) -LINE("`U", 2, "U", 1) -LINE("`a", 2, "a", 1) -LINE("`e", 2, "e", 1) -LINE("`i", 2, "i", 1) -LINE("`o", 2, "o", 1) -LINE("`u", 2, "u", 1) -LINE("~A", 2, "A", 1) -LINE("~N", 2, "N", 1) -LINE("~O", 2, "O", 1) -LINE("~a", 2, "a", 1) -LINE("~n", 2, "n", 1) -LINE("~o", 2, "o", 1) -LINE("lA", 2, "<=", 2) -LINE("rA", 2, "=>", 2) -LINE("uA", 2, "^", 1) -LINE("dA", 2, "v", 1) -LINE("hA", 2, "<=>", 3) -LINE(":A", 2, "A", 1) -LINE(":E", 2, "E", 1) -LINE(":I", 2, "I", 1) -LINE(":O", 2, "O", 1) -LINE(":U", 2, "U", 1) -LINE(":a", 2, "a", 1) -LINE(":e", 2, "e", 1) -LINE(":i", 2, "i", 1) -LINE(":o", 2, "o", 1) -LINE(":u", 2, "u", 1) -LINE(":y", 2, "y", 1) -LINE("^A", 2, "A", 1) -LINE("^E", 2, "E", 1) -LINE("^I", 2, "I", 1) -LINE("^O", 2, "O", 1) -LINE("^U", 2, "U", 1) -LINE("^a", 2, "a", 1) -LINE("^e", 2, "e", 1) -LINE("^i", 2, "i", 1) -LINE("^o", 2, "o", 1) -LINE("^u", 2, "u", 1) -LINE("-D", 2, "D", 1) -LINE("Sd", 2, "o", 1) -LINE("TP", 2, "b", 1) -LINE("Tp", 2, "b", 1) -LINE(",C", 2, "C", 1) -LINE(",c", 2, "c", 1) -LINE("/L", 2, "L", 1) -LINE("/l", 2, "l", 1) -LINE("/O", 2, "O", 1) -LINE("/o", 2, "o", 1) -LINE("oA", 2, "A", 1) -LINE("oa", 2, "a", 1) -LINE("a^", 2, "^", 1) -LINE("ac", 2, ",", 1) -LINE("ad", 2, "\"", 1) -LINE("ah", 2, "v", 1) -LINE("ao", 2, "o", 1) -LINE("ho", 2, ",", 1) -LINE("ab", 2, "`", 1) -LINE("a\"", 2, "\"", 1) -LINE("a-", 2, "-", 1) -LINE("Cs", 2, "x", 1) -LINE("Do", 2, "$", 1) -LINE("Po", 2, "L", 1) -LINE("Ye", 2, "Y", 1) -LINE("Fn", 2, "f", 1) -LINE("ct", 2, "c", 1) -LINE("ff", 2, "ff", 2) -LINE("fi", 2, "fi", 2) -LINE("fl", 2, "fl", 2) -LINE("Fi", 2, "ffi", 3) -LINE("Fl", 2, "ffl", 3) -LINE("r!", 2, "i", 1) -LINE("r?", 2, "c", 1) -LINE("dd", 2, "=", 1) -LINE("dg", 2, "-", 1) -LINE("ps", 2, "9|", 2) -LINE("sc", 2, "S", 1) -LINE("de", 2, "o", 1) -LINE("tf", 2, ".:.", 3) -LINE("~~", 2, "~~", 2) -LINE("~=", 2, "~=", 2) -LINE("=~", 2, "=~", 2) -LINE("AN", 2, "^", 1) -LINE("OR", 2, "v", 1) -LINE("no", 2, "~", 1) -LINE("fa", 2, "V", 1) -LINE("te", 2, "3", 1) -LINE("Ah", 2, "N", 1) -LINE("Im", 2, "I", 1) -LINE("Re", 2, "R", 1) -LINE("mo", 2, "E", 1) -LINE("nm", 2, "E", 1) -LINE("eq", 2, "=", 1) -LINE("pl", 2, "+", 1) -LINE("di", 2, "-:-", 3) -LINE("mu", 2, "x", 1) -LINE("(=", 2, "(=", 2) -LINE("=)", 2, "=)", 2) -LINE("ap", 2, "~", 1) -LINE("pd", 2, "a", 1) -LINE("gr", 2, "V", 1) -LINE("ca", 2, "(^)", 3) -LINE("cu", 2, "U", 1) -LINE("es", 2, "{}", 2) -LINE("st", 2, "-)", 2) +STRING("left-parenthesis", 16, "(", 1) +STRING("right-parenthesis", 17, ")", 1) +STRING("lp", 2, "(", 1) +STRING("rp", 2, ")", 1) +STRING("left-bracket", 12, "[", 1) +STRING("right-bracket", 13, "]", 1) +STRING("left-singlequote", 16, "`", 1) +STRING("right-singlequote", 17, "\'", 1) +STRING("quote-left", 10, "`", 1) +STRING("quote-right", 11, "\'", 1) +STRING("q", 1, "\"", 1) +STRING("Ne", 2, "!=", 2) +STRING("Le", 2, "<=", 2) +STRING("Ge", 2, ">=", 2) +STRING("Lt", 2, "<", 1) +STRING("Gt", 2, ">", 1) +STRING("Pm", 2, "+-", 2) +STRING("Na", 2, "NaN", 3) +STRING("Ba", 2, "|", 1) +STRING("Am", 2, "&", 1) +STRING("Rq", 2, "\'\'", 2) +STRING("Lq", 2, "``", 2) +STRING("Pi", 2, "pi", 2) +STRING("If", 2, "infinity", 8) + +BOTH("aa", 2, "\'", 1) +BOTH("ga", 2, "`", 1) +BOTH("ua", 2, "^", 1) +BOTH("<=", 2, "<=", 2) +BOTH(">=", 2, ">=", 2) + +CHAR("\\", 1, "\\", 1) +CHAR("\'", 1, "\'", 1) +CHAR("`", 1, "`", 1) +CHAR("%", 1, "", 0) +CHAR("-", 1, "-", 1) +CHAR(" ", 1, " ", 1) +CHAR("~", 1, " ", 1) +CHAR("^", 1, "", 0) +CHAR("0", 1, " ", 1) +CHAR(".", 1, ".", 1) +CHAR("&", 1, "", 0) +CHAR("e", 1, "\\", 1) +CHAR("|", 1, "", 0) +CHAR("rC", 2, "}", 1) +CHAR("lC", 2, "{", 1) +CHAR("rB", 2, "]", 1) +CHAR("lB", 2, "[", 1) +CHAR("ra", 2, ">", 1) +CHAR("la", 2, "<", 1) +CHAR("lq", 2, "``", 2) +CHAR("rq", 2, "\'\'", 2) +CHAR("oq", 2, "`", 1) +CHAR("aq", 2, "\'", 1) +CHAR("Bq", 2, ",,", 2) +CHAR("bq", 2, ",,", 2) +CHAR("<-", 2, "<-", 2) +CHAR("->", 2, "->", 2) +CHAR("<>", 2, "<>", 2) +CHAR("ua", 2, "^", 1) +CHAR("da", 2, "v", 1) +CHAR("bu", 2, "o", 1) +CHAR("ci", 2, "O", 1) +CHAR("ba", 2, "|", 1) +CHAR("bb", 2, "|", 1) +CHAR("co", 2, "(C)", 3) +CHAR("rg", 2, "(R)", 3) +CHAR("tm", 2, "tm", 2) +CHAR("<=", 2, "<=", 2) +CHAR(">=", 2, ">=", 2) +CHAR("==", 2, "==", 2) +CHAR("!=", 2, "!=", 2) +CHAR("+-", 2, "+-", 2) +CHAR("if", 2, "oo", 2) +CHAR("na", 2, "NaN", 3) +CHAR("**", 2, "*", 1) +CHAR("aa", 2, "\'", 1) +CHAR("a~", 2, "~", 1) +CHAR("ga", 2, "`", 1) +CHAR("en", 2, "-", 1) +CHAR("em", 2, "--", 2) +CHAR("hy", 2, "-", 1) +CHAR("Fo", 2, "<<", 2) +CHAR("Fc", 2, ">>", 2) +CHAR("fo", 2, "<", 1) +CHAR("fc", 2, ">", 1) +CHAR("lh", 2, "<=", 2) +CHAR("rh", 2, "=>", 2) +CHAR("ae", 2, "ae", 2) +CHAR("AE", 2, "AE", 2) +CHAR("oe", 2, "oe", 2) +CHAR("OE", 2, "OE", 2) +CHAR("ss", 2, "ss", 2) +CHAR("\'A", 2, "A", 1) +CHAR("\'E", 2, "E", 1) +CHAR("\'I", 2, "I", 1) +CHAR("\'O", 2, "O", 1) +CHAR("\'U", 2, "U", 1) +CHAR("\'a", 2, "a", 1) +CHAR("\'e", 2, "e", 1) +CHAR("\'i", 2, "i", 1) +CHAR("\'o", 2, "o", 1) +CHAR("\'u", 2, "u", 1) +CHAR("`A", 2, "A", 1) +CHAR("`E", 2, "E", 1) +CHAR("`I", 2, "I", 1) +CHAR("`O", 2, "O", 1) +CHAR("`U", 2, "U", 1) +CHAR("`a", 2, "a", 1) +CHAR("`e", 2, "e", 1) +CHAR("`i", 2, "i", 1) +CHAR("`o", 2, "o", 1) +CHAR("`u", 2, "u", 1) +CHAR("~A", 2, "A", 1) +CHAR("~N", 2, "N", 1) +CHAR("~O", 2, "O", 1) +CHAR("~a", 2, "a", 1) +CHAR("~n", 2, "n", 1) +CHAR("~o", 2, "o", 1) +CHAR("lA", 2, "<=", 2) +CHAR("rA", 2, "=>", 2) +CHAR("uA", 2, "^", 1) +CHAR("dA", 2, "v", 1) +CHAR("hA", 2, "<=>", 3) +CHAR(":A", 2, "A", 1) +CHAR(":E", 2, "E", 1) +CHAR(":I", 2, "I", 1) +CHAR(":O", 2, "O", 1) +CHAR(":U", 2, "U", 1) +CHAR(":a", 2, "a", 1) +CHAR(":e", 2, "e", 1) +CHAR(":i", 2, "i", 1) +CHAR(":o", 2, "o", 1) +CHAR(":u", 2, "u", 1) +CHAR(":y", 2, "y", 1) +CHAR("^A", 2, "A", 1) +CHAR("^E", 2, "E", 1) +CHAR("^I", 2, "I", 1) +CHAR("^O", 2, "O", 1) +CHAR("^U", 2, "U", 1) +CHAR("^a", 2, "a", 1) +CHAR("^e", 2, "e", 1) +CHAR("^i", 2, "i", 1) +CHAR("^o", 2, "o", 1) +CHAR("^u", 2, "u", 1) +CHAR("-D", 2, "D", 1) +CHAR("Sd", 2, "o", 1) +CHAR("TP", 2, "b", 1) +CHAR("Tp", 2, "b", 1) +CHAR(",C", 2, "C", 1) +CHAR(",c", 2, "c", 1) +CHAR("/L", 2, "L", 1) +CHAR("/l", 2, "l", 1) +CHAR("/O", 2, "O", 1) +CHAR("/o", 2, "o", 1) +CHAR("oA", 2, "A", 1) +CHAR("oa", 2, "a", 1) +CHAR("a^", 2, "^", 1) +CHAR("ac", 2, ",", 1) +CHAR("ad", 2, "\"", 1) +CHAR("ah", 2, "v", 1) +CHAR("ao", 2, "o", 1) +CHAR("ho", 2, ",", 1) +CHAR("ab", 2, "`", 1) +CHAR("a\"", 2, "\"", 1) +CHAR("a-", 2, "-", 1) +CHAR("Cs", 2, "x", 1) +CHAR("Do", 2, "$", 1) +CHAR("Po", 2, "L", 1) +CHAR("Ye", 2, "Y", 1) +CHAR("Fn", 2, "f", 1) +CHAR("ct", 2, "c", 1) +CHAR("ff", 2, "ff", 2) +CHAR("fi", 2, "fi", 2) +CHAR("fl", 2, "fl", 2) +CHAR("Fi", 2, "ffi", 3) +CHAR("Fl", 2, "ffl", 3) +CHAR("r!", 2, "i", 1) +CHAR("r?", 2, "c", 1) +CHAR("dd", 2, "=", 1) +CHAR("dg", 2, "-", 1) +CHAR("ps", 2, "9|", 2) +CHAR("sc", 2, "S", 1) +CHAR("de", 2, "o", 1) +CHAR("tf", 2, ".:.", 3) +CHAR("~~", 2, "~~", 2) +CHAR("~=", 2, "~=", 2) +CHAR("=~", 2, "=~", 2) +CHAR("AN", 2, "^", 1) +CHAR("OR", 2, "v", 1) +CHAR("no", 2, "~", 1) +CHAR("fa", 2, "V", 1) +CHAR("te", 2, "3", 1) +CHAR("Ah", 2, "N", 1) +CHAR("Im", 2, "I", 1) +CHAR("Re", 2, "R", 1) +CHAR("mo", 2, "E", 1) +CHAR("nm", 2, "E", 1) +CHAR("eq", 2, "=", 1) +CHAR("pl", 2, "+", 1) +CHAR("di", 2, "-:-", 3) +CHAR("mu", 2, "x", 1) +CHAR("(=", 2, "(=", 2) +CHAR("=)", 2, "=)", 2) +CHAR("ap", 2, "~", 1) +CHAR("pd", 2, "a", 1) +CHAR("gr", 2, "V", 1) +CHAR("ca", 2, "(^)", 3) +CHAR("cu", 2, "U", 1) +CHAR("es", 2, "{}", 2) +CHAR("st", 2, "-)", 2) diff --git a/mandoc_char.7 b/mandoc_char.7 index cfeaf16e..168b262b 100644 --- a/mandoc_char.7 +++ b/mandoc_char.7 @@ -39,8 +39,18 @@ Both .Xr mdoc 7 and .Xr man 7 -encode special characters with slightly different semantics; consult the -respective manuals for these escapes. +encode these special characters with +.Sq \eX +.Pq for a one-character escape , +.Sq \e(XX +.Pq two-character , +and +.Sq \e[N] +.Pq N-character . +One may generalise +.Sq \e(XX +as +.Sq \e[XX] . .\" PARAGRAPH .Pp Typographic: @@ -51,10 +61,12 @@ Typographic: .Pq space .It \e^ .Pq zero-width space -.It \e^ +.It \e% .Pq zero-width space .It \e& .Pq zero-width space +.It \e| +.Pq zero-width space .El .\" PARAGRAPH .Pp @@ -111,12 +123,8 @@ Enclosures: .Pq double-quote .It \e(lq .Pq left double-quote -.It \e(Lq -.Pq left double-quote, deprecated .It \e(rq .Pq right double-quote -.It \e(Rq -.Pq right double-quote, deprecated .It \e(oq .Pq left single-quote .It \e(aq @@ -211,36 +219,20 @@ Mathematical: .Pq approximately equals .It \e(=~ .Pq congruent -.It \e(Gt -.Pq greater-than, deprecated -.It \e(Lt -.Pq less-than, deprecated .It \e(<= .Pq less-than-equal -.It \e(Le -.Pq less-than-equal, deprecated .It \e(>= .Pq greater-than-equal -.It \e(Ge -.Pq greater-than-equal .It \e(== .Pq equal .It \e(!= .Pq not equal -.It \e(Ne -.Pq not equal, deprecated .It \e(if .Pq infinity -.It \e(If -.Pq infinity, deprecated .It \e(na .Pq NaN , an extension -.It \e(Na -.Pq NaN, deprecated .It \e(+- .Pq plus-minus -.It \e(Pm -.Pq plus-minus, deprecated .It \e(** .Pq asterisk .El @@ -457,20 +449,14 @@ Special symbols: .Pq bar .It \e(bb .Pq broken bar -.It \e(Ba -.Pq bar, deprecated .It \e(co .Pq copyright .It \e(rg .Pq registered .It \e(tm .Pq trademarked -.It \e& -.Pq non-breaking space .It \ee .Pq escape -.It \e(Am -.Pq ampersand, deprecated .El .\" SECTION .Sh COMPATIBILITY @@ -34,6 +34,8 @@ static void term_free(struct termp *); static void term_pescape(struct termp *, const char **); static void term_nescape(struct termp *, const char *, size_t); +static void term_sescape(struct termp *, + const char *, size_t); static void term_chara(struct termp *, char); static void term_encodea(struct termp *, char); static int term_isopendelim(const char *); @@ -399,9 +401,26 @@ term_nescape(struct termp *p, const char *word, size_t len) rhs = term_a2ascii(p->symtab, word, len, &sz); - if (rhs) - for (i = 0; i < (int)sz; i++) - term_encodea(p, rhs[i]); + if (NULL == rhs) + return; + for (i = 0; i < (int)sz; i++) + term_encodea(p, rhs[i]); +} + + +static void +term_sescape(struct termp *p, const char *word, size_t len) +{ + const char *rhs; + size_t sz; + int i; + + rhs = term_a2res(p->symtab, word, len, &sz); + + if (NULL == rhs) + return; + for (i = 0; i < (int)sz; i++) + term_encodea(p, rhs[i]); } @@ -448,13 +467,13 @@ term_pescape(struct termp *p, const char **word) return; } - term_nescape(p, wp, 2); + term_sescape(p, wp, 2); *word = ++wp; return; case ('['): break; default: - term_nescape(p, wp, 1); + term_sescape(p, wp, 1); *word = wp; return; } @@ -58,6 +58,7 @@ struct termp { void *term_ascii2htab(void); const char *term_a2ascii(void *, const char *, size_t, size_t *); +const char *term_a2res(void *, const char *, size_t, size_t *); void term_asciifree(void *); void term_newln(struct termp *); |