6 #pragma implementation "trans.h"
11 #include "support/filetools.h"
12 #include "tex-strings.h"
15 #include "trans_mgr.h"
25 KmodInfo::KmodInfo(const KmodInfo& o)
31 KmodInfo& KmodInfo::operator=(const KmodInfo& o)
37 exception_list=o.exception_list;
45 bool DefaultTrans::init_=false;
48 DefaultTrans::DefaultTrans()
57 string DefaultTrans::process(char c,TransManager& k)
62 return k.normalkey(c,dummy);
75 for(i=0; i<TEX_MAX_ACCENT+1; i++)
86 void Trans::InsertException(Trans::keyexc& exclist, char c,
87 const string& data,bool flag,tex_accent accent)
103 void Trans::FreeException(Trans::keyexc& exclist)
116 void Trans::FreeKeymap()
125 for(i=0; i<TEX_MAX_ACCENT+1; i++)
127 FreeException(kmod_list_[i]->exception_list);
128 delete kmod_list_[i];
134 bool Trans::IsDefined()
136 return !name_.empty();
140 const string& Trans::GetName()
155 struct keyword_item kmapTags[K_LAST-1] = {
163 tex_accent getkeymod(const string&);
166 void Trans::AddDeadkey(tex_accent accent,const string& keys,
167 const string& allowed)
169 if (kmod_list_[accent]) {
170 FreeException(kmod_list_[accent]->exception_list);
172 delete kmod_list_[accent];
175 kmod_list_[accent] = new kmod_list_decl;
176 kmod_list_[accent]->data = keys;
177 kmod_list_[accent]->accent = accent;
178 if (allowed=="all") {
179 kmod_list_[accent]->allowed=lyx_accent_table[accent].native;
181 kmod_list_[accent]->allowed = allowed;
184 for(string::size_type i = 0; i < keys.length(); ++i) {
186 temp = keymap_[(unsigned char)keys[i]] = new char[2];
187 temp[0] = 0; temp[1] = accent;
189 kmod_list_[accent]->exception_list=0;
193 int Trans::Load(LyXLex &lex)
197 while (lex.IsOK() && !error) {
201 if (lyxerr.debugging(Debug::KBMAP))
202 lyxerr << "KMOD:\t" << lex.text() << endl;
203 if (lex.next(true)) {
204 if (lyxerr.debugging(Debug::KBMAP))
205 lyxerr << "key\t`" << lex.text()
210 string keys = lex.GetString();
212 if (lex.next(true)) {
213 if ( lyxerr.debugging(Debug::KBMAP))
214 lyxerr << "accent\t`" << lex.text()
219 tex_accent accent = getkeymod(lex.GetString());
221 if (accent==TEX_NOACCENT)
224 if (lex.next(true)) {
225 if (lyxerr.debugging(Debug::KBMAP))
226 lyxerr << "allowed\t`" << lex.text()
231 string allowed = lex.GetString();
233 AddDeadkey(accent, keys, allowed);
239 lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
240 if (lex.next(true)) {
242 lyxerr[Debug::KBMAP] << str << endl;
246 tex_accent accent_1=getkeymod(str);
247 if (accent_1==TEX_NOACCENT) return -1;
249 if (lex.next(true)) {
251 lyxerr[Debug::KBMAP] << str << endl;
255 tex_accent accent_2=getkeymod(str);
256 if (accent_2==TEX_NOACCENT) return -1;
258 if (kmod_list_[accent_1]==0 || kmod_list_[accent_2]==0)
261 // Find what key accent_2 is on - should check about accent_1 also
264 for(key=0;key<256;key++)
265 if (keymap_[key] && keymap_[key][0]==0 && keymap_[key][1]==accent_2)
271 allowed=lex.GetString();
272 lyxerr[Debug::KBMAP] << "allowed: "
277 InsertException(kmod_list_[accent_1]->exception_list,(char)key,allowed,true,accent_2);
284 if (lyxerr.debugging(Debug::KBMAP))
285 lyxerr << "KMAP:\t" << lex.text() << endl;
286 if (lex.next(true)) {
287 key_from=lex.text()[0];
288 if (lyxerr.debugging(Debug::KBMAP))
289 lyxerr << "\t`" << lex.text() << "'"
294 if (lex.next(true)) {
295 char const *t = lex.text();
296 string_to = strcpy(new char[strlen(t)+1],t);
297 keymap_[(unsigned char)key_from]=string_to;
298 if (lyxerr.debugging(Debug::KBMAP))
299 lyxerr << "\t`" << string_to << "'"
311 if (lyxerr.debugging(Debug::KBMAP))
312 lyxerr << "KXMOD:\t" << lex.text() << endl;
313 if (lex.next(true)) {
314 if (lyxerr.debugging(Debug::KBMAP))
315 lyxerr << "\t`" << lex.text() << "'"
317 accent = getkeymod(lex.GetString());
321 if (lex.next(true)) {
322 if (lyxerr.debugging(Debug::KBMAP))
323 lyxerr << "\t`" << lex.text() << "'"
329 if (lex.next(true)) {
330 if (lyxerr.debugging(Debug::KBMAP))
331 lyxerr << "\t`" << lex.text() << "'"
337 InsertException(kmod_list_[accent]->exception_list,key,str);
340 case LyXLex::LEX_FEOF:
341 lyxerr[Debug::PARSER] << "End of parsing" << endl;
344 lex.printError("ParseKeymapFile: "
345 "Unknown tag: `$$Token'");
353 bool Trans::isAccentDefined(tex_accent accent,KmodInfo& i)
355 if (kmod_list_[accent]!=0) {
356 i=*kmod_list_[accent];
363 string Trans::process(char c,TransManager& k)
370 if ((t==0 && (*dt=c)) || (t[0]!=0 && (dt=t)) ){
371 return k.normalkey(c,dt);
373 return k.deadkey(c,*kmod_list_[(tex_accent)t[1]]);
378 int Trans::Load(string const &language)
380 string filename = LibFileSearch("kbd", language, "kmap");
381 if (filename.empty())
385 LyXLex lex(kmapTags, K_LAST-1);
386 lex.setFile(filename);
399 tex_accent getkeymod(string const &p)
400 /* return modifier - decoded from p and update p */
402 for (int i = 1; i <= TEX_MAX_ACCENT; i++) {
403 if (lyxerr.debugging(Debug::KBMAP))
404 lyxerr << "p = " << p
405 << ", lyx_accent_table[" << i
406 <<"].name = `" << lyx_accent_table[i].name
409 if ( lyx_accent_table[i].name && contains(p, lyx_accent_table[i].name)) {
410 lyxerr[Debug::KBMAP] << "Found it!" << endl;
411 return (tex_accent)i;