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"
26 #ifndef CXX_GLOBAL_CSTD
32 bool getTokenValue(string const & str, char const * token, string & ret)
34 size_t token_length = strlen(token);
35 string::size_type pos = str.find(token);
37 if (pos == string::npos || pos + token_length + 1 >= str.length()
38 || str[pos + token_length] != '=')
41 pos += token_length + 1;
43 if ((ch != '"') && (ch != '\'')) { // only read till next space
47 while ((pos < str.length() - 1) && (str[++pos] != ch))
54 bool getTokenValue(string const & str, char const * token, int & num)
56 string::size_type pos = str.find(token);
57 char ch = str[pos + strlen(token)];
59 if ((pos == string::npos) || (ch != '='))
62 pos += strlen(token) + 1;
64 if ((ch != '"') && (ch != '\'')) { // only read till next space
70 while ((pos < str.length() - 1) && IsDigit(str[pos]))
78 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
81 bool const ret = getTokenValue(str, token, tmp);
82 num = static_cast<LyXAlignment>(tmp);
87 bool getTokenValue(string const & str, char const * token,
88 LyXTabular::VAlignment & num)
91 bool const ret = getTokenValue(str, token, tmp);
92 num = static_cast<LyXTabular::VAlignment>(tmp);
97 bool getTokenValue(string const & str, char const * token,
98 LyXTabular::BoxType & num)
101 bool ret = getTokenValue(str, token, tmp);
102 num = static_cast<LyXTabular::BoxType>(tmp);
107 bool getTokenValue(string const & str, char const * token, bool & flag)
109 string::size_type pos = str.find(token);
110 char ch = str[pos + strlen(token)];
112 if ((pos == string::npos) || (ch != '='))
115 pos += strlen(token) + 1;
117 if ((ch != '"') && (ch != '\'')) { // only read till next space
123 while ((pos < str.length() - 1) && IsDigit(str[pos]))
126 flag = strToInt(ret);
131 bool getTokenValue(string const & str, const char * token, LyXLength & len)
134 if (!getTokenValue(str, token, tmp))
136 return isValidLength(tmp, &len);
141 void l_getline(istream & is, string & str)
144 //#warning old l_getline
154 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
155 LyXLex & lex, string const & l)
160 if (!getTokenValue(line, "rows", rows_arg))
162 if (!getTokenValue(line, "columns", columns_arg))
164 Init(buf->params, rows_arg, columns_arg);
166 if (!prefixIs(line, "<Features ")) {
167 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
171 getTokenValue(line, "islongtable", is_long_tabular);
177 getTokenValue(line, "endhead", hrow);
178 getTokenValue(line, "endfirsthead", fhrow);
179 getTokenValue(line, "endfoot", frow);
180 getTokenValue(line, "endlastfoot", lfrow);
181 setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
183 for (int i = 0; i < rows_; ++i) {
185 if (!prefixIs(line, "<Row ")) {
186 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
190 getTokenValue(line, "topline", row_info[i].top_line);
191 getTokenValue(line, "bottomline", row_info[i].bottom_line);
192 getTokenValue(line, "newpage", row_info[i].newpage);
193 for (int j = 0; j < columns_; ++j) {
195 if (!prefixIs(line,"<Column")) {
196 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
201 getTokenValue(line, "alignment", column_info[j].alignment);
202 getTokenValue(line, "valignment", column_info[j].valignment);
203 getTokenValue(line, "leftline", column_info[j].left_line);
204 getTokenValue(line, "rightline", column_info[j].right_line);
205 getTokenValue(line, "width", column_info[j].p_width);
206 getTokenValue(line, "special", column_info[j].align_special);
209 if (!prefixIs(line, "<Cell")) {
210 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
214 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
215 getTokenValue(line, "alignment", cell_info[i][j].alignment);
216 getTokenValue(line, "valignment", cell_info[i][j].valignment);
217 getTokenValue(line, "topline", cell_info[i][j].top_line);
218 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
219 getTokenValue(line, "leftline", cell_info[i][j].left_line);
220 getTokenValue(line, "rightline", cell_info[i][j].right_line);
221 getTokenValue(line, "rotate", cell_info[i][j].rotate);
222 getTokenValue(line, "usebox", cell_info[i][j].usebox);
223 getTokenValue(line, "width", cell_info[i][j].p_width);
224 getTokenValue(line, "special", cell_info[i][j].align_special);
226 if (prefixIs(line, "\\begin_inset")) {
227 cell_info[i][j].inset.read(buf, lex);
230 if (line != "</Cell>") {
231 lyxerr << "Wrong tabular format (expected </Cell> got" <<
236 if (line != "</Column>") {
237 lyxerr << "Wrong tabular format (expected </Column> got" <<
243 if (line != "</Row>") {
244 lyxerr << "Wrong tabular format (expected </Row> got" <<
249 while (line != "</LyXTabular>") {
252 set_row_column_number_info();