Index: src/entity.c
===================================================================
--- src/entity.c	(revision 767)
+++ src/entity.c	(working copy)
@@ -9,6 +9,7 @@
 
 
 #include <string.h>
+#include <ctype.h>
 
 /*********************************************
  * Convert from named entity to its encoding.
@@ -23,7 +24,6 @@
     unsigned short value;
 };
 
-#if IN_GCC
 static NameId namesA[]={
         "Aacgr",        0x0386,
         "aacgr",        0x03AC,
@@ -42,7 +42,9 @@
         "agr",          0x03B1,
         "Agrave",       0x00C0,
         "agrave",       0x00E0,
+        "alefsym",      0x2135,
         "aleph",        0x2135,
+        "Alpha",        0x0391,
         "alpha",        0x03B1,
         "Amacr",        0x0100,
         "amacr",        0x0101,
@@ -58,11 +60,11 @@
         "aogon",        0x0105,
         "ap",           0x2248,
         "ape",          0x224A,
-        "apos",         0x0027,
+        "apos",         0x02BC,
         "Aring",        0x00C5,
         "aring",        0x00E5,
         "ast",          0x002A,
-        "asymp",        0x224D,
+        "asymp",        0x2248,
         "Atilde",       0x00C3,
         "atilde",       0x00E3,
         "Auml",         0x00C4,
@@ -76,9 +78,11 @@
         "bcong",        0x224C,
         "Bcy",          0x0411,
         "bcy",          0x0431,
+        "bdquo",        0x201E,
         "becaus",       0x2235,
         "bepsi",        0x220D,
         "bernou",       0x212C,
+        "Beta",         0x0392,
         "beta",         0x03B2,
         "beth",         0x2136,
         "Bgr",          0x0392,
@@ -91,47 +95,48 @@
         "bottom",       0x22A5,
         "bowtie",       0x22C8,
         "boxdl",        0x2510,
-        "boxDL",        0x2555,
-        "boxdL",        0x2556,
-        "boxDl",        0x2557,
+        "boxdL",        0x2555,
+        "boxDl",        0x2556,
+        "boxDL",        0x2557,
         "boxdr",        0x250C,
-        "boxDR",        0x2552,
+        "boxdR",        0x2552,
         "boxDr",        0x2553,
-        "boxdR",        0x2554,
+        "boxDR",        0x2554,
         "boxh",         0x2500,
         "boxH",         0x2550,
         "boxhd",        0x252C,
-        "boxhD",        0x2564,
-        "boxHD",        0x2565,
-        "boxHd",        0x2566,
+        "boxHd",        0x2564,
+        "boxhD",        0x2565,
+        "boxHD",        0x2566,
         "boxhu",        0x2534,
-        "boxhU",        0x2567,
-        "boxHU",        0x2568,
-        "boxHu",        0x2569,
+        "boxHu",        0x2567,
+        "boxhU",        0x2568,
+        "boxHU",        0x2569,
         "boxul",        0x2518,
-        "boxUL",        0x255B,
+        "boxuL",        0x255B,
         "boxUl",        0x255C,
-        "boxuL",        0x255D,
+        "boxUL",        0x255D,
         "boxur",        0x2514,
-        "boxUR",        0x2558,
-        "boxuR",        0x2559,
-        "boxUr",        0x255A,
+        "boxuR",        0x2558,
+        "boxUr",        0x2559,
+        "boxUR",        0x255A,
         "boxv",         0x2502,
         "boxV",         0x2551,
         "boxvh",        0x253C,
         "boxvH",        0x256A,
-        "boxVH",        0x256B,
-        "boxVh",        0x256C,
+        "boxVh",        0x256B,
+        "boxVH",        0x256C,
         "boxvl",        0x2524,
         "boxvL",        0x2561,
-        "boxVL",        0x2562,
-        "boxVl",        0x2563,
+        "boxVl",        0x2562,
+        "boxVL",        0x2563,
         "boxvr",        0x251C,
         "boxvR",        0x255E,
-        "boxVR",        0x255F,
-        "boxVr",        0x2560,
+        "boxVr",        0x255F,
+        "boxVR",        0x2560,
         "bprime",       0x2035,
         "breve",        0x02D8,
+        "brkbar",       0x00A6,
         "brvbar",       0x00A6,
         "bsim",         0x223D,
         "bsime",        0x22CD,
@@ -162,9 +167,10 @@
         "CHcy",         0x0427,
         "chcy",         0x0447,
         "check",        0x2713,
+        "Chi",          0x03A7,
         "chi",          0x03C7,
         "cir",          0x25CB,
-        "circ",         0x005E,
+        "circ",         0x02C6,
         "cire",         0x2257,
         "clubs",        0x2663,
         "colon",        0x003A,
@@ -178,6 +184,7 @@
         "coprod",       0x2210,
         "copy",         0x00A9,
         "copysr",       0x2117,
+        "crarr",        0x21B5,
         "cross",        0x2717,
         "cuepr",        0x22DE,
         "cuesc",        0x22DF,
@@ -271,27 +278,33 @@
         "els",          0x22DC,
         "Emacr",        0x0112,
         "emacr",        0x0113,
+        "emdash",       0x2014,
         "empty",        0x2205,
         "emsp",         0x2003,
         "emsp13",       0x2004,
         "emsp14",       0x2005,
+        "endash",       0x2013,
         "ENG",          0x014A,
         "eng",          0x014B,
         "ensp",         0x2002,
         "Eogon",        0x0118,
         "eogon",        0x0119,
-        "epsi",         0x220A,
+        "epsi",         0x03B5,
+        "Epsilon",      0x0395,
+        "epsilon",      0x03B5,
         "epsis",        0x220A,
         "epsiv",        0x03B5,
         "equals",       0x003D,
         "equiv",        0x2261,
         "erDot",        0x2253,
         "esdot",        0x2250,
+        "Eta",          0x0397,
         "eta",          0x03B7,
         "ETH",          0x00D0,
         "eth",          0x00F0,
         "Euml",         0x00CB,
         "euml",         0x00EB,
+        "euro",         0x20AC,
         "excl",         0x0021,
         "exist",        0x2203,
         NULL,           0
@@ -325,6 +338,7 @@
         "frac56",       0x215A,
         "frac58",       0x215D,
         "frac78",       0x215E,
+        "frasl",        0x2044,
         "frown",        0x2322,
         NULL,           0
 };
@@ -338,6 +352,7 @@
         "Gbreve",       0x011E,
         "gbreve",       0x011F,
         "Gcedil",       0x0122,
+        "gcedil",       0x0123,
         "Gcirc",        0x011C,
         "gcirc",        0x011D,
         "Gcy",          0x0413,
@@ -382,6 +397,7 @@
         "hcirc",        0x0125,
         "hearts",       0x2665,
         "hellip",       0x2026,
+        "hibar",        0x00AF,
         "horbar",       0x2015,
         "Hstrok",       0x0126,
         "hstrok",       0x0127,
@@ -425,9 +441,10 @@
         "iocy",         0x0451,
         "Iogon",        0x012E,
         "iogon",        0x012F,
+        "Iota",         0x0399,
         "iota",         0x03B9,
         "iquest",       0x00BF,
-        "isin",         0x220A,
+        "isin",         0x2208,
         "Itilde",       0x0128,
         "itilde",       0x0129,
         "Iukcy",        0x0406,
@@ -450,6 +467,7 @@
 };
 
 static NameId namesK[]={
+        "Kappa",        0x039A,
         "kappa",        0x03BA,
         "kappav",       0x03F0,
         "Kcedil",       0x0136,
@@ -475,7 +493,7 @@
         "lagran",       0x2112,
         "Lambda",       0x039B,
         "lambda",       0x03BB,
-        "lang",         0x3008,
+        "lang",         0x2329,
         "lap",          0x2272,
         "laquo",        0x00AB,
         "larr",         0x2190,
@@ -524,6 +542,8 @@
         "lpar",         0x0028,
         "lrarr2",       0x21C6,
         "lrhar2",       0x21CB,
+        "lrm",          0x200E,
+        "lsaquo",       0x2039,
         "lsh",          0x21B0,
         "lsim",         0x2272,
         "lsqb",         0x005B,
@@ -561,6 +581,7 @@
         "mldr",         0x2026,
         "mnplus",       0x2213,
         "models",       0x22A7,
+        "Mu",           0x039C,
         "mu",           0x03BC,
         "mumap",        0x22B8,
         NULL,           0
@@ -573,8 +594,7 @@
         "nap",          0x2249,
         "napos",        0x0149,
         "natur",        0x266E,
-//      "nbsp",         0x00A0,
-        "nbsp",         32,    // make non-breaking space appear as space
+        "nbsp",         0x00A0,
         "Ncaron",       0x0147,
         "ncaron",       0x0148,
         "Ncedil",       0x0145,
@@ -595,7 +615,7 @@
         "ngt",          0x226F,
         "nharr",        0x21AE,
         "nhArr",        0x21CE,
-        "ni",           0x220D,
+        "ni",           0x220B,
         "NJcy",         0x040A,
         "njcy",         0x045A,
         "nlarr",        0x219A,
@@ -631,6 +651,7 @@
         "nsupE",        0x2289,
         "Ntilde",       0x00D1,
         "ntilde",       0x00F1,
+        "Nu",           0x039D,
         "nu",           0x03BD,
         "num",          0x0023,
         "numero",       0x2116,
@@ -671,10 +692,13 @@
         "ohgr",         0x03C9,
         "ohm",          0x2126,
         "olarr",        0x21BA,
+        "oline",        0x203E,
         "Omacr",        0x014C,
         "omacr",        0x014D,
         "Omega",        0x03A9,
         "omega",        0x03C9,
+        "Omicron",      0x039F,
+        "omicron",      0x03BF,
         "ominus",       0x2296,
         "oplus",        0x2295,
         "or",           0x2228,
@@ -709,6 +733,7 @@
         "PHgr",         0x03A6,
         "phgr",         0x03C6,
         "Phi",          0x03A6,
+        "phi",          0x03C6,
         "phis",         0x03C6,
         "phiv",         0x03D5,
         "phmmat",       0x2133,
@@ -752,7 +777,7 @@
         "Racute",       0x0154,
         "racute",       0x0155,
         "radic",        0x221A,
-        "rang",         0x3009,
+        "rang",         0x232A,
         "raquo",        0x00BB,
         "rarr",         0x2192,
         "Rarr",         0x21A0,
@@ -780,13 +805,16 @@
         "rgr",          0x03C1,
         "rhard",        0x21C1,
         "rharu",        0x21C0,
+        "Rho",          0x03A1,
         "rho",          0x03C1,
         "rhov",         0x03F1,
         "ring",         0x02DA,
         "rlarr2",       0x21C4,
         "rlhar2",       0x21CC,
+        "rlm",          0x200F,
         "rpar",         0x0029,
         "rpargt",       0xE291,
+        "rsaquo",       0x203A,
         "rsh",          0x21B1,
         "rsqb",         0x005D,
         "rsquo",        0x2019,
@@ -804,6 +832,7 @@
         "Sacute",       0x015A,
         "sacute",       0x015B,
         "samalg",       0x2210,
+        "sbquo",        0x201A,
         "sbsol",        0xFE68,
         "sc",           0x227B,
         "scap",         0x227F,
@@ -839,6 +868,7 @@
         "shy",          0x00AD,
         "Sigma",        0x03A3,
         "sigma",        0x03C3,
+        "sigmaf",       0x03C2,
         "sigmav",       0x03C2,
         "sim",          0x223C,
         "sime",         0x2243,
@@ -861,7 +891,7 @@
         "ssetmn",       0x2216,
         "ssmile",       0x2323,
         "sstarf",       0x22C6,
-        "star",         0x22C6,
+        "star",         0x2606,
         "starf",        0x2605,
         "sub",          0x2282,
         "Sub",          0x22D0,
@@ -870,7 +900,7 @@
         "subne",        0x228A,
         "subnE",        0x228A,
         "sum",          0x2211,
-        "sung",         0x2669,
+        "sung",         0x266A,
         "sup",          0x2283,
         "Sup",          0x22D1,
         "sup1",         0x00B9,
@@ -886,6 +916,7 @@
 
 static NameId namesT[]={
         "target",       0x2316,
+        "Tau",          0x03A4,
         "tau",          0x03C4,
         "Tcaron",       0x0164,
         "tcaron",       0x0165,
@@ -899,7 +930,9 @@
         "tgr",          0x03C4,
         "there4",       0x2234,
         "Theta",        0x0398,
+        "theta",        0x03B8,
         "thetas",       0x03B8,
+        "thetasym",     0x03D1,
         "thetav",       0x03D1,
         "THgr",         0x0398,
         "thgr",         0x03B8,
@@ -961,8 +994,11 @@
         "Uogon",        0x0172,
         "uogon",        0x0173,
         "uplus",        0x228E,
+        "Upsi",         0x03A5,
         "upsi",         0x03C5,
-        "Upsi",         0x03D2,
+        "upsih",        0x03D2,
+        "Upsilon",      0x03A5,
+        "upsilon",      0x03C5,
         "urcorn",       0x231D,
         "urcrop",       0x230E,
         "Uring",        0x016E,
@@ -1052,11 +1088,14 @@
         "zcy",          0x0437,
         "Zdot",         0x017B,
         "zdot",         0x017C,
+        "Zeta",         0x0396,
         "zeta",         0x03B6,
         "Zgr",          0x0396,
         "zgr",          0x03B6,
         "ZHcy",         0x0416,
         "zhcy",         0x0436,
+        "zwj",          0x200D,
+        "zwnj",         0x200C,
         NULL, 0
 };
 
@@ -1070,297 +1109,17 @@
 int HtmlNamedEntity(unsigned char *p, int length)
 {
     int tableIndex = tolower(*p) - 'a';
-    if (tableIndex >= 0 && tableIndex < 26) {
+    if (tableIndex >= 0 && tableIndex < 26)
+    {
         NameId* names = namesTable[tableIndex];
         int i;
 
-        for (i = 0; names[i].name; i++){
-                if (strncmp(names[i].name, (char *)p, length) == 0){
-                        return names[i].value;
-                }
+        for (i = 0; names[i].name; i++)
+        {
+            if (strncmp(names[i].name, (char *)p, length) == 0)
+                return names[i].value;
         }
     }
-    error("unrecognized character entity \"%.*s\"", length, p);
     return -1;
 }
 
-#else //TODO: Merge Walter's list with Thomas'
-
-static NameId names[] =
-{
-    // Entities
-    "quot",     34,
-    "amp",      38,
-    "lt",       60,
-    "gt",       62,
-
-    "OElig",    338,
-    "oelig",    339,
-    "Scaron",   352,
-    "scaron",   353,
-    "Yuml",     376,
-    "circ",     710,
-    "tilde",    732,
-    "ensp",     8194,
-    "emsp",     8195,
-    "thinsp",   8201,
-    "zwnj",     8204,
-    "zwj",      8205,
-    "lrm",      8206,
-    "rlm",      8207,
-    "ndash",    8211,
-    "mdash",    8212,
-    "lsquo",    8216,
-    "rsquo",    8217,
-    "sbquo",    8218,
-    "ldquo",    8220,
-    "rdquo",    8221,
-    "bdquo",    8222,
-    "dagger",   8224,
-    "Dagger",   8225,
-    "permil",   8240,
-    "lsaquo",   8249,
-    "rsaquo",   8250,
-    "euro",     8364,
-
-    // Latin-1 (ISO-8859-1) Entities
-    "nbsp",     160,
-    "iexcl",    161,
-    "cent",     162,
-    "pound",    163,
-    "curren",   164,
-    "yen",      165,
-    "brvbar",   166,
-    "sect",     167,
-    "uml",      168,
-    "copy",     169,
-    "ordf",     170,
-    "laquo",    171,
-    "not",      172,
-    "shy",      173,
-    "reg",      174,
-    "macr",     175,
-    "deg",      176,
-    "plusmn",   177,
-    "sup2",     178,
-    "sup3",     179,
-    "acute",    180,
-    "micro",    181,
-    "para",     182,
-    "middot",   183,
-    "cedil",    184,
-    "sup1",     185,
-    "ordm",     186,
-    "raquo",    187,
-    "frac14",   188,
-    "frac12",   189,
-    "frac34",   190,
-    "iquest",   191,
-    "Agrave",   192,
-    "Aacute",   193,
-    "Acirc",    194,
-    "Atilde",   195,
-    "Auml",     196,
-    "Aring",    197,
-    "AElig",    198,
-    "Ccedil",   199,
-    "Egrave",   200,
-    "Eacute",   201,
-    "Ecirc",    202,
-    "Euml",     203,
-    "Igrave",   204,
-    "Iacute",   205,
-    "Icirc",    206,
-    "Iuml",     207,
-    "ETH",      208,
-    "Ntilde",   209,
-    "Ograve",   210,
-    "Oacute",   211,
-    "Ocirc",    212,
-    "Otilde",   213,
-    "Ouml",     214,
-    "times",    215,
-    "Oslash",   216,
-    "Ugrave",   217,
-    "Uacute",   218,
-    "Ucirc",    219,
-    "Uuml",     220,
-    "Yacute",   221,
-    "THORN",    222,
-    "szlig",    223,
-    "agrave",   224,
-    "aacute",   225,
-    "acirc",    226,
-    "atilde",   227,
-    "auml",     228,
-    "aring",    229,
-    "aelig",    230,
-    "ccedil",   231,
-    "egrave",   232,
-    "eacute",   233,
-    "ecirc",    234,
-    "euml",     235,
-    "igrave",   236,
-    "iacute",   237,
-    "icirc",    238,
-    "iuml",     239,
-    "eth",      240,
-    "ntilde",   241,
-    "ograve",   242,
-    "oacute",   243,
-    "ocirc",    244,
-    "otilde",   245,
-    "ouml",     246,
-    "divide",   247,
-    "oslash",   248,
-    "ugrave",   249,
-    "uacute",   250,
-    "ucirc",    251,
-    "uuml",     252,
-    "yacute",   253,
-    "thorn",    254,
-    "yuml",     255,
-
-        // Symbols and Greek letter entities
-    "fnof",     402,
-    "Alpha",    913,
-    "Beta",     914,
-    "Gamma",    915,
-    "Delta",    916,
-    "Epsilon",  917,
-    "Zeta",     918,
-    "Eta",      919,
-    "Theta",    920,
-    "Iota",     921,
-    "Kappa",    922,
-    "Lambda",   923,
-    "Mu",       924,
-    "Nu",       925,
-    "Xi",       926,
-    "Omicron",  927,
-    "Pi",       928,
-    "Rho",      929,
-    "Sigma",    931,
-    "Tau",      932,
-    "Upsilon",  933,
-    "Phi",      934,
-    "Chi",      935,
-    "Psi",      936,
-    "Omega",    937,
-    "alpha",    945,
-    "beta",     946,
-    "gamma",    947,
-    "delta",    948,
-    "epsilon",  949,
-    "zeta",     950,
-    "eta",      951,
-    "theta",    952,
-    "iota",     953,
-    "kappa",    954,
-    "lambda",   955,
-    "mu",       956,
-    "nu",       957,
-    "xi",       958,
-    "omicron",  959,
-    "pi",       960,
-    "rho",      961,
-    "sigmaf",   962,
-    "sigma",    963,
-    "tau",      964,
-    "upsilon",  965,
-    "phi",      966,
-    "chi",      967,
-    "psi",      968,
-    "omega",    969,
-    "thetasym", 977,
-    "upsih",    978,
-    "piv",      982,
-    "bull",     8226,
-    "hellip",   8230,
-    "prime",    8242,
-    "Prime",    8243,
-    "oline",    8254,
-    "frasl",    8260,
-    "weierp",   8472,
-    "image",    8465,
-    "real",     8476,
-    "trade",    8482,
-    "alefsym",  8501,
-    "larr",     8592,
-    "uarr",     8593,
-    "rarr",     8594,
-    "darr",     8595,
-    "harr",     8596,
-    "crarr",    8629,
-    "lArr",     8656,
-    "uArr",     8657,
-    "rArr",     8658,
-    "dArr",     8659,
-    "hArr",     8660,
-    "forall",   8704,
-    "part",     8706,
-    "exist",    8707,
-    "empty",    8709,
-    "nabla",    8711,
-    "isin",     8712,
-    "notin",    8713,
-    "ni",       8715,
-    "prod",     8719,
-    "sum",      8721,
-    "minus",    8722,
-    "lowast",   8727,
-    "radic",    8730,
-    "prop",     8733,
-    "infin",    8734,
-    "ang",      8736,
-    "and",      8743,
-    "or",       8744,
-    "cap",      8745,
-    "cup",      8746,
-    "int",      8747,
-    "there4",   8756,
-    "sim",      8764,
-    "cong",     8773,
-    "asymp",    8776,
-    "ne",       8800,
-    "equiv",    8801,
-    "le",       8804,
-    "ge",       8805,
-    "sub",      8834,
-    "sup",      8835,
-    "nsub",     8836,
-    "sube",     8838,
-    "supe",     8839,
-    "oplus",    8853,
-    "otimes",   8855,
-    "perp",     8869,
-    "sdot",     8901,
-    "lceil",    8968,
-    "rceil",    8969,
-    "lfloor",   8970,
-    "rfloor",   8971,
-    "lang",     9001,
-    "rang",     9002,
-    "loz",      9674,
-    "spades",   9824,
-    "clubs",    9827,
-    "hearts",   9829,
-    "diams",    9830,
-};
-
-int HtmlNamedEntity(unsigned char *p, int length)
-{
-    int i;
-
-    // BUG: this is a dumb, slow linear search
-    for (i = 0; i < sizeof(names) / sizeof(names[0]); i++)
-    {
-        // Entries are case sensitive
-        if (memcmp(names[i].name, (char *)p, length) == 0 &&
-            !names[i].name[length])
-            return names[i].value;
-    }
-    return -1;
-}
-
-#endif
