lang.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. /* lang.c -- language-dependent support.
  2. $Id: lang.c,v 1.34 2007-12-03 01:38:43 karl Exp $
  3. Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
  4. Free Software Foundation, Inc.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. Originally written by Karl Heinz Marbaise <kama@hippo.fido.de>. */
  16. #include "system.h"
  17. #include "cmds.h"
  18. #include "files.h"
  19. #include "lang.h"
  20. #include "makeinfo.h"
  21. #include "xml.h"
  22. #include <assert.h>
  23. /* Current document encoding. */
  24. encoding_code_type document_encoding_code = no_encoding;
  25. /* Current language code; default is English. */
  26. language_code_type language_code = en;
  27. /* Language to use for translations that end up in the output. */
  28. char *document_language = "C";
  29. /* By default, unsupported encoding is an empty string. */
  30. char *unknown_encoding = NULL;
  31. static iso_map_type asis_map [] = {{NULL, 0, 0}}; /* ASCII, etc. */
  32. /* Translation table between HTML and ISO Codes. The last item is
  33. hopefully the Unicode. It might be possible that those Unicodes are
  34. not correct, cause I didn't check them. kama */
  35. static iso_map_type iso8859_1_map [] = {
  36. { "nbsp", 0xA0, 0x00A0 },
  37. { "iexcl", 0xA1, 0x00A1 },
  38. { "cent", 0xA2, 0x00A2 },
  39. { "pound", 0xA3, 0x00A3 },
  40. { "curren", 0xA4, 0x00A4 },
  41. { "yen", 0xA5, 0x00A5 },
  42. { "brkbar", 0xA6, 0x00A6 },
  43. { "sect", 0xA7, 0x00A7 },
  44. { "uml", 0xA8, 0x00A8 },
  45. { "copy", 0xA9, 0x00A9 },
  46. { "ordf", 0xAA, 0x00AA },
  47. { "laquo", 0xAB, 0x00AB },
  48. { "not", 0xAC, 0x00AC },
  49. { "shy", 0xAD, 0x00AD },
  50. { "reg", 0xAE, 0x00AE },
  51. { "hibar", 0xAF, 0x00AF },
  52. { "deg", 0xB0, 0x00B0 },
  53. { "plusmn", 0xB1, 0x00B1 },
  54. { "sup2", 0xB2, 0x00B2 },
  55. { "sup3", 0xB3, 0x00B3 },
  56. { "acute", 0xB4, 0x00B4 },
  57. { "micro", 0xB5, 0x00B5 },
  58. { "para", 0xB6, 0x00B6 },
  59. { "middot", 0xB7, 0x00B7 },
  60. { "cedil", 0xB8, 0x00B8 },
  61. { "sup1", 0xB9, 0x00B9 },
  62. { "ordm", 0xBA, 0x00BA },
  63. { "raquo", 0xBB, 0x00BB },
  64. { "frac14", 0xBC, 0x00BC },
  65. { "frac12", 0xBD, 0x00BD },
  66. { "frac34", 0xBE, 0x00BE },
  67. { "iquest", 0xBF, 0x00BF },
  68. { "Agrave", 0xC0, 0x00C0, "A" },
  69. { "Aacute", 0xC1, 0x00C1, "A" },
  70. { "Acirc", 0xC2, 0x00C2, "A" },
  71. { "Atilde", 0xC3, 0x00C3, "A" },
  72. { "Auml", 0xC4, 0x00C4, "A" },
  73. { "Aring", 0xC5, 0x00C5, "AA" },
  74. { "AElig", 0xC6, 0x00C6, "AE" },
  75. { "Ccedil", 0xC7, 0x00C7, "C" },
  76. { "Ccedil", 0xC7, 0x00C7, "C" },
  77. { "Egrave", 0xC8, 0x00C8, "E" },
  78. { "Eacute", 0xC9, 0x00C9, "E" },
  79. { "Ecirc", 0xCA, 0x00CA, "E" },
  80. { "Euml", 0xCB, 0x00CB, "E" },
  81. { "Igrave", 0xCC, 0x00CC, "I" },
  82. { "Iacute", 0xCD, 0x00CD, "I" },
  83. { "Icirc", 0xCE, 0x00CE, "I" },
  84. { "Iuml", 0xCF, 0x00CF, "I" },
  85. { "ETH", 0xD0, 0x00D0, "DH" },
  86. { "Ntilde", 0xD1, 0x00D1, "N" },
  87. { "Ograve", 0xD2, 0x00D2, "O" },
  88. { "Oacute", 0xD3, 0x00D3, "O" },
  89. { "Ocirc", 0xD4, 0x00D4, "O" },
  90. { "Otilde", 0xD5, 0x00D5, "O" },
  91. { "Ouml", 0xD6, 0x00D6, "O" },
  92. { "times", 0xD7, 0x00D7 },
  93. { "Oslash", 0xD8, 0x00D8, "OE" },
  94. { "Ugrave", 0xD9, 0x00D9, "U" },
  95. { "Uacute", 0xDA, 0x00DA, "U" },
  96. { "Ucirc", 0xDB, 0x00DB, "U" },
  97. { "Uuml", 0xDC, 0x00DC, "U" },
  98. { "Yacute", 0xDD, 0x00DD, "Y" },
  99. { "THORN", 0xDE, 0x00DE, "TH" },
  100. { "szlig", 0xDF, 0x00DF, "s" },
  101. { "agrave", 0xE0, 0x00E0, "a" },
  102. { "aacute", 0xE1, 0x00E1, "a" },
  103. { "acirc", 0xE2, 0x00E2, "a" },
  104. { "atilde", 0xE3, 0x00E3, "a" },
  105. { "auml", 0xE4, 0x00E4, "a" },
  106. { "aring", 0xE5, 0x00E5, "aa" },
  107. { "aelig", 0xE6, 0x00E6, "ae" },
  108. { "ccedil", 0xE7, 0x00E7, "c" },
  109. { "egrave", 0xE8, 0x00E8, "e" },
  110. { "eacute", 0xE9, 0x00E9, "e" },
  111. { "ecirc", 0xEA, 0x00EA, "e" },
  112. { "euml", 0xEB, 0x00EB, "e" },
  113. { "igrave", 0xEC, 0x00EC, "i" },
  114. { "iacute", 0xED, 0x00ED, "i" },
  115. { "icirc", 0xEE, 0x00EE, "i" },
  116. { "iuml", 0xEF, 0x00EF, "i" },
  117. { "eth", 0xF0, 0x00F0, "dh" },
  118. { "ntilde", 0xF1, 0x00F1, "n" },
  119. { "ograve", 0xF2, 0x00F2, "o"},
  120. { "oacute", 0xF3, 0x00F3, "o" },
  121. { "ocirc", 0xF4, 0x00F4, "o" },
  122. { "otilde", 0xF5, 0x00F5, "o" },
  123. { "ouml", 0xF6, 0x00F6, "o" },
  124. { "divide", 0xF7, 0x00F7 },
  125. { "oslash", 0xF8, 0x00F8, "oe" },
  126. { "ugrave", 0xF9, 0x00F9, "u" },
  127. { "uacute", 0xFA, 0x00FA, "u" },
  128. { "ucirc", 0xFB, 0x00FB, "u" },
  129. { "uuml", 0xFC, 0x00FC, "u" },
  130. { "yacute", 0xFD, 0x00FD, "y" },
  131. { "thorn", 0xFE, 0x00FE, "th" },
  132. { "yuml", 0xFF, 0x00FF, "y" },
  133. { NULL, 0, 0 }
  134. };
  135. /* ISO 8859-15, also known as Latin 9, differs from Latin 1 in only a
  136. few positions. http://www.cs.tut.fi/~jkorpela/latin9.html has a good
  137. explanation and listing, summarized here. The names here are
  138. abbreviated to fit in a decent line length.
  139. code position
  140. dec oct hex latin1 latin1 name latin9 latin9 name
  141. 164 0244 0xA4 U+00A4 currency symbol U+20AC euro sign
  142. 166 0246 0xA6 U+00A6 broken bar U+0160 S with caron
  143. 168 0250 0xA8 U+00A8 diaeresis U+0161 s with caron
  144. 180 0264 0xB4 U+00B4 acute accent U+017D Z with caron
  145. 184 0270 0xB8 U+00B8 cedilla U+017E z with caron
  146. 188 0274 0xBC U+00BC fraction 1/4 U+0152 ligature OE
  147. 189 0275 0xBD U+00BD fraction 1/2 U+0153 ligature oe
  148. 190 0276 0xBE U+00BE fraction 3/4 U+0178 Y with diaeresis
  149. */
  150. static iso_map_type iso8859_15_map [] = {
  151. { "nbsp", 0xA0, 0x00A0 },
  152. { "iexcl", 0xA1, 0x00A1 },
  153. { "cent", 0xA2, 0x00A2 },
  154. { "pound", 0xA3, 0x00A3 },
  155. { "euro", 0xA4, 0x20AC },
  156. { "yen", 0xA5, 0x00A5 },
  157. { "Scaron", 0xA6, 0x0160, "S" },
  158. { "sect", 0xA7, 0x00A7 },
  159. { "scaron", 0xA8, 0x0161, "s" },
  160. { "copy", 0xA9, 0x00A9 },
  161. { "ordf", 0xAA, 0x00AA },
  162. { "laquo", 0xAB, 0x00AB },
  163. { "not", 0xAC, 0x00AC },
  164. { "shy", 0xAD, 0x00AD },
  165. { "reg", 0xAE, 0x00AE },
  166. { "hibar", 0xAF, 0x00AF },
  167. { "deg", 0xB0, 0x00B0 },
  168. { "plusmn", 0xB1, 0x00B1 },
  169. { "sup2", 0xB2, 0x00B2 },
  170. { "sup3", 0xB3, 0x00B3 },
  171. { "Zcaron", 0xB4, 0x017D, "Z" },
  172. { "micro", 0xB5, 0x00B5 },
  173. { "para", 0xB6, 0x00B6 },
  174. { "middot", 0xB7, 0x00B7 },
  175. { "zcaron", 0xB8, 0x017E, "z" },
  176. { "sup1", 0xB9, 0x00B9 },
  177. { "ordm", 0xBA, 0x00BA },
  178. { "raquo", 0xBB, 0x00BB },
  179. { "OElig", 0xBC, 0x0152, "OE" },
  180. { "oelig", 0xBD, 0x0153, "oe" },
  181. { "Yuml", 0xBE, 0x0178, "y" },
  182. { "iquest", 0xBF, 0x00BF },
  183. { "Agrave", 0xC0, 0x00C0, "A" },
  184. { "Aacute", 0xC1, 0x00C1, "A" },
  185. { "Acirc", 0xC2, 0x00C2, "A" },
  186. { "Atilde", 0xC3, 0x00C3, "A" },
  187. { "Auml", 0xC4, 0x00C4, "A" },
  188. { "Aring", 0xC5, 0x00C5, "AA" },
  189. { "AElig", 0xC6, 0x00C6, "AE" },
  190. { "Ccedil", 0xC7, 0x00C7, "C" },
  191. { "Egrave", 0xC8, 0x00C8, "E" },
  192. { "Eacute", 0xC9, 0x00C9, "E" },
  193. { "Ecirc", 0xCA, 0x00CA, "E" },
  194. { "Euml", 0xCB, 0x00CB, "E" },
  195. { "Igrave", 0xCC, 0x00CC, "I" },
  196. { "Iacute", 0xCD, 0x00CD, "I" },
  197. { "Icirc", 0xCE, 0x00CE, "I" },
  198. { "Iuml", 0xCF, 0x00CF, "I" },
  199. { "ETH", 0xD0, 0x00D0, "DH" },
  200. { "Ntilde", 0xD1, 0x00D1, "N" },
  201. { "Ograve", 0xD2, 0x00D2, "O" },
  202. { "Oacute", 0xD3, 0x00D3, "O" },
  203. { "Ocirc", 0xD4, 0x00D4, "O" },
  204. { "Otilde", 0xD5, 0x00D5, "O" },
  205. { "Ouml", 0xD6, 0x00D6, "O" },
  206. { "times", 0xD7, 0x00D7 },
  207. { "Oslash", 0xD8, 0x00D8, "OE" },
  208. { "Ugrave", 0xD9, 0x00D9, "U" },
  209. { "Uacute", 0xDA, 0x00DA, "U" },
  210. { "Ucirc", 0xDB, 0x00DB, "U" },
  211. { "Uuml", 0xDC, 0x00DC, "U" },
  212. { "Yacute", 0xDD, 0x00DD, "Y" },
  213. { "THORN", 0xDE, 0x00DE, "TH" },
  214. { "szlig", 0xDF, 0x00DF, "s" },
  215. { "agrave", 0xE0, 0x00E0, "a" },
  216. { "aacute", 0xE1, 0x00E1, "a" },
  217. { "acirc", 0xE2, 0x00E2, "a" },
  218. { "atilde", 0xE3, 0x00E3, "a" },
  219. { "auml", 0xE4, 0x00E4, "a" },
  220. { "aring", 0xE5, 0x00E5, "aa" },
  221. { "aelig", 0xE6, 0x00E6, "ae" },
  222. { "ccedil", 0xE7, 0x00E7, "c" },
  223. { "egrave", 0xE8, 0x00E8, "e" },
  224. { "eacute", 0xE9, 0x00E9, "e" },
  225. { "ecirc", 0xEA, 0x00EA, "e" },
  226. { "euml", 0xEB, 0x00EB, "e" },
  227. { "igrave", 0xEC, 0x00EC, "i" },
  228. { "iacute", 0xED, 0x00ED, "i" },
  229. { "icirc", 0xEE, 0x00EE, "i" },
  230. { "iuml", 0xEF, 0x00EF, "i" },
  231. { "eth", 0xF0, 0x00F0, "d" },
  232. { "ntilde", 0xF1, 0x00F1, "n" },
  233. { "ograve", 0xF2, 0x00F2, "o" },
  234. { "oacute", 0xF3, 0x00F3, "o" },
  235. { "ocirc", 0xF4, 0x00F4, "o" },
  236. { "otilde", 0xF5, 0x00F5, "o" },
  237. { "ouml", 0xF6, 0x00F6, "o" },
  238. { "divide", 0xF7, 0x00F7 },
  239. { "oslash", 0xF8, 0x00F8, "oe" },
  240. { "ugrave", 0xF9, 0x00F9, "u" },
  241. { "uacute", 0xFA, 0x00FA, "u" },
  242. { "ucirc", 0xFB, 0x00FB, "u" },
  243. { "uuml", 0xFC, 0x00FC, "u" },
  244. { "yacute", 0xFD, 0x00FD, "y" },
  245. { "thorn", 0xFE, 0x00FE, "th" },
  246. { "yuml", 0xFF, 0x00FF, "y" },
  247. { NULL, 0, 0 }
  248. };
  249. /* Date: Mon, 31 Mar 2003 00:19:28 +0200
  250. From: Wojciech Polak <polak@gnu.org>
  251. ...
  252. * Primary Polish site for ogonki is http://www.agh.edu.pl/ogonki/,
  253. but it's only in Polish language (it has some interesting links).
  254. * A general site about ISO 8859-2 at http://nl.ijs.si/gnusl/cee/iso8859-2.html
  255. * ISO 8859-2 Character Set at http://nl.ijs.si/gnusl/cee/charset.html
  256. This site provides almost all information about iso-8859-2,
  257. including the character table!!! (must see!)
  258. * ISO 8859-2 and even HTML entities !!! (must see!)
  259. 88592.txt in the GNU enscript distribution
  260. * (minor) http://www.agh.edu.pl/ogonki/plchars.html
  261. One more table, this time it includes even information about Polish
  262. characters in Unicode.
  263. */
  264. static iso_map_type iso8859_2_map [] = {
  265. { "nbsp", 0xA0, 0x00A0 }, /* NO-BREAK SPACE */
  266. { "", 0xA1, 0x0104, "A" }, /* LATIN CAPITAL LETTER A WITH OGONEK */
  267. { "", 0xA2, 0x02D8 }, /* BREVE */
  268. { "", 0xA3, 0x0141, "L" }, /* LATIN CAPITAL LETTER L WITH STROKE */
  269. { "curren", 0xA4, 0x00A4 }, /* CURRENCY SIGN */
  270. { "", 0xA5, 0x013D, "L" }, /* LATIN CAPITAL LETTER L WITH CARON */
  271. { "", 0xA6, 0x015A, "S" }, /* LATIN CAPITAL LETTER S WITH ACUTE */
  272. { "sect", 0xA7, 0x00A7 }, /* SECTION SIGN */
  273. { "uml", 0xA8, 0x00A8 }, /* DIAERESIS */
  274. { "#xa9", 0xA9, 0x0160, "S" }, /* LATIN CAPITAL LETTER S WITH CARON */
  275. { "", 0xAA, 0x015E, "S" }, /* LATIN CAPITAL LETTER S WITH CEDILLA */
  276. { "", 0xAB, 0x0164, "T" }, /* LATIN CAPITAL LETTER T WITH CARON */
  277. { "", 0xAC, 0x0179, "Z" }, /* LATIN CAPITAL LETTER Z WITH ACUTE */
  278. { "shy", 0xAD, 0x00AD }, /* SOFT HYPHEN */
  279. { "", 0xAE, 0x017D, "Z" }, /* LATIN CAPITAL LETTER Z WITH CARON */
  280. { "", 0xAF, 0x017B, "Z" }, /* LATIN CAPITAL LETTER Z WITH DOT ABOVE */
  281. { "deg", 0xB0, 0x00B0 }, /* DEGREE SIGN */
  282. { "", 0xB1, 0x0105, "a" }, /* LATIN SMALL LETTER A WITH OGONEK */
  283. { "", 0xB2, 0x02DB }, /* OGONEK */
  284. { "", 0xB3, 0x0142, "l" }, /* LATIN SMALL LETTER L WITH STROKE */
  285. { "acute", 0xB4, 0x00B4 }, /* ACUTE ACCENT */
  286. { "", 0xB5, 0x013E, "l" }, /* LATIN SMALL LETTER L WITH CARON */
  287. { "", 0xB6, 0x015B, "s" }, /* LATIN SMALL LETTER S WITH ACUTE */
  288. { "", 0xB7, 0x02C7 }, /* CARON (Mandarin Chinese third tone) */
  289. { "cedil", 0xB8, 0x00B8 }, /* CEDILLA */
  290. { "", 0xB9, 0x0161, "s" }, /* LATIN SMALL LETTER S WITH CARON */
  291. { "", 0xBA, 0x015F, "s" }, /* LATIN SMALL LETTER S WITH CEDILLA */
  292. { "", 0xBB, 0x0165, "t" }, /* LATIN SMALL LETTER T WITH CARON */
  293. { "", 0xBC, 0x017A, "z" }, /* LATIN SMALL LETTER Z WITH ACUTE */
  294. { "", 0xBD, 0x02DD }, /* DOUBLE ACUTE ACCENT */
  295. { "", 0xBE, 0x017E, "z" }, /* LATIN SMALL LETTER Z WITH CARON */
  296. { "", 0xBF, 0x017C, "z" }, /* LATIN SMALL LETTER Z WITH DOT ABOVE */
  297. { "", 0xC0, 0x0154, "R" }, /* LATIN CAPITAL LETTER R WITH ACUTE */
  298. { "Aacute", 0xC1, 0x00C1, "A" }, /* LATIN CAPITAL LETTER A WITH ACUTE */
  299. { "Acirc", 0xC2, 0x00C2, "A" }, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
  300. { "", 0xC3, 0x0102, "A" }, /* LATIN CAPITAL LETTER A WITH BREVE */
  301. { "Auml", 0xC4, 0x00C4, "A" }, /* LATIN CAPITAL LETTER A WITH DIAERESIS */
  302. { "", 0xC5, 0x0139, "L" }, /* LATIN CAPITAL LETTER L WITH ACUTE */
  303. { "", 0xC6, 0x0106, "C" }, /* LATIN CAPITAL LETTER C WITH ACUTE */
  304. { "Ccedil", 0xC7, 0x00C7, "C" }, /* LATIN CAPITAL LETTER C WITH CEDILLA */
  305. { "", 0xC8, 0x010C, "C" }, /* LATIN CAPITAL LETTER C WITH CARON */
  306. { "Eacute", 0xC9, 0x00C9, "E" }, /* LATIN CAPITAL LETTER E WITH ACUTE */
  307. { "", 0xCA, 0x0118, "E" }, /* LATIN CAPITAL LETTER E WITH OGONEK */
  308. { "Euml", 0xCB, 0x00CB, "E" }, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
  309. { "", 0xCC, 0x011A, "E" }, /* LATIN CAPITAL LETTER E WITH CARON */
  310. { "Iacute", 0xCD, 0x00CD, "I" }, /* LATIN CAPITAL LETTER I WITH ACUTE */
  311. { "Icirc", 0xCE, 0x00CE, "I" }, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
  312. { "", 0xCF, 0x010E, "D" }, /* LATIN CAPITAL LETTER D WITH CARON */
  313. { "ETH", 0xD0, 0x0110, "D" }, /* LATIN CAPITAL LETTER D WITH STROKE */
  314. { "", 0xD1, 0x0143, "N" }, /* LATIN CAPITAL LETTER N WITH ACUTE */
  315. { "", 0xD2, 0x0147, "N" }, /* LATIN CAPITAL LETTER N WITH CARON */
  316. { "Oacute", 0xD3, 0x00D3, "O" }, /* LATIN CAPITAL LETTER O WITH ACUTE */
  317. { "Ocirc", 0xD4, 0x00D4, "O" }, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
  318. { "", 0xD5, 0x0150, "O" }, /* LATIN CAPITAL LETTER O WITH DOUBLE ACUTE */
  319. { "Ouml", 0xD6, 0x00D6, "O" }, /* LATIN CAPITAL LETTER O WITH DIAERESIS */
  320. { "times", 0xD7, 0x00D7 }, /* MULTIPLICATION SIGN */
  321. { "", 0xD8, 0x0158, "R" }, /* LATIN CAPITAL LETTER R WITH CARON */
  322. { "", 0xD9, 0x016E, "U" }, /* LATIN CAPITAL LETTER U WITH RING ABOVE */
  323. { "Uacute", 0xDA, 0x00DA, "U" }, /* LATIN CAPITAL LETTER U WITH ACUTE */
  324. { "", 0xDB, 0x0170, "U" }, /* LATIN CAPITAL LETTER U WITH DOUBLE ACUTE */
  325. { "Uuml", 0xDC, 0x00DC, "U" }, /* LATIN CAPITAL LETTER U WITH DIAERESIS */
  326. { "Yacute", 0xDD, 0x00DD, "Y" }, /* LATIN CAPITAL LETTER Y WITH ACUTE */
  327. { "", 0xDE, 0x0162, "T" }, /* LATIN CAPITAL LETTER T WITH CEDILLA */
  328. { "szlig", 0xDF, 0x00DF, "ss" }, /* LATIN SMALL LETTER SHARP S (German) */
  329. { "", 0xE0, 0x0155, "s" }, /* LATIN SMALL LETTER R WITH ACUTE */
  330. { "aacute", 0xE1, 0x00E1, "a" }, /* LATIN SMALL LETTER A WITH ACUTE */
  331. { "acirc", 0xE2, 0x00E2, "a" }, /* LATIN SMALL LETTER A WITH CIRCUMFLEX */
  332. { "", 0xE3, 0x0103, "a" }, /* LATIN SMALL LETTER A WITH BREVE */
  333. { "auml", 0xE4, 0x00E4, "a" }, /* LATIN SMALL LETTER A WITH DIAERESIS */
  334. { "", 0xE5, 0x013A, "l" }, /* LATIN SMALL LETTER L WITH ACUTE */
  335. { "", 0xE6, 0x0107, "c" }, /* LATIN SMALL LETTER C WITH ACUTE */
  336. { "ccedil", 0xE7, 0x00E7, "c" }, /* LATIN SMALL LETTER C WITH CEDILLA */
  337. { "", 0xE8, 0x010D, "c" }, /* LATIN SMALL LETTER C WITH CARON */
  338. { "eacute", 0xE9, 0x00E9, "e" }, /* LATIN SMALL LETTER E WITH ACUTE */
  339. { "", 0xEA, 0x0119, "e" }, /* LATIN SMALL LETTER E WITH OGONEK */
  340. { "euml", 0xEB, 0x00EB, "e" }, /* LATIN SMALL LETTER E WITH DIAERESIS */
  341. { "", 0xEC, 0x011B, "e" }, /* LATIN SMALL LETTER E WITH CARON */
  342. { "iacute", 0xED, 0x00ED, "i" }, /* LATIN SMALL LETTER I WITH ACUTE */
  343. { "icirc", 0xEE, 0x00EE, "i" }, /* LATIN SMALL LETTER I WITH CIRCUMFLEX */
  344. { "", 0xEF, 0x010F, "d" }, /* LATIN SMALL LETTER D WITH CARON */
  345. { "", 0xF0, 0x0111, "d" }, /* LATIN SMALL LETTER D WITH STROKE */
  346. { "", 0xF1, 0x0144, "n" }, /* LATIN SMALL LETTER N WITH ACUTE */
  347. { "", 0xF2, 0x0148, "n" }, /* LATIN SMALL LETTER N WITH CARON */
  348. { "oacute", 0xF3, 0x00F3, "o" }, /* LATIN SMALL LETTER O WITH ACUTE */
  349. { "ocirc", 0xF4, 0x00F4, "o" }, /* LATIN SMALL LETTER O WITH CIRCUMFLEX */
  350. { "", 0xF5, 0x0151, "o" }, /* LATIN SMALL LETTER O WITH DOUBLE ACUTE */
  351. { "ouml", 0xF6, 0x00F6, "o" }, /* LATIN SMALL LETTER O WITH DIAERESIS */
  352. { "divide", 0xF7, 0x00F7 }, /* DIVISION SIGN */
  353. { "", 0xF8, 0x0159, "r" }, /* LATIN SMALL LETTER R WITH CARON */
  354. { "", 0xF9, 0x016F, "u" }, /* LATIN SMALL LETTER U WITH RING ABOVE */
  355. { "uacute", 0xFA, 0x00FA, "u" }, /* LATIN SMALL LETTER U WITH ACUTE */
  356. { "", 0xFB, 0x0171, "u" }, /* LATIN SMALL LETTER U WITH DOUBLE ACUTE */
  357. { "uuml", 0xFC, 0x00FC, "u" }, /* LATIN SMALL LETTER U WITH DIAERESIS */
  358. { "yacute", 0xFD, 0x00FD, "y" }, /* LATIN SMALL LETTER Y WITH ACUTE */
  359. { "", 0xFE, 0x0163, "t" }, /* LATIN SMALL LETTER T WITH CEDILLA */
  360. { "", 0xFF, 0x02D9 }, /* DOT ABOVE (Mandarin Chinese light tone) */
  361. { NULL, 0, 0 }
  362. };
  363. /* Common map for koi8-u, koi8-r */
  364. static iso_map_type koi8_map [] = {
  365. { "", 0xa3, 0x0415, "io"}, /* CYRILLIC SMALL LETTER IO */
  366. { "", 0xa4, 0x0454, "ie"}, /* CYRILLIC SMALL LETTER UKRAINIAN IE */
  367. { "", 0xa6, 0x0456, "i"}, /* CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I */
  368. { "", 0xa7, 0x0457, "yi"}, /* CYRILLIC SMALL LETTER YI */
  369. { "", 0xb3, 0x04d7, "IO"}, /* CYRILLIC CAPITAL LETTER IO */
  370. { "", 0xb4, 0x0404, "IE"}, /* CYRILLIC CAPITAL LETTER UKRAINIAN IE */
  371. { "", 0xb6, 0x0406, "I"}, /* CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I */
  372. { "", 0xb7, 0x0407, "YI"}, /* CYRILLIC CAPITAL LETTER YI */
  373. /* { "", 0xbf, 0x}, / * CYRILLIC COPYRIGHT SIGN */
  374. { "", 0xc0, 0x042e, "yu"}, /* CYRILLIC SMALL LETTER YU */
  375. { "", 0xc1, 0x0430, "a"}, /* CYRILLIC SMALL LETTER A */
  376. { "", 0xc2, 0x0431, "b"}, /* CYRILLIC SMALL LETTER BE */
  377. { "", 0xc3, 0x0446, "c"}, /* CYRILLIC SMALL LETTER TSE */
  378. { "", 0xc4, 0x0434, "d"}, /* CYRILLIC SMALL LETTER DE */
  379. { "", 0xc5, 0x0435, "e"}, /* CYRILLIC SMALL LETTER IE */
  380. { "", 0xc6, 0x0444, "f"}, /* CYRILLIC SMALL LETTER EF */
  381. { "", 0xc7, 0x0433, "g"}, /* CYRILLIC SMALL LETTER GHE */
  382. { "", 0xc8, 0x0445, "h"}, /* CYRILLIC SMALL LETTER HA */
  383. { "", 0xc9, 0x0438, "i"}, /* CYRILLIC SMALL LETTER I */
  384. { "", 0xca, 0x0439, "i"}, /* CYRILLIC SMALL LETTER SHORT I */
  385. { "", 0xcb, 0x043a, "k"}, /* CYRILLIC SMALL LETTER KA */
  386. { "", 0xcc, 0x043b, "l"}, /* CYRILLIC SMALL LETTER EL */
  387. { "", 0xcd, 0x043c, "m"}, /* CYRILLIC SMALL LETTER EM */
  388. { "", 0xce, 0x043d, "n"}, /* CYRILLIC SMALL LETTER EN */
  389. { "", 0xcf, 0x043e, "o"}, /* CYRILLIC SMALL LETTER O */
  390. { "", 0xd0, 0x043f, "p"}, /* CYRILLIC SMALL LETTER PE */
  391. { "", 0xd1, 0x044f, "ya"}, /* CYRILLIC SMALL LETTER YA */
  392. { "", 0xd2, 0x0440, "r"}, /* CYRILLIC SMALL LETTER ER */
  393. { "", 0xd3, 0x0441, "s"}, /* CYRILLIC SMALL LETTER ES */
  394. { "", 0xd4, 0x0442, "t"}, /* CYRILLIC SMALL LETTER TE */
  395. { "", 0xd5, 0x0443, "u"}, /* CYRILLIC SMALL LETTER U */
  396. { "", 0xd6, 0x0436, "zh"}, /* CYRILLIC SMALL LETTER ZHE */
  397. { "", 0xd7, 0x0432, "v"}, /* CYRILLIC SMALL LETTER VE */
  398. { "", 0xd8, 0x044c, "x"}, /* CYRILLIC SMALL LETTER SOFT SIGN */
  399. { "", 0xd9, 0x044b, "y"}, /* CYRILLIC SMALL LETTER YERU */
  400. { "", 0xda, 0x0437, "z"}, /* CYRILLIC SMALL LETTER ZE */
  401. { "", 0xdb, 0x0448, "sh"}, /* CYRILLIC SMALL LETTER SHA */
  402. { "", 0xdc, 0x044d, "e"}, /* CYRILLIC SMALL LETTER E */
  403. { "", 0xdd, 0x0449, "shch"}, /* CYRILLIC SMALL LETTER SHCHA */
  404. { "", 0xde, 0x0447, "ch"}, /* CYRILLIC SMALL LETTER CHA */
  405. { "", 0xdf, 0x044a, "w"}, /* CYRILLIC SMALL LETTER HARD SIGN */
  406. { "", 0xe0, 0x042d, "YU"}, /* CYRILLIC CAPITAL LETTER YU */
  407. { "", 0xe1, 0x0410, "A"}, /* CYRILLIC CAPITAL LETTER A */
  408. { "", 0xe2, 0x0411, "B"}, /* CYRILLIC CAPITAL LETTER BE */
  409. { "", 0xe3, 0x0426, "C"}, /* CYRILLIC CAPITAL LETTER TSE */
  410. { "", 0xe4, 0x0414, "D"}, /* CYRILLIC CAPITAL LETTER DE */
  411. { "", 0xe5, 0x0415, "E"}, /* CYRILLIC CAPITAL LETTER IE */
  412. { "", 0xe6, 0x0424, "F"}, /* CYRILLIC CAPITAL LETTER EF */
  413. { "", 0xe7, 0x0413, "G"}, /* CYRILLIC CAPITAL LETTER GHE */
  414. { "", 0xe8, 0x0425, "H"}, /* CYRILLIC CAPITAL LETTER HA */
  415. { "", 0xe9, 0x0418, "I"}, /* CYRILLIC CAPITAL LETTER I */
  416. { "", 0xea, 0x0419, "I"}, /* CYRILLIC CAPITAL LETTER SHORT I */
  417. { "", 0xeb, 0x041a, "K"}, /* CYRILLIC CAPITAL LETTER KA */
  418. { "", 0xec, 0x041b, "L"}, /* CYRILLIC CAPITAL LETTER EL */
  419. { "", 0xed, 0x041c, "M"}, /* CYRILLIC CAPITAL LETTER EM */
  420. { "", 0xee, 0x041d, "N"}, /* CYRILLIC CAPITAL LETTER EN */
  421. { "", 0xef, 0x041e, "O"}, /* CYRILLIC CAPITAL LETTER O */
  422. { "", 0xf0, 0x041f, "P"}, /* CYRILLIC CAPITAL LETTER PE */
  423. { "", 0xf1, 0x042f, "YA"}, /* CYRILLIC CAPITAL LETTER YA */
  424. { "", 0xf2, 0x0420, "R"}, /* CYRILLIC CAPITAL LETTER ER */
  425. { "", 0xf3, 0x0421, "S"}, /* CYRILLIC CAPITAL LETTER ES */
  426. { "", 0xf4, 0x0422, "T"}, /* CYRILLIC CAPITAL LETTER TE */
  427. { "", 0xf5, 0x0423, "U"}, /* CYRILLIC CAPITAL LETTER U */
  428. { "", 0xf6, 0x0416, "ZH"}, /* CYRILLIC CAPITAL LETTER ZHE */
  429. { "", 0xf7, 0x0412, "V"}, /* CYRILLIC CAPITAL LETTER VE */
  430. { "", 0xf8, 0x042c, "X"}, /* CYRILLIC CAPITAL LETTER SOFT SIGN */
  431. { "", 0xf9, 0x042b, "Y"}, /* CYRILLIC CAPITAL LETTER YERU */
  432. { "", 0xfa, 0x0417, "Z"}, /* CYRILLIC CAPITAL LETTER ZE */
  433. { "", 0xfb, 0x0428, "SH"}, /* CYRILLIC CAPITAL LETTER SHA */
  434. { "", 0xfc, 0x042d, "E"}, /* CYRILLIC CAPITAL LETTER E */
  435. { "", 0xfd, 0x0429, "SHCH"}, /* CYRILLIC CAPITAL LETTER SHCHA */
  436. { "", 0xfe, 0x0427, "CH"}, /* CYRILLIC CAPITAL LETTER CHE */
  437. { "", 0xff, 0x042a, "W"}, /* CYRILLIC CAPITAL LETTER HARD SIGN */
  438. { NULL, 0, 0 }
  439. };
  440. encoding_type encoding_table[] = {
  441. { no_encoding, "(no encoding)", NULL },
  442. { US_ASCII, "US-ASCII", asis_map },
  443. { ISO_8859_1, "iso-8859-1", (iso_map_type *) iso8859_1_map },
  444. { ISO_8859_2, "iso-8859-2", (iso_map_type *) iso8859_2_map },
  445. { ISO_8859_3, "iso-8859-3", NULL },
  446. { ISO_8859_4, "iso-8859-4", NULL },
  447. { ISO_8859_5, "iso-8859-5", NULL },
  448. { ISO_8859_6, "iso-8859-6", NULL },
  449. { ISO_8859_7, "iso-8859-7", NULL },
  450. { ISO_8859_8, "iso-8859-8", NULL },
  451. { ISO_8859_9, "iso-8859-9", NULL },
  452. { ISO_8859_10, "iso-8859-10", NULL },
  453. { ISO_8859_11, "iso-8859-11", NULL },
  454. { ISO_8859_12, "iso-8859-12", NULL },
  455. { ISO_8859_13, "iso-8859-13", NULL },
  456. { ISO_8859_14, "iso-8859-14", NULL },
  457. { ISO_8859_15, "iso-8859-15", (iso_map_type *) iso8859_15_map },
  458. { KOI8_R, "koi8-r", (iso_map_type *) koi8_map },
  459. { KOI8_U, "koi8-u", (iso_map_type *) koi8_map },
  460. { UTF_8, "utf-8", asis_map }, /* specific code for this below */
  461. { last_encoding_code, NULL, NULL }
  462. };
  463. /* List of HTML entities. */
  464. static struct { const char *html; unsigned int unicode; } unicode_map[] = {
  465. /* Extracted from http://www.w3.org/TR/html401/sgml/entities.html through
  466. sed -n -e 's|<!ENTITY \([^ ][^ ]*\) *CDATA "[&]#\([0-9][0-9]*\);".*| { "\1", \2 },|p'
  467. | LC_ALL=C sort -k2 */
  468. { "AElig", 198 },
  469. { "Aacute", 193 },
  470. { "Acirc", 194 },
  471. { "Agrave", 192 },
  472. { "Alpha", 913 },
  473. { "Aring", 197 },
  474. { "Atilde", 195 },
  475. { "Auml", 196 },
  476. { "Beta", 914 },
  477. { "Ccedil", 199 },
  478. { "Chi", 935 },
  479. { "Dagger", 8225 },
  480. { "Delta", 916 },
  481. { "ETH", 208 },
  482. { "Eacute", 201 },
  483. { "Ecirc", 202 },
  484. { "Egrave", 200 },
  485. { "Epsilon", 917 },
  486. { "Eta", 919 },
  487. { "Euml", 203 },
  488. { "Gamma", 915 },
  489. { "Iacute", 205 },
  490. { "Icirc", 206 },
  491. { "Igrave", 204 },
  492. { "Iota", 921 },
  493. { "Iuml", 207 },
  494. { "Kappa", 922 },
  495. { "Lambda", 923 },
  496. { "Mu", 924 },
  497. { "Ntilde", 209 },
  498. { "Nu", 925 },
  499. { "OElig", 338 },
  500. { "Oacute", 211 },
  501. { "Ocirc", 212 },
  502. { "Ograve", 210 },
  503. { "Omega", 937 },
  504. { "Omicron", 927 },
  505. { "Oslash", 216 },
  506. { "Otilde", 213 },
  507. { "Ouml", 214 },
  508. { "Phi", 934 },
  509. { "Pi", 928 },
  510. { "Prime", 8243 },
  511. { "Psi", 936 },
  512. { "Rho", 929 },
  513. { "Scaron", 352 },
  514. { "Sigma", 931 },
  515. { "THORN", 222 },
  516. { "Tau", 932 },
  517. { "Theta", 920 },
  518. { "Uacute", 218 },
  519. { "Ucirc", 219 },
  520. { "Ugrave", 217 },
  521. { "Upsilon", 933 },
  522. { "Uuml", 220 },
  523. { "Xi", 926 },
  524. { "Yacute", 221 },
  525. { "Yuml", 376 },
  526. { "Zeta", 918 },
  527. { "aacute", 225 },
  528. { "acirc", 226 },
  529. { "acute", 180 },
  530. { "aelig", 230 },
  531. { "agrave", 224 },
  532. { "alefsym", 8501 },
  533. { "alpha", 945 },
  534. { "amp", 38 },
  535. { "and", 8743 },
  536. { "ang", 8736 },
  537. { "aring", 229 },
  538. { "asymp", 8776 },
  539. { "atilde", 227 },
  540. { "auml", 228 },
  541. { "bdquo", 8222 },
  542. { "beta", 946 },
  543. { "brvbar", 166 },
  544. { "bull", 8226 },
  545. { "cap", 8745 },
  546. { "ccedil", 231 },
  547. { "cedil", 184 },
  548. { "cent", 162 },
  549. { "chi", 967 },
  550. { "circ", 710 },
  551. { "clubs", 9827 },
  552. { "cong", 8773 },
  553. { "copy", 169 },
  554. { "crarr", 8629 },
  555. { "cup", 8746 },
  556. { "curren", 164 },
  557. { "dArr", 8659 },
  558. { "dagger", 8224 },
  559. { "darr", 8595 },
  560. { "deg", 176 },
  561. { "delta", 948 },
  562. { "diams", 9830 },
  563. { "divide", 247 },
  564. { "eacute", 233 },
  565. { "ecirc", 234 },
  566. { "egrave", 232 },
  567. { "empty", 8709 },
  568. { "emsp", 8195 },
  569. { "ensp", 8194 },
  570. { "epsilon", 949 },
  571. { "equiv", 8801 },
  572. { "eta", 951 },
  573. { "eth", 240 },
  574. { "euml", 235 },
  575. { "euro", 8364 },
  576. { "exist", 8707 },
  577. { "fnof", 402 },
  578. { "forall", 8704 },
  579. { "frac12", 189 },
  580. { "frac14", 188 },
  581. { "frac34", 190 },
  582. { "frasl", 8260 },
  583. { "gamma", 947 },
  584. { "ge", 8805 },
  585. { "gt", 62 },
  586. { "hArr", 8660 },
  587. { "harr", 8596 },
  588. { "hearts", 9829 },
  589. { "hellip", 8230 },
  590. { "iacute", 237 },
  591. { "icirc", 238 },
  592. { "iexcl", 161 },
  593. { "igrave", 236 },
  594. { "image", 8465 },
  595. { "infin", 8734 },
  596. { "int", 8747 },
  597. { "iota", 953 },
  598. { "iquest", 191 },
  599. { "isin", 8712 },
  600. { "iuml", 239 },
  601. { "kappa", 954 },
  602. { "lArr", 8656 },
  603. { "lambda", 955 },
  604. { "lang", 9001 },
  605. { "laquo", 171 },
  606. { "larr", 8592 },
  607. { "lceil", 8968 },
  608. { "ldquo", 8220 },
  609. { "le", 8804 },
  610. { "lfloor", 8970 },
  611. { "lowast", 8727 },
  612. { "loz", 9674 },
  613. { "lrm", 8206 },
  614. { "lsaquo", 8249 },
  615. { "lsquo", 8216 },
  616. { "lt", 60 },
  617. { "macr", 175 },
  618. { "mdash", 8212 },
  619. { "micro", 181 },
  620. { "middot", 183 },
  621. { "minus", 8722 },
  622. { "mu", 956 },
  623. { "nabla", 8711 },
  624. { "nbsp", 160 },
  625. { "ndash", 8211 },
  626. { "ne", 8800 },
  627. { "ni", 8715 },
  628. { "not", 172 },
  629. { "notin", 8713 },
  630. { "nsub", 8836 },
  631. { "ntilde", 241 },
  632. { "nu", 957 },
  633. { "oacute", 243 },
  634. { "ocirc", 244 },
  635. { "oelig", 339 },
  636. { "ograve", 242 },
  637. { "oline", 8254 },
  638. { "omega", 969 },
  639. { "omicron", 959 },
  640. { "oplus", 8853 },
  641. { "or", 8744 },
  642. { "ordf", 170 },
  643. { "ordm", 186 },
  644. { "oslash", 248 },
  645. { "otilde", 245 },
  646. { "otimes", 8855 },
  647. { "ouml", 246 },
  648. { "para", 182 },
  649. { "part", 8706 },
  650. { "permil", 8240 },
  651. { "perp", 8869 },
  652. { "phi", 966 },
  653. { "pi", 960 },
  654. { "piv", 982 },
  655. { "plusmn", 177 },
  656. { "pound", 163 },
  657. { "prime", 8242 },
  658. { "prod", 8719 },
  659. { "prop", 8733 },
  660. { "psi", 968 },
  661. { "quot", 34 },
  662. { "rArr", 8658 },
  663. { "radic", 8730 },
  664. { "rang", 9002 },
  665. { "raquo", 187 },
  666. { "rarr", 8594 },
  667. { "rceil", 8969 },
  668. { "rdquo", 8221 },
  669. { "real", 8476 },
  670. { "reg", 174 },
  671. { "rfloor", 8971 },
  672. { "rho", 961 },
  673. { "rlm", 8207 },
  674. { "rsaquo", 8250 },
  675. { "rsquo", 8217 },
  676. { "sbquo", 8218 },
  677. { "scaron", 353 },
  678. { "sdot", 8901 },
  679. { "sect", 167 },
  680. { "shy", 173 },
  681. { "sigma", 963 },
  682. { "sigmaf", 962 },
  683. { "sim", 8764 },
  684. { "spades", 9824 },
  685. { "sub", 8834 },
  686. { "sube", 8838 },
  687. { "sum", 8721 },
  688. { "sup", 8835 },
  689. { "sup1", 185 },
  690. { "sup2", 178 },
  691. { "sup3", 179 },
  692. { "supe", 8839 },
  693. { "szlig", 223 },
  694. { "tau", 964 },
  695. { "there4", 8756 },
  696. { "theta", 952 },
  697. { "thetasym", 977 },
  698. { "thinsp", 8201 },
  699. { "thorn", 254 },
  700. { "tilde", 732 },
  701. { "times", 215 },
  702. { "trade", 8482 },
  703. { "uArr", 8657 },
  704. { "uacute", 250 },
  705. { "uarr", 8593 },
  706. { "ucirc", 251 },
  707. { "ugrave", 249 },
  708. { "uml", 168 },
  709. { "upsih", 978 },
  710. { "upsilon", 965 },
  711. { "uuml", 252 },
  712. { "weierp", 8472 },
  713. { "xi", 958 },
  714. { "yacute", 253 },
  715. { "yen", 165 },
  716. { "yuml", 255 },
  717. { "zeta", 950 },
  718. { "zwj", 8205 },
  719. { "zwnj", 8204 }
  720. };
  721. /* To update this list of language codes, download the current data from
  722. http://www.loc.gov/standards/iso639-2; specifically,
  723. http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits-8559-1.txt.
  724. Run cut -d\| -f 3,4 <ISO-639-2_values_8bits-8559-1.txt | sort -u >/tmp/639.2
  725. Extract the C table below to a file, say /tmp/lc, and run:
  726. cut -c 10- /tmp/lc| sed -e 's/", "/|/' -e 's,".*,,'>/tmp/lang.2
  727. Then: comm -3 /tmp/639.2 /tmp/lang.c.
  728. Also update the enum in lang.h. */
  729. language_type language_table[] = {
  730. { aa, "aa", "Afar" },
  731. { ab, "ab", "Abkhazian" },
  732. { ae, "ae", "Avestan" },
  733. { af, "af", "Afrikaans" },
  734. { ak, "ak", "Akan" },
  735. { am, "am", "Amharic" },
  736. { an, "an", "Aragonese" },
  737. { ar, "ar", "Arabic" },
  738. { as, "as", "Assamese" },
  739. { av, "av", "Avaric" },
  740. { ay, "ay", "Aymara" },
  741. { az, "az", "Azerbaijani" },
  742. { ba, "ba", "Bashkir" },
  743. { be, "be", "Belarusian" },
  744. { bg, "bg", "Bulgarian" },
  745. { bh, "bh", "Bihari" },
  746. { bi, "bi", "Bislama" },
  747. { bm, "bm", "Bambara" },
  748. { bn, "bn", "Bengali" },
  749. { bo, "bo", "Tibetan" },
  750. { br, "br", "Breton" },
  751. { bs, "bs", "Bosnian" },
  752. { ca, "ca", "Catalan; Valencian" },
  753. { ce, "ce", "Chechen" },
  754. { ch, "ch", "Chamorro" },
  755. { co, "co", "Corsican" },
  756. { cr, "cr", "Cree" },
  757. { cs, "cs", "Czech" },
  758. { cu, "cu", "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic" },
  759. { cv, "cv", "Chuvash" },
  760. { cy, "cy", "Welsh" },
  761. { da, "da", "Danish" },
  762. { de, "de", "German" },
  763. { dv, "dv", "Divehi; Dhivehi; Maldivian" },
  764. { dz, "dz", "Dzongkha" },
  765. { ee, "ee", "Ewe" },
  766. { el, "el", "Greek, Modern (1453-)" },
  767. { en, "en", "English" },
  768. { eo, "eo", "Esperanto" },
  769. { es, "es", "Spanish; Castilian" },
  770. { et, "et", "Estonian" },
  771. { eu, "eu", "Basque" },
  772. { fa, "fa", "Persian" },
  773. { ff, "ff", "Fulah" },
  774. { fi, "fi", "Finnish" },
  775. { fj, "fj", "Fijian" },
  776. { fo, "fo", "Faroese" },
  777. { fr, "fr", "French" },
  778. { fy, "fy", "Western Frisian" },
  779. { ga, "ga", "Irish" },
  780. { gd, "gd", "Gaelic; Scottish Gaelic" },
  781. { gl, "gl", "Galician" },
  782. { gn, "gn", "Guarani" },
  783. { gu, "gu", "Gujarati" },
  784. { gv, "gv", "Manx" },
  785. { ha, "ha", "Hausa" },
  786. { he, "he", "Hebrew" } /* (formerly iw) */,
  787. { hi, "hi", "Hindi" },
  788. { ho, "ho", "Hiri Motu" },
  789. { hr, "hr", "Croatian" },
  790. { ht, "ht", "Haitian; Haitian Creole" },
  791. { hu, "hu", "Hungarian" },
  792. { hy, "hy", "Armenian" },
  793. { hz, "hz", "Herero" },
  794. { ia, "ia", "Interlingua (International Auxiliary Language Association)" },
  795. { id, "id", "Indonesian" } /* (formerly in) */,
  796. { ie, "ie", "Interlingue" },
  797. { ig, "ig", "Igbo" },
  798. { ii, "ii", "Sichuan Yi" },
  799. { ik, "ik", "Inupiaq" },
  800. { io, "io", "Ido" },
  801. { is, "is", "Icelandic" },
  802. { it, "it", "Italian" },
  803. { iu, "iu", "Inuktitut" },
  804. { ja, "ja", "Japanese" },
  805. { jv, "jv", "Javanese" },
  806. { ka, "ka", "Georgian" },
  807. { kg, "kg", "Kongo" },
  808. { ki, "ki", "Kikuyu; Gikuyu" },
  809. { kj, "kj", "Kuanyama; Kwanyama" },
  810. { kk, "kk", "Kazakh" },
  811. { kl, "kl", "Kalaallisut; Greenlandic" },
  812. { km, "km", "Central Khmer" },
  813. { kn, "kn", "Kannada" },
  814. { ko, "ko", "Korean" },
  815. { kr, "kr", "Kanuri" },
  816. { ks, "ks", "Kashmiri" },
  817. { ku, "ku", "Kurdish" },
  818. { kv, "kv", "Komi" },
  819. { kw, "kw", "Cornish" },
  820. { ky, "ky", "Kirghiz; Kyrgyz" },
  821. { la, "la", "Latin" },
  822. { lb, "lb", "Luxembourgish; Letzeburgesch" },
  823. { lg, "lg", "Ganda" },
  824. { li, "li", "Limburgan; Limburger; Limburgish" },
  825. { ln, "ln", "Lingala" },
  826. { lo, "lo", "Lao" },
  827. { lt, "lt", "Lithuanian" },
  828. { lu, "lu", "Luba-Katanga" },
  829. { lv, "lv", "Latvian" },
  830. { mg, "mg", "Malagasy" },
  831. { mh, "mh", "Marshallese" },
  832. { mi, "mi", "Maori" },
  833. { mk, "mk", "Macedonian" },
  834. { ml, "ml", "Malayalam" },
  835. { mn, "mn", "Mongolian" },
  836. { mo, "mo", "Moldavian" },
  837. { mr, "mr", "Marathi" },
  838. { ms, "ms", "Malay" },
  839. { mt, "mt", "Maltese" },
  840. { my, "my", "Burmese" },
  841. { na, "na", "Nauru" },
  842. { nb, "nb", "Bokmål, Norwegian; Norwegian Bokmål" },
  843. { nd, "nd", "Ndebele, North; North Ndebele" },
  844. { ne, "ne", "Nepali" },
  845. { ng, "ng", "Ndonga" },
  846. { nl, "nl", "Dutch; Flemish" },
  847. { nn, "nn", "Norwegian Nynorsk; Nynorsk, Norwegian" },
  848. { no, "no", "Norwegian" },
  849. { nr, "nr", "Ndebele, South; South Ndebele" },
  850. { nv, "nv", "Navajo; Navaho" },
  851. { ny, "ny", "Chichewa; Chewa; Nyanja" },
  852. { oc, "oc", "Occitan (post 1500); Provençal" },
  853. { oj, "oj", "Ojibwa" },
  854. { om, "om", "Oromo" },
  855. { or, "or", "Oriya" },
  856. { os, "os", "Ossetian; Ossetic" },
  857. { pa, "pa", "Panjabi; Punjabi" },
  858. { pi, "pi", "Pali" },
  859. { pl, "pl", "Polish" },
  860. { ps, "ps", "Pushto" },
  861. { pt, "pt", "Portuguese" },
  862. { qu, "qu", "Quechua" },
  863. { rm, "rm", "Romansh" },
  864. { rn, "rn", "Rundi" },
  865. { ro, "ro", "Romanian" },
  866. { ru, "ru", "Russian" },
  867. { rw, "rw", "Kinyarwanda" },
  868. { sa, "sa", "Sanskrit" },
  869. { sc, "sc", "Sardinian" },
  870. { sd, "sd", "Sindhi" },
  871. { se, "se", "Northern Sami" },
  872. { sg, "sg", "Sango" },
  873. { si, "si", "Sinhala; Sinhalese" },
  874. { sk, "sk", "Slovak" },
  875. { sl, "sl", "Slovenian" },
  876. { sm, "sm", "Samoan" },
  877. { sn, "sn", "Shona" },
  878. { so, "so", "Somali" },
  879. { sq, "sq", "Albanian" },
  880. { sr, "sr", "Serbian" },
  881. { ss, "ss", "Swati" },
  882. { st, "st", "Sotho, Souther" },
  883. { su, "su", "Sundanese" },
  884. { sv, "sv", "Swedish" },
  885. { sw, "sw", "Swahili" },
  886. { ta, "ta", "Tamil" },
  887. { te, "te", "Telugu" },
  888. { tg, "tg", "Tajik" },
  889. { th, "th", "Thai" },
  890. { ti, "ti", "Tigrinya" },
  891. { tk, "tk", "Turkmen" },
  892. { tl, "tl", "Tagalog" },
  893. { tn, "tn", "Tswana" },
  894. { to, "to", "Tonga (Tonga Islands)" },
  895. { tr, "tr", "Turkish" },
  896. { ts, "ts", "Tsonga" },
  897. { tt, "tt", "Tatar" },
  898. { tw, "tw", "Twi" },
  899. { ty, "ty", "Tahitian" },
  900. { ug, "ug", "Uighur; Uyghur" },
  901. { uk, "uk", "Ukrainian" },
  902. { ur, "ur", "Urdu" },
  903. { uz, "uz", "Uzbek" },
  904. { ve, "ve", "Venda" },
  905. { vi, "vi", "Vietnamese" },
  906. { vo, "vo", "Volapük" },
  907. { wa, "wa", "Walloon" },
  908. { wo, "wo", "Wolof" },
  909. { xh, "xh", "Xhosa" },
  910. { yi, "yi", "Yiddish" } /* (formerly ji) */,
  911. { yo, "yo", "Yoruba" },
  912. { za, "za", "Zhuang; Chuang" },
  913. { zh, "zh", "Chinese" },
  914. { zu, "zu", "Zulu" },
  915. { last_language_code, NULL, NULL }
  916. };
  917. static const char *
  918. cm_search_iso_map_char (byte_t ch)
  919. {
  920. int i;
  921. iso_map_type *iso = encoding_table[document_encoding_code].isotab;
  922. /* If no conversion table for this encoding, quit. */
  923. if (!iso)
  924. return NULL;
  925. for (i = 0; iso[i].html; i++)
  926. if (iso[i].bytecode == ch)
  927. return iso[i].translit;
  928. return NULL;
  929. }
  930. const char *
  931. lang_transliterate_char (byte_t ch)
  932. {
  933. if (transliterate_file_names
  934. && document_encoding_code != no_encoding)
  935. return cm_search_iso_map_char (ch);
  936. return NULL;
  937. }
  938. /* Given a language code LL_CODE, return a "default" country code (in
  939. new memory). We use the same table as gettext, and return LL_CODE
  940. uppercased in the absence of any better possibility, with a warning.
  941. (gettext silently defaults to the C locale, but we want to give users
  942. a shot at fixing ambiguities.) We also return en_US for en, while
  943. gettext does not. */
  944. #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
  945. static char *
  946. default_country_for_lang (const char *ll_code)
  947. {
  948. /* This table comes from msginit.c in gettext (0.16.1). It is
  949. intentionally copied verbatim even though the format is not the
  950. most convenient for our purposes, to make updates simple. */
  951. static const char *locales_with_principal_territory[] = {
  952. /* Language Main territory */
  953. "ace_ID", /* Achinese Indonesia */
  954. "af_ZA", /* Afrikaans South Africa */
  955. "ak_GH", /* Akan Ghana */
  956. "am_ET", /* Amharic Ethiopia */
  957. "an_ES", /* Aragonese Spain */
  958. "ang_GB", /* Old English Britain */
  959. "as_IN", /* Assamese India */
  960. "av_RU", /* Avaric Russia */
  961. "awa_IN", /* Awadhi India */
  962. "az_AZ", /* Azerbaijani Azerbaijan */
  963. "bad_CF", /* Banda Central African Republic */
  964. "ban_ID", /* Balinese Indonesia */
  965. "be_BY", /* Belarusian Belarus */
  966. "bem_ZM", /* Bemba Zambia */
  967. "bg_BG", /* Bulgarian Bulgaria */
  968. "bho_IN", /* Bhojpuri India */
  969. "bik_PH", /* Bikol Philippines */
  970. "bin_NG", /* Bini Nigeria */
  971. "bm_ML", /* Bambara Mali */
  972. "bn_IN", /* Bengali India */
  973. "bo_CN", /* Tibetan China */
  974. "br_FR", /* Breton France */
  975. "bs_BA", /* Bosnian Bosnia */
  976. "btk_ID", /* Batak Indonesia */
  977. "bug_ID", /* Buginese Indonesia */
  978. "ca_ES", /* Catalan Spain */
  979. "ce_RU", /* Chechen Russia */
  980. "ceb_PH", /* Cebuano Philippines */
  981. "co_FR", /* Corsican France */
  982. "cr_CA", /* Cree Canada */
  983. "cs_CZ", /* Czech Czech Republic */
  984. "csb_PL", /* Kashubian Poland */
  985. "cy_GB", /* Welsh Britain */
  986. "da_DK", /* Danish Denmark */
  987. "de_DE", /* German Germany */
  988. "din_SD", /* Dinka Sudan */
  989. "doi_IN", /* Dogri India */
  990. "dv_MV", /* Divehi Maldives */
  991. "dz_BT", /* Dzongkha Bhutan */
  992. "ee_GH", /* Éwé Ghana */
  993. "el_GR", /* Greek Greece */
  994. /* Don't put "en_GB" or "en_US" here. That would be asking for fruitless
  995. political discussion. */
  996. "es_ES", /* Spanish Spain */
  997. "et_EE", /* Estonian Estonia */
  998. "fa_IR", /* Persian Iran */
  999. "fi_FI", /* Finnish Finland */
  1000. "fil_PH", /* Filipino Philippines */
  1001. "fj_FJ", /* Fijian Fiji */
  1002. "fo_FO", /* Faroese Faeroe Islands */
  1003. "fon_BJ", /* Fon Benin */
  1004. "fr_FR", /* French France */
  1005. "fy_NL", /* Western Frisian Netherlands */
  1006. "ga_IE", /* Irish Ireland */
  1007. "gd_GB", /* Scots Britain */
  1008. "gon_IN", /* Gondi India */
  1009. "gsw_CH", /* Swiss German Switzerland */
  1010. "gu_IN", /* Gujarati India */
  1011. "he_IL", /* Hebrew Israel */
  1012. "hi_IN", /* Hindi India */
  1013. "hil_PH", /* Hiligaynon Philippines */
  1014. "hr_HR", /* Croatian Croatia */
  1015. "ht_HT", /* Haitian Haiti */
  1016. "hu_HU", /* Hungarian Hungary */
  1017. "hy_AM", /* Armenian Armenia */
  1018. "id_ID", /* Indonesian Indonesia */
  1019. "ig_NG", /* Igbo Nigeria */
  1020. "ii_CN", /* Sichuan Yi China */
  1021. "ilo_PH", /* Iloko Philippines */
  1022. "is_IS", /* Icelandic Iceland */
  1023. "it_IT", /* Italian Italy */
  1024. "ja_JP", /* Japanese Japan */
  1025. "jab_NG", /* Hyam Nigeria */
  1026. "jv_ID", /* Javanese Indonesia */
  1027. "ka_GE", /* Georgian Georgia */
  1028. "kab_DZ", /* Kabyle Algeria */
  1029. "kaj_NG", /* Jju Nigeria */
  1030. "kam_KE", /* Kamba Kenya */
  1031. "kmb_AO", /* Kimbundu Angola */
  1032. "kcg_NG", /* Tyap Nigeria */
  1033. "kdm_NG", /* Kagoma Nigeria */
  1034. "kg_CD", /* Kongo Democratic Republic of Congo */
  1035. "kk_KZ", /* Kazakh Kazakhstan */
  1036. "kl_GL", /* Kalaallisut Greenland */
  1037. "km_KH", /* Khmer Cambodia */
  1038. "kn_IN", /* Kannada India */
  1039. "ko_KR", /* Korean Korea (South) */
  1040. "kok_IN", /* Konkani India */
  1041. "kr_NG", /* Kanuri Nigeria */
  1042. "kru_IN", /* Kurukh India */
  1043. "lg_UG", /* Ganda Uganda */
  1044. "li_BE", /* Limburgish Belgium */
  1045. "lo_LA", /* Laotian Laos */
  1046. "lt_LT", /* Lithuanian Lithuania */
  1047. "lu_CD", /* Luba-Katanga Democratic Republic of Congo */
  1048. "lua_CD", /* Luba-Lulua Democratic Republic of Congo */
  1049. "luo_KE", /* Luo Kenya */
  1050. "lv_LV", /* Latvian Latvia */
  1051. "mad_ID", /* Madurese Indonesia */
  1052. "mag_IN", /* Magahi India */
  1053. "mai_IN", /* Maithili India */
  1054. "mak_ID", /* Makasar Indonesia */
  1055. "man_ML", /* Mandingo Mali */
  1056. "men_SL", /* Mende Sierra Leone */
  1057. "mg_MG", /* Malagasy Madagascar */
  1058. "min_ID", /* Minangkabau Indonesia */
  1059. "mk_MK", /* Macedonian Macedonia */
  1060. "ml_IN", /* Malayalam India */
  1061. "mn_MN", /* Mongolian Mongolia */
  1062. "mni_IN", /* Manipuri India */
  1063. "mos_BF", /* Mossi Burkina Faso */
  1064. "mr_IN", /* Marathi India */
  1065. "ms_MY", /* Malay Malaysia */
  1066. "mt_MT", /* Maltese Malta */
  1067. "mwr_IN", /* Marwari India */
  1068. "my_MM", /* Burmese Myanmar */
  1069. "na_NR", /* Nauru Nauru */
  1070. "nah_MX", /* Nahuatl Mexico */
  1071. "nap_IT", /* Neapolitan Italy */
  1072. "nb_NO", /* Norwegian Bokmål Norway */
  1073. "nds_DE", /* Low Saxon Germany */
  1074. "ne_NP", /* Nepali Nepal */
  1075. "nl_NL", /* Dutch Netherlands */
  1076. "nn_NO", /* Norwegian Nynorsk Norway */
  1077. "no_NO", /* Norwegian Norway */
  1078. "nr_ZA", /* South Ndebele South Africa */
  1079. "nso_ZA", /* Northern Sotho South Africa */
  1080. "nym_TZ", /* Nyamwezi Tanzania */
  1081. "nyn_UG", /* Nyankole Uganda */
  1082. "oc_FR", /* Occitan France */
  1083. "oj_CA", /* Ojibwa Canada */
  1084. "or_IN", /* Oriya India */
  1085. "pa_IN", /* Punjabi India */
  1086. "pag_PH", /* Pangasinan Philippines */
  1087. "pam_PH", /* Pampanga Philippines */
  1088. "pbb_CO", /* Páez Colombia */
  1089. "pl_PL", /* Polish Poland */
  1090. "ps_AF", /* Pashto Afghanistan */
  1091. "pt_PT", /* Portuguese Portugal */
  1092. "raj_IN", /* Rajasthani India */
  1093. "rm_CH", /* Rhaeto-Roman Switzerland */
  1094. "rn_BI", /* Kirundi Burundi */
  1095. "ro_RO", /* Romanian Romania */
  1096. "ru_RU", /* Russian Russia */
  1097. "sa_IN", /* Sanskrit India */
  1098. "sas_ID", /* Sasak Indonesia */
  1099. "sat_IN", /* Santali India */
  1100. "sc_IT", /* Sardinian Italy */
  1101. "scn_IT", /* Sicilian Italy */
  1102. "sg_CF", /* Sango Central African Republic */
  1103. "shn_MM", /* Shan Myanmar */
  1104. "si_LK", /* Sinhala Sri Lanka */
  1105. "sid_ET", /* Sidamo Ethiopia */
  1106. "sk_SK", /* Slovak Slovakia */
  1107. "sl_SI", /* Slovenian Slovenia */
  1108. "so_SO", /* Somali Somalia */
  1109. "sq_AL", /* Albanian Albania */
  1110. "sr_RS", /* Serbian Serbia */
  1111. "sr_YU", /* Serbian Yugoslavia */
  1112. "srr_SN", /* Serer Senegal */
  1113. "suk_TZ", /* Sukuma Tanzania */
  1114. "sus_GN", /* Susu Guinea */
  1115. "sv_SE", /* Swedish Sweden */
  1116. "te_IN", /* Telugu India */
  1117. "tem_SL", /* Timne Sierra Leone */
  1118. "tet_ID", /* Tetum Indonesia */
  1119. "tg_TJ", /* Tajik Tajikistan */
  1120. "th_TH", /* Thai Thailand */
  1121. "tiv_NG", /* Tiv Nigeria */
  1122. "tk_TM", /* Turkmen Turkmenistan */
  1123. "tl_PH", /* Tagalog Philippines */
  1124. "to_TO", /* Tonga Tonga */
  1125. "tr_TR", /* Turkish Turkey */
  1126. "tum_MW", /* Tumbuka Malawi */
  1127. "uk_UA", /* Ukrainian Ukraine */
  1128. "umb_AO", /* Umbundu Angola */
  1129. "ur_PK", /* Urdu Pakistan */
  1130. "uz_UZ", /* Uzbek Uzbekistan */
  1131. "ve_ZA", /* Venda South Africa */
  1132. "vi_VN", /* Vietnamese Vietnam */
  1133. "wa_BE", /* Walloon Belgium */
  1134. "wal_ET", /* Walamo Ethiopia */
  1135. "war_PH", /* Waray Philippines */
  1136. "wen_DE", /* Sorbian Germany */
  1137. "yao_MW", /* Yao Malawi */
  1138. "zap_MX" /* Zapotec Mexico */
  1139. };
  1140. int c;
  1141. int cc_len;
  1142. int ll_len = strlen (ll_code);
  1143. char *cc_code = xmalloc (ll_len + 1 + 1);
  1144. int principal_len = SIZEOF (locales_with_principal_territory);
  1145. strcpy (cc_code, ll_code);
  1146. strcat (cc_code, "_");
  1147. cc_len = ll_len + 1;
  1148. for (c = 0; c < principal_len; c++)
  1149. {
  1150. const char *principal_locale = locales_with_principal_territory[c];
  1151. if (strncmp (principal_locale, cc_code, cc_len) == 0)
  1152. {
  1153. const char *underscore = strchr (principal_locale, '_');
  1154. /* should always be there, but in case ... */
  1155. free (cc_code);
  1156. cc_code = xstrdup (underscore ? underscore + 1 : principal_locale);
  1157. break;
  1158. }
  1159. }
  1160. /* If we didn't find one to copy, warn and duplicate. */
  1161. if (c == principal_len)
  1162. {
  1163. if (mbscasecmp (ll_code, "en") == 0)
  1164. cc_code = xstrdup ("en_US");
  1165. else
  1166. {
  1167. warning (_("no default territory known for language `%s'"), ll_code);
  1168. for (c = 0; c < strlen (ll_code); c++)
  1169. cc_code[c] = toupper (ll_code[c]);
  1170. cc_code[c] = 0;
  1171. /* We're probably wasting a byte, oops. */
  1172. }
  1173. }
  1174. return cc_code;
  1175. }
  1176. /* @documentlanguage ARG. We set the global `document_language' (which
  1177. `getdocumenttext' uses) to the gettextish string, and
  1178. `language_code' to the corresponding enum value. */
  1179. void
  1180. cm_documentlanguage (void)
  1181. {
  1182. language_code_type c;
  1183. char *lang_arg, *ll_part, *cc_part, *locale_string;
  1184. char *underscore;
  1185. /* Read the line with the language code on it. */
  1186. get_rest_of_line (0, &lang_arg);
  1187. /* What we're passed might be either just a language code LL (we'll
  1188. also need it with the usual _CC appended, if there is one), or a
  1189. locale name as used by gettext, LL_CC (we'll also need its
  1190. constituents separately). */
  1191. underscore = strchr (lang_arg, '_');
  1192. if (underscore)
  1193. {
  1194. ll_part = substring (lang_arg, underscore);
  1195. cc_part = xstrdup (underscore + 1);
  1196. locale_string = xstrdup (lang_arg);
  1197. }
  1198. else
  1199. {
  1200. ll_part = xstrdup (lang_arg);
  1201. cc_part = default_country_for_lang (ll_part);
  1202. locale_string = xmalloc (strlen (ll_part) + 1 + strlen (cc_part) + 1);
  1203. strcpy (locale_string, ll_part);
  1204. strcat (locale_string, "_");
  1205. strcat (locale_string, cc_part);
  1206. }
  1207. /* Done with analysis of user-supplied string. */
  1208. free (lang_arg);
  1209. /* Linear search is fine these days. */
  1210. for (c = aa; c != last_language_code; c++)
  1211. {
  1212. if (strcmp (ll_part, language_table[c].abbrev) == 0)
  1213. { /* Set current language code. */
  1214. language_code = c;
  1215. break;
  1216. }
  1217. }
  1218. /* If we didn't find this code, complain. */
  1219. if (c == last_language_code)
  1220. warning (_("%s is not a valid ISO 639 language code"), ll_part);
  1221. /* Set the language our `getdocumenttext' function uses for
  1222. translating document strings. */
  1223. document_language = xstrdup (locale_string);
  1224. free (locale_string);
  1225. if (xml && !docbook)
  1226. { /* According to http://www.opentag.com/xfaq_lang.htm, xml:lang
  1227. takes an ISO 639 language code, optionally followed by a dash
  1228. (not underscore) and an ISO 3166 country code. So we have
  1229. to make another version with - instead of _. */
  1230. char *xml_locale = xmalloc (strlen (ll_part) + 1 + strlen (cc_part) + 1);
  1231. strcpy (xml_locale, ll_part);
  1232. strcat (xml_locale, "-");
  1233. strcat (xml_locale, cc_part);
  1234. xml_insert_element_with_attribute (DOCUMENTLANGUAGE, START,
  1235. "xml:lang=\"%s\"", xml_locale);
  1236. xml_insert_element (DOCUMENTLANGUAGE, END);
  1237. free (xml_locale);
  1238. }
  1239. free (ll_part);
  1240. free (cc_part);
  1241. }
  1242. /* Search through the encoding table for the given character, returning
  1243. its equivalent. */
  1244. static int
  1245. cm_search_iso_map (char *html)
  1246. {
  1247. if (document_encoding_code == UTF_8)
  1248. {
  1249. /* Binary search in unicode_map. */
  1250. size_t low = 0;
  1251. size_t high = sizeof (unicode_map) / sizeof (unicode_map[0]);
  1252. /* At each loop iteration, low < high; for indices < low the values are
  1253. smaller than HTML; for indices >= high the values are greater than HTML.
  1254. So, if HTML occurs in the list, it is at low <= position < high. */
  1255. do
  1256. {
  1257. size_t mid = low + (high - low) / 2; /* low <= mid < high */
  1258. int cmp = strcmp (unicode_map[mid].html, html);
  1259. if (cmp < 0)
  1260. low = mid + 1;
  1261. else if (cmp > 0)
  1262. high = mid;
  1263. else /* cmp == 0 */
  1264. return unicode_map[mid].unicode;
  1265. }
  1266. while (low < high);
  1267. return -1;
  1268. }
  1269. else
  1270. {
  1271. int i;
  1272. iso_map_type *iso = encoding_table[document_encoding_code].isotab;
  1273. /* If no conversion table for this encoding, quit. */
  1274. if (!iso)
  1275. return -1;
  1276. for (i = 0; iso[i].html; i++)
  1277. {
  1278. if (strcmp (html, iso[i].html) == 0)
  1279. return i;
  1280. }
  1281. return -1;
  1282. }
  1283. }
  1284. /* @documentencoding. Set the translation table. */
  1285. void
  1286. cm_documentencoding (void)
  1287. {
  1288. if (!handling_delayed_writes)
  1289. {
  1290. encoding_code_type enc;
  1291. char *enc_arg;
  1292. /* This is ugly and probably needs to apply to other commands'
  1293. argument parsing as well. When we're doing @documentencoding,
  1294. we're generally in the frontmatter of the document, and so the.
  1295. expansion in html/xml/docbook would generally be the empty string.
  1296. (Because those modes wait until the first normal text of the
  1297. document to start outputting.) The result would thus be a warning
  1298. "unrecognized encoding name `'". Sigh. */
  1299. int save_html = html;
  1300. int save_xml = xml;
  1301. html = 0;
  1302. xml = 0;
  1303. get_rest_of_line (1, &enc_arg);
  1304. html = save_html;
  1305. xml = save_xml;
  1306. /* See if we have this encoding. */
  1307. for (enc = no_encoding+1; enc != last_encoding_code; enc++)
  1308. {
  1309. if (mbscasecmp (enc_arg, encoding_table[enc].encname) == 0)
  1310. {
  1311. document_encoding_code = enc;
  1312. break;
  1313. }
  1314. }
  1315. /* If we didn't find this code, complain. */
  1316. if (enc == last_encoding_code)
  1317. {
  1318. warning (_("unrecognized encoding name `%s'"), enc_arg);
  1319. /* Let the previous one go. */
  1320. if (unknown_encoding && *unknown_encoding)
  1321. free (unknown_encoding);
  1322. unknown_encoding = xstrdup (enc_arg);
  1323. }
  1324. else if (encoding_table[document_encoding_code].isotab == NULL)
  1325. warning (_("sorry, encoding `%s' not supported"), enc_arg);
  1326. free (enc_arg);
  1327. }
  1328. else if (xml)
  1329. {
  1330. char *encoding = current_document_encoding ();
  1331. if (encoding && *encoding)
  1332. {
  1333. insert_string (" encoding=\"");
  1334. insert_string (encoding);
  1335. insert_string ("\"");
  1336. }
  1337. free (encoding);
  1338. }
  1339. }
  1340. char *
  1341. current_document_encoding (void)
  1342. {
  1343. if (document_encoding_code != no_encoding)
  1344. return xstrdup (encoding_table[document_encoding_code].encname);
  1345. else if (unknown_encoding && *unknown_encoding)
  1346. return xstrdup (unknown_encoding);
  1347. else
  1348. return xstrdup ("");
  1349. }
  1350. /* Add RC per the current encoding. */
  1351. static void
  1352. add_encoded_char_from_code (int rc)
  1353. {
  1354. if (document_encoding_code == UTF_8)
  1355. {
  1356. if (rc < 0x80)
  1357. add_char (rc);
  1358. else if (rc < 0x800)
  1359. {
  1360. add_char (0xc0 | (rc >> 6));
  1361. add_char (0x80 | (rc & 0x3f));
  1362. }
  1363. else if (rc < 0x10000)
  1364. {
  1365. add_char (0xe0 | (rc >> 12));
  1366. add_char (0x80 | ((rc >> 6) & 0x3f));
  1367. add_char (0x80 | (rc & 0x3f));
  1368. }
  1369. else
  1370. {
  1371. add_char (0xf0 | (rc >> 18));
  1372. add_char (0x80 | ((rc >> 12) & 0x3f));
  1373. add_char (0x80 | ((rc >> 6) & 0x3f));
  1374. add_char (0x80 | (rc & 0x3f));
  1375. }
  1376. }
  1377. else
  1378. add_char (encoding_table[document_encoding_code].isotab[rc].bytecode);
  1379. }
  1380. /* If html or xml output, add &HTML_STR; to the output. If not html and
  1381. the user requested encoded output, add the real 8-bit character
  1382. corresponding to HTML_STR from the translation tables. Otherwise,
  1383. add INFO_STR. */
  1384. static void
  1385. add_encoded_char (char *html_str, char *info_str)
  1386. {
  1387. if (html)
  1388. add_word_args ("&%s;", html_str);
  1389. else if (xml)
  1390. xml_insert_entity (html_str);
  1391. else if (enable_encoding && document_encoding_code != no_encoding)
  1392. {
  1393. /* Look for HTML_STR in the current translation table. */
  1394. int rc = cm_search_iso_map (html_str);
  1395. if (rc >= 0)
  1396. /* We found it, add the real character. */
  1397. add_encoded_char_from_code (rc);
  1398. else
  1399. { /* We didn't find it, that seems bad. */
  1400. warning (_("invalid encoded character `%s'"), html_str);
  1401. add_word (info_str);
  1402. }
  1403. }
  1404. else
  1405. add_word (info_str);
  1406. }
  1407. /* Output an accent for HTML or XML. */
  1408. static void
  1409. cm_accent_generic_html (int arg, int start, int end, char *html_supported,
  1410. int single, int html_solo_standalone, char *html_solo)
  1411. {
  1412. static int valid_html_accent; /* yikes */
  1413. if (arg == START)
  1414. { /* If HTML has good support for this character, use it. */
  1415. if (strchr (html_supported, curchar ()))
  1416. { /* Yes; start with an ampersand. The character itself
  1417. will be added later in read_command (makeinfo.c). */
  1418. int saved_escape_html = escape_html;
  1419. escape_html = 0;
  1420. valid_html_accent = 1;
  1421. add_char ('&');
  1422. escape_html = saved_escape_html;
  1423. }
  1424. else
  1425. { /* @dotless{i} is not listed in html_supported but HTML entities
  1426. starting with `i' can be used, such as &icirc;. */
  1427. int save_input_text_offset = input_text_offset;
  1428. char *accent_contents;
  1429. get_until_in_braces ("\n", &accent_contents);
  1430. canon_white (accent_contents);
  1431. if (strstr (accent_contents, "@dotless{i"))
  1432. {
  1433. add_word_args ("&%c", accent_contents[9]);
  1434. valid_html_accent = 1;
  1435. }
  1436. else
  1437. {
  1438. /* Search for @dotless{} wasn't successful, so rewind. */
  1439. input_text_offset = save_input_text_offset;
  1440. valid_html_accent = 0;
  1441. if (html_solo_standalone)
  1442. { /* No special HTML support, so produce standalone char. */
  1443. if (xml)
  1444. xml_insert_entity (html_solo);
  1445. else
  1446. add_word_args ("&%s;", html_solo);
  1447. }
  1448. else
  1449. /* If the html_solo does not exist as standalone character
  1450. (namely &circ; &grave; &tilde;), then we use
  1451. the single character version instead. */
  1452. add_char (single);
  1453. }
  1454. free (accent_contents);
  1455. }
  1456. }
  1457. else if (arg == END)
  1458. { /* Only if we saw a valid_html_accent can we use the full
  1459. HTML accent (umlaut, grave ...). */
  1460. if (valid_html_accent)
  1461. {
  1462. add_word (html_solo);
  1463. add_char (';');
  1464. }
  1465. }
  1466. }
  1467. /* If END is zero, there is nothing in the paragraph to accent. This
  1468. can happen when we're in a menu with an accent command and
  1469. --no-headers is given, so the base character is not added. In this
  1470. case we're not producing any output anyway, so just forget it.
  1471. Otherwise, produce the ASCII version of the accented char. */
  1472. static void
  1473. cm_accent_generic_no_headers (int arg, int start, int end, int single,
  1474. char *html_solo)
  1475. {
  1476. if (arg == END && end > 0)
  1477. {
  1478. if (no_encoding)
  1479. add_char (single);
  1480. else
  1481. {
  1482. int rc;
  1483. char *buffer = xmalloc (1 + strlen (html_solo) + 1);
  1484. assert (end > 0);
  1485. buffer[0] = output_paragraph[end - 1];
  1486. buffer[1] = 0;
  1487. strcat (buffer, html_solo);
  1488. rc = cm_search_iso_map (buffer);
  1489. if (rc >= 0)
  1490. {
  1491. /* Here we replace the character which has
  1492. been inserted in read_command with
  1493. the value we have found in the conversion table. */
  1494. output_paragraph_offset--;
  1495. add_encoded_char_from_code (rc);
  1496. }
  1497. else
  1498. { /* If we didn't find a translation for this character,
  1499. put the single instead. E.g., &Xuml; does not exist so X&uml;
  1500. should be produced. */
  1501. /* When the below warning is issued, an author has nothing
  1502. wrong in their document, let alone anything ``fixable''
  1503. on their side. So it is commented out for now. */
  1504. /* warning (_("%s is an invalid ISO code, using %c"),
  1505. buffer, single); */
  1506. add_char (single);
  1507. }
  1508. free (buffer);
  1509. }
  1510. }
  1511. }
  1512. /* Accent commands that take explicit arguments and don't have any
  1513. special HTML support. */
  1514. void
  1515. cm_accent (int arg)
  1516. {
  1517. int old_escape_html = escape_html;
  1518. escape_html = 0;
  1519. if (arg == START)
  1520. {
  1521. /* Must come first to avoid ambiguity with overdot. */
  1522. if (strcmp (command, "udotaccent") == 0) /* underdot */
  1523. add_char ('.');
  1524. }
  1525. else if (arg == END)
  1526. {
  1527. if (strcmp (command, "=") == 0) /* macron */
  1528. add_word ((html || xml) ? "&macr;" : "=");
  1529. else if (strcmp (command, "H") == 0) /* Hungarian umlaut */
  1530. add_word ("''");
  1531. else if (strcmp (command, "dotaccent") == 0) /* overdot */
  1532. add_meta_char ('.');
  1533. else if (strcmp (command, "ringaccent") == 0) /* ring */
  1534. add_char ('*');
  1535. else if (strcmp (command, "tieaccent") == 0) /* long tie */
  1536. add_char ('[');
  1537. else if (strcmp (command, "u") == 0) /* breve */
  1538. add_char ('(');
  1539. else if (strcmp (command, "ubaraccent") == 0) /* underbar */
  1540. add_char ('_');
  1541. else if (strcmp (command, "v") == 0) /* hacek/check */
  1542. add_word ((html || xml) ? "&lt;" : "<");
  1543. }
  1544. escape_html = old_escape_html;
  1545. }
  1546. /* Common routine for the accent characters that have support in HTML.
  1547. If the character being accented is in the HTML_SUPPORTED set, then
  1548. produce &CHTML_SOLO;, for example, &Auml; for an A-umlaut. If not in
  1549. HTML_SUPPORTED, just produce &HTML_SOLO;X for the best we can do with
  1550. at an X-umlaut. If not producing HTML, just use SINGLE, a
  1551. character such as " which is the best plain text representation we
  1552. can manage. If HTML_SOLO_STANDALONE is nonzero the given HTML_SOLO
  1553. exists as valid standalone character in HTML, e.g., &uml;. */
  1554. static void
  1555. cm_accent_generic (int arg, int start, int end, char *html_supported,
  1556. int single, int html_solo_standalone, char *html_solo)
  1557. {
  1558. /* Accentuating space characters makes no sense, so issue a warning. */
  1559. if (arg == START && isspace (input_text[input_text_offset]))
  1560. warning ("Accent command `@%s' must not be followed by whitespace",
  1561. command);
  1562. if (html || xml)
  1563. cm_accent_generic_html (arg, start, end, html_supported,
  1564. single, html_solo_standalone, html_solo);
  1565. else if (no_headers)
  1566. cm_accent_generic_no_headers (arg, start, end, single, html_solo);
  1567. else if (arg == END)
  1568. {
  1569. if (enable_encoding)
  1570. /* use 8-bit if available */
  1571. cm_accent_generic_no_headers (arg, start, end, single, html_solo);
  1572. else
  1573. /* use regular character */
  1574. add_char (single);
  1575. }
  1576. }
  1577. void
  1578. cm_accent_umlaut (int arg, int start, int end)
  1579. {
  1580. cm_accent_generic (arg, start, end, "aouAOUEeIiy", '"', 1, "uml");
  1581. }
  1582. void
  1583. cm_accent_acute (int arg, int start, int end)
  1584. {
  1585. cm_accent_generic (arg, start, end, "AEIOUYaeiouy", '\'', 1, "acute");
  1586. }
  1587. void
  1588. cm_accent_cedilla (int arg, int start, int end)
  1589. {
  1590. cm_accent_generic (arg, start, end, "Cc", ',', 1, "cedil");
  1591. }
  1592. void
  1593. cm_accent_hat (int arg, int start, int end)
  1594. {
  1595. cm_accent_generic (arg, start, end, "AEIOUaeiou", '^', 0, "circ");
  1596. }
  1597. void
  1598. cm_accent_grave (int arg, int start, int end)
  1599. {
  1600. cm_accent_generic (arg, start, end, "AEIOUaeiou", '`', 0, "grave");
  1601. }
  1602. void
  1603. cm_accent_tilde (int arg, int start, int end)
  1604. {
  1605. cm_accent_generic (arg, start, end, "ANOano", '~', 0, "tilde");
  1606. }
  1607. /* Non-English letters/characters that don't insert themselves. */
  1608. void
  1609. cm_special_char (int arg)
  1610. {
  1611. int old_escape_html = escape_html;
  1612. escape_html = 0;
  1613. if (arg == START)
  1614. {
  1615. if ((*command == 'L' || *command == 'l'
  1616. || *command == 'O' || *command == 'o')
  1617. && command[1] == 0)
  1618. { /* Lslash lslash Oslash oslash.
  1619. Lslash and lslash aren't supported in HTML. */
  1620. if (command[0] == 'O')
  1621. add_encoded_char ("Oslash", "/O");
  1622. else if (command[0] == 'o')
  1623. add_encoded_char ("oslash", "/o");
  1624. else
  1625. add_word_args ("/%c", command[0]);
  1626. }
  1627. else if (strcmp (command, "exclamdown") == 0)
  1628. add_encoded_char ("iexcl", "!");
  1629. else if (strcmp (command, "questiondown") == 0)
  1630. add_encoded_char ("iquest", "?");
  1631. else if (strcmp (command, "euro") == 0)
  1632. /* http://www.cs.tut.fi/~jkorpela/html/euro.html suggests that
  1633. &euro; degrades best in old browsers. */
  1634. add_encoded_char ("euro", "Euro ");
  1635. else if (strcmp (command, "pounds") == 0)
  1636. add_encoded_char ("pound" , "#");
  1637. else if (strcmp (command, "ordf") == 0)
  1638. add_encoded_char ("ordf" , "a");
  1639. else if (strcmp (command, "ordm") == 0)
  1640. add_encoded_char ("ordm" , "o");
  1641. else if (strcmp (command, "textdegree") == 0)
  1642. add_encoded_char ("deg" , "o");
  1643. else if (strcmp (command, "AE") == 0)
  1644. add_encoded_char ("AElig", command);
  1645. else if (strcmp (command, "ae") == 0)
  1646. add_encoded_char ("aelig", command);
  1647. else if (strcmp (command, "OE") == 0)
  1648. add_encoded_char ("OElig", command);
  1649. else if (strcmp (command, "oe") == 0)
  1650. add_encoded_char ("oelig", command);
  1651. else if (strcmp (command, "AA") == 0)
  1652. add_encoded_char ("Aring", command);
  1653. else if (strcmp (command, "aa") == 0)
  1654. add_encoded_char ("aring", command);
  1655. else if (strcmp (command, "ss") == 0)
  1656. add_encoded_char ("szlig", command);
  1657. else if (strcmp (command, "guillemetleft") == 0
  1658. || strcmp (command, "guillemotleft") == 0)
  1659. add_encoded_char ("laquo", "<<");
  1660. else if (strcmp (command, "guillemetright") == 0
  1661. || strcmp (command, "guillemotright") == 0)
  1662. add_encoded_char ("raquo", ">>");
  1663. else
  1664. line_error ("cm_special_char internal error: command=@%s", command);
  1665. }
  1666. escape_html = old_escape_html;
  1667. }
  1668. /* Dotless i or j. */
  1669. void
  1670. cm_dotless (int arg, int start, int end)
  1671. {
  1672. if (arg == END)
  1673. {
  1674. xml_no_para --;
  1675. if (output_paragraph[start] != 'i' && output_paragraph[start] != 'j')
  1676. /* This error message isn't perfect if the argument is multiple
  1677. characters, but it doesn't seem worth getting right. */
  1678. line_error (_("%c%s expects `i' or `j' as argument, not `%c'"),
  1679. COMMAND_PREFIX, command, output_paragraph[start]);
  1680. else if (end - start != 1)
  1681. line_error (_("%c%s expects a single character `i' or `j' as argument"),
  1682. COMMAND_PREFIX, command);
  1683. /* We've already inserted the `i' or `j', so nothing to do. */
  1684. }
  1685. else
  1686. xml_no_para ++;
  1687. }