1 | /* |
1 | /* |
2 | parse_common.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_common.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | #include "compat.h" |
21 | #include "compat.h" |
22 | #include <stdlib.h> |
22 | #include <stdlib.h> |
23 | #include <string.h> |
23 | #include <string.h> |
24 | |
24 | |
25 | #include "data.h" |
|
|
26 | #include "parse_routines.h" |
25 | #include "parse_routines.h" |
|
|
26 | #include "error.h" |
|
|
27 | |
|
|
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
|
|
31 | |
27 | |
32 | |
28 | static int psiconv_parse_layout_section(const psiconv_buffer buf, |
33 | static int psiconv_parse_layout_section(const psiconv_buffer buf, |
29 | int lev,psiconv_u32 off, |
34 | int lev,psiconv_u32 off, |
30 | int *length, |
35 | int *length, |
31 | psiconv_text_and_layout result, |
36 | psiconv_text_and_layout result, |
… | |
… | |
39 | int res=0; |
44 | int res=0; |
40 | int len=0; |
45 | int len=0; |
41 | psiconv_u32 temp; |
46 | psiconv_u32 temp; |
42 | |
47 | |
43 | psiconv_progress(lev+1,off+len,"Going to read the header section"); |
48 | psiconv_progress(lev+1,off+len,"Going to read the header section"); |
44 | (*result) = malloc(sizeof(**result)); |
49 | if (!((*result) = malloc(sizeof(**result)))) |
|
|
50 | goto ERROR1; |
45 | |
51 | |
46 | psiconv_progress(lev+2,off+len,"Going to read UID1 to UID3"); |
52 | psiconv_progress(lev+2,off+len,"Going to read UID1 to UID3"); |
47 | (*result)->uid1 = psiconv_read_u32(buf,lev+2,off+len); |
53 | (*result)->uid1 = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
54 | if (res) |
|
|
55 | goto ERROR2; |
48 | psiconv_debug(lev+2,off+len,"UID1: %08x",(*result)->uid1); |
56 | psiconv_debug(lev+2,off+len,"UID1: %08x",(*result)->uid1); |
49 | if ((*result)->uid1 == PSICONV_ID_CLIPART) { |
57 | if ((*result)->uid1 == PSICONV_ID_CLIPART) { |
50 | /* That's all folks... */ |
58 | /* That's all folks... */ |
51 | (*result)->file = psiconv_clipart_file; |
59 | (*result)->file = psiconv_clipart_file; |
52 | (*result)->uid2 = 0; |
60 | (*result)->uid2 = 0; |
… | |
… | |
57 | goto DONE; |
65 | goto DONE; |
58 | } |
66 | } |
59 | if ((*result)->uid1 != PSICONV_ID_PSION5) { |
67 | if ((*result)->uid1 != PSICONV_ID_PSION5) { |
60 | psiconv_warn(lev+2,off+len,"UID1 has unknown value. This is probably " |
68 | psiconv_warn(lev+2,off+len,"UID1 has unknown value. This is probably " |
61 | "not a (parsable) Psion 5 file"); |
69 | "not a (parsable) Psion 5 file"); |
62 | res = -1; |
70 | res = -PSICONV_E_PARSE; |
|
|
71 | goto ERROR2; |
63 | } |
72 | } |
64 | len += 4; |
73 | len += 4; |
65 | (*result)->uid2 = psiconv_read_u32(buf,lev+2,off+len); |
74 | (*result)->uid2 = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
75 | if (res) |
|
|
76 | goto ERROR2; |
66 | psiconv_debug(lev+2,off+len,"UID2: %08x",(*result)->uid2); |
77 | psiconv_debug(lev+2,off+len,"UID2: %08x",(*result)->uid2); |
67 | len += 4; |
78 | len += 4; |
68 | (*result)->uid3 = psiconv_read_u32(buf,lev+2,off+len); |
79 | (*result)->uid3 = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
80 | if (res) |
|
|
81 | goto ERROR2; |
69 | psiconv_debug(lev+2,off+len,"UID3: %08x",(*result)->uid3); |
82 | psiconv_debug(lev+2,off+len,"UID3: %08x",(*result)->uid3); |
70 | len += 4; |
83 | len += 4; |
71 | |
84 | |
72 | (*result)->file = psiconv_unknown_file; |
85 | (*result)->file = psiconv_unknown_file; |
73 | if ((*result)->uid1 == PSICONV_ID_PSION5) { |
86 | if ((*result)->uid1 == PSICONV_ID_PSION5) { |
… | |
… | |
79 | (*result)->file = psiconv_texted_file; |
92 | (*result)->file = psiconv_texted_file; |
80 | psiconv_debug(lev+2,off+len,"File is a TextEd file"); |
93 | psiconv_debug(lev+2,off+len,"File is a TextEd file"); |
81 | } else if ((*result)->uid3 == PSICONV_ID_SKETCH) { |
94 | } else if ((*result)->uid3 == PSICONV_ID_SKETCH) { |
82 | (*result)->file = psiconv_sketch_file; |
95 | (*result)->file = psiconv_sketch_file; |
83 | psiconv_debug(lev+2,off+len,"File is a Sketch file"); |
96 | psiconv_debug(lev+2,off+len,"File is a Sketch file"); |
|
|
97 | } else if ((*result)->uid3 == PSICONV_ID_SHEET) { |
|
|
98 | (*result)->file = psiconv_sheet_file; |
|
|
99 | psiconv_debug(lev+2,off+len,"File is a Sheet file"); |
84 | } |
100 | } |
85 | } else if ((*result)->uid2 == PSICONV_ID_MBM_FILE) { |
101 | } else if ((*result)->uid2 == PSICONV_ID_MBM_FILE) { |
86 | (*result)->file = psiconv_mbm_file; |
102 | (*result)->file = psiconv_mbm_file; |
87 | if ((*result)->uid3 != 0x00) |
103 | if ((*result)->uid3 != 0x00) |
88 | psiconv_warn(lev+2,off+len,"UID3 set in MBM file?!?"); |
104 | psiconv_warn(lev+2,off+len,"UID3 set in MBM file?!?"); |
89 | psiconv_debug(lev+2,off+len,"File is a MBM file"); |
105 | psiconv_debug(lev+2,off+len,"File is a MBM file"); |
… | |
… | |
93 | psiconv_warn(lev+2,off+len,"Unknown file type"); |
109 | psiconv_warn(lev+2,off+len,"Unknown file type"); |
94 | (*result)->file = psiconv_unknown_file; |
110 | (*result)->file = psiconv_unknown_file; |
95 | } |
111 | } |
96 | |
112 | |
97 | psiconv_progress(lev+2,off+len,"Checking UID4"); |
113 | psiconv_progress(lev+2,off+len,"Checking UID4"); |
98 | temp = psiconv_read_u32(buf,lev+2,off+len); |
114 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
115 | if (res) |
|
|
116 | goto ERROR2; |
99 | if (temp == psiconv_checkuid((*result)->uid1,(*result)->uid2, |
117 | if (temp == psiconv_checkuid((*result)->uid1,(*result)->uid2, |
100 | (*result)->uid3)) |
118 | (*result)->uid3)) |
101 | psiconv_debug(lev+2,off+len,"Checksum %08x is correct",temp); |
119 | psiconv_debug(lev+2,off+len,"Checksum %08x is correct",temp); |
102 | else { |
120 | else { |
103 | psiconv_warn(lev+2,off+len,"Checksum failed, file corrupted!"); |
121 | psiconv_warn(lev+2,off+len,"Checksum failed, file corrupted!"); |
104 | psiconv_debug(lev+2,off+len,"Expected checksum %08x, found %08x", |
122 | psiconv_debug(lev+2,off+len,"Expected checksum %08x, found %08x", |
105 | psiconv_checkuid((*result)->uid1,(*result)->uid2, |
123 | psiconv_checkuid((*result)->uid1,(*result)->uid2, |
106 | (*result)->uid3),temp); |
124 | (*result)->uid3),temp); |
107 | res = -1; |
125 | res = -PSICONV_E_PARSE; |
|
|
126 | goto ERROR2; |
108 | } |
127 | } |
109 | len += 4; |
128 | len += 4; |
110 | |
129 | |
111 | DONE: |
130 | DONE: |
112 | if (length) |
131 | if (length) |
… | |
… | |
114 | |
133 | |
115 | psiconv_progress(lev+1,off+len-1, |
134 | psiconv_progress(lev+1,off+len-1, |
116 | "End of Header Section (total length: %08x)",len); |
135 | "End of Header Section (total length: %08x)",len); |
117 | |
136 | |
118 | return res; |
137 | return res; |
|
|
138 | |
|
|
139 | ERROR2: |
|
|
140 | free(*result); |
|
|
141 | ERROR1: |
|
|
142 | psiconv_warn(lev+1,off,"Reading of Header Section failed"); |
|
|
143 | if (length) |
|
|
144 | *length = 0; |
|
|
145 | if (res == 0) |
|
|
146 | return -PSICONV_E_NOMEM; |
|
|
147 | else |
|
|
148 | return res; |
119 | } |
149 | } |
120 | |
150 | |
121 | int psiconv_parse_section_table_section(const psiconv_buffer buf, int lev, |
151 | int psiconv_parse_section_table_section(const psiconv_buffer buf, int lev, |
122 | psiconv_u32 off, int *length, |
152 | psiconv_u32 off, int *length, |
123 | psiconv_section_table_section *result) |
153 | psiconv_section_table_section *result) |
… | |
… | |
128 | |
158 | |
129 | int i; |
159 | int i; |
130 | psiconv_u8 nr; |
160 | psiconv_u8 nr; |
131 | |
161 | |
132 | psiconv_progress(lev+1,off+len,"Going to read the section table section"); |
162 | psiconv_progress(lev+1,off+len,"Going to read the section table section"); |
133 | *result = psiconv_list_new(sizeof(*entry)); |
163 | if (!(*result = psiconv_list_new(sizeof(*entry)))) |
|
|
164 | goto ERROR1; |
134 | |
165 | |
135 | psiconv_progress(lev+2,off+len,"Going to read the section table length"); |
166 | psiconv_progress(lev+2,off+len,"Going to read the section table length"); |
136 | nr = psiconv_read_u8(buf,lev+2,off+len); |
167 | nr = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
168 | if (res) |
|
|
169 | goto ERROR2; |
137 | psiconv_debug(lev+2,off+len,"Length: %08x",nr); |
170 | psiconv_debug(lev+2,off+len,"Length: %08x",nr); |
138 | if (nr & 0x01) { |
171 | if (nr & 0x01) { |
139 | psiconv_warn(lev+2,off+len, |
172 | psiconv_warn(lev+2,off+len, |
140 | "Section table length odd - ignoring last entry"); |
173 | "Section table length odd - ignoring last entry"); |
141 | res = -1; |
|
|
142 | } |
174 | } |
143 | len ++; |
175 | len ++; |
144 | |
176 | |
145 | psiconv_progress(lev+2,off+len,"Going to read the section table entries"); |
177 | psiconv_progress(lev+2,off+len,"Going to read the section table entries"); |
146 | entry = malloc(sizeof(*entry)); |
178 | entry = malloc(sizeof(*entry)); |
147 | for (i = 0; i < nr / 2; i++) { |
179 | for (i = 0; i < nr / 2; i++) { |
148 | entry->id = psiconv_read_u32(buf,lev+2,off + len); |
180 | entry->id = psiconv_read_u32(buf,lev+2,off + len,&res); |
|
|
181 | if (res) |
|
|
182 | goto ERROR3; |
149 | psiconv_debug(lev+2,off + len,"Entry %d: ID = %08x",i,entry->id); |
183 | psiconv_debug(lev+2,off + len,"Entry %d: ID = %08x",i,entry->id); |
150 | len += 0x04; |
184 | len += 0x04; |
151 | entry->offset = psiconv_read_u32(buf,lev+2,off + len); |
185 | entry->offset = psiconv_read_u32(buf,lev+2,off + len,&res); |
|
|
186 | if (res) |
|
|
187 | goto ERROR3; |
152 | psiconv_debug(lev+2,off +len,"Entry %d: Offset = %08x",i,entry->offset); |
188 | psiconv_debug(lev+2,off +len,"Entry %d: Offset = %08x",i,entry->offset); |
153 | len += 0x04; |
189 | len += 0x04; |
154 | psiconv_list_add(*result,entry); |
190 | if ((res=psiconv_list_add(*result,entry))) |
|
|
191 | goto ERROR3; |
155 | } |
192 | } |
156 | |
193 | |
157 | free(entry); |
194 | free(entry); |
158 | |
195 | |
159 | if (length) |
196 | if (length) |
160 | *length = len; |
197 | *length = len; |
161 | |
198 | |
162 | psiconv_progress(lev+1,off+len-1,"End of section table section " |
199 | psiconv_progress(lev+1,off+len-1,"End of section table section " |
163 | "(total length: %08x)", len); |
200 | "(total length: %08x)", len); |
164 | |
201 | |
|
|
202 | return 0; |
|
|
203 | ERROR3: |
|
|
204 | free(entry); |
|
|
205 | ERROR2: |
|
|
206 | psiconv_list_free(*result); |
|
|
207 | ERROR1: |
|
|
208 | psiconv_warn(lev+1,off,"Reading of Section Table Section failed"); |
|
|
209 | if (length) |
|
|
210 | *length = 0; |
|
|
211 | if (res == 0) |
|
|
212 | return -PSICONV_E_NOMEM; |
|
|
213 | else |
165 | return res; |
214 | return res; |
166 | } |
215 | } |
167 | |
216 | |
168 | int psiconv_parse_application_id_section(const psiconv_buffer buf, int lev, |
217 | int psiconv_parse_application_id_section(const psiconv_buffer buf, int lev, |
169 | psiconv_u32 off, int *length, |
218 | psiconv_u32 off, int *length, |
170 | psiconv_application_id_section *result) |
219 | psiconv_application_id_section *result) |
… | |
… | |
172 | int res=0; |
221 | int res=0; |
173 | int len=0; |
222 | int len=0; |
174 | int leng; |
223 | int leng; |
175 | |
224 | |
176 | psiconv_progress(lev+1,off,"Going to read the application id section"); |
225 | psiconv_progress(lev+1,off,"Going to read the application id section"); |
177 | (*result) = malloc(sizeof(**result)); |
226 | if (!(*result = malloc(sizeof(**result)))) |
|
|
227 | goto ERROR1; |
178 | |
228 | |
179 | psiconv_progress(lev+2,off+len,"Going to read the type identifier"); |
229 | psiconv_progress(lev+2,off+len,"Going to read the type identifier"); |
180 | (*result)->id = psiconv_read_u32(buf,lev+2,off+len); |
230 | (*result)->id = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
231 | if (res) |
|
|
232 | goto ERROR2; |
181 | psiconv_debug(lev+2,off+len,"Identifier: %08x",(*result)->id); |
233 | psiconv_debug(lev+2,off+len,"Identifier: %08x",(*result)->id); |
182 | len += 4; |
234 | len += 4; |
183 | |
235 | |
184 | psiconv_progress(lev+2,off+len,"Going to read the application id string"); |
236 | psiconv_progress(lev+2,off+len,"Going to read the application id string"); |
185 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng); |
237 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
238 | if (res) |
|
|
239 | goto ERROR2; |
186 | len += leng; |
240 | len += leng; |
187 | |
241 | |
188 | if (length) |
242 | if (length) |
189 | *length = len; |
243 | *length = len; |
190 | |
244 | |
191 | psiconv_progress(lev+1,off+len-1,"End of application id section " |
245 | psiconv_progress(lev+1,off+len-1,"End of application id section " |
192 | "(total length: %08x", len); |
246 | "(total length: %08x", len); |
193 | |
247 | |
194 | return res; |
248 | return res; |
|
|
249 | ERROR2: |
|
|
250 | free(*result); |
|
|
251 | ERROR1: |
|
|
252 | psiconv_warn(lev+1,off,"Reading of Application ID Section failed"); |
|
|
253 | if (length) |
|
|
254 | *length = 0; |
|
|
255 | if (res == 0) |
|
|
256 | return -PSICONV_E_NOMEM; |
|
|
257 | else |
|
|
258 | return res; |
195 | } |
259 | } |
196 | |
260 | |
197 | int psiconv_parse_text_section(const psiconv_buffer buf,int lev,psiconv_u32 off, |
261 | int psiconv_parse_text_section(const psiconv_buffer buf,int lev,psiconv_u32 off, |
198 | int *length,psiconv_text_and_layout *result) |
262 | int *length,psiconv_text_and_layout *result) |
199 | { |
263 | { |
… | |
… | |
203 | |
267 | |
204 | psiconv_u32 text_len; |
268 | psiconv_u32 text_len; |
205 | psiconv_paragraph para; |
269 | psiconv_paragraph para; |
206 | |
270 | |
207 | int nr; |
271 | int nr; |
208 | int i,j,start,leng; |
272 | int i,j,start,leng,temp; |
209 | char *str_copy; |
273 | char *str_copy; |
210 | |
274 | |
211 | psiconv_progress(lev+1,off,"Going to parse the text section"); |
275 | psiconv_progress(lev+1,off,"Going to parse the text section"); |
212 | psiconv_progress(lev+2,off,"Reading the text length"); |
276 | psiconv_progress(lev+2,off,"Reading the text length"); |
|
|
277 | |
|
|
278 | if(!(*result = psiconv_list_new(sizeof(*para)))) |
|
|
279 | goto ERROR1; |
|
|
280 | if (!(para = malloc(sizeof(*para)))) |
|
|
281 | goto ERROR2; |
|
|
282 | |
213 | text_len = psiconv_read_X(buf,lev+2,off,&leng); |
283 | text_len = psiconv_read_X(buf,lev+2,off,&leng,&res); |
|
|
284 | if (res) |
|
|
285 | goto ERROR3; |
214 | psiconv_debug(lev+2,off,"Length: %08x",text_len); |
286 | psiconv_debug(lev+2,off,"Length: %08x",text_len); |
215 | len += leng; |
287 | len += leng; |
216 | |
|
|
217 | *result = psiconv_list_new(sizeof(*para)); |
|
|
218 | para = malloc(sizeof(*para)); |
|
|
219 | |
288 | |
220 | psiconv_progress(lev+2,off+len,"Going to read all paragraph text"); |
289 | psiconv_progress(lev+2,off+len,"Going to read all paragraph text"); |
221 | nr = 0; |
290 | nr = 0; |
222 | start = 0; |
291 | start = 0; |
223 | for (i = 0; i < text_len; i++) |
292 | for (i = 0; i < text_len; i++) { |
224 | if (psiconv_read_u8(buf,lev+2,off+len+i) == 0x06) { |
293 | temp = psiconv_read_u8(buf,lev+2,off+len+i,&res); |
|
|
294 | if (res) |
|
|
295 | goto ERROR3; |
|
|
296 | if (temp == 0x06) { |
225 | para->text = malloc(i - start + 1); |
297 | if (!(para->text = malloc(i - start + 1))) |
|
|
298 | goto ERROR3; |
226 | for (j = 0; j < i - start; j++) |
299 | for (j = 0; j < i - start; j++) { |
227 | para->text[j] = psiconv_read_u8(buf,lev+1,off + len + start + j); |
300 | temp = psiconv_read_u8(buf,lev+1,off + len + start + j,&res); |
|
|
301 | if (res) |
|
|
302 | goto ERROR4; |
|
|
303 | para->text[j] = temp; |
|
|
304 | } |
228 | para->text[j] = 0; |
305 | para->text[j] = 0; |
229 | |
306 | |
230 | psiconv_list_add(*result,para); |
307 | if ((res = psiconv_list_add(*result,para))) |
|
|
308 | goto ERROR4; |
231 | |
309 | |
232 | str_copy = psiconv_make_printable(para->text); |
310 | if (!(str_copy = psiconv_make_printable(para->text))) |
|
|
311 | goto ERROR3; |
233 | psiconv_debug(lev+2,off+i+len,"Line %d: %d characters",nr, |
312 | psiconv_debug(lev+2,off+i+len,"Line %d: %d characters",nr, |
234 | strlen(str_copy) +1); |
313 | strlen(str_copy) +1); |
235 | psiconv_debug(lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); |
314 | psiconv_debug(lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); |
236 | free(str_copy); |
315 | free(str_copy); |
237 | |
316 | |
238 | start = i + 1; |
317 | start = i + 1; |
239 | nr ++; |
318 | nr ++; |
240 | } |
319 | } |
|
|
320 | } |
241 | |
321 | |
242 | if (start != text_len) { |
322 | if (start != text_len) { |
243 | res = -1; |
|
|
244 | psiconv_warn(lev+2,off+start+len, |
323 | psiconv_warn(lev+2,off+start+len, |
245 | "Last line does not end on EOL (%d characters left)", len - start); |
324 | "Last line does not end on EOL (%d characters left)", len - start); |
246 | para->text = malloc(text_len - start + 1); |
325 | if (!(para->text = malloc(text_len - start + 1))) |
|
|
326 | goto ERROR3; |
247 | for (j = 0; j < text_len - start; j++) |
327 | for (j = 0; j < text_len - start; j++) { |
248 | para->text[j] = psiconv_read_u8(buf,lev+2,off + start + j + len); |
328 | temp = psiconv_read_u8(buf,lev+2,off + start + j + len, &res); |
|
|
329 | if (res) |
|
|
330 | goto ERROR4; |
|
|
331 | para->text[j] = temp; |
|
|
332 | } |
249 | para->text[text_len - start] = 0; |
333 | para->text[text_len - start] = 0; |
250 | psiconv_list_add(*result,para); |
334 | if ((res = psiconv_list_add(*result,para))) |
|
|
335 | goto ERROR4; |
251 | str_copy = psiconv_make_printable(para->text); |
336 | if (!(str_copy = psiconv_make_printable(para->text))) |
|
|
337 | goto ERROR3; |
252 | psiconv_debug(lev+2,off+start+len,"Last line: %d characters",nr, |
338 | psiconv_debug(lev+2,off+start+len,"Last line: %d characters",nr, |
253 | strlen(str_copy)+1); |
339 | strlen(str_copy)+1); |
254 | psiconv_debug(lev+2,off+start+len,"Last line: `%s'",str_copy); |
340 | psiconv_debug(lev+2,off+start+len,"Last line: `%s'",str_copy); |
255 | free(str_copy); |
341 | free(str_copy); |
256 | } |
342 | } |
257 | |
343 | |
258 | free(para); |
344 | free(para); |
259 | |
345 | |
260 | /* Initialize the remaining parts of each paragraph */ |
346 | /* Initialize the remaining parts of each paragraph */ |
261 | for (i = 0; i < psiconv_list_length(*result); i ++) { |
347 | for (i = 0; i < psiconv_list_length(*result); i ++) { |
262 | para = psiconv_list_get(*result,i); |
348 | if (!(para = psiconv_list_get(*result,i))) { |
263 | para->in_lines = psiconv_list_new(sizeof(struct psiconv_in_line_layout)); |
349 | psiconv_warn(lev+2,off+len,"Massive memory corruption"); |
264 | para->replacements = psiconv_list_new(sizeof(struct psiconv_replacement)); |
350 | goto ERROR2_0; |
|
|
351 | } |
|
|
352 | if (!(para->in_lines = psiconv_list_new(sizeof( |
|
|
353 | struct psiconv_in_line_layout_s)))) |
|
|
354 | goto ERROR2_0; |
|
|
355 | if (!(para->replacements = psiconv_list_new(sizeof( |
|
|
356 | struct psiconv_replacement_s)))) |
|
|
357 | goto ERROR2_1; |
|
|
358 | if (!(para->base_character = psiconv_basic_character_layout())) |
|
|
359 | goto ERROR2_2; |
|
|
360 | if (!(para->base_paragraph = psiconv_basic_paragraph_layout())) |
|
|
361 | goto ERROR2_3; |
265 | para->base_style = 0; |
362 | para->base_style = 0; |
266 | para->base_character = psiconv_basic_character_layout(); |
|
|
267 | para->base_paragraph = psiconv_basic_paragraph_layout(); |
|
|
268 | } |
363 | } |
269 | |
364 | |
270 | |
365 | |
271 | len += text_len; |
366 | len += text_len; |
272 | |
367 | |
… | |
… | |
275 | |
370 | |
276 | psiconv_progress(lev+1,off+len-1,"End of text section (total length: %08x", |
371 | psiconv_progress(lev+1,off+len-1,"End of text section (total length: %08x", |
277 | len); |
372 | len); |
278 | |
373 | |
279 | return res; |
374 | return res; |
|
|
375 | |
|
|
376 | ERROR2_3: |
|
|
377 | psiconv_free_character_layout(para->base_character); |
|
|
378 | ERROR2_2: |
|
|
379 | psiconv_list_free(para->replacements); |
|
|
380 | ERROR2_1: |
|
|
381 | psiconv_list_free(para->in_lines); |
|
|
382 | ERROR2_0: |
|
|
383 | for (j = 0; j < i; j++) { |
|
|
384 | if (!(para = psiconv_list_get(*result,j))) { |
|
|
385 | psiconv_warn(lev+1,off,"Massive memory corruption..."); |
|
|
386 | break; |
|
|
387 | } |
|
|
388 | psiconv_list_free(para->in_lines); |
|
|
389 | psiconv_list_free(para->replacements); |
|
|
390 | psiconv_free_character_layout(para->base_character); |
|
|
391 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
392 | } |
|
|
393 | goto ERROR2; |
|
|
394 | |
|
|
395 | ERROR4: |
|
|
396 | free(para->text); |
|
|
397 | ERROR3: |
|
|
398 | free(para); |
|
|
399 | ERROR2: |
|
|
400 | for (i = 0; i < psiconv_list_length(*result);i++) { |
|
|
401 | if (!(para = psiconv_list_get(*result,i))) { |
|
|
402 | psiconv_warn(lev+1,off,"Massive memory corruption..."); |
|
|
403 | break; |
|
|
404 | } |
|
|
405 | free(para->text); |
|
|
406 | } |
|
|
407 | psiconv_list_free(*result); |
|
|
408 | ERROR1: |
|
|
409 | psiconv_warn(lev+1,off,"Reading of Text Section failed"); |
|
|
410 | if (length) |
|
|
411 | *length = 0; |
|
|
412 | if (!res) |
|
|
413 | return -PSICONV_E_NOMEM; |
|
|
414 | else |
|
|
415 | return res; |
280 | } |
416 | } |
281 | |
417 | |
282 | /* First do a parse_text_section, or you will get into trouble here */ |
418 | /* First do a parse_text_section, or you will get into trouble here */ |
283 | int psiconv_parse_layout_section(const psiconv_buffer buf, |
419 | int psiconv_parse_layout_section(const psiconv_buffer buf, |
284 | int lev,psiconv_u32 off, |
420 | int lev,psiconv_u32 off, |
… | |
… | |
290 | int res = 0; |
426 | int res = 0; |
291 | int len = 0; |
427 | int len = 0; |
292 | psiconv_u32 temp; |
428 | psiconv_u32 temp; |
293 | int parse_styles,nr,i,j,total,leng,line_length; |
429 | int parse_styles,nr,i,j,total,leng,line_length; |
294 | |
430 | |
295 | typedef struct anon_style |
431 | typedef struct anon_style_s |
296 | { |
432 | { |
297 | int nr; |
433 | int nr; |
298 | psiconv_s16 base_style; |
434 | psiconv_s16 base_style; |
299 | psiconv_character_layout character; |
435 | psiconv_character_layout character; |
300 | psiconv_paragraph_layout paragraph; |
436 | psiconv_paragraph_layout paragraph; |
301 | } *anon_style; |
437 | } *anon_style; |
302 | |
438 | |
303 | typedef psiconv_list anon_style_list; /* of struct anon_style */ |
439 | typedef psiconv_list anon_style_list; /* of struct anon_style */ |
304 | |
440 | |
305 | anon_style_list anon_styles; |
441 | anon_style_list anon_styles; |
306 | struct anon_style anon; |
442 | struct anon_style_s anon; |
307 | anon_style anon_ptr=NULL; |
443 | anon_style anon_ptr=NULL; |
308 | |
444 | |
|
|
445 | psiconv_character_layout temp_char; |
|
|
446 | psiconv_paragraph_layout temp_para; |
|
|
447 | psiconv_word_style temp_style; |
309 | psiconv_paragraph para; |
448 | psiconv_paragraph para; |
310 | struct psiconv_in_line_layout in_line; |
449 | struct psiconv_in_line_layout_s in_line; |
311 | |
450 | |
312 | int *inline_count; |
451 | int *inline_count; |
313 | |
452 | |
314 | |
453 | |
315 | psiconv_progress(lev+1,off,"Going to read the layout section"); |
454 | psiconv_progress(lev+1,off,"Going to read the layout section"); |
316 | |
455 | |
317 | psiconv_progress(lev+2,off,"Going to read the section type"); |
456 | psiconv_progress(lev+2,off,"Going to read the section type"); |
318 | temp = psiconv_read_u16(buf,lev+2,off+len); |
457 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
|
|
458 | if (res) |
|
|
459 | goto ERROR1; |
319 | psiconv_debug(lev+2,off+len,"Type: %02x",temp); |
460 | psiconv_debug(lev+2,off+len,"Type: %02x",temp); |
320 | parse_styles = with_styles; |
461 | parse_styles = with_styles; |
321 | if ((temp == 0x0001) && !with_styles) { |
462 | if ((temp == 0x0001) && !with_styles) { |
322 | psiconv_warn(lev+2,off+len,"Styleless layout section expected, " |
463 | psiconv_warn(lev+2,off+len,"Styleless layout section expected, " |
323 | "but styled section found!"); |
464 | "but styled section found!"); |
324 | parse_styles = 1; |
465 | parse_styles = 1; |
325 | res = -1; |
|
|
326 | } else if ((temp == 0x0000) && (with_styles)) { |
466 | } else if ((temp == 0x0000) && (with_styles)) { |
327 | psiconv_warn(lev+2,off+len,"Styled layout section expected, " |
467 | psiconv_warn(lev+2,off+len,"Styled layout section expected, " |
328 | "but styleless section found!"); |
468 | "but styleless section found!"); |
329 | parse_styles = 0; |
469 | parse_styles = 0; |
330 | res = -1; |
|
|
331 | } else if ((temp != 0x0000) && (temp != 0x0001)) { |
470 | } else if ((temp != 0x0000) && (temp != 0x0001)) { |
332 | psiconv_warn(lev+2,off+len, |
471 | psiconv_warn(lev+2,off+len, |
333 | "Layout section type indicator has unknown value!"); |
472 | "Layout section type indicator has unknown value!"); |
334 | res = -1; |
|
|
335 | } |
473 | } |
336 | len += 0x02; |
474 | len += 0x02; |
337 | |
475 | |
338 | psiconv_progress(lev+2,off+len,"Going to read paragraph type list"); |
476 | psiconv_progress(lev+2,off+len,"Going to read paragraph type list"); |
339 | anon_styles = psiconv_list_new(sizeof(anon)); |
477 | if (!(anon_styles = psiconv_list_new(sizeof(anon)))) |
|
|
478 | goto ERROR1; |
340 | psiconv_progress(lev+3,off+len,"Going to read paragraph type list length"); |
479 | psiconv_progress(lev+3,off+len,"Going to read paragraph type list length"); |
341 | nr = psiconv_read_u8(buf,lev+3,off+len); |
480 | nr = psiconv_read_u8(buf,lev+3,off+len,&res); |
|
|
481 | if (res) |
|
|
482 | goto ERROR2; |
342 | psiconv_debug(lev+3,off+len,"Length: %02x",nr); |
483 | psiconv_debug(lev+3,off+len,"Length: %02x",nr); |
343 | len ++; |
484 | len ++; |
344 | |
485 | |
345 | psiconv_progress(lev+3,off+len, |
486 | psiconv_progress(lev+3,off+len, |
346 | "Going to read the paragraph type list elements"); |
487 | "Going to read the paragraph type list elements"); |
347 | for (i = 0; i < nr; i ++) { |
488 | for (i = 0; i < nr; i ++) { |
348 | psiconv_progress(lev+3,off+len,"Element %d",i); |
489 | psiconv_progress(lev+3,off+len,"Element %d",i); |
349 | anon.nr = psiconv_read_u32(buf,lev+4,off+len); |
490 | anon.nr = psiconv_read_u32(buf,lev+4,off+len,&res); |
|
|
491 | if (res) |
|
|
492 | goto ERROR3; |
350 | psiconv_debug(lev+4,off+len,"Number: %08x",anon.nr); |
493 | psiconv_debug(lev+4,off+len,"Number: %08x",anon.nr); |
351 | len += 0x04; |
494 | len += 0x04; |
352 | |
495 | |
353 | psiconv_progress(lev+4,off,"Going to determine the base style"); |
496 | psiconv_progress(lev+4,off,"Going to determine the base style"); |
354 | if (parse_styles) { |
497 | if (parse_styles) { |
|
|
498 | temp = psiconv_read_u32(buf,lev+4, off+len,&res); |
|
|
499 | if (res) |
|
|
500 | goto ERROR3; |
355 | anon.base_style = psiconv_read_u8(buf,lev+3, |
501 | anon.base_style = psiconv_read_u8(buf,lev+3, off+len+4+temp,&res); |
356 | off+len+4+psiconv_read_u32(buf,lev+4, |
502 | if (res) |
357 | off+len)); |
503 | goto ERROR3; |
358 | psiconv_debug(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len), |
504 | psiconv_debug(lev+4,off+len+temp, |
359 | "Style indicator: %02x",anon.base_style); |
505 | "Style indicator: %02x",anon.base_style); |
360 | } else |
506 | } else |
361 | anon.base_style = 0; |
507 | anon.base_style = 0; |
|
|
508 | if (!(temp_style = psiconv_get_style(styles,anon.base_style))) { |
|
|
509 | psiconv_warn(lev+4,off,"Unknown Style referenced"); |
|
|
510 | if (!(temp_style = psiconv_get_style(styles,anon.base_style))) { |
|
|
511 | psiconv_warn(lev+4,off,"Base style unknown"); |
|
|
512 | goto ERROR3; |
|
|
513 | } |
|
|
514 | } |
362 | anon.paragraph = psiconv_clone_paragraph_layout(psiconv_get_style |
515 | if (!(anon.paragraph = psiconv_clone_paragraph_layout |
363 | (styles,anon.base_style)->paragraph); |
516 | (temp_style->paragraph))) |
|
|
517 | goto ERROR3; |
364 | anon.character = psiconv_clone_character_layout(psiconv_get_style |
518 | if (!(anon.character = psiconv_clone_character_layout |
365 | (styles,anon.base_style)->character); |
519 | (temp_style->character))) |
|
|
520 | goto ERROR3_1; |
366 | |
521 | |
367 | psiconv_progress(lev+4,off+len,"Going to read the paragraph layout"); |
522 | psiconv_progress(lev+4,off+len,"Going to read the paragraph layout"); |
368 | res |= psiconv_parse_paragraph_layout_list(buf,lev+4,off+len,&leng, |
523 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+4,off+len,&leng, |
369 | anon.paragraph); |
524 | anon.paragraph))) |
|
|
525 | goto ERROR3_2; |
370 | len += leng; |
526 | len += leng; |
371 | if (parse_styles) |
527 | if (parse_styles) |
372 | len ++; |
528 | len ++; |
373 | |
529 | |
374 | psiconv_progress(lev+4,off+len,"Going to read the character layout"); |
530 | psiconv_progress(lev+4,off+len,"Going to read the character layout"); |
375 | res |= psiconv_parse_character_layout_list(buf,lev+4,off+len,&leng, |
531 | if ((res = psiconv_parse_character_layout_list(buf,lev+4,off+len,&leng, |
376 | anon.character); |
532 | anon.character))) |
|
|
533 | goto ERROR3_2; |
377 | len += leng; |
534 | len += leng; |
378 | psiconv_list_add(anon_styles,&anon); |
535 | if ((res = psiconv_list_add(anon_styles,&anon))) |
|
|
536 | goto ERROR3_2; |
379 | } |
537 | } |
380 | |
538 | |
381 | psiconv_progress(lev+2,off+len,"Going to parse the paragraph element list"); |
539 | psiconv_progress(lev+2,off+len,"Going to parse the paragraph element list"); |
382 | psiconv_progress(lev+3,off+len,"Going to read the number of paragraphs"); |
540 | psiconv_progress(lev+3,off+len,"Going to read the number of paragraphs"); |
383 | nr = psiconv_read_u32(buf,lev+3,off+len); |
541 | nr = psiconv_read_u32(buf,lev+3,off+len,&res); |
|
|
542 | if (res) |
|
|
543 | goto ERROR3; |
384 | if (nr != psiconv_list_length(result)) { |
544 | if (nr != psiconv_list_length(result)) { |
385 | psiconv_warn(lev+3,off+len, |
545 | psiconv_warn(lev+3,off+len, |
386 | "Number of text paragraphs and paragraph elements does not match"); |
546 | "Number of text paragraphs and paragraph elements does not match"); |
387 | psiconv_debug(lev+3,off+len, |
547 | psiconv_debug(lev+3,off+len, |
388 | "%d text paragraphs, %d paragraph elements", |
548 | "%d text paragraphs, %d paragraph elements", |
389 | psiconv_list_length(result),nr); |
549 | psiconv_list_length(result),nr); |
390 | } |
550 | } |
391 | psiconv_debug(lev+3,off+len,"Number of paragraphs: %d",nr); |
551 | psiconv_debug(lev+3,off+len,"Number of paragraphs: %d",nr); |
392 | len += 4; |
552 | len += 4; |
393 | inline_count = malloc(nr * sizeof(*inline_count)); |
553 | if (!(inline_count = malloc(nr * sizeof(*inline_count)))) |
|
|
554 | goto ERROR3; |
394 | |
555 | |
395 | psiconv_progress(lev+3,off+len,"Going to read the paragraph elements"); |
556 | psiconv_progress(lev+3,off+len,"Going to read the paragraph elements"); |
396 | for (i = 0; i < nr; i ++) { |
557 | for (i = 0; i < nr; i ++) { |
397 | psiconv_progress(lev+3,off+len,"Element %d",i); |
558 | psiconv_progress(lev+3,off+len,"Element %d",i); |
398 | if (i >= psiconv_list_length(result)) { |
559 | if (i >= psiconv_list_length(result)) { |
399 | psiconv_debug(lev+4,off+len,"Going to allocate a new element"); |
560 | psiconv_debug(lev+4,off+len,"Going to allocate a new element"); |
400 | para = malloc(sizeof(*para)); |
561 | if (!(para = malloc(sizeof(*para)))) |
401 | para->in_lines = psiconv_list_new(sizeof(struct psiconv_in_line_layout)); |
562 | goto ERROR4; |
|
|
563 | if (!(para->in_lines = psiconv_list_new(sizeof( |
|
|
564 | struct psiconv_in_line_layout_s)))) |
|
|
565 | goto ERROR4_1; |
402 | para->base_style = 0; |
566 | para->base_style = 0; |
403 | para->base_character = psiconv_basic_character_layout(); |
567 | if (!(para->base_character = psiconv_basic_character_layout())) |
|
|
568 | goto ERROR4_2; |
404 | para->base_paragraph = psiconv_basic_paragraph_layout(); |
569 | if (!(para->base_paragraph = psiconv_basic_paragraph_layout())) |
|
|
570 | goto ERROR4_3; |
|
|
571 | if ((res = psiconv_list_add(result,para))) |
|
|
572 | goto ERROR4_4; |
405 | free(para); |
573 | free(para); |
406 | } |
574 | } |
407 | para = psiconv_list_get(result,i); |
575 | if (!(para = psiconv_list_get(result,i))) |
|
|
576 | goto ERROR4; |
408 | |
577 | |
409 | psiconv_progress(lev+4,off+len,"Going to read the paragraph length"); |
578 | psiconv_progress(lev+4,off+len,"Going to read the paragraph length"); |
410 | temp = psiconv_read_u32(buf,lev+4,off+len); |
579 | temp = psiconv_read_u32(buf,lev+4,off+len,&res); |
|
|
580 | if (res) |
|
|
581 | goto ERROR4; |
411 | if (temp != strlen(para->text)+1) { |
582 | if (temp != strlen(para->text)+1) { |
412 | res = -1; |
|
|
413 | psiconv_warn(lev+4,off+len, |
583 | psiconv_warn(lev+4,off+len, |
414 | "Disagreement of the length of paragraph in layout section"); |
584 | "Disagreement of the length of paragraph in layout section"); |
415 | psiconv_debug(lev+4,off+len, |
585 | psiconv_debug(lev+4,off+len, |
416 | "Paragraph length: layout section says %d, counted %d", |
586 | "Paragraph length: layout section says %d, counted %d", |
417 | temp,strlen(para->text)+1); |
587 | temp,strlen(para->text)+1); |
418 | } else |
588 | } else |
419 | psiconv_debug(lev+4,off+len,"Paragraph length: %d",temp); |
589 | psiconv_debug(lev+4,off+len,"Paragraph length: %d",temp); |
420 | len += 4; |
590 | len += 4; |
421 | |
591 | |
422 | psiconv_progress(lev+4,off+len,"Going to read the paragraph type"); |
592 | psiconv_progress(lev+4,off+len,"Going to read the paragraph type"); |
423 | temp = psiconv_read_u8(buf,lev+4,off+len); |
593 | temp = psiconv_read_u8(buf,lev+4,off+len,&res); |
|
|
594 | if (res) |
|
|
595 | goto ERROR4; |
424 | if (temp != 0x00) { |
596 | if (temp != 0x00) { |
425 | psiconv_debug(lev+4,off+len,"Type: %02x",temp); |
597 | psiconv_debug(lev+4,off+len,"Type: %02x",temp); |
426 | for (j = 0; j < psiconv_list_length(anon_styles); j++) { |
598 | for (j = 0; j < psiconv_list_length(anon_styles); j++) { |
427 | anon_ptr = psiconv_list_get(anon_styles,j); |
599 | if (!(anon_ptr = psiconv_list_get(anon_styles,j))) { |
|
|
600 | psiconv_warn(lev+4,off+len,"Massive memory curruption"); |
|
|
601 | goto ERROR4; |
|
|
602 | } |
428 | if (temp == anon_ptr->nr) |
603 | if (temp == anon_ptr->nr) |
429 | break; |
604 | break; |
430 | } |
605 | } |
431 | if (j == psiconv_list_length(anon_styles)) { |
606 | if (j == psiconv_list_length(anon_styles)) { |
432 | psiconv_warn(lev+4,off+len,"Layout section paragraph type unknown"); |
607 | psiconv_warn(lev+4,off+len,"Layout section paragraph type unknown"); |
433 | psiconv_debug(lev+4,off+len,"Unknown type - using base styles instead"); |
608 | psiconv_debug(lev+4,off+len,"Unknown type - using base styles instead"); |
434 | para->base_style = 0; |
609 | para->base_style = 0; |
|
|
610 | if (!(temp_style = psiconv_get_style(styles,0))) { |
|
|
611 | psiconv_warn(lev+4,off,"Base style unknown"); |
|
|
612 | goto ERROR4; |
|
|
613 | } |
|
|
614 | if (!(temp_para = psiconv_clone_paragraph_layout |
|
|
615 | (temp_style->paragraph))) |
|
|
616 | goto ERROR4; |
435 | psiconv_free_paragraph_layout(para->base_paragraph); |
617 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
618 | para->base_paragraph = temp_para; |
|
|
619 | |
|
|
620 | if (!(temp_char = psiconv_clone_character_layout |
|
|
621 | (temp_style->character))) |
|
|
622 | goto ERROR4; |
436 | psiconv_free_character_layout(para->base_character); |
623 | psiconv_free_character_layout(para->base_character); |
437 | para->base_paragraph = psiconv_clone_paragraph_layout(psiconv_get_style |
624 | para->base_character = temp_char; |
438 | (styles,0)->paragraph); |
|
|
439 | para->base_character = psiconv_clone_character_layout(psiconv_get_style |
|
|
440 | (styles,0)->character); |
|
|
441 | } else { |
625 | } else { |
442 | para->base_style = anon_ptr->base_style; |
626 | para->base_style = anon_ptr->base_style; |
|
|
627 | if (!(temp_para = psiconv_clone_paragraph_layout (anon_ptr->paragraph))) |
|
|
628 | goto ERROR4; |
443 | psiconv_free_paragraph_layout(para->base_paragraph); |
629 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
630 | para->base_paragraph = temp_para; |
|
|
631 | |
|
|
632 | if (!(temp_char = psiconv_clone_character_layout (anon_ptr->character))) |
|
|
633 | goto ERROR4; |
444 | psiconv_free_character_layout(para->base_character); |
634 | psiconv_free_character_layout(para->base_character); |
445 | para->base_paragraph = psiconv_clone_paragraph_layout |
635 | para->base_character = temp_char; |
446 | (anon_ptr->paragraph); |
|
|
447 | para->base_character = psiconv_clone_character_layout |
|
|
448 | (anon_ptr->character); |
|
|
449 | } |
636 | } |
450 | inline_count[i] = 0; |
637 | inline_count[i] = 0; |
451 | len += 0x01; |
638 | len += 0x01; |
452 | } else { |
639 | } else { |
453 | psiconv_debug(lev+4,off+len,"Type: %02x (not based on a paragraph type)" |
640 | psiconv_debug(lev+4,off+len,"Type: %02x (not based on a paragraph type)" |
454 | ,temp); |
641 | ,temp); |
455 | len += 0x01; |
642 | len += 0x01; |
456 | if (parse_styles) { |
643 | if (parse_styles) { |
457 | psiconv_progress(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len), |
644 | temp = psiconv_read_u32(buf,lev+4,off+len,&res); |
|
|
645 | if (res) |
|
|
646 | goto ERROR4; |
|
|
647 | psiconv_progress(lev+4,off+len+temp+4, |
458 | "Going to read the paragraph element base style"); |
648 | "Going to read the paragraph element base style"); |
459 | temp = psiconv_read_u8(buf,lev+4, |
649 | temp = psiconv_read_u8(buf,lev+4, off+len+temp+4,&res); |
460 | off+len+psiconv_read_u32(buf,lev+4,off+len)); |
650 | if (res) |
461 | psiconv_debug(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len), |
651 | goto ERROR4; |
462 | "Style: %02x",temp); |
652 | psiconv_debug(lev+4,off+len+temp+4, "Style: %02x",temp); |
463 | } else |
653 | } else |
464 | temp = 0x00; |
654 | temp = 0x00; |
|
|
655 | |
|
|
656 | if (!(temp_style = psiconv_get_style (styles,temp))) { |
|
|
657 | psiconv_warn(lev+4,off,"Unknown Style referenced"); |
|
|
658 | if (!(temp_style = psiconv_get_style(styles,0))) { |
|
|
659 | psiconv_warn(lev+4,off,"Base style unknown"); |
|
|
660 | goto ERROR4; |
|
|
661 | } |
|
|
662 | } |
|
|
663 | |
|
|
664 | if (!(temp_para = psiconv_clone_paragraph_layout(temp_style->paragraph))) |
|
|
665 | goto ERROR4; |
465 | psiconv_free_paragraph_layout(para->base_paragraph); |
666 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
667 | para->base_paragraph = temp_para; |
|
|
668 | |
|
|
669 | if (!(temp_char = psiconv_clone_character_layout(temp_style->character))) |
|
|
670 | goto ERROR4; |
466 | psiconv_free_character_layout(para->base_character); |
671 | psiconv_free_character_layout(para->base_character); |
467 | para->base_paragraph = psiconv_clone_paragraph_layout(psiconv_get_style |
672 | para->base_character = temp_char; |
468 | (styles,temp)->paragraph); |
673 | |
469 | para->base_character = psiconv_clone_character_layout(psiconv_get_style |
|
|
470 | (styles,temp)->character); |
|
|
471 | para->base_style = temp; |
674 | para->base_style = temp; |
472 | psiconv_progress(lev+4,off+len,"Going to read paragraph layout"); |
675 | psiconv_progress(lev+4,off+len,"Going to read paragraph layout"); |
473 | psiconv_parse_paragraph_layout_list(buf,lev+4,off+len,&leng, |
676 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+4,off+len,&leng, |
474 | para->base_paragraph); |
677 | para->base_paragraph))) |
|
|
678 | goto ERROR4; |
475 | len += leng; |
679 | len += leng; |
476 | if (parse_styles) |
680 | if (parse_styles) |
477 | len += 1; |
681 | len += 1; |
478 | psiconv_progress(lev+4,off+len,"Going to read number of in-line " |
682 | psiconv_progress(lev+4,off+len,"Going to read number of in-line " |
479 | "layout elements"); |
683 | "layout elements"); |
480 | inline_count[i] = psiconv_read_u32(buf,lev+4,off+len); |
684 | inline_count[i] = psiconv_read_u32(buf,lev+4,off+len,&res); |
|
|
685 | if (res) |
|
|
686 | goto ERROR4; |
481 | psiconv_debug(lev+4,off+len,"Nr: %08x",inline_count[i]); |
687 | psiconv_debug(lev+4,off+len,"Nr: %08x",inline_count[i]); |
482 | len += 4; |
688 | len += 4; |
483 | } |
689 | } |
484 | } |
690 | } |
485 | |
691 | |
486 | psiconv_progress(lev+2,off+len,"Going to read the text layout inline list"); |
692 | psiconv_progress(lev+2,off+len,"Going to read the text layout inline list"); |
487 | |
693 | |
488 | psiconv_progress(lev+3,off+len,"Going to read the number of elements"); |
694 | psiconv_progress(lev+3,off+len,"Going to read the number of elements"); |
489 | nr = psiconv_read_u32(buf,lev+3,off+len); |
695 | nr = psiconv_read_u32(buf,lev+3,off+len,&res); |
|
|
696 | if (res) |
|
|
697 | goto ERROR4; |
490 | psiconv_debug(lev+3,off,"Elements: %08x",nr); |
698 | psiconv_debug(lev+3,off+len,"Elements: %08x",nr); |
491 | len += 0x04; |
699 | len += 0x04; |
492 | |
700 | |
493 | psiconv_progress(lev+3,off+len, |
701 | psiconv_progress(lev+3,off+len, |
494 | "Going to read the text layout inline elements"); |
702 | "Going to read the text layout inline elements"); |
495 | total = 0; |
703 | total = 0; |
496 | for (i = 0; i < psiconv_list_length(result); i++) { |
704 | for (i = 0; i < psiconv_list_length(result); i++) { |
497 | para = psiconv_list_get(result,i); |
705 | if (!(para = psiconv_list_get(result,i))) { |
|
|
706 | psiconv_warn(lev+3,off+len,"Massive memory corruption"); |
|
|
707 | goto ERROR4; |
|
|
708 | } |
498 | line_length = -1; |
709 | line_length = -1; |
499 | for (j = 0; j < inline_count[i]; j++) { |
710 | for (j = 0; j < inline_count[i]; j++) { |
500 | psiconv_progress(lev+3,off+len,"Element %d: Paragraph %d, element %d", |
711 | psiconv_progress(lev+3,off+len,"Element %d: Paragraph %d, element %d", |
501 | total,i,j); |
712 | total,i,j); |
502 | if (total >= nr) { |
713 | if (total >= nr) { |
503 | psiconv_warn(lev+3,off+len, |
714 | psiconv_warn(lev+3,off+len, |
504 | "Layout section inlines: not enough element"); |
715 | "Layout section inlines: not enough element"); |
505 | res = -1; |
|
|
506 | psiconv_debug(lev+3,off+len,"Can't read element!"); |
716 | psiconv_debug(lev+3,off+len,"Can't read element!"); |
507 | } else { |
717 | } else { |
508 | total ++; |
718 | total ++; |
|
|
719 | in_line.object = NULL; |
|
|
720 | in_line.layout = NULL; |
509 | in_line.layout = psiconv_clone_character_layout(para->base_character); |
721 | if (!(in_line.layout = psiconv_clone_character_layout |
|
|
722 | (para->base_character))) |
|
|
723 | goto ERROR4; |
510 | psiconv_progress(lev+4,off+len,"Going to read the element type"); |
724 | psiconv_progress(lev+4,off+len,"Going to read the element type"); |
511 | temp = psiconv_read_u8(buf,lev+4,len+off); |
725 | temp = psiconv_read_u8(buf,lev+4,len+off,&res); |
|
|
726 | if (res) |
|
|
727 | goto ERROR5; |
512 | len += 1; |
728 | len += 1; |
513 | psiconv_debug(lev+4,off,"Type: %02x",temp); |
729 | psiconv_debug(lev+4,off+len,"Type: %02x",temp); |
514 | psiconv_progress(lev+4,off, |
730 | psiconv_progress(lev+4,off+len, |
515 | "Going to read the number of characters it applies to"); |
731 | "Going to read the number of characters it applies to"); |
516 | in_line.length = psiconv_read_u32(buf,lev+4,len+off); |
732 | in_line.length = psiconv_read_u32(buf,lev+4,len+off,&res); |
|
|
733 | if (res) |
|
|
734 | goto ERROR5; |
517 | psiconv_debug(lev+4,off+len,"Length: %02x",in_line.length); |
735 | psiconv_debug(lev+4,off+len,"Length: %02x",in_line.length); |
518 | len += 4; |
736 | len += 4; |
519 | psiconv_progress(lev+4,off+len,"Going to read the character layout"); |
737 | psiconv_progress(lev+4,off+len,"Going to read the character layout"); |
520 | res |= psiconv_parse_character_layout_list(buf,lev+4,off+len,&leng, |
738 | if ((res = psiconv_parse_character_layout_list(buf,lev+4,off+len,&leng, |
521 | in_line.layout); |
739 | in_line.layout))) |
|
|
740 | goto ERROR5; |
522 | len += leng; |
741 | len += leng; |
523 | |
742 | |
524 | if (temp == 0x01) { |
743 | if (temp == 0x01) { |
525 | psiconv_debug(lev+4,off+len,"Skipping object data"); |
744 | psiconv_debug(lev+4,off+len,"Found an embedded object"); |
526 | len += 0x10; |
745 | psiconv_progress(lev+4,off+len,"Going to read the object marker " |
|
|
746 | "(0x%08x expected)",PSICONV_ID_OBJECT); |
|
|
747 | temp = psiconv_read_u32(buf,lev+4,off+len,&res); |
|
|
748 | if (res) |
|
|
749 | goto ERROR5; |
|
|
750 | if (temp != PSICONV_ID_OBJECT) { |
|
|
751 | psiconv_warn(lev+4,off+len,"Unknown id marks embedded object"); |
|
|
752 | psiconv_debug(lev+4,off+len,"Marker: read %08x, expected %08x", |
|
|
753 | temp,PSICONV_ID_OBJECT); |
|
|
754 | } |
|
|
755 | len += 4; |
|
|
756 | psiconv_progress(lev+4,off+len, |
|
|
757 | "Going to read the Embedded Object Section offset"); |
|
|
758 | temp = psiconv_read_u32(buf,lev+4,off+len,&res); |
|
|
759 | if (res) |
|
|
760 | goto ERROR5; |
|
|
761 | psiconv_debug(lev+4,off+len, "Offset: %08x",temp); |
|
|
762 | len += 4; |
|
|
763 | psiconv_progress(lev+4,off+len, |
|
|
764 | "Going to parse the Embedded Object"); |
|
|
765 | if ((res = psiconv_parse_embedded_object(buf,lev+4,temp, |
|
|
766 | NULL,&(in_line.object)))) |
|
|
767 | goto ERROR5; |
|
|
768 | psiconv_progress(lev+4,off+len, |
|
|
769 | "Going to read the object width"); |
|
|
770 | in_line.object_width = psiconv_read_length(buf,lev+4,off+len, |
|
|
771 | &leng,&res); |
|
|
772 | if (res) |
|
|
773 | goto ERROR5; |
|
|
774 | psiconv_debug(lev+4,off+len,"Object width: %f cm", |
|
|
775 | in_line.object_width); |
|
|
776 | len += leng; |
|
|
777 | psiconv_progress(lev+4,off+len, |
|
|
778 | "Going to read the object height"); |
|
|
779 | in_line.object_height = psiconv_read_length(buf,lev+4,off+len,&leng, |
|
|
780 | &res); |
|
|
781 | if (res) |
|
|
782 | goto ERROR5; |
|
|
783 | psiconv_debug(lev+4,off+len,"Object height: %f cm", |
|
|
784 | in_line.object_height); |
|
|
785 | len += leng; |
527 | } else if (temp != 0x00) { |
786 | } else if (temp != 0x00) { |
528 | psiconv_warn(lev+4,off+len,"Layout section unknown inline type"); |
787 | psiconv_warn(lev+4,off+len,"Layout section unknown inline type"); |
529 | res = -1; |
|
|
530 | } |
788 | } |
531 | if (line_length + in_line.length > strlen(para->text)) { |
789 | if (line_length + in_line.length > strlen(para->text)) { |
532 | psiconv_warn(lev+4,off+len, |
790 | psiconv_warn(lev+4,off+len, |
533 | "Layout section inlines: line length mismatch"); |
791 | "Layout section inlines: line length mismatch"); |
534 | res = -1; |
792 | res = -1; |
535 | in_line.length = strlen(para->text) - line_length; |
793 | in_line.length = strlen(para->text) - line_length; |
536 | } |
794 | } |
537 | line_length += in_line.length; |
795 | line_length += in_line.length; |
538 | psiconv_list_add(para->in_lines,&in_line); |
796 | if ((res = psiconv_list_add(para->in_lines,&in_line))) |
|
|
797 | goto ERROR5; |
539 | } |
798 | } |
540 | } |
799 | } |
541 | } |
800 | } |
542 | |
801 | |
543 | if (total != nr) { |
802 | if (total != nr) { |
… | |
… | |
546 | } |
805 | } |
547 | |
806 | |
548 | free(inline_count); |
807 | free(inline_count); |
549 | |
808 | |
550 | for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { |
809 | for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { |
551 | anon_ptr = psiconv_list_get(anon_styles,i); |
810 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
|
|
811 | psiconv_warn(lev+4,off+len,"Massive memory corruption"); |
|
|
812 | goto ERROR2; |
|
|
813 | } |
552 | psiconv_free_character_layout(anon_ptr->character); |
814 | psiconv_free_character_layout(anon_ptr->character); |
553 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
815 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
554 | } |
816 | } |
555 | psiconv_list_free(anon_styles); |
817 | psiconv_list_free(anon_styles); |
556 | |
818 | |
557 | if (length) |
819 | if (length) |
558 | *length = len; |
820 | *length = len; |
559 | |
821 | |
560 | psiconv_progress(lev+1,off+len-1,"End of layout section (total length: %08x", |
822 | psiconv_progress(lev+1,off+len-1,"End of layout section (total length: %08x)", |
561 | len); |
823 | len); |
562 | |
824 | |
|
|
825 | return 0; |
|
|
826 | |
|
|
827 | ERROR4_4: |
|
|
828 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
829 | ERROR4_3: |
|
|
830 | psiconv_free_character_layout(para->base_character); |
|
|
831 | ERROR4_2: |
|
|
832 | psiconv_list_free(para->in_lines); |
|
|
833 | ERROR4_1: |
|
|
834 | free(para); |
|
|
835 | goto ERROR4; |
|
|
836 | |
|
|
837 | ERROR3_2: |
|
|
838 | psiconv_free_character_layout(anon.character); |
|
|
839 | ERROR3_1: |
|
|
840 | psiconv_free_paragraph_layout(anon.paragraph); |
|
|
841 | goto ERROR3; |
|
|
842 | |
|
|
843 | ERROR5: |
|
|
844 | if (in_line.layout) |
|
|
845 | psiconv_free_character_layout(in_line.layout); |
|
|
846 | if (in_line.object) |
|
|
847 | psiconv_free_object(in_line.object); |
|
|
848 | ERROR4: |
|
|
849 | free(inline_count); |
|
|
850 | ERROR3: |
|
|
851 | for (i = 0; i < psiconv_list_length(anon_styles); i++) { |
|
|
852 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
|
|
853 | psiconv_warn(lev+1,off,"Massive memory corruption"); |
|
|
854 | break; |
|
|
855 | } |
|
|
856 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
|
|
857 | psiconv_free_character_layout(anon_ptr->character); |
|
|
858 | } |
|
|
859 | |
|
|
860 | ERROR2: |
|
|
861 | psiconv_list_free(anon_styles); |
|
|
862 | ERROR1: |
|
|
863 | psiconv_warn(lev+1,off,"Reading of Layout Section failed"); |
|
|
864 | if (length) |
|
|
865 | *length = 0; |
|
|
866 | if (!res) |
|
|
867 | return -PSICONV_E_NOMEM; |
|
|
868 | else |
563 | return res; |
869 | return res; |
564 | } |
870 | } |
565 | |
871 | |
566 | int psiconv_parse_styled_layout_section(const psiconv_buffer buf, |
872 | int psiconv_parse_styled_layout_section(const psiconv_buffer buf, |
567 | int lev,psiconv_u32 off, |
873 | int lev,psiconv_u32 off, |
568 | int *length, |
874 | int *length, |
… | |
… | |
571 | { |
877 | { |
572 | return psiconv_parse_layout_section(buf,lev,off,length,result,styles,1); |
878 | return psiconv_parse_layout_section(buf,lev,off,length,result,styles,1); |
573 | } |
879 | } |
574 | |
880 | |
575 | int psiconv_parse_styleless_layout_section(const psiconv_buffer buf, |
881 | int psiconv_parse_styleless_layout_section(const psiconv_buffer buf, |
576 | int lev,psiconv_u32 off, |
882 | int lev,psiconv_u32 off, |
577 | int *length, |
883 | int *length, |
578 | psiconv_text_and_layout result, |
884 | psiconv_text_and_layout result, |
579 | psiconv_character_layout base_char, |
885 | const psiconv_character_layout base_char, |
580 | psiconv_paragraph_layout base_para) |
886 | const psiconv_paragraph_layout base_para) |
581 | { |
887 | { |
582 | int res; |
888 | int res = 0; |
583 | psiconv_word_styles_section styles_section; |
889 | psiconv_word_styles_section styles_section; |
584 | |
890 | |
585 | styles_section = malloc(sizeof(*styles_section)); |
891 | if (!(styles_section = malloc(sizeof(*styles_section)))) |
|
|
892 | goto ERROR1; |
586 | styles_section->normal = malloc(sizeof(*styles_section->normal)); |
893 | if (!(styles_section->normal = malloc(sizeof(*styles_section->normal)))) |
587 | styles_section->normal->character = psiconv_clone_character_layout(base_char); |
894 | goto ERROR2; |
588 | styles_section->normal->paragraph = psiconv_clone_paragraph_layout(base_para); |
895 | if (!(styles_section->normal->character = |
|
|
896 | psiconv_clone_character_layout(base_char))) |
|
|
897 | goto ERROR3; |
|
|
898 | if (!(styles_section->normal->paragraph = |
|
|
899 | psiconv_clone_paragraph_layout(base_para))) |
|
|
900 | goto ERROR4; |
589 | styles_section->normal->hotkey = 0; |
901 | styles_section->normal->hotkey = 0; |
590 | styles_section->normal->name = strdup(""); |
902 | if (!(styles_section->normal->name = strdup(""))) |
|
|
903 | goto ERROR5; |
591 | styles_section->styles = psiconv_list_new(sizeof(struct psiconv_word_style)); |
904 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
|
|
905 | struct psiconv_word_style_s)))) |
|
|
906 | goto ERROR6; |
592 | |
907 | |
593 | res = psiconv_parse_layout_section(buf,lev,off,length,result, |
908 | res = psiconv_parse_layout_section(buf,lev,off,length,result, |
594 | styles_section,0); |
909 | styles_section,0); |
595 | |
910 | |
596 | psiconv_free_word_styles_section(styles_section); |
911 | psiconv_free_word_styles_section(styles_section); |
597 | return res; |
912 | return res; |
|
|
913 | |
|
|
914 | ERROR6: |
|
|
915 | free(styles_section->normal->name); |
|
|
916 | ERROR5: |
|
|
917 | psiconv_free_paragraph_layout(styles_section->normal->paragraph); |
|
|
918 | ERROR4: |
|
|
919 | psiconv_free_character_layout(styles_section->normal->character); |
|
|
920 | ERROR3: |
|
|
921 | free(styles_section->normal); |
|
|
922 | ERROR2: |
|
|
923 | free(styles_section); |
|
|
924 | ERROR1: |
|
|
925 | psiconv_warn(lev+1,off,"Reading of Styleless Layout Section failed"); |
|
|
926 | if (length) |
|
|
927 | *length = 0; |
|
|
928 | if (!res) |
|
|
929 | return -PSICONV_E_NOMEM; |
|
|
930 | else |
|
|
931 | return res; |
598 | } |
932 | } |
599 | |
933 | |
|
|
934 | int psiconv_parse_embedded_object(const psiconv_buffer buf, int lev, |
|
|
935 | psiconv_u32 off, int *length, |
|
|
936 | psiconv_object *result) |
|
|
937 | { |
|
|
938 | int res=0; |
|
|
939 | int len=0; |
|
|
940 | int leng,i; |
|
|
941 | psiconv_section_table_section table; |
|
|
942 | psiconv_section_table_entry entry; |
|
|
943 | psiconv_u32 icon_sec=0,display_sec=0,table_sec=0; |
|
|
944 | |
|
|
945 | psiconv_progress(lev+1,off+len,"Going to read an Embedded Object"); |
|
|
946 | if (!(*result = malloc(sizeof(**result)))) |
|
|
947 | goto ERROR1; |
|
|
948 | |
|
|
949 | psiconv_progress(lev+2,off+len,"Going to read the Embedded Object Section"); |
|
|
950 | psiconv_parse_section_table_section(buf,lev+2,off+len,&leng,&table); |
|
|
951 | len += leng; |
|
|
952 | |
|
|
953 | for (i = 0; i < psiconv_list_length(table); i++) { |
|
|
954 | psiconv_progress(lev+2,off+len,"Going to read entry %d",i); |
|
|
955 | if (!(entry = psiconv_list_get(table,i))) |
|
|
956 | goto ERROR2; |
|
|
957 | if (entry->id == PSICONV_ID_OBJECT_DISPLAY_SECTION) { |
|
|
958 | display_sec = entry->offset; |
|
|
959 | psiconv_debug(lev+3,off+len,"Found the Object Display Section at %08x", |
|
|
960 | display_sec); |
|
|
961 | } else if (entry->id == PSICONV_ID_OBJECT_ICON_SECTION) { |
|
|
962 | icon_sec = entry->offset; |
|
|
963 | psiconv_debug(lev+3,off+len,"Found the Object Icon Section at %08x", |
|
|
964 | icon_sec); |
|
|
965 | } else if (entry->id == PSICONV_ID_OBJECT_SECTION_TABLE_SECTION) { |
|
|
966 | table_sec = entry->offset; |
|
|
967 | psiconv_debug(lev+3,off+len,"Found the Object Section Table Section at %08x", |
|
|
968 | table_sec); |
|
|
969 | } else { |
|
|
970 | psiconv_warn(lev+3,off+len, |
|
|
971 | "Found unknown section in the Object Display Section " |
|
|
972 | "(ignoring)"); |
|
|
973 | psiconv_debug(lev+3,off+len,"Section ID %08x, offset %08x", |
|
|
974 | entry->id, entry->offset); |
|
|
975 | } |
|
|
976 | } |
|
|
977 | |
|
|
978 | psiconv_progress(lev+2,off+len,"Looking for the Object Display Section"); |
|
|
979 | if (!icon_sec) { |
|
|
980 | psiconv_warn(lev+2,off+len,"Object Display Section not found"); |
|
|
981 | (*result)->display = NULL; |
|
|
982 | } else { |
|
|
983 | psiconv_debug(lev+2,off+len,"Object Display Section at offset %08x", |
|
|
984 | display_sec); |
|
|
985 | if ((res = psiconv_parse_object_display_section(buf,lev+2,display_sec,NULL, |
|
|
986 | &(*result)->display))) |
|
|
987 | goto ERROR2; |
|
|
988 | } |
|
|
989 | |
|
|
990 | psiconv_progress(lev+2,off+len,"Looking for the Object Icon Section"); |
|
|
991 | if (!icon_sec) { |
|
|
992 | psiconv_warn(lev+2,off+len,"Object Icon Section not found"); |
|
|
993 | (*result)->icon = NULL; |
|
|
994 | } else { |
|
|
995 | psiconv_debug(lev+2,off+len,"Object Icon Section at offset %08x",icon_sec); |
|
|
996 | if ((res = psiconv_parse_object_icon_section(buf,lev+2,icon_sec,NULL, |
|
|
997 | &(*result)->icon))) |
|
|
998 | goto ERROR2; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | if (length) |
|
|
1002 | *length = len; |
|
|
1003 | |
|
|
1004 | psiconv_progress(lev+1,off+len-1,"End of Embedded Object Section " |
|
|
1005 | "(total length: %08x)",len); |
|
|
1006 | |
|
|
1007 | return res; |
|
|
1008 | |
|
|
1009 | |
|
|
1010 | ERROR2: |
|
|
1011 | psiconv_free_section_table_section(table); |
|
|
1012 | ERROR1: |
|
|
1013 | psiconv_warn(lev+1,off,"Reading Embedded Object failed"); |
|
|
1014 | |
|
|
1015 | if (length) |
|
|
1016 | *length = 0; |
|
|
1017 | |
|
|
1018 | if (res == 0) |
|
|
1019 | return -PSICONV_E_NOMEM; |
|
|
1020 | else |
|
|
1021 | return res; |
|
|
1022 | } |
|
|
1023 | |
|
|
1024 | int psiconv_parse_object_display_section(const psiconv_buffer buf,int lev, |
|
|
1025 | psiconv_u32 off, int *length, |
|
|
1026 | psiconv_object_display_section *result) |
|
|
1027 | { |
|
|
1028 | int res = 0; |
|
|
1029 | int len = 0; |
|
|
1030 | int leng; |
|
|
1031 | psiconv_u32 temp; |
|
|
1032 | |
|
|
1033 | psiconv_progress(lev+1,off,"Going to read the Object Display Section"); |
|
|
1034 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1035 | goto ERROR1; |
|
|
1036 | |
|
|
1037 | psiconv_progress(lev+2,off+len,"Going to read the display as icon flag " |
|
|
1038 | "(expecting 0x00 or 0x01)"); |
|
|
1039 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1040 | if (res) |
|
|
1041 | goto ERROR2; |
|
|
1042 | if (temp == 0x00) { |
|
|
1043 | (*result)->show_icon = psiconv_bool_true; |
|
|
1044 | psiconv_debug(lev+2,off+len,"Displayed as full document"); |
|
|
1045 | } else if (temp == 0x01) { |
|
|
1046 | (*result)->show_icon = psiconv_bool_false; |
|
|
1047 | psiconv_debug(lev+2,off+len,"Displayed as icon"); |
|
|
1048 | } else { |
|
|
1049 | psiconv_warn(lev+2,off+len,"Unknown Object Display Section Icon Flag"); |
|
|
1050 | psiconv_debug(lev+2,off+len,"Icon flag found: %02x",temp); |
|
|
1051 | /* Improvise */ |
|
|
1052 | (*result)->show_icon = (temp & 0x01?psiconv_bool_false:psiconv_bool_true); |
|
|
1053 | } |
|
|
1054 | len ++; |
|
|
1055 | |
|
|
1056 | psiconv_progress(lev+2,off+len,"Going to read the icon width"); |
|
|
1057 | (*result)->width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
|
|
1058 | if (res) |
|
|
1059 | goto ERROR2; |
|
|
1060 | psiconv_debug(lev+2,off+len,"Icon width: %f cm",(*result)->width); |
|
|
1061 | len += leng; |
|
|
1062 | |
|
|
1063 | psiconv_progress(lev+2,off+len,"Going to read the icon height"); |
|
|
1064 | (*result)->height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
|
|
1065 | if (res) |
|
|
1066 | goto ERROR2; |
|
|
1067 | psiconv_debug(lev+2,off+len,"Icon length: %f cm",(*result)->height); |
|
|
1068 | len += leng; |
|
|
1069 | |
|
|
1070 | psiconv_progress(lev+2,off+len,"Going to read unknown long (%08x expected)", |
|
|
1071 | 0); |
|
|
1072 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1073 | if (temp != 0) { |
|
|
1074 | psiconv_warn(lev+2,off+len,"Unknown Object Display Section final long"); |
|
|
1075 | psiconv_debug(lev+2,off+len,"Long read: %08x",temp); |
|
|
1076 | } |
|
|
1077 | len += 4; |
|
|
1078 | |
|
|
1079 | if (length) |
|
|
1080 | *length = len; |
|
|
1081 | |
|
|
1082 | psiconv_progress(lev+1,off+len-1,"End of Object Display Section" |
|
|
1083 | "(total length: %08x",len); |
|
|
1084 | return res; |
|
|
1085 | |
|
|
1086 | ERROR2: |
|
|
1087 | free(*result); |
|
|
1088 | ERROR1: |
|
|
1089 | psiconv_warn(lev+1,off+len,"Reading of Object Display Section failed"); |
|
|
1090 | if (length) |
|
|
1091 | *length=0; |
|
|
1092 | if (!res) |
|
|
1093 | return -PSICONV_E_NOMEM; |
|
|
1094 | else |
|
|
1095 | return res; |
|
|
1096 | } |
|
|
1097 | |
|
|
1098 | int psiconv_parse_object_icon_section(const psiconv_buffer buf,int lev, |
|
|
1099 | psiconv_u32 off, int *length, |
|
|
1100 | psiconv_object_icon_section *result) |
|
|
1101 | { |
|
|
1102 | int res = 0; |
|
|
1103 | int len = 0; |
|
|
1104 | int leng; |
|
|
1105 | |
|
|
1106 | psiconv_progress(lev+1,off,"Going to read the Object Icon Section"); |
|
|
1107 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1108 | goto ERROR1; |
|
|
1109 | |
|
|
1110 | psiconv_progress(lev+2,off+len,"Going to read the icon name"); |
|
|
1111 | (*result)->icon_name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
1112 | if (res) |
|
|
1113 | goto ERROR2; |
|
|
1114 | psiconv_debug(lev+2,off+len,"Icon name: %s",(*result)->icon_name); |
|
|
1115 | len += leng; |
|
|
1116 | |
|
|
1117 | psiconv_progress(lev+2,off+len,"Going to read the icon width"); |
|
|
1118 | (*result)->icon_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
|
|
1119 | if (res) |
|
|
1120 | goto ERROR3; |
|
|
1121 | psiconv_debug(lev+2,off+len,"Icon width: %f cm",(*result)->icon_width); |
|
|
1122 | len += leng; |
|
|
1123 | |
|
|
1124 | psiconv_progress(lev+2,off+len,"Going to read the icon height"); |
|
|
1125 | (*result)->icon_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
|
|
1126 | if (res) |
|
|
1127 | goto ERROR3; |
|
|
1128 | psiconv_debug(lev+2,off+len,"Icon length: %f cm",(*result)->icon_height); |
|
|
1129 | len += leng; |
|
|
1130 | |
|
|
1131 | if (length) |
|
|
1132 | *length = len; |
|
|
1133 | |
|
|
1134 | psiconv_progress(lev+1,off+len-1,"End of Object Icon Section" |
|
|
1135 | "(total length: %08x",len); |
|
|
1136 | return res; |
|
|
1137 | |
|
|
1138 | ERROR3: |
|
|
1139 | free((*result)->icon_name); |
|
|
1140 | ERROR2: |
|
|
1141 | free(*result); |
|
|
1142 | ERROR1: |
|
|
1143 | psiconv_warn(lev+1,off+len,"Reading of Object Icon Section failed"); |
|
|
1144 | if (length) |
|
|
1145 | *length=0; |
|
|
1146 | if (!res) |
|
|
1147 | return -PSICONV_E_NOMEM; |
|
|
1148 | else |
|
|
1149 | return res; |
|
|
1150 | } |