1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * @author: Jürgen Vigna
10 * ======================================================
17 #include "support/lstrings.h"
18 #include "support/textutils.h"
24 #ifndef CXX_GLOBAL_CSTD
30 bool getTokenValue(string const & str, char const * token, string & ret)
32 size_t token_length = strlen(token);
33 string::size_type pos = str.find(token);
35 if (pos == string::npos || pos + token_length + 1 >= str.length()
36 || str[pos + token_length] != '=')
39 pos += token_length + 1;
41 if ((ch != '"') && (ch != '\'')) { // only read till next space
45 while ((pos < str.length() - 1) && (str[++pos] != ch))
52 bool getTokenValue(string const & str, char const * token, int & num)
54 string::size_type pos = str.find(token);
55 char ch = str[pos + strlen(token)];
57 if ((pos == string::npos) || (ch != '='))
60 pos += strlen(token) + 1;
62 if ((ch != '"') && (ch != '\'')) { // only read till next space
68 while ((pos < str.length() - 1) && IsDigit(str[pos]))
76 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
79 bool const ret = getTokenValue(str, token, tmp);
80 num = static_cast<LyXAlignment>(tmp);
85 bool getTokenValue(string const & str, char const * token,
86 LyXTabular::VAlignment & num)
89 bool const ret = getTokenValue(str, token, tmp);
90 num = static_cast<LyXTabular::VAlignment>(tmp);
95 bool getTokenValue(string const & str, char const * token,
96 LyXTabular::BoxType & num)
99 bool ret = getTokenValue(str, token, tmp);
100 num = static_cast<LyXTabular::BoxType>(tmp);
105 bool getTokenValue(string const & str, char const * token, bool & flag)
107 string::size_type pos = str.find(token);
108 char ch = str[pos + strlen(token)];
110 if ((pos == string::npos) || (ch != '='))
113 pos += strlen(token) + 1;
115 if ((ch != '"') && (ch != '\'')) { // only read till next space
121 while ((pos < str.length() - 1) && IsDigit(str[pos]))
124 flag = strToInt(ret);
129 bool getTokenValue(string const & str, const char * token, LyXLength & len)
132 if (!getTokenValue(str, token, tmp))
134 return isValidLength(tmp, &len);
139 void l_getline(istream & is, string & str)
142 //#warning old l_getline
152 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
153 LyXLex & lex, string const & l)
158 if (!getTokenValue(line, "rows", rows_arg))
160 if (!getTokenValue(line, "columns", columns_arg))
162 Init(rows_arg, columns_arg);
164 if (!prefixIs(line, "<Features ")) {
165 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
169 getTokenValue(line, "islongtable", is_long_tabular);
175 getTokenValue(line, "endhead", hrow);
176 getTokenValue(line, "endfirsthead", fhrow);
177 getTokenValue(line, "endfoot", frow);
178 getTokenValue(line, "endlastfoot", lfrow);
179 setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
181 for (int i = 0; i < rows_; ++i) {
183 if (!prefixIs(line, "<Row ")) {
184 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
188 getTokenValue(line, "topline", row_info[i].top_line);
189 getTokenValue(line, "bottomline", row_info[i].bottom_line);
190 getTokenValue(line, "newpage", row_info[i].newpage);
191 for (int j = 0; j < columns_; ++j) {
193 if (!prefixIs(line,"<Column")) {
194 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
199 getTokenValue(line, "alignment", column_info[j].alignment);
200 getTokenValue(line, "valignment", column_info[j].valignment);
201 getTokenValue(line, "leftline", column_info[j].left_line);
202 getTokenValue(line, "rightline", column_info[j].right_line);
203 getTokenValue(line, "width", column_info[j].p_width);
204 getTokenValue(line, "special", column_info[j].align_special);
207 if (!prefixIs(line, "<Cell")) {
208 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
212 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
213 getTokenValue(line, "alignment", cell_info[i][j].alignment);
214 getTokenValue(line, "valignment", cell_info[i][j].valignment);
215 getTokenValue(line, "topline", cell_info[i][j].top_line);
216 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
217 getTokenValue(line, "leftline", cell_info[i][j].left_line);
218 getTokenValue(line, "rightline", cell_info[i][j].right_line);
219 getTokenValue(line, "rotate", cell_info[i][j].rotate);
220 getTokenValue(line, "usebox", cell_info[i][j].usebox);
221 getTokenValue(line, "width", cell_info[i][j].p_width);
222 getTokenValue(line, "special", cell_info[i][j].align_special);
224 if (prefixIs(line, "\\begin_inset")) {
225 cell_info[i][j].inset.read(buf, lex);
228 if (line != "</Cell>") {
229 lyxerr << "Wrong tabular format (expected </Cell> got" <<
234 if (line != "</Column>") {
235 lyxerr << "Wrong tabular format (expected </Column> got" <<
241 if (line != "</Row>") {
242 lyxerr << "Wrong tabular format (expected </Row> got" <<
247 while (line != "</LyXTabular>") {
250 set_row_column_number_info();