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