1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "chset.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-11-15 12:01:38 +00:00
|
|
|
#include "support/LRegex.h"
|
|
|
|
#include "support/LSubstring.h"
|
2000-09-26 13:54:57 +00:00
|
|
|
#include "support/lyxlib.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::ifstream;
|
2000-05-04 10:57:00 +00:00
|
|
|
using std::getline;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::pair;
|
2000-02-04 09:38:32 +00:00
|
|
|
using std::make_pair;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
bool CharacterSet::loadFile(string const & fname)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
map_.clear();
|
2000-05-04 10:57:00 +00:00
|
|
|
name_.erase();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
|
|
|
if (fname.empty() || fname == "ascii")
|
1999-09-27 18:44:28 +00:00
|
|
|
return true; // ascii 7-bit
|
1999-11-15 12:01:38 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// open definition file
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP]
|
1999-12-15 14:50:27 +00:00
|
|
|
<< "Reading character set file " << fname << ".cdef" << endl;
|
2001-05-16 07:53:23 +00:00
|
|
|
string const filename = LibFileSearch("kbd", fname, "cdef");
|
1999-11-15 12:01:38 +00:00
|
|
|
ifstream ifs(filename.c_str());
|
|
|
|
if (!ifs) {
|
1999-12-15 14:50:27 +00:00
|
|
|
lyxerr << "Unable to open character set file" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return true; // no definition, use 7-bit ascii
|
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
name_ = fname;
|
|
|
|
|
|
|
|
string line;
|
1999-12-16 06:43:25 +00:00
|
|
|
// Ok, I'll be the first to admit that this is probably not
|
|
|
|
// the fastest way to parse the cdef files, but I though it
|
|
|
|
// was a bit neat. Anyway it is wrong to use the lyxlex parse
|
|
|
|
// without the use of a keyword table.
|
1999-11-15 12:01:38 +00:00
|
|
|
LRegex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
|
|
|
|
while(getline(ifs, line)) {
|
|
|
|
if (reg.exact_match(line)) {
|
|
|
|
LRegex::SubMatches const & sub = reg.exec(line);
|
2001-05-16 07:53:23 +00:00
|
|
|
int const n = lyx::atoi(line.substr(sub[1].first,
|
2000-09-26 13:54:57 +00:00
|
|
|
sub[1].second));
|
2001-05-16 07:53:23 +00:00
|
|
|
string const str = LSubstring(line, sub[2].first,
|
|
|
|
sub[2].second);
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "Chardef: " << n
|
1999-11-15 12:01:38 +00:00
|
|
|
<< " to [" << str << "]" << endl;
|
|
|
|
map_[str] = n;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
pair<bool, int> const CharacterSet::encodeString(string const & str) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-16 06:43:25 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "Checking if we know [" << str << "]" << endl;
|
|
|
|
bool ret = false;
|
|
|
|
int val = 0;
|
1999-11-15 12:01:38 +00:00
|
|
|
Cdef::const_iterator cit = map_.find(str);
|
1999-12-16 06:43:25 +00:00
|
|
|
if (cit != map_.end()) {
|
|
|
|
ret = true;
|
2001-07-12 11:11:10 +00:00
|
|
|
val = cit->second;
|
1999-12-16 06:43:25 +00:00
|
|
|
}
|
|
|
|
lyxerr[Debug::KBMAP] << " "
|
|
|
|
<< (ret ? "yes we" : "no we don't")
|
|
|
|
<< " know [" << str << "]" << endl;
|
|
|
|
return make_pair(ret, val);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
string const & CharacterSet::getName() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|