Debian Codegraph @

src/mule.c

raw symbols SCIP
1 /* Conversion of files between different charsets and surfaces.
2 Copyright © 1997-2018 Free Software Foundation, Inc.
3 Contributed by François Pinard <[email protected]>, 1997.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 3 of the
8 License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the Recode Library; see the file `COPYING.LIB'.
17 If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21 #include "common.h"
22 #include "decsteps.h"
23
24 static bool
25 transform_latin_mule (RECODE_SUBTASK subtask,
26 unsigned prefix)
27 {
28 int character;
29
30 while (character = recode_get_byte (subtask), character != EOF)
31 {
32 if (!IS_ASCII (character))
33 recode_put_byte (prefix, subtask);
34 recode_put_byte (character, subtask);
35 }
36 SUBTASK_RETURN (subtask);
37 }
38
39 static bool
40 transform_mule_latin (RECODE_SUBTASK subtask,
41 unsigned prefix)
42 {
43 int character;
44
45 while (character = recode_get_byte (subtask), character != EOF)
46 if (IS_ASCII (character))
47 recode_put_byte (character, subtask);
48 else if ((character & BIT_MASK (8)) == prefix)
49 {
50 character = recode_get_byte (subtask);
51
52 while ((character & BIT_MASK (8)) == prefix)
53 {
54 /* This happens in practice, sometimes, that Emacs goes a bit
55 berzerk and generates strings of prefix characters. Remove
56 all succeeding prefixes in a row. This is irreversible. */
57 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
58 character = recode_get_byte (subtask);
59 }
60
61 if (character == EOF)
62 {
63 RETURN_IF_NOGO (RECODE_INVALID_INPUT, subtask);
64 break;
65 }
66
67 if (IS_ASCII (character))
68 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
69 recode_put_byte (character, subtask);
70 }
71 else
72 RETURN_IF_NOGO (RECODE_UNTRANSLATABLE, subtask);
73
74 SUBTASK_RETURN (subtask);
75 }
76
77 #define TRANSFORM_LATIN(To_mule, From_mule, Prefix) \
78 \
79 static bool \
80 To_mule (RECODE_SUBTASK subtask) \
81 { \
82 return transform_latin_mule (subtask, Prefix); \
83 } \
84 \
85 static bool \
86 From_mule (RECODE_SUBTASK subtask) \
87 { \
88 return transform_mule_latin (subtask, Prefix); \
89 }
90
91 TRANSFORM_LATIN (transform_latin1_mule, transform_mule_latin1, 129)
92 TRANSFORM_LATIN (transform_latin2_mule, transform_mule_latin2, 130)
93
94 /*-------------------.
95 | Register methods. |
96 `-------------------*/
97
98 bool
99 module_mule (RECODE_OUTER outer)
100 {
101 return
102 recode_declare_single (outer, "ISO-8859-1", "Mule",
103 outer->quality_byte_to_variable,
104 NULL, transform_latin1_mule)
105 && recode_declare_single (outer, "Mule", "ISO-8859-1",
106 outer->quality_variable_to_byte,
107 NULL, transform_mule_latin1)
108 && recode_declare_single (outer, "ISO-8859-2", "Mule",
109 outer->quality_byte_to_variable,
110 NULL, transform_latin2_mule)
111 && recode_declare_single (outer, "Mule", "ISO-8859-2",
112 outer->quality_variable_to_byte,
113 NULL, transform_mule_latin2);
114 }
115
116 void
117 delmodule_mule (_GL_UNUSED RECODE_OUTER outer)
118 {
119 }