1 /* lang.c -- language-dependent support.
2 $Id: lang.c,v 1.1.1.3 2006/07/17 16:03:47 espie Exp $
3
4 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software
5 Foundation, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 Originally written by Karl Heinz Marbaise <kama@hippo.fido.de>. */
22
23 #include "system.h"
24 #include "cmds.h"
25 #include "files.h"
26 #include "lang.h"
27 #include "makeinfo.h"
28 #include "xml.h"
29
30 /* Current document encoding. */
31 encoding_code_type document_encoding_code = no_encoding;
32
33 /* Current language code; default is English. */
34 language_code_type language_code = en;
35
36 /* By default, unsupported encoding is an empty string. */
37 char *unknown_encoding = NULL;
38
39 static iso_map_type us_ascii_map [] = {{NULL, 0, 0}}; /* ASCII map is trivial */
40
41 /* Translation table between HTML and ISO Codes. The last item is
42 hopefully the Unicode. It might be possible that those Unicodes are
43 not correct, cause I didn't check them. kama */
44 static iso_map_type iso8859_1_map [] = {
45 { "nbsp", 0xA0, 0x00A0 },
46 { "iexcl", 0xA1, 0x00A1 },
47 { "cent", 0xA2, 0x00A2 },
48 { "pound", 0xA3, 0x00A3 },
49 { "curren", 0xA4, 0x00A4 },
50 { "yen", 0xA5, 0x00A5 },
51 { "brkbar", 0xA6, 0x00A6 },
52 { "sect", 0xA7, 0x00A7 },
53 { "uml", 0xA8, 0x00A8 },
54 { "copy", 0xA9, 0x00A9 },
55 { "ordf", 0xAA, 0x00AA },
56 { "laquo", 0xAB, 0x00AB },
57 { "not", 0xAC, 0x00AC },
58 { "shy", 0xAD, 0x00AD },
59 { "reg", 0xAE, 0x00AE },
60 { "hibar", 0xAF, 0x00AF },
61 { "deg", 0xB0, 0x00B0 },
62 { "plusmn", 0xB1, 0x00B1 },
63 { "sup2", 0xB2, 0x00B2 },
64 { "sup3", 0xB3, 0x00B3 },
65 { "acute", 0xB4, 0x00B4 },
66 { "micro", 0xB5, 0x00B5 },
67 { "para", 0xB6, 0x00B6 },
68 { "middot", 0xB7, 0x00B7 },
69 { "cedil", 0xB8, 0x00B8 },
70 { "sup1", 0xB9, 0x00B9 },
71 { "ordm", 0xBA, 0x00BA },
72 { "raquo", 0xBB, 0x00BB },
73 { "frac14", 0xBC, 0x00BC },
74 { "frac12", 0xBD, 0x00BD },
75 { "frac34", 0xBE, 0x00BE },
76 { "iquest", 0xBF, 0x00BF },
77 { "Agrave", 0xC0, 0x00C0 },
78 { "Aacute", 0xC1, 0x00C1 },
79 { "Acirc", 0xC2, 0x00C2 },
80 { "Atilde", 0xC3, 0x00C3 },
81 { "Auml", 0xC4, 0x00C4 },
82 { "Aring", 0xC5, 0x00C5 },
83 { "AElig", 0xC6, 0x00C6 },
84 { "Ccedil", 0xC7, 0x00C7 },
85 { "Ccedil", 0xC7, 0x00C7 },
86 { "Egrave", 0xC8, 0x00C8 },
87 { "Eacute", 0xC9, 0x00C9 },
88 { "Ecirc", 0xCA, 0x00CA },
89 { "Euml", 0xCB, 0x00CB },
90 { "Igrave", 0xCC, 0x00CC },
91 { "Iacute", 0xCD, 0x00CD },
92 { "Icirc", 0xCE, 0x00CE },
93 { "Iuml", 0xCF, 0x00CF },
94 { "ETH", 0xD0, 0x00D0 },
95 { "Ntilde", 0xD1, 0x00D1 },
96 { "Ograve", 0xD2, 0x00D2 },
97 { "Oacute", 0xD3, 0x00D3 },
98 { "Ocirc", 0xD4, 0x00D4 },
99 { "Otilde", 0xD5, 0x00D5 },
100 { "Ouml", 0xD6, 0x00D6 },
101 { "times", 0xD7, 0x00D7 },
102 { "Oslash", 0xD8, 0x00D8 },
103 { "Ugrave", 0xD9, 0x00D9 },
104 { "Uacute", 0xDA, 0x00DA },
105 { "Ucirc", 0xDB, 0x00DB },
106 { "Uuml", 0xDC, 0x00DC },
107 { "Yacute", 0xDD, 0x00DD },
108 { "THORN", 0xDE, 0x00DE },
109 { "szlig", 0xDF, 0x00DF },
110 { "agrave", 0xE0, 0x00E0 },
111 { "aacute", 0xE1, 0x00E1 },
112 { "acirc", 0xE2, 0x00E2 },
113 { "atilde", 0xE3, 0x00E3 },
114 { "auml", 0xE4, 0x00E4 },
115 { "aring", 0xE5, 0x00E5 },
116 { "aelig", 0xE6, 0x00E6 },
117 { "ccedil", 0xE7, 0x00E7 },
118 { "egrave", 0xE8, 0x00E8 },
119 { "eacute", 0xE9, 0x00E9 },
120 { "ecirc", 0xEA, 0x00EA },
121 { "euml", 0xEB, 0x00EB },
122 { "igrave", 0xEC, 0x00EC },
123 { "iacute", 0xED, 0x00ED },
124 { "icirc", 0xEE, 0x00EE },
125 { "iuml", 0xEF, 0x00EF },
126 { "eth", 0xF0, 0x00F0 },
127 { "ntilde", 0xF1, 0x00F1 },
128 { "ograve", 0xF2, 0x00F2 },
129 { "oacute", 0xF3, 0x00F3 },
130 { "ocirc", 0xF4, 0x00F4 },
131 { "otilde", 0xF5, 0x00F5 },
132 { "ouml", 0xF6, 0x00F6 },
133 { "divide", 0xF7, 0x00F7 },
134 { "oslash", 0xF8, 0x00F8 },
135 { "ugrave", 0xF9, 0x00F9 },
136 { "uacute", 0xFA, 0x00FA },
137 { "ucirc", 0xFB, 0x00FB },
138 { "uuml", 0xFC, 0x00FC },
139 { "yacute", 0xFD, 0x00FD },
140 { "thorn", 0xFE, 0x00FE },
141 { "yuml", 0xFF, 0x00FF },
142 { NULL, 0, 0 }
143 };
144
145
146 /* ISO 8859-15, also known as Latin 9, differs from Latin 1 in only a
147 few positions. http://www.cs.tut.fi/~jkorpela/latin9.html has a good
148 explanation and listing, summarized here. The names are abbreviated
149 from the official Unicode names, to fit in a decent line length.
150
151 code position
152 dec oct hex latin1 latin1 name latin9 latin9 name
153
154 164 0244 0xA4 U+00A4 currency symbol U+20AC euro sign
155 166 0246 0xA6 U+00A6 broken bar U+0160 S with caron
156 168 0250 0xA8 U+00A8 diaeresis U+0161 s with caron
157 180 0264 0xB4 U+00B4 acute accent U+017D Z with caron
158 184 0270 0xB8 U+00B8 cedilla U+017E z with caron
159 188 0274 0xBC U+00BC fraction 1/4 U+0152 ligature OE
160 189 0275 0xBD U+00BD fraction 1/2 U+0153 ligature oe
161 190 0276 0xBE U+00BE fraction 3/4 U+0178 Y with diaeresis
162 */
163
164 static iso_map_type iso8859_15_map [] = {
165 { "nbsp", 0xA0, 0x00A0 },
166 { "iexcl", 0xA1, 0x00A1 },
167 { "cent", 0xA2, 0x00A2 },
168 { "pound", 0xA3, 0x00A3 },
169 { "euro", 0xA4, 0x20AC },
170 { "yen", 0xA5, 0x00A5 },
171 { "Scaron", 0xA6, 0x0160 },
172 { "sect", 0xA7, 0x00A7 },
173 { "scaron", 0xA8, 0x0161 },
174 { "copy", 0xA9, 0x00A9 },
175 { "ordf", 0xAA, 0x00AA },
176 { "laquo", 0xAB, 0x00AB },
177 { "not", 0xAC, 0x00AC },
178 { "shy", 0xAD, 0x00AD },
179 { "reg", 0xAE, 0x00AE },
180 { "hibar", 0xAF, 0x00AF },
181 { "deg", 0xB0, 0x00B0 },
182 { "plusmn", 0xB1, 0x00B1 },
183 { "sup2", 0xB2, 0x00B2 },
184 { "sup3", 0xB3, 0x00B3 },
185 { "Zcaron", 0xB4, 0x017D },
186 { "micro", 0xB5, 0x00B5 },
187 { "para", 0xB6, 0x00B6 },
188 { "middot", 0xB7, 0x00B7 },
189 { "zcaron", 0xB8, 0x017E },
190 { "sup1", 0xB9, 0x00B9 },
191 { "ordm", 0xBA, 0x00BA },
192 { "raquo", 0xBB, 0x00BB },
193 { "OElig", 0xBC, 0x0152 },
194 { "oelig", 0xBD, 0x0153 },
195 { "Yuml", 0xBE, 0x0178 },
196 { "iquest", 0xBF, 0x00BF },
197 { "Agrave", 0xC0, 0x00C0 },
198 { "Aacute", 0xC1, 0x00C1 },
199 { "Acirc", 0xC2, 0x00C2 },
200 { "Atilde", 0xC3, 0x00C3 },
201 { "Auml", 0xC4, 0x00C4 },
202 { "Aring", 0xC5, 0x00C5 },
203 { "AElig", 0xC6, 0x00C6 },
204 { "Ccedil", 0xC7, 0x00C7 },
205 { "Ccedil", 0xC7, 0x00C7 },
206 { "Egrave", 0xC8, 0x00C8 },
207 { "Eacute", 0xC9, 0x00C9 },
208 { "Ecirc", 0xCA, 0x00CA },
209 { "Euml", 0xCB, 0x00CB },
210 { "Igrave", 0xCC, 0x00CC },
211 { "Iacute", 0xCD, 0x00CD },
212 { "Icirc", 0xCE, 0x00CE },
213 { "Iuml", 0xCF, 0x00CF },
214 { "ETH", 0xD0, 0x00D0 },
215 { "Ntilde", 0xD1, 0x00D1 },
216 { "Ograve", 0xD2, 0x00D2 },
217 { "Oacute", 0xD3, 0x00D3 },
218 { "Ocirc", 0xD4, 0x00D4 },
219 { "Otilde", 0xD5, 0x00D5 },
220 { "Ouml", 0xD6, 0x00D6 },
221 { "times", 0xD7, 0x00D7 },
222 { "Oslash", 0xD8, 0x00D8 },
223 { "Ugrave", 0xD9, 0x00D9 },
224 { "Uacute", 0xDA, 0x00DA },
225 { "Ucirc", 0xDB, 0x00DB },
226 { "Uuml", 0xDC, 0x00DC },
227 { "Yacute", 0xDD, 0x00DD },
228 { "THORN", 0xDE, 0x00DE },
229 { "szlig", 0xDF, 0x00DF },
230 { "agrave", 0xE0, 0x00E0 },
231 { "aacute", 0xE1, 0x00E1 },
232 { "acirc", 0xE2, 0x00E2 },
233 { "atilde", 0xE3, 0x00E3 },
234 { "auml", 0xE4, 0x00E4 },
235 { "aring", 0xE5, 0x00E5 },
236 { "aelig", 0xE6, 0x00E6 },
237 { "ccedil", 0xE7, 0x00E7 },
238 { "egrave", 0xE8, 0x00E8 },
239 { "eacute", 0xE9, 0x00E9 },
240 { "ecirc", 0xEA, 0x00EA },
241 { "euml", 0xEB, 0x00EB },
242 { "igrave", 0xEC, 0x00EC },
243 { "iacute", 0xED, 0x00ED },
244 { "icirc", 0xEE, 0x00EE },
245 { "iuml", 0xEF, 0x00EF },
246 { "eth", 0xF0, 0x00F0 },
247 { "ntilde", 0xF1, 0x00F1 },
248 { "ograve", 0xF2, 0x00F2 },
249 { "oacute", 0xF3, 0x00F3 },
250 { "ocirc", 0xF4, 0x00F4 },
251 { "otilde", 0xF5, 0x00F5 },
252 { "ouml", 0xF6, 0x00F6 },
253 { "divide", 0xF7, 0x00F7 },
254 { "oslash", 0xF8, 0x00F8 },
255 { "ugrave", 0xF9, 0x00F9 },
256 { "uacute", 0xFA, 0x00FA },
257 { "ucirc", 0xFB, 0x00FB },
258 { "uuml", 0xFC, 0x00FC },
259 { "yacute", 0xFD, 0x00FD },
260 { "thorn", 0xFE, 0x00FE },
261 { "yuml", 0xFF, 0x00FF },
262 { NULL, 0, 0 }
263 };
264
265
266
267 /* Date: Mon, 31 Mar 2003 00:19:28 +0200
268 From: Wojciech Polak <polak@gnu.org>
269 ...
270 * Primary Polish site for ogonki is http://www.agh.edu.pl/ogonki/,
271 but it's only in Polish language (it has some interesting links).
272
273 * A general site about ISO 8859-2 at http://nl.ijs.si/gnusl/cee/iso8859-2.html
274
275 * ISO 8859-2 Character Set at http://nl.ijs.si/gnusl/cee/charset.html
276 This site provides almost all information about iso-8859-2,
277 including the character table!!! (must see!)
278
279 * ISO 8859-2 and even HTML entities !!! (must see!)
280 http://people.ssh.fi/mtr/genscript/88592.txt
281
282 * (minor) http://www.agh.edu.pl/ogonki/plchars.html
283 One more table, this time it includes even information about Polish
284 characters in Unicode.
285 */
286
287 static iso_map_type iso8859_2_map [] = {
288 { "nbsp", 0xA0, 0x00A0 }, /* NO-BREAK SPACE */
289 { "", 0xA1, 0x0104 }, /* LATIN CAPITAL LETTER A WITH OGONEK */
290 { "", 0xA2, 0x02D8 }, /* BREVE */
291 { "", 0xA3, 0x0141 }, /* LATIN CAPITAL LETTER L WITH STROKE */
292 { "curren", 0xA4, 0x00A4 }, /* CURRENCY SIGN */
293 { "", 0xA5, 0x013D }, /* LATIN CAPITAL LETTER L WITH CARON */
294 { "", 0xA6, 0x015A }, /* LATIN CAPITAL LETTER S WITH ACUTE */
295 { "sect", 0xA7, 0x00A7 }, /* SECTION SIGN */
296 { "uml", 0xA8, 0x00A8 }, /* DIAERESIS */
297 { "", 0xA9, 0x0160 }, /* LATIN CAPITAL LETTER S WITH CARON */
298 { "", 0xAA, 0x015E }, /* LATIN CAPITAL LETTER S WITH CEDILLA */
299 { "", 0xAB, 0x0164 }, /* LATIN CAPITAL LETTER T WITH CARON */
300 { "", 0xAC, 0x0179 }, /* LATIN CAPITAL LETTER Z WITH ACUTE */
301 { "shy", 0xAD, 0x00AD }, /* SOFT HYPHEN */
302 { "", 0xAE, 0x017D }, /* LATIN CAPITAL LETTER Z WITH CARON */
303 { "", 0xAF, 0x017B }, /* LATIN CAPITAL LETTER Z WITH DOT ABOVE */
304 { "deg", 0xB0, 0x00B0 }, /* DEGREE SIGN */
305 { "", 0xB1, 0x0105 }, /* LATIN SMALL LETTER A WITH OGONEK */
306 { "", 0xB2, 0x02DB }, /* OGONEK */
307 { "", 0xB3, 0x0142 }, /* LATIN SMALL LETTER L WITH STROKE */
308 { "acute", 0xB4, 0x00B4 }, /* ACUTE ACCENT */
309 { "", 0xB5, 0x013E }, /* LATIN SMALL LETTER L WITH CARON */
310 { "", 0xB6, 0x015B }, /* LATIN SMALL LETTER S WITH ACUTE */
311 { "", 0xB7, 0x02C7 }, /* CARON (Mandarin Chinese third tone) */
312 { "cedil", 0xB8, 0x00B8 }, /* CEDILLA */
313 { "", 0xB9, 0x0161 }, /* LATIN SMALL LETTER S WITH CARON */
314 { "", 0xBA, 0x015F }, /* LATIN SMALL LETTER S WITH CEDILLA */
315 { "", 0xBB, 0x0165 }, /* LATIN SMALL LETTER T WITH CARON */
316 { "", 0xBC, 0x017A }, /* LATIN SMALL LETTER Z WITH ACUTE */
317 { "", 0xBD, 0x02DD }, /* DOUBLE ACUTE ACCENT */
318 { "", 0xBE, 0x017E }, /* LATIN SMALL LETTER Z WITH CARON */
319 { "", 0xBF, 0x017C }, /* LATIN SMALL LETTER Z WITH DOT ABOVE */
320 { "", 0xC0, 0x0154 }, /* LATIN CAPITAL LETTER R WITH ACUTE */
321 { "", 0xC1, 0x00C1 }, /* LATIN CAPITAL LETTER A WITH ACUTE */
322 { "", 0xC2, 0x00C2 }, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
323 { "", 0xC3, 0x0102 }, /* LATIN CAPITAL LETTER A WITH BREVE */
324 { "", 0xC4, 0x00C4 }, /* LATIN CAPITAL LETTER A WITH DIAERESIS */
325 { "", 0xC5, 0x0139 }, /* LATIN CAPITAL LETTER L WITH ACUTE */
326 { "", 0xC6, 0x0106 }, /* LATIN CAPITAL LETTER C WITH ACUTE */
327 { "", 0xC7, 0x00C7 }, /* LATIN CAPITAL LETTER C WITH CEDILLA */
328 { "", 0xC8, 0x010C }, /* LATIN CAPITAL LETTER C WITH CARON */
329 { "", 0xC9, 0x00C9 }, /* LATIN CAPITAL LETTER E WITH ACUTE */
330 { "", 0xCA, 0x0118 }, /* LATIN CAPITAL LETTER E WITH OGONEK */
331 { "", 0xCB, 0x00CB }, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
332 { "", 0xCC, 0x011A }, /* LATIN CAPITAL LETTER E WITH CARON */
333 { "", 0xCD, 0x00CD }, /* LATIN CAPITAL LETTER I WITH ACUTE */
334 { "", 0xCE, 0x00CE }, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
335 { "", 0xCF, 0x010E }, /* LATIN CAPITAL LETTER D WITH CARON */
336 { "", 0xD0, 0x0110 }, /* LATIN CAPITAL LETTER D WITH STROKE */
337 { "", 0xD1, 0x0143 }, /* LATIN CAPITAL LETTER N WITH ACUTE */
338 { "", 0xD2, 0x0147 }, /* LATIN CAPITAL LETTER N WITH CARON */
339 { "", 0xD3, 0x00D3 }, /* LATIN CAPITAL LETTER O WITH ACUTE */
340 { "", 0xD4, 0x00D4 }, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
341 { "", 0xD5, 0x0150 }, /* LATIN CAPITAL LETTER O WITH DOUBLE ACUTE */
342 { "", 0xD6, 0x00D6 }, /* LATIN CAPITAL LETTER O WITH DIAERESIS */
343 { "times", 0xD7, 0x00D7 }, /* MULTIPLICATION SIGN */
344 { "", 0xD8, 0x0158 }, /* LATIN CAPITAL LETTER R WITH CARON */
345 { "", 0xD9, 0x016E }, /* LATIN CAPITAL LETTER U WITH RING ABOVE */
346 { "", 0xDA, 0x00DA }, /* LATIN CAPITAL LETTER U WITH ACUTE */
347 { "", 0xDB, 0x0170 }, /* LATIN CAPITAL LETTER U WITH DOUBLE ACUTE */
348 { "", 0xDC, 0x00DC }, /* LATIN CAPITAL LETTER U WITH DIAERESIS */
349 { "", 0xDD, 0x00DD }, /* LATIN CAPITAL LETTER Y WITH ACUTE */
350 { "", 0xDE, 0x0162 }, /* LATIN CAPITAL LETTER T WITH CEDILLA */
351 { "", 0xDF, 0x00DF }, /* LATIN SMALL LETTER SHARP S (German) */
352 { "", 0xE0, 0x0155 }, /* LATIN SMALL LETTER R WITH ACUTE */
353 { "", 0xE1, 0x00E1 }, /* LATIN SMALL LETTER A WITH ACUTE */
354 { "", 0xE2, 0x00E2 }, /* LATIN SMALL LETTER A WITH CIRCUMFLEX */
355 { "", 0xE3, 0x0103 }, /* LATIN SMALL LETTER A WITH BREVE */
356 { "", 0xE4, 0x00E4 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
357 { "", 0xE5, 0x013A }, /* LATIN SMALL LETTER L WITH ACUTE */
358 { "", 0xE6, 0x0107 }, /* LATIN SMALL LETTER C WITH ACUTE */
359 { "", 0xE7, 0x00E7 }, /* LATIN SMALL LETTER C WITH CEDILLA */
360 { "", 0xE8, 0x010D }, /* LATIN SMALL LETTER C WITH CARON */
361 { "", 0xE9, 0x00E9 }, /* LATIN SMALL LETTER E WITH ACUTE */
362 { "", 0xEA, 0x0119 }, /* LATIN SMALL LETTER E WITH OGONEK */
363 { "", 0xEB, 0x00EB }, /* LATIN SMALL LETTER E WITH DIAERESIS */
364 { "", 0xEC, 0x011B }, /* LATIN SMALL LETTER E WITH CARON */
365 { "", 0xED, 0x00ED }, /* LATIN SMALL LETTER I WITH ACUTE */
366 { "", 0xEE, 0x00EE }, /* LATIN SMALL LETTER I WITH CIRCUMFLEX */
367 { "", 0xEF, 0x010F }, /* LATIN SMALL LETTER D WITH CARON */
368 { "", 0xF0, 0x0111 }, /* LATIN SMALL LETTER D WITH STROKE */
369 { "", 0xF1, 0x0144 }, /* LATIN SMALL LETTER N WITH ACUTE */
370 { "", 0xF2, 0x0148 }, /* LATIN SMALL LETTER N WITH CARON */
371 { "", 0xF3, 0x00F3 }, /* LATIN SMALL LETTER O WITH ACUTE */
372 { "", 0xF4, 0x00F4 }, /* LATIN SMALL LETTER O WITH CIRCUMFLEX */
373 { "", 0xF5, 0x0151 }, /* LATIN SMALL LETTER O WITH DOUBLE ACUTE */
374 { "", 0xF6, 0x00F6 }, /* LATIN SMALL LETTER O WITH DIAERESIS */
375 { "divide", 0xF7, 0x00F7 }, /* DIVISION SIGN */
376 { "", 0xF8, 0x0159 }, /* LATIN SMALL LETTER R WITH CARON */
377 { "", 0xF9, 0x016F }, /* LATIN SMALL LETTER U WITH RING ABOVE */
378 { "", 0xFA, 0x00FA }, /* LATIN SMALL LETTER U WITH ACUTE */
379 { "", 0xFB, 0x0171 }, /* LATIN SMALL LETTER U WITH DOUBLE ACUTE */
380 { "", 0xFC, 0x00FC }, /* LATIN SMALL LETTER U WITH DIAERESIS */
381 { "", 0xFD, 0x00FD }, /* LATIN SMALL LETTER Y WITH ACUTE */
382 { "", 0xFE, 0x0163 }, /* LATIN SMALL LETTER T WITH CEDILLA */
383 { "", 0xFF, 0x02D9 }, /* DOT ABOVE (Mandarin Chinese light tone) */
384 { NULL, 0, 0 }
385 };
386
387 encoding_type encoding_table[] = {
388 { no_encoding, "(no encoding)", NULL },
389 { US_ASCII, "US-ASCII", us_ascii_map },
390 { ISO_8859_1, "iso-8859-1", (iso_map_type *) iso8859_1_map },
391 { ISO_8859_2, "iso-8859-2", (iso_map_type *) iso8859_2_map },
392 { ISO_8859_3, "iso-8859-3", NULL },
393 { ISO_8859_4, "iso-8859-4", NULL },
394 { ISO_8859_5, "iso-8859-5", NULL },
395 { ISO_8859_6, "iso-8859-6", NULL },
396 { ISO_8859_7, "iso-8859-7", NULL },
397 { ISO_8859_8, "iso-8859-8", NULL },
398 { ISO_8859_9, "iso-8859-9", NULL },
399 { ISO_8859_10, "iso-8859-10", NULL },
400 { ISO_8859_11, "iso-8859-11", NULL },
401 { ISO_8859_12, "iso-8859-12", NULL },
402 { ISO_8859_13, "iso-8859-13", NULL },
403 { ISO_8859_14, "iso-8859-14", NULL },
404 { ISO_8859_15, "iso-8859-15", (iso_map_type *) iso8859_15_map },
405 { last_encoding_code, NULL, NULL }
406 };
407
408
409 language_type language_table[] = {
410 { aa, "aa", "Afar" },
411 { ab, "ab", "Abkhazian" },
412 { af, "af", "Afrikaans" },
413 { am, "am", "Amharic" },
414 { ar, "ar", "Arabic" },
415 { as, "as", "Assamese" },
416 { ay, "ay", "Aymara" },
417 { az, "az", "Azerbaijani" },
418 { ba, "ba", "Bashkir" },
419 { be, "be", "Byelorussian" },
420 { bg, "bg", "Bulgarian" },
421 { bh, "bh", "Bihari" },
422 { bi, "bi", "Bislama" },
423 { bn, "bn", "Bengali; Bangla" },
424 { bo, "bo", "Tibetan" },
425 { br, "br", "Breton" },
426 { ca, "ca", "Catalan" },
427 { co, "co", "Corsican" },
428 { cs, "cs", "Czech" },
429 { cy, "cy", "Welsh" },
430 { da, "da", "Danish" },
431 { de, "de", "German" },
432 { dz, "dz", "Bhutani" },
433 { el, "el", "Greek" },
434 { en, "en", "English" },
435 { eo, "eo", "Esperanto" },
436 { es, "es", "Spanish" },
437 { et, "et", "Estonian" },
438 { eu, "eu", "Basque" },
439 { fa, "fa", "Persian" },
440 { fi, "fi", "Finnish" },
441 { fj, "fj", "Fiji" },
442 { fo, "fo", "Faroese" },
443 { fr, "fr", "French" },
444 { fy, "fy", "Frisian" },
445 { ga, "ga", "Irish" },
446 { gd, "gd", "Scots Gaelic" },
447 { gl, "gl", "Galician" },
448 { gn, "gn", "Guarani" },
449 { gu, "gu", "Gujarati" },
450 { ha, "ha", "Hausa" },
451 { he, "he", "Hebrew" } /* (formerly iw) */,
452 { hi, "hi", "Hindi" },
453 { hr, "hr", "Croatian" },
454 { hu, "hu", "Hungarian" },
455 { hy, "hy", "Armenian" },
456 { ia, "ia", "Interlingua" },
457 { id, "id", "Indonesian" } /* (formerly in) */,
458 { ie, "ie", "Interlingue" },
459 { ik, "ik", "Inupiak" },
460 { is, "is", "Icelandic" },
461 { it, "it", "Italian" },
462 { iu, "iu", "Inuktitut" },
463 { ja, "ja", "Japanese" },
464 { jw, "jw", "Javanese" },
465 { ka, "ka", "Georgian" },
466 { kk, "kk", "Kazakh" },
467 { kl, "kl", "Greenlandic" },
468 { km, "km", "Cambodian" },
469 { kn, "kn", "Kannada" },
470 { ko, "ko", "Korean" },
471 { ks, "ks", "Kashmiri" },
472 { ku, "ku", "Kurdish" },
473 { ky, "ky", "Kirghiz" },
474 { la, "la", "Latin" },
475 { ln, "ln", "Lingala" },
476 { lo, "lo", "Laothian" },
477 { lt, "lt", "Lithuanian" },
478 { lv, "lv", "Latvian, Lettish" },
479 { mg, "mg", "Malagasy" },
480 { mi, "mi", "Maori" },
481 { mk, "mk", "Macedonian" },
482 { ml, "ml", "Malayalam" },
483 { mn, "mn", "Mongolian" },
484 { mo, "mo", "Moldavian" },
485 { mr, "mr", "Marathi" },
486 { ms, "ms", "Malay" },
487 { mt, "mt", "Maltese" },
488 { my, "my", "Burmese" },
489 { na, "na", "Nauru" },
490 { ne, "ne", "Nepali" },
491 { nl, "nl", "Dutch" },
492 { no, "no", "Norwegian" },
493 { oc, "oc", "Occitan" },
494 { om, "om", "(Afan) Oromo" },
495 { or, "or", "Oriya" },
496 { pa, "pa", "Punjabi" },
497 { pl, "pl", "Polish" },
498 { ps, "ps", "Pashto, Pushto" },
499 { pt, "pt", "Portuguese" },
500 { qu, "qu", "Quechua" },
501 { rm, "rm", "Rhaeto-Romance" },
502 { rn, "rn", "Kirundi" },
503 { ro, "ro", "Romanian" },
504 { ru, "ru", "Russian" },
505 { rw, "rw", "Kinyarwanda" },
506 { sa, "sa", "Sanskrit" },
507 { sd, "sd", "Sindhi" },
508 { sg, "sg", "Sangro" },
509 { sh, "sh", "Serbo-Croatian" },
510 { si, "si", "Sinhalese" },
511 { sk, "sk", "Slovak" },
512 { sl, "sl", "Slovenian" },
513 { sm, "sm", "Samoan" },
514 { sn, "sn", "Shona" },
515 { so, "so", "Somali" },
516 { sq, "sq", "Albanian" },
517 { sr, "sr", "Serbian" },
518 { ss, "ss", "Siswati" },
519 { st, "st", "Sesotho" },
520 { su, "su", "Sundanese" },
521 { sv, "sv", "Swedish" },
522 { sw, "sw", "Swahili" },
523 { ta, "ta", "Tamil" },
524 { te, "te", "Telugu" },
525 { tg, "tg", "Tajik" },
526 { th, "th", "Thai" },
527 { ti, "ti", "Tigrinya" },
528 { tk, "tk", "Turkmen" },
529 { tl, "tl", "Tagalog" },
530 { tn, "tn", "Setswana" },
531 { to, "to", "Tonga" },
532 { tr, "tr", "Turkish" },
533 { ts, "ts", "Tsonga" },
534 { tt, "tt", "Tatar" },
535 { tw, "tw", "Twi" },
536 { ug, "ug", "Uighur" },
537 { uk, "uk", "Ukrainian" },
538 { ur, "ur", "Urdu" },
539 { uz, "uz", "Uzbek" },
540 { vi, "vi", "Vietnamese" },
541 { vo, "vo", "Volapuk" },
542 { wo, "wo", "Wolof" },
543 { xh, "xh", "Xhosa" },
544 { yi, "yi", "Yiddish" } /* (formerly ji) */,
545 { yo, "yo", "Yoruba" },
546 { za, "za", "Zhuang" },
547 { zh, "zh", "Chinese" },
548 { zu, "zu", "Zulu" },
549 { last_language_code, NULL, NULL }
550 };
551
552 /* @documentlanguage. Maybe we'll do something useful with this in the
553 future. For now, we just recognize it. */
554
555 /* XML documents can make use of this data. Unfortunately, it clashes with
556 the structure currently used. So instead of enclosing content into
557 a language block, we just output an empty element. Anyways, a stream based
558 parser can make good use of it. */
559 void
cm_documentlanguage(void)560 cm_documentlanguage (void)
561 {
562 language_code_type c;
563 char *lang_arg;
564
565 /* Read the line with the language code on it. */
566 get_rest_of_line (0, &lang_arg);
567
568 /* Linear search is fine these days. */
569 for (c = aa; c != last_language_code; c++)
570 {
571 if (strcmp (lang_arg, language_table[c].abbrev) == 0)
572 { /* Set current language code. */
573 language_code = c;
574 break;
575 }
576 }
577
578 /* If we didn't find this code, complain. */
579 if (c == last_language_code)
580 warning (_("%s is not a valid ISO 639 language code"), lang_arg);
581
582 if (xml && !docbook)
583 {
584 xml_insert_element_with_attribute (DOCUMENTLANGUAGE, START, "xml:lang=\"%s\"", lang_arg);
585 xml_insert_element (DOCUMENTLANGUAGE, END);
586 }
587
588 free (lang_arg);
589 }
590
591
592
593 /* Search through the encoding table for the given character, returning
594 its equivalent. */
595
596 static int
cm_search_iso_map(char * html)597 cm_search_iso_map (char *html)
598 {
599 int i;
600 iso_map_type *iso = encoding_table[document_encoding_code].isotab;
601
602 /* If no conversion table for this encoding, quit. */
603 if (!iso)
604 return -1;
605
606 for (i = 0; iso[i].html; i++)
607 {
608 if (strcmp (html, iso[i].html) == 0)
609 return i;
610 }
611
612 return -1;
613 }
614
615
616 /* @documentencoding. Set the translation table. */
617
618 void
cm_documentencoding(void)619 cm_documentencoding (void)
620 {
621 if (!handling_delayed_writes)
622 {
623 encoding_code_type enc;
624 char *enc_arg;
625
626 /* This is ugly and probably needs to apply to other commands'
627 argument parsing as well. When we're doing @documentencoding,
628 we're generally in the frontmatter of the document, and so the.
629 expansion in html/xml/docbook would generally be the empty string.
630 (Because those modes wait until the first normal text of the
631 document to start outputting.) The result would thus be a warning
632 "unrecognized encoding name `'". Sigh. */
633 int save_html = html;
634 int save_xml = xml;
635
636 html = 0;
637 xml = 0;
638 get_rest_of_line (1, &enc_arg);
639 html = save_html;
640 xml = save_xml;
641
642 /* See if we have this encoding. */
643 for (enc = no_encoding+1; enc != last_encoding_code; enc++)
644 {
645 if (strcasecmp (enc_arg, encoding_table[enc].encname) == 0)
646 {
647 document_encoding_code = enc;
648 break;
649 }
650 }
651
652 /* If we didn't find this code, complain. */
653 if (enc == last_encoding_code)
654 {
655 warning (_("unrecognized encoding name `%s'"), enc_arg);
656 /* Let the previous one go. */
657 if (unknown_encoding && *unknown_encoding)
658 free (unknown_encoding);
659 unknown_encoding = xstrdup (enc_arg);
660 }
661
662 else if (encoding_table[document_encoding_code].isotab == NULL)
663 warning (_("sorry, encoding `%s' not supported"), enc_arg);
664
665 free (enc_arg);
666 }
667 else if (xml)
668 {
669 char *encoding = current_document_encoding ();
670
671 if (encoding && *encoding)
672 {
673 insert_string (" encoding=\"");
674 insert_string (encoding);
675 insert_string ("\"");
676 }
677
678 free (encoding);
679 }
680 }
681
682 char *
current_document_encoding(void)683 current_document_encoding (void)
684 {
685 if (document_encoding_code != no_encoding)
686 return xstrdup (encoding_table[document_encoding_code].encname);
687 else if (unknown_encoding && *unknown_encoding)
688 return xstrdup (unknown_encoding);
689 else
690 return xstrdup ("");
691 }
692
693
694 /* If html or xml output, add &HTML_STR; to the output. If not html and
695 the user requested encoded output, add the real 8-bit character
696 corresponding to HTML_STR from the translation tables. Otherwise,
697 add INFO_STR. */
698
699 static void
add_encoded_char(char * html_str,char * info_str)700 add_encoded_char (char *html_str, char *info_str)
701 {
702 if (html)
703 add_word_args ("&%s;", html_str);
704 else if (xml)
705 xml_insert_entity (html_str);
706 else if (enable_encoding)
707 {
708 /* Look for HTML_STR in the current translation table. */
709 int rc = cm_search_iso_map (html_str);
710 if (rc >= 0)
711 /* We found it, add the real character. */
712 add_char (encoding_table[document_encoding_code].isotab[rc].bytecode);
713 else
714 { /* We didn't find it, that seems bad. */
715 warning (_("invalid encoded character `%s'"), html_str);
716 add_word (info_str);
717 }
718 }
719 else
720 add_word (info_str);
721 }
722
723
724
725 /* Output an accent for HTML or XML. */
726
727 static void
cm_accent_generic_html(int arg,int start,int end,char * html_supported,int single,int html_solo_standalone,char * html_solo)728 cm_accent_generic_html (int arg, int start, int end, char *html_supported,
729 int single, int html_solo_standalone, char *html_solo)
730 {
731 static int valid_html_accent; /* yikes */
732
733 if (arg == START)
734 { /* If HTML has good support for this character, use it. */
735 if (strchr (html_supported, curchar ()))
736 { /* Yes; start with an ampersand. The character itself
737 will be added later in read_command (makeinfo.c). */
738 int saved_escape_html = escape_html;
739 escape_html = 0;
740 valid_html_accent = 1;
741 add_char ('&');
742 escape_html = saved_escape_html;
743 }
744 else
745 { /* @dotless{i} is not listed in html_supported but HTML entities
746 starting with `i' can be used, such as î. */
747 int save_input_text_offset = input_text_offset;
748 char *accent_contents;
749
750 get_until_in_braces ("\n", &accent_contents);
751 canon_white (accent_contents);
752
753 if (strstr (accent_contents, "@dotless{i"))
754 {
755 add_word_args ("&%c", accent_contents[9]);
756 valid_html_accent = 1;
757 }
758 else
759 {
760 /* Search for @dotless{} wasn't successful, so rewind. */
761 input_text_offset = save_input_text_offset;
762 valid_html_accent = 0;
763 if (html_solo_standalone)
764 { /* No special HTML support, so produce standalone char. */
765 if (xml)
766 xml_insert_entity (html_solo);
767 else
768 add_word_args ("&%s;", html_solo);
769 }
770 else
771 /* If the html_solo does not exist as standalone character
772 (namely ˆ ` ˜), then we use
773 the single character version instead. */
774 add_char (single);
775 }
776
777 free (accent_contents);
778 }
779 }
780 else if (arg == END)
781 { /* Only if we saw a valid_html_accent can we use the full
782 HTML accent (umlaut, grave ...). */
783 if (valid_html_accent)
784 {
785 add_word (html_solo);
786 add_char (';');
787 }
788 }
789 }
790
791
792 static void
cm_accent_generic_no_headers(int arg,int start,int end,int single,char * html_solo)793 cm_accent_generic_no_headers (int arg, int start, int end, int single,
794 char *html_solo)
795 {
796 if (arg == END)
797 {
798 if (no_encoding)
799 add_char (single);
800 else
801 {
802 int rc;
803 char *buffer = xmalloc (1 + strlen (html_solo) + 1);
804 buffer[0] = output_paragraph[end - 1];
805 buffer[1] = 0;
806 strcat (buffer, html_solo);
807
808 rc = cm_search_iso_map (buffer);
809 if (rc >= 0)
810 /* A little bit tricky ;-)
811 Here we replace the character which has
812 been inserted in read_command with
813 the value we have found in converting table
814 Does there exist a better way to do this? kama. */
815 output_paragraph[end - 1]
816 = encoding_table[document_encoding_code].isotab[rc].bytecode;
817 else
818 { /* If we didn't find a translation for this character,
819 put the single instead. E.g., &Xuml; does not exist so X¨
820 should be produced. */
821 /* When the below warning is issued, an author has nothing
822 wrong in their document, let alone anything ``fixable''
823 on their side. So it is commented out for now. */
824 /* warning (_("%s is an invalid ISO code, using %c"),
825 buffer, single); */
826 add_char (single);
827 }
828
829 free (buffer);
830 }
831 }
832 }
833
834
835
836 /* Accent commands that take explicit arguments and don't have any
837 special HTML support. */
838
839 void
cm_accent(int arg)840 cm_accent (int arg)
841 {
842 int old_escape_html = escape_html;
843 escape_html = 0;
844 if (arg == START)
845 {
846 /* Must come first to avoid ambiguity with overdot. */
847 if (strcmp (command, "udotaccent") == 0) /* underdot */
848 add_char ('.');
849 }
850 else if (arg == END)
851 {
852 if (strcmp (command, "=") == 0) /* macron */
853 add_word ((html || xml) ? "¯" : "=");
854 else if (strcmp (command, "H") == 0) /* Hungarian umlaut */
855 add_word ("''");
856 else if (strcmp (command, "dotaccent") == 0) /* overdot */
857 add_meta_char ('.');
858 else if (strcmp (command, "ringaccent") == 0) /* ring */
859 add_char ('*');
860 else if (strcmp (command, "tieaccent") == 0) /* long tie */
861 add_char ('[');
862 else if (strcmp (command, "u") == 0) /* breve */
863 add_char ('(');
864 else if (strcmp (command, "ubaraccent") == 0) /* underbar */
865 add_char ('_');
866 else if (strcmp (command, "v") == 0) /* hacek/check */
867 add_word ((html || xml) ? "<" : "<");
868 }
869 escape_html = old_escape_html;
870 }
871
872 /* Common routine for the accent characters that have support in HTML.
873 If the character being accented is in the HTML_SUPPORTED set, then
874 produce &CHTML_SOLO;, for example, Ä for an A-umlaut. If not in
875 HTML_SUPPORTED, just produce &HTML_SOLO;X for the best we can do with
876 at an X-umlaut. If not producing HTML, just use SINGLE, a
877 character such as " which is the best plain text representation we
878 can manage. If HTML_SOLO_STANDALONE is nonzero the given HTML_SOLO
879 exists as valid standalone character in HTML, e.g., ¨. */
880
881 static void
cm_accent_generic(int arg,int start,int end,char * html_supported,int single,int html_solo_standalone,char * html_solo)882 cm_accent_generic (int arg, int start, int end, char *html_supported,
883 int single, int html_solo_standalone, char *html_solo)
884 {
885 /* Accentuating space characters makes no sense, so issue a warning. */
886 if (arg == START && isspace (input_text[input_text_offset]))
887 warning ("Accent command `@%s' must not be followed by whitespace",
888 command);
889
890 if (html || xml)
891 cm_accent_generic_html (arg, start, end, html_supported,
892 single, html_solo_standalone, html_solo);
893 else if (no_headers)
894 cm_accent_generic_no_headers (arg, start, end, single, html_solo);
895 else if (arg == END)
896 {
897 if (enable_encoding)
898 /* use 8-bit if available */
899 cm_accent_generic_no_headers (arg, start, end, single, html_solo);
900 else
901 /* use regular character */
902 add_char (single);
903 }
904 }
905
906 void
cm_accent_umlaut(int arg,int start,int end)907 cm_accent_umlaut (int arg, int start, int end)
908 {
909 cm_accent_generic (arg, start, end, "aouAOUEeIiy", '"', 1, "uml");
910 }
911
912 void
cm_accent_acute(int arg,int start,int end)913 cm_accent_acute (int arg, int start, int end)
914 {
915 cm_accent_generic (arg, start, end, "AEIOUYaeiouy", '\'', 1, "acute");
916 }
917
918 void
cm_accent_cedilla(int arg,int start,int end)919 cm_accent_cedilla (int arg, int start, int end)
920 {
921 cm_accent_generic (arg, start, end, "Cc", ',', 1, "cedil");
922 }
923
924 void
cm_accent_hat(int arg,int start,int end)925 cm_accent_hat (int arg, int start, int end)
926 {
927 cm_accent_generic (arg, start, end, "AEIOUaeiou", '^', 0, "circ");
928 }
929
930 void
cm_accent_grave(int arg,int start,int end)931 cm_accent_grave (int arg, int start, int end)
932 {
933 cm_accent_generic (arg, start, end, "AEIOUaeiou", '`', 0, "grave");
934 }
935
936 void
cm_accent_tilde(int arg,int start,int end)937 cm_accent_tilde (int arg, int start, int end)
938 {
939 cm_accent_generic (arg, start, end, "ANOano", '~', 0, "tilde");
940 }
941
942
943
944 /* Non-English letters/characters that don't insert themselves. */
945 void
cm_special_char(int arg)946 cm_special_char (int arg)
947 {
948 int old_escape_html = escape_html;
949 escape_html = 0;
950
951 if (arg == START)
952 {
953 if ((*command == 'L' || *command == 'l'
954 || *command == 'O' || *command == 'o')
955 && command[1] == 0)
956 { /* Lslash lslash Oslash oslash.
957 Lslash and lslash aren't supported in HTML. */
958 if (command[0] == 'O')
959 add_encoded_char ("Oslash", "/O");
960 else if (command[0] == 'o')
961 add_encoded_char ("oslash", "/o");
962 else
963 add_word_args ("/%c", command[0]);
964 }
965 else if (strcmp (command, "exclamdown") == 0)
966 add_encoded_char ("iexcl", "!");
967 else if (strcmp (command, "questiondown") == 0)
968 add_encoded_char ("iquest", "?");
969 else if (strcmp (command, "euro") == 0)
970 /* http://www.cs.tut.fi/~jkorpela/html/euro.html suggests that
971 € degrades best in old browsers. */
972 add_encoded_char ("euro", "Euro ");
973 else if (strcmp (command, "pounds") == 0)
974 add_encoded_char ("pound" , "#");
975 else if (strcmp (command, "ordf") == 0)
976 add_encoded_char ("ordf" , "a");
977 else if (strcmp (command, "ordm") == 0)
978 add_encoded_char ("ordm" , "o");
979 else if (strcmp (command, "AE") == 0)
980 add_encoded_char ("AElig", command);
981 else if (strcmp (command, "ae") == 0)
982 add_encoded_char ("aelig", command);
983 else if (strcmp (command, "OE") == 0)
984 add_encoded_char ("OElig", command);
985 else if (strcmp (command, "oe") == 0)
986 add_encoded_char ("oelig", command);
987 else if (strcmp (command, "AA") == 0)
988 add_encoded_char ("Aring", command);
989 else if (strcmp (command, "aa") == 0)
990 add_encoded_char ("aring", command);
991 else if (strcmp (command, "ss") == 0)
992 add_encoded_char ("szlig", command);
993 else
994 line_error ("cm_special_char internal error: command=@%s", command);
995 }
996 escape_html = old_escape_html;
997 }
998
999 /* Dotless i or j. */
1000 void
cm_dotless(int arg,int start,int end)1001 cm_dotless (int arg, int start, int end)
1002 {
1003 if (arg == END)
1004 {
1005 xml_no_para --;
1006 if (output_paragraph[start] != 'i' && output_paragraph[start] != 'j')
1007 /* This error message isn't perfect if the argument is multiple
1008 characters, but it doesn't seem worth getting right. */
1009 line_error (_("%c%s expects `i' or `j' as argument, not `%c'"),
1010 COMMAND_PREFIX, command, output_paragraph[start]);
1011
1012 else if (end - start != 1)
1013 line_error (_("%c%s expects a single character `i' or `j' as argument"),
1014 COMMAND_PREFIX, command);
1015
1016 /* We've already inserted the `i' or `j', so nothing to do. */
1017 }
1018 else
1019 xml_no_para ++;
1020 }
1021