1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "trans.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "trans.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "tex-strings.h"
|
|
|
|
#include "lyxlex.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "trans_mgr.h"
|
|
|
|
|
|
|
|
|
|
|
|
// KmodInfo
|
|
|
|
KmodInfo::KmodInfo()
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
exception_list = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Default Trans
|
1999-11-15 12:01:38 +00:00
|
|
|
bool DefaultTrans::init_ = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
DefaultTrans::DefaultTrans()
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
if (init_ == false) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Do initialization
|
1999-11-15 12:01:38 +00:00
|
|
|
init_ = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
string DefaultTrans::process(char c, TransManager & k)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
char dummy[2] = "?";
|
|
|
|
dummy[0] = c;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
return k.normalkey(c, dummy);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Trans class
|
|
|
|
|
|
|
|
Trans::Trans()
|
|
|
|
{
|
1999-12-16 06:43:25 +00:00
|
|
|
int i = 0;
|
|
|
|
for(; i < 256; ++i)
|
1999-11-15 12:01:38 +00:00
|
|
|
keymap_[i] = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
|
|
|
|
kmod_list_[i] = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Trans::~Trans()
|
|
|
|
{
|
|
|
|
FreeKeymap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
void Trans::InsertException(Trans::keyexc & exclist, char c,
|
|
|
|
string const & data, bool flag, tex_accent accent)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
keyexc p;
|
|
|
|
|
|
|
|
p = new Keyexc;
|
1999-11-15 12:01:38 +00:00
|
|
|
p->next = exclist;
|
|
|
|
p->c = c;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
p->data = data;
|
1999-11-15 12:01:38 +00:00
|
|
|
p->combined = flag;
|
|
|
|
p->accent = accent;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
exclist = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
void Trans::FreeException(Trans::keyexc & exclist)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-16 06:43:25 +00:00
|
|
|
Trans::keyexc p = exclist;
|
1999-09-27 18:44:28 +00:00
|
|
|
while (p) {
|
|
|
|
p = exclist->next;
|
|
|
|
delete exclist;
|
|
|
|
exclist = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Trans::FreeKeymap()
|
|
|
|
{
|
1999-12-16 06:43:25 +00:00
|
|
|
int i = 0;
|
|
|
|
for(; i < 256; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
if (keymap_[i]) {
|
|
|
|
delete keymap_[i];
|
1999-11-15 12:01:38 +00:00
|
|
|
keymap_[i] = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
for(i = 0; i < TEX_MAX_ACCENT + 1; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
if (kmod_list_[i]) {
|
|
|
|
FreeException(kmod_list_[i]->exception_list);
|
|
|
|
delete kmod_list_[i];
|
1999-11-15 12:01:38 +00:00
|
|
|
kmod_list_[i] = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Trans::IsDefined()
|
|
|
|
{
|
|
|
|
return !name_.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
string const & Trans::GetName()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum _kmaptags {
|
1999-11-15 12:01:38 +00:00
|
|
|
KCOMB = 1,
|
1999-09-27 18:44:28 +00:00
|
|
|
KMOD,
|
|
|
|
KMAP,
|
|
|
|
KXMOD,
|
|
|
|
K_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
struct keyword_item kmapTags[K_LAST - 1] = {
|
1999-11-15 12:01:38 +00:00
|
|
|
{"\\kcomb", KCOMB },
|
1999-09-27 18:44:28 +00:00
|
|
|
{ "\\kmap", KMAP },
|
|
|
|
{ "\\kmod", KMOD },
|
|
|
|
{ "\\kxmod", KXMOD }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
tex_accent getkeymod(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
void Trans::AddDeadkey(tex_accent accent, string const & keys,
|
|
|
|
string const & allowed)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (kmod_list_[accent]) {
|
|
|
|
FreeException(kmod_list_[accent]->exception_list);
|
|
|
|
|
|
|
|
delete kmod_list_[accent];
|
|
|
|
}
|
|
|
|
|
|
|
|
kmod_list_[accent] = new kmod_list_decl;
|
|
|
|
kmod_list_[accent]->data = keys;
|
|
|
|
kmod_list_[accent]->accent = accent;
|
1999-11-15 12:01:38 +00:00
|
|
|
if (allowed == "all") {
|
|
|
|
kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
|
|
|
kmod_list_[accent]->allowed = allowed;
|
|
|
|
}
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
for(string::size_type i = 0; i < keys.length(); ++i) {
|
1999-12-13 00:05:34 +00:00
|
|
|
char * temp =
|
1999-12-13 21:59:26 +00:00
|
|
|
keymap_[static_cast<unsigned char>(keys[i])] =
|
1999-12-13 00:05:34 +00:00
|
|
|
new char[2];
|
1999-10-02 16:21:10 +00:00
|
|
|
temp[0] = 0; temp[1] = accent;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
kmod_list_[accent]->exception_list = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
int Trans::Load(LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
while (lex.IsOK() && !error) {
|
|
|
|
switch(lex.lex()) {
|
|
|
|
case KMOD:
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "KMOD:\t" << lex.text() << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lex.next(true)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "key\t`" << lex.text()
|
|
|
|
<< "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string keys = lex.GetString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lex.next(true)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if ( lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "accent\t`" << lex.text()
|
|
|
|
<< "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
tex_accent accent = getkeymod(lex.GetString());
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
if (accent == TEX_NOACCENT)
|
1999-09-27 18:44:28 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (lex.next(true)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "allowed\t`" << lex.text()
|
|
|
|
<< "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string allowed = lex.GetString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
AddDeadkey(accent, keys, allowed);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KCOMB: {
|
1999-11-15 12:01:38 +00:00
|
|
|
char const * str;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "KCOMB:" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lex.next(true)) {
|
1999-11-15 12:01:38 +00:00
|
|
|
str= lex.text();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << str << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
tex_accent accent_1 = getkeymod(str);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (accent_1 == TEX_NOACCENT) return -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lex.next(true)) {
|
1999-12-13 00:05:34 +00:00
|
|
|
str = lex.text();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << str << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
tex_accent accent_2= getkeymod(str);
|
|
|
|
if (accent_2 == TEX_NOACCENT) return -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
if (kmod_list_[accent_1] == 0
|
|
|
|
|| kmod_list_[accent_2] == 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
return -1;
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
// Find what key accent_2 is on - should
|
|
|
|
// check about accent_1 also
|
|
|
|
int key = 0;
|
|
|
|
for(; key < 256; ++key) {
|
1999-11-15 12:01:38 +00:00
|
|
|
if (keymap_[key] && keymap_[key][0] == 0
|
|
|
|
&& keymap_[key][1] == accent_2)
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-11-15 12:01:38 +00:00
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
string allowed;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lex.next()) {
|
1999-11-15 12:01:38 +00:00
|
|
|
allowed = lex.GetString();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "allowed: "
|
|
|
|
<< allowed << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
InsertException(kmod_list_[accent_1]->exception_list,
|
|
|
|
static_cast<char>(key), allowed,
|
|
|
|
true, accent_2);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KMAP: {
|
1999-12-10 00:07:59 +00:00
|
|
|
unsigned char key_from;
|
1999-11-15 12:01:38 +00:00
|
|
|
char * string_to;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "KMAP:\t" << lex.text() << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lex.next(true)) {
|
1999-11-15 12:01:38 +00:00
|
|
|
key_from= lex.text()[0];
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "\t`" << lex.text() << "'"
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (lex.next(true)) {
|
1999-11-15 12:01:38 +00:00
|
|
|
char const * t = lex.text();
|
|
|
|
string_to = strcpy(new char[strlen(t)+1], t);
|
|
|
|
keymap_[key_from] = string_to;
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "\t`" << string_to << "'"
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KXMOD: {
|
|
|
|
tex_accent accent;
|
|
|
|
char key;
|
1999-11-15 12:01:38 +00:00
|
|
|
char const * str;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "KXMOD:\t" << lex.text() << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lex.next(true)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "\t`" << lex.text() << "'"
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
accent = getkeymod(lex.GetString());
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (lex.next(true)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "\t`" << lex.text() << "'"
|
|
|
|
<< endl;
|
1999-11-15 12:01:38 +00:00
|
|
|
key = lex.text()[0];
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (lex.next(true)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "\t`" << lex.text() << "'"
|
|
|
|
<< endl;
|
1999-11-15 12:01:38 +00:00
|
|
|
str = lex.text();
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
InsertException(kmod_list_[accent]->exception_list,
|
|
|
|
key, str);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LyXLex::LEX_FEOF:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::PARSER] << "End of parsing" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lex.printError("ParseKeymapFile: "
|
|
|
|
"Unknown tag: `$$Token'");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
if (kmod_list_[accent]!= 0) {
|
|
|
|
i = *kmod_list_[accent];
|
1999-09-27 18:44:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
string Trans::process(char c, TransManager & k)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
char dummy[2] = "?";
|
|
|
|
char * dt = dummy;
|
1999-12-13 21:59:26 +00:00
|
|
|
char * t = Match(static_cast<unsigned char>(c));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
if ((t == 0 && (*dt = c)) || (t[0] != 0 && (dt = t)) ){
|
1999-11-15 12:01:38 +00:00
|
|
|
return k.normalkey(c, dt);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-12-16 06:43:25 +00:00
|
|
|
return k.deadkey(c,
|
|
|
|
*kmod_list_[static_cast<tex_accent>(t[1])]);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
int Trans::Load(string const & language)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string filename = LibFileSearch("kbd", language, "kmap");
|
1999-09-27 18:44:28 +00:00
|
|
|
if (filename.empty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
FreeKeymap();
|
|
|
|
LyXLex lex(kmapTags, K_LAST-1);
|
|
|
|
lex.setFile(filename);
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
int res = Load(lex);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
if (res == 0) {
|
|
|
|
name_ = language;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
1999-10-19 20:59:27 +00:00
|
|
|
name_.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
tex_accent getkeymod(string const & p)
|
1999-09-27 18:44:28 +00:00
|
|
|
/* return modifier - decoded from p and update p */
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "p = " << p
|
|
|
|
<< ", lyx_accent_table[" << i
|
1999-11-15 12:01:38 +00:00
|
|
|
<< "].name = `" << lyx_accent_table[i].name
|
1999-10-07 18:44:17 +00:00
|
|
|
<< "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
if ( lyx_accent_table[i].name
|
|
|
|
&& contains(p, lyx_accent_table[i].name)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "Found it!" << endl;
|
1999-12-13 00:05:34 +00:00
|
|
|
return static_cast<tex_accent>(i);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TEX_NOACCENT;
|
|
|
|
}
|