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(Error::KBMAP))
202 fprintf(stderr,"KMOD: %s\n",lex.text());
203 if (lex.next(true)) {
204 if (lyxerr.debugging(Error::KBMAP))
205 fprintf(stderr, "key `%s'\n", lex.text());
209 string keys = lex.GetString();
211 if (lex.next(true)) {
212 if ( lyxerr.debugging(Error::KBMAP))
213 fprintf(stderr, "accent `%s'\n", lex.text());
217 tex_accent accent = getkeymod(lex.GetString());
219 if (accent==TEX_NOACCENT)
222 if (lex.next(true)) {
223 if (lyxerr.debugging(Error::KBMAP))
230 string allowed = lex.GetString();
232 AddDeadkey(accent, keys, allowed);
238 lyxerr.debug("KCOMB:",Error::KBMAP);
239 if (lex.next(true)) {
241 lyxerr.debug(str,Error::KBMAP);
245 tex_accent accent_1=getkeymod(str);
246 if (accent_1==TEX_NOACCENT) return -1;
248 if (lex.next(true)) {
250 lyxerr.debug(str,Error::KBMAP);
254 tex_accent accent_2=getkeymod(str);
255 if (accent_2==TEX_NOACCENT) return -1;
257 if (kmod_list_[accent_1]==0 || kmod_list_[accent_2]==0)
260 // Find what key accent_2 is on - should check about accent_1 also
263 for(key=0;key<256;key++)
264 if (keymap_[key] && keymap_[key][0]==0 && keymap_[key][1]==accent_2)
270 allowed=lex.GetString();
271 lyxerr.debug("allowed: "+allowed,Error::KBMAP);
275 InsertException(kmod_list_[accent_1]->exception_list,(char)key,allowed,true,accent_2);
282 if (lyxerr.debugging(Error::KBMAP))
283 fprintf(stderr, "KMAP: %s\n", lex.text());
284 if (lex.next(true)) {
285 key_from=lex.text()[0];
286 if (lyxerr.debugging(Error::KBMAP))
287 fprintf(stderr, " `%s'\n", lex.text());
291 if (lex.next(true)) {
292 char const *t = lex.text();
293 string_to = strcpy(new char[strlen(t)+1],t);
294 keymap_[(unsigned char)key_from]=string_to;
295 if (lyxerr.debugging(Error::KBMAP))
296 fprintf(stderr, " `%s'\n", string_to);
307 if (lyxerr.debugging(Error::KBMAP))
308 fprintf(stderr, "KXMOD: %s\n", lex.text());
309 if (lex.next(true)) {
310 if (lyxerr.debugging(Error::KBMAP))
311 fprintf(stderr, " `%s'\n", lex.text());
312 accent = getkeymod(lex.GetString());
316 if (lex.next(true)) {
317 if (lyxerr.debugging(Error::KBMAP))
318 fprintf(stderr, " `%s'\n", lex.text());
323 if (lex.next(true)) {
324 if (lyxerr.debugging(Error::KBMAP))
325 fprintf(stderr, " `%s'\n", lex.text());
330 InsertException(kmod_list_[accent]->exception_list,key,str);
333 case LyXLex::LEX_FEOF:
334 lyxerr.debug("End of parsing",Error::LEX_PARSER);
337 lex.printError("ParseKeymapFile: "
338 "Unknown tag: `$$Token'");
346 bool Trans::isAccentDefined(tex_accent accent,KmodInfo& i)
348 if (kmod_list_[accent]!=0) {
349 i=*kmod_list_[accent];
356 string Trans::process(char c,TransManager& k)
363 if ((t==0 && (*dt=c)) || (t[0]!=0 && (dt=t)) ){
364 return k.normalkey(c,dt);
366 return k.deadkey(c,*kmod_list_[(tex_accent)t[1]]);
371 int Trans::Load(string const &language)
373 string filename = LibFileSearch("kbd", language, "kmap");
374 if (filename.empty())
378 LyXLex lex(kmapTags, K_LAST-1);
379 lex.setFile(filename);
392 tex_accent getkeymod(string const &p)
393 /* return modifier - decoded from p and update p */
395 for (int i = 1; i <= TEX_MAX_ACCENT; i++) {
396 if (lyxerr.debugging(Error::KBMAP))
398 "p = %s, lyx_accent_table[%d].name = `%s'\n",
399 p.c_str(), i, lyx_accent_table[i].name);
401 if ( lyx_accent_table[i].name && contains(p, lyx_accent_table[i].name)) {
402 lyxerr.debug("Found it!",Error::KBMAP);
403 return (tex_accent)i;