mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-05 17:09:56 +00:00
fix bug 1542 (crash wehn reading invalid equations)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@9413 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
22f6b2cae8
commit
c8e12cf1cc
@ -1,3 +1,12 @@
|
|||||||
|
2004-12-22 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||||
|
|
||||||
|
* math_parser.C (addRow, addCol): new, try to add a row or column to
|
||||||
|
a MathGridInset
|
||||||
|
* math_parser.C (parse1): use addRow and addCol, fixes bug 1542
|
||||||
|
* math_hullinset.[Ch] (rowChangeOK): new
|
||||||
|
* math_hullinset.C (addRow, delRow): check wether rows can be changed
|
||||||
|
* math_hullinset.C (delCol): don't delete if this is the only column
|
||||||
|
|
||||||
2004-12-14 Angus Leeming <leeming@lyx.org>
|
2004-12-14 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* Makefile.am (INCLUDES): Remove trailing slash from -Ifoo/
|
* Makefile.am (INCLUDES): Remove trailing slash from -Ifoo/
|
||||||
|
@ -400,6 +400,16 @@ void MathHullInset::footer_write(WriteStream & os) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MathHullInset::rowChangeOK() const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
type_ == "eqnarray" || type_ == "align" ||
|
||||||
|
type_ == "flalign" || type_ == "alignat" ||
|
||||||
|
type_ == "xalignat" || type_ == "xxalignat" ||
|
||||||
|
type_ == "gather" || type_ == "multline";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MathHullInset::colChangeOK() const
|
bool MathHullInset::colChangeOK() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
@ -410,6 +420,10 @@ bool MathHullInset::colChangeOK() const
|
|||||||
|
|
||||||
void MathHullInset::addRow(row_type row)
|
void MathHullInset::addRow(row_type row)
|
||||||
{
|
{
|
||||||
|
if (!rowChangeOK()) {
|
||||||
|
lyxerr << "Can't change number of rows in '" << type_ << "'\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
nonum_.insert(nonum_.begin() + row + 1, !numberedType());
|
nonum_.insert(nonum_.begin() + row + 1, !numberedType());
|
||||||
label_.insert(label_.begin() + row + 1, string());
|
label_.insert(label_.begin() + row + 1, string());
|
||||||
MathGridInset::addRow(row);
|
MathGridInset::addRow(row);
|
||||||
@ -418,8 +432,10 @@ void MathHullInset::addRow(row_type row)
|
|||||||
|
|
||||||
void MathHullInset::delRow(row_type row)
|
void MathHullInset::delRow(row_type row)
|
||||||
{
|
{
|
||||||
if (nrows() <= 1)
|
if (nrows() <= 1 || !rowChangeOK()) {
|
||||||
|
lyxerr << "Can't change number of rows in '" << type_ << "'\n";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
MathGridInset::delRow(row);
|
MathGridInset::delRow(row);
|
||||||
nonum_.erase(nonum_.begin() + row);
|
nonum_.erase(nonum_.begin() + row);
|
||||||
label_.erase(label_.begin() + row);
|
label_.erase(label_.begin() + row);
|
||||||
@ -437,10 +453,10 @@ void MathHullInset::addCol(col_type col)
|
|||||||
|
|
||||||
void MathHullInset::delCol(col_type col)
|
void MathHullInset::delCol(col_type col)
|
||||||
{
|
{
|
||||||
if (colChangeOK())
|
if (ncols() <= 1 || !colChangeOK())
|
||||||
MathGridInset::delCol(col);
|
|
||||||
else
|
|
||||||
lyxerr << "Can't change number of columns in '" << type_ << "'\n";
|
lyxerr << "Can't change number of columns in '" << type_ << "'\n";
|
||||||
|
else
|
||||||
|
MathGridInset::delCol(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,6 +110,8 @@ private:
|
|||||||
char const * standardFont() const;
|
char const * standardFont() const;
|
||||||
/// consistency check
|
/// consistency check
|
||||||
void check() const;
|
void check() const;
|
||||||
|
/// can this change its number of rows?
|
||||||
|
bool rowChangeOK() const;
|
||||||
/// can this change its number of cols?
|
/// can this change its number of cols?
|
||||||
bool colChangeOK() const;
|
bool colChangeOK() const;
|
||||||
|
|
||||||
|
@ -101,6 +101,65 @@ bool stared(string const & s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Add the row \p cellrow to \p grid.
|
||||||
|
* \returns wether the row could be added. Adding a row can fail for
|
||||||
|
* environments like "equation" that have a fixed number of rows.
|
||||||
|
*/
|
||||||
|
bool addRow(MathGridInset & grid, MathGridInset::row_type & cellrow,
|
||||||
|
string const & vskip)
|
||||||
|
{
|
||||||
|
++cellrow;
|
||||||
|
if (cellrow == grid.nrows()) {
|
||||||
|
//lyxerr << "adding row " << cellrow << endl;
|
||||||
|
grid.addRow(cellrow - 1);
|
||||||
|
if (cellrow == grid.nrows()) {
|
||||||
|
// We can't add a row to this grid, so let's
|
||||||
|
// append the content of this cell to the previous
|
||||||
|
// one.
|
||||||
|
// This does not happen in well formed .lyx files,
|
||||||
|
// but LyX versions 1.3.x and older could create
|
||||||
|
// such files and tex2lyx can still do that.
|
||||||
|
--cellrow;
|
||||||
|
lyxerr << "ignoring extra row";
|
||||||
|
if (!vskip.empty())
|
||||||
|
lyxerr << " with extra space " << vskip;
|
||||||
|
lyxerr << '.' << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
grid.vcrskip(LyXLength(vskip), cellrow - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Add the column \p cellcol to \p grid.
|
||||||
|
* \returns wether the column could be added. Adding a column can fail for
|
||||||
|
* environments like "eqnarray" that have a fixed number of columns.
|
||||||
|
*/
|
||||||
|
bool addCol(MathGridInset & grid, MathGridInset::col_type & cellcol)
|
||||||
|
{
|
||||||
|
++cellcol;
|
||||||
|
if (cellcol == grid.ncols()) {
|
||||||
|
//lyxerr << "adding column " << cellcol << endl;
|
||||||
|
grid.addCol(cellcol - 1);
|
||||||
|
if (cellcol == grid.ncols()) {
|
||||||
|
// We can't add a column to this grid, so let's
|
||||||
|
// append the content of this cell to the previous
|
||||||
|
// one.
|
||||||
|
// This does not happen in well formed .lyx files,
|
||||||
|
// but LyX versions 1.3.x and older could create
|
||||||
|
// such files and tex2lyx can still do that.
|
||||||
|
--cellcol;
|
||||||
|
lyxerr << "ignoring extra column." << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// These are TeX's catcodes
|
// These are TeX's catcodes
|
||||||
enum CatCode {
|
enum CatCode {
|
||||||
catEscape, // 0 backslash
|
catEscape, // 0 backslash
|
||||||
@ -722,13 +781,11 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cat() == catAlign) {
|
else if (t.cat() == catAlign) {
|
||||||
++cellcol;
|
//lyxerr << " column now " << (cellcol + 1)
|
||||||
//lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
|
// << " max: " << grid.ncols() << endl;
|
||||||
if (cellcol == grid.ncols()) {
|
if (addCol(grid, cellcol))
|
||||||
//lyxerr << "adding column " << cellcol << "\n";
|
cell = &grid.cell(grid.index(cellrow,
|
||||||
grid.addCol(cellcol - 1);
|
cellcol));
|
||||||
}
|
|
||||||
cell = &grid.cell(grid.index(cellrow, cellcol));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cat() == catSuper || t.cat() == catSub) {
|
else if (t.cat() == catSuper || t.cat() == catSub) {
|
||||||
@ -876,14 +933,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "\\") {
|
else if (t.cs() == "\\") {
|
||||||
grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
|
if (addRow(grid, cellrow, getArg('[', ']'))) {
|
||||||
++cellrow;
|
cellcol = 0;
|
||||||
cellcol = 0;
|
if (grid.asHullInset())
|
||||||
if (cellrow == grid.nrows())
|
grid.asHullInset()->numbered(
|
||||||
grid.addRow(cellrow - 1);
|
cellrow, numbered);
|
||||||
if (grid.asHullInset())
|
cell = &grid.cell(grid.index(cellrow,
|
||||||
grid.asHullInset()->numbered(cellrow, numbered);
|
cellcol));
|
||||||
cell = &grid.cell(grid.index(cellrow, cellcol));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -897,16 +954,15 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
// resize the table if necessary
|
// resize the table if necessary
|
||||||
for (int i = 0; i < cols; ++i) {
|
for (int i = 0; i < cols; ++i) {
|
||||||
++cellcol;
|
if (addCol(grid, cellcol)) {
|
||||||
if (cellcol == grid.ncols()) {
|
cell = &grid.cell(grid.index(
|
||||||
//lyxerr << "adding column " << cellcol << "\n";
|
cellrow, cellcol));
|
||||||
grid.addCol(cellcol - 1);
|
// mark this as dummy
|
||||||
|
grid.cellinfo(grid.index(
|
||||||
|
cellrow, cellcol)).dummy_ = true;
|
||||||
}
|
}
|
||||||
cell = &grid.cell(grid.index(cellrow, cellcol));
|
|
||||||
// mark this as dummy
|
|
||||||
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
|
|
||||||
}
|
}
|
||||||
// the last cell is the real thng, not a dummy
|
// the last cell is the real thing, not a dummy
|
||||||
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
|
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
|
||||||
|
|
||||||
// read special alignment
|
// read special alignment
|
||||||
|
Loading…
Reference in New Issue
Block a user