From: Jürgen Vigna Date: Tue, 9 Jan 2001 16:23:48 +0000 (+0000) Subject: Changed tabular-file-format + fixes in tabular. X-Git-Tag: 1.6.10~21742 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fe00b6f1a2f1735361739f7146ba55dda2bc8ad0;p=features.git Changed tabular-file-format + fixes in tabular. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1308 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 8ac3da2741..f80e76033a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2001-01-09 Juergen Vigna + + * src/tabular.C (OldFormatRead): convert the footer/header information + to the right row. + (getTokenValue): chaned this functions again. + (string2type): added a bunch of this functions per type. + (Write): use type2string and write columns first. + (type2string): added a bunch of this functions per type. + (TeXBottomHLine): + (TeXTopHLine): check row parameter. + +2001-01-08 Dekel Tsur + + * src/tabular.C (getTokenValue): Fix crash with malformed files. + (Read): Read the rotate attribute. + 2001-01-09 Jean-Marc Lasgouttes * src/frontends/xforms/FormDocument.C (CheckChoiceClass): fix diff --git a/src/tabular.C b/src/tabular.C index a7115bdb68..18b3777bbf 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -943,6 +943,62 @@ string const write_attribute(string const & name, bool value) #endif +string const type2string(LyXAlignment num) +{ + switch(num) { + case LYX_ALIGN_NONE: + return "none"; + case LYX_ALIGN_BLOCK: + return "block"; + case LYX_ALIGN_LEFT: + return "left"; + case LYX_ALIGN_CENTER: + return "center"; + case LYX_ALIGN_RIGHT: + return "right"; + case LYX_ALIGN_LAYOUT: + return "layout"; + case LYX_ALIGN_SPECIAL: + return "special"; + } + return string(); +} + + +string const type2string(LyXTabular::VAlignment num) +{ + switch(num) { + case LyXTabular::LYX_VALIGN_TOP: + return "top"; + case LyXTabular::LYX_VALIGN_CENTER: + return "center"; + case LyXTabular::LYX_VALIGN_BOTTOM: + return "bottom"; + } + return string(); +} + + +string const type2string(LyXTabular::BoxType num) +{ + switch(num) { + case LyXTabular::BOX_NONE: + return "none"; + case LyXTabular::BOX_PARBOX: + return "parbox"; + case LyXTabular::BOX_MINIPAGE: + return "minipage"; + } + return string(); +} + + +string const type2string(bool flag) +{ + return (flag ? "true" : "false"); +} + + void LyXTabular::Write(Buffer const * buf, ostream & os) const { // header line @@ -953,26 +1009,39 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const << ">\n"; // global longtable options os << "\n\n"; + << ">\n"; + for (int j = 0; j < columns_; ++j) { + os << "\n"; + } for (int i = 0; i < rows_; ++i) { os << "\n"; for (int j = 0; j < columns_; ++j) { +#if 0 if (!i) { os << "\n"; } +#endif os << "\n"; os << "\\begin_inset "; cell_info[i][j].inset.Write(buf, os); os << "\n\\end_inset \n" - << "\n" + << "\n"; +#if 0 << "\n"; +#endif } os << "\n"; } @@ -1006,17 +1078,75 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const } +bool string2type(string const str, LyXAlignment & num) +{ + if (str == "none") + num = LYX_ALIGN_NONE; + else if (str == "block") + num = LYX_ALIGN_BLOCK; + else if (str == "left") + num = LYX_ALIGN_LEFT; + else if (str == "center") + num = LYX_ALIGN_CENTER; + else if (str == "right") + num = LYX_ALIGN_RIGHT; + else + return false; + return true; +} + + +bool string2type(string const str, LyXTabular::VAlignment & num) +{ + if (str == "top") + num = LyXTabular::LYX_VALIGN_TOP; + else if (str == "center") + num = LyXTabular::LYX_VALIGN_CENTER; + else if (str == "bottom") + num = LyXTabular::LYX_VALIGN_BOTTOM; + else + return false; + return true; +} + + +bool string2type(string const str, LyXTabular::BoxType & num) +{ + if (str == "none") + num = LyXTabular::BOX_NONE; + else if (str == "parbox") + num = LyXTabular::BOX_PARBOX; + else if (str == "minipage") + num = LyXTabular::BOX_MINIPAGE; + else + return false; + return true; +} + + +bool string2type(string const str, bool & num) +{ + if (str == "true") + num = true; + else if (str == "false") + num = false; + else + return false; + return true; +} + static bool getTokenValue(string const & str, const char * token, string & ret) { + size_t token_length = strlen(token); string::size_type pos = str.find(token); - char ch = str[pos + strlen(token)]; - if ((pos == string::npos) || (ch != '=')) + if (pos == string::npos || pos+token_length+1 >= str.length() + || str[pos+token_length] != '=') return false; ret.erase(); - pos += strlen(token) + 1; - ch = str[pos]; + pos += token_length + 1; + char ch = str[pos]; if ((ch != '"') && (ch != '\'')) { // only read till next space ret += ch; ch = ' '; @@ -1028,6 +1158,63 @@ bool getTokenValue(string const & str, const char * token, string & ret) } +//#define USE_OLD_READFORMAT + +#ifndef USE_OLD_READFORMAT +static +bool getTokenValue(string const & str, const char * token, int & num) +{ + string tmp; + if (!getTokenValue(str, token, tmp)) + return false; + num = strToInt(tmp); + return true; +} + + +static +bool getTokenValue(string const & str, const char * token, LyXAlignment & num) +{ + string tmp; + if (!getTokenValue(str, token, tmp)) + return false; + return string2type(tmp, num); +} + + +static +bool getTokenValue(string const & str, const char * token, + LyXTabular::VAlignment & num) +{ + string tmp; + if (!getTokenValue(str, token, tmp)) + return false; + return string2type(tmp, num); +} + + +static +bool getTokenValue(string const & str, const char * token, + LyXTabular::BoxType & num) +{ + string tmp; + if (!getTokenValue(str, token, tmp)) + return false; + return string2type(tmp, num); +} + + +static +bool getTokenValue(string const & str, const char * token, bool & flag) +{ + string tmp; + if (!getTokenValue(str, token, tmp)) + return false; + return string2type(tmp, flag); +} + +#else + static bool getTokenValue(string const & str, const char * token, int & num) { @@ -1109,6 +1296,7 @@ bool getTokenValue(string const & str, const char * token, bool & flag) return true; } +#endif static inline void l_getline(istream & is, string & str) @@ -1119,6 +1307,111 @@ void l_getline(istream & is, string & str) } +#ifndef USE_OLD_READFORMAT + +void LyXTabular::Read(Buffer const * buf, LyXLex & lex) +{ + string line; + istream & is = lex.getStream(); + + l_getline(is, line); + if (!prefixIs(line, " got" << + line << ")" << endl; + return; + } + getTokenValue(line, "rotate", rotate); + getTokenValue(line, "islongtable", is_long_tabular); + getTokenValue(line, "endhead", endhead); + getTokenValue(line, "endfirsthead", endfirsthead); + getTokenValue(line, "endfoot", endfoot); + getTokenValue(line, "endlastfoot", endlastfoot); + + for (int j = 0; j < columns_; ++j) { + l_getline(is,line); + if (!prefixIs(line," got" << + line << ")" << endl; + return; + } + getTokenValue(line, "alignment", column_info[j].alignment); + getTokenValue(line, "valignment", column_info[j].valignment); + getTokenValue(line, "leftline", column_info[j].left_line); + getTokenValue(line, "rightline", column_info[j].right_line); + getTokenValue(line, "width", column_info[j].p_width); + getTokenValue(line, "special", column_info[j].align_special); + } + + for (int i = 0; i < rows_; ++i) { + l_getline(is, line); + if (!prefixIs(line, " got" << + line << ")" << endl; + return; + } + getTokenValue(line, "topline", row_info[i].top_line); + getTokenValue(line, "bottomline", row_info[i].bottom_line); + getTokenValue(line, "newpage", row_info[i].newpage); + for (int j = 0; j < columns_; ++j) { + l_getline(is, line); + if (!prefixIs(line, " got" << + line << ")" << endl; + return; + } + getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn); + getTokenValue(line, "alignment", cell_info[i][j].alignment); + getTokenValue(line, "valignment", cell_info[i][j].valignment); + getTokenValue(line, "topline", cell_info[i][j].top_line); + getTokenValue(line, "bottomline", cell_info[i][j].bottom_line); + getTokenValue(line, "leftline", cell_info[i][j].left_line); + getTokenValue(line, "rightline", cell_info[i][j].right_line); + getTokenValue(line, "rotate", cell_info[i][j].rotate); + getTokenValue(line, "usebox", cell_info[i][j].usebox); + getTokenValue(line, "width", cell_info[i][j].p_width); + getTokenValue(line, "special", cell_info[i][j].align_special); + l_getline(is, line); + if (prefixIs(line, "\\begin_inset")) { + cell_info[i][j].inset.Read(buf, lex); + l_getline(is, line); + } + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << + line << ")" << endl; + return; + } + } + l_getline(is, line); + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << + line << ")" << endl; + return; + } + } + while (line != "") { + l_getline(is, line); + } + set_row_column_number_info(); +} + +#else + void LyXTabular::Read(Buffer const * buf, LyXLex & lex) { string line; @@ -1223,7 +1516,7 @@ void LyXTabular::Read(Buffer const * buf, LyXLex & lex) } set_row_column_number_info(); } - +#endif void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) { @@ -1286,10 +1579,10 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) cont_row_info = vector(rows_arg); SetLongTabular(is_long_tabular_arg); SetRotateTabular(rotate_arg); - endhead = a; - endfirsthead = b; - endfoot = c; - endlastfoot = d; + endhead = a + 1; + endfirsthead = b + 1; + endfoot = c + 1; + endlastfoot = d + 1; for (i = 0; i < rows_; ++i) { a = b = c = d = e = f = g = 0; is >> a >> b >> c >> d; @@ -1940,6 +2233,9 @@ bool LyXTabular::IsPartOfMultiColumn(int row, int column) const int LyXTabular::TeXTopHLine(ostream & os, int row) const { + if ((row < 0) || (row >= rows_)) + return 0; + int const fcell = GetFirstCellInRow(row); int const n = NumberOfCellsInRow(fcell) + fcell; int tmp = 0; @@ -1970,6 +2266,9 @@ int LyXTabular::TeXTopHLine(ostream & os, int row) const int LyXTabular::TeXBottomHLine(ostream & os, int row) const { + if ((row < 0) || (row >= rows_)) + return 0; + int const fcell = GetFirstCellInRow(row); int const n = NumberOfCellsInRow(fcell) + fcell; int tmp = 0; @@ -2187,8 +2486,7 @@ int LyXTabular::Latex(Buffer const * buf, } } if (ret > bret) { - if (i > 0) - ret += TeXBottomHLine(os, i-1); + ret += TeXBottomHLine(os, i-1); ret += TeXTopHLine(os, i); } for (int j = 0; j < columns_; ++j) { @@ -2232,8 +2530,8 @@ int LyXTabular::Latex(Buffer const * buf, os << "\\endlastfoot\n"; ++ret; } - if (ret > bret) - ret += TeXBottomHLine(os, i); +// if (ret > bret) +// ret += TeXBottomHLine(os, i); if (row_info[i].newpage) { os << "\\newpage\n"; ++ret;