Use lyxlex to parse rgb.txt + small compilation fixes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1206 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-11-08 15:19:55 +00:00
parent 7ec7c9da44
commit 1a3ed565d9
10 changed files with 92 additions and 65 deletions

View File

@ -1,3 +1,18 @@
2000-11-08 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/frontends/xforms/FormPreferences.C (ColoursLoadBrowser): use
lyxlex to parse the rgb.txt file.
* src/lyxlex.[Ch]:
* src/lyxlex_pimpl.[Ch]: implement setCommentChar method, to
replace the default '#' comment character.
* src/support/tempname.C: add "using" directive
* src/frontends/ButtonPolicies.C: ditto.
* src/support/filetools.C (DirList): add an explicit cast to avoid
a compile error (probably not the right fix)
2000-11-08 Lars Gullik Bjønnes <larsbj@lyx.org> 2000-11-08 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/support/filetools.C (DirList): implement using system functions * src/support/filetools.C (DirList): implement using system functions

View File

@ -47,35 +47,35 @@ src/frontends/kde/refdlg.C
src/frontends/kde/tocdlg.C src/frontends/kde/tocdlg.C
src/frontends/kde/urldlg.C src/frontends/kde/urldlg.C
src/frontends/xforms/FormBase.h src/frontends/xforms/FormBase.h
src/frontends/xforms/form_citation.C
src/frontends/xforms/FormCitation.C src/frontends/xforms/FormCitation.C
src/frontends/xforms/form_copyright.C src/frontends/xforms/form_citation.C
src/frontends/xforms/FormCopyright.C src/frontends/xforms/FormCopyright.C
src/frontends/xforms/form_document.C src/frontends/xforms/form_copyright.C
src/frontends/xforms/FormDocument.C src/frontends/xforms/FormDocument.C
src/frontends/xforms/form_error.C src/frontends/xforms/form_document.C
src/frontends/xforms/FormError.C src/frontends/xforms/FormError.C
src/frontends/xforms/form_graphics.C src/frontends/xforms/form_error.C
src/frontends/xforms/FormGraphics.C src/frontends/xforms/FormGraphics.C
src/frontends/xforms/form_index.C src/frontends/xforms/form_graphics.C
src/frontends/xforms/FormIndex.C src/frontends/xforms/FormIndex.C
src/frontends/xforms/form_index.C
src/frontends/xforms/FormInset.h src/frontends/xforms/FormInset.h
src/frontends/xforms/form_paragraph.C
src/frontends/xforms/FormParagraph.C src/frontends/xforms/FormParagraph.C
src/frontends/xforms/form_preferences.C src/frontends/xforms/form_paragraph.C
src/frontends/xforms/FormPreferences.C src/frontends/xforms/FormPreferences.C
src/frontends/xforms/form_print.C src/frontends/xforms/form_preferences.C
src/frontends/xforms/FormPrint.C src/frontends/xforms/FormPrint.C
src/frontends/xforms/form_ref.C src/frontends/xforms/form_print.C
src/frontends/xforms/FormRef.C src/frontends/xforms/FormRef.C
src/frontends/xforms/form_tabular.C src/frontends/xforms/form_ref.C
src/frontends/xforms/FormTabular.C src/frontends/xforms/FormTabular.C
src/frontends/xforms/form_tabular_create.C src/frontends/xforms/form_tabular.C
src/frontends/xforms/FormTabularCreate.C src/frontends/xforms/FormTabularCreate.C
src/frontends/xforms/form_toc.C src/frontends/xforms/form_tabular_create.C
src/frontends/xforms/FormToc.C src/frontends/xforms/FormToc.C
src/frontends/xforms/form_url.C src/frontends/xforms/form_toc.C
src/frontends/xforms/FormUrl.C src/frontends/xforms/FormUrl.C
src/frontends/xforms/form_url.C
src/frontends/xforms/Menubar_pimpl.C src/frontends/xforms/Menubar_pimpl.C
src/gettext.h src/gettext.h
src/importer.C src/importer.C

View File

@ -21,6 +21,7 @@
#include "ButtonPolicies.h" #include "ButtonPolicies.h"
#include "debug.h" #include "debug.h"
using std::endl;
/// Helper function /// Helper function
static inline static inline
@ -38,7 +39,7 @@ void nextState(ButtonPolicy::State & state,
<< in << in
<< " from state " << " from state "
<< state << state
<< std::endl; << endl;
} }
} }

View File

