]> git.lyx.org Git - lyx.git/blob - src/tabular-old.C
Look for mathed xpms. Doesn't do anything yet due to lack of workable XPMs
[lyx.git] / src / tabular-old.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2000-2001 The LyX Team.
7  *
8  *           @author: Jürgen Vigna
9  *
10  * ======================================================
11  */
12
13 #include <config.h>
14
15 #include "tabular.h"
16 #include "buffer.h"
17 #include "debug.h"
18
19 #include "support/lstrings.h"
20 #include "support/textutils.h"
21
22 using std::abs;
23 using std::istream;
24 using std::getline;
25 using std::endl;
26
27 #ifndef CXX_GLOBAL_CSTD
28 using std::strlen;
29 #endif
30
31 namespace {
32
33 bool getTokenValue(string const & str, char const * token, string & ret)
34 {
35     size_t token_length = strlen(token);
36     string::size_type pos = str.find(token);
37
38     if (pos == string::npos || pos + token_length + 1 >= str.length()
39         || str[pos + token_length] != '=')
40         return false;
41     ret.erase();
42     pos += token_length + 1;
43     char ch = str[pos];
44     if ((ch != '"') && (ch != '\'')) { // only read till next space
45         ret += ch;
46         ch = ' ';
47     }
48     while ((pos < str.length() - 1) && (str[++pos] != ch))
49         ret += str[pos];
50
51     return true;
52 }
53
54
55 bool getTokenValue(string const & str, char const * token, int & num)
56 {
57     string::size_type pos = str.find(token);
58     char ch = str[pos + strlen(token)];
59
60     if ((pos == string::npos) || (ch != '='))
61         return false;
62     string ret;
63     pos += strlen(token) + 1;
64     ch = str[pos];
65     if ((ch != '"') && (ch != '\'')) { // only read till next space
66         if (!IsDigit(ch))
67             return false;
68         ret += ch;
69     }
70     ++pos;
71     while ((pos < str.length() - 1) && IsDigit(str[pos]))
72         ret += str[pos++];
73
74     num = strToInt(ret);
75     return true;
76 }
77
78
79 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
80 {
81     int tmp;
82     bool const ret = getTokenValue(str, token, tmp);
83     num = static_cast<LyXAlignment>(tmp);
84     return ret;
85 }
86
87
88 bool getTokenValue(string const & str, char const * token,
89                    LyXTabular::VAlignment & num)
90 {
91     int tmp;
92     bool const ret = getTokenValue(str, token, tmp);
93     num = static_cast<LyXTabular::VAlignment>(tmp);
94     return ret;
95 }
96
97
98 bool getTokenValue(string const & str, char const * token,
99                    LyXTabular::BoxType & num)
100 {
101     int tmp;
102     bool ret = getTokenValue(str, token, tmp);
103     num = static_cast<LyXTabular::BoxType>(tmp);
104     return ret;
105 }
106
107
108 bool getTokenValue(string const & str, char const * token, bool & flag)
109 {
110     string::size_type pos = str.find(token);
111     char ch = str[pos + strlen(token)];
112
113     if ((pos == string::npos) || (ch != '='))
114         return false;
115     string ret;
116     pos += strlen(token) + 1;
117     ch = str[pos];
118     if ((ch != '"') && (ch != '\'')) { // only read till next space
119         if (!IsDigit(ch))
120             return false;
121         ret += ch;
122     }
123     ++pos;
124     while ((pos < str.length() - 1) && IsDigit(str[pos]))
125         ret += str[pos++];
126
127     flag = strToInt(ret);
128     return true;
129 }
130
131
132 bool getTokenValue(string const & str, const char * token, LyXLength & len)
133 {
134         string tmp;
135         if (!getTokenValue(str, token, tmp))
136                 return false;
137         return isValidLength(tmp, &len);
138 }
139
140
141 inline
142 void l_getline(istream & is, string & str)
143 {
144 #ifdef WITH_WARNINGS
145 //#warning old l_getline
146 #endif
147     getline(is, str);
148     while (str.empty())
149         getline(is, str);
150 }
151
152 } // namespace anon
153
154
155 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
156                          LyXLex & lex, string const & l)
157 {
158     string line(l);
159     int rows_arg;
160     int columns_arg;
161     if (!getTokenValue(line, "rows", rows_arg))
162         return;
163     if (!getTokenValue(line, "columns", columns_arg))
164         return;
165     Init(buf->params, rows_arg, columns_arg);
166     l_getline(is, line);
167     if (!prefixIs(line, "<Features ")) {
168         lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
169             line << ")" << endl;
170         return;
171     }
172     getTokenValue(line, "islongtable", is_long_tabular);
173         int hrow;
174         int fhrow;
175         int frow;
176         int lfrow;
177
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));
183
184     for (int i = 0; i < rows_; ++i) {
185         l_getline(is, line);
186         if (!prefixIs(line, "<Row ")) {
187             lyxerr << "Wrong tabular format (expected <Row ...> got" <<
188                 line << ")" << endl;
189             return;
190         }
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) {
195             l_getline(is,line);
196             if (!prefixIs(line,"<Column")) {
197                 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
198                     line << ")" << endl;
199                 return;
200             }
201             if (!i) {
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);
208             }
209             l_getline(is, line);
210             if (!prefixIs(line, "<Cell")) {
211                 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
212                     line << ")" << endl;
213                 return;
214             }
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);
226             l_getline(is, line);
227             if (prefixIs(line, "\\begin_inset")) {
228                 cell_info[i][j].inset.read(buf, lex);
229                 l_getline(is, line);
230             }
231             if (line != "</Cell>") {
232                 lyxerr << "Wrong tabular format (expected </Cell> got" <<
233                     line << ")" << endl;
234                 return;
235             }
236             l_getline(is, line);
237             if (line != "</Column>") {
238                 lyxerr << "Wrong tabular format (expected </Column> got" <<
239                     line << ")" << endl;
240                 return;
241             }
242         }
243         l_getline(is, line);
244         if (line != "</Row>") {
245             lyxerr << "Wrong tabular format (expected </Row> got" <<
246                 line << ")" << endl;
247             return;
248         }
249     }
250     while (line != "</LyXTabular>") {
251         l_getline(is, line);
252     }
253     set_row_column_number_info();
254 }