4 #pragma implementation "trans.h"
9 #include "support/filetools.h"
10 #include "tex-strings.h"
13 #include "trans_mgr.h"
26 bool DefaultTrans::init_ = false;
29 DefaultTrans::DefaultTrans()
38 string const DefaultTrans::process(char c, TransManager & k)
43 return k.normalkey(c, dummy);
51 for(int i = 0; i < TEX_MAX_ACCENT + 1; ++i)
62 void Trans::InsertException(Trans::keyexc & exclist, char c,
63 string const & data, bool flag, tex_accent accent)
65 keyexc p = new Keyexc;
77 void Trans::FreeException(Trans::keyexc & exclist)
79 Trans::keyexc p = exclist;
88 void Trans::FreeKeymap()
90 for(int i = 0; i < 256; ++i)
91 if (!keymap_[i].empty()) {
94 for(int i = 0; i < TEX_MAX_ACCENT + 1; ++i)
96 FreeException(kmod_list_[i]->exception_list);
103 bool Trans::IsDefined() const
105 return !name_.empty();
109 string const & Trans::GetName() const
124 struct keyword_item kmapTags[K_LAST - 1] = {
132 tex_accent getkeymod(string const &);
135 void Trans::AddDeadkey(tex_accent accent, string const & keys,
136 string const & allowed)
138 if (kmod_list_[accent]) {
139 FreeException(kmod_list_[accent]->exception_list);
141 delete kmod_list_[accent];
144 kmod_list_[accent] = new kmod_list_decl;
145 kmod_list_[accent]->data = keys;
146 kmod_list_[accent]->accent = accent;
147 if (allowed == "native") {
148 kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
150 kmod_list_[accent]->allowed = allowed;
153 for(string::size_type i = 0; i < keys.length(); ++i) {
156 &keymap_[static_cast<unsigned char>(keys[i])];
157 #warning this is not really clean we should find a cleaner way (Jug)
158 *temp = "xx"; /* this is needed for the being sure that
159 the below assignment is not assigned to
160 a nullpointer (if size of string = 0)
166 keymap_[static_cast<unsigned char>(keys[i])];
171 // But the question remains: "Should we be allowed
172 // to change bindings, without unbinding first?"
174 lyxerr << "Hey... keymap_[xx] not empty." << endl;
176 temp += char(accent);
180 kmod_list_[accent]->exception_list = 0;
184 int Trans::Load(LyXLex & lex)
188 while (lex.IsOK() && !error) {
192 if (lyxerr.debugging(Debug::KBMAP))
193 lyxerr << "KMOD:\t" << lex.text() << endl;
194 if (lex.next(true)) {
195 if (lyxerr.debugging(Debug::KBMAP))
196 lyxerr << "key\t`" << lex.text()
201 string keys = lex.GetString();
203 if (lex.next(true)) {
204 if ( lyxerr.debugging(Debug::KBMAP))
205 lyxerr << "accent\t`" << lex.text()
210 tex_accent accent = getkeymod(lex.GetString());
212 if (accent == TEX_NOACCENT)
215 if (lex.next(true)) {
216 if (lyxerr.debugging(Debug::KBMAP))
217 lyxerr << "allowed\t`" << lex.text()
222 string allowed = lex.GetString();
224 AddDeadkey(accent, keys, allowed);
230 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
231 if (lex.next(true)) {
233 lyxerr[Debug::KBMAP] << str << endl;
237 tex_accent accent_1 = getkeymod(str);
238 if (accent_1 == TEX_NOACCENT) return -1;
240 if (lex.next(true)) {
242 lyxerr[Debug::KBMAP] << str << endl;
246 tex_accent accent_2= getkeymod(str);
247 if (accent_2 == TEX_NOACCENT) return -1;
249 if (kmod_list_[accent_1] == 0
250 || kmod_list_[accent_2] == 0)
253 // Find what key accent_2 is on - should
254 // check about accent_1 also
256 for(; key < 256; ++key) {
257 if (!keymap_[key].empty()
258 && keymap_[key][0] == 0
259 && keymap_[key][1] == accent_2)
265 allowed = lex.GetString();
266 lyxerr[Debug::KBMAP] << "allowed: "
271 InsertException(kmod_list_[accent_1]->exception_list,
272 static_cast<char>(key), allowed,
277 unsigned char key_from;
279 if (lyxerr.debugging(Debug::KBMAP))
280 lyxerr << "KMAP:\t" << lex.text() << endl;
281 if (lex.next(true)) {
282 key_from = lex.text()[0];
283 if (lyxerr.debugging(Debug::KBMAP))
284 lyxerr << "\t`" << lex.text() << "'"
289 if (lex.next(true)) {
290 string string_to = lex.text();
292 // strcpy(new char[strlen(t)+1], t);
293 keymap_[key_from] = string_to;
294 if (lyxerr.debugging(Debug::KBMAP))
295 lyxerr << "\t`" << string_to << "'"
307 if (lyxerr.debugging(Debug::KBMAP))
308 lyxerr << "KXMOD:\t" << lex.text() << endl;
309 if (lex.next(true)) {
310 if (lyxerr.debugging(Debug::KBMAP))
311 lyxerr << "\t`" << lex.text() << "'"
313 accent = getkeymod(lex.GetString());
317 if (lex.next(true)) {
318 if (lyxerr.debugging(Debug::KBMAP))
319 lyxerr << "\t`" << lex.text() << "'"
325 if (lex.next(true)) {
326 if (lyxerr.debugging(Debug::KBMAP))
327 lyxerr << "\t`" << lex.text() << "'"
333 InsertException(kmod_list_[accent]->exception_list,
337 case LyXLex::LEX_FEOF:
338 lyxerr[Debug::PARSER] << "End of parsing" << endl;
341 lex.printError("ParseKeymapFile: "
342 "Unknown tag: `$$Token'");
350 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
352 if (kmod_list_[accent] != 0) {
353 i = *kmod_list_[accent];
360 string const Trans::process(char c, TransManager & k)
364 string const t = Match(static_cast<unsigned char>(c));
366 if (t.empty() && c != 0) {
368 return k.normalkey(c, dt);
369 } else if (!t.empty()) {
371 return k.normalkey(c, dt);
374 *kmod_list_[static_cast<tex_accent>(t[1])]);
379 int Trans::Load(string const & language)
381 string filename = LibFileSearch("kbd", language, "kmap");
382 if (filename.empty())
386 LyXLex lex(kmapTags, K_LAST-1);
387 lex.setFile(filename);
400 tex_accent getkeymod(string const & p)
401 /* return modifier - decoded from p and update p */
403 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
404 if (lyxerr.debugging(Debug::KBMAP))
405 lyxerr << "p = " << p
406 << ", lyx_accent_table[" << i
407 << "].name = `" << lyx_accent_table[i].name
410 if ( lyx_accent_table[i].name
411 && contains(p, lyx_accent_table[i].name)) {
412 lyxerr[Debug::KBMAP] << "Found it!" << endl;
413 return static_cast<tex_accent>(i);