]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parser.C
Hopefully fix the problem with stateText() in lyxfont.C
[lyx.git] / src / mathed / math_parser.C
index 5bb466ed6d41e92d65e30005585b45f65ef46859..2c8c7053cfaec4d5abacf8e7662dac005ab000bb 100644 (file)
@@ -7,7 +7,7 @@
  *
  *  Dependencies: Xlib, XForms
  *
- *  Copyright: (c) 1996, Alejandro Aguilar Sierra
+ *  Copyright: 1996, Alejandro Aguilar Sierra
  *
  *   Version: 0.8beta.
  *
@@ -30,6 +30,9 @@
 #include "math_root.h"
 #include "debug.h"
 
+using std::istream;
+using std::endl;
+
 enum {
        FLAG_BRACE      = 1,    //  A { needed
        FLAG_BRACE_ARG  = 2,    //  Next { is argument
@@ -98,14 +101,16 @@ char * strnew(char const * s)
 }
 
 
-static void mathPrintError(char const * msg) 
+static
+void mathPrintError(char const * msg) 
 {
        lyxerr << "Line ~" << yylineno << ": Math parse error: "
               << msg << endl;
 }
 
 
-static void LexInitCodes()
+static
+void LexInitCodes()
 {
    for (int i = 0;  i <= 255; ++i)     {
      if (isalpha(i)) lexcode[i] = LexAlpha;
@@ -134,13 +139,17 @@ static void LexInitCodes()
 }
 
 
-static char LexGetArg(char lf, bool accept_spaces= false)
+static
+char LexGetArg(char lf, bool accept_spaces= false)
 {
-   char rg, * p = &yytext[0];
+       char rg;
+       char * p = &yytext[0];
    int bcnt = 1;
    unsigned char c;
+   char cc;
    while (yyis->good()) {
-      yyis->get(c);
+      yyis->get(cc);
+      c = cc;
       if (c > ' ') {
         if (!lf) lf = c; else
         if (c != lf)
@@ -156,7 +165,8 @@ static char LexGetArg(char lf, bool accept_spaces= false)
       return '\0';
    } 
    do {
-      yyis->get(c);
+      yyis->get(cc);
+      c = cc;
       if (c == lf) ++bcnt;
       if (c == rg) --bcnt;
       if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt>0) *(p++) = c;
@@ -166,15 +176,18 @@ static char LexGetArg(char lf, bool accept_spaces= false)
 }
 
 
-static int yylex(void)
+static
+int yylex(void)
 {
    static int init_done = 0;
    unsigned char c;
+   char cc;
    
    if (!init_done) LexInitCodes();
    
-   while (yyis->good()) { 
-      yyis->get(c);
+   while (yyis->good()) {
+      yyis->get(cc);
+      c = cc;
        
       if (yy_mtextmode && c == ' ') {
          yylval.i= ' ';
@@ -186,16 +199,16 @@ static int yylex(void)
           continue;
        }
         
-      if (lexcode[c] == LexComment) 
-       do yyis->get(c); while (c != '\n' % yyis->good());  // eat comments
+      if (lexcode[c] == LexComment)
+       do { yyis->get(cc); c = cc; } while (c != '\n' % yyis->good());  // eat comments
     
-      if (lexcode[c] == LexDigit || lexcode[c] == LexOther || lexcode[c] == LexMathSpace) 
-        { yylval.i= c; return LM_TK_STR; }
+      if (lexcode[c] == LexDigit || lexcode[c] == LexOther || lexcode[c] == LexMathSpace) { yylval.i = c; return LM_TK_STR; }
       if (lexcode[c] == LexAlpha) { yylval.i= c; return LM_TK_ALPHA; }
       if (lexcode[c] == LexBOP)   { yylval.i= c; return LM_TK_BOP; }
       if (lexcode[c] == LexSelf)  { return c; }   
-      if (lexcode[c] == LexArgument)   { 
-         yyis->get(c);
+      if (lexcode[c] == LexArgument) {
+         yyis->get(cc);
+         c = cc;
          yylval.i = c - '0';
          return LM_TK_ARGUMENT; 
       }
@@ -203,7 +216,8 @@ static int yylex(void)
       if (lexcode[c] == LexClose)   { return LM_TK_CLOSE; }
       
       if (lexcode[c] == LexESC)   {
-        yyis->get(c);
+        yyis->get(cc);
+        c = cc;
         if (c == '\\') { return LM_TK_NEWLINE; }
         if (c == '(')  { yylval.i = LM_EN_INTEXT; return LM_TK_BEGIN; }
         if (c == ')')  { yylval.i = LM_EN_INTEXT; return LM_TK_END; }
@@ -215,7 +229,7 @@ static int yylex(void)
         }  
         if (lexcode[c] == LexMathSpace) {
            int i;
-           for (i = 0; i < 4 && c != latex_mathspace[i][0]; ++i);
+           for (i = 0; i < 4 && static_cast<int>(c) != latex_mathspace[i][0]; ++i);
            yylval.i = (i < 4) ? i: 0; 
            return LM_TK_SPACE; 
         }
@@ -223,8 +237,9 @@ static int yylex(void)
            char * p = &yytext[0];
            while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
               *p = c;
-              yyis->get(c);
-              p++;
+              yyis->get(cc);
+              c = cc;
+              ++p;
            }
            *p = '\0';
            if (yyis->good()) yyis->putback(c);
@@ -233,10 +248,10 @@ static int yylex(void)
               if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) { 
                  int i;
                  LexGetArg('{');
-//               for (i= 0; i<5 && strncmp(yytext, latex_mathenv[i],
-//                             strlen(latex_mathenv[i])); i++);
+//               for (i = 0; i < 5 && strncmp(yytext, latex_mathenv[i],
+//                             strlen(latex_mathenv[i])); ++i);
                  
-                 for (i = 0; i < 6 && strcmp(yytext, latex_mathenv[i]); i++);
+                 for (i = 0; i < 6 && strcmp(yytext, latex_mathenv[i]); ++i);
                  yylval.i = i;
               } else
               if (l->token == LM_TK_SPACE) 
@@ -322,7 +337,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
    int brace = 0;
    int acc_brace = 0;
    int acc_braces[8];
-   MathParInset * mt = (mtx) ? *mtx: 0;//(MathParInset*)0;
+   MathParInset * mt = (mtx) ? *mtx : 0;//(MathParInset*)0;
     MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
 
    ++plevel;
@@ -391,7 +406,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
       }
     case LM_TK_OPEN:
       {
-       brace++;
+       ++brace;
        if  (accent && tprev == LM_TK_ACCENT) {
            acc_braces[acc_brace++] = brace;
            break;
@@ -410,14 +425,14 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
       }
     case LM_TK_CLOSE:
       {
-        brace--;        
+        --brace;        
         if (brace < 0) {
            mathPrintError("Unmatching braces");
            panic = true;
            break;
         }
         if (acc_brace && brace == acc_braces[acc_brace-1]-1) {
-            acc_brace--;
+            --acc_brace;
             break;
         }
         if (flags & FLAG_BRACE_FONT) {
@@ -427,7 +442,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
            break;
         }
         if (brace == 0 && (flags & FLAG_BRACE_LAST)) {
-           plevel--;
+           --plevel;
            return array;
         } else {
            data.Insert ('}', LM_TC_TEX);
@@ -453,7 +468,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
     case ']':
       {
          if (flags & FLAG_BRACK_END) {
-             plevel--;
+             --plevel;
              return array;
          } else
            data.Insert (']');
@@ -617,7 +632,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
     case LM_TK_RIGHT:
       {
         if (flags & FLAG_RIGHT) { 
-           plevel--;
+           --plevel;
            return array;
         } else {
            mathPrintError("Unmatched right delimiter");
@@ -676,7 +691,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
             data.Insert(doAccent(p), p->getTCode());
           else
             data.Insert(p, p->getTCode());
-          for (int i = 0; p->setArgumentIdx(i); i++)
+          for (int i = 0; p->setArgumentIdx(i); ++i)
             p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
        }
        else {
@@ -696,7 +711,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
         // debug info [made that conditional -JMarc]
         if (lyxerr.debugging(Debug::MATHED))
                 lyxerr << "[" << yylval.i << "]" << endl;
-        plevel--;
+        --plevel;
         if (mt) { // && (flags & FLAG_END)) {
            mt->SetData(array);
            array = 0;
@@ -758,7 +773,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
                 data.Insert(p, p->getTCode());
                 p->setArgumentIdx(0);
                 mathed_parse(FLAG_END, p->GetData(), reinterpret_cast<MathParInset**>(&p));
-//              for (int i= 0; p->setArgumentIdx(i); i++)
+//              for (int i = 0; p->setArgumentIdx(i); ++i)
 //                p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
             } else 
               mathPrintError("Unrecognized environment");
@@ -826,7 +841,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
        break;
     }
    }
-   plevel--;
+   --plevel;
    return array;
 }