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 * ======================================================
19 #include "support/lstrings.h"
20 #include "support/textutils.h"
27 #ifndef CXX_GLOBAL_CSTD
33 bool getTokenValue(string const & str, char const * token, string & ret)
35 size_t token_length = strlen(token);
36 string::size_type pos = str.find(token);
38 if (pos == string::npos || pos + token_length + 1 >= str.length()
39 || str[pos + token_length] != '=')
42 pos += token_length + 1;
44 if ((ch != '"') && (ch != '\'')) { // only read till next space
48 while ((pos < str.length() - 1) && (str[++pos] != ch))
55 bool getTokenValue(string const & str, char const * token, int & num)
57 string::size_type pos = str.find(token);
58 char ch = str[pos + strlen(token)];
60 if ((pos == string::npos) || (ch != '='))
63 pos += strlen(token) + 1;
65 if ((ch != '"') && (ch != '\'')) { // only read till next space
71 while ((pos < str.length() - 1) && IsDigit(str[pos]))
79 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
82 bool const ret = getTokenValue(str, token, tmp);
83 num = static_cast<LyXAlignment>(tmp);
88 bool getTokenValue(string const & str, char const * token,
89 LyXTabular::VAlignment & num)
92 bool const ret = getTokenValue(str, token, tmp);
93 num = static_cast<LyXTabular::VAlignment>(tmp);
98 bool getTokenValue(string const & str, char const * token,
99 LyXTabular::BoxType & num)
102 bool ret = getTokenValue(str, token, tmp);
103 num = static_cast<LyXTabular::BoxType>(tmp);
108 bool getTokenValue(string const & str, char const * token, bool & flag)
110 string::size_type pos = str.find(token);
111 char ch = str[pos + strlen(token)];
113 if ((pos == string::npos) || (ch != '='))
116 pos += strlen(token) + 1;
118 if ((ch != '"') && (ch != '\'')) { // only read till next space
124 while ((pos < str.length() - 1) && IsDigit(str[pos]))
127 flag = strToInt(ret);
132 bool getTokenValue(string const & str, const char * token, LyXLength & len)
135 if (!getTokenValue(str, token, tmp))
137 return isValidLength(tmp, &len);
142 void l_getline(istream & is, string & str)
145 //#warning old l_getline
155 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
156 LyXLex & lex, string const & l)
161 if (!getTokenValue(line, "rows", rows_arg))
163 if (!getTokenValue(line, "columns", columns_arg))
165 Init(buf->params, rows_arg, columns_arg);
167 if (!prefixIs(line, "<Features ")) {
168 lyxerr << "Wrong tabular format (expected <Feture ...> got"
169 << line << ')' << endl;
172 getTokenValue(line, "islongtable", is_long_tabular);
178 getTokenValue(line, "endhead", hrow);
179 getTokenValue(line, "endfirsthead", fhrow);
180 getTokenValue(line, "endfoot", frow);
181 getTokenValue(line, "endlastfoot", lfrow);
182 setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
184 for (int i = 0; i < rows_; ++i) {
186 if (!prefixIs(line, "<Row ")) {
187 lyxerr << "Wrong tabular format (expected <Row ...> got"
188 << line << ')' << endl;
191 getTokenValue(line, "topline", row_info[i].top_line);
192 getTokenValue(line, "bottomline", row_info[i].bottom_line);
193 getTokenValue(line, "newpage", row_info[i].newpage);
194 for (int j = 0; j < columns_; ++j) {
196 if (!prefixIs(line,"<Column")) {
197 lyxerr << "Wrong tabular format (expected <Column ...> got"
198 << line << ')' << endl;
202 getTokenValue(line, "alignment", column_info[j].alignment);
203 getTokenValue(line, "valignment", column_info[j].valignment);
204 getTokenValue(line, "leftline", column_info[j].left_line);
205 getTokenValue(line, "rightline", column_info[j].right_line);
206 getTokenValue(line, "width", column_info[j].p_width);
207 getTokenValue(line, "special", column_info[j].align_special);
210 if (!prefixIs(line, "<Cell")) {
211 lyxerr << "Wrong tabular format (expected <Cell ...> got"
212 << line << ')' << endl;
215 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
216 getTokenValue(line, "alignment", cell_info[i][j].alignment);
217 getTokenValue(line, "valignment", cell_info[i][j].valignment);
218 getTokenValue(line, "topline", cell_info[i][j].top_line);
219 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
220 getTokenValue(line, "leftline", cell_info[i][j].left_line);
221 getTokenValue(line, "rightline", cell_info[i][j].right_line);
222 getTokenValue(line, "rotate", cell_info[i][j].rotate);
223 getTokenValue(line, "usebox", cell_info[i][j].usebox);
224 getTokenValue(line, "width", cell_info[i][j].p_width);
225 getTokenValue(line, "special", cell_info[i][j].align_special);
227 if (prefixIs(line, "\\begin_inset")) {
228 cell_info[i][j].inset.read(buf, lex);
231 if (line != "</Cell>") {
232 lyxerr << "Wrong tabular format (expected </Cell> got"
233 << line << ')' << endl;
237 if (line != "</Column>") {
238 lyxerr << "Wrong tabular format (expected </Column> got"
239 << line << ')' << endl;
244 if (line != "</Row>") {
245 lyxerr << "Wrong tabular format (expected </Row> got"
246 << line << ')' << endl;
250 while (line != "</LyXTabular>") {
253 set_row_column_number_info();