1 |
frodo |
2 |
/* |
2 |
|
|
parse_driver.c - Part of psiconv, a PSION 5 file formats converter |
3 |
|
|
Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> |
4 |
|
|
|
5 |
|
|
This program is free software; you can redistribute it and/or modify |
6 |
|
|
it under the terms of the GNU General Public License as published by |
7 |
|
|
the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
(at your option) any later version. |
9 |
|
|
|
10 |
|
|
This program is distributed in the hope that it will be useful, |
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
GNU General Public License for more details. |
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU General Public License |
16 |
|
|
along with this program; if not, write to the Free Software |
17 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include "config.h" |
21 |
|
|
#include <stdlib.h> |
22 |
|
|
|
23 |
|
|
#include "parse.h" |
24 |
|
|
#include "parse_routines.h" |
25 |
|
|
#include "data.h" |
26 |
|
|
|
27 |
frodo |
60 |
int psiconv_verbosity = PSICONV_VERB_WARN; |
28 |
|
|
|
29 |
frodo |
18 |
psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, |
30 |
|
|
psiconv_header_section *result) |
31 |
frodo |
2 |
{ |
32 |
|
|
psiconv_header_section header; |
33 |
|
|
psiconv_file_type_t res; |
34 |
frodo |
18 |
int leng; |
35 |
frodo |
2 |
|
36 |
frodo |
18 |
psiconv_parse_header_section(buf,0,0,&leng,&header); |
37 |
frodo |
2 |
res = header->file; |
38 |
frodo |
18 |
if (result) |
39 |
|
|
*result = header; |
40 |
|
|
else |
41 |
|
|
psiconv_free_header_section(header); |
42 |
|
|
if (length) |
43 |
|
|
*length = leng; |
44 |
frodo |
2 |
return res; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
int psiconv_parse(const psiconv_buffer buf,psiconv_file *result) |
48 |
|
|
{ |
49 |
|
|
int res=0; |
50 |
|
|
int lev=0; |
51 |
|
|
int off=0; |
52 |
frodo |
18 |
int leng; |
53 |
frodo |
2 |
|
54 |
|
|
(*result) = malloc(sizeof(**result)); |
55 |
|
|
|
56 |
frodo |
18 |
(*result)->type = psiconv_file_type(buf,&leng,NULL); |
57 |
frodo |
2 |
if ((*result)->type == psiconv_unknown_file) { |
58 |
|
|
psiconv_warn(lev+1,off,"Unknown file type: can't parse!"); |
59 |
|
|
(*result)->file = NULL; |
60 |
|
|
res = -1; |
61 |
|
|
} else if ((*result)->type == psiconv_word_file) |
62 |
frodo |
18 |
res = psiconv_parse_word_file(buf,lev+2,leng, |
63 |
frodo |
2 |
(psiconv_word_f *)(&((*result)->file))); |
64 |
|
|
else if ((*result)->type == psiconv_texted_file) |
65 |
frodo |
18 |
res = psiconv_parse_texted_file(buf,lev+2,leng, |
66 |
frodo |
2 |
(psiconv_texted_f *)(&((*result)->file))); |
67 |
frodo |
12 |
else if ((*result)->type == psiconv_mbm_file) |
68 |
frodo |
18 |
res = psiconv_parse_mbm_file(buf,lev+2,leng, |
69 |
frodo |
12 |
(psiconv_mbm_f *)(&((*result)->file))); |
70 |
frodo |
24 |
else if ((*result)->type == psiconv_sketch_file) |
71 |
|
|
res = psiconv_parse_sketch_file(buf,lev+2,leng, |
72 |
|
|
(psiconv_sketch_f *)(&((*result)->file))); |
73 |
frodo |
41 |
else if ((*result)->type == psiconv_clipart_file) |
74 |
|
|
res = psiconv_parse_clipart_file(buf,lev+2,leng, |
75 |
|
|
(psiconv_clipart_f *)(&((*result)->file))); |
76 |
frodo |
2 |
else { |
77 |
|
|
psiconv_warn(lev+1,off,"Can't parse this file yet!"); |
78 |
|
|
(*result)->file = NULL; |
79 |
|
|
} |
80 |
|
|
res = -1; |
81 |
|
|
|
82 |
|
|
return res; |
83 |
|
|
} |
84 |
|
|
|
85 |
frodo |
41 |
int psiconv_parse_clipart_file(const psiconv_buffer buf,int lev, |
86 |
|
|
psiconv_u32 off, psiconv_clipart_f *result) |
87 |
|
|
{ |
88 |
frodo |
42 |
int res=0; |
89 |
frodo |
43 |
int i; |
90 |
|
|
psiconv_jumptable_section table; |
91 |
|
|
psiconv_clipart_section clipart; |
92 |
|
|
psiconv_u32 *entry; |
93 |
|
|
|
94 |
|
|
psiconv_progress(lev+1,off,"Going to read a clipart file"); |
95 |
frodo |
41 |
(*result) = malloc(sizeof(**result)); |
96 |
frodo |
43 |
|
97 |
|
|
psiconv_progress(lev+2,off,"Going to read the MBM jumptable"); |
98 |
|
|
res |= psiconv_parse_jumptable_section(buf,lev+2,off, NULL,&table); |
99 |
|
|
|
100 |
|
|
psiconv_progress(lev+2,off,"Going to read the clipart sections"); |
101 |
|
|
(*result)->sections = psiconv_list_new(sizeof(*clipart)); |
102 |
|
|
for (i = 0; i < psiconv_list_length(table); i ++) { |
103 |
|
|
entry = psiconv_list_get(table,i); |
104 |
|
|
psiconv_progress(lev+3,off,"Going to read clipart section %i",i); |
105 |
|
|
psiconv_parse_clipart_section(buf,lev+3,*entry,NULL,&clipart); |
106 |
|
|
psiconv_list_add((*result)->sections,clipart); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
psiconv_free_jumptable_section(table); |
110 |
|
|
psiconv_progress(lev+1,off,"End of clipart file"); |
111 |
|
|
return res; |
112 |
frodo |
41 |
} |
113 |
|
|
|
114 |
frodo |
12 |
int psiconv_parse_mbm_file(const psiconv_buffer buf,int lev, psiconv_u32 off, |
115 |
|
|
psiconv_mbm_f *result) |
116 |
|
|
{ |
117 |
|
|
int res=0; |
118 |
|
|
int i; |
119 |
frodo |
42 |
psiconv_jumptable_section table; |
120 |
frodo |
12 |
psiconv_paint_data_section paint; |
121 |
|
|
psiconv_u32 *entry; |
122 |
frodo |
18 |
psiconv_u32 sto; |
123 |
frodo |
12 |
|
124 |
|
|
psiconv_progress(lev+1,off,"Going to read a mbm file"); |
125 |
|
|
*result = malloc(sizeof(**result)); |
126 |
|
|
|
127 |
frodo |
18 |
psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); |
128 |
|
|
sto = psiconv_read_u32(buf,lev+2,off); |
129 |
|
|
psiconv_debug(lev+2,off,"Offset: %08x",sto); |
130 |
frodo |
12 |
|
131 |
|
|
psiconv_progress(lev+2,off,"Going to read the MBM jumptable"); |
132 |
frodo |
42 |
res |= psiconv_parse_jumptable_section(buf,lev+2,sto, NULL,&table); |
133 |
frodo |
12 |
|
134 |
frodo |
13 |
psiconv_progress(lev+2,off,"Going to read the picture sections"); |
135 |
frodo |
12 |
(*result)->sections = psiconv_list_new(sizeof(*paint)); |
136 |
|
|
for (i = 0; i < psiconv_list_length(table); i ++) { |
137 |
|
|
entry = psiconv_list_get(table,i); |
138 |
frodo |
13 |
psiconv_progress(lev+3,off,"Going to read picture section %i",i); |
139 |
frodo |
45 |
psiconv_parse_paint_data_section(buf,lev+3,*entry,NULL,0,&paint); |
140 |
frodo |
13 |
psiconv_list_add((*result)->sections,paint); |
141 |
frodo |
12 |
} |
142 |
|
|
|
143 |
frodo |
42 |
psiconv_free_jumptable_section(table); |
144 |
frodo |
12 |
psiconv_progress(lev+1,off,"End of mbm file"); |
145 |
|
|
return res; |
146 |
|
|
} |
147 |
|
|
|
148 |
frodo |
24 |
int psiconv_parse_sketch_file(const psiconv_buffer buf,int lev, |
149 |
|
|
psiconv_u32 off, |
150 |
|
|
psiconv_sketch_f *result) |
151 |
|
|
{ |
152 |
|
|
psiconv_section_table_section table; |
153 |
|
|
psiconv_application_id_section appl_id; |
154 |
|
|
psiconv_u32 applid_sec = 0; |
155 |
|
|
psiconv_u32 sketch_sec = 0; |
156 |
|
|
psiconv_u32 sto; |
157 |
|
|
psiconv_section_table_entry entry; |
158 |
|
|
int i; |
159 |
|
|
int res=0; |
160 |
|
|
char *temp_str; |
161 |
|
|
|
162 |
|
|
psiconv_progress(lev+1,off,"Going to read a sketch file"); |
163 |
|
|
*result = malloc(sizeof(**result)); |
164 |
|
|
|
165 |
|
|
psiconv_progress(lev+2,off, |
166 |
|
|
"Going to read the offset of the section table section"); |
167 |
|
|
sto = psiconv_read_u32(buf,lev+2,off); |
168 |
|
|
psiconv_debug(lev+2,off,"Offset: %08x",sto); |
169 |
|
|
|
170 |
|
|
psiconv_progress(lev+2,sto, "Going to read the section table section"); |
171 |
|
|
res |= psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table); |
172 |
|
|
|
173 |
|
|
for (i = 0; i < psiconv_list_length(table); i ++) { |
174 |
|
|
psiconv_progress(lev+2,sto, "Going to read entry %d",i); |
175 |
|
|
entry = psiconv_list_get(table,i); |
176 |
|
|
if (entry->id == PSICONV_ID_APPL_ID_SECTION) { |
177 |
|
|
applid_sec = entry->offset; |
178 |
|
|
psiconv_debug(lev+3,sto, |
179 |
|
|
"Found the Application ID section at %08x",applid_sec); |
180 |
|
|
} else if (entry->id == PSICONV_ID_SKETCH_SECTION) { |
181 |
|
|
sketch_sec = entry->offset; |
182 |
|
|
psiconv_debug(lev+3,sto, |
183 |
|
|
"Found the Sketch section at %08x",sketch_sec); |
184 |
|
|
} else { |
185 |
|
|
psiconv_warn(lev+3,sto, |
186 |
|
|
"Found unknown section in the Section Table"); |
187 |
|
|
psiconv_debug(lev+3,sto, |
188 |
|
|
"Section ID %08x, offset %08x",entry->id,entry->offset); |
189 |
|
|
res = -1; |
190 |
|
|
} |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
psiconv_progress(lev+2,sto, "Looking for the Application ID section"); |
194 |
|
|
if (! applid_sec) { |
195 |
|
|
psiconv_warn(lev+2,sto, |
196 |
|
|
"Application ID section not found in the section table"); |
197 |
|
|
res = -1; |
198 |
|
|
} else { |
199 |
|
|
psiconv_debug(lev+2,sto, |
200 |
|
|
"Application ID section at offset %08x",applid_sec); |
201 |
|
|
res |= psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL, |
202 |
|
|
&appl_id); |
203 |
|
|
} |
204 |
|
|
if ((appl_id->id != PSICONV_ID_SKETCH) || |
205 |
|
|
strcmp(appl_id->name,"Paint.app")) { |
206 |
|
|
psiconv_warn(lev+2,applid_sec, |
207 |
|
|
"Application ID section contains unexpected data"); |
208 |
|
|
psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
209 |
|
|
PSICONV_ID_SKETCH,appl_id->id); |
210 |
|
|
temp_str = psiconv_make_printable(appl_id->name); |
211 |
|
|
psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
212 |
|
|
"Paint.app",temp_str); |
213 |
|
|
free(temp_str); |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
psiconv_progress(lev+2,sto, "Looking for the Sketch section"); |
217 |
|
|
if (! sketch_sec) { |
218 |
|
|
psiconv_warn(lev+2,sto, |
219 |
|
|
"Sketch section not found in the section table"); |
220 |
|
|
res = -1; |
221 |
|
|
} else { |
222 |
|
|
psiconv_debug(lev+2,sto, |
223 |
|
|
"Sketch section at offset %08x",applid_sec); |
224 |
|
|
res |= psiconv_parse_sketch_section(buf,lev+2,sketch_sec,NULL,0, |
225 |
|
|
&(*result)->sketch_sec); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
psiconv_free_application_id_section(appl_id); |
229 |
|
|
psiconv_free_section_table_section(table); |
230 |
|
|
|
231 |
|
|
psiconv_progress(lev+1,off,"End of word file"); |
232 |
|
|
return res; |
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
frodo |
18 |
int psiconv_parse_texted_file(const psiconv_buffer buf,int lev, |
238 |
|
|
psiconv_u32 off, |
239 |
frodo |
2 |
psiconv_texted_f *result) |
240 |
|
|
{ |
241 |
|
|
int res=0; |
242 |
|
|
psiconv_section_table_section table; |
243 |
|
|
psiconv_application_id_section appl_id; |
244 |
|
|
char *temp_str; |
245 |
|
|
psiconv_character_layout base_char; |
246 |
|
|
psiconv_paragraph_layout base_para; |
247 |
|
|
psiconv_u32 page_sec = 0; |
248 |
|
|
psiconv_u32 texted_sec = 0; |
249 |
|
|
psiconv_u32 applid_sec = 0; |
250 |
frodo |
18 |
psiconv_u32 sto; |
251 |
frodo |
2 |
psiconv_section_table_entry entry; |
252 |
|
|
int i; |
253 |
|
|
|
254 |
|
|
psiconv_progress(lev+1,off,"Going to read a texted file"); |
255 |
|
|
*result = malloc(sizeof(**result)); |
256 |
|
|
|
257 |
frodo |
24 |
psiconv_progress(lev+2,off, |
258 |
|
|
"Going to read the offset of the section table section"); |
259 |
frodo |
18 |
sto = psiconv_read_u32(buf,lev+2,off); |
260 |
|
|
psiconv_debug(lev+2,off,"Offset: %08x",sto); |
261 |
frodo |
2 |
|
262 |
frodo |
18 |
psiconv_progress(lev+2,sto, "Going to read the section table section"); |
263 |
|
|
res |= psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table); |
264 |
frodo |
2 |
|
265 |
|
|
for (i = 0; i < psiconv_list_length(table); i ++) { |
266 |
frodo |
18 |
psiconv_progress(lev+2,sto, "Going to read entry %d",i); |
267 |
frodo |
2 |
entry = psiconv_list_get(table,i); |
268 |
|
|
if (entry->id == PSICONV_ID_APPL_ID_SECTION) { |
269 |
|
|
applid_sec = entry->offset; |
270 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
271 |
frodo |
2 |
"Found the Application ID section at %08x",applid_sec); |
272 |
|
|
} else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) { |
273 |
|
|
page_sec = entry->offset; |
274 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
275 |
frodo |
2 |
"Found the Page Layout section at %08x",page_sec); |
276 |
|
|
} else if (entry->id == PSICONV_ID_TEXTED) { |
277 |
|
|
texted_sec = entry->offset; |
278 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
279 |
frodo |
2 |
"Found the TextEd section at %08x",texted_sec); |
280 |
|
|
} else { |
281 |
frodo |
18 |
psiconv_warn(lev+3,sto, |
282 |
frodo |
2 |
"Found unknown section in the Section Table"); |
283 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
284 |
frodo |
2 |
"Section ID %08x, offset %08x",entry->id,entry->offset); |
285 |
|
|
res = -1; |
286 |
|
|
} |
287 |
|
|
} |
288 |
|
|
|
289 |
frodo |
18 |
psiconv_progress(lev+2,sto, "Looking for the Application ID section"); |
290 |
frodo |
2 |
if (! applid_sec) { |
291 |
frodo |
18 |
psiconv_warn(lev+2,sto, |
292 |
frodo |
2 |
"Application ID section not found in the section table"); |
293 |
|
|
res = -1; |
294 |
|
|
} else { |
295 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
296 |
frodo |
2 |
"Application ID section at offset %08x",applid_sec); |
297 |
|
|
res |= psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL, |
298 |
|
|
&appl_id); |
299 |
|
|
} |
300 |
|
|
if ((appl_id->id != PSICONV_ID_TEXTED) || |
301 |
|
|
strcmp(appl_id->name,"TextEd.app")) { |
302 |
|
|
psiconv_warn(lev+2,applid_sec, |
303 |
|
|
"Application ID section contains unexpected data"); |
304 |
|
|
psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
305 |
|
|
PSICONV_ID_TEXTED,appl_id->id); |
306 |
|
|
temp_str = psiconv_make_printable(appl_id->name); |
307 |
|
|
psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
308 |
frodo |
24 |
"TextEd.app",temp_str); |
309 |
frodo |
2 |
free(temp_str); |
310 |
|
|
} |
311 |
|
|
|
312 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
313 |
frodo |
2 |
"Looking for the Page layout section"); |
314 |
|
|
if (! page_sec) { |
315 |
frodo |
18 |
psiconv_warn(lev+2,sto, |
316 |
frodo |
2 |
"Page layout section not found in the section table"); |
317 |
|
|
(*result)->page_sec = NULL; |
318 |
|
|
res = -1; |
319 |
|
|
} else { |
320 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
321 |
frodo |
2 |
"Page layout section at offset %08x",page_sec); |
322 |
|
|
res |= psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL, |
323 |
|
|
&(*result)->page_sec); |
324 |
|
|
} |
325 |
|
|
|
326 |
|
|
base_char = psiconv_basic_character_layout(); |
327 |
|
|
base_para = psiconv_basic_paragraph_layout(); |
328 |
|
|
|
329 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
330 |
frodo |
2 |
"Looking for the TextEd section"); |
331 |
|
|
if (! texted_sec) { |
332 |
frodo |
18 |
psiconv_warn(lev+2,sto, |
333 |
frodo |
2 |
"TextEd section not found in the section table"); |
334 |
|
|
(*result)->texted_sec = NULL; |
335 |
|
|
res = -1; |
336 |
|
|
} else { |
337 |
frodo |
18 |
psiconv_debug(lev+2,sto, "TextEd section at offset %08x",texted_sec); |
338 |
frodo |
2 |
res |= psiconv_parse_texted_section(buf,lev+2,texted_sec,NULL, |
339 |
|
|
&(*result)->texted_sec, |
340 |
|
|
base_char,base_para); |
341 |
|
|
} |
342 |
|
|
psiconv_free_character_layout(base_char); |
343 |
|
|
psiconv_free_paragraph_layout(base_para); |
344 |
|
|
|
345 |
|
|
psiconv_free_application_id_section(appl_id); |
346 |
|
|
psiconv_free_section_table_section(table); |
347 |
|
|
|
348 |
|
|
psiconv_progress(lev+1,off,"End of word file"); |
349 |
|
|
return res; |
350 |
|
|
} |
351 |
|
|
|
352 |
|
|
int psiconv_parse_word_file(const psiconv_buffer buf,int lev, psiconv_u32 off, |
353 |
|
|
psiconv_word_f *result) |
354 |
|
|
{ |
355 |
|
|
int res=0; |
356 |
|
|
psiconv_section_table_section table; |
357 |
|
|
psiconv_application_id_section appl_id; |
358 |
|
|
char *temp_str; |
359 |
|
|
psiconv_u32 pwd_sec = 0; |
360 |
|
|
psiconv_u32 status_sec = 0; |
361 |
|
|
psiconv_u32 styles_sec = 0; |
362 |
|
|
psiconv_u32 page_sec = 0; |
363 |
|
|
psiconv_u32 text_sec = 0; |
364 |
|
|
psiconv_u32 layout_sec = 0; |
365 |
|
|
psiconv_u32 applid_sec = 0; |
366 |
|
|
psiconv_section_table_entry entry; |
367 |
frodo |
18 |
psiconv_u32 sto; |
368 |
frodo |
2 |
int i; |
369 |
|
|
|
370 |
|
|
psiconv_progress(lev+1,off,"Going to read a word file"); |
371 |
|
|
*result = malloc(sizeof(**result)); |
372 |
|
|
|
373 |
frodo |
24 |
psiconv_progress(lev+2,off, |
374 |
|
|
"Going to read the offset of the section table section"); |
375 |
frodo |
18 |
sto = psiconv_read_u32(buf,lev+2,off); |
376 |
|
|
psiconv_debug(lev+2,off,"Offset: %08x",sto); |
377 |
frodo |
2 |
|
378 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
379 |
frodo |
2 |
"Going to read the section table section"); |
380 |
frodo |
18 |
res |= psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table); |
381 |
frodo |
2 |
|
382 |
|
|
for (i = 0; i < psiconv_list_length(table); i ++) { |
383 |
frodo |
18 |
psiconv_progress(lev+2,sto, "Going to read entry %d",i); |
384 |
frodo |
2 |
entry = psiconv_list_get(table,i); |
385 |
|
|
if (entry->id == PSICONV_ID_APPL_ID_SECTION) { |
386 |
|
|
applid_sec = entry->offset; |
387 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
388 |
frodo |
2 |
"Found the Application ID section at %08x",applid_sec); |
389 |
|
|
} else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) { |
390 |
|
|
page_sec = entry->offset; |
391 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
392 |
frodo |
2 |
"Found the Page Layout section at %08x",page_sec); |
393 |
|
|
} else if (entry->id == PSICONV_ID_TEXT_SECTION) { |
394 |
|
|
text_sec = entry->offset; |
395 |
frodo |
18 |
psiconv_debug(lev+3,sto, "Found the Text section at %08x",text_sec); |
396 |
frodo |
2 |
} else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { |
397 |
|
|
pwd_sec = entry->offset; |
398 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
399 |
frodo |
2 |
"Found the Password section at %08x",pwd_sec); |
400 |
frodo |
18 |
psiconv_warn(lev+3,sto, |
401 |
frodo |
2 |
"Password section found - can't read encrypted data"); |
402 |
|
|
res = -1; |
403 |
|
|
} else if (entry->id == PSICONV_ID_WORD_STATUS_SECTION) { |
404 |
|
|
status_sec = entry->offset; |
405 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
406 |
frodo |
2 |
"Found the Word Status section at %08x",status_sec); |
407 |
|
|
} else if (entry->id == PSICONV_ID_WORD_STYLES_SECTION) { |
408 |
|
|
styles_sec = entry->offset; |
409 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
410 |
frodo |
2 |
"Found the Word Styles section at %08x",styles_sec); |
411 |
|
|
} else if (entry->id == PSICONV_ID_LAYOUT_SECTION) { |
412 |
|
|
layout_sec = entry->offset; |
413 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
414 |
frodo |
2 |
"Found the Layout section at %08x",layout_sec); |
415 |
|
|
} else { |
416 |
frodo |
18 |
psiconv_warn(lev+3,sto, |
417 |
frodo |
2 |
"Found unknown section in the Section Table"); |
418 |
frodo |
18 |
psiconv_debug(lev+3,sto, |
419 |
frodo |
2 |
"Section ID %08x, offset %08x",entry->id,entry->offset); |
420 |
|
|
res = -1; |
421 |
|
|
} |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
|
425 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
426 |
frodo |
2 |
"Looking for the Status section"); |
427 |
|
|
if (!status_sec) { |
428 |
frodo |
18 |
psiconv_warn(lev+2,sto, "Status section not found in the section table"); |
429 |
frodo |
2 |
res = -1; |
430 |
|
|
} else { |
431 |
frodo |
18 |
psiconv_debug(lev+2,sto, "Status section at offset %08x",status_sec); |
432 |
frodo |
2 |
res |= psiconv_parse_word_status_section(buf,lev+2,status_sec,NULL, |
433 |
|
|
&((*result)->status_sec)); |
434 |
|
|
} |
435 |
|
|
|
436 |
frodo |
18 |
psiconv_progress(lev+2,sto, "Looking for the Application ID section"); |
437 |
frodo |
2 |
if (! applid_sec) { |
438 |
frodo |
18 |
psiconv_warn(lev+2,sto, |
439 |
frodo |
2 |
"Application ID section not found in the section table"); |
440 |
|
|
res = -1; |
441 |
|
|
} else { |
442 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
443 |
frodo |
2 |
"Application ID section at offset %08x",applid_sec); |
444 |
|
|
res |= psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL, |
445 |
|
|
&appl_id); |
446 |
|
|
} |
447 |
|
|
if ((appl_id->id != PSICONV_ID_WORD) || |
448 |
|
|
strcmp(appl_id->name,"Word.app")) { |
449 |
|
|
psiconv_warn(lev+2,applid_sec, |
450 |
|
|
"Application ID section contains unexpected data"); |
451 |
|
|
psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
452 |
|
|
PSICONV_ID_WORD,appl_id->id); |
453 |
|
|
temp_str = psiconv_make_printable(appl_id->name); |
454 |
|
|
psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
455 |
frodo |
24 |
"Word.app",temp_str); |
456 |
frodo |
2 |
free(temp_str); |
457 |
|
|
} |
458 |
|
|
|
459 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
460 |
frodo |
2 |
"Looking for the Page layout section"); |
461 |
|
|
if (! page_sec) { |
462 |
frodo |
18 |
psiconv_warn(lev+2,sto, |
463 |
frodo |
2 |
"Page layout section not found in the section table"); |
464 |
|
|
(*result)->page_sec = NULL; |
465 |
|
|
res = -1; |
466 |
|
|
} else { |
467 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
468 |
frodo |
2 |
"Page layout section at offset %08x",page_sec); |
469 |
|
|
res |= psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL, |
470 |
|
|
&(*result)->page_sec); |
471 |
|
|
} |
472 |
|
|
|
473 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
474 |
frodo |
2 |
"Looking for the Word Style section"); |
475 |
|
|
if (!styles_sec) { |
476 |
frodo |
18 |
psiconv_warn(lev+2,sto, |
477 |
frodo |
2 |
"Word styles section not found in the section table"); |
478 |
|
|
(*result)->styles_sec = NULL; |
479 |
|
|
res = -1; |
480 |
|
|
} else { |
481 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
482 |
frodo |
2 |
"Word styles section at offset %08x",styles_sec); |
483 |
|
|
res |= psiconv_parse_word_styles_section(buf,lev+2,styles_sec,NULL, |
484 |
|
|
&(*result)->styles_sec); |
485 |
|
|
} |
486 |
|
|
|
487 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
488 |
frodo |
2 |
"Looking for the Text section"); |
489 |
|
|
if (!text_sec) { |
490 |
frodo |
18 |
psiconv_warn(lev+2,sto, "Text section not found in the section table"); |
491 |
frodo |
2 |
(*result)->paragraphs = NULL; |
492 |
|
|
res = -1; |
493 |
|
|
} else { |
494 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
495 |
frodo |
2 |
"Text section at offset %08x",text_sec); |
496 |
|
|
res |= psiconv_parse_text_section(buf,lev+2,text_sec,NULL, |
497 |
|
|
&(*result)->paragraphs); |
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
if (((*result)->paragraphs) && ((*result)->styles_sec)) { |
501 |
frodo |
18 |
psiconv_progress(lev+2,sto, |
502 |
frodo |
2 |
"Looking for the Layout section"); |
503 |
|
|
if (!layout_sec) { |
504 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
505 |
frodo |
2 |
"Layout section not found in the section table"); |
506 |
|
|
res = -1; |
507 |
|
|
} else { |
508 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
509 |
frodo |
2 |
"Layout section at offset %08x",layout_sec); |
510 |
|
|
res |= psiconv_parse_styled_layout_section(buf,lev+2,layout_sec,NULL, |
511 |
|
|
(*result)->paragraphs, |
512 |
|
|
(*result)->styles_sec); |
513 |
|
|
} |
514 |
|
|
} else |
515 |
frodo |
18 |
psiconv_debug(lev+2,sto, |
516 |
frodo |
2 |
"Skipping search for Layout section, as either the " |
517 |
|
|
"text or the word styles section was not found"); |
518 |
|
|
|
519 |
|
|
psiconv_free_application_id_section(appl_id); |
520 |
|
|
psiconv_free_section_table_section(table); |
521 |
|
|
|
522 |
|
|
psiconv_progress(lev+1,off,"End of word file"); |
523 |
|
|
return res; |
524 |
|
|
} |