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"
|
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
|
|
|
|
2002-05-25 00:19:56 +00:00
|
|
|
#include <boost/regex.hpp>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
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;
|
2002-05-25 00:19:56 +00:00
|
|
|
using boost::regex;
|
|
|
|
using boost::regex_match;
|
|
|
|
using boost::smatch;
|
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();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
// ascii 7-bit
|
|
|
|
if (fname.empty() || fname == "ascii")
|
|
|
|
return true;
|
2002-03-21 17:27:08 +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;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
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
|
2002-03-21 17:27:08 +00:00
|
|
|
// without the use of a keyword table.
|
2002-05-25 00:19:56 +00:00
|
|
|
regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
|
2001-12-05 08:04:20 +00:00
|
|
|
while (getline(ifs, line)) {
|
2002-05-25 00:19:56 +00:00
|
|
|
smatch sub;
|
|
|
|
if (regex_match(line, sub, reg)) {
|
|
|
|
int const n = lyx::atoi(sub[1]);
|
|
|
|
string const str = sub[2];
|
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_;
|
|
|
|
}
|