1 /* lang.c -- language-dependent support.
2 $Id: lang.c,v 1.14 2001/09/11 18:04:35 karl Exp $
4 Copyright (C) 1999, 2000, 01 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 Originally written by Karl Heinz Marbaise <kama@hippo.fido.de>. */
28 /* Current document encoding. */
29 encoding_code_type document_encoding_code = no_encoding;
31 /* Current language code; default is English. */
32 language_code_type language_code = en;
34 /* Translation table between HTML and ISO Codes. The last item is
35 hopefully the Unicode. It might be possible that those Unicodes are
36 not correct, cause I didn't check them. kama */
37 iso_map_type iso8859_1_map [] = {
38 { "nbsp", 0xA0, 0x00A0 },
39 { "iexcl", 0xA1, 0x00A1 },
40 { "cent", 0xA2, 0x00A2 },
41 { "pound", 0xA3, 0x00A3 },
42 { "curren", 0xA4, 0x00A4 },
43 { "yen", 0xA5, 0x00A5 },
44 { "brkbar", 0xA6, 0x00A6 },
45 { "sect", 0xA7, 0x00A7 },
46 { "uml", 0xA8, 0x00A8 },
47 { "copy", 0xA9, 0x00A9 },
48 { "ordf", 0xAA, 0x00AA },
49 { "laquo", 0xAB, 0x00AB },
50 { "not", 0xAC, 0x00AC },
51 { "shy", 0xAD, 0x00AD },
52 { "reg", 0xAE, 0x00AE },
53 { "hibar", 0xAF, 0x00AF },
54 { "deg", 0xB0, 0x00B0 },
55 { "plusmn", 0xB1, 0x00B1 },
56 { "sup2", 0xB2, 0x00B2 },
57 { "sup3", 0xB3, 0x00B3 },
58 { "acute", 0xB4, 0x00B4 },
59 { "micro", 0xB5, 0x00B5 },
60 { "para", 0xB6, 0x00B6 },
61 { "middot", 0xB7, 0x00B7 },
62 { "cedil", 0xB8, 0x00B8 },
63 { "sup1", 0xB9, 0x00B9 },
64 { "ordm", 0xBA, 0x00BA },
65 { "raquo", 0xBB, 0x00BB },
66 { "frac14", 0xBC, 0x00BC },
67 { "frac12", 0xBD, 0x00BD },
68 { "frac34", 0xBE, 0x00BE },
69 { "iquest", 0xBF, 0x00BF },
70 { "Agrave", 0xC0, 0x00C0 },
71 { "Aacute", 0xC1, 0x00C1 },
72 { "Acirc", 0xC2, 0x00C2 },
73 { "Atilde", 0xC3, 0x00C3 },
74 { "Auml", 0xC4, 0x00C4 },
75 { "Aring", 0xC5, 0x00C5 },
76 { "AElig", 0xC6, 0x00C6 },
77 { "Ccedil", 0xC7, 0x00C7 },
78 { "Ccedil", 0xC7, 0x00C7 },
79 { "Egrave", 0xC8, 0x00C8 },
80 { "Eacute", 0xC9, 0x00C9 },
81 { "Ecirc", 0xCA, 0x00CA },
82 { "Euml", 0xCB, 0x00CB },
83 { "Igrave", 0xCC, 0x00CC },
84 { "Iacute", 0xCD, 0x00CD },
85 { "Icirc", 0xCE, 0x00CE },
86 { "Iuml", 0xCF, 0x00CF },
87 { "ETH", 0xD0, 0x00D0 }, /* I don't know ;-( */
88 { "Ntilde", 0xD1, 0x00D1 },
89 { "Ograve", 0xD2, 0x00D2 },
90 { "Oacute", 0xD3, 0x00D3 },
91 { "Ocirc", 0xD4, 0x00D4 },
92 { "Otilde", 0xD5, 0x00D5 },
93 { "Ouml", 0xD6, 0x00D6 },
94 { "times", 0xD7, 0x00D7 },
95 { "Oslash", 0xD8, 0x00D8 },
96 { "Ugrave", 0xD9, 0x00D9 },
97 { "Uacute", 0xDA, 0x00DA },
98 { "Ucirc", 0xDB, 0x00DB },
99 { "Uuml", 0xDC, 0x00DC },
100 { "Yacute", 0xDD, 0x00DD },
101 { "THORN", 0xDE, 0x00DE },
102 { "szlig", 0xDF, 0x00DF },
103 { "agrave", 0xE0, 0x00E0 },
104 { "aacute", 0xE1, 0x00E1 },
105 { "acirc", 0xE2, 0x00E2 },
106 { "atilde", 0xE3, 0x00E3 },
107 { "auml", 0xE4, 0x00E4 },
108 { "aring", 0xE5, 0x00E5 },
109 { "aelig", 0xE6, 0x00E6 },
110 { "ccedil", 0xE7, 0x00E7 },
111 { "egrave", 0xE8, 0x00E8 },
112 { "eacute", 0xE9, 0x00E9 },
113 { "ecirc", 0xEA, 0x00EA },
114 { "euml", 0xEB, 0x00EB },
115 { "igrave", 0xEC, 0x00EC },
116 { "iacute", 0xED, 0x00ED },
117 { "icirc", 0xEE, 0x00EE },
118 { "iuml", 0xEF, 0x00EF },
119 { "eth", 0xF0, 0x00F0 },
120 { "ntilde", 0xF1, 0x00F1 },
121 { "ograve", 0xF2, 0x00F2 },
122 { "oacute", 0xF3, 0x00F3 },
123 { "ocirc", 0xF4, 0x00F4 },
124 { "otilde", 0xF5, 0x00F5 },
125 { "ouml", 0xF6, 0x00F6 },
126 { "divide", 0xF7, 0x00F7 },
127 { "oslash", 0xF8, 0x00F8 },
128 { "ugrave", 0xF9, 0x00F9 },
129 { "uacute", 0xFA, 0x00FA },
130 { "ucirc", 0xFB, 0x00FB },
131 { "uuml", 0xFC, 0x00FC },
132 { "yacute", 0xFD, 0x00FD },
133 { "thorn", 0xFE, 0x00FE },
134 { "yuml", 0xFF, 0x00FF }
137 /* This might be put into structure below and NOT coded via define,
138 because some translation tables could contain different numbers of
139 characters, but for now it suffices. */
140 #define ISO_MAP_SIZE (sizeof (iso8859_1_map) / sizeof (iso8859_1_map[0]))
142 encoding_type encoding_table[] = {
143 { no_encoding, "(no encoding)", NULL },
144 { ISO_8859_1, "ISO-8859-1", (iso_map_type *) iso8859_1_map },
145 { ISO_8859_2, "ISO-8859-2", NULL },
146 { ISO_8859_3, "ISO-8859-3", NULL },
147 { ISO_8859_4, "ISO-8859-4", NULL },
148 { ISO_8859_5, "ISO-8859-5", NULL },
149 { ISO_8859_6, "ISO-8859-6", NULL },
150 { ISO_8859_7, "ISO-8859-7", NULL },
151 { ISO_8859_8, "ISO-8859-8", NULL },
152 { ISO_8859_9, "ISO-8859-9", NULL },
153 { ISO_8859_10, "ISO-8859-10", NULL },
154 { ISO_8859_11, "ISO-8859-11", NULL },
155 { ISO_8859_12, "ISO-8859-12", NULL },
156 { ISO_8859_13, "ISO-8859-13", NULL },
157 { ISO_8859_14, "ISO-8859-14", NULL },
158 { ISO_8859_15, "ISO-8859-15", NULL },
159 { last_encoding_code, NULL, NULL }
163 language_type language_table[] = {
164 { aa, "aa", "Afar" },
165 { ab, "ab", "Abkhazian" },
166 { af, "af", "Afrikaans" },
167 { am, "am", "Amharic" },
168 { ar, "ar", "Arabic" },
169 { as, "as", "Assamese" },
170 { ay, "ay", "Aymara" },
171 { az, "az", "Azerbaijani" },
172 { ba, "ba", "Bashkir" },
173 { be, "be", "Byelorussian" },
174 { bg, "bg", "Bulgarian" },
175 { bh, "bh", "Bihari" },
176 { bi, "bi", "Bislama" },
177 { bn, "bn", "Bengali; Bangla" },
178 { bo, "bo", "Tibetan" },
179 { br, "br", "Breton" },
180 { ca, "ca", "Catalan" },
181 { co, "co", "Corsican" },
182 { cs, "cs", "Czech" },
183 { cy, "cy", "Welsh" },
184 { da, "da", "Danish" },
185 { de, "de", "German" },
186 { dz, "dz", "Bhutani" },
187 { el, "el", "Greek" },
188 { en, "en", "English" },
189 { eo, "eo", "Esperanto" },
190 { es, "es", "Spanish" },
191 { et, "et", "Estonian" },
192 { eu, "eu", "Basque" },
193 { fa, "fa", "Persian" },
194 { fi, "fi", "Finnish" },
195 { fj, "fj", "Fiji" },
196 { fo, "fo", "Faroese" },
197 { fr, "fr", "French" },
198 { fy, "fy", "Frisian" },
199 { ga, "ga", "Irish" },
200 { gd, "gd", "Scots Gaelic" },
201 { gl, "gl", "Galician" },
202 { gn, "gn", "Guarani" },
203 { gu, "gu", "Gujarati" },
204 { ha, "ha", "Hausa" },
205 { he, "he", "Hebrew" } /* (formerly iw) */,
206 { hi, "hi", "Hindi" },
207 { hr, "hr", "Croatian" },
208 { hu, "hu", "Hungarian" },
209 { hy, "hy", "Armenian" },
210 { ia, "ia", "Interlingua" },
211 { id, "id", "Indonesian" } /* (formerly in) */,
212 { ie, "ie", "Interlingue" },
213 { ik, "ik", "Inupiak" },
214 { is, "is", "Icelandic" },
215 { it, "it", "Italian" },
216 { iu, "iu", "Inuktitut" },
217 { ja, "ja", "Japanese" },
218 { jw, "jw", "Javanese" },
219 { ka, "ka", "Georgian" },
220 { kk, "kk", "Kazakh" },
221 { kl, "kl", "Greenlandic" },
222 { km, "km", "Cambodian" },
223 { kn, "kn", "Kannada" },
224 { ko, "ko", "Korean" },
225 { ks, "ks", "Kashmiri" },
226 { ku, "ku", "Kurdish" },
227 { ky, "ky", "Kirghiz" },
228 { la, "la", "Latin" },
229 { ln, "ln", "Lingala" },
230 { lo, "lo", "Laothian" },
231 { lt, "lt", "Lithuanian" },
232 { lv, "lv", "Latvian, Lettish" },
233 { mg, "mg", "Malagasy" },
234 { mi, "mi", "Maori" },
235 { mk, "mk", "Macedonian" },
236 { ml, "ml", "Malayalam" },
237 { mn, "mn", "Mongolian" },
238 { mo, "mo", "Moldavian" },
239 { mr, "mr", "Marathi" },
240 { ms, "ms", "Malay" },
241 { mt, "mt", "Maltese" },
242 { my, "my", "Burmese" },
243 { na, "na", "Nauru" },
244 { ne, "ne", "Nepali" },
245 { nl, "nl", "Dutch" },
246 { no, "no", "Norwegian" },
247 { oc, "oc", "Occitan" },
248 { om, "om", "(Afan) Oromo" },
249 { or, "or", "Oriya" },
250 { pa, "pa", "Punjabi" },
251 { pl, "pl", "Polish" },
252 { ps, "ps", "Pashto, Pushto" },
253 { pt, "pt", "Portuguese" },
254 { qu, "qu", "Quechua" },
255 { rm, "rm", "Rhaeto-Romance" },
256 { rn, "rn", "Kirundi" },
257 { ro, "ro", "Romanian" },
258 { ru, "ru", "Russian" },
259 { rw, "rw", "Kinyarwanda" },
260 { sa, "sa", "Sanskrit" },
261 { sd, "sd", "Sindhi" },
262 { sg, "sg", "Sangro" },
263 { sh, "sh", "Serbo-Croatian" },
264 { si, "si", "Sinhalese" },
265 { sk, "sk", "Slovak" },
266 { sl, "sl", "Slovenian" },
267 { sm, "sm", "Samoan" },
268 { sn, "sn", "Shona" },
269 { so, "so", "Somali" },
270 { sq, "sq", "Albanian" },
271 { sr, "sr", "Serbian" },
272 { ss, "ss", "Siswati" },
273 { st, "st", "Sesotho" },
274 { su, "su", "Sundanese" },
275 { sv, "sv", "Swedish" },
276 { sw, "sw", "Swahili" },
277 { ta, "ta", "Tamil" },
278 { te, "te", "Telugu" },
279 { tg, "tg", "Tajik" },
280 { th, "th", "Thai" },
281 { ti, "ti", "Tigrinya" },
282 { tk, "tk", "Turkmen" },
283 { tl, "tl", "Tagalog" },
284 { tn, "tn", "Setswana" },
285 { to, "to", "Tonga" },
286 { tr, "tr", "Turkish" },
287 { ts, "ts", "Tsonga" },
288 { tt, "tt", "Tatar" },
290 { ug, "ug", "Uighur" },
291 { uk, "uk", "Ukrainian" },
292 { ur, "ur", "Urdu" },
293 { uz, "uz", "Uzbek" },
294 { vi, "vi", "Vietnamese" },
295 { vo, "vo", "Volapuk" },
296 { wo, "wo", "Wolof" },
297 { xh, "xh", "Xhosa" },
298 { yi, "yi", "Yiddish" } /* (formerly ji) */,
299 { yo, "yo", "Yoruba" },
300 { za, "za", "Zhuang" },
301 { zh, "zh", "Chinese" },
302 { zu, "zu", "Zulu" },
303 { last_language_code, NULL, NULL }
308 /* @documentlanguage. Maybe we'll do something useful with this in the
309 future. For now, we just recognize it. */
311 cm_documentlanguage ()
313 language_code_type c;
316 /* Read the line with the language code on it. */
317 get_rest_of_line (0, &lang_arg);
319 /* Linear search is fine these days. */
320 for (c = aa; c != last_language_code; c++)
322 if (strcmp (lang_arg, language_table[c].abbrev) == 0)
323 { /* Set current language code. */
329 /* If we didn't find this code, complain. */
330 if (c == last_language_code)
331 warning (_("%s is not a valid ISO 639 language code"), lang_arg);
338 /* Search through the encoding table for the given character, returning
342 cm_search_iso_map (html)
346 iso_map_type *iso = encoding_table[document_encoding_code].isotab;
348 /* If no conversion table for this encoding, quit. */
352 for (i = 0; i < ISO_MAP_SIZE; i++)
354 if (strcmp (html, iso[i].html) == 0)
362 /* @documentencoding. Set the translation table. */
365 cm_documentencoding ()
367 encoding_code_type enc;
370 get_rest_of_line (1, &enc_arg);
372 /* See if we have this encoding. */
373 for (enc = ISO_8859_1; enc != last_encoding_code; enc++)
375 if (strcasecmp (enc_arg, encoding_table[enc].ecname) == 0)
377 document_encoding_code = enc;
382 /* If we didn't find this code, complain. */
383 if (enc == last_encoding_code)
384 warning (_("unrecogized encoding name `%s'"), enc_arg);
386 else if (encoding_table[document_encoding_code].isotab == NULL)
387 warning (_("sorry, encoding `%s' not supported"), enc_arg);
393 /* If html or xml output, add HTML_STR to the output. If not html and
394 the user requested encoded output, add the real 8-bit character
395 corresponding to HTML_STR from the translation tables. Otherwise,
399 add_encoded_char (html_str, info_str)
404 add_word_args ("&%s;", html_str);
405 else if (enable_encoding)
407 /* Look for HTML_STR in the current translation table. */
408 int rc = cm_search_iso_map (html_str);
410 /* We found it, add the real character. */
411 add_char (encoding_table[document_encoding_code].isotab[rc].bytecode);
413 { /* We didn't find it, that seems bad. */
414 warning (_("invalid encoded character `%s'"), html_str);
424 /* Output an accent for HTML or XML. */
427 cm_accent_generic_html (arg, start, end, html_supported, single,
428 html_solo_standalone, html_solo)
430 char *html_supported;
432 int html_solo_standalone;
435 static int valid_html_accent; /* yikes */
438 { /* If HTML has good support for this character, use it. */
439 if (strchr (html_supported, curchar ()))
440 { /* Yes; start with an ampersand. The character itself
441 will be added later in read_command (makeinfo.c). */
442 valid_html_accent = 1;
447 valid_html_accent = 0;
448 if (html_solo_standalone)
449 { /* No special HTML support, so produce standalone char. */
450 add_word_args ("&%s;", html_solo);
453 /* If the html_solo does not exist as standalone character
454 (namely ˆ ` ˜), then we use
455 the single character version instead. */
460 { /* Only if we saw a valid_html_accent can we use the full
461 HTML accent (umlaut, grave ...). */
462 if (valid_html_accent)
464 add_word (html_solo);
472 cm_accent_generic_no_headers (arg, start, end, single, html_solo)
484 char *buffer = xmalloc (1 + strlen (html_solo) + 1);
485 buffer[0] = output_paragraph[end - 1];
487 strcat (buffer, html_solo);
489 rc = cm_search_iso_map (buffer);
491 /* A little bit tricky ;-)
492 Here we replace the character which has
493 been inserted in read_command with
494 the value we have found in converting table
495 Does there exist a better way to do this? kama. */
496 output_paragraph[end - 1]
497 = encoding_table[document_encoding_code].isotab[rc].bytecode;
499 { /* If we didn't find a translation for this character,
500 put the single instead. E.g., &Xuml; does not exist so X¨
501 should be produced. */
502 warning (_("%s is an invalid ISO code, using %c"),
514 /* Accent commands that take explicit arguments and don't have any
515 special HTML support. */
521 int old_escape_html = escape_html;
525 /* Must come first to avoid ambiguity with overdot. */
526 if (strcmp (command, "udotaccent") == 0) /* underdot */
531 if (strcmp (command, "=") == 0) /* macron */
532 add_word ((html || xml) ? "¯" : "=");
533 else if (strcmp (command, "H") == 0) /* Hungarian umlaut */
535 else if (strcmp (command, "dotaccent") == 0) /* overdot */
537 else if (strcmp (command, "ringaccent") == 0) /* ring */
539 else if (strcmp (command, "tieaccent") == 0) /* long tie */
541 else if (strcmp (command, "u") == 0) /* breve */
543 else if (strcmp (command, "ubaraccent") == 0) /* underbar */
545 else if (strcmp (command, "v") == 0) /* hacek/check */
546 add_word ((html || xml) ? "<" : "<");
548 escape_html = old_escape_html;
551 /* Common routine for the accent characters that have support in HTML.
552 If the character being accented is in the HTML_SUPPORTED set, then
553 produce &CHTML_SOLO;, for example, Ä for an A-umlaut. If not in
554 HTML_SUPPORTED, just produce &HTML_SOLO;X for the best we can do with
555 at an X-umlaut. If not producing HTML, just use SINGLE, a
556 character such as " which is the best plain text representation we
557 can manage. If HTML_SOLO_STANDALONE is nonzero the given HTML_SOLO
558 exists as valid standalone character in HTML, e.g., ¨. */
561 cm_accent_generic (arg, start, end, html_supported, single,
562 html_solo_standalone, html_solo)
564 char *html_supported;
566 int html_solo_standalone;
570 cm_accent_generic_html (arg, start, end, html_supported,
571 single, html_solo_standalone, html_solo);
573 cm_accent_generic_no_headers (arg, start, end, single, html_solo);
577 /* use 8-bit if available */
578 cm_accent_generic_no_headers (arg, start, end, single, html_solo);
580 /* use regular character */
586 cm_accent_umlaut (arg, start, end)
589 cm_accent_generic (arg, start, end, "aouAOUEeIiy", '"', 1, "uml");
593 cm_accent_acute (arg, start, end)
596 cm_accent_generic (arg, start, end, "AEIOUYaeiouy", '\'', 1, "acute");
600 cm_accent_cedilla (arg, start, end)
603 cm_accent_generic (arg, start, end, "Cc", ',', 1, "cedil");
607 cm_accent_hat (arg, start, end)
610 cm_accent_generic (arg, start, end, "AEIOUaeiou", '^', 0, "circ");
614 cm_accent_grave (arg, start, end)
617 cm_accent_generic (arg, start, end, "AEIOUaeiou", '`', 0, "grave");
621 cm_accent_tilde (arg, start, end)
624 cm_accent_generic (arg, start, end, "ANOano", '~', 0, "tilde");
629 /* Non-English letters/characters that don't insert themselves. */
631 cm_special_char (arg)
633 int old_escape_html = escape_html;
638 if ((*command == 'L' || *command == 'l'
639 || *command == 'O' || *command == 'o')
641 { /* Lslash lslash Oslash oslash.
642 Lslash and lslash aren't supported in HTML. */
643 if ((html || xml) && command[0] == 'O')
644 add_encoded_char ("Oslash", "/O");
645 else if ((html || xml) && command[0] == 'o')
646 add_encoded_char ("oslash", "/o");
648 add_word_args ("/%c", command[0]);
650 else if (strcmp (command, "exclamdown") == 0)
651 add_encoded_char ("iexcl", "!");
652 else if (strcmp (command, "pounds") == 0)
653 add_encoded_char ("pound" , "#");
654 else if (strcmp (command, "questiondown") == 0)
655 add_encoded_char ("iquest", "?");
656 else if (strcmp (command, "AE") == 0)
657 add_encoded_char ("AElig", command);
658 else if (strcmp (command, "ae") == 0)
659 add_encoded_char ("aelig", command);
660 else if (strcmp (command, "OE") == 0)
661 add_word ("Œ", command);
662 else if (strcmp (command, "oe") == 0)
663 add_word ("œ", command);
664 else if (strcmp (command, "AA") == 0)
665 add_encoded_char ("Aring", command);
666 else if (strcmp (command, "aa") == 0)
667 add_encoded_char ("aring", command);
668 else if (strcmp (command, "ss") == 0)
669 add_encoded_char ("szlig", command);
671 line_error ("cm_special_char internal error: command=@%s", command);
673 escape_html = old_escape_html;
676 /* Dotless i or j. */
678 cm_dotless (arg, start, end)
684 if (output_paragraph[start] != 'i' && output_paragraph[start] != 'j')
685 /* This error message isn't perfect if the argument is multiple
686 characters, but it doesn't seem worth getting right. */
687 line_error (_("%c%s expects `i' or `j' as argument, not `%c'"),
688 COMMAND_PREFIX, command, output_paragraph[start]);
690 else if (end - start != 1)
691 line_error (_("%c%s expects a single character `i' or `j' as argument"),
692 COMMAND_PREFIX, command);
694 /* We've already inserted the `i' or `j', so nothing to do. */