8 #include "support/filetools.h"
9 #include "support/lstrings.h"
10 #include "tex-strings.h"
13 #include "trans_mgr.h"
38 void Trans::InsertException(KmodException & exclist, char c,
39 string const & data, bool flag, tex_accent accent)
46 exclist.insert(exclist.begin(), p);
48 // exclist.push_back(p);
52 void Trans::FreeException(KmodException & exclist)
58 void Trans::FreeKeymap()
65 bool Trans::IsDefined() const
67 return !name_.empty();
71 string const & Trans::GetName() const
86 struct keyword_item kmapTags[K_LAST - 1] = {
94 tex_accent getkeymod(string const &);
97 void Trans::AddDeadkey(tex_accent accent, string const & keys)
102 kmod_list_[accent] = tmp;
104 for (string::size_type i = 0; i < keys.length(); ++i) {
108 keymap_[keys[i]] = tmp;
113 int Trans::Load(LyXLex & lex)
117 while (lex.isOK() && !error) {
121 if (lyxerr.debugging(Debug::KBMAP))
122 lyxerr << "KMOD:\t" << lex.text() << endl;
123 if (lex.next(true)) {
124 if (lyxerr.debugging(Debug::KBMAP))
125 lyxerr << "key\t`" << lex.text()
130 string const keys = lex.getString();
132 if (lex.next(true)) {
133 if (lyxerr.debugging(Debug::KBMAP))
134 lyxerr << "accent\t`" << lex.text()
139 tex_accent accent = getkeymod(lex.getString());
141 if (accent == TEX_NOACCENT)
145 //#warning This code should be removed...
146 // But we need to fix up all the kmap files first
147 // so that this field is not present anymore.
148 if (lex.next(true)) {
149 if (lyxerr.debugging(Debug::KBMAP))
150 lyxerr << "allowed\t`" << lex.text()
155 /* string const allowed = lex.getString(); */
156 AddDeadkey(accent, keys /*, allowed*/);
158 AddDeadkey(accent, keys);
165 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
166 if (lex.next(true)) {
168 lyxerr[Debug::KBMAP] << str << endl;
172 tex_accent accent_1 = getkeymod(str);
173 if (accent_1 == TEX_NOACCENT) return -1;
175 if (lex.next(true)) {
177 lyxerr[Debug::KBMAP] << str << endl;
181 tex_accent accent_2= getkeymod(str);
182 if (accent_2 == TEX_NOACCENT) return -1;
184 map<int, KmodInfo>::iterator it1 =
185 kmod_list_.find(accent_1);
186 map<int, KmodInfo>::iterator it2 =
187 kmod_list_.find(accent_2);
188 if (it1 == kmod_list_.end()
189 || it2 == kmod_list_.end()) {
193 // Find what key accent_2 is on - should
194 // check about accent_1 also
195 map<int, string>::iterator it = keymap_.begin();
196 map<int, string>::iterator end = keymap_.end();
197 for (; it != end; ++it) {
198 if (!it->second.empty()
199 && it->second[0] == 0
200 && it->second[1] == accent_2)
205 allowed = lex.getString();
206 lyxerr[Debug::KBMAP] << "allowed: "
212 InsertException(kmod_list_[accent_1].exception_list,
213 static_cast<char>(it->first), allowed,
218 unsigned char key_from;
220 if (lyxerr.debugging(Debug::KBMAP))
221 lyxerr << "KMAP:\t" << lex.text() << endl;
222 if (lex.next(true)) {
223 key_from = lex.text()[0];
224 if (lyxerr.debugging(Debug::KBMAP))
225 lyxerr << "\t`" << lex.text() << "'"
230 if (lex.next(true)) {
231 string string_to = lex.text();
232 keymap_[key_from] = string_to;
233 if (lyxerr.debugging(Debug::KBMAP))
234 lyxerr << "\t`" << string_to << "'"
246 if (lyxerr.debugging(Debug::KBMAP))
247 lyxerr << "KXMOD:\t" << lex.text() << endl;
248 if (lex.next(true)) {
249 if (lyxerr.debugging(Debug::KBMAP))
250 lyxerr << "\t`" << lex.text() << "'"
252 accent = getkeymod(lex.getString());
256 if (lex.next(true)) {
257 if (lyxerr.debugging(Debug::KBMAP))
258 lyxerr << "\t`" << lex.text() << "'"
264 if (lex.next(true)) {
265 if (lyxerr.debugging(Debug::KBMAP))
266 lyxerr << "\t`" << lex.text() << "'"
272 InsertException(kmod_list_[accent].exception_list,
276 case LyXLex::LEX_FEOF:
277 lyxerr[Debug::PARSER] << "End of parsing" << endl;
280 lex.printError("ParseKeymapFile: "
281 "Unknown tag: `$$Token'");
289 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
291 map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
292 if (cit != kmod_list_.end()) {
300 string const Trans::process(char c, TransManager & k)
302 string const t = Match(static_cast<unsigned char>(c));
304 if (t.empty() && c != 0) {
305 return k.normalkey(c);
306 } else if (!t.empty() && t[0] != char(0)) {
307 //return k.normalkey(c);
311 kmod_list_[static_cast<tex_accent>(t[1])]);
316 int Trans::Load(string const & language)
318 string const filename = LibFileSearch("kbd", language, "kmap");
319 if (filename.empty())
323 LyXLex lex(kmapTags, K_LAST - 1);
324 lex.setFile(filename);
326 int const res = Load(lex);
337 tex_accent getkeymod(string const & p)
338 /* return modifier - decoded from p and update p */
340 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
341 if (lyxerr.debugging(Debug::KBMAP))
342 lyxerr << "p = " << p
343 << ", lyx_accent_table[" << i
344 << "].name = `" << lyx_accent_table[i].name
347 if (lyx_accent_table[i].name
348 && contains(p, lyx_accent_table[i].name)) {
349 lyxerr[Debug::KBMAP] << "Found it!" << endl;
350 return static_cast<tex_accent>(i);