]> git.lyx.org Git - lyx.git/commitdiff
Fix mathed bugs.
authorDekel Tsur <dekelts@tau.ac.il>
Fri, 26 Jan 2001 22:24:20 +0000 (22:24 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Fri, 26 Jan 2001 22:24:20 +0000 (22:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1406 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/math_iter.C
src/mathed/math_iter.h
src/mathed/math_parser.C

index 26dc2f1afc15b5b23003108077d9ae15f053d315..fe366709f8e584d76d2974c85259fda5bae1bd77 100644 (file)
@@ -1,3 +1,12 @@
+2001-01-26  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * math_parser.C (LexGetArg): Fix crash when loading corrupt files.
+
+       * formula.C (LocalDispatch): Before inserting a label in an
+       eqnarray, move the cursor to the top level.
+
+       * math_iter.C (getLabel): Test if crow == 0.
+
 2001-01-15  Dekel Tsur  <dekelts@tau.ac.il>
 
        * math_draw.C (Metrics): Use the correct GetString.
index 47243e9b87985fe12eba7cd850bf0dfe6060e1d8..386be2062b7c1280178b55652f9d49c79abdb062 100644 (file)
@@ -938,9 +938,14 @@ InsetFormula::LocalDispatch(BufferView * bv,
 //        MathMatrixInset *mt = (MathMatrixInset*)par;
           //BUG 
 //        mt->SetNumbered(!mt->IsNumbered());
-           
+
+#warning This is a terrible hack! We should find a better solution.
+       while (mathcursor->getLabel() == MathedXIter::error_label) {
+          if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
+              return DISPATCHED;
+       }
            mathcursor->setNumbered();
-          UpdateLocal(bv);
+           UpdateLocal(bv);
        }
        break;
     }
@@ -1055,18 +1060,25 @@ InsetFormula::LocalDispatch(BufferView * bv,
        if (par->GetType() < LM_OT_PAR)
              break;
 
-       string old_label = (par->GetType() == LM_OT_MPARN)
+       string old_label = (par->GetType() == LM_OT_MPARN ||
+                          par->GetType() == LM_OT_MPAR)
               ?  mathcursor->getLabel() : label;
+
+#warning This is a terrible hack! We should find a better solution.
+       /// This is needed becuase in some positions mathcursor->cursor->crow
+       /// is equal to 0, and therefore the label cannot be inserted.
+       /// So we move the cursor left until mathcursor->cursor->crow != 0.
+       while (old_label == MathedXIter::error_label) {
+          if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
+              return DISPATCHED;
+          old_label = mathcursor->getLabel();
+       }
+
        string new_label = arg;
        if (new_label.empty()) {
-#ifdef LABEL_INIT
          string default_label = (lyxrc.label_init_length >= 0) ? "eq:" : "";
          pair<bool, string> res = old_label.empty()
                  ? askForText(_("Enter new label to insert:"), default_label)
-#else
-         pair<bool, string> res = old_label.empty()
-                 ? askForText(_("Enter new label to insert:"))
-#endif
                  : askForText(_("Enter label:"), old_label);
          if (!res.first)
             break;
index 2b3212585f7ffd82541bee4c8e3da447ebdeea4e..5b7d4bc1e6b73d25dcdae430eb2a5536a9890fb8 100644 (file)
@@ -999,3 +999,5 @@ MathedRowSt * MathedXIter::adjustVerticalSt()
     }
     return mrow;
 }
+
+string MathedXIter::error_label = "$mathed-error$";
index 218e9a4382dec8b94d6d4acdea1fe2e2dfdaf3a2..48e8f571215152732eec5c3cfa24ddf360e6c585 100644 (file)
@@ -222,8 +222,10 @@ class MathedXIter: public MathedIter {
     ///
     bool setLabel(string const & label);
     ///
+    static string error_label;
+    ///
     string const & getLabel() const {
-           return crow->getLabel();
+           return crow ? crow->getLabel() : error_label;
     }
     ///
     bool setNumbered(bool);
index 8e7232c9ccd1fa139344fa52266ac4df8ec7d539..c57e2becfe937ecffed6d9c5252780165bd3cd0f 100644 (file)
@@ -99,6 +99,7 @@ enum lexcode_enum {
 };
 
 static lexcode_enum lexcode[256];  
+#warning Replace with string
 static char yytext[256];
 static int yylineno;
 static istream * yyis;
@@ -154,10 +155,13 @@ char LexGetArg(char lf, bool accept_spaces= false)
       yyis->get(cc);
       c = cc;
       if (c > ' ') {
-        if (!lf) lf = c; else
-        if (c != lf)
+        if (!lf) 
+            lf = c;
+        else if (c != lf) {
                 lyxerr << "Math parse error: unexpected '"
                        << c << "'" << endl;
+                return '\0';
+        }
         break;
       }
    }
@@ -176,7 +180,7 @@ char LexGetArg(char lf, bool accept_spaces= false)
       if (c == lf) ++bcnt;
       if (c == rg) --bcnt;
       if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) *(p++) = c;
-   } while (bcnt > 0 && yyis->good());
+   } while (bcnt > 0 && yyis->good() && p-yytext < 255);
    *p = '\0';
    return rg;
 }
@@ -275,7 +279,8 @@ int yylex(void)
         }
         if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
            char * p = &yytext[0];
-           while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
+           while ((lexcode[c] == LexAlpha || lexcode[c] == LexDigit)
+                  && p-yytext < 255) {
               *p = c;
               yyis->get(cc);
               c = cc;