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