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);
53 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
64 void Trans::InsertException(Trans::keyexc & exclist, char c,
65 string const & data, bool flag, tex_accent accent)
67 keyexc p = new Keyexc;
79 void Trans::FreeException(Trans::keyexc & exclist)
81 Trans::keyexc p = exclist;
90 void Trans::FreeKeymap()
98 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
100 FreeException(kmod_list_[i]->exception_list);
101 delete kmod_list_[i];
107 bool Trans::IsDefined()
109 return !name_.empty();
113 string const & Trans::GetName()
128 struct keyword_item kmapTags[K_LAST - 1] = {
136 tex_accent getkeymod(string const &);
139 void Trans::AddDeadkey(tex_accent accent, string const & keys,
140 string const & allowed)
142 if (kmod_list_[accent]) {
143 FreeException(kmod_list_[accent]->exception_list);
145 delete kmod_list_[accent];
148 kmod_list_[accent] = new kmod_list_decl;
149 kmod_list_[accent]->data = keys;
150 kmod_list_[accent]->accent = accent;
151 if (allowed == "all") {
152 kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
154 kmod_list_[accent]->allowed = allowed;
157 for(string::size_type i = 0; i < keys.length(); ++i) {
159 keymap_[static_cast<unsigned char>(keys[i])] =
161 temp[0] = 0; temp[1] = accent;
163 kmod_list_[accent]->exception_list = 0;
167 int Trans::Load(LyXLex & lex)
171 while (lex.IsOK() && !error) {
175 if (lyxerr.debugging(Debug::KBMAP))
176 lyxerr << "KMOD:\t" << lex.text() << endl;
177 if (lex.next(true)) {
178 if (lyxerr.debugging(Debug::KBMAP))
179 lyxerr << "key\t`" << lex.text()
184 string keys = lex.GetString();
186 if (lex.next(true)) {
187 if ( lyxerr.debugging(Debug::KBMAP))
188 lyxerr << "accent\t`" << lex.text()
193 tex_accent accent = getkeymod(lex.GetString());
195 if (accent == TEX_NOACCENT)
198 if (lex.next(true)) {
199 if (lyxerr.debugging(Debug::KBMAP))
200 lyxerr << "allowed\t`" << lex.text()
205 string allowed = lex.GetString();
207 AddDeadkey(accent, keys, allowed);
213 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
214 if (lex.next(true)) {
216 lyxerr[Debug::KBMAP] << str << endl;
220 tex_accent accent_1 = getkeymod(str);
221 if (accent_1 == TEX_NOACCENT) return -1;
223 if (lex.next(true)) {
225 lyxerr[Debug::KBMAP] << str << endl;
229 tex_accent accent_2= getkeymod(str);
230 if (accent_2 == TEX_NOACCENT) return -1;
232 if (kmod_list_[accent_1] == 0
233 || kmod_list_[accent_2] == 0)
236 // Find what key accent_2 is on - should
237 // check about accent_1 also
239 for(; key < 256; ++key) {
240 if (keymap_[key] && keymap_[key][0] == 0
241 && keymap_[key][1] == accent_2)
247 allowed = lex.GetString();
248 lyxerr[Debug::KBMAP] << "allowed: "
253 InsertException(kmod_list_[accent_1]->exception_list,
254 static_cast<char>(key), allowed,
259 unsigned char key_from;
261 if (lyxerr.debugging(Debug::KBMAP))
262 lyxerr << "KMAP:\t" << lex.text() << endl;
263 if (lex.next(true)) {
264 key_from = lex.text()[0];
265 if (lyxerr.debugging(Debug::KBMAP))
266 lyxerr << "\t`" << lex.text() << "'"
271 if (lex.next(true)) {
272 char const * t = lex.text();
274 strcpy(new char[strlen(t)+1], t);
275 keymap_[key_from] = string_to;
276 if (lyxerr.debugging(Debug::KBMAP))
277 lyxerr << "\t`" << string_to << "'"
289 if (lyxerr.debugging(Debug::KBMAP))
290 lyxerr << "KXMOD:\t" << lex.text() << endl;
291 if (lex.next(true)) {
292 if (lyxerr.debugging(Debug::KBMAP))
293 lyxerr << "\t`" << lex.text() << "'"
295 accent = getkeymod(lex.GetString());
299 if (lex.next(true)) {
300 if (lyxerr.debugging(Debug::KBMAP))
301 lyxerr << "\t`" << lex.text() << "'"
307 if (lex.next(true)) {
308 if (lyxerr.debugging(Debug::KBMAP))
309 lyxerr << "\t`" << lex.text() << "'"
315 InsertException(kmod_list_[accent]->exception_list,
319 case LyXLex::LEX_FEOF:
320 lyxerr[Debug::PARSER] << "End of parsing" << endl;
323 lex.printError("ParseKeymapFile: "
324 "Unknown tag: `$$Token'");
332 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i)
334 if (kmod_list_[accent]!= 0) {
335 i = *kmod_list_[accent];
342 string Trans::process(char c, TransManager & k)
346 char * t = Match(static_cast<unsigned char>(c));
348 if ((t == 0 && (*dt = c)) || (t[0] != 0 && (dt = t)) ){
349 return k.normalkey(c, dt);
352 *kmod_list_[static_cast<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
389 && contains(p, lyx_accent_table[i].name)) {
390 lyxerr[Debug::KBMAP] << "Found it!" << endl;
391 return static_cast<tex_accent>(i);