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"
17 #include "tex-strings.h"
20 #include "trans_mgr.h"
22 using namespace lyx::support;
47 void Trans::InsertException(KmodException & exclist, char c,
48 string const & data, bool flag, tex_accent accent)
55 exclist.insert(exclist.begin(), p);
57 // exclist.push_back(p);
61 void Trans::FreeException(KmodException & exclist)
67 void Trans::FreeKeymap()
74 bool Trans::IsDefined() const
76 return !name_.empty();
80 string const & Trans::GetName() const
95 struct keyword_item kmapTags[K_LAST - 1] = {
103 tex_accent getkeymod(string const &);
106 void Trans::AddDeadkey(tex_accent accent, string const & keys)
111 kmod_list_[accent] = tmp;
113 for (string::size_type i = 0; i < keys.length(); ++i) {
117 keymap_[keys[i]] = tmp;
122 int Trans::Load(LyXLex & lex)
126 while (lex.isOK() && !error) {
130 if (lyxerr.debugging(Debug::KBMAP))
131 lyxerr << "KMOD:\t" << lex.getString() << endl;
132 if (lex.next(true)) {
133 if (lyxerr.debugging(Debug::KBMAP))
134 lyxerr << "key\t`" << lex.getString()
139 string const keys = lex.getString();
141 if (lex.next(true)) {
142 if (lyxerr.debugging(Debug::KBMAP))
143 lyxerr << "accent\t`" << lex.getString()
148 tex_accent accent = getkeymod(lex.getString());
150 if (accent == TEX_NOACCENT)
154 //#warning This code should be removed...
155 // But we need to fix up all the kmap files first
156 // so that this field is not present anymore.
157 if (lex.next(true)) {
158 if (lyxerr.debugging(Debug::KBMAP))
159 lyxerr << "allowed\t`" << lex.getString()
164 /* string const allowed = lex.getString(); */
165 AddDeadkey(accent, keys /*, allowed*/);
167 AddDeadkey(accent, keys);
174 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
175 if (lex.next(true)) {
176 str = lex.getString();
177 lyxerr[Debug::KBMAP] << str << endl;
181 tex_accent accent_1 = getkeymod(str);
182 if (accent_1 == TEX_NOACCENT) return -1;
184 if (lex.next(true)) {
185 str = lex.getString();
186 lyxerr[Debug::KBMAP] << str << endl;
190 tex_accent accent_2= getkeymod(str);
191 if (accent_2 == TEX_NOACCENT) return -1;
193 map<int, KmodInfo>::iterator it1 =
194 kmod_list_.find(accent_1);
195 map<int, KmodInfo>::iterator it2 =
196 kmod_list_.find(accent_2);
197 if (it1 == kmod_list_.end()
198 || it2 == kmod_list_.end()) {
202 // Find what key accent_2 is on - should
203 // check about accent_1 also
204 map<int, string>::iterator it = keymap_.begin();
205 map<int, string>::iterator end = keymap_.end();
206 for (; it != end; ++it) {
207 if (!it->second.empty()
208 && it->second[0] == 0
209 && it->second[1] == accent_2)
214 allowed = lex.getString();
215 lyxerr[Debug::KBMAP] << "allowed: "
221 InsertException(kmod_list_[accent_1].exception_list,
222 static_cast<char>(it->first), allowed,
227 unsigned char key_from;
229 if (lyxerr.debugging(Debug::KBMAP))
230 lyxerr << "KMAP:\t" << lex.getString() << endl;
231 if (lex.next(true)) {
232 key_from = lex.getString()[0];
233 if (lyxerr.debugging(Debug::KBMAP))
234 lyxerr << "\t`" << lex.getString() << '\''
239 if (lex.next(true)) {
240 string const string_to = lex.getString();
241 keymap_[key_from] = string_to;
242 if (lyxerr.debugging(Debug::KBMAP))
243 lyxerr << "\t`" << string_to << '\''
255 if (lyxerr.debugging(Debug::KBMAP))
256 lyxerr << "KXMOD:\t" << lex.getString() << endl;
257 if (lex.next(true)) {
258 if (lyxerr.debugging(Debug::KBMAP))
259 lyxerr << "\t`" << lex.getString() << '\''
261 accent = getkeymod(lex.getString());
265 if (lex.next(true)) {
266 if (lyxerr.debugging(Debug::KBMAP))
267 lyxerr << "\t`" << lex.getString() << '\''
269 key = lex.getString()[0];
273 if (lex.next(true)) {
274 if (lyxerr.debugging(Debug::KBMAP))
275 lyxerr << "\t`" << lex.getString() << '\''
277 str = lex.getString();
281 InsertException(kmod_list_[accent].exception_list,
285 case LyXLex::LEX_FEOF:
286 lyxerr[Debug::PARSER] << "End of parsing" << endl;
289 lex.printError("ParseKeymapFile: "
290 "Unknown tag: `$$Token'");
298 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
300 map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
301 if (cit != kmod_list_.end()) {
309 string const Trans::process(char c, TransManager & k)
311 string const t = Match(static_cast<unsigned char>(c));
313 if (t.empty() && c != 0) {
314 return k.normalkey(c);
315 } else if (!t.empty() && t[0] != char(0)) {
316 //return k.normalkey(c);
320 kmod_list_[static_cast<tex_accent>(t[1])]);
325 int Trans::Load(string const & language)
327 string const filename = LibFileSearch("kbd", language, "kmap");
328 if (filename.empty())
332 LyXLex lex(kmapTags, K_LAST - 1);
333 lex.setFile(filename);
335 int const res = Load(lex);
346 tex_accent getkeymod(string const & p)
347 /* return modifier - decoded from p and update p */
349 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
350 if (lyxerr.debugging(Debug::KBMAP))
351 lyxerr << "p = " << p
352 << ", lyx_accent_table[" << i
353 << "].name = `" << lyx_accent_table[i].name
356 if (lyx_accent_table[i].name
357 && contains(p, lyx_accent_table[i].name)) {
358 lyxerr[Debug::KBMAP] << "Found it!" << endl;
359 return static_cast<tex_accent>(i);