2001-12-05 Lars Gullik Bjønnes <larsbj@birdstep.com>
+ * trans_decl.h:
+ * trans_mgr.[Ch]:
+ * trans.[Ch]:
+ * lyxgluelength.C:
+ * lyxlength.C: remove out-commented code.
+
* BufferView_pimpl:
* CutAndPaste.C:
* DepTable.C:
#include "Lsstream.h"
-#if 0
-namespace {
-// this is now here and in lyxlenght.h
-
-int const num_units = LyXLength::UNIT_NONE;
-
-// I am not sure if "mu" should be possible to select (Lgb)
-char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
- "mm", "pc", "cc", "cm",
- "in", "ex", "em", "mu",
- "%", "c%", "p%", "l%" };
-
-}
-#endif
LyXGlueLength::LyXGlueLength(LyXLength const & len)
: len_(len)
#include <cstdlib>
-#if 0
-namespace {
-// this is now here and in lyxgluelength.C
-
-int const num_units = LyXLength::UNIT_NONE;
-
-// I am not sure if "mu" should be possible to select (Lgb)
-char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
- "mm", "pc", "cc", "cm",
- "in", "ex", "em", "mu",
- "%", "c%", "p%", "l%" };
-
-
-LyXLength::UNIT unitFromString(string const & data)
-{
- int i = 0;
- while (i < num_units && data != unit_name[i])
- ++i;
- return static_cast<LyXLength::UNIT>(i);
-}
-
-}
-#endif
-
LyXLength::LyXLength()
: val_(0), unit_(LyXLength::PT)
// KmodInfo
KmodInfo::KmodInfo()
{
-#if 0
- exception_list = 0;
-#endif
-}
-
-
-#if 0
-// Default Trans
-bool DefaultTrans::init_ = false;
-
-
-DefaultTrans::DefaultTrans()
-{
- if (init_ == false) {
- // Do initialization
- init_ = true;
- }
}
-#if 0
-string const DefaultTrans::process(char c, TransManager & k)
-{
- char dummy[2] = "?";
- dummy[0] = c;
-
- return k.normalkey(c, dummy);
-}
-#else
-string const DefaultTrans::process(char c, TransManager & k)
-{
- return k.normalkey(c);
-}
-#endif
-#endif
-
// Trans class
Trans::Trans()
{
-#if 0
- for (int i = 0; i < TEX_MAX_ACCENT + 1; ++i)
- kmod_list_[i] = 0;
-#endif
}
void Trans::InsertException(KmodException & exclist, char c,
string const & data, bool flag, tex_accent accent)
{
-#if 0
- keyexc p = new Keyexc;
- p->next = exclist;
- p->c = c;
-
- p->data = data;
- p->combined = flag;
- p->accent = accent;
-
- exclist = p;
-#else
Keyexc p;
p.c = c;
p.data = data;
exclist.insert(exclist.begin(), p);
// or just
// exclist.push_back(p);
-#endif
}
void Trans::FreeException(KmodException & exclist)
{
-#if 0
- Trans::keyexc p = exclist;
- while (p) {
- p = exclist->next;
- delete exclist;
- exclist = p;
- }
-#else
exclist.clear();
-#endif
}
void Trans::FreeKeymap()
{
-#if 0
- for (int i = 0; i < 256; ++i)
- if (!keymap_[i].empty()) {
- keymap_[i].erase();
- }
- for (int i = 0; i < TEX_MAX_ACCENT + 1; ++i)
- if (kmod_list_[i]) {
- FreeException(kmod_list_[i]->exception_list);
- delete kmod_list_[i];
- kmod_list_[i] = 0;
- }
-#else
kmod_list_.clear();
keymap_.clear();
-#endif
}
tex_accent getkeymod(string const &);
-#if 0
-void Trans::AddDeadkey(tex_accent accent, string const & keys,
- string const & allowed)
-#else
void Trans::AddDeadkey(tex_accent accent, string const & keys)
-#endif
{
-#if 0
- if (kmod_list_[accent]) {
- FreeException(kmod_list_[accent]->exception_list);
-
- delete kmod_list_[accent];
- }
-
- kmod_list_[accent] = new KmodInfo;
- kmod_list_[accent]->data = keys;
- kmod_list_[accent]->accent = accent;
-#else
KmodInfo tmp;
tmp.data = keys;
tmp.accent = accent;
kmod_list_[accent] = tmp;
-#endif
-#if 0
- if (allowed == "native") {
- kmod_list_[accent]->allowed= lyx_accent_table[accent].native;
- } else {
- kmod_list_[accent]->allowed = allowed;
- }
- for (string::size_type i = 0; i < keys.length(); ++i) {
- string & temp =
- keymap_[static_cast<unsigned char>(keys[i])];
- if (!temp.empty())
- temp.erase();
-
- // But the question remains: "Should we be allowed
- // to change bindings, without unbinding first?"
- // Lgb
- temp += char(0);
- temp += char(accent);
- }
-#else
for (string::size_type i = 0; i < keys.length(); ++i) {
string tmp;
tmp += char(0);
tmp += char(accent);
keymap_[keys[i]] = tmp;
}
-#endif
-#if 0
- kmod_list_[accent]->exception_list = 0;
-#endif
}
tex_accent accent_2= getkeymod(str);
if (accent_2 == TEX_NOACCENT) return -1;
-#if 0
- if (kmod_list_[accent_1] == 0
- || kmod_list_[accent_2] == 0)
- return -1;
-#else
std::map<int, KmodInfo>::iterator it1 =
kmod_list_.find(accent_1);
std::map<int, KmodInfo>::iterator it2 =
|| it2 == kmod_list_.end()) {
return -1;
}
-#endif
// Find what key accent_2 is on - should
// check about accent_1 also
-#if 0
- int key = 0;
- for (; key < 256; ++key) {
- if (!keymap_[key].empty()
- && keymap_[key][0] == 0
- && keymap_[key][1] == accent_2)
- break;
- }
- string allowed;
-
- if (lex.next()) {
- allowed = lex.GetString();
- lyxerr[Debug::KBMAP] << "allowed: "
- << allowed << endl;
- } else
- return -1;
-
- InsertException(kmod_list_[accent_1].exception_list,
- static_cast<char>(key), allowed,
- true, accent_2);
-#else
std::map<int, string>::iterator it = keymap_.begin();
std::map<int, string>::iterator end = keymap_.end();
for (; it != end; ++it) {
InsertException(kmod_list_[accent_1].exception_list,
static_cast<char>(it->first), allowed,
true, accent_2);
-#endif
}
break;
case KMAP: {
bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
{
-#if 0
- if (kmod_list_[accent] != 0) {
- i = *kmod_list_[accent];
- return true;
- }
- return false;
-#else
std::map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
if (cit != kmod_list_.end()) {
i = cit->second;
return true;
}
return false;
-#endif
}
-#if 0
-string const Trans::process(char c, TransManager & k)
-{
- string dt("?");
- string const t = Match(static_cast<unsigned char>(c));
-
- if (t.empty() && c != 0) {
- dt[0] = c;
- return k.normalkey(c, dt);
- } else if (!t.empty() && t[0] != char(0)) {
- dt = t;
- return k.normalkey(c, dt);
- } else {
- return k.deadkey(c,
- *kmod_list_[static_cast<tex_accent>(t[1])]);
- }
-}
-#else
string const Trans::process(char c, TransManager & k)
{
string const t = Match(static_cast<unsigned char>(c));
//return k.normalkey(c);
return t;
} else {
-#if 0
- return k.deadkey(c,
- *kmod_list_[static_cast<tex_accent>(t[1])]);
-#else
return k.deadkey(c,
kmod_list_[static_cast<tex_accent>(t[1])]);
-#endif
}
}
-#endif
int Trans::Load(string const & language)
class TransManager;
-#if 0
-/**
- TransInterface: the interface that every translation class
- should obey too.
- Visitor pattern applied here
- */
-class TransInterface {
-public:
- ///
- virtual string const process(char, TransManager &) = 0;
- ///
- virtual bool isAccentDefined(tex_accent, KmodInfo &) const = 0;
-};
-
-/**
- DefaultTrans: the default translation class. Holds info
- on tex-accents. Monostate
- */
-class DefaultTrans : public TransInterface {
-public:
- ///
- DefaultTrans();
- ///
- virtual string const process(char, TransManager &);
-private:
- ///
- static bool init_;
-};
-#endif
-
/**
Trans: holds a .kmap file
*/
bool isAccentDefined(tex_accent, KmodInfo &) const;
private:
-#if 0
- ///
- typedef KmodInfo kmod_list_decl;
- ///
- typedef KmodException keyexc;
-#endif
-#if 0
- ///
- void AddDeadkey(tex_accent, string const &, string const &);
-#else
///
void AddDeadkey(tex_accent, string const &);
-#endif
///
void FreeKeymap();
///
int Load(LyXLex &);
///
- inline string const & Match(unsigned char c);
+ string const & Match(unsigned char c);
///
void InsertException(KmodException & exclist, char c,
string const & data, bool = false,
///
string name_;
-#if 0
///
- string keymap_[256];
-#else
std::map<int, string> keymap_;
-#endif
-#if 0
///
- kmod_list_decl * kmod_list_[TEX_MAX_ACCENT+1];
-#else
- ///
- //KmodInfo * kmod_list_[TEX_MAX_ACCENT+1];
std::map<int, KmodInfo> kmod_list_;
-#endif
};
///
+inline
string const & Trans::Match(unsigned char c)
{
-#if 0
- return keymap_[c];
-#else
std::map<int, string>::iterator it = keymap_.find(c);
if (it != keymap_.end()) {
return it->second;
}
static string dummy;
return dummy;
-#endif
}
#endif
#ifndef Trans_Decl_h
#define Trans_Decl_h
-#include <list>
-
#include "LString.h"
#include "tex-accent.h"
+#include <list>
+
+
///
struct Keyexc {
/// character to make exception
char c;
/// exception data
string data;
-#if 0
- ///
- Keyexc * next;
-#endif
/// Combination with another deadkey
bool combined;
/// The accent comined with
tex_accent accent;
};
-#if 0
-///
-typedef Keyexc * KmodException;
-#else
///
typedef std::list<Keyexc> KmodException;
-#endif
///
struct KmodInfo {
string data;
///
tex_accent accent;
-#if 0
- ///
- string allowed;
-#endif
///
KmodException exception_list;
///
{
deadkey_ = deadkey2_ = 0;
deadkey_info_.accent = deadkey2_info_.accent = TEX_NOACCENT;
-#if 0
- comb_info_ = 0;
-#endif
}
}
-#if 0
-string const TransInitState::normalkey(char c, string const & t)
-{
- string res;
- if (!t.empty()) res = t;
- else res = c;
-
- return res;
-}
-#else
string const TransInitState::normalkey(char c)
{
string res;
res = c;
return res;
}
-#endif
string const TransInitState::deadkey(char c, KmodInfo d)
}
-#if 0
-string const TransDeadkeyState::normalkey(char c, string const & trans)
-{
- string res;
-
- // Check if it is an exception
- KmodException l = deadkey_info_.exception_list;
- while (l != 0) {
- if (l->c == c) {
- res = l->data;
- break;
- }
- l = l->next;
- }
- if (l == 0) {
- // Not an exception. Check if it allowed
- if (countChar(deadkey_info_.allowed, c) > 0) {
- res = DoAccent(c, deadkey_info_.accent);
- } else {
- // Not allowed
- if (deadkey_!= 0)
- res = deadkey_;
- res+= TOKEN_SEP;
- res+= trans;
- }
- }
- currentState = init_state_;
- return res;
-}
-#else
string const TransDeadkeyState::normalkey(char c)
{
-#if 0
- string res;
-
- // Check if it is an exception
- KmodException l = deadkey_info_.exception_list;
- while (l != 0) {
- if (l->c == c) {
- res = l->data;
- break;
- }
- l = l->next;
- }
- if (l == 0) {
- res = DoAccent(c, deadkey_info_.accent);
- }
- currentState = init_state_;
- return res;
-#else
string res;
KmodException::iterator it = deadkey_info_.exception_list.begin();
}
currentState = init_state_;
return res;
-#endif
}
-#endif
string const TransDeadkeyState::deadkey(char c, KmodInfo d)
}
// Check if it is a combination or an exception
-#if 0
- KmodException l;
- l = deadkey_info_.exception_list;
-
- while (l) {
- if (l->combined == true && l->accent == d.accent) {
- deadkey2_ = c;
- deadkey2_info_ = d;
- comb_info_ = l;
- currentState = combined_state_;
- return string();
- }
- if (l->c == c) {
- res = l->data;
- deadkey_ = 0;
- deadkey_info_.accent = TEX_NOACCENT;
- currentState = init_state_;
- return res;
- }
- l = l->next;
- }
-#else
KmodException::const_iterator cit = deadkey_info_.exception_list.begin();
KmodException::const_iterator end = deadkey_info_.exception_list.end();
for (; cit != end; ++cit) {
return res;
}
}
-#endif
+
// Not a combination or an exception.
// Output deadkey1 and keep deadkey2
}
-#if 0
-string const TransCombinedState::normalkey(char c, string const & trans)
-{
- string res;
-
- // Check if the key is allowed on the combination
- if (countChar(comb_info_->data, c) > 0) {
- string const temp = DoAccent(c, deadkey2_info_.accent);
- res = DoAccent(temp, deadkey_info_.accent);
- currentState = init_state_;
- } else {
- // Not allowed. Output deadkey1 and check deadkey2 + c
- if (deadkey_ != 0)
- res += deadkey_;
- res += TOKEN_SEP;
- deadkey_ = deadkey2_;
- deadkey_info_ = deadkey2_info_;
- // Call deadkey state and leave it to setup the FSM
- res += deadkey_state_->normalkey(c, trans);
- }
- return res;
-}
-#else
string const TransCombinedState::normalkey(char c)
{
- string res;
-
string const temp = DoAccent(c, deadkey2_info_.accent);
- res = DoAccent(temp, deadkey_info_.accent);
+ string const res = DoAccent(temp, deadkey_info_.accent);
currentState = init_state_;
return res;
}
-#endif
string const TransCombinedState::deadkey(char c, KmodInfo d)
if (active_ == &default_ || c == 0) {
KmodInfo i;
i.accent = accent;
-#if 0
- i.allowed = lyx_accent_table[accent].native;
-#endif
i.data.erase();
-#if 0
- i.exception_list = 0;
-#endif
string res = trans_fsm_.currentState->deadkey(c, i);
insert(res, t);
} else {
public:
///
virtual ~TransState() {}
-#if 0
- ///
- virtual string const normalkey(char, string const &) = 0;
-#else
///
virtual string const normalkey(char) = 0;
-#endif
///
virtual bool backspace() = 0;
///
char deadkey2_;
///
KmodInfo deadkey2_info_;
-#if 0
- ///
- KmodException comb_info_;
-#else
///
Keyexc comb_info_;
-#endif
///
TransState * init_state_;
///
public:
///
TransInitState();
-#if 0
- ///
- virtual string const normalkey(char, string const &);
-#else
///
virtual string const normalkey(char);
-#endif
///
virtual bool backspace() { return true; }
///
public:
///
TransDeadkeyState();
-#if 0
- ///
- virtual string const normalkey(char, string const &);
-#else
///
virtual string const normalkey(char);
-#endif
///
virtual bool backspace() {
currentState = init_state_;
public:
///
TransCombinedState();
-#if 0
- ///
- virtual string const normalkey(char, string const &);
-#else
///
virtual string const normalkey(char);
-#endif
///
virtual bool backspace() {
// cancel the second deadkey
void TranslateAndInsert(char, LyXText *);
///
string const deadkey(char, KmodInfo);
-#if 0
- ///
- string const normalkey(char, string const &);
-#else
///
string const normalkey(char);
-#endif
///
void deadkey(char, tex_accent, LyXText *);
};
-#if 0
-inline
-string const TransManager::normalkey(char c, string const & t)
-{
- return trans_fsm_.currentState->normalkey(c, t);
-}
-#else
inline
string const TransManager::normalkey(char c)
{
return trans_fsm_.currentState->normalkey(c);
}
-#endif
inline