From 0a2b9f4b81f651cc0b833a8f8c79d3297e2381e5 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Fri, 26 Jan 2001 22:24:20 +0000 Subject: [PATCH] Fix mathed bugs. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1406 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 9 +++++++++ src/mathed/formula.C | 28 ++++++++++++++++++++-------- src/mathed/math_iter.C | 2 ++ src/mathed/math_iter.h | 4 +++- src/mathed/math_parser.C | 13 +++++++++---- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 26dc2f1afc..fe366709f8 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ +2001-01-26 Dekel Tsur + + * 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 * math_draw.C (Metrics): Use the correct GetString. diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 47243e9b87..386be2062b 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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 res = old_label.empty() ? askForText(_("Enter new label to insert:"), default_label) -#else - pair res = old_label.empty() - ? askForText(_("Enter new label to insert:")) -#endif : askForText(_("Enter label:"), old_label); if (!res.first) break; diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index 2b3212585f..5b7d4bc1e6 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -999,3 +999,5 @@ MathedRowSt * MathedXIter::adjustVerticalSt() } return mrow; } + +string MathedXIter::error_label = "$mathed-error$"; diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index 218e9a4382..48e8f57121 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -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); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 8e7232c9cc..c57e2becfe 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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;