3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Matthias Ettrich
9 * Full author contact details are available in file CREDITS.
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
19 #include "trans_mgr.h"
21 using namespace lyx::support;
46 void Trans::InsertException(KmodException & exclist, char c,
47 string const & data, bool flag, tex_accent accent)
54 exclist.insert(exclist.begin(), p);
56 // exclist.push_back(p);
60 void Trans::FreeException(KmodException & exclist)
66 void Trans::FreeKeymap()
73 bool Trans::IsDefined() const
75 return !name_.empty();
79 string const & Trans::GetName() const
94 struct keyword_item kmapTags[K_LAST - 1] = {
102 tex_accent getkeymod(string const &);
105 void Trans::AddDeadkey(tex_accent accent, string const & keys)
110 kmod_list_[accent] = tmp;
112 for (string::size_type i = 0; i < keys.length(); ++i) {
116 keymap_[keys[i]] = tmp;
121 int Trans::Load(LyXLex & lex)
125 while (lex.isOK() && !error) {
129 if (lyxerr.debugging(Debug::KBMAP))
130 lyxerr << "KMOD:\t" << lex.getString() << endl;
131 if (lex.next(true)) {
132 if (lyxerr.debugging(Debug::KBMAP))
133 lyxerr << "key\t`" << lex.getString()
138 string const keys = lex.getString();
140 if (lex.next(true)) {
141 if (lyxerr.debugging(Debug::KBMAP))
142 lyxerr << "accent\t`" << lex.getString()
147 tex_accent accent = getkeymod(lex.getString());
149 if (accent == TEX_NOACCENT)
153 //#warning This code should be removed...
154 // But we need to fix up all the kmap files first
155 // so that this field is not present anymore.
156 if (lex.next(true)) {
157 if (lyxerr.debugging(Debug::KBMAP))
158 lyxerr << "allowed\t`" << lex.getString()
163 /* string const allowed = lex.getString(); */
164 AddDeadkey(accent, keys /*, allowed*/);
166 AddDeadkey(accent, keys);
173 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
174 if (lex.next(true)) {
175 str = lex.getString();
176 lyxerr[Debug::KBMAP] << str << endl;
180 tex_accent accent_1 = getkeymod(str);
181 if (accent_1 == TEX_NOACCENT) return -1;
183 if (lex.next(true)) {
184 str = lex.getString();
185 lyxerr[Debug::KBMAP] << str << endl;
189 tex_accent accent_2= getkeymod(str);
190 if (accent_2 == TEX_NOACCENT) return -1;
192 map<int, KmodInfo>::iterator it1 =
193 kmod_list_.find(accent_1);
194 map<int, KmodInfo>::iterator it2 =
195 kmod_list_.find(accent_2);
196 if (it1 == kmod_list_.end()
197 || it2 == kmod_list_.end()) {
201 // Find what key accent_2 is on - should
202 // check about accent_1 also
203 map<int, string>::iterator it = keymap_.begin();
204 map<int, string>::iterator end = keymap_.end();
205 for (; it != end; ++it) {
206 if (!it->second.empty()
207 && it->second[0] == 0
208 && it->second[1] == accent_2)
213 allowed = lex.getString();
214 lyxerr[Debug::KBMAP] << "allowed: "
220 InsertException(kmod_list_[accent_1].exception_list,
221 static_cast<char>(it->first), allowed,
226 unsigned char key_from;
228 if (lyxerr.debugging(Debug::KBMAP))
229 lyxerr << "KMAP:\t" << lex.getString() << endl;
230 if (lex.next(true)) {
231 key_from = lex.getString()[0];
232 if (lyxerr.debugging(Debug::KBMAP))
233 lyxerr << "\t`" << lex.getString() << '\''
238 if (lex.next(true)) {
239 string const string_to = lex.getString();
240 keymap_[key_from] = string_to;
241 if (lyxerr.debugging(Debug::KBMAP))
242 lyxerr << "\t`" << string_to << '\''
254 if (lyxerr.debugging(Debug::KBMAP))
255 lyxerr << "KXMOD:\t" << lex.getString() << endl;
256 if (lex.next(true)) {
257 if (lyxerr.debugging(Debug::KBMAP))
258 lyxerr << "\t`" << lex.getString() << '\''
260 accent = getkeymod(lex.getString());
264 if (lex.next(true)) {
265 if (lyxerr.debugging(Debug::KBMAP))
266 lyxerr << "\t`" << lex.getString() << '\''
268 key = lex.getString()[0];
272 if (lex.next(true)) {
273 if (lyxerr.debugging(Debug::KBMAP))
274 lyxerr << "\t`" << lex.getString() << '\''
276 str = lex.getString();
280 InsertException(kmod_list_[accent].exception_list,
284 case LyXLex::LEX_FEOF:
285 lyxerr[Debug::PARSER] << "End of parsing" << endl;
288 lex.printError("ParseKeymapFile: "
289 "Unknown tag: `$$Token'");
297 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
299 map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
300 if (cit != kmod_list_.end()) {
308 string const Trans::process(char c, TransManager & k)
310 string const t = Match(static_cast<unsigned char>(c));
312 if (t.empty() && c != 0) {
313 return k.normalkey(c);
314 } else if (!t.empty() && t[0] != char(0)) {
315 //return k.normalkey(c);
319 kmod_list_[static_cast<tex_accent>(t[1])]);
324 int Trans::Load(string const & language)
326 string const filename = LibFileSearch("kbd", language, "kmap");
327 if (filename.empty())
331 LyXLex lex(kmapTags, K_LAST - 1);
332 lex.setFile(filename);
334 int const res = Load(lex);
345 tex_accent getkeymod(string const & p)
346 /* return modifier - decoded from p and update p */
348 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
349 if (lyxerr.debugging(Debug::KBMAP))
350 lyxerr << "p = " << p
351 << ", lyx_accent_table[" << i
352 << "].name = `" << lyx_accent_table[i].name
355 if (lyx_accent_table[i].name
356 && contains(p, lyx_accent_table[i].name)) {
357 lyxerr[Debug::KBMAP] << "Found it!" << endl;
358 return static_cast<tex_accent>(i);