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