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