4 #include "support/filetools.h"
5 #include "support/lstrings.h"
6 #include "tex-strings.h"
34 void Trans::InsertException(KmodException & exclist, char c,
35 string const & data, bool flag, tex_accent accent)
42 exclist.insert(exclist.begin(), p);
44 // exclist.push_back(p);
48 void Trans::FreeException(KmodException & exclist)
54 void Trans::FreeKeymap()
61 bool Trans::IsDefined() const
63 return !name_.empty();
67 string const & Trans::GetName() const
82 struct keyword_item kmapTags[K_LAST - 1] = {
90 tex_accent getkeymod(string const &);
93 void Trans::AddDeadkey(tex_accent accent, string const & keys)
98 kmod_list_[accent] = tmp;
100 for (string::size_type i = 0; i < keys.length(); ++i) {
104 keymap_[keys[i]] = tmp;
109 int Trans::Load(LyXLex & lex)
113 while (lex.isOK() && !error) {
117 if (lyxerr.debugging(Debug::KBMAP))
118 lyxerr << "KMOD:\t" << lex.text() << endl;
119 if (lex.next(true)) {
120 if (lyxerr.debugging(Debug::KBMAP))
121 lyxerr << "key\t`" << lex.text()
126 string const keys = lex.getString();
128 if (lex.next(true)) {
129 if (lyxerr.debugging(Debug::KBMAP))
130 lyxerr << "accent\t`" << lex.text()
135 tex_accent accent = getkeymod(lex.getString());
137 if (accent == TEX_NOACCENT)
141 //#warning This code should be removed...
142 // But we need to fix up all the kmap files first
143 // so that this field is not present anymore.
144 if (lex.next(true)) {
145 if (lyxerr.debugging(Debug::KBMAP))
146 lyxerr << "allowed\t`" << lex.text()
151 /* string const allowed = lex.getString(); */
152 AddDeadkey(accent, keys /*, allowed*/);
154 AddDeadkey(accent, keys);
161 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
162 if (lex.next(true)) {
164 lyxerr[Debug::KBMAP] << str << endl;
168 tex_accent accent_1 = getkeymod(str);
169 if (accent_1 == TEX_NOACCENT) return -1;
171 if (lex.next(true)) {
173 lyxerr[Debug::KBMAP] << str << endl;
177 tex_accent accent_2= getkeymod(str);
178 if (accent_2 == TEX_NOACCENT) return -1;
180 map<int, KmodInfo>::iterator it1 =
181 kmod_list_.find(accent_1);
182 map<int, KmodInfo>::iterator it2 =
183 kmod_list_.find(accent_2);
184 if (it1 == kmod_list_.end()
185 || it2 == kmod_list_.end()) {
189 // Find what key accent_2 is on - should
190 // check about accent_1 also
191 map<int, string>::iterator it = keymap_.begin();
192 map<int, string>::iterator end = keymap_.end();
193 for (; it != end; ++it) {
194 if (!it->second.empty()
195 && it->second[0] == 0
196 && it->second[1] == accent_2)
201 allowed = lex.getString();
202 lyxerr[Debug::KBMAP] << "allowed: "
208 InsertException(kmod_list_[accent_1].exception_list,
209 static_cast<char>(it->first), allowed,
214 unsigned char key_from;
216 if (lyxerr.debugging(Debug::KBMAP))
217 lyxerr << "KMAP:\t" << lex.text() << endl;
218 if (lex.next(true)) {
219 key_from = lex.text()[0];
220 if (lyxerr.debugging(Debug::KBMAP))
221 lyxerr << "\t`" << lex.text() << '\''
226 if (lex.next(true)) {
227 string string_to = lex.text();
228 keymap_[key_from] = string_to;
229 if (lyxerr.debugging(Debug::KBMAP))
230 lyxerr << "\t`" << string_to << '\''
242 if (lyxerr.debugging(Debug::KBMAP))
243 lyxerr << "KXMOD:\t" << lex.text() << endl;
244 if (lex.next(true)) {
245 if (lyxerr.debugging(Debug::KBMAP))
246 lyxerr << "\t`" << lex.text() << '\''
248 accent = getkeymod(lex.getString());
252 if (lex.next(true)) {
253 if (lyxerr.debugging(Debug::KBMAP))
254 lyxerr << "\t`" << lex.text() << '\''
260 if (lex.next(true)) {
261 if (lyxerr.debugging(Debug::KBMAP))
262 lyxerr << "\t`" << lex.text() << '\''
268 InsertException(kmod_list_[accent].exception_list,
272 case LyXLex::LEX_FEOF:
273 lyxerr[Debug::PARSER] << "End of parsing" << endl;
276 lex.printError("ParseKeymapFile: "
277 "Unknown tag: `$$Token'");
285 bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
287 map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
288 if (cit != kmod_list_.end()) {
296 string const Trans::process(char c, TransManager & k)
298 string const t = Match(static_cast<unsigned char>(c));
300 if (t.empty() && c != 0) {
301 return k.normalkey(c);
302 } else if (!t.empty() && t[0] != char(0)) {
303 //return k.normalkey(c);
307 kmod_list_[static_cast<tex_accent>(t[1])]);
312 int Trans::Load(string const & language)
314 string const filename = LibFileSearch("kbd", language, "kmap");
315 if (filename.empty())
319 LyXLex lex(kmapTags, K_LAST - 1);
320 lex.setFile(filename);
322 int const res = Load(lex);
333 tex_accent getkeymod(string const & p)
334 /* return modifier - decoded from p and update p */
336 for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
337 if (lyxerr.debugging(Debug::KBMAP))
338 lyxerr << "p = " << p
339 << ", lyx_accent_table[" << i
340 << "].name = `" << lyx_accent_table[i].name
343 if (lyx_accent_table[i].name
344 && contains(p, lyx_accent_table[i].name)) {
345 lyxerr[Debug::KBMAP] << "Found it!" << endl;
346 return static_cast<tex_accent>(i);