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);
52 for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
63 void Trans::InsertException(Trans::keyexc & exclist, char c,
64 string const & data, bool flag, tex_accent accent)
66 keyexc p = new Keyexc;
78 void Trans::FreeException(Trans::keyexc & exclist)
80 Trans::keyexc p = exclist;
89 void Trans::FreeKeymap()
91 for(int i = 0; i < 256; ++i)
92 if (!keymap_[i].empty()) {
96 for(int i = 0; i < TEX_MAX_ACCENT + 1; ++i)
98 FreeException(kmod_list_[i]->exception_list);
105 bool Trans::IsDefined() const
107 return !name_.empty();
111 string const & Trans::GetName() const
126 struct keyword_item kmapTags[K_LAST - 1] = {
134 tex_accent getkeymod(string const &);
137 void Trans::AddDeadkey(tex_accent accent, string const & keys,
138 string const & allowed)
140 if (kmod_list_[accent]) {
141 FreeException(kmod_list_[accent]->exception_list);
143 delete kmod_list_[accent];
146 kmod_list_[accent] = new kmod_list_decl;
147 kmod_list_[accent]->data = keys;
148 kmod_list_[accent]->accent = accent;
149 if (allowed == "native") {
150 kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
152 kmod_list_[accent]->allowed = allowed;
155 for(string::size_type i = 0; i < keys.length(); ++i) {
157 &keymap_[static_cast<unsigned char>(keys[i])];
158 #warning this is not really clean we should find a cleaner way (Jug)
159 *temp = "xx"; /* this is needed for the being sure that the below
160 assignment is not assigned to a nullpointer
161 (if size of string = 0)
166 kmod_list_[accent]->exception_list = 0;
170 int Trans::Load(LyXLex & lex)
174 while (lex.IsOK() && !error) {
178 if (lyxerr.debugging(Debug::KBMAP))
179 lyxerr << "KMOD:\t" << lex.text() << endl;
180 if (lex.next(true)) {
181 if (lyxerr.debugging(Debug::KBMAP))
182 lyxerr << "key\t`" << lex.text()
187 string keys = lex.GetString();
189 if (lex.next(true)) {
190 if ( lyxerr.debugging(Debug::KBMAP))
191 lyxerr << "accent\t`" << lex.text()
196 tex_accent accent = getkeymod(lex.GetString());
198 if (accent == TEX_NOACCENT)
201 if (lex.next(true)) {
202 if (lyxerr.debugging(Debug::KBMAP))
203 lyxerr << "allowed\t`" << lex.text()
208 string allowed = lex.GetString();
210 AddDeadkey(accent, keys, allowed);
216 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
217 if (lex.next(true)) {
219 lyxerr[Debug::KBMAP] << str << endl;
223 tex_accent accent_1 = getkeymod(str);
224 if (accent_1 == TEX_NOACCENT) return -1;
226 if (lex.next(true)) {
228 lyxerr[Debug::KBMAP] << str << endl;
232 tex_accent accent_2= getkeymod(str);
233 if (accent_2 == TEX_NOACCENT) return -1;
235 if (kmod_list_[accent_1] == 0
236 || kmod_list_[accent_2] == 0)
239 // Find what key accent_2 is on - should
240 // check about accent_1 also
242 for(; key < 256; ++key) {
243 if (!keymap_[key].empty()
244 && 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,
258 static_cast<char>(key), allowed,
263 unsigned char key_from;
265 if (lyxerr.debugging(Debug::KBMAP))
266 lyxerr << "KMAP:\t" << lex.text() << endl;
267 if (lex.next(true)) {
268 key_from = lex.text()[0];
269 if (lyxerr.debugging(Debug::KBMAP))
270 lyxerr << "\t`" << lex.text() << "'"
275 if (lex.next(true)) {
276 string string_to = lex.text();
278 // strcpy(new char[strlen(t)+1], t);
279 keymap_[key_from] = string_to;
280 if (lyxerr.debugging(Debug::KBMAP))
281 lyxerr << "\t`" << string_to << "'"
293 if (lyxerr.debugging(Debug::KBMAP))
294 lyxerr << "KXMOD:\t" << lex.text() << endl;
295 if (lex.next(true)) {
296 if (lyxerr.debugging(Debug::KBMAP))
297 lyxerr << "\t`" << lex.text() << "'"
299 accent = getkeymod(lex.GetString());
303 if (lex.next(true)) {
304 if (lyxerr.debugging(Debug::KBMAP))
305 lyxerr << "\t`" << lex.text() << "'"
311 if (lex.next(true)) {
312 if (lyxerr.debugging(Debug::KBMAP))
313 lyxerr << "\t`" << lex.text() << "'"
319 InsertException(kmod_list_[accent]->exception_list,
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) const
338 if (kmod_list_[accent] != 0) {
339 i = *kmod_list_[accent];
346 string const Trans::process(char c, TransManager & k)
350 string const t = Match(static_cast<unsigned char>(c));
352 if (t.empty() && c != 0) {
354 return k.normalkey(c, dt);
355 } else if (!t.empty()) {
357 return k.normalkey(c, dt);
360 *kmod_list_[static_cast<tex_accent>(t[1])]);
365 int Trans::Load(string const & language)
367 string filename = LibFileSearch("kbd", language, "kmap");
368 if (filename.empty())
372 LyXLex lex(kmapTags, K_LAST-1);
373 lex.setFile(filename);
386 tex_accent getkeymod(string const & p)
387 /* return modifier - decoded from p and update p */
389 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
390 if (lyxerr.debugging(Debug::KBMAP))
391 lyxerr << "p = " << p
392 << ", lyx_accent_table[" << i
393 << "].name = `" << lyx_accent_table[i].name
396 if ( lyx_accent_table[i].name
397 && contains(p, lyx_accent_table[i].name)) {
398 lyxerr[Debug::KBMAP] << "Found it!" << endl;
399 return static_cast<tex_accent>(i);