4 #pragma implementation "trans.h"
9 #include "support/filetools.h"
10 #include "tex-strings.h"
13 #include "trans_mgr.h"
24 bool DefaultTrans::init_ = false;
27 DefaultTrans::DefaultTrans()
36 string DefaultTrans::process(char c, TransManager & k)
41 return k.normalkey(c, dummy);
51 for(i = 0; i < 256; ++i)
54 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
65 void Trans::InsertException(Trans::keyexc & exclist, char c,
66 string const & data, bool flag, tex_accent accent)
82 void Trans::FreeException(Trans::keyexc & exclist)
95 void Trans::FreeKeymap()
99 for(i = 0; i < 256; ++i)
104 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
106 FreeException(kmod_list_[i]->exception_list);
107 delete kmod_list_[i];
113 bool Trans::IsDefined()
115 return !name_.empty();
119 string const & Trans::GetName()
134 struct keyword_item kmapTags[K_LAST-1] = {
142 tex_accent getkeymod(string const &);
145 void Trans::AddDeadkey(tex_accent accent, string const & keys,
146 string const & allowed)
148 if (kmod_list_[accent]) {
149 FreeException(kmod_list_[accent]->exception_list);
151 delete kmod_list_[accent];
154 kmod_list_[accent] = new kmod_list_decl;
155 kmod_list_[accent]->data = keys;
156 kmod_list_[accent]->accent = accent;
157 if (allowed == "all") {
158 kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
160 kmod_list_[accent]->allowed = allowed;
163 for(string::size_type i = 0; i < keys.length(); ++i) {
165 temp = keymap_[static_cast<unsigned char>(keys[i])] = new char[2];
166 temp[0] = 0; temp[1] = accent;
168 kmod_list_[accent]->exception_list = 0;
172 int Trans::Load(LyXLex & lex)
176 while (lex.IsOK() && !error) {
180 if (lyxerr.debugging(Debug::KBMAP))
181 lyxerr << "KMOD:\t" << lex.text() << endl;
182 if (lex.next(true)) {
183 if (lyxerr.debugging(Debug::KBMAP))
184 lyxerr << "key\t`" << lex.text()
189 string keys = lex.GetString();
191 if (lex.next(true)) {
192 if ( lyxerr.debugging(Debug::KBMAP))
193 lyxerr << "accent\t`" << lex.text()
198 tex_accent accent = getkeymod(lex.GetString());
200 if (accent == TEX_NOACCENT)
203 if (lex.next(true)) {
204 if (lyxerr.debugging(Debug::KBMAP))
205 lyxerr << "allowed\t`" << lex.text()
210 string allowed = lex.GetString();
212 AddDeadkey(accent, keys, allowed);
218 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
219 if (lex.next(true)) {
221 lyxerr[Debug::KBMAP] << str << endl;
225 tex_accent accent_1= getkeymod(str);
226 if (accent_1 == TEX_NOACCENT) return -1;
228 if (lex.next(true)) {
230 lyxerr[Debug::KBMAP] << str << endl;
234 tex_accent accent_2= getkeymod(str);
235 if (accent_2 == TEX_NOACCENT) return -1;
237 if (kmod_list_[accent_1] == 0 || kmod_list_[accent_2] == 0)
240 // Find what key accent_2 is on - should check about accent_1 also
243 for(key = 0; key < 256; ++key) {
244 if (keymap_[key] && keymap_[key][0] == 0
245 && keymap_[key][1] == accent_2)
251 allowed = lex.GetString();
252 lyxerr[Debug::KBMAP] << "allowed: "
257 InsertException(kmod_list_[accent_1]->exception_list,(char)key, allowed, true, accent_2);
261 unsigned char key_from;
264 if (lyxerr.debugging(Debug::KBMAP))
265 lyxerr << "KMAP:\t" << lex.text() << endl;
266 if (lex.next(true)) {
267 key_from= lex.text()[0];
268 if (lyxerr.debugging(Debug::KBMAP))
269 lyxerr << "\t`" << lex.text() << "'"
274 if (lex.next(true)) {
275 char const * t = lex.text();
276 string_to = strcpy(new char[strlen(t)+1], t);
277 keymap_[key_from] = string_to;
278 if (lyxerr.debugging(Debug::KBMAP))
279 lyxerr << "\t`" << string_to << "'"
291 if (lyxerr.debugging(Debug::KBMAP))
292 lyxerr << "KXMOD:\t" << lex.text() << endl;
293 if (lex.next(true)) {
294 if (lyxerr.debugging(Debug::KBMAP))
295 lyxerr << "\t`" << lex.text() << "'"
297 accent = getkeymod(lex.GetString());
301 if (lex.next(true)) {
302 if (lyxerr.debugging(Debug::KBMAP))
303 lyxerr << "\t`" << lex.text() << "'"
309 if (lex.next(true)) {
310 if (lyxerr.debugging(Debug::KBMAP))
311 lyxerr << "\t`" << lex.text() << "'"
317 InsertException(kmod_list_[accent]->exception_list, key, str);
320 case LyXLex::LEX_FEOF:
321 lyxerr[Debug::PARSER] << "End of parsing" << endl;
324 lex.printError("ParseKeymapFile: "
325 "Unknown tag: `$$Token'");
333 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i)
335 if (kmod_list_[accent]!= 0) {
336 i = *kmod_list_[accent];
343 string Trans::process(char c, TransManager & k)
349 if ((t == 0 && (*dt = c)) || (t[0] != 0 && (dt = t)) ){
350 return k.normalkey(c, dt);
352 return k.deadkey(c, *kmod_list_[(tex_accent)t[1]]);
357 int Trans::Load(string const & language)
359 string filename = LibFileSearch("kbd", language, "kmap");
360 if (filename.empty())
364 LyXLex lex(kmapTags, K_LAST-1);
365 lex.setFile(filename);
378 tex_accent getkeymod(string const & p)
379 /* return modifier - decoded from p and update p */
381 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
382 if (lyxerr.debugging(Debug::KBMAP))
383 lyxerr << "p = " << p
384 << ", lyx_accent_table[" << i
385 << "].name = `" << lyx_accent_table[i].name
388 if ( lyx_accent_table[i].name && contains(p, lyx_accent_table[i].name)) {
389 lyxerr[Debug::KBMAP] << "Found it!" << endl;
390 return (tex_accent)i;