]> git.lyx.org Git - features.git/commitdiff
Use lyxlex to parse rgb.txt + small compilation fixes
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 8 Nov 2000 15:19:55 +0000 (15:19 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 8 Nov 2000 15:19:55 +0000 (15:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1206 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
po/POTFILES.in
src/frontends/ButtonPolicies.C
src/frontends/xforms/FormPreferences.C
src/lyxlex.C
src/lyxlex.h
src/lyxlex_pimpl.C
src/lyxlex_pimpl.h
src/support/filetools.C
src/support/tempname.C

index 31aa95c7c51711c6581794a3db9e234ba9cbdde0..79fccd09c0f3d6c977fbe883796c4202e73c8ff3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * src/support/filetools.C (DirList): implement using system functions
index d18943019e80b3f29bea47097260ae46c3037269..cfcf30161702ce831e6a246162c5ebeb468f4f14 100644 (file)
@@ -47,35 +47,35 @@ src/frontends/kde/refdlg.C
 src/frontends/kde/tocdlg.C
 src/frontends/kde/urldlg.C
 src/frontends/xforms/FormBase.h
-src/frontends/xforms/form_citation.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/form_document.C
+src/frontends/xforms/form_copyright.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/form_graphics.C
+src/frontends/xforms/form_error.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/form_index.C
 src/frontends/xforms/FormInset.h
-src/frontends/xforms/form_paragraph.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/form_print.C
+src/frontends/xforms/form_preferences.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/form_tabular.C
+src/frontends/xforms/form_ref.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/form_toc.C
+src/frontends/xforms/form_tabular_create.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/form_url.C
 src/frontends/xforms/Menubar_pimpl.C
 src/gettext.h
 src/importer.C
index 23812b42c1cfc1176d1822c8612bd36935e51aba..3662facfeb28410c569d0a0270992df2b36acf47 100644 (file)
@@ -21,6 +21,7 @@
 #include "ButtonPolicies.h"
 #include "debug.h"
 
+using std::endl;
 
 /// Helper function
 static inline
@@ -38,7 +39,7 @@ void nextState(ButtonPolicy::State & state,
                       << in
                       << " from state "
                       << state
-                      << std::endl;
+                      << endl;
        }
 }
 
index 0d5f1dc05d6c5a9139348ca0821210e301d12ea9..768bf3047f6cab8d976c554d38d28bff44bd9f59 100644 (file)
@@ -39,8 +39,6 @@ using SigC::slot;
 
 using std::find;
 using std::find_if;
-using std::getline;
-using std::istream;
 using std::pair;
 using std::sort;
 using std::vector;
@@ -426,58 +424,47 @@ bool FormPreferences::inputColours( FL_OBJECT const * const ob )
 bool FormPreferences::ColoursLoadBrowser(string const & filename)
 {
        LyXLex lex(0, 0);
-
+       lex.setCommentChar('!');
+       
        if (!lex.setFile(filename))
                return false;
 
-       istream & is = lex.getStream();
-       string line;
-
        vector<RGB> cols;
        vector<string> names;
        
-       while (true) {
-               getline( is, line );
-               if (line.empty() )
-                       break;
-
-               if (line[0] != '!') {
-                       RGB col;
-                       string name;
+       while (lex.next()) {
+               RGB col;
+               col.r = lex.GetInteger();
+               lex.next();
+               col.g = lex.GetInteger();
+               lex.next();
+               col.b = lex.GetInteger();
+               lex.EatLine();
+               string name = frontStrip(lex.GetString(), " \t");
+
+               // 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";
                        
-                       istringstream iss(line.c_str());
-                       iss >> col.r >> col.g >> col.b;
-                       while (iss.good()) {
-                               string next;
-                               iss >> next;
-                               if (!name.empty() ) 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 (name == "black" || name == "white") {
+                               cols.insert(cols.begin(), col);
+                               names.insert(names.begin(), name);
+                       } else {
+                               cols.push_back(col);
+                               names.push_back(name);
                        }
-                       
-                       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();
        for (vector<RGB>::const_iterator iit = cols.begin();
             iit != cols.end(); ++iit, ++sit) {
index 4dc6bbfa51db87b5c22b78e0c8a557e6df234ca0..4b93787423c7685d12ba833372bd9cd52e37b25c 100644 (file)
@@ -104,6 +104,11 @@ void LyXLex::setStream(istream & i)
 }
 
 
+void LyXLex::setCommentChar(char c)
+{
+       pimpl_->setCommentChar(c);
+}
+
 int LyXLex::lex()
 {
        return pimpl_->lex();
index f7113e9c9c16f84731ce1c790e81df355816f2da..5b2f85e54ee8320635e2631987f0457a674ce660 100644 (file)
@@ -58,7 +58,9 @@ public:
        std::istream & getStream();
        /// Danger! Don't use it unless you know what you are doing.
        void setLineNo(int l);
-       
+       /// Change the character that begins a comment. Default is '#'
+       void setCommentChar(char c);
+
        /// returns a lex code
        int lex();
 
index 2dcd2c054cd4b4ac60ba4850c532522dec2d48ff..94a268f1713fbe0868ecaac0c4e02f00b9b2d29b 100644 (file)
@@ -30,7 +30,7 @@ struct compare_tags {
 
 LyXLex::Pimpl::Pimpl(keyword_item * tab, int num) 
        : is(&fb__), table(tab), no_items(num),
-         status(0), lineno(0)
+         status(0), lineno(0), commentChar('#')
 {
        verifyTable();
 }
@@ -130,6 +130,11 @@ void LyXLex::Pimpl::setStream(istream & i)
        lineno = 0;
 }
 
+void LyXLex::Pimpl::setCommentChar(char c)
+{
+       commentChar = c;
+}
+
 
 bool LyXLex::Pimpl::next(bool esc /* = false */)
 {
@@ -146,7 +151,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */)
                while (is && !status) {
                        is.get(cc);
                        c = cc;
-                       if (c == '#') {
+                       if (c == commentChar) {
                                // Read rest of line (fast :-)
                                // That is not fast... (Lgb)
 #if 1
@@ -262,7 +267,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */)
                                continue;
                        }
                        
-                       if (c == '#') {
+                       if (c == commentChar) {
                                // Read rest of line (fast :-)
                                // That is still not fast... (Lgb)
 #if 1
index 0acc50974d2b92d6a82a4fd7fa3fd690bf269651..3090b5d6d9d958734d1e127e8ef46a2ef9747e27 100644 (file)
@@ -37,6 +37,8 @@ struct LyXLex::Pimpl : public noncopyable {
        ///
        void setStream(std::istream & i);
        ///
+       void setCommentChar(char c);
+       ///
        bool next(bool esc = false);
        ///
        int search_kw(char const * const tag) const;
@@ -66,6 +68,8 @@ struct LyXLex::Pimpl : public noncopyable {
        int lineno;
        ///
        string pushTok;
+       ///
+       char commentChar;
 private:
        ///
        void verifyTable();
index 5d084b314135850f8fc6f3d2d5d53ea3443214ad..a85f4a1091dbb3bf4c37cd01d57602871405c1fe 100644 (file)
@@ -269,7 +269,13 @@ vector<string> const DirList( string const & dir, string const & ext)
        // This is a non-error checking C/system implementation
        // of the above.
        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;
        DIR * dirp = ::opendir(dir.c_str());
        dirent * dire;
index ee34988735da95631a41f69a3556208295c49a9f..98adcd0a31705584dba382bac8c9a1d9dbf3cb21 100644 (file)
@@ -10,6 +10,8 @@
 #include "debug.h"
 #include "filetools.h"
 
+using std::endl;
+
 extern string system_tempdir;
 
 string const lyx::tempName(string const & dir, string const & mask)