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 keymap_[static_cast<unsigned int>(keys[i])] =
167 temp[0] = 0; temp[1] = accent;
169 kmod_list_[accent]->exception_list = 0;
173 int Trans::Load(LyXLex & lex)
177 while (lex.IsOK() && !error) {
181 if (lyxerr.debugging(Debug::KBMAP))
182 lyxerr << "KMOD:\t" << lex.text() << endl;
183 if (lex.next(true)) {
184 if (lyxerr.debugging(Debug::KBMAP))
185 lyxerr << "key\t`" << lex.text()
190 string keys = lex.GetString();
192 if (lex.next(true)) {
193 if ( lyxerr.debugging(Debug::KBMAP))
194 lyxerr << "accent\t`" << lex.text()
199 tex_accent accent = getkeymod(lex.GetString());
201 if (accent == TEX_NOACCENT)
204 if (lex.next(true)) {
205 if (lyxerr.debugging(Debug::KBMAP))
206 lyxerr << "allowed\t`" << lex.text()
211 string allowed = lex.GetString();
213 AddDeadkey(accent, keys, allowed);
219 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
220 if (lex.next(true)) {
222 lyxerr[Debug::KBMAP] << str << endl;
226 tex_accent accent_1 = getkeymod(str);
227 if (accent_1 == TEX_NOACCENT) return -1;
229 if (lex.next(true)) {
231 lyxerr[Debug::KBMAP] << str << endl;
235 tex_accent accent_2= getkeymod(str);
236 if (accent_2 == TEX_NOACCENT) return -1;
238 if (kmod_list_[accent_1] == 0 || kmod_list_[accent_2] == 0)
241 // Find what key accent_2 is on - should
242 // check about accent_1 also
244 for(; key < 256; ++key) {
245 if (keymap_[key] && keymap_[key][0] == 0
246 && keymap_[key][1] == accent_2)
252 allowed = lex.GetString();
253 lyxerr[Debug::KBMAP] << "allowed: "
258 InsertException(kmod_list_[accent_1]->exception_list,
259 static_cast<char>(key), allowed,
264 unsigned char key_from;
267 if (lyxerr.debugging(Debug::KBMAP))
268 lyxerr << "KMAP:\t" << lex.text() << endl;
269 if (lex.next(true)) {
270 key_from= lex.text()[0];
271 if (lyxerr.debugging(Debug::KBMAP))
272 lyxerr << "\t`" << lex.text() << "'"
277 if (lex.next(true)) {
278 char const * t = lex.text();
279 string_to = strcpy(new char[strlen(t)+1], t);
280 keymap_[key_from] = string_to;
281 if (lyxerr.debugging(Debug::KBMAP))
282 lyxerr << "\t`" << string_to << "'"
294 if (lyxerr.debugging(Debug::KBMAP))
295 lyxerr << "KXMOD:\t" << lex.text() << endl;
296 if (lex.next(true)) {
297 if (lyxerr.debugging(Debug::KBMAP))
298 lyxerr << "\t`" << lex.text() << "'"
300 accent = getkeymod(lex.GetString());
304 if (lex.next(true)) {
305 if (lyxerr.debugging(Debug::KBMAP))
306 lyxerr << "\t`" << lex.text() << "'"
312 if (lex.next(true)) {
313 if (lyxerr.debugging(Debug::KBMAP))
314 lyxerr << "\t`" << lex.text() << "'"
320 InsertException(kmod_list_[accent]->exception_list, key, str);
323 case LyXLex::LEX_FEOF:
324 lyxerr[Debug::PARSER] << "End of parsing" << endl;
327 lex.printError("ParseKeymapFile: "
328 "Unknown tag: `$$Token'");
336 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i)
338 if (kmod_list_[accent]!= 0) {
339 i = *kmod_list_[accent];
346 string Trans::process(char c, TransManager & k)
352 if ((t == 0 && (*dt = c)) || (t[0] != 0 && (dt = t)) ){
353 return k.normalkey(c, dt);
355 return k.deadkey(c, *kmod_list_[static_cast<tex_accent>(t[1])]);
360 int Trans::Load(string const & language)
362 string filename = LibFileSearch("kbd", language, "kmap");
363 if (filename.empty())
367 LyXLex lex(kmapTags, K_LAST-1);
368 lex.setFile(filename);
381 tex_accent getkeymod(string const & p)
382 /* return modifier - decoded from p and update p */
384 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
385 if (lyxerr.debugging(Debug::KBMAP))
386 lyxerr << "p = " << p
387 << ", lyx_accent_table[" << i
388 << "].name = `" << lyx_accent_table[i].name
391 if ( lyx_accent_table[i].name && contains(p, lyx_accent_table[i].name)) {
392 lyxerr[Debug::KBMAP] << "Found it!" << endl;
393 return static_cast<tex_accent>(i);