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