@ -39,8 +39,6 @@ using SigC::slot;
using std::find; using std::find;
using std::find_if; using std::find_if;
using std::getline;
using std::istream;
using std::pair; using std::pair;
using std::sort; using std::sort;
using std::vector; using std::vector;
@ -426,58 +424,47 @@ bool FormPreferences::inputColours( FL_OBJECT const * const ob )
bool FormPreferences::ColoursLoadBrowser(string const & filename) bool FormPreferences::ColoursLoadBrowser(string const & filename)
{ {
LyXLex lex(0, 0); LyXLex lex(0, 0);
lex.setCommentChar('!');
if (!lex.setFile(filename)) if (!lex.setFile(filename))
return false; return false;
istream & is = lex.getStream();
string line;
vector<RGB> cols; vector<RGB> cols;
vector<string> names; vector<string> names;
while (true) { while (lex.next()) {
getline( is, line ); RGB col;
if (line.empty() ) col.r = lex.GetInteger();
break; lex.next();
col.g = lex.GetInteger();
lex.next();
col.b = lex.GetInteger();
lex.EatLine();
string name = frontStrip(lex.GetString(), " \t");
if (line[0] != '!') { // remove redundant entries on the fly
RGB col; bool add = cols.empty();
string name; if (!add) {
vector<RGB>::const_iterator it =
find( cols.begin(), cols.end(), col );
add = (it == cols.end());
}
if (add) {
name = lowercase( name );
if (name == "gray0" ) name = "black";
if (name == "gray100" ) name = "white";
istringstream iss(line.c_str()); if (name == "black" || name == "white") {
iss >> col.r >> col.g >> col.b; cols.insert(cols.begin(), col);
while (iss.good()) { names.insert(names.begin(), name);
string next; } else {
iss >> next; cols.push_back(col);
if (!name.empty() ) name += " "; names.push_back(name);
name += next;
} }
}
// remove redundant entries on the fly }
bool add = cols.empty();
if (!add) {
vector<RGB>::const_iterator it =
find( cols.begin(), cols.end(), col );
add = (it == cols.end());
}
if (add) {
name = lowercase( name );
if (name == "gray0" ) name = "black";
if (name == "gray100" ) name = "white";
if (name == "black" || name == "white") {
cols.insert(cols.begin(), col);
names.insert(names.begin(), name);
} else {
cols.push_back(col);
names.push_back(name);
}
}
}
}
vector<string>::iterator sit = names.begin(); vector<string>::iterator sit = names.begin();
for (vector<RGB>::const_iterator iit = cols.begin(); for (vector<RGB>::const_iterator iit = cols.begin();
iit != cols.end(); ++iit, ++sit) { iit != cols.end(); ++iit, ++sit) {

View File

@ -104,6 +104,11 @@ void LyXLex::setStream(istream & i)
} }
void LyXLex::setCommentChar(char c)
{
pimpl_->setCommentChar(c);
}
int LyXLex::lex() int LyXLex::lex()
{ {
return pimpl_->lex(); return pimpl_->lex();

View File

@ -58,7 +58,9 @@ public:
std::istream & getStream(); std::istream & getStream();
/// Danger! Don't use it unless you know what you are doing. /// Danger! Don't use it unless you know what you are doing.
void setLineNo(int l); void setLineNo(int l);
/// Change the character that begins a comment. Default is '#'
void setCommentChar(char c);
/// returns a lex code /// returns a lex code
int lex(); int lex();

View File

@ -30,7 +30,7 @@ struct compare_tags {
LyXLex::Pimpl::Pimpl(keyword_item * tab, int num) LyXLex::Pimpl::Pimpl(keyword_item * tab, int num)
: is(&fb__), table(tab), no_items(num), : is(&fb__), table(tab), no_items(num),
status(0), lineno(0) status(0), lineno(0), commentChar('#')
{ {
verifyTable(); verifyTable();
} }
@ -130,6 +130,11 @@ void LyXLex::Pimpl::setStream(istream & i)
lineno = 0; lineno = 0;
} }
void LyXLex::Pimpl::setCommentChar(char c)
{
commentChar = c;
}
bool LyXLex::Pimpl::next(bool esc /* = false */) bool LyXLex::Pimpl::next(bool esc /* = false */)
{ {
@ -146,7 +151,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */)
while (is && !status) { while (is && !status) {
is.get(cc); is.get(cc);
c = cc; c = cc;
if (c == '#') { if (c == commentChar) {
// Read rest of line (fast :-) // Read rest of line (fast :-)
// That is not fast... (Lgb) // That is not fast... (Lgb)
#if 1 #if 1
@ -262,7 +267,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */)
continue; continue;
} }
if (c == '#') { if (c == commentChar) {
// Read rest of line (fast :-) // Read rest of line (fast :-)
// That is still not fast... (Lgb) // That is still not fast... (Lgb)
#if 1 #if 1

View File

@ -37,6 +37,8 @@ struct LyXLex::Pimpl : public noncopyable {
/// ///
void setStream(std::istream & i); void setStream(std::istream & i);
/// ///
void setCommentChar(char c);
///
bool next(bool esc = false); bool next(bool esc = false);
/// ///
int search_kw(char const * const tag) const; int search_kw(char const * const tag) const;
@ -66,6 +68,8 @@ struct LyXLex::Pimpl : public noncopyable {
int lineno; int lineno;
/// ///
string pushTok; string pushTok;
///
char commentChar;
private: private:
/// ///
void verifyTable(); void verifyTable();

View File

@ -269,7 +269,13 @@ vector<string> const DirList( string const & dir, string const & ext)
// This is a non-error checking C/system implementation // This is a non-error checking C/system implementation
// of the above. // of the above.
string extension(ext); string extension(ext);
if (extension[0] != '.') extension.insert(0u, 1u, '.'); if (extension[0] != '.')
// If I do not use the explicit cast below, compaq cxx
// is not able to guess between
// insert(size_type, size_type, value_type)
// and
// insert(iterator, size_type, value_type)
extension.insert(string::size_type(0), 1u, '.');
vector<string> dirlist; vector<string> dirlist;
DIR * dirp = ::opendir(dir.c_str()); DIR * dirp = ::opendir(dir.c_str());
dirent * dire; dirent * dire;

View File

@ -10,6 +10,8 @@
#include "debug.h" #include "debug.h"
#include "filetools.h" #include "filetools.h"
using std::endl;
extern string system_tempdir; extern string system_tempdir;
string const lyx::tempName(string const & dir, string const & mask) string const lyx::tempName(string const & dir, string const & mask)