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"
23 #ifndef CXX_GLOBAL_CSTD
29 bool getTokenValue(string const & str, char const * token, string & ret)
31 size_t token_length = strlen(token);
32 string::size_type pos = str.find(token);
34 if (pos == string::npos || pos + token_length + 1 >= str.length()
35 || str[pos + token_length] != '=')
38 pos += token_length + 1;
40 if ((ch != '"') && (ch != '\'')) { // only read till next space
44 while ((pos < str.length() - 1) && (str[++pos] != ch))
51 bool getTokenValue(string const & str, char const * token, int & num)
53 string::size_type pos = str.find(token);
54 char ch = str[pos + strlen(token)];
56 if ((pos == string::npos) || (ch != '='))
59 pos += strlen(token) + 1;
61 if ((ch != '"') && (ch != '\'')) { // only read till next space
67 while ((pos < str.length() - 1) && isdigit(str[pos]))
75 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
78 bool const ret = getTokenValue(str, token, tmp);
79 num = static_cast<LyXAlignment>(tmp);
84 bool getTokenValue(string const & str, char const * token,
85 LyXTabular::VAlignment & num)
88 bool const ret = getTokenValue(str, token, tmp);
89 num = static_cast<LyXTabular::VAlignment>(tmp);
94 bool getTokenValue(string const & str, char const * token,
95 LyXTabular::BoxType & num)
98 bool ret = getTokenValue(str, token, tmp);
99 num = static_cast<LyXTabular::BoxType>(tmp);
104 bool getTokenValue(string const & str, char const * token, bool & flag)
106 string::size_type pos = str.find(token);
107 char ch = str[pos + strlen(token)];
109 if ((pos == string::npos) || (ch != '='))
112 pos += strlen(token) + 1;
114 if ((ch != '"') && (ch != '\'')) { // only read till next space
120 while ((pos < str.length() - 1) && isdigit(str[pos]))
123 flag = strToInt(ret);
128 bool getTokenValue(string const & str, const char * token, LyXLength & len)
131 if (!getTokenValue(str, token, tmp))
133 return isValidLength(tmp, &len);
138 void l_getline(istream & is, string & str)
141 //#warning old l_getline
151 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
152 LyXLex & lex, string const & l)
157 if (!getTokenValue(line, "rows", rows_arg))
159 if (!getTokenValue(line, "columns", columns_arg))
161 Init(rows_arg, columns_arg);
163 if (!prefixIs(line, "<Features ")) {
164 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
168 getTokenValue(line, "islongtable", is_long_tabular);
174 getTokenValue(line, "endhead", hrow);
175 getTokenValue(line, "endfirsthead", fhrow);
176 getTokenValue(line, "endfoot", frow);
177 getTokenValue(line, "endlastfoot", lfrow);
178 setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
180 for (int i = 0; i < rows_; ++i) {
182 if (!prefixIs(line, "<Row ")) {
183 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
187 getTokenValue(line, "topline", row_info[i].top_line);
188 getTokenValue(line, "bottomline", row_info[i].bottom_line);
189 getTokenValue(line, "newpage", row_info[i].newpage);
190 for (int j = 0; j < columns_; ++j) {
192 if (!prefixIs(line,"<Column")) {
193 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
198 getTokenValue(line, "alignment", column_info[j].alignment);
199 getTokenValue(line, "valignment", column_info[j].valignment);
200 getTokenValue(line, "leftline", column_info[j].left_line);
201 getTokenValue(line, "rightline", column_info[j].right_line);
202 getTokenValue(line, "width", column_info[j].p_width);
203 getTokenValue(line, "special", column_info[j].align_special);
206 if (!prefixIs(line, "<Cell")) {
207 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
211 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
212 getTokenValue(line, "alignment", cell_info[i][j].alignment);
213 getTokenValue(line, "valignment", cell_info[i][j].valignment);
214 getTokenValue(line, "topline", cell_info[i][j].top_line);
215 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
216 getTokenValue(line, "leftline", cell_info[i][j].left_line);
217 getTokenValue(line, "rightline", cell_info[i][j].right_line);
218 getTokenValue(line, "rotate", cell_info[i][j].rotate);
219 getTokenValue(line, "usebox", cell_info[i][j].usebox);
220 getTokenValue(line, "width", cell_info[i][j].p_width);
221 getTokenValue(line, "special", cell_info[i][j].align_special);
223 if (prefixIs(line, "\\begin_inset")) {
224 cell_info[i][j].inset.read(buf, lex);
227 if (line != "</Cell>") {
228 lyxerr << "Wrong tabular format (expected </Cell> got" <<
233 if (line != "</Column>") {
234 lyxerr << "Wrong tabular format (expected </Column> got" <<
240 if (line != "</Row>") {
241 lyxerr << "Wrong tabular format (expected </Row> got" <<
246 while (line != "</LyXTabular>") {
249 set_row_column_number_info();