1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "chset.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyxlex.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
CharacterSet::CharacterSet()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
map_=0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CharacterSet::~CharacterSet()
|
|
|
|
{
|
|
|
|
freeMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CharacterSet::freeMap()
|
|
|
|
{
|
|
|
|
Cdef* t;
|
|
|
|
while(map_) {
|
|
|
|
t=map_;
|
|
|
|
map_=map_->next;
|
|
|
|
delete t;
|
|
|
|
}
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
name_.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
bool CharacterSet::loadFile(const string& fname)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
freeMap();
|
|
|
|
|
|
|
|
if (fname.empty() || fname=="ascii")
|
|
|
|
return true; // ascii 7-bit
|
|
|
|
|
|
|
|
// open definition file
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP]
|
|
|
|
<< "Opening keymap file " << fname << ".cdef" << endl;
|
1999-10-02 16:21:10 +00:00
|
|
|
string filename = LibFileSearch("kbd", fname.c_str(), "cdef");
|
1999-09-27 18:44:28 +00:00
|
|
|
FilePtr f(filename, FilePtr::read);
|
|
|
|
if (filename.empty() || !f()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Unable to open keymap file" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return true; // no definition, use 7-bit ascii
|
|
|
|
}
|
|
|
|
|
|
|
|
name_=fname;
|
|
|
|
|
|
|
|
// now read the file
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXLex lex(0,0);
|
1999-09-27 18:44:28 +00:00
|
|
|
lex.setFile(f());
|
|
|
|
|
|
|
|
bool error=false;
|
1999-10-02 16:21:10 +00:00
|
|
|
string str;
|
1999-09-27 18:44:28 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
while(lex.IsOK() && !error) {
|
|
|
|
|
|
|
|
switch(lex.lex()){
|
|
|
|
case LyXLex::LEX_FEOF :
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "End of parsing of .cdef file"
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Get Integer
|
|
|
|
n=lex.GetInteger();
|
|
|
|
if (n<0) {
|
|
|
|
error=true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get String
|
|
|
|
lex.next(true);
|
|
|
|
str=lex.GetString();
|
|
|
|
|
|
|
|
Cdef* tempc=new Cdef;
|
|
|
|
tempc->str=str;
|
|
|
|
tempc->ic=n;
|
|
|
|
tempc->next=map_;
|
|
|
|
map_=tempc;
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "Chardef: " << n
|
|
|
|
<< " to [" << tempc->str << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-19 16:48:35 +00:00
|
|
|
bool CharacterSet::encodeString(string & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
Cdef *t=map_;
|
|
|
|
|
|
|
|
while(t) {
|
|
|
|
if (t->str==str) {
|
1999-10-19 16:48:35 +00:00
|
|
|
// Can this fail? Why is ic an unsigned char?
|
|
|
|
str = char(t->ic);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
t=t->next;
|
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
return (t!=0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string CharacterSet::getName()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|