Debian Codegraph @

src/lat1txte.c

raw symbols SCIP
1 /* Conversion of files between different charsets and surfaces.
2 Copyright © 1990-2018 Free Software Foundation, Inc.
3 Contributed by François Pinard <[email protected]>, 1988.
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 const char *const translation_table[128] =
25 {
26 NULL, /* 128 */
27 NULL, /* 129 */
28 NULL, /* 130 */
29 NULL, /* 131 */
30 NULL, /* 132 */
31 NULL, /* 133 */
32 NULL, /* 134 */
33 NULL, /* 135 */
34 NULL, /* 136 */
35 NULL, /* 137 */
36 NULL, /* 138 */
37 NULL, /* 139 */
38 NULL, /* 140 */
39 NULL, /* 141 */
40 NULL, /* 142 */
41 NULL, /* 143 */
42 NULL, /* 144 */
43 NULL, /* 145 */
44 NULL, /* 146 */
45 NULL, /* 147 */
46 NULL, /* 148 */
47 NULL, /* 149 */
48 NULL, /* 150 */
49 NULL, /* 151 */
50 NULL, /* 152 */
51 NULL, /* 153 */
52 NULL, /* 154 */
53 NULL, /* 155 */
54 NULL, /* 156 */
55 NULL, /* 157 */
56 NULL, /* 158 */
57 NULL, /* 159 */
58
59 " ", /* 160 no-break space */
60 NULL, /* 161 inverted exclamation mark */
61 NULL, /* 162 cent sign */
62 NULL, /* 163 pound sign */
63 NULL, /* 164 currency sign */
64 NULL, /* 165 yen sign */
65 NULL, /* 166 broken bar */
66 NULL, /* 167 paragraph sign, section sign */
67 NULL, /* 168 diaeresis */
68 NULL, /* 169 copyright sign */
69 NULL, /* 170 feminine ordinal indicator */
70 "``", /* 171 left angle quotation mark */
71 NULL, /* 172 not sign */
72 NULL, /* 173 soft hyphen */
73 NULL, /* 174 registered trade mark sign */
74 NULL, /* 175 macron */
75 NULL, /* 176 degree sign */
76 NULL, /* 177 plus-minus sign */
77 NULL, /* 178 superscript two */
78 NULL, /* 179 superscript three */
79 NULL, /* 180 acute accent */
80 NULL, /* 181 small greek mu, micro sign */
81 NULL, /* 182 pilcrow sign */
82 NULL, /* 183 middle dot */
83 NULL, /* 184 cedilla */
84 NULL, /* 185 superscript one */
85 NULL, /* 186 masculine ordinal indicator */
86 "''", /* 187 right angle quotation mark */
87 NULL, /* 188 vulgar fraction one quarter */
88 NULL, /* 189 vulgar fraction one half */
89 NULL, /* 190 vulgar fraction three quarters */
90 NULL, /* 191 inverted question mark */
91 "A`", /* 192 capital A with grave accent */
92 NULL, /* 193 capital A with acute accent */
93 "A^", /* 194 capital A with circumflex accent */
94 NULL, /* 195 capital A with tilde */
95 "A\"", /* 196 capital A diaeresis */
96 NULL, /* 197 capital A with ring above */
97 NULL, /* 198 capital diphthong A with E */
98 "C,", /* 199 capital C with cedilla */
99 "E`", /* 200 capital E with grave accent */
100 "E\'", /* 201 capital E with acute accent */
101 "E^", /* 202 capital E with circumflex accent */
102 "E\"", /* 203 capital E with diaeresis */
103 NULL, /* 204 capital I with grave accent */
104 NULL, /* 205 capital I with acute accent */
105 "I^", /* 206 capital I with circumflex accent */
106 "I\"", /* 207 capital I with diaeresis */
107 NULL, /* 208 capital icelandic ETH */
108 NULL, /* 209 capital N with tilde */
109 "O`", /* 210 capital O with grave accent */
110 NULL, /* 211 capital O with acute accent */
111 "O^", /* 212 capital O with circumflex accent */
112 NULL, /* 213 capital O with tilde */
113 "O\"", /* 214 capital O with diaeresis */
114 NULL, /* 215 multiplication sign */
115 NULL, /* 216 capital O with oblique stroke */
116 "U`", /* 217 capital U with grave accent */
117 NULL, /* 218 capital U with acute accent */
118 "U^", /* 219 capital U with circumflex accent */
119 "U\"", /* 220 capital U with diaeresis */
120 NULL, /* 221 capital Y with acute accent */
121 NULL, /* 222 capital icelandic THORN */
122 NULL, /* 223 small german sharp s */
123 "a`", /* 224 small a with grave accent */
124 NULL, /* 225 small a with acute accent */
125 "a^", /* 226 small a with circumflex accent */
126 NULL, /* 227 small a with tilde */
127 "a\"", /* 228 small a with diaeresis */
128 NULL, /* 229 small a with ring above */
129 NULL, /* 230 small diphthong a with e */
130 "c,", /* 231 small c with cedilla */
131 "e`", /* 232 small e with grave accent */
132 "e\'", /* 233 small e with acute accent */
133 "e^", /* 234 small e with circumflex accent */
134 "e\"", /* 235 small e with diaeresis */
135 NULL, /* 236 small i with grave accent */
136 NULL, /* 237 small i with acute accent */
137 "i^", /* 238 small i with circumflex accent */
138 "i\"", /* 239 small i with diaeresis */
139 NULL, /* 240 small icelandic eth */
140 NULL, /* 241 small n with tilde */
141 "o`", /* 242 small o with grave accent */
142 NULL, /* 243 small o with acute accent */
143 "o^", /* 244 small o with circumflex accent */
144 NULL, /* 245 small o with tilde */
145 "o\"", /* 246 small o with diaeresis */
146 NULL, /* 247 division sign */
147 NULL, /* 248 small o with oblique stroke */
148 "u`", /* 249 small u with grave accent */
149 NULL, /* 250 small u with acute accent */
150 "u^", /* 251 small u with circumflex accent */
151 "u\"", /* 252 small u with diaeresis */
152 NULL, /* 253 small y with acute accent */
153 NULL, /* 254 small icelandic thorn */
154 NULL, /* 255 small y with diaeresis */
155 };
156
157 static bool
158 init_latin1_texte (RECODE_STEP step,
159 const struct recode_request *request,
160 RECODE_CONST_OPTION_LIST before_options,
161 RECODE_CONST_OPTION_LIST after_options)
162 {
163 RECODE_OUTER outer = request->outer;
164
165 unsigned rewritten; /* number of rewritten translations */
166 const char **table; /* allocated structure, including pool */
167 char *pool; /* cursor in character pool */
168 unsigned counter; /* general purpose counter */
169
170 if (before_options || after_options)
171 return false;
172
173 /* The algorithm for proper processing of -c option depends on the fact
174 that quotes to be changed in colons are exactly those, in strings
175 from translation_table, which are in second position while the
176 string is two characters in length. This is sufficient for now. */
177
178 rewritten = 0;
179 if (request->diaeresis_char != '"')
180 for (counter = 128; counter < 256; counter++)
181 if (translation_table[counter - 128]
182 && translation_table[counter - 128][1] == '"'
183 && translation_table[counter - 128][2] == NUL)
184 rewritten++;
185
186 if (!ALLOC_SIZE (table, sizeof (char *) * 256 + 2 * 128 + 3 * rewritten,
187 const char *))
188 return false;
189 pool = (char *) (table + 256);
190
191 for (counter = 0; counter < 128; counter++)
192 {
193 table[counter] = pool;
194 *pool++ = counter;
195 *pool++ = NUL;
196 }
197
198 for (; counter < 256; counter++)
199 if (request->diaeresis_char != '"'
200 && translation_table[counter - 128]
201 && translation_table[counter - 128][1] == '"'
202 && translation_table[counter - 128][2] == NUL)
203 {
204 table[counter] = pool;
205 *pool++ = translation_table[counter - 128][0];
206 *pool++ = request->diaeresis_char;
207 *pool++ = NUL;
208 }
209 else
210 table[counter] = translation_table[counter - 128];
211
212 step->step_type = RECODE_BYTE_TO_STRING;
213 step->step_table = table;
214 step->step_table_term_routine = free;
215 return true;
216 }
217
218 bool
219 module_latin1_texte (RECODE_OUTER outer)
220 {
221 return
222 recode_declare_single (outer, "Latin-1", "Texte",
223 outer->quality_byte_to_variable,
224 init_latin1_texte, recode_transform_byte_to_variable)
225 && recode_declare_alias (outer, "txte", "Texte");
226 }
227
228 void
229 delmodule_latin1_texte (_GL_UNUSED RECODE_OUTER outer)
230 {
231 }