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])];
170 // But the question remains: "Should we be allowed
171 // to change bindings, without unbinding first?"
174 temp += char(accent);
177 kmod_list_[accent]->exception_list = 0;
181 int Trans::Load(LyXLex & lex)
185 while (lex.IsOK() && !error) {
189 if (lyxerr.debugging(Debug::KBMAP))
190 lyxerr << "KMOD:\t" << lex.text() << endl;
191 if (lex.next(true)) {
192 if (lyxerr.debugging(Debug::KBMAP))
193 lyxerr << "key\t`" << lex.text()
198 string keys = lex.GetString();
200 if (lex.next(true)) {
201 if ( lyxerr.debugging(Debug::KBMAP))
202 lyxerr << "accent\t`" << lex.text()
207 tex_accent accent = getkeymod(lex.GetString());
209 if (accent == TEX_NOACCENT)
212 if (lex.next(true)) {
213 if (lyxerr.debugging(Debug::KBMAP))
214 lyxerr << "allowed\t`" << lex.text()
219 string allowed = lex.GetString();
221 AddDeadkey(accent, keys, allowed);
227 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
228 if (lex.next(true)) {
230 lyxerr[Debug::KBMAP] << str << endl;
234 tex_accent accent_1 = getkeymod(str);
235 if (accent_1 == TEX_NOACCENT) return -1;
237 if (lex.next(true)) {
239 lyxerr[Debug::KBMAP] << str << endl;
243 tex_accent accent_2= getkeymod(str);
244 if (accent_2 == TEX_NOACCENT) return -1;
246 if (kmod_list_[accent_1] == 0
247 || kmod_list_[accent_2] == 0)
250 // Find what key accent_2 is on - should
251 // check about accent_1 also
253 for(; key < 256; ++key) {
254 if (!keymap_[key].empty()
255 && keymap_[key][0] == 0
256 && keymap_[key][1] == accent_2)
262 allowed = lex.GetString();
263 lyxerr[Debug::KBMAP] << "allowed: "
268 InsertException(kmod_list_[accent_1]->exception_list,
269 static_cast<char>(key), allowed,
274 unsigned char key_from;
276 if (lyxerr.debugging(Debug::KBMAP))
277 lyxerr << "KMAP:\t" << lex.text() << endl;
278 if (lex.next(true)) {
279 key_from = lex.text()[0];
280 if (lyxerr.debugging(Debug::KBMAP))
281 lyxerr << "\t`" << lex.text() << "'"
286 if (lex.next(true)) {
287 string string_to = lex.text();
289 // strcpy(new char[strlen(t)+1], t);
290 keymap_[key_from] = string_to;
291 if (lyxerr.debugging(Debug::KBMAP))
292 lyxerr << "\t`" << string_to << "'"
304 if (lyxerr.debugging(Debug::KBMAP))
305 lyxerr << "KXMOD:\t" << lex.text() << endl;
306 if (lex.next(true)) {
307 if (lyxerr.debugging(Debug::KBMAP))
308 lyxerr << "\t`" << lex.text() << "'"
310 accent = getkeymod(lex.GetString());
314 if (lex.next(true)) {
315 if (lyxerr.debugging(Debug::KBMAP))
316 lyxerr << "\t`" << lex.text() << "'"
322 if (lex.next(true)) {
323 if (lyxerr.debugging(Debug::KBMAP))
324 lyxerr << "\t`" << lex.text() << "'"
330 InsertException(kmod_list_[accent]->exception_list,
334 case LyXLex::LEX_FEOF:
335 lyxerr[Debug::PARSER] << "End of parsing" << endl;
338 lex.printError("ParseKeymapFile: "
339 "Unknown tag: `$$Token'");
347 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
349 if (kmod_list_[accent] != 0) {
350 i = *kmod_list_[accent];
357 string const Trans::process(char c, TransManager & k)
361 string const t = Match(static_cast<unsigned char>(c));
363 if (t.empty() && c != 0) {
365 return k.normalkey(c, dt);
366 } else if (!t.empty()) {
368 return k.normalkey(c, dt);
371 *kmod_list_[static_cast<tex_accent>(t[1])]);
376 int Trans::Load(string const & language)
378 string filename = LibFileSearch("kbd", language, "kmap");
379 if (filename.empty())
383 LyXLex lex(kmapTags, K_LAST-1);
384 lex.setFile(filename);
397 tex_accent getkeymod(string const & p)
398 /* return modifier - decoded from p and update p */
400 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
401 if (lyxerr.debugging(Debug::KBMAP))
402 lyxerr << "p = " << p
403 << ", lyx_accent_table[" << i
404 << "].name = `" << lyx_accent_table[i].name
407 if ( lyx_accent_table[i].name
408 && contains(p, lyx_accent_table[i].name)) {
409 lyxerr[Debug::KBMAP] << "Found it!" << endl;
410 return static_cast<tex_accent>(i);