2001-01-09 20:17:06 +00:00
|
|
|
|
/* This file is part of
|
|
|
|
|
* ======================================================
|
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 2000-2001 The LyX Team.
|
2001-01-09 20:17:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @author: J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* ======================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "tabular.h"
|
2002-03-03 20:25:07 +00:00
|
|
|
|
#include "buffer.h"
|
2001-01-09 20:17:06 +00:00
|
|
|
|
#include "debug.h"
|
2002-03-03 20:25:07 +00:00
|
|
|
|
|
2001-01-09 20:17:06 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2001-12-20 15:11:51 +00:00
|
|
|
|
#include "support/textutils.h"
|
2001-01-09 20:17:06 +00:00
|
|
|
|
|
|
|
|
|
using std::istream;
|
|
|
|
|
using std::getline;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
2001-06-01 10:53:24 +00:00
|
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
|
using std::strlen;
|
|
|
|
|
#endif
|
2001-01-09 20:17:06 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
|
bool getTokenValue(string const & str, char const * token, string & ret)
|
2001-01-09 20:17:06 +00:00
|
|
|
|
{
|
2001-06-01 10:53:24 +00:00
|
|
|
|
size_t token_length = strlen(token);
|
2001-01-09 20:17:06 +00:00
|
|
|
|
string::size_type pos = str.find(token);
|
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (pos == string::npos || pos + token_length + 1 >= str.length()
|
|
|
|
|
|| str[pos + token_length] != '=')
|
2001-01-09 20:17:06 +00:00
|
|
|
|
return false;
|
|
|
|
|
ret.erase();
|
|
|
|
|
pos += token_length + 1;
|
|
|
|
|
char ch = str[pos];
|
|
|
|
|
if ((ch != '"') && (ch != '\'')) { // only read till next space
|
|
|
|
|
ret += ch;
|
|
|
|
|
ch = ' ';
|
|
|
|
|
}
|
2001-12-05 08:04:20 +00:00
|
|
|
|
while ((pos < str.length() - 1) && (str[++pos] != ch))
|
2001-01-09 20:17:06 +00:00
|
|
|
|
ret += str[pos];
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
|
bool getTokenValue(string const & str, char const * token, int & num)
|
2001-01-09 20:17:06 +00:00
|
|
|
|
{
|
|
|
|
|
string::size_type pos = str.find(token);
|
2001-06-01 10:53:24 +00:00
|
|
|
|
char ch = str[pos + strlen(token)];
|
2001-01-09 20:17:06 +00:00
|
|
|
|
|
|
|
|
|
if ((pos == string::npos) || (ch != '='))
|
|
|
|
|
return false;
|
|
|
|
|
string ret;
|
2001-06-01 10:53:24 +00:00
|
|
|
|
pos += strlen(token) + 1;
|
2001-01-09 20:17:06 +00:00
|
|
|
|
ch = str[pos];
|
|
|
|
|
if ((ch != '"') && (ch != '\'')) { // only read till next space
|
2001-12-20 15:11:51 +00:00
|
|
|
|
if (!IsDigit(ch))
|
2001-01-09 20:17:06 +00:00
|
|
|
|
return false;
|
|
|
|
|
ret += ch;
|
|
|
|
|
}
|
|
|
|
|
++pos;
|
2001-12-20 15:11:51 +00:00
|
|
|
|
while ((pos < str.length() - 1) && IsDigit(str[pos]))
|
2001-01-09 20:17:06 +00:00
|
|
|
|
ret += str[pos++];
|
|
|
|
|
|
|
|
|
|
num = strToInt(ret);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
|
bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
|
2001-01-09 20:17:06 +00:00
|
|
|
|
{
|
|
|
|
|
int tmp;
|
|
|
|
|
bool const ret = getTokenValue(str, token, tmp);
|
|
|
|
|
num = static_cast<LyXAlignment>(tmp);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
|
bool getTokenValue(string const & str, char const * token,
|
2001-01-09 20:17:06 +00:00
|
|
|
|
LyXTabular::VAlignment & num)
|
|
|
|
|
{
|
|
|
|
|
int tmp;
|
|
|
|
|
bool const ret = getTokenValue(str, token, tmp);
|
|
|
|
|
num = static_cast<LyXTabular::VAlignment>(tmp);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
|
bool getTokenValue(string const & str, char const * token,
|
2001-01-09 20:17:06 +00:00
|
|
|
|
LyXTabular::BoxType & num)
|
|
|
|
|
{
|
|
|
|
|
int tmp;
|
|
|
|
|
bool ret = getTokenValue(str, token, tmp);
|
|
|
|
|
num = static_cast<LyXTabular::BoxType>(tmp);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
|
bool getTokenValue(string const & str, char const * token, bool & flag)
|
2001-01-09 20:17:06 +00:00
|
|
|
|
{
|
|
|
|
|
string::size_type pos = str.find(token);
|
2001-06-01 10:53:24 +00:00
|
|
|
|
char ch = str[pos + strlen(token)];
|
2001-01-09 20:17:06 +00:00
|
|
|
|
|
|
|
|
|
if ((pos == string::npos) || (ch != '='))
|
|
|
|
|
return false;
|
|
|
|
|
string ret;
|
2001-06-01 10:53:24 +00:00
|
|
|
|
pos += strlen(token) + 1;
|
2001-01-09 20:17:06 +00:00
|
|
|
|
ch = str[pos];
|
|
|
|
|
if ((ch != '"') && (ch != '\'')) { // only read till next space
|
2001-12-20 15:11:51 +00:00
|
|
|
|
if (!IsDigit(ch))
|
2001-01-09 20:17:06 +00:00
|
|
|
|
return false;
|
|
|
|
|
ret += ch;
|
|
|
|
|
}
|
|
|
|
|
++pos;
|
2001-12-20 15:11:51 +00:00
|
|
|
|
while ((pos < str.length() - 1) && IsDigit(str[pos]))
|
2001-01-09 20:17:06 +00:00
|
|
|
|
ret += str[pos++];
|
|
|
|
|
|
|
|
|
|
flag = strToInt(ret);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-11 17:26:52 +00:00
|
|
|
|
bool getTokenValue(string const & str, const char * token, LyXLength & len)
|
|
|
|
|
{
|
|
|
|
|
string tmp;
|
|
|
|
|
if (!getTokenValue(str, token, tmp))
|
|
|
|
|
return false;
|
|
|
|
|
return isValidLength(tmp, &len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
inline
|
2001-01-09 20:17:06 +00:00
|
|
|
|
void l_getline(istream & is, string & str)
|
|
|
|
|
{
|
2001-04-17 00:19:49 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2001-09-09 22:02:19 +00:00
|
|
|
|
//#warning old l_getline
|
2001-04-17 00:19:49 +00:00
|
|
|
|
#endif
|
2001-01-09 20:17:06 +00:00
|
|
|
|
getline(is, str);
|
2001-12-05 08:04:20 +00:00
|
|
|
|
while (str.empty())
|
2001-01-09 20:17:06 +00:00
|
|
|
|
getline(is, str);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2001-01-09 20:17:06 +00:00
|
|
|
|
|
|
|
|
|
void LyXTabular::ReadOld(Buffer const * buf, istream & is,
|
|
|
|
|
LyXLex & lex, string const & l)
|
|
|
|
|
{
|
|
|
|
|
string line(l);
|
|
|
|
|
int rows_arg;
|
|
|
|
|
int columns_arg;
|
|
|
|
|
if (!getTokenValue(line, "rows", rows_arg))
|
|
|
|
|
return;
|
|
|
|
|
if (!getTokenValue(line, "columns", columns_arg))
|
|
|
|
|
return;
|
2002-03-03 20:25:07 +00:00
|
|
|
|
Init(buf->params, rows_arg, columns_arg);
|
2001-01-09 20:17:06 +00:00
|
|
|
|
l_getline(is, line);
|
|
|
|
|
if (!prefixIs(line, "<Features ")) {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
|
|
|
|
|
line << ")" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
getTokenValue(line, "islongtable", is_long_tabular);
|
2001-12-19 21:25:34 +00:00
|
|
|
|
int hrow;
|
|
|
|
|
int fhrow;
|
|
|
|
|
int frow;
|
|
|
|
|
int lfrow;
|
|
|
|
|
|
|
|
|
|
getTokenValue(line, "endhead", hrow);
|
|
|
|
|
getTokenValue(line, "endfirsthead", fhrow);
|
|
|
|
|
getTokenValue(line, "endfoot", frow);
|
|
|
|
|
getTokenValue(line, "endlastfoot", lfrow);
|
2001-12-20 14:52:15 +00:00
|
|
|
|
setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
|
2001-01-09 20:17:06 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rows_; ++i) {
|
|
|
|
|
l_getline(is, line);
|
|
|
|
|
if (!prefixIs(line, "<Row ")) {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected <Row ...> 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,"<Column")) {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected <Column ...> got" <<
|
|
|
|
|
line << ")" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!i) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
l_getline(is, line);
|
|
|
|
|
if (!prefixIs(line, "<Cell")) {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected <Cell ...> 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")) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
cell_info[i][j].inset.read(buf, lex);
|
2001-01-09 20:17:06 +00:00
|
|
|
|
l_getline(is, line);
|
|
|
|
|
}
|
|
|
|
|
if (line != "</Cell>") {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected </Cell> got" <<
|
|
|
|
|
line << ")" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
l_getline(is, line);
|
|
|
|
|
if (line != "</Column>") {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected </Column> got" <<
|
|
|
|
|
line << ")" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
l_getline(is, line);
|
|
|
|
|
if (line != "</Row>") {
|
|
|
|
|
lyxerr << "Wrong tabular format (expected </Row> got" <<
|
|
|
|
|
line << ")" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (line != "</LyXTabular>") {
|
|
|
|
|
l_getline(is, line);
|
|
|
|
|
}
|
|
|
|
|
set_row_column_number_info();
|
|
|
|
|
}
|