Debian Codegraph @

modules/gcide/grk.c

raw
1 /* Greek transliteration for GCIDE. This file is part of GNU Dico.
2 Copyright (C) 2012-2024 Sergey Poznyakoff
3
4 GNU Dico is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Dico is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <stdlib.h>
19 #include "gcide.h"
20
21 struct xlit {
22 char *seq;
23 char *grk;
24 };
25
26 /* NOTE: 1. According to WEBFONT.ASC, "[r]oman j, v, u are unused".
27 Nevertheless, "u" is used in place of "y" (meaning υ) so often
28 that I decided to support both forms.
29 2. It is not clear whether trema (:) should appear after accents
30 or vice-versa. The table below supports both forms.
31 */
32
33 static struct xlit xlit[] = {
34 { "'A", "Ἀ" },
35 { "'A,", "ᾈ" },
36 { "'A^", "Ἆ" },
37 { "'A`", "Ἄ" },
38 { "'A~", "Ἂ" },
39 { "'A~,", "ᾊ" },
40 { "'A~,", "ᾌ" },
41 { "'A~,", "ᾎ" },
42 { "'E", "Ἐ" },
43 { "'E`", "Ἔ" },
44 { "'E~", "Ἒ" },
45 { "'H", "Ἠ" },
46 { "'H,", "ᾘ" },
47 { "'H^", "Ἦ" },
48 { "'H`", "Ἤ" },
49 { "'H~", "Ἢ" },
50 { "'H~,", "ᾚ" },
51 { "'H~,", "ᾜ" },
52 { "'H~,", "ᾞ" },
53 { "'I", "Ἰ" },
54 { "'I^", "Ἶ" },
55 { "'I`", "Ἴ" },
56 { "'I~", "Ἲ" },
57 { "'O", "Ὀ" },
58 { "'O`", "Ὄ" },
59 { "'O~", "Ὂ" },
60 { "'W", "Ὠ" },
61 { "'W,", "ᾨ" },
62 { "'W^", "Ὦ" },
63 { "'W`", "Ὤ" },
64 { "'W~", "Ὢ" },
65 { "'W~,", "ᾪ" },
66 { "'W~,", "ᾬ" },
67 { "'W~,", "ᾮ" },
68 { "'`O", "Ὄ" },
69 { "'a", "ἀ" },
70 { "'a,", "ᾀ" },
71 { "'a^", "ἆ" },
72 { "'a^,", "ᾆ" },
73 { "'a`", "ἄ" },
74 { "'a`,", "ᾄ" },
75 { "'a~", "ἂ" },
76 { "'a~,", "ᾂ" },
77 { "'e", "ἐ" },
78 { "'e`", "ἔ" },
79 { "'e~", "ἒ" },
80 { "'h", "ἠ" },
81 { "'h,", "ᾐ" },
82 { "'h^", "ἦ" },
83 { "'h^,", "ᾖ" },
84 { "'h`", "῎η" },
85 { "'h`,", "ᾔ" },
86 { "'h~", "ἢ" },
87 { "'h~,", "ᾒ" },
88 { "'i", "ἰ" },
89 { "'i^", "ἶ" },
90 { "'i`", "ἴ" },
91 { "'i~", "ἲ" },
92 { "'o", "ὀ" },
93 { "'o`", "ὄ" },
94 { "'o~", "ὂ" },
95 { "'r", "ῤ" },
96 { "'u", "ὐ" },
97 { "'u^", "ὖ" },
98 { "'u`", "ὔ" },
99 { "'u~", "ὒ" },
100 { "'w", "ὠ" },
101 { "'w,", "ᾠ" },
102 { "'w^", "ὦ" },
103 { "'w^,", "ᾦ" },
104 { "'w`", "ὤ" },
105 { "'w`,", "ᾤ" },
106 { "'w~", "ὢ" },
107 { "'w~,", "ᾢ" },
108 { "'y", "ὐ" },
109 { "'y^", "ὖ" },
110 { "'y`", "ὔ" },
111 { "'y~", "ὒ" },
112 { "A", "Α" },
113 { "A", "Α" },
114 { "A,", "ᾼ" },
115 { "A`", "Ά" },
116 { "A~", "Ἁ" },
117 { "B", "Β" },
118 { "CH", "Χ" },
119 { "Ch", "Χ" },
120 { "D", "Δ" },
121 { "E", "Ε" },
122 { "E", "Ε" },
123 { "E`", "Έ" },
124 { "E~", "Ἑ" },
125 { "F", "Φ" },
126 { "G", "Γ" },
127 { "H", "Η" },
128 { "H", "Η" },
129 { "H,", "ῌ" },
130 { "H`", "Ή" },
131 { "H~", "Ἡ" },
132 { "I", "Ι" },
133 { "I", "Ι" },
134 { "I`", "Ί" },
135 { "I~", "Ἱ" },
136 { "K", "Κ" },
137 { "L", "Λ" },
138 { "M", "Μ" },
139 { "N", "Ν" },
140 { "O", "Ο" },
141 { "O", "Ο" },
142 { "O`", "Ό" },
143 { "O~", "Ὁ" },
144 { "P", "Π" },
145 { "PS", "Ψ" },
146 { "Ps", "Ψ" },
147 { "Q", "Θ" },
148 { "R", "Ρ" },
149 { "S", "Σ" },
150 { "T", "Τ" },
151 { "U", "Υ" },
152 { "U", "Υ" },
153 { "U`", "Ύ" },
154 { "U~", "Ὑ" },
155 { "W", "Ω" },
156 { "W", "Ω" },
157 { "W,", "ῼ" },
158 { "W`", "Ώ" },
159 { "W~", "Ὡ" },
160 { "X", "Ξ" },
161 { "Y", "Υ" },
162 { "Y", "Υ" },
163 { "Y`", "Ύ" },
164 { "Y~", "Ὑ" },
165 { "Z", "Ζ" },
166 { "\"A", "Ὰ" },
167 { "\"A,", "ᾉ" },
168 { "\"A^", "Ἇ" },
169 { "\"A^,", "ᾏ" },
170 { "\"A`", "Ἅ" },
171 { "\"A`,", "ᾍ" },
172 { "\"A~", "Ἃ" },
173 { "\"A~,", "ᾋ" },
174 { "\"E", "Ὲ" },
175 { "\"E`", "Ἕ" },
176 { "\"E~", "Ἓ" },
177 { "\"H", "Ὴ" },
178 { "\"H,", "ᾙ" },
179 { "\"H^", "Ἧ" },
180 { "\"H^,", "ᾟ" },
181 { "\"H`", "Ἥ" },
182 { "\"H`,", "ᾝ" },
183 { "\"H~", "Ἣ" },
184 { "\"H~,", "ᾛ" },
185 { "\"I", "Ὶ" },
186 { "\"I^", "Ἷ" },
187 { "\"I`", "Ἵ" },
188 { "\"I~", "Ἳ" },
189 { "\"O", "Ὸ" },
190 { "\"O`", "Ὅ" },
191 { "\"O~", "Ὃ" },
192 { "\"R", "Ῥ" },
193 { "\"U", "Ὺ" },
194 { "\"U^", "Ὗ" },
195 { "\"U`", "Ὕ" },
196 { "\"U~", "Ὓ" },
197 { "\"W", "Ὼ" },
198 { "\"W,", "ᾩ" },
199 { "\"W^", "Ὧ" },
200 { "\"W^,", "ᾯ" },
201 { "\"W`", "Ὥ" },
202 { "\"W`,", "ᾭ" },
203 { "\"W~", "Ὣ" },
204 { "\"W~,", "ᾫ" },
205 { "\"Y", "Ὺ" },
206 { "\"Y^", "Ὗ" },
207 { "\"Y`", "Ὕ" },
208 { "\"Y~", "Ὓ" },
209 { "\"a", "ἁ" },
210 { "\"a,", "ᾁ" },
211 { "\"a^", "ἇ" },
212 { "\"a^,", "ᾇ" },
213 { "\"a`", "ἄ" },
214 { "\"a`", "ἅ" },
215 { "\"a`,", "ᾅ" },
216 { "\"a~", "ἂ" },
217 { "\"a~", "ἃ" },
218 { "\"a~,", "ᾃ" },
219 { "\"e", "ἑ" },
220 { "\"e`", "ἕ" },
221 { "\"e~", "ἓ" },
222 { "\"h", "ἡ" },
223 { "\"h,", "ᾑ" },
224 { "\"h^", "ἧ" },
225 { "\"h^,", "ᾗ" },
226 { "\"h`", "ἥ" },
227 { "\"h`,", "ᾕ" },
228 { "\"h~", "ἣ" },
229 { "\"h~,", "ᾓ" },
230 { "\"i", "ἱ" },
231 { "\"i^", "ἷ" },
232 { "\"i`", "ἵ" },
233 { "\"i~", "ἳ" },
234 { "\"o", "ὁ" },
235 { "\"o`", "ὅ" },
236 { "\"o~", "ὃ" },
237 { "\"r", "ῥ" },
238 { "\"u", "ὑ" },
239 { "\"u^", "ὗ" },
240 { "\"u`", "ὕ" },
241 { "\"u~", "ὓ" },
242 { "\"w", "ὡ" },
243 { "\"w,", "ᾡ" },
244 { "\"w^", "ὣ" },
245 { "\"w^", "ὧ" },
246 { "\"w^,", "ᾧ" },
247 { "\"w`", "ὥ" },
248 { "\"w`,", "ᾥ" },
249 { "\"w~,", "ᾣ" },
250 { "\"y", "ὑ" },
251 { "\"y^", "ὗ" },
252 { "\"y`", "ὕ" },
253 { "\"y~", "ὓ" },
254 { "a", "α" },
255 { "a,", "ᾳ" },
256 { "a^", "ᾶ" },
257 { "a^,", "ᾷ" },
258 { "a`", "ά" },
259 { "a`,", "ᾴ" },
260 { "a~", "ὰ" },
261 { "a~,", "ᾲ" },
262 { "b", "β" },
263 { "ch", "χ" },
264 { "d", "δ" },
265 { "e", "ε" },
266 { "e`", "έ" },
267 { "e~", "ὲ" },
268 { "f", "φ" },
269 { "g", "γ" },
270 { "h", "η" },
271 { "h,", "ῃ" },
272 { "h^", "ῆ" },
273 { "h^,", "ῇ" },
274 { "h`", "ή" },
275 { "h`,", "ῄ" },
276 { "h~", "ὴ" },
277 { "h~,", "ῂ" },
278 { "i", "ι" },
279 { "i:", "ϊ" },
280 { "i:^", "ῗ" },
281 { "i:~", "ῒ" },
282 { "i:`", "ΐ" },
283 { "i^", "ῖ" },
284 { "i^:", "ῗ" },
285 { "i`", "ί" },
286 { "i`:", "ῒ" },
287 { "i`:", "ΐ" },
288 { "i~", "ὶ" },
289 { "k", "κ" },
290 { "l", "λ" },
291 { "m", "μ" },
292 { "n", "ν" },
293 { "o", "ο" },
294 { "o`", "ό" },
295 { "o~", "ὸ" },
296 { "p", "π" },
297 { "ps", "ψ" },
298 { "q", "θ" },
299 { "r", "ρ" },
300 { "s", "σ" },
301 { "t", "τ" },
302 { "u", "υ" },
303 { "u:", "ϋ" },
304 { "u:^", "ῧ" },
305 { "u:`", "ΰ" },
306 { "u:~", "ῢ" },
307 { "u^", "ῦ" },
308 { "u^:", "ῧ" },
309 { "u`", "ύ" },
310 { "u`:", "ΰ" },
311 { "u~", "ὺ" },
312 { "u~:", "ῢ" },
313 { "w", "ω" },
314 { "w,", "ῳ" },
315 { "w^", "ῶ" },
316 { "w^,", "ῷ" },
317 { "w`", "ώ" },
318 { "w`,", "ῴ" },
319 { "w~", "ὼ" },
320 { "w~,", "ῲ" },
321 { "x", "ξ" },
322 { "y", "υ" },
323 { "y:", "ϋ" },
324 { "y:^", "ῧ" },
325 { "y:`", "ΰ" },
326 { "y:~", "ῢ" },
327 { "y^", "ῦ" },
328 { "y^:", "ῧ" },
329 { "y`", "ύ" },
330 { "y`:", "ΰ" },
331 { "y~", "ὺ" },
332 { "y~:", "ῢ" },
333 { "z", "ζ" },
334 { NULL }
335 };
336
337 const char *
338 gcide_grk_to_utf8(const char *input, size_t *prd)
339 {
340 struct xlit *p, *found_xlit = NULL;
341 size_t found_len = 0;
342
343 if (input[0] == 's' && input[1] == 0) {
344 *prd = 1;
345 return "ς";
346 }
347 for (p = xlit; p->seq; p++) {
348 int i;
349
350 for (i = 0; input[i]; i++)
351 if (input[i] != p->seq[i])
352 break;
353
354 if (p->seq[i]) {
355 if (found_len && i == 0)
356 break;
357 continue;
358 }
359
360 if (i > found_len) {
361 found_len = i;
362 found_xlit = p;
363 }
364 }
365
366 if (found_len) {
367 *prd = found_len;
368 return found_xlit->grk;
369 }
370
371 return NULL;
372 }