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