aboutsummaryrefslogtreecommitdiff
path: root/contrib/texinfo/makeinfo/lang.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2002-03-25 13:08:32 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2002-03-25 13:08:32 +0000
commit3423f6a2cba6d3cc1f5f66cdb873f30d92afbffb (patch)
treea83aebd48e0338a00136e68cbd70a1ef081175fc /contrib/texinfo/makeinfo/lang.c
parentcab79d664647c337ec2def083dd99de2ce69c174 (diff)
Import of stripped down GNU texinfo 4.1
Notes
Notes: svn path=/vendor/texinfo/dist/; revision=93139
Diffstat (limited to 'contrib/texinfo/makeinfo/lang.c')
-rw-r--r--contrib/texinfo/makeinfo/lang.c419
1 files changed, 351 insertions, 68 deletions
diff --git a/contrib/texinfo/makeinfo/lang.c b/contrib/texinfo/makeinfo/lang.c
index eeb9ef582a4f..468bed80b1f0 100644
--- a/contrib/texinfo/makeinfo/lang.c
+++ b/contrib/texinfo/makeinfo/lang.c
@@ -1,7 +1,7 @@
-/* lang.c -- language depend behaviour (startpoint)
- $Id: lang.c,v 1.11 1999/07/13 21:16:29 karl Exp $
+/* lang.c -- language-dependent support.
+ $Id: lang.c,v 1.14 2001/09/11 18:04:35 karl Exp $
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 01 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,20 +17,150 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- Written by Karl Heinz Marbaise <kama@hippo.fido.de>. */
+ Originally written by Karl Heinz Marbaise <kama@hippo.fido.de>. */
#include "system.h"
#include "cmds.h"
#include "lang.h"
#include "makeinfo.h"
+#include "xml.h"
/* Current document encoding. */
-char *document_encoding = NULL;
+encoding_code_type document_encoding_code = no_encoding;
/* Current language code; default is English. */
language_code_type language_code = en;
-language_struct language_table[] = {
+/* Translation table between HTML and ISO Codes. The last item is
+ hopefully the Unicode. It might be possible that those Unicodes are
+ not correct, cause I didn't check them. kama */
+iso_map_type iso8859_1_map [] = {
+ { "nbsp", 0xA0, 0x00A0 },
+ { "iexcl", 0xA1, 0x00A1 },
+ { "cent", 0xA2, 0x00A2 },
+ { "pound", 0xA3, 0x00A3 },
+ { "curren", 0xA4, 0x00A4 },
+ { "yen", 0xA5, 0x00A5 },
+ { "brkbar", 0xA6, 0x00A6 },
+ { "sect", 0xA7, 0x00A7 },
+ { "uml", 0xA8, 0x00A8 },
+ { "copy", 0xA9, 0x00A9 },
+ { "ordf", 0xAA, 0x00AA },
+ { "laquo", 0xAB, 0x00AB },
+ { "not", 0xAC, 0x00AC },
+ { "shy", 0xAD, 0x00AD },
+ { "reg", 0xAE, 0x00AE },
+ { "hibar", 0xAF, 0x00AF },
+ { "deg", 0xB0, 0x00B0 },
+ { "plusmn", 0xB1, 0x00B1 },
+ { "sup2", 0xB2, 0x00B2 },
+ { "sup3", 0xB3, 0x00B3 },
+ { "acute", 0xB4, 0x00B4 },
+ { "micro", 0xB5, 0x00B5 },
+ { "para", 0xB6, 0x00B6 },
+ { "middot", 0xB7, 0x00B7 },
+ { "cedil", 0xB8, 0x00B8 },
+ { "sup1", 0xB9, 0x00B9 },
+ { "ordm", 0xBA, 0x00BA },
+ { "raquo", 0xBB, 0x00BB },
+ { "frac14", 0xBC, 0x00BC },
+ { "frac12", 0xBD, 0x00BD },
+ { "frac34", 0xBE, 0x00BE },
+ { "iquest", 0xBF, 0x00BF },
+ { "Agrave", 0xC0, 0x00C0 },
+ { "Aacute", 0xC1, 0x00C1 },
+ { "Acirc", 0xC2, 0x00C2 },
+ { "Atilde", 0xC3, 0x00C3 },
+ { "Auml", 0xC4, 0x00C4 },
+ { "Aring", 0xC5, 0x00C5 },
+ { "AElig", 0xC6, 0x00C6 },
+ { "Ccedil", 0xC7, 0x00C7 },
+ { "Ccedil", 0xC7, 0x00C7 },
+ { "Egrave", 0xC8, 0x00C8 },
+ { "Eacute", 0xC9, 0x00C9 },
+ { "Ecirc", 0xCA, 0x00CA },
+ { "Euml", 0xCB, 0x00CB },
+ { "Igrave", 0xCC, 0x00CC },
+ { "Iacute", 0xCD, 0x00CD },
+ { "Icirc", 0xCE, 0x00CE },
+ { "Iuml", 0xCF, 0x00CF },
+ { "ETH", 0xD0, 0x00D0 }, /* I don't know ;-( */
+ { "Ntilde", 0xD1, 0x00D1 },
+ { "Ograve", 0xD2, 0x00D2 },
+ { "Oacute", 0xD3, 0x00D3 },
+ { "Ocirc", 0xD4, 0x00D4 },
+ { "Otilde", 0xD5, 0x00D5 },
+ { "Ouml", 0xD6, 0x00D6 },
+ { "times", 0xD7, 0x00D7 },
+ { "Oslash", 0xD8, 0x00D8 },
+ { "Ugrave", 0xD9, 0x00D9 },
+ { "Uacute", 0xDA, 0x00DA },
+ { "Ucirc", 0xDB, 0x00DB },
+ { "Uuml", 0xDC, 0x00DC },
+ { "Yacute", 0xDD, 0x00DD },
+ { "THORN", 0xDE, 0x00DE },
+ { "szlig", 0xDF, 0x00DF },
+ { "agrave", 0xE0, 0x00E0 },
+ { "aacute", 0xE1, 0x00E1 },
+ { "acirc", 0xE2, 0x00E2 },
+ { "atilde", 0xE3, 0x00E3 },
+ { "auml", 0xE4, 0x00E4 },
+ { "aring", 0xE5, 0x00E5 },
+ { "aelig", 0xE6, 0x00E6 },
+ { "ccedil", 0xE7, 0x00E7 },
+ { "egrave", 0xE8, 0x00E8 },
+ { "eacute", 0xE9, 0x00E9 },
+ { "ecirc", 0xEA, 0x00EA },
+ { "euml", 0xEB, 0x00EB },
+ { "igrave", 0xEC, 0x00EC },
+ { "iacute", 0xED, 0x00ED },
+ { "icirc", 0xEE, 0x00EE },
+ { "iuml", 0xEF, 0x00EF },
+ { "eth", 0xF0, 0x00F0 },
+ { "ntilde", 0xF1, 0x00F1 },
+ { "ograve", 0xF2, 0x00F2 },
+ { "oacute", 0xF3, 0x00F3 },
+ { "ocirc", 0xF4, 0x00F4 },
+ { "otilde", 0xF5, 0x00F5 },
+ { "ouml", 0xF6, 0x00F6 },
+ { "divide", 0xF7, 0x00F7 },
+ { "oslash", 0xF8, 0x00F8 },
+ { "ugrave", 0xF9, 0x00F9 },
+ { "uacute", 0xFA, 0x00FA },
+ { "ucirc", 0xFB, 0x00FB },
+ { "uuml", 0xFC, 0x00FC },
+ { "yacute", 0xFD, 0x00FD },
+ { "thorn", 0xFE, 0x00FE },
+ { "yuml", 0xFF, 0x00FF }
+};
+
+/* This might be put into structure below and NOT coded via define,
+ because some translation tables could contain different numbers of
+ characters, but for now it suffices. */
+#define ISO_MAP_SIZE (sizeof (iso8859_1_map) / sizeof (iso8859_1_map[0]))
+
+encoding_type encoding_table[] = {
+ { no_encoding, "(no encoding)", NULL },
+ { ISO_8859_1, "ISO-8859-1", (iso_map_type *) iso8859_1_map },
+ { ISO_8859_2, "ISO-8859-2", NULL },
+ { ISO_8859_3, "ISO-8859-3", NULL },
+ { ISO_8859_4, "ISO-8859-4", NULL },
+ { ISO_8859_5, "ISO-8859-5", NULL },
+ { ISO_8859_6, "ISO-8859-6", NULL },
+ { ISO_8859_7, "ISO-8859-7", NULL },
+ { ISO_8859_8, "ISO-8859-8", NULL },
+ { ISO_8859_9, "ISO-8859-9", NULL },
+ { ISO_8859_10, "ISO-8859-10", NULL },
+ { ISO_8859_11, "ISO-8859-11", NULL },
+ { ISO_8859_12, "ISO-8859-12", NULL },
+ { ISO_8859_13, "ISO-8859-13", NULL },
+ { ISO_8859_14, "ISO-8859-14", NULL },
+ { ISO_8859_15, "ISO-8859-15", NULL },
+ { last_encoding_code, NULL, NULL }
+};
+
+
+language_type language_table[] = {
{ aa, "aa", "Afar" },
{ ab, "ab", "Abkhazian" },
{ af, "af", "Afrikaans" },
@@ -173,16 +303,18 @@ language_struct language_table[] = {
{ last_language_code, NULL, NULL }
};
+
+
/* @documentlanguage. Maybe we'll do something useful with this in the
future. For now, we just recognize it. */
void
cm_documentlanguage ()
{
language_code_type c;
- char *lang_arg;
+ char *lang_arg;
/* Read the line with the language code on it. */
- get_rest_of_line (1, &lang_arg);
+ get_rest_of_line (0, &lang_arg);
/* Linear search is fine these days. */
for (c = aa; c != last_language_code; c++)
@@ -203,11 +335,178 @@ cm_documentlanguage ()
-/* @documentencoding. Set global. */
+/* Search through the encoding table for the given character, returning
+ its equivalent. */
+
+static int
+cm_search_iso_map (html)
+ char *html;
+{
+ int i;
+ iso_map_type *iso = encoding_table[document_encoding_code].isotab;
+
+ /* If no conversion table for this encoding, quit. */
+ if (!iso)
+ return -1;
+
+ for (i = 0; i < ISO_MAP_SIZE; i++)
+ {
+ if (strcmp (html, iso[i].html) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+
+/* @documentencoding. Set the translation table. */
+
void
cm_documentencoding ()
{
- get_rest_of_line (1, &document_encoding);
+ encoding_code_type enc;
+ char *enc_arg;
+
+ get_rest_of_line (1, &enc_arg);
+
+ /* See if we have this encoding. */
+ for (enc = ISO_8859_1; enc != last_encoding_code; enc++)
+ {
+ if (strcasecmp (enc_arg, encoding_table[enc].ecname) == 0)
+ {
+ document_encoding_code = enc;
+ break;
+ }
+ }
+
+ /* If we didn't find this code, complain. */
+ if (enc == last_encoding_code)
+ warning (_("unrecogized encoding name `%s'"), enc_arg);
+
+ else if (encoding_table[document_encoding_code].isotab == NULL)
+ warning (_("sorry, encoding `%s' not supported"), enc_arg);
+
+ free (enc_arg);
+}
+
+
+/* If html or xml output, add HTML_STR to the output. If not html and
+ the user requested encoded output, add the real 8-bit character
+ corresponding to HTML_STR from the translation tables. Otherwise,
+ add INFO_STR. */
+
+void
+add_encoded_char (html_str, info_str)
+ char *html_str;
+ char *info_str;
+{
+ if (html || xml)
+ add_word_args ("&%s;", html_str);
+ else if (enable_encoding)
+ {
+ /* Look for HTML_STR in the current translation table. */
+ int rc = cm_search_iso_map (html_str);
+ if (rc >= 0)
+ /* We found it, add the real character. */
+ add_char (encoding_table[document_encoding_code].isotab[rc].bytecode);
+ else
+ { /* We didn't find it, that seems bad. */
+ warning (_("invalid encoded character `%s'"), html_str);
+ add_word (info_str);
+ }
+ }
+ else
+ add_word (info_str);
+}
+
+
+
+/* Output an accent for HTML or XML. */
+
+static void
+cm_accent_generic_html (arg, start, end, html_supported, single,
+ html_solo_standalone, html_solo)
+ int arg, start, end;
+ char *html_supported;
+ int single;
+ int html_solo_standalone;
+ char *html_solo;
+{
+ static int valid_html_accent; /* yikes */
+
+ if (arg == START)
+ { /* If HTML has good support for this character, use it. */
+ if (strchr (html_supported, curchar ()))
+ { /* Yes; start with an ampersand. The character itself
+ will be added later in read_command (makeinfo.c). */
+ valid_html_accent = 1;
+ add_char ('&');
+ }
+ else
+ {
+ valid_html_accent = 0;
+ if (html_solo_standalone)
+ { /* No special HTML support, so produce standalone char. */
+ add_word_args ("&%s;", html_solo);
+ }
+ else
+ /* If the html_solo does not exist as standalone character
+ (namely &circ; &grave; &tilde;), then we use
+ the single character version instead. */
+ add_char (single);
+ }
+ }
+ else if (arg == END)
+ { /* Only if we saw a valid_html_accent can we use the full
+ HTML accent (umlaut, grave ...). */
+ if (valid_html_accent)
+ {
+ add_word (html_solo);
+ add_char (';');
+ }
+ }
+}
+
+
+static void
+cm_accent_generic_no_headers (arg, start, end, single, html_solo)
+ int arg, start, end;
+ int single;
+ char *html_solo;
+{
+ if (arg == END)
+ {
+ if (no_encoding)
+ add_char (single);
+ else
+ {
+ int rc;
+ char *buffer = xmalloc (1 + strlen (html_solo) + 1);
+ buffer[0] = output_paragraph[end - 1];
+ buffer[1] = 0;
+ strcat (buffer, html_solo);
+
+ rc = cm_search_iso_map (buffer);
+ if (rc >= 0)
+ /* A little bit tricky ;-)
+ Here we replace the character which has
+ been inserted in read_command with
+ the value we have found in converting table
+ Does there exist a better way to do this? kama. */
+ output_paragraph[end - 1]
+ = encoding_table[document_encoding_code].isotab[rc].bytecode;
+ else
+ { /* If we didn't find a translation for this character,
+ put the single instead. E.g., &Xuml; does not exist so X&uml;
+ should be produced. */
+ warning (_("%s is an invalid ISO code, using %c"),
+ buffer, single);
+ add_char (single);
+ }
+
+ free (buffer);
+ }
+ }
}
@@ -219,6 +518,8 @@ void
cm_accent (arg)
int arg;
{
+ int old_escape_html = escape_html;
+ escape_html = 0;
if (arg == START)
{
/* Must come first to avoid ambiguity with overdot. */
@@ -228,7 +529,7 @@ cm_accent (arg)
else if (arg == END)
{
if (strcmp (command, "=") == 0) /* macron */
- add_word (html ? "&macr;" : "=");
+ add_word ((html || xml) ? "&macr;" : "=");
else if (strcmp (command, "H") == 0) /* Hungarian umlaut */
add_word ("''");
else if (strcmp (command, "dotaccent") == 0) /* overdot */
@@ -242,18 +543,19 @@ cm_accent (arg)
else if (strcmp (command, "ubaraccent") == 0) /* underbar */
add_char ('_');
else if (strcmp (command, "v") == 0) /* hacek/check */
- add_word (html ? "&lt;" : "<");
+ add_word ((html || xml) ? "&lt;" : "<");
}
+ escape_html = old_escape_html;
}
/* Common routine for the accent characters that have support in HTML.
If the character being accented is in the HTML_SUPPORTED set, then
produce &CHTML_SOLO;, for example, &Auml; for an A-umlaut. If not in
HTML_SUPPORTED, just produce &HTML_SOLO;X for the best we can do with
- at an X-umlaut. Finally, if not producing HTML, just use SINGLE, a
+ at an X-umlaut. If not producing HTML, just use SINGLE, a
character such as " which is the best plain text representation we
- can manage. If HTML_SOLO_STANDALONE is zero the given HTML_SOLO
- does not exist as valid standalone character in HTML. */
+ can manage. If HTML_SOLO_STANDALONE is nonzero the given HTML_SOLO
+ exists as valid standalone character in HTML, e.g., &uml;. */
static void
cm_accent_generic (arg, start, end, html_supported, single,
@@ -264,47 +566,19 @@ cm_accent_generic (arg, start, end, html_supported, single,
int html_solo_standalone;
char *html_solo;
{
- if (html)
- {
- static int valid_html_accent;
-
- if (arg == START)
- { /* If HTML has good support for this character, use it. */
- if (strchr (html_supported, curchar ()))
- { /* Yes; start with an ampersand. The character itself
- will be added later in read_command (makeinfo.c). */
- add_char ('&');
- valid_html_accent = 1;
- }
- else
- { /* No special HTML support, so produce standalone char. */
- valid_html_accent = 0;
- if (html_solo_standalone)
- {
- add_char ('&');
- add_word (html_solo);
- add_char (';');
- }
- else
- /* If the html_solo does not exist as standalone character
- (namely &circ; &grave; &tilde;), then we use
- the single character version instead. */
- add_char (single);
- }
- }
- else if (arg == END)
- { /* Only if we saw a valid_html_accent can we use the full
- HTML accent (umlaut, grave ...). */
- if (valid_html_accent)
- {
- add_word (html_solo);
- add_char (';');
- }
- }
- }
+ if (html || xml)
+ cm_accent_generic_html (arg, start, end, html_supported,
+ single, html_solo_standalone, html_solo);
+ else if (no_headers)
+ cm_accent_generic_no_headers (arg, start, end, single, html_solo);
else if (arg == END)
- { /* Not producing HTML, so just use the normal character. */
- add_char (single);
+ {
+ if (enable_encoding)
+ /* use 8-bit if available */
+ cm_accent_generic_no_headers (arg, start, end, single, html_solo);
+ else
+ /* use regular character */
+ add_char (single);
}
}
@@ -347,7 +621,7 @@ void
cm_accent_tilde (arg, start, end)
int arg, start, end;
{
- cm_accent_generic (arg, start, end, "AOano", '~', 0, "tilde");
+ cm_accent_generic (arg, start, end, "ANOano", '~', 0, "tilde");
}
@@ -356,6 +630,9 @@ cm_accent_tilde (arg, start, end)
void
cm_special_char (arg)
{
+ int old_escape_html = escape_html;
+ escape_html = 0;
+
if (arg == START)
{
if ((*command == 'L' || *command == 'l'
@@ -363,34 +640,37 @@ cm_special_char (arg)
&& command[1] == 0)
{ /* Lslash lslash Oslash oslash.
Lslash and lslash aren't supported in HTML. */
- if (html && (command[0] == 'O' || command[0] == 'o'))
- add_word_args ("&%cslash;", command[0]);
+ if ((html || xml) && command[0] == 'O')
+ add_encoded_char ("Oslash", "/O");
+ else if ((html || xml) && command[0] == 'o')
+ add_encoded_char ("oslash", "/o");
else
add_word_args ("/%c", command[0]);
}
else if (strcmp (command, "exclamdown") == 0)
- add_word (html ? "&iexcl;" : "!");
+ add_encoded_char ("iexcl", "!");
else if (strcmp (command, "pounds") == 0)
- add_word (html ? "&pound;" : "#");
+ add_encoded_char ("pound" , "#");
else if (strcmp (command, "questiondown") == 0)
- add_word (html ? "&iquest;" : "?");
+ add_encoded_char ("iquest", "?");
else if (strcmp (command, "AE") == 0)
- add_word (html ? "&AElig;" : command);
+ add_encoded_char ("AElig", command);
else if (strcmp (command, "ae") == 0)
- add_word (html ? "&aelig;" : command);
+ add_encoded_char ("aelig", command);
else if (strcmp (command, "OE") == 0)
- add_word (html ? "&#140;" : command);
+ add_word ("&#140;", command);
else if (strcmp (command, "oe") == 0)
- add_word (html ? "&#156;" : command);
+ add_word ("&#156;", command);
else if (strcmp (command, "AA") == 0)
- add_word (html ? "&Aring;" : command);
+ add_encoded_char ("Aring", command);
else if (strcmp (command, "aa") == 0)
- add_word (html ? "&aring;" : command);
+ add_encoded_char ("aring", command);
else if (strcmp (command, "ss") == 0)
- add_word (html ? "&szlig;" : command);
+ add_encoded_char ("szlig", command);
else
line_error ("cm_special_char internal error: command=@%s", command);
}
+ escape_html = old_escape_html;
}
/* Dotless i or j. */
@@ -400,6 +680,7 @@ cm_dotless (arg, start, end)
{
if (arg == END)
{
+ xml_no_para --;
if (output_paragraph[start] != 'i' && output_paragraph[start] != 'j')
/* This error message isn't perfect if the argument is multiple
characters, but it doesn't seem worth getting right. */
@@ -412,4 +693,6 @@ cm_dotless (arg, start, end)
/* We've already inserted the `i' or `j', so nothing to do. */
}
+ else
+ xml_no_para ++;
}