… | |
… | |
21 | #include <stdlib.h> |
21 | #include <stdlib.h> |
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 | |
|
|
27 | int psiconv_verbosity = PSICONV_VERB_WARN; |
26 | |
28 | |
27 | psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, |
29 | psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, |
28 | psiconv_header_section *result) |
30 | psiconv_header_section *result) |
29 | { |
31 | { |
30 | psiconv_header_section header; |
32 | psiconv_header_section header; |
… | |
… | |
63 | res = psiconv_parse_texted_file(buf,lev+2,leng, |
65 | res = psiconv_parse_texted_file(buf,lev+2,leng, |
64 | (psiconv_texted_f *)(&((*result)->file))); |
66 | (psiconv_texted_f *)(&((*result)->file))); |
65 | else if ((*result)->type == psiconv_mbm_file) |
67 | else if ((*result)->type == psiconv_mbm_file) |
66 | res = psiconv_parse_mbm_file(buf,lev+2,leng, |
68 | res = psiconv_parse_mbm_file(buf,lev+2,leng, |
67 | (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))); |
68 | else { |
76 | else { |
69 | psiconv_warn(lev+1,off,"Can't parse this file yet!"); |
77 | psiconv_warn(lev+1,off,"Can't parse this file yet!"); |
70 | (*result)->file = NULL; |
78 | (*result)->file = NULL; |
71 | } |
79 | } |
72 | res = -1; |
80 | res = -1; |
73 | |
81 | |
74 | return res; |
82 | return res; |
75 | } |
83 | } |
76 | |
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 | |
77 | 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, |
78 | psiconv_mbm_f *result) |
115 | psiconv_mbm_f *result) |
79 | { |
116 | { |
80 | int res=0; |
117 | int res=0; |
81 | int i; |
118 | int i; |
82 | psiconv_mbm_jumptable_section table; |
119 | psiconv_jumptable_section table; |
83 | psiconv_paint_data_section paint; |
120 | psiconv_paint_data_section paint; |
84 | psiconv_u32 *entry; |
121 | psiconv_u32 *entry; |
85 | psiconv_u32 sto; |
122 | psiconv_u32 sto; |
86 | |
123 | |
87 | psiconv_progress(lev+1,off,"Going to read a mbm file"); |
124 | psiconv_progress(lev+1,off,"Going to read a mbm file"); |
… | |
… | |
90 | psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); |
127 | psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); |
91 | sto = psiconv_read_u32(buf,lev+2,off); |
128 | sto = psiconv_read_u32(buf,lev+2,off); |
92 | psiconv_debug(lev+2,off,"Offset: %08x",sto); |
129 | psiconv_debug(lev+2,off,"Offset: %08x",sto); |
93 | |
130 | |
94 | psiconv_progress(lev+2,off,"Going to read the MBM jumptable"); |
131 | psiconv_progress(lev+2,off,"Going to read the MBM jumptable"); |
95 | res |= psiconv_parse_mbm_jumptable_section(buf,lev+2,sto, NULL,&table); |
132 | res |= psiconv_parse_jumptable_section(buf,lev+2,sto, NULL,&table); |
96 | |
133 | |
97 | psiconv_progress(lev+2,off,"Going to read the picture sections"); |
134 | psiconv_progress(lev+2,off,"Going to read the picture sections"); |
98 | (*result)->sections = psiconv_list_new(sizeof(*paint)); |
135 | (*result)->sections = psiconv_list_new(sizeof(*paint)); |
99 | for (i = 0; i < psiconv_list_length(table); i ++) { |
136 | for (i = 0; i < psiconv_list_length(table); i ++) { |
100 | entry = psiconv_list_get(table,i); |
137 | entry = psiconv_list_get(table,i); |
101 | psiconv_progress(lev+3,off,"Going to read picture section %i",i); |
138 | psiconv_progress(lev+3,off,"Going to read picture section %i",i); |
102 | psiconv_parse_paint_data_section(buf,lev+3,*entry,NULL,&paint); |
139 | psiconv_parse_paint_data_section(buf,lev+3,*entry,NULL,0,&paint); |
103 | psiconv_list_add((*result)->sections,paint); |
140 | psiconv_list_add((*result)->sections,paint); |
104 | } |
141 | } |
105 | |
142 | |
106 | psiconv_free_mbm_jumptable_section(table); |
143 | psiconv_free_jumptable_section(table); |
107 | psiconv_progress(lev+1,off,"End of mbm file"); |
144 | psiconv_progress(lev+1,off,"End of mbm file"); |
108 | return res; |
145 | return res; |
109 | } |
146 | } |
|
|
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 | |
110 | |
236 | |
111 | int psiconv_parse_texted_file(const psiconv_buffer buf,int lev, |
237 | int psiconv_parse_texted_file(const psiconv_buffer buf,int lev, |
112 | psiconv_u32 off, |
238 | psiconv_u32 off, |
113 | psiconv_texted_f *result) |
239 | psiconv_texted_f *result) |
114 | { |
240 | { |
… | |
… | |
126 | int i; |
252 | int i; |
127 | |
253 | |
128 | psiconv_progress(lev+1,off,"Going to read a texted file"); |
254 | psiconv_progress(lev+1,off,"Going to read a texted file"); |
129 | *result = malloc(sizeof(**result)); |
255 | *result = malloc(sizeof(**result)); |
130 | |
256 | |
131 | psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); |
257 | psiconv_progress(lev+2,off, |
|
|
258 | "Going to read the offset of the section table section"); |
132 | sto = psiconv_read_u32(buf,lev+2,off); |
259 | sto = psiconv_read_u32(buf,lev+2,off); |
133 | psiconv_debug(lev+2,off,"Offset: %08x",sto); |
260 | psiconv_debug(lev+2,off,"Offset: %08x",sto); |
134 | |
261 | |
135 | psiconv_progress(lev+2,sto, "Going to read the section table section"); |
262 | psiconv_progress(lev+2,sto, "Going to read the section table section"); |
136 | res |= psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table); |
263 | res |= psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table); |
… | |
… | |
176 | "Application ID section contains unexpected data"); |
303 | "Application ID section contains unexpected data"); |
177 | psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
304 | psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
178 | PSICONV_ID_TEXTED,appl_id->id); |
305 | PSICONV_ID_TEXTED,appl_id->id); |
179 | temp_str = psiconv_make_printable(appl_id->name); |
306 | temp_str = psiconv_make_printable(appl_id->name); |
180 | psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
307 | psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
181 | PSICONV_ID_TEXTED,temp_str); |
308 | "TextEd.app",temp_str); |
182 | free(temp_str); |
309 | free(temp_str); |
183 | } |
310 | } |
184 | |
311 | |
185 | psiconv_progress(lev+2,sto, |
312 | psiconv_progress(lev+2,sto, |
186 | "Looking for the Page layout section"); |
313 | "Looking for the Page layout section"); |
… | |
… | |
241 | int i; |
368 | int i; |
242 | |
369 | |
243 | psiconv_progress(lev+1,off,"Going to read a word file"); |
370 | psiconv_progress(lev+1,off,"Going to read a word file"); |
244 | *result = malloc(sizeof(**result)); |
371 | *result = malloc(sizeof(**result)); |
245 | |
372 | |
246 | psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); |
373 | psiconv_progress(lev+2,off, |
|
|
374 | "Going to read the offset of the section table section"); |
247 | sto = psiconv_read_u32(buf,lev+2,off); |
375 | sto = psiconv_read_u32(buf,lev+2,off); |
248 | psiconv_debug(lev+2,off,"Offset: %08x",sto); |
376 | psiconv_debug(lev+2,off,"Offset: %08x",sto); |
249 | |
377 | |
250 | psiconv_progress(lev+2,sto, |
378 | psiconv_progress(lev+2,sto, |
251 | "Going to read the section table section"); |
379 | "Going to read the section table section"); |
… | |
… | |
322 | "Application ID section contains unexpected data"); |
450 | "Application ID section contains unexpected data"); |
323 | psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
451 | psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", |
324 | PSICONV_ID_WORD,appl_id->id); |
452 | PSICONV_ID_WORD,appl_id->id); |
325 | temp_str = psiconv_make_printable(appl_id->name); |
453 | temp_str = psiconv_make_printable(appl_id->name); |
326 | psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
454 | psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
327 | PSICONV_ID_WORD,temp_str); |
455 | "Word.app",temp_str); |
328 | free(temp_str); |
456 | free(temp_str); |
329 | } |
457 | } |
330 | |
458 | |
331 | psiconv_progress(lev+2,sto, |
459 | psiconv_progress(lev+2,sto, |
332 | "Looking for the Page layout section"); |
460 | "Looking for the Page layout section"); |