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 (*temp)[0] = 0; (*temp)[1] = accent;
160 kmod_list_[accent]->exception_list = 0;
164 int Trans::Load(LyXLex & lex)
168 while (lex.IsOK() && !error) {
172 if (lyxerr.debugging(Debug::KBMAP))
173 lyxerr << "KMOD:\t" << lex.text() << endl;
174 if (lex.next(true)) {
175 if (lyxerr.debugging(Debug::KBMAP))
176 lyxerr << "key\t`" << lex.text()
181 string keys = lex.GetString();
183 if (lex.next(true)) {
184 if ( lyxerr.debugging(Debug::KBMAP))
185 lyxerr << "accent\t`" << lex.text()
190 tex_accent accent = getkeymod(lex.GetString());
192 if (accent == TEX_NOACCENT)
195 if (lex.next(true)) {
196 if (lyxerr.debugging(Debug::KBMAP))
197 lyxerr << "allowed\t`" << lex.text()
202 string allowed = lex.GetString();
204 AddDeadkey(accent, keys, allowed);
210 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
211 if (lex.next(true)) {
213 lyxerr[Debug::KBMAP] << str << endl;
217 tex_accent accent_1 = getkeymod(str);
218 if (accent_1 == TEX_NOACCENT) return -1;
220 if (lex.next(true)) {
222 lyxerr[Debug::KBMAP] << str << endl;
226 tex_accent accent_2= getkeymod(str);
227 if (accent_2 == TEX_NOACCENT) return -1;
229 if (kmod_list_[accent_1] == 0
230 || kmod_list_[accent_2] == 0)
233 // Find what key accent_2 is on - should
234 // check about accent_1 also
236 for(; key < 256; ++key) {
237 if (!keymap_[key].empty()
238 && keymap_[key][0] == 0
239 && keymap_[key][1] == accent_2)
245 allowed = lex.GetString();
246 lyxerr[Debug::KBMAP] << "allowed: "
251 InsertException(kmod_list_[accent_1]->exception_list,
252 static_cast<char>(key), allowed,
257 unsigned char key_from;
259 if (lyxerr.debugging(Debug::KBMAP))
260 lyxerr << "KMAP:\t" << lex.text() << endl;
261 if (lex.next(true)) {
262 key_from = lex.text()[0];
263 if (lyxerr.debugging(Debug::KBMAP))
264 lyxerr << "\t`" << lex.text() << "'"
269 if (lex.next(true)) {
270 string string_to = lex.text();
272 // strcpy(new char[strlen(t)+1], t);
273 keymap_[key_from] = string_to;
274 if (lyxerr.debugging(Debug::KBMAP))
275 lyxerr << "\t`" << string_to << "'"
287 if (lyxerr.debugging(Debug::KBMAP))
288 lyxerr << "KXMOD:\t" << lex.text() << endl;
289 if (lex.next(true)) {
290 if (lyxerr.debugging(Debug::KBMAP))
291 lyxerr << "\t`" << lex.text() << "'"
293 accent = getkeymod(lex.GetString());
297 if (lex.next(true)) {
298 if (lyxerr.debugging(Debug::KBMAP))
299 lyxerr << "\t`" << lex.text() << "'"
305 if (lex.next(true)) {
306 if (lyxerr.debugging(Debug::KBMAP))
307 lyxerr << "\t`" << lex.text() << "'"
313 InsertException(kmod_list_[accent]->exception_list,
317 case LyXLex::LEX_FEOF:
318 lyxerr[Debug::PARSER] << "End of parsing" << endl;
321 lex.printError("ParseKeymapFile: "
322 "Unknown tag: `$$Token'");
330 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
332 if (kmod_list_[accent] != 0) {
333 i = *kmod_list_[accent];
340 string const Trans::process(char c, TransManager & k)
344 string const t = Match(static_cast<unsigned char>(c));
346 if (t.empty() && c != 0) {
348 return k.normalkey(c, dt);
349 } else if (!t.empty()) {
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);