version 1.68, 2015/10/13 22:59:54 |
version 1.79, 2020/02/13 16:18:29 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011, 2014, 2015, 2017, 2018, 2020 |
|
* Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <stddef.h> |
#include <stddef.h> |
#include <stdint.h> |
#include <stdint.h> |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
Line 46 static struct ln lines[] = { |
|
Line 48 static struct ln lines[] = { |
|
/* Spacing. */ |
/* Spacing. */ |
{ " ", ascii_nbrsp, 0x00a0 }, |
{ " ", ascii_nbrsp, 0x00a0 }, |
{ "~", ascii_nbrsp, 0x00a0 }, |
{ "~", ascii_nbrsp, 0x00a0 }, |
{ "0", " ", 0x2002 }, |
{ "0", ascii_nbrsp, 0x00a0 }, |
{ "|", "", 0 }, |
|
{ "^", "", 0 }, |
|
{ "&", "", 0 }, |
|
{ "%", "", 0 }, |
|
{ ":", ascii_break, 0 }, |
{ ":", ascii_break, 0 }, |
/* XXX The following three do not really belong here. */ |
|
{ "t", "", 0 }, |
|
{ "c", "", 0 }, |
|
{ "}", "", 0 }, |
|
|
|
/* Lines. */ |
/* Lines. */ |
{ "ba", "|", 0x007c }, |
{ "ba", "|", 0x007c }, |
{ "br", "|", 0x2502 }, |
{ "br", "|", 0x2502 }, |
{ "ul", "_", 0x005f }, |
{ "ul", "_", 0x005f }, |
|
{ "_", "_", 0x005f }, |
|
{ "ru", "_", 0x005f }, |
{ "rn", "-", 0x203e }, |
{ "rn", "-", 0x203e }, |
{ "bb", "|", 0x00a6 }, |
{ "bb", "|", 0x00a6 }, |
{ "sl", "/", 0x002f }, |
{ "sl", "/", 0x002f }, |
Line 69 static struct ln lines[] = { |
|
Line 65 static struct ln lines[] = { |
|
/* Text markers. */ |
/* Text markers. */ |
{ "ci", "O", 0x25cb }, |
{ "ci", "O", 0x25cb }, |
{ "bu", "+\bo", 0x2022 }, |
{ "bu", "+\bo", 0x2022 }, |
{ "dd", "|\b=", 0x2021 }, |
{ "dd", "<**>", 0x2021 }, |
{ "dg", "|\b-", 0x2020 }, |
{ "dg", "<*>", 0x2020 }, |
{ "lz", "<>", 0x25ca }, |
{ "lz", "<>", 0x25ca }, |
{ "sq", "[]", 0x25a1 }, |
{ "sq", "[]", 0x25a1 }, |
{ "ps", "<par>", 0x00b6 }, |
{ "ps", "<paragraph>", 0x00b6 }, |
{ "sc", "<sec>", 0x00a7 }, |
{ "sc", "<section>", 0x00a7 }, |
{ "lh", "<=", 0x261c }, |
{ "lh", "<=", 0x261c }, |
{ "rh", "=>", 0x261e }, |
{ "rh", "=>", 0x261e }, |
{ "at", "@", 0x0040 }, |
{ "at", "@", 0x0040 }, |
{ "sh", "#", 0x0023 }, |
{ "sh", "#", 0x0023 }, |
{ "CR", "_|", 0x21b5 }, |
{ "CR", "<cr>", 0x21b5 }, |
{ "OK", "\\/", 0x2713 }, |
{ "OK", "\\/", 0x2713 }, |
|
{ "CL", "C", 0x2663 }, |
|
{ "SP", "S", 0x2660 }, |
|
{ "HE", "H", 0x2665 }, |
|
{ "DI", "D", 0x2666 }, |
|
|
/* Legal symbols. */ |
/* Legal symbols. */ |
{ "co", "(C)", 0x00a9 }, |
{ "co", "(C)", 0x00a9 }, |
Line 101 static struct ln lines[] = { |
|
Line 101 static struct ln lines[] = { |
|
{ "bq", ",", 0x201a }, |
{ "bq", ",", 0x201a }, |
{ "lq", "\"", 0x201c }, |
{ "lq", "\"", 0x201c }, |
{ "rq", "\"", 0x201d }, |
{ "rq", "\"", 0x201d }, |
{ "Lq", "``", 0x201c }, |
{ "Lq", "\"", 0x201c }, |
{ "Rq", "''", 0x201d }, |
{ "Rq", "\"", 0x201d }, |
{ "oq", "`", 0x2018 }, |
{ "oq", "`", 0x2018 }, |
{ "cq", "\'", 0x2019 }, |
{ "cq", "\'", 0x2019 }, |
{ "aq", "\'", 0x0027 }, |
{ "aq", "\'", 0x0027 }, |
Line 161 static struct ln lines[] = { |
|
Line 161 static struct ln lines[] = { |
|
{ "uA", "=\b^", 0x21d1 }, |
{ "uA", "=\b^", 0x21d1 }, |
{ "dA", "=\bv", 0x21d3 }, |
{ "dA", "=\bv", 0x21d3 }, |
{ "vA", "^=v", 0x21d5 }, |
{ "vA", "^=v", 0x21d5 }, |
|
{ "an", "-", 0x23af }, |
|
|
/* Logic. */ |
/* Logic. */ |
{ "AN", "^", 0x2227 }, |
{ "AN", "^", 0x2227 }, |
{ "OR", "v", 0x2228 }, |
{ "OR", "v", 0x2228 }, |
{ "no", "~", 0x00ac }, |
{ "no", "~", 0x00ac }, |
{ "tno", "~", 0x00ac }, |
{ "tno", "~", 0x00ac }, |
{ "te", "3", 0x2203 }, |
{ "te", "<there\037exists>", 0x2203 }, |
{ "fa", "-\bV", 0x2200 }, |
{ "fa", "<for\037all>", 0x2200 }, |
{ "st", "-)", 0x220b }, |
{ "st", "<such\037that>", 0x220b }, |
{ "tf", ".:.", 0x2234 }, |
{ "tf", "<therefore>", 0x2234 }, |
{ "3d", ".:.", 0x2234 }, |
{ "3d", "<therefore>", 0x2234 }, |
{ "or", "|", 0x007c }, |
{ "or", "|", 0x007c }, |
|
|
/* Mathematicals. */ |
/* Mathematicals. */ |
Line 187 static struct ln lines[] = { |
|
Line 188 static struct ln lines[] = { |
|
{ "tmu", "x", 0x00d7 }, |
{ "tmu", "x", 0x00d7 }, |
{ "c*", "O\bx", 0x2297 }, |
{ "c*", "O\bx", 0x2297 }, |
{ "c+", "O\b+", 0x2295 }, |
{ "c+", "O\b+", 0x2295 }, |
{ "di", "-:-", 0x00f7 }, |
{ "di", "/", 0x00f7 }, |
{ "tdi", "-:-", 0x00f7 }, |
{ "tdi", "/", 0x00f7 }, |
{ "f/", "/", 0x2044 }, |
{ "f/", "/", 0x2044 }, |
{ "**", "*", 0x2217 }, |
{ "**", "*", 0x2217 }, |
{ "<=", "<=", 0x2264 }, |
{ "<=", "<=", 0x2264 }, |
Line 204 static struct ln lines[] = { |
|
Line 205 static struct ln lines[] = { |
|
{ "=~", "=~", 0x2245 }, |
{ "=~", "=~", 0x2245 }, |
{ "~~", "~~", 0x2248 }, |
{ "~~", "~~", 0x2248 }, |
{ "~=", "~=", 0x2248 }, |
{ "~=", "~=", 0x2248 }, |
{ "pt", "oc", 0x221d }, |
{ "pt", "<proportional\037to>", 0x221d }, |
{ "es", "{}", 0x2205 }, |
{ "es", "{}", 0x2205 }, |
{ "mo", "E", 0x2208 }, |
{ "mo", "<element\037of>", 0x2208 }, |
{ "nm", "!E", 0x2209 }, |
{ "nm", "<not\037element\037of>", 0x2209 }, |
{ "sb", "(=", 0x2282 }, |
{ "sb", "<proper\037subset>", 0x2282 }, |
{ "nb", "(!=", 0x2284 }, |
{ "nb", "<not\037subset>", 0x2284 }, |
{ "sp", "=)", 0x2283 }, |
{ "sp", "<proper\037superset>", 0x2283 }, |
{ "nc", "!=)", 0x2285 }, |
{ "nc", "<not\037superset>", 0x2285 }, |
{ "ib", "(=\b_", 0x2286 }, |
{ "ib", "<subset\037or\037equal>", 0x2286 }, |
{ "ip", "=\b_)", 0x2287 }, |
{ "ip", "<superset\037or\037equal>", 0x2287 }, |
{ "ca", "(^)", 0x2229 }, |
{ "ca", "<intersection>", 0x2229 }, |
{ "cu", "U", 0x222a }, |
{ "cu", "<union>", 0x222a }, |
{ "/_", "_\b/", 0x2220 }, |
{ "/_", "<angle>", 0x2220 }, |
{ "pp", "_\b|", 0x22a5 }, |
{ "pp", "<perpendicular>", 0x22a5 }, |
{ "is", "'\b,\bI", 0x222b }, |
{ "is", "<integral>", 0x222b }, |
{ "integral", "'\b,\bI", 0x222b }, |
{ "integral", "<integral>", 0x222b }, |
{ "sum", "E", 0x2211 }, |
{ "sum", "<sum>", 0x2211 }, |
{ "product", "TT", 0x220f }, |
{ "product", "<product>", 0x220f }, |
{ "coproduct", "U", 0x2210 }, |
{ "coproduct", "<coproduct>", 0x2210 }, |
{ "gr", "V", 0x2207 }, |
{ "gr", "<nabla>", 0x2207 }, |
{ "sr", "\\/", 0x221a }, |
{ "sr", "<sqrt>", 0x221a }, |
{ "sqrt", "\\/", 0x221a }, |
{ "sqrt", "<sqrt>", 0x221a }, |
{ "lc", "|~", 0x2308 }, |
{ "lc", "|~", 0x2308 }, |
{ "rc", "~|", 0x2309 }, |
{ "rc", "~|", 0x2309 }, |
{ "lf", "|_", 0x230a }, |
{ "lf", "|_", 0x230a }, |
{ "rf", "_|", 0x230b }, |
{ "rf", "_|", 0x230b }, |
{ "if", "oo", 0x221e }, |
{ "if", "<infinity>", 0x221e }, |
{ "Ah", "N", 0x2135 }, |
{ "Ah", "<Aleph>", 0x2135 }, |
{ "Im", "I", 0x2111 }, |
{ "Im", "<Im>", 0x2111 }, |
{ "Re", "R", 0x211c }, |
{ "Re", "<Re>", 0x211c }, |
{ "pd", "a", 0x2202 }, |
{ "wp", "p", 0x2118 }, |
|
{ "pd", "<del>", 0x2202 }, |
{ "-h", "/h", 0x210f }, |
{ "-h", "/h", 0x210f }, |
|
{ "hbar", "/h", 0x210f }, |
{ "12", "1/2", 0x00bd }, |
{ "12", "1/2", 0x00bd }, |
{ "14", "1/4", 0x00bc }, |
{ "14", "1/4", 0x00bc }, |
{ "34", "3/4", 0x00be }, |
{ "34", "3/4", 0x00be }, |
|
{ "18", "1/8", 0x215B }, |
|
{ "38", "3/8", 0x215C }, |
|
{ "58", "5/8", 0x215D }, |
|
{ "78", "7/8", 0x215E }, |
|
{ "S1", "^1", 0x00B9 }, |
|
{ "S2", "^2", 0x00B2 }, |
|
{ "S3", "^3", 0x00B3 }, |
|
|
/* Ligatures. */ |
/* Ligatures. */ |
{ "ff", "ff", 0xfb00 }, |
{ "ff", "ff", 0xfb00 }, |
Line 272 static struct ln lines[] = { |
|
Line 282 static struct ln lines[] = { |
|
{ "ho", ",", 0x02db }, |
{ "ho", ",", 0x02db }, |
{ "ha", "^", 0x005e }, |
{ "ha", "^", 0x005e }, |
{ "ti", "~", 0x007e }, |
{ "ti", "~", 0x007e }, |
|
{ "u02DC", "~", 0x02dc }, |
|
|
/* Accented letters. */ |
/* Accented letters. */ |
{ "'A", "'\bA", 0x00c1 }, |
{ "'A", "'\bA", 0x00c1 }, |
Line 279 static struct ln lines[] = { |
|
Line 290 static struct ln lines[] = { |
|
{ "'I", "'\bI", 0x00cd }, |
{ "'I", "'\bI", 0x00cd }, |
{ "'O", "'\bO", 0x00d3 }, |
{ "'O", "'\bO", 0x00d3 }, |
{ "'U", "'\bU", 0x00da }, |
{ "'U", "'\bU", 0x00da }, |
|
{ "'Y", "'\bY", 0x00dd }, |
{ "'a", "'\ba", 0x00e1 }, |
{ "'a", "'\ba", 0x00e1 }, |
{ "'e", "'\be", 0x00e9 }, |
{ "'e", "'\be", 0x00e9 }, |
{ "'i", "'\bi", 0x00ed }, |
{ "'i", "'\bi", 0x00ed }, |
{ "'o", "'\bo", 0x00f3 }, |
{ "'o", "'\bo", 0x00f3 }, |
{ "'u", "'\bu", 0x00fa }, |
{ "'u", "'\bu", 0x00fa }, |
|
{ "'y", "'\by", 0x00fd }, |
{ "`A", "`\bA", 0x00c0 }, |
{ "`A", "`\bA", 0x00c0 }, |
{ "`E", "`\bE", 0x00c8 }, |
{ "`E", "`\bE", 0x00c8 }, |
{ "`I", "`\bI", 0x00cc }, |
{ "`I", "`\bI", 0x00cc }, |
Line 331 static struct ln lines[] = { |
|
Line 344 static struct ln lines[] = { |
|
{ "oa", "o\ba", 0x00e5 }, |
{ "oa", "o\ba", 0x00e5 }, |
|
|
/* Special letters. */ |
/* Special letters. */ |
{ "-D", "-\bD", 0x00d0 }, |
{ "-D", "Dh", 0x00d0 }, |
{ "Sd", "d", 0x00f0 }, |
{ "Sd", "dh", 0x00f0 }, |
{ "TP", "Th", 0x00de }, |
{ "TP", "Th", 0x00de }, |
{ "Tp", "th", 0x00fe }, |
{ "Tp", "th", 0x00fe }, |
{ ".i", "i", 0x0131 }, |
{ ".i", "i", 0x0131 }, |
Line 344 static struct ln lines[] = { |
|
Line 357 static struct ln lines[] = { |
|
{ "Eu", "EUR", 0x20ac }, |
{ "Eu", "EUR", 0x20ac }, |
{ "eu", "EUR", 0x20ac }, |
{ "eu", "EUR", 0x20ac }, |
{ "Ye", "=\bY", 0x00a5 }, |
{ "Ye", "=\bY", 0x00a5 }, |
{ "Po", "GBP", 0x00a3 }, |
{ "Po", "-\bL", 0x00a3 }, |
{ "Cs", "o\bx", 0x00a4 }, |
{ "Cs", "o\bx", 0x00a4 }, |
{ "Fn", ",\bf", 0x0192 }, |
{ "Fn", ",\bf", 0x0192 }, |
|
|
/* Units. */ |
/* Units. */ |
{ "de", "<deg>", 0x00b0 }, |
{ "de", "<degree>", 0x00b0 }, |
{ "%0", "%o", 0x2030 }, |
{ "%0", "<permille>", 0x2030 }, |
{ "fm", "\'", 0x2032 }, |
{ "fm", "\'", 0x2032 }, |
{ "sd", "''", 0x2033 }, |
{ "sd", "''", 0x2033 }, |
{ "mc", ",\bu", 0x00b5 }, |
{ "mc", "<micro>", 0x00b5 }, |
|
{ "Of", "_\ba", 0x00aa }, |
|
{ "Om", "_\bo", 0x00ba }, |
|
|
/* Greek characters. */ |
/* Greek characters. */ |
{ "*A", "A", 0x0391 }, |
{ "*A", "A", 0x0391 }, |
{ "*B", "B", 0x0392 }, |
{ "*B", "B", 0x0392 }, |
{ "*G", "G", 0x0393 }, |
{ "*G", "<Gamma>", 0x0393 }, |
{ "*D", "_\b/_\b\\", 0x0394 }, |
{ "*D", "<Delta>", 0x0394 }, |
{ "*E", "E", 0x0395 }, |
{ "*E", "E", 0x0395 }, |
{ "*Z", "Z", 0x0396 }, |
{ "*Z", "Z", 0x0396 }, |
{ "*Y", "H", 0x0397 }, |
{ "*Y", "H", 0x0397 }, |
{ "*H", "-\bO", 0x0398 }, |
{ "*H", "<Theta>", 0x0398 }, |
{ "*I", "I", 0x0399 }, |
{ "*I", "I", 0x0399 }, |
{ "*K", "K", 0x039a }, |
{ "*K", "K", 0x039a }, |
{ "*L", "/\\", 0x039b }, |
{ "*L", "<Lambda>", 0x039b }, |
{ "*M", "M", 0x039c }, |
{ "*M", "M", 0x039c }, |
{ "*N", "N", 0x039d }, |
{ "*N", "N", 0x039d }, |
{ "*C", "_\bH", 0x039e }, |
{ "*C", "<Xi>", 0x039e }, |
{ "*O", "O", 0x039f }, |
{ "*O", "O", 0x039f }, |
{ "*P", "TT", 0x03a0 }, |
{ "*P", "<Pi>", 0x03a0 }, |
{ "*R", "P", 0x03a1 }, |
{ "*R", "P", 0x03a1 }, |
{ "*S", "S", 0x03a3 }, |
{ "*S", "<Sigma>", 0x03a3 }, |
{ "*T", "T", 0x03a4 }, |
{ "*T", "T", 0x03a4 }, |
{ "*U", "Y", 0x03a5 }, |
{ "*U", "Y", 0x03a5 }, |
{ "*F", "I\bO", 0x03a6 }, |
{ "*F", "<Phi>", 0x03a6 }, |
{ "*X", "X", 0x03a7 }, |
{ "*X", "X", 0x03a7 }, |
{ "*Q", "I\bY", 0x03a8 }, |
{ "*Q", "<Psi>", 0x03a8 }, |
{ "*W", "_\bO", 0x03a9 }, |
{ "*W", "<Omega>", 0x03a9 }, |
{ "*a", "a", 0x03b1 }, |
{ "*a", "<alpha>", 0x03b1 }, |
{ "*b", "B", 0x03b2 }, |
{ "*b", "<beta>", 0x03b2 }, |
{ "*g", "y", 0x03b3 }, |
{ "*g", "<gamma>", 0x03b3 }, |
{ "*d", "d", 0x03b4 }, |
{ "*d", "<delta>", 0x03b4 }, |
{ "*e", "e", 0x03b5 }, |
{ "*e", "<epsilon>", 0x03b5 }, |
{ "*z", ",\bC", 0x03b6 }, |
{ "*z", "<zeta>", 0x03b6 }, |
{ "*y", "n", 0x03b7 }, |
{ "*y", "<eta>", 0x03b7 }, |
{ "*h", "-\b0", 0x03b8 }, |
{ "*h", "<theta>", 0x03b8 }, |
{ "*i", "i", 0x03b9 }, |
{ "*i", "<iota>", 0x03b9 }, |
{ "*k", "k", 0x03ba }, |
{ "*k", "<kappa>", 0x03ba }, |
{ "*l", ">\b\\", 0x03bb }, |
{ "*l", "<lambda>", 0x03bb }, |
{ "*m", ",\bu", 0x03bc }, |
{ "*m", "<mu>", 0x03bc }, |
{ "*n", "v", 0x03bd }, |
{ "*n", "<nu>", 0x03bd }, |
{ "*c", ",\bE", 0x03be }, |
{ "*c", "<xi>", 0x03be }, |
{ "*o", "o", 0x03bf }, |
{ "*o", "o", 0x03bf }, |
{ "*p", "-\bn", 0x03c0 }, |
{ "*p", "<pi>", 0x03c0 }, |
{ "*r", "p", 0x03c1 }, |
{ "*r", "<rho>", 0x03c1 }, |
{ "*s", "-\bo", 0x03c3 }, |
{ "*s", "<sigma>", 0x03c3 }, |
{ "*t", "~\bt", 0x03c4 }, |
{ "*t", "<tau>", 0x03c4 }, |
{ "*u", "u", 0x03c5 }, |
{ "*u", "<upsilon>", 0x03c5 }, |
{ "*f", "|\bo", 0x03d5 }, |
{ "*f", "<phi>", 0x03d5 }, |
{ "*x", "x", 0x03c7 }, |
{ "*x", "<chi>", 0x03c7 }, |
{ "*q", "|\bu", 0x03c8 }, |
{ "*q", "<psi>", 0x03c8 }, |
{ "*w", "w", 0x03c9 }, |
{ "*w", "<omega>", 0x03c9 }, |
{ "+h", "-\b0", 0x03d1 }, |
{ "+h", "<theta>", 0x03d1 }, |
{ "+f", "|\bo", 0x03c6 }, |
{ "+f", "<phi>", 0x03c6 }, |
{ "+p", "-\bw", 0x03d6 }, |
{ "+p", "<pi>", 0x03d6 }, |
{ "+e", "e", 0x03f5 }, |
{ "+e", "<epsilon>", 0x03f5 }, |
{ "ts", "s", 0x03c2 }, |
{ "ts", "<sigma>", 0x03c2 }, |
}; |
}; |
|
|
static struct ohash mchars; |
static struct ohash mchars; |
Line 443 mchars_spec2cp(const char *p, size_t sz) |
|
Line 458 mchars_spec2cp(const char *p, size_t sz) |
|
|
|
end = p + sz; |
end = p + sz; |
ln = ohash_find(&mchars, ohash_qlookupi(&mchars, p, &end)); |
ln = ohash_find(&mchars, ohash_qlookupi(&mchars, p, &end)); |
return ln != NULL ? ln->unicode : sz == 1 ? (unsigned char)*p : -1; |
return ln != NULL ? ln->unicode : -1; |
} |
} |
|
|
int |
int |
Line 473 mchars_spec2str(const char *p, size_t sz, size_t *rsz) |
|
Line 488 mchars_spec2str(const char *p, size_t sz, size_t *rsz) |
|
|
|
end = p + sz; |
end = p + sz; |
ln = ohash_find(&mchars, ohash_qlookupi(&mchars, p, &end)); |
ln = ohash_find(&mchars, ohash_qlookupi(&mchars, p, &end)); |
if (ln == NULL) { |
if (ln == NULL) |
*rsz = 1; |
return NULL; |
return sz == 1 ? p : NULL; |
|
} |
|
|
|
*rsz = strlen(ln->ascii); |
*rsz = strlen(ln->ascii); |
return ln->ascii; |
return ln->ascii; |