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 DefaultTrans::process(char c, TransManager & k)
43 return k.normalkey(c, dummy);
55 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
66 void Trans::InsertException(Trans::keyexc & exclist, char c,
67 string const & data, bool flag, tex_accent accent)
69 keyexc p = new Keyexc;
81 void Trans::FreeException(Trans::keyexc & exclist)
83 Trans::keyexc p = exclist;
92 void Trans::FreeKeymap()
100 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
102 FreeException(kmod_list_[i]->exception_list);
103 delete kmod_list_[i];
109 bool Trans::IsDefined()
111 return !name_.empty();
115 string const & Trans::GetName()
130 struct keyword_item kmapTags[K_LAST - 1] = {
138 tex_accent getkeymod(string const &);
141 void Trans::AddDeadkey(tex_accent accent, string const & keys,
142 string const & allowed)
144 if (kmod_list_[accent]) {
145 FreeException(kmod_list_[accent]->exception_list);
147 delete kmod_list_[accent];
150 kmod_list_[accent] = new kmod_list_decl;
151 kmod_list_[accent]->data = keys;
152 kmod_list_[accent]->accent = accent;
153 if (allowed == "all") {
154 kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
156 kmod_list_[accent]->allowed = allowed;
159 for(string::size_type i = 0; i < keys.length(); ++i) {
161 keymap_[static_cast<unsigned char>(keys[i])] =
163 temp[0] = 0; temp[1] = accent;
165 kmod_list_[accent]->exception_list = 0;
169 int Trans::Load(LyXLex & lex)
173 while (lex.IsOK() && !error) {
177 if (lyxerr.debugging(Debug::KBMAP))
178 lyxerr << "KMOD:\t" << lex.text() << endl;
179 if (lex.next(true)) {
180 if (lyxerr.debugging(Debug::KBMAP))
181 lyxerr << "key\t`" << lex.text()
186 string keys = lex.GetString();
188 if (lex.next(true)) {
189 if ( lyxerr.debugging(Debug::KBMAP))
190 lyxerr << "accent\t`" << lex.text()
195 tex_accent accent = getkeymod(lex.GetString());
197 if (accent == TEX_NOACCENT)
200 if (lex.next(true)) {
201 if (lyxerr.debugging(Debug::KBMAP))
202 lyxerr << "allowed\t`" << lex.text()
207 string allowed = lex.GetString();
209 AddDeadkey(accent, keys, allowed);
215 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
216 if (lex.next(true)) {
218 lyxerr[Debug::KBMAP] << str << endl;
222 tex_accent accent_1 = getkeymod(str);
223 if (accent_1 == TEX_NOACCENT) return -1;
225 if (lex.next(true)) {
227 lyxerr[Debug::KBMAP] << str << endl;
231 tex_accent accent_2= getkeymod(str);
232 if (accent_2 == TEX_NOACCENT) return -1;
234 if (kmod_list_[accent_1] == 0
235 || kmod_list_[accent_2] == 0)
238 // Find what key accent_2 is on - should
239 // check about accent_1 also
241 for(; key < 256; ++key) {
242 if (keymap_[key] && keymap_[key][0] == 0
243 && keymap_[key][1] == accent_2)
249 allowed = lex.GetString();
250 lyxerr[Debug::KBMAP] << "allowed: "
255 InsertException(kmod_list_[accent_1]->exception_list,
256 static_cast<char>(key), allowed,
261 unsigned char key_from;
263 if (lyxerr.debugging(Debug::KBMAP))
264 lyxerr << "KMAP:\t" << lex.text() << endl;
265 if (lex.next(true)) {
266 key_from = lex.text()[0];
267 if (lyxerr.debugging(Debug::KBMAP))
268 lyxerr << "\t`" << lex.text() << "'"
273 if (lex.next(true)) {
274 char const * t = lex.text();
276 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,
321 case LyXLex::LEX_FEOF:
322 lyxerr[Debug::PARSER] << "End of parsing" << endl;
325 lex.printError("ParseKeymapFile: "
326 "Unknown tag: `$$Token'");
334 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i)
336 if (kmod_list_[accent]!= 0) {
337 i = *kmod_list_[accent];
344 string Trans::process(char c, TransManager & k)
348 char * t = Match(static_cast<unsigned char>(c));
350 if ((t == 0 && (*dt = c)) || (t[0] != 0 && (dt = t)) ){
351 return k.normalkey(c, dt);
354 *kmod_list_[static_cast<tex_accent>(t[1])]);
359 int Trans::Load(string const & language)
361 string filename = LibFileSearch("kbd", language, "kmap");
362 if (filename.empty())
366 LyXLex lex(kmapTags, K_LAST-1);
367 lex.setFile(filename);
380 tex_accent getkeymod(string const & p)
381 /* return modifier - decoded from p and update p */
383 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
384 if (lyxerr.debugging(Debug::KBMAP))
385 lyxerr << "p = " << p
386 << ", lyx_accent_table[" << i
387 << "].name = `" << lyx_accent_table[i].name
390 if ( lyx_accent_table[i].name
391 && contains(p, lyx_accent_table[i].name)) {
392 lyxerr[Debug::KBMAP] << "Found it!" << endl;
393 return static_cast<tex_accent>(i);