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