9 #include "support/filetools.h"
10 #include "support/lstrings.h"
11 #include "tex-strings.h"
14 #include "trans_mgr.h"
39 void Trans::InsertException(KmodException & exclist, char c,
40 string const & data, bool flag, tex_accent accent)
47 exclist.insert(exclist.begin(), p);
49 // exclist.push_back(p);
53 void Trans::FreeException(KmodException & exclist)
59 void Trans::FreeKeymap()
66 bool Trans::IsDefined() const
68 return !name_.empty();
72 string const & Trans::GetName() const
87 struct keyword_item kmapTags[K_LAST - 1] = {
95 tex_accent getkeymod(string const &);
98 void Trans::AddDeadkey(tex_accent accent, string const & keys)
103 kmod_list_[accent] = tmp;
105 for (string::size_type i = 0; i < keys.length(); ++i) {
109 keymap_[keys[i]] = tmp;
114 int Trans::Load(LyXLex & lex)
118 while (lex.isOK() && !error) {
122 if (lyxerr.debugging(Debug::KBMAP))
123 lyxerr << "KMOD:\t" << lex.text() << endl;
124 if (lex.next(true)) {
125 if (lyxerr.debugging(Debug::KBMAP))
126 lyxerr << "key\t`" << lex.text()
131 string const keys = lex.getString();
133 if (lex.next(true)) {
134 if (lyxerr.debugging(Debug::KBMAP))
135 lyxerr << "accent\t`" << lex.text()
140 tex_accent accent = getkeymod(lex.getString());
142 if (accent == TEX_NOACCENT)
146 //#warning This code should be removed...
147 // But we need to fix up all the kmap files first
148 // so that this field is not present anymore.
149 if (lex.next(true)) {
150 if (lyxerr.debugging(Debug::KBMAP))
151 lyxerr << "allowed\t`" << lex.text()
156 /* string const allowed = lex.getString(); */
157 AddDeadkey(accent, keys /*, allowed*/);
159 AddDeadkey(accent, keys);
166 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
167 if (lex.next(true)) {
169 lyxerr[Debug::KBMAP] << str << endl;
173 tex_accent accent_1 = getkeymod(str);
174 if (accent_1 == TEX_NOACCENT) return -1;
176 if (lex.next(true)) {
178 lyxerr[Debug::KBMAP] << str << endl;
182 tex_accent accent_2= getkeymod(str);
183 if (accent_2 == TEX_NOACCENT) return -1;
185 map<int, KmodInfo>::iterator it1 =
186 kmod_list_.find(accent_1);
187 map<int, KmodInfo>::iterator it2 =
188 kmod_list_.find(accent_2);
189 if (it1 == kmod_list_.end()
190 || it2 == kmod_list_.end()) {
194 // Find what key accent_2 is on - should
195 // check about accent_1 also
196 map<int, string>::iterator it = keymap_.begin();
197 map<int, string>::iterator end = keymap_.end();
198 for (; it != end; ++it) {
199 if (!it->second.empty()
200 && it->second[0] == 0
201 && it->second[1] == accent_2)
206 allowed = lex.getString();
207 lyxerr[Debug::KBMAP] << "allowed: "
213 InsertException(kmod_list_[accent_1].exception_list,
214 static_cast<char>(it->first), allowed,
219 unsigned char key_from;
221 if (lyxerr.debugging(Debug::KBMAP))
222 lyxerr << "KMAP:\t" << lex.text() << endl;
223 if (lex.next(true)) {
224 key_from = lex.text()[0];
225 if (lyxerr.debugging(Debug::KBMAP))
226 lyxerr << "\t`" << lex.text() << "'"
231 if (lex.next(true)) {
232 string string_to = lex.text();
233 keymap_[key_from] = string_to;
234 if (lyxerr.debugging(Debug::KBMAP))
235 lyxerr << "\t`" << string_to << "'"
247 if (lyxerr.debugging(Debug::KBMAP))
248 lyxerr << "KXMOD:\t" << lex.text() << endl;
249 if (lex.next(true)) {
250 if (lyxerr.debugging(Debug::KBMAP))
251 lyxerr << "\t`" << lex.text() << "'"
253 accent = getkeymod(lex.getString());
257 if (lex.next(true)) {
258 if (lyxerr.debugging(Debug::KBMAP))
259 lyxerr << "\t`" << lex.text() << "'"
265 if (lex.next(true)) {
266 if (lyxerr.debugging(Debug::KBMAP))
267 lyxerr << "\t`" << lex.text() << "'"
273 InsertException(kmod_list_[accent].exception_list,
277 case LyXLex::LEX_FEOF:
278 lyxerr[Debug::PARSER] << "End of parsing" << endl;
281 lex.printError("ParseKeymapFile: "
282 "Unknown tag: `$$Token'");
290 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
292 map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
293 if (cit != kmod_list_.end()) {
301 string const Trans::process(char c, TransManager & k)
303 string const t = Match(static_cast<unsigned char>(c));
305 if (t.empty() && c != 0) {
306 return k.normalkey(c);
307 } else if (!t.empty() && t[0] != char(0)) {
308 //return k.normalkey(c);
312 kmod_list_[static_cast<tex_accent>(t[1])]);
317 int Trans::Load(string const & language)
319 string const filename = LibFileSearch("kbd", language, "kmap");
320 if (filename.empty())
324 LyXLex lex(kmapTags, K_LAST-1);
325 lex.setFile(filename);
327 int const res = Load(lex);
338 tex_accent getkeymod(string const & p)
339 /* return modifier - decoded from p and update p */
341 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
342 if (lyxerr.debugging(Debug::KBMAP))
343 lyxerr << "p = " << p
344 << ", lyx_accent_table[" << i
345 << "].name = `" << lyx_accent_table[i].name
348 if (lyx_accent_table[i].name
349 && contains(p, lyx_accent_table[i].name)) {
350 lyxerr[Debug::KBMAP] << "Found it!" << endl;
351 return static_cast<tex_accent>(i);