]> git.lyx.org Git - lyx.git/blobdiff - src/lyxlex.C
use the new bufferstorage (this change only deletes all references to the old one
[lyx.git] / src / lyxlex.C
index f036360a67669472561ff581c5ff8a9d95bc2d70..00a488341b39b41059953efc1acf892f799379cd 100644 (file)
@@ -13,7 +13,7 @@
 #endif
 
 #include "lyxlex.h"
-#include "error.h"
+#include "debug.h"
 #include "support/filetools.h"
 
 LyXLex::LyXLex(keyword_item * tab, int num)
@@ -41,7 +41,7 @@ void LyXLex::pushTable(keyword_item * tab, int num)
 void LyXLex::popTable()
 {
        if (pushed == 0)
-               lyxerr.print("LyXLex error: nothing to pop!");
+               lyxerr << "LyXLex error: nothing to pop!" << endl;
 
        pushed_table * tmp;
        tmp = pushed;
@@ -55,27 +55,27 @@ void LyXLex::popTable()
 
 void LyXLex::printTable()
 {
-       lyxerr.print(string("\nNumber of tags: ") + tostr(no_items));
-       for(int i=0; i<no_items; i++)
-               lyxerr.print(string("table[")+ tostr(i) +
-                              "]:  tag: `" + table[i].tag +
-                              "'  code:" + tostr(table[i].code));
-       lyxerr.print(string());
+       lyxerr << "\nNumber of tags: " << no_items << endl;
+       for(int i= 0; i<no_items; i++)
+               lyxerr << "table[" << i
+                      << "]:  tag: `" << table[i].tag
+                      << "'  code:" << table[i].code << endl;
+       lyxerr << endl;
 }
 
 
 void LyXLex::printError(string const & message)
 {
        string tmpmsg = subst(message, "$$Token", GetString());
-       lyxerr.print("LyX: " + tmpmsg + " [around line " + tostr(lineno) + " of file "
-                     + MakeDisplayPath(name) + ']');
+       lyxerr << "LyX: " << tmpmsg << " [around line " << lineno
+              << " of file " << MakeDisplayPath(name) << ']' << endl;
 }
 
 
 bool LyXLex::setFile(string const & filename)
 {
         if (file) 
-               lyxerr.print("Error in LyXLex::setFile: file already set.");
+               lyxerr << "Error in LyXLex::setFile: file already set." <<endl;
        file = fopen(filename.c_str(), "r");
        name = filename;
        owns_file = true;
@@ -87,7 +87,7 @@ bool LyXLex::setFile(string const & filename)
 void LyXLex::setFile(FILE * f)
 {
         if (file) 
-               lyxerr.print("Error in LyXLex::setFile: file already set.");
+               lyxerr << "Error in LyXLex::setFile: file already set." << endl;
        file = f;
        owns_file = false;
        lineno = 0; // this is bogus if the file already has been read from
@@ -97,7 +97,7 @@ void LyXLex::setFile(FILE * f)
 int LyXLex::lex()
 {
        //NOTE: possible bug.
-   if (next() && status==LEX_TOKEN)
+   if (next() && status == LEX_TOKEN)
        return search_kw(buff);
    else
        return status;
@@ -147,7 +147,8 @@ string LyXLex::getLongString(string const & endtoken)
                
                string const token = frontStrip(strip(GetString()), " \t");
                
-               lyxerr.debug("LongString: `"+GetString()+'\'', Error::LEX_PARSER);
+               lyxerr[Debug::PARSER] << "LongString: `"
+                                     << GetString() << '\'' << endl;
 
                // We do a case independent comparison, like search_kw
                // does.
@@ -161,8 +162,8 @@ string LyXLex::getLongString(string const & endtoken)
                                        prefix += ' ';
                                }
                                firstline = false;
-                               lyxerr.debug("Prefix = `"+prefix+'\'',
-                                             Error::LEX_PARSER); 
+                               lyxerr[Debug::PARSER] << "Prefix = `" << prefix
+                                                     << '\'' << endl;
                        } 
 
                        if (!prefix.empty() 
@@ -193,21 +194,21 @@ bool LyXLex::GetBool()
 
 bool LyXLex::EatLine()
 {
-       int i=0;
+       int i= 0;
        int c = '\0'; // getc() returns an int
 
-       while (!feof(file) && c!='\n' && i!=(LEX_MAX_BUFF-1)) {
+       while (!feof(file) && c!= '\n' && i!= (LEX_MAX_BUFF-1)) {
                c = getc(file);
                if (c != '\r')
                        buff[i++] = c;
        }
-       if (i==(LEX_MAX_BUFF-1) && c !='\n') {
+       if (i == (LEX_MAX_BUFF-1) && c != '\n') {
                printError("Line too long");
                c = '\n'; // Pretend we had an end of line
                --lineno; // but don't increase line counter (netto effect)
                ++i; // and preserve last character read.
        }
-       if (c=='\n') {
+       if (c == '\n') {
                ++lineno;
                buff[--i] = '\0'; // i can never be 0 here, so no danger
                status = LEX_DATA;
@@ -221,25 +222,21 @@ bool LyXLex::EatLine()
 
 int LyXLex::search_kw(char const * const tag) const
 {
-       int m, k=0 , l= 0, r=no_items;
+       int m, k= 0 , l= 0, r= no_items;
 
        while (l < r) {
                m = (l+r)/2;
 
-               if (lyxerr.debugging(Error::LEX_PARSER)) {
-                       string my_l;
-                       my_l+="LyXLex::search_kw: elem " ;
-                       my_l+= m; 
-                       my_l+=" tag "; 
-                       my_l+=table[m].tag;
-                       my_l+=" search tag ";
-                       my_l+= tag;
-                       lyxerr.print(my_l);
+               if (lyxerr.debugging(Debug::PARSER)) {
+                       lyxerr << "LyXLex::search_kw: elem " << m
+                              << " tag " << table[m].tag
+                              << " search tag " << tag
+                              << endl;
                }
 
                if (table[m].tag)
                        k = compare_no_case(table[m].tag, tag);
-               if (k==0)
+               if (k == 0)
                        return table[m].code;
                else
                        if (k<0) l = m+1; else r = m;
@@ -253,37 +250,37 @@ bool LyXLex::next(bool esc)
 
        if (!esc) {
                int c; // getc() returns an int
-               int i;
+               //int i;
                
                
                status = 0;
                while (!feof(file) && !status) { 
                        c = getc(file);
-                       if (c=='#') {
+                       if (c == '#') {
                                // Read rest of line (fast :-)
                                fgets(buff, sizeof(buff), file);
                                ++lineno;
                                continue;
                        }
                        
-                       if (c=='\"') {
-                               i = -1;
+                       if (c == '\"') {
+                               int i = -1;
                                do {
                                        c = getc(file);
                                        if (c != '\r')
                                                buff[++i] = c;
-                               } while (c!='\"' && c!='\n' && !feof(file) &&
-                                        i!=(LEX_MAX_BUFF-2));
+                               } while (c!= '\"' && c!= '\n' && !feof(file) &&
+                                        i!= (LEX_MAX_BUFF-2));
                                
-                               if (i==(LEX_MAX_BUFF-2)) {
+                               if (i == (LEX_MAX_BUFF-2)) {
                                        printError("Line too long");
                                        c = '\"'; // Pretend we got a "
                                        ++i;
                                }
                                
-                               if (c!='\"') {
+                               if (c!= '\"') {
                                        printError("Missing quote");
-                                       if (c=='\n')
+                                       if (c == '\n')
                                                ++lineno;
                                }
                                
@@ -292,11 +289,11 @@ bool LyXLex::next(bool esc)
                                break; 
                        }
                        
-                       if (c==',')
+                       if (c == ',')
                                continue;              /* Skip ','s */
                        
                        if (c > ' ' && !feof(file))  {
-                               i = 0;
+                               int i = 0;
                                do {
                                        buff[i++] = c;
                                        c = getc(file);
@@ -309,7 +306,7 @@ bool LyXLex::next(bool esc)
                                status = LEX_TOKEN;
                        }
                        
-                       if (c== '\r' && !feof(file)) {
+                       if (c == '\r' && !feof(file)) {
                                // The Windows support has lead to the
                                // possibility of "\r\n" at the end of
                                // a line.  This will stop LyX choking
@@ -317,7 +314,7 @@ bool LyXLex::next(bool esc)
                                c = getc(file);
                        }
 
-                       if (c=='\n')
+                       if (c == '\n')
                                ++lineno;
                        
                }
@@ -328,7 +325,7 @@ bool LyXLex::next(bool esc)
                return false;
        } else {
                int c; // getc() returns an int
-               int i;
+               //int i;
                
                
                status = 0;
@@ -336,11 +333,11 @@ bool LyXLex::next(bool esc)
                        c = getc(file);
 
                        // skip ','s
-                       if (c==',') continue;
+                       if (c == ',') continue;
                        
-                       if (c=='\\') {
+                       if (c == '\\') {
                                // escape
-                               i = 0;
+                               int i = 0;
                                do {
                                        if (c == '\\') {
                                                // escape the next char
@@ -358,7 +355,7 @@ bool LyXLex::next(bool esc)
                                continue;
                        }
                        
-                       if (c=='#') {
+                       if (c == '#') {
                                // Read rest of line (fast :-)
                                fgets(buff, sizeof(buff), file);
                                ++lineno;
@@ -366,8 +363,8 @@ bool LyXLex::next(bool esc)
                        }
 
                        // string
-                       if (c=='\"') {
-                               i = -1;
+                       if (c == '\"') {
+                               int i = -1;
                                bool escaped = false;
                                do {
                                        escaped = false;
@@ -381,18 +378,18 @@ bool LyXLex::next(bool esc)
                                        buff[++i] = c;
                                
                                        if (!escaped && c == '\"') break;
-                               } while (c!='\n' && !feof(file) &&
-                                        i!=(LEX_MAX_BUFF-2));
+                               } while (c!= '\n' && !feof(file) &&
+                                        i!= (LEX_MAX_BUFF-2));
                                
-                               if (i==(LEX_MAX_BUFF-2)) {
+                               if (i == (LEX_MAX_BUFF-2)) {
                                        printError("Line too long");
                                        c = '\"'; // Pretend we got a "
                                        ++i;
                                }
                                
-                               if (c!='\"') {
+                               if (c!= '\"') {
                                        printError("Missing quote");
-                                       if (c=='\n')
+                                       if (c == '\n')
                                                ++lineno;
                                }
                                
@@ -402,7 +399,7 @@ bool LyXLex::next(bool esc)
                        }
                        
                        if (c > ' ' && !feof(file))  {
-                               i = 0;
+                               int i = 0;
                                do {
                                        if (c == '\\') {
                                                // escape the next char
@@ -421,7 +418,7 @@ bool LyXLex::next(bool esc)
                        }
 
                        // new line
-                       if (c=='\n')
+                       if (c == '\n')
                                ++lineno;
                }
                
@@ -463,12 +460,12 @@ bool LyXLex::nextToken()
                                printError("Line too long");
                        }
 
-                       if (c == '\\') ungetc(c,file); // put it back
+                       if (c == '\\') ungetc(c, file); // put it back
                        buff[i] = '\0';
                        status = LEX_TOKEN;
                }
                  
-               if (c=='\n')
+               if (c == '\n')
                        ++lineno;
        
        }