2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file chset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "chset.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
#include "support/convert.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-05-25 00:19:56 +00:00
|
|
|
|
#include <boost/regex.hpp>
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using lyx::support::libFileSearch;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
using boost::regex;
|
|
|
|
|
using boost::smatch;
|
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
2000-05-04 10:57:00 +00:00
|
|
|
|
using std::getline;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
using std::make_pair;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
|
|
|
|
using std::ifstream;
|
|
|
|
|
using std::pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
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;
|
2006-04-08 22:31:11 +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;
|
2003-09-15 11:00:00 +00:00
|
|
|
|
if (regex_match(line, sub, reg)) {
|
2005-01-27 21:05:44 +00:00
|
|
|
|
int const n = convert<int>(sub.str(1));
|
2003-09-15 11:00:00 +00:00
|
|
|
|
string const str = sub.str(2);
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
|
lyxerr << "Chardef: " << n
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< " to [" << str << ']' << endl;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
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
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
|
1999-12-16 06:43:25 +00:00
|
|
|
|
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")
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< " know [" << str << ']' << endl;
|
1999-12-16 06:43:25 +00:00
|
|
|
|
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_;
|
|
|
|
|
}
|