4 #include "support/filetools.h"
5 #include "support/lstrings.h"
6 #include "tex-strings.h"
11 using namespace lyx::support;
36 void Trans::InsertException(KmodException & exclist, char c,
37 string const & data, bool flag, tex_accent accent)
44 exclist.insert(exclist.begin(), p);
46 // exclist.push_back(p);
50 void Trans::FreeException(KmodException & exclist)
56 void Trans::FreeKeymap()
63 bool Trans::IsDefined() const
65 return !name_.empty();
69 string const & Trans::GetName() const
84 struct keyword_item kmapTags[K_LAST - 1] = {
92 tex_accent getkeymod(string const &);
95 void Trans::AddDeadkey(tex_accent accent, string const & keys)
100 kmod_list_[accent] = tmp;
102 for (string::size_type i = 0; i < keys.length(); ++i) {
106 keymap_[keys[i]] = tmp;
111 int Trans::Load(LyXLex & lex)
115 while (lex.isOK() && !error) {
119 if (lyxerr.debugging(Debug::KBMAP))
120 lyxerr << "KMOD:\t" << lex.getString() << endl;
121 if (lex.next(true)) {
122 if (lyxerr.debugging(Debug::KBMAP))
123 lyxerr << "key\t`" << lex.getString()
128 string const keys = lex.getString();
130 if (lex.next(true)) {
131 if (lyxerr.debugging(Debug::KBMAP))
132 lyxerr << "accent\t`" << lex.getString()
137 tex_accent accent = getkeymod(lex.getString());
139 if (accent == TEX_NOACCENT)
143 //#warning This code should be removed...
144 // But we need to fix up all the kmap files first
145 // so that this field is not present anymore.
146 if (lex.next(true)) {
147 if (lyxerr.debugging(Debug::KBMAP))
148 lyxerr << "allowed\t`" << lex.getString()
153 /* string const allowed = lex.getString(); */
154 AddDeadkey(accent, keys /*, allowed*/);
156 AddDeadkey(accent, keys);
163 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
164 if (lex.next(true)) {
165 str = lex.getString();
166 lyxerr[Debug::KBMAP] << str << endl;
170 tex_accent accent_1 = getkeymod(str);
171 if (accent_1 == TEX_NOACCENT) return -1;
173 if (lex.next(true)) {
174 str = lex.getString();
175 lyxerr[Debug::KBMAP] << str << endl;
179 tex_accent accent_2= getkeymod(str);
180 if (accent_2 == TEX_NOACCENT) return -1;
182 map<int, KmodInfo>::iterator it1 =
183 kmod_list_.find(accent_1);
184 map<int, KmodInfo>::iterator it2 =
185 kmod_list_.find(accent_2);
186 if (it1 == kmod_list_.end()
187 || it2 == kmod_list_.end()) {
191 // Find what key accent_2 is on - should
192 // check about accent_1 also
193 map<int, string>::iterator it = keymap_.begin();
194 map<int, string>::iterator end = keymap_.end();
195 for (; it != end; ++it) {
196 if (!it->second.empty()
197 && it->second[0] == 0
198 && it->second[1] == accent_2)
203 allowed = lex.getString();
204 lyxerr[Debug::KBMAP] << "allowed: "
210 InsertException(kmod_list_[accent_1].exception_list,
211 static_cast<char>(it->first), allowed,
216 unsigned char key_from;
218 if (lyxerr.debugging(Debug::KBMAP))
219 lyxerr << "KMAP:\t" << lex.getString() << endl;
220 if (lex.next(true)) {
221 key_from = lex.getString()[0];
222 if (lyxerr.debugging(Debug::KBMAP))
223 lyxerr << "\t`" << lex.getString() << '\''
228 if (lex.next(true)) {
229 string const string_to = lex.getString();
230 keymap_[key_from] = string_to;
231 if (lyxerr.debugging(Debug::KBMAP))
232 lyxerr << "\t`" << string_to << '\''
244 if (lyxerr.debugging(Debug::KBMAP))
245 lyxerr << "KXMOD:\t" << lex.getString() << endl;
246 if (lex.next(true)) {
247 if (lyxerr.debugging(Debug::KBMAP))
248 lyxerr << "\t`" << lex.getString() << '\''
250 accent = getkeymod(lex.getString());
254 if (lex.next(true)) {
255 if (lyxerr.debugging(Debug::KBMAP))
256 lyxerr << "\t`" << lex.getString() << '\''
258 key = lex.getString()[0];
262 if (lex.next(true)) {
263 if (lyxerr.debugging(Debug::KBMAP))
264 lyxerr << "\t`" << lex.getString() << '\''
266 str = lex.getString();
270 InsertException(kmod_list_[accent].exception_list,
274 case LyXLex::LEX_FEOF:
275 lyxerr[Debug::PARSER] << "End of parsing" << endl;
278 lex.printError("ParseKeymapFile: "
279 "Unknown tag: `$$Token'");
287 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
289 map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
290 if (cit != kmod_list_.end()) {
298 string const Trans::process(char c, TransManager & k)
300 string const t = Match(static_cast<unsigned char>(c));
302 if (t.empty() && c != 0) {
303 return k.normalkey(c);
304 } else if (!t.empty() && t[0] != char(0)) {
305 //return k.normalkey(c);
309 kmod_list_[static_cast<tex_accent>(t[1])]);
314 int Trans::Load(string const & language)
316 string const filename = LibFileSearch("kbd", language, "kmap");
317 if (filename.empty())
321 LyXLex lex(kmapTags, K_LAST - 1);
322 lex.setFile(filename);
324 int const res = Load(lex);
335 tex_accent getkeymod(string const & p)
336 /* return modifier - decoded from p and update p */
338 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
339 if (lyxerr.debugging(Debug::KBMAP))
340 lyxerr << "p = " << p
341 << ", lyx_accent_table[" << i
342 << "].name = `" << lyx_accent_table[i].name
345 if (lyx_accent_table[i].name
346 && contains(p, lyx_accent_table[i].name)) {
347 lyxerr[Debug::KBMAP] << "Found it!" << endl;
348 return static_cast<tex_accent>(i);