driver: don't list specials that was appeared in path
[k8muffin.git] / src / translit.c
blobad5560caa7e9c8710fc848405604b62520ec5080
1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program 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 of the License, or
7 * (at your option) any later version.
9 * This program 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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "translit.h"
19 #include <ctype.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <string.h>
25 static const struct {
26 uint8_t code;
27 const char *ch;
28 } atrans[74] = {
29 {0xE1, "A"}, //á
30 {0xE0, "YU"}, //à
31 {0xE3, "C"}, //ã
32 {0xE2, "B"}, //â
33 {0xE5, "E"}, //å
34 {0xE4, "D"}, //ä
35 {0xE7, "G"}, //ç
36 {0xE6, "F"}, //æ
37 {0xE9, "I"}, //é
38 {0xE8, "H"}, //è
39 {0xEB, "K"}, //ë
40 {0xEA, "IJ"}, //ê
41 {0xED, "M"}, //í
42 {0xEC, "L"}, //ì
43 {0xEF, "O"}, //ï
44 {0xEE, "N"}, //î
45 {0xF1, "YA"}, //ñ
46 {0xF0, "P"}, //ð
47 {0xF3, "S"}, //ó
48 {0xF2, "R"}, //ò
49 {0xF5, "U"}, //õ
50 {0xF4, "T"}, //ô
51 {0xF7, "V"}, //÷
52 {0xF6, "J"}, //ö
53 {0xF9, "Y"}, //ù
54 {0xF8, ""}, //ø
55 {0xFB, "SH"}, //û
56 {0xFA, "Z"}, //ú
57 {0xFD, "SCH"}, //ý
58 {0xFC, "E"}, //ü
59 {0xFF, ""}, //ÿ
60 {0xFE, "CH"}, //þ
61 {0xA3, "yo"}, //£
62 {0xA4, "ye"}, //¤
63 {0xA7, "yj"}, //§
64 {0xA6, "i"}, //¦
65 {0xAD, "g"}, //­
66 {0xB3, "YO"}, //³
67 {0xB4, "YE"}, //´
68 {0xB7, "YJ"}, //·
69 {0xB6, "I"}, //¶
70 {0xBF, "(c)"}, //¿
71 {0xC1, "a"}, //Á
72 {0xC0, "yu"}, //À
73 {0xC3, "c"}, //Ã
74 {0xC2, "b"}, //Â
75 {0xC5, "e"}, //Å
76 {0xC4, "d"}, //Ä
77 {0xC7, "g"}, //Ç
78 {0xC6, "f"}, //Æ
79 {0xC9, "i"}, //É
80 {0xC8, "h"}, //È
81 {0xCB, "k"}, //Ë
82 {0xCA, "ij"}, //Ê
83 {0xCD, "m"}, //Í
84 {0xCC, "l"}, //Ì
85 {0xCF, "o"}, //Ï
86 {0xCE, "n"}, //Î
87 {0xD1, "ya"}, //Ñ
88 {0xD0, "p"}, //Ð
89 {0xD3, "s"}, //Ó
90 {0xD2, "r"}, //Ò
91 {0xD5, "u"}, //Õ
92 {0xD4, "t"}, //Ô
93 {0xD7, "v"}, //×
94 {0xD6, "j"}, //Ö
95 {0xD9, "y"}, //Ù
96 {0xD8, ""}, //Ø
97 {0xDB, "sh"}, //Û
98 {0xDA, "z"}, //Ú
99 {0xDD, "sch"}, //Ý
100 {0xDC, "e"}, //Ü
101 {0xDF, ""}, //ß
102 {0xDE, "ch"}, //Þ
106 static inline const char *findTRC (char c) {
107 uint8_t cc = c&0xff;
108 for (size_t f = 0; f < sizeof(atrans)/sizeof(atrans[0]); ++f) {
109 if (atrans[f].code == cc) return atrans[f].ch;
111 return NULL;
115 char *translitstr (const char *src) {
116 char *res, *dest;
117 if (src == NULL) src = "";
118 res = dest = calloc(strlen(src)*4+2, sizeof(char));
119 for (int f = 0; f < strlen(src); ++f) {
120 const char *ch = findTRC(src[f]);
121 if (ch != NULL) {
122 for (; *ch; ++ch) *dest++ = le2lower(*ch);
123 } else {
124 *dest++ = le2lower(src[f]);
127 *dest = '\0';
128 return res;