]> git.lyx.org Git - lyx.git/blob - src/tabular-old.C
Applied Angus patch to compile on DEC C++ and to avoid name clashes
[lyx.git] / src / tabular-old.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000 The LyX Team.
7  *
8  *           @author: Jürgen Vigna
9  *
10  * ====================================================== 
11  */
12
13 #include <config.h>
14
15 #include "tabular.h"
16 #include "debug.h"
17 #include "support/lstrings.h"
18
19 using std::istream;
20 using std::getline;
21 using std::endl;
22
23
24 namespace {
25
26 bool getTokenValue(string const & str, const char * token, string & ret)
27 {
28     size_t token_length = strlen(token);
29     string::size_type pos = str.find(token);
30
31     if (pos == string::npos || pos+token_length+1 >= str.length()
32         || str[pos+token_length] != '=')
33         return false;
34     ret.erase();
35     pos += token_length + 1;
36     char ch = str[pos];
37     if ((ch != '"') && (ch != '\'')) { // only read till next space
38         ret += ch;
39         ch = ' ';
40     }
41     while((pos < str.length() - 1) && (str[++pos] != ch))
42         ret += str[pos];
43
44     return true;
45 }
46
47
48 bool getTokenValue(string const & str, const char * token, int & num)
49 {
50     string::size_type pos = str.find(token);
51     char ch = str[pos + strlen(token)];
52
53     if ((pos == string::npos) || (ch != '='))
54         return false;
55     string ret;
56     pos += strlen(token) + 1;
57     ch = str[pos];
58     if ((ch != '"') && (ch != '\'')) { // only read till next space
59         if (!isdigit(ch))
60             return false;
61         ret += ch;
62     }
63     ++pos;
64     while((pos < str.length() - 1) && isdigit(str[pos]))
65         ret += str[pos++];
66
67     num = strToInt(ret);
68     return true;
69 }
70
71
72 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
73 {
74     int tmp;
75     bool const ret = getTokenValue(str, token, tmp);
76     num = static_cast<LyXAlignment>(tmp);
77     return ret;
78 }
79
80
81 bool getTokenValue(string const & str, const char * token,
82                    LyXTabular::VAlignment & num)
83 {
84     int tmp;
85     bool const ret = getTokenValue(str, token, tmp);
86     num = static_cast<LyXTabular::VAlignment>(tmp);
87     return ret;
88 }
89
90
91 bool getTokenValue(string const & str, const char * token,
92                    LyXTabular::BoxType & num)
93 {
94     int tmp;
95     bool ret = getTokenValue(str, token, tmp);
96     num = static_cast<LyXTabular::BoxType>(tmp);
97     return ret;
98 }
99
100
101 bool getTokenValue(string const & str, const char * token, bool & flag)
102 {
103     string::size_type pos = str.find(token);
104     char ch = str[pos + strlen(token)];
105
106     if ((pos == string::npos) || (ch != '='))
107         return false;
108     string ret;
109     pos += strlen(token) + 1;
110     ch = str[pos];
111     if ((ch != '"') && (ch != '\'')) { // only read till next space
112         if (!isdigit(ch))
113             return false;
114         ret += ch;
115     }
116     ++pos;
117     while((pos < str.length() - 1) && isdigit(str[pos]))
118         ret += str[pos++];
119
120     flag = strToInt(ret);
121     return true;
122 }
123
124
125 inline
126 void l_getline(istream & is, string & str)
127 {
128 #warning old l_getline
129     getline(is, str);
130     while(str.empty())
131         getline(is, str);
132 }
133
134 } // namespace anon
135
136
137 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
138                          LyXLex & lex, string const & l)
139 {
140     string line(l);
141     int rows_arg;
142     int columns_arg;
143     if (!getTokenValue(line, "rows", rows_arg))
144         return;
145     if (!getTokenValue(line, "columns", columns_arg))
146         return;
147     Init(rows_arg, columns_arg);
148     l_getline(is, line);
149     if (!prefixIs(line, "<Features ")) {
150         lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
151             line << ")" << endl;
152         return;
153     }
154     getTokenValue(line, "islongtable", is_long_tabular);
155     getTokenValue(line, "endhead", endhead);
156     getTokenValue(line, "endfirsthead", endfirsthead);
157     getTokenValue(line, "endfoot", endfoot);
158     getTokenValue(line, "endlastfoot", endlastfoot);
159
160     for (int i = 0; i < rows_; ++i) {
161         l_getline(is, line);
162         if (!prefixIs(line, "<Row ")) {
163             lyxerr << "Wrong tabular format (expected <Row ...> got" <<
164                 line << ")" << endl;
165             return;
166         }
167         getTokenValue(line, "topline", row_info[i].top_line);
168         getTokenValue(line, "bottomline", row_info[i].bottom_line);
169         getTokenValue(line, "newpage", row_info[i].newpage);
170         for (int j = 0; j < columns_; ++j) {
171             l_getline(is,line);
172             if (!prefixIs(line,"<Column")) {
173                 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
174                     line << ")" << endl;
175                 return;
176             }
177             if (!i) {
178                 getTokenValue(line, "alignment", column_info[j].alignment);
179                 getTokenValue(line, "valignment", column_info[j].valignment);
180                 getTokenValue(line, "leftline", column_info[j].left_line);
181                 getTokenValue(line, "rightline", column_info[j].right_line);
182                 getTokenValue(line, "width", column_info[j].p_width);
183                 getTokenValue(line, "special", column_info[j].align_special);
184             }
185             l_getline(is, line);
186             if (!prefixIs(line, "<Cell")) {
187                 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
188                     line << ")" << endl;
189                 return;
190             }
191             getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
192             getTokenValue(line, "alignment", cell_info[i][j].alignment);
193             getTokenValue(line, "valignment", cell_info[i][j].valignment);
194             getTokenValue(line, "topline", cell_info[i][j].top_line);
195             getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
196             getTokenValue(line, "leftline", cell_info[i][j].left_line);
197             getTokenValue(line, "rightline", cell_info[i][j].right_line);
198             getTokenValue(line, "rotate", cell_info[i][j].rotate);
199             getTokenValue(line, "usebox", cell_info[i][j].usebox);
200             getTokenValue(line, "width", cell_info[i][j].p_width);
201             getTokenValue(line, "special", cell_info[i][j].align_special);
202             l_getline(is, line);
203             if (prefixIs(line, "\\begin_inset")) {
204                 cell_info[i][j].inset.Read(buf, lex);
205                 l_getline(is, line);
206             }
207             if (line != "</Cell>") {
208                 lyxerr << "Wrong tabular format (expected </Cell> got" <<
209                     line << ")" << endl;
210                 return;
211             }
212             l_getline(is, line);
213             if (line != "</Column>") {
214                 lyxerr << "Wrong tabular format (expected </Column> got" <<
215                     line << ")" << endl;
216                 return;
217             }
218         }
219         l_getline(is, line);
220         if (line != "</Row>") {
221             lyxerr << "Wrong tabular format (expected </Row> got" <<
222                 line << ")" << endl;
223             return;
224         }
225     }
226     while (line != "</LyXTabular>") {
227         l_getline(is, line);
228     }
229     set_row_column_number_info();
230 }