1 | /* |
1 | /* |
2 | parse_word.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_word.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. |
… | |
… | |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | */ |
18 | */ |
19 | |
19 | |
20 | #include "config.h" |
20 | #include "config.h" |
|
|
21 | #include "compat.h" |
|
|
22 | |
21 | #include <stdlib.h> |
23 | #include <stdlib.h> |
|
|
24 | |
22 | #include "parse_routines.h" |
25 | #include "parse_routines.h" |
|
|
26 | #include "error.h" |
|
|
27 | |
|
|
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
23 | |
31 | |
24 | int psiconv_parse_word_status_section(const psiconv_buffer buf, int lev, |
32 | int psiconv_parse_word_status_section(const psiconv_buffer buf, int lev, |
25 | psiconv_u32 off, int *length, |
33 | psiconv_u32 off, int *length, |
26 | psiconv_word_status_section *result) |
34 | psiconv_word_status_section *result) |
27 | { |
35 | { |
… | |
… | |
29 | int len=0; |
37 | int len=0; |
30 | psiconv_u32 temp; |
38 | psiconv_u32 temp; |
31 | int leng; |
39 | int leng; |
32 | |
40 | |
33 | psiconv_progress(lev+1,off,"Going to read the word status section"); |
41 | psiconv_progress(lev+1,off,"Going to read the word status section"); |
34 | *result = malloc(sizeof(**result)); |
42 | if (!(*result = malloc(sizeof(**result)))) |
|
|
43 | goto ERROR1; |
35 | |
44 | |
36 | psiconv_progress(lev+2,off+len, |
45 | psiconv_progress(lev+2,off+len, |
37 | "Going to read the initial byte (%02x expected)",0x02); |
46 | "Going to read the initial byte (%02x expected)",0x02); |
38 | temp = psiconv_read_u8(buf,lev+2,off+len); |
47 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
48 | if (res) |
|
|
49 | goto ERROR2; |
39 | if (temp != 0x02) { |
50 | if (temp != 0x02) { |
40 | psiconv_warn(lev+2,off+len, |
51 | psiconv_warn(lev+2,off+len, |
41 | "Word status section initial byte unknown value"); |
52 | "Word status section initial byte unknown value (ignored)"); |
42 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
53 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
43 | res = -1; |
|
|
44 | } |
54 | } |
45 | len ++; |
55 | len ++; |
46 | |
56 | |
47 | psiconv_progress(lev+2,off+len, |
57 | psiconv_progress(lev+2,off+len, |
48 | "Going to read the first byte of display flags"); |
58 | "Going to read the first byte of display flags"); |
49 | temp = psiconv_read_u8(buf,lev+2,off+len); |
59 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
60 | if (res) |
|
|
61 | goto ERROR2; |
50 | |
62 | |
51 | (*result)->show_tabs = temp&0x01 ? psiconv_bool_true : psiconv_bool_false; |
63 | (*result)->show_tabs = temp&0x01 ? psiconv_bool_true : psiconv_bool_false; |
52 | psiconv_debug(lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs); |
64 | psiconv_debug(lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs); |
53 | (*result)->show_spaces = temp&0x02 ? psiconv_bool_true : psiconv_bool_false; |
65 | (*result)->show_spaces = temp&0x02 ? psiconv_bool_true : psiconv_bool_false; |
54 | psiconv_debug(lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces); |
66 | psiconv_debug(lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces); |
… | |
… | |
68 | psiconv_bool_false; |
80 | psiconv_bool_false; |
69 | psiconv_debug(lev+2,off+len,"Show hard space: %02x", |
81 | psiconv_debug(lev+2,off+len,"Show hard space: %02x", |
70 | (*result)->show_hard_space); |
82 | (*result)->show_hard_space); |
71 | if (temp & 0x90) { |
83 | if (temp & 0x90) { |
72 | psiconv_warn(lev+2,off+len,"Word status section first byte of display " |
84 | psiconv_warn(lev+2,off+len,"Word status section first byte of display " |
73 | "flags contains unknown flags"); |
85 | "flags contains unknown flags (ignored)"); |
74 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0x90); |
86 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0x90); |
75 | res = -1; |
|
|
76 | } |
87 | } |
77 | len ++; |
88 | len ++; |
78 | |
89 | |
79 | psiconv_progress(lev+2,off+len,"Going to read second byte of display flags"); |
90 | psiconv_progress(lev+2,off+len,"Going to read second byte of display flags"); |
80 | temp = psiconv_read_u8(buf,lev+2,off+len); |
91 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
92 | if (res) |
|
|
93 | goto ERROR2; |
81 | |
94 | |
82 | (*result)->show_full_pictures = temp & 0x01 ? psiconv_bool_true : |
95 | (*result)->show_full_pictures = temp & 0x01 ? psiconv_bool_true : |
83 | psiconv_bool_false; |
96 | psiconv_bool_false; |
84 | psiconv_debug(lev+2,off+len,"Show full pictures: %02x", |
97 | psiconv_debug(lev+2,off+len,"Show full pictures: %02x", |
85 | (*result)->show_full_pictures); |
98 | (*result)->show_full_pictures); |
… | |
… | |
87 | psiconv_bool_false; |
100 | psiconv_bool_false; |
88 | psiconv_debug(lev+2,off+len,"Show full graphs: %02x", |
101 | psiconv_debug(lev+2,off+len,"Show full graphs: %02x", |
89 | (*result)->show_full_graphs); |
102 | (*result)->show_full_graphs); |
90 | if (temp & 0xfc) { |
103 | if (temp & 0xfc) { |
91 | psiconv_warn(lev+2,off+len,"Word status section second byte of display " |
104 | psiconv_warn(lev+2,off+len,"Word status section second byte of display " |
92 | "flags contains unknown flags"); |
105 | "flags contains unknown flags (ignored)"); |
93 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); |
106 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); |
94 | res = -1; |
|
|
95 | } |
107 | } |
96 | len ++; |
108 | len ++; |
97 | |
109 | |
98 | psiconv_progress(lev+2,off+len,"Going to read top toolbar setting"); |
110 | psiconv_progress(lev+2,off+len,"Going to read top toolbar setting"); |
99 | psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->show_top_toolbar); |
111 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
|
|
112 | &(*result)->show_top_toolbar))) |
|
|
113 | goto ERROR2; |
100 | len += leng; |
114 | len += leng; |
101 | |
115 | |
102 | psiconv_progress(lev+2,off+len,"Going to read side toolbar setting"); |
116 | psiconv_progress(lev+2,off+len,"Going to read side toolbar setting"); |
103 | psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->show_side_toolbar); |
117 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
|
|
118 | &(*result)->show_side_toolbar))) |
|
|
119 | goto ERROR2; |
104 | len += leng; |
120 | len += leng; |
105 | |
121 | |
106 | psiconv_progress(lev+2,off+len,"Going to read operational flags"); |
122 | psiconv_progress(lev+2,off+len,"Going to read operational flags"); |
107 | temp = psiconv_read_u8(buf,lev+2,off+len); |
123 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
124 | if (res) |
|
|
125 | goto ERROR2; |
108 | (*result)->fit_lines_to_screen = temp & 0x08 ? psiconv_bool_true : |
126 | (*result)->fit_lines_to_screen = temp & 0x08 ? psiconv_bool_true : |
109 | psiconv_bool_false; |
127 | psiconv_bool_false; |
110 | psiconv_debug(lev+2,off+len,"Fit lines to screen: %02x", |
128 | psiconv_debug(lev+2,off+len,"Fit lines to screen: %02x", |
111 | (*result)->fit_lines_to_screen); |
129 | (*result)->fit_lines_to_screen); |
112 | if (temp & 0xf7) { |
130 | if (temp & 0xf7) { |
113 | psiconv_warn(lev+2,off+len,"Word status section operational flags " |
131 | psiconv_warn(lev+2,off+len,"Word status section operational flags " |
114 | "contains unknown flags"); |
132 | "contains unknown flags (ignored)"); |
115 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); |
133 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); |
116 | res = -1; |
|
|
117 | } |
134 | } |
118 | len ++; |
135 | len ++; |
119 | |
136 | |
120 | psiconv_progress(lev+2,off+len,"Going to read cursor position"); |
137 | psiconv_progress(lev+2,off+len,"Going to read cursor position"); |
121 | (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len); |
138 | (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len,&res); |
|
|
139 | if (res) |
|
|
140 | goto ERROR2; |
122 | psiconv_debug(lev+2,off+len,"Cursor position: %08x", |
141 | psiconv_debug(lev+2,off+len,"Cursor position: %08x", |
123 | (*result)->cursor_position); |
142 | (*result)->cursor_position); |
124 | len += 0x04; |
143 | len += 0x04; |
125 | |
144 | |
126 | psiconv_progress(lev+2,off+len,"Going to read display size"); |
145 | psiconv_progress(lev+2,off+len,"Going to read display size"); |
127 | (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len); |
146 | (*result)->display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
|
|
147 | if (res) |
|
|
148 | goto ERROR2; |
128 | psiconv_debug(lev+2,off+len,"Display size: %08x", |
149 | psiconv_debug(lev+2,off+len,"Display size: %08x", |
129 | (*result)->cursor_position); |
150 | (*result)->display_size); |
130 | len += 0x04; |
151 | len += 0x04; |
131 | |
152 | |
132 | if (length) |
153 | if (length) |
133 | *length = len; |
154 | *length = len; |
134 | |
155 | |
135 | psiconv_progress(lev,off+len-1, |
156 | psiconv_progress(lev,off+len-1, |
136 | "End of word status section (total length: %08x)", len); |
157 | "End of word status section (total length: %08x)", len); |
|
|
158 | return 0; |
137 | |
159 | |
|
|
160 | ERROR2: |
|
|
161 | free (*result); |
|
|
162 | ERROR1: |
|
|
163 | psiconv_warn(lev+1,off,"Reading of Word Status Section failed"); |
|
|
164 | if (length) |
|
|
165 | *length = 0; |
|
|
166 | if (!res) |
|
|
167 | return -PSICONV_E_NOMEM; |
|
|
168 | else |
138 | return res; |
169 | return res; |
139 | } |
170 | } |
140 | |
171 | |
141 | int psiconv_parse_word_styles_section(const psiconv_buffer buf, int lev, |
172 | int psiconv_parse_word_styles_section(const psiconv_buffer buf, int lev, |
142 | psiconv_u32 off, int *length, |
173 | psiconv_u32 off, int *length, |
143 | psiconv_word_styles_section *result) |
174 | psiconv_word_styles_section *result) |
144 | { |
175 | { |
145 | int res=0; |
176 | int res=0; |
146 | int len=0; |
177 | int len=0; |
147 | int leng,i,nr; |
178 | int leng,i,nr,j; |
148 | psiconv_word_style style; |
179 | psiconv_word_style style; |
149 | psiconv_u32 temp; |
180 | psiconv_u32 temp; |
150 | |
181 | |
151 | psiconv_progress(lev+1,off,"Going to read the word styles section"); |
182 | psiconv_progress(lev+1,off,"Going to read the word styles section"); |
152 | *result = malloc(sizeof(**result)); |
183 | if (!(*result = malloc(sizeof(**result)))) |
|
|
184 | goto ERROR1; |
153 | |
185 | |
154 | psiconv_progress(lev+2,off+len,"Going to read style normal"); |
186 | psiconv_progress(lev+2,off+len,"Going to read style normal"); |
155 | style = malloc(sizeof(*style)); |
187 | if (!(style = malloc(sizeof(*style)))) |
|
|
188 | goto ERROR2; |
156 | style->name = NULL; |
189 | style->name = NULL; |
157 | style->paragraph = psiconv_basic_paragraph_layout(); |
190 | if (!(style->paragraph = psiconv_basic_paragraph_layout())) |
|
|
191 | goto ERROR2_1; |
158 | psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); |
192 | psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); |
159 | res |= psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
193 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
160 | style->paragraph); |
194 | style->paragraph))) |
|
|
195 | goto ERROR2_2; |
161 | len += leng; |
196 | len += leng; |
162 | psiconv_progress(lev+3,off+len,"Going to read the character codes"); |
197 | psiconv_progress(lev+3,off+len,"Going to read the character codes"); |
163 | style->character = psiconv_basic_character_layout(); |
198 | if (!(style->character = psiconv_basic_character_layout())) |
|
|
199 | goto ERROR2_2; |
164 | res |= psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
200 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
165 | style->character); |
201 | style->character))) |
|
|
202 | goto ERROR2_3; |
166 | len += leng; |
203 | len += leng; |
167 | psiconv_progress(lev+3,off+len,"Going to read the hotkey"); |
204 | psiconv_progress(lev+3,off+len,"Going to read the hotkey"); |
168 | temp = psiconv_read_u32(buf,lev+3,off+len); |
205 | temp = psiconv_read_u32(buf,lev+3,off+len,&res); |
|
|
206 | if (res) |
|
|
207 | goto ERROR2_3; |
169 | if (temp & 0xffffff00) { |
208 | if (temp & 0xffffff00) { |
170 | psiconv_warn(lev+3,off+len,"Normal style hotkey has unknown value"); |
209 | psiconv_warn(lev+3,off+len, |
|
|
210 | "Normal style hotkey has unknown value (ignored)"); |
171 | psiconv_debug(lev+3,off+len,"Hotkey value %08x",temp); |
211 | psiconv_debug(lev+3,off+len,"Hotkey value %08x",temp); |
172 | temp = 0; |
212 | temp = 0; |
173 | res = -1; |
|
|
174 | } |
213 | } |
175 | style->hotkey = temp; |
214 | style->hotkey = temp & 0x000000ff; |
176 | if ((style->hotkey >= 32) && (style->hotkey < 127)) |
215 | if ((style->hotkey >= 32) && (style->hotkey < 127)) |
177 | psiconv_debug(lev+3,off+len,"Hotkey: %c",style->hotkey); |
216 | psiconv_debug(lev+3,off+len,"Hotkey: %c",style->hotkey); |
178 | else if (style->hotkey == 0x00) |
217 | else if (style->hotkey == 0x00) |
179 | psiconv_debug(lev+3,off+len,"Hotkey: <none>"); |
218 | psiconv_debug(lev+3,off+len,"Hotkey: <none>"); |
180 | else |
219 | else |
181 | psiconv_debug(lev+3,off+len,"Hotkey: %02x",style->hotkey); |
220 | psiconv_debug(lev+3,off+len,"Hotkey: %02x",style->hotkey); |
182 | (*result)->normal = style; |
221 | (*result)->normal = style; |
183 | len += 0x04; |
222 | len += 0x04; |
184 | |
223 | |
185 | psiconv_progress(lev+2,off+len,"Going to read hotkeys list"); |
224 | psiconv_progress(lev+2,off+len,"Going to read hotkeys list"); |
186 | (*result)->styles = psiconv_list_new(sizeof(*style)); |
225 | if (!((*result)->styles = psiconv_list_new(sizeof(*style)))) |
|
|
226 | goto ERROR3; |
187 | style = malloc(sizeof(*style)); |
227 | if (!(style = malloc(sizeof(*style)))) { |
|
|
228 | goto ERROR3_1; |
|
|
229 | } |
|
|
230 | |
188 | psiconv_progress(lev+3,off+len,"Going to read the number of entries"); |
231 | psiconv_progress(lev+3,off+len,"Going to read the number of entries"); |
189 | nr = psiconv_read_u8(buf,lev+3,off+len); |
232 | nr = psiconv_read_u8(buf,lev+3,off+len,&res); |
|
|
233 | if (res) |
|
|
234 | goto ERROR3_2; |
190 | len ++; |
235 | len ++; |
191 | psiconv_debug(lev+3,off+len,"Nummer of hotkeys: %02x",nr); |
236 | psiconv_debug(lev+3,off+len,"Nummer of hotkeys: %02x",nr); |
192 | for (i = 0; i < nr; i ++) { |
237 | for (i = 0; i < nr; i ++) { |
193 | temp = psiconv_read_u32(buf,lev+2,off+len); |
238 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
239 | if (res) |
|
|
240 | goto ERROR3_2; |
194 | if (temp & 0xffffff00) { |
241 | if (temp & 0xffffff00) { |
195 | psiconv_warn(lev+3,off+len,"Style hotkey has unknown value"); |
242 | psiconv_warn(lev+3,off+len,"Style hotkey has unknown value (ignored)"); |
196 | psiconv_debug(lev+3,off+len,"Hotkey %d value %08x",i,temp); |
243 | psiconv_debug(lev+3,off+len,"Hotkey %d value %08x",i,temp); |
197 | temp = 0; |
244 | temp = 0; |
198 | res = -1; |
|
|
199 | } |
245 | } |
200 | style->hotkey = temp; |
246 | style->hotkey = temp & 0x000000ff; |
201 | if ((style->hotkey >= 32) && (style->hotkey < 127)) |
247 | if ((style->hotkey >= 32) && (style->hotkey < 127)) |
202 | psiconv_debug(lev+3,off+len,"Hotkey %d: %c",i,style->hotkey); |
248 | psiconv_debug(lev+3,off+len,"Hotkey %d: %c",i,style->hotkey); |
203 | else if (style->hotkey == 0x00) |
249 | else if (style->hotkey == 0x00) |
204 | psiconv_debug(lev+3,off+len,"Hotkey %d: <none>",i); |
250 | psiconv_debug(lev+3,off+len,"Hotkey %d: <none>",i); |
205 | else |
251 | else |
206 | psiconv_debug(lev+3,off+len,"Hotkey %d: %02x",i,style->hotkey); |
252 | psiconv_debug(lev+3,off+len,"Hotkey %d: %02x",i,style->hotkey); |
207 | psiconv_list_add((*result)->styles,style); |
253 | if ((res = psiconv_list_add((*result)->styles,style))) |
|
|
254 | goto ERROR3_2; |
208 | len += 0x04; |
255 | len += 0x04; |
209 | } |
256 | } |
210 | free(style); |
257 | free(style); |
211 | |
258 | |
212 | psiconv_progress(lev+2,off+len,"Going to read all other styles"); |
259 | psiconv_progress(lev+2,off+len,"Going to read all other styles"); |
213 | psiconv_progress(lev+2,off+len,"Going to read the number of styles"); |
260 | psiconv_progress(lev+2,off+len,"Going to read the number of styles"); |
214 | nr = psiconv_read_u8(buf,lev+3,off+len); |
261 | nr = psiconv_read_u8(buf,lev+3,off+len,&res); |
|
|
262 | if (res) |
|
|
263 | goto ERROR4; |
215 | if (nr != psiconv_list_length((*result)->styles)) { |
264 | if (nr != psiconv_list_length((*result)->styles)) { |
216 | psiconv_warn(lev+3,off+len,"Number of styles and hotkeys do not match"); |
265 | psiconv_warn(lev+3,off+len,"Number of styles and hotkeys do not match"); |
217 | psiconv_debug(lev+3,off+len,"%d hotkeys, %d styles", |
266 | psiconv_debug(lev+3,off+len,"%d hotkeys, %d styles", |
218 | psiconv_list_length((*result)->styles), nr); |
267 | psiconv_list_length((*result)->styles), nr); |
219 | res = -1; |
|
|
220 | } |
268 | } |
221 | len ++; |
269 | len ++; |
222 | |
270 | |
223 | for (i = 0; i < nr; i++) { |
271 | for (i = 0; i < nr; i++) { |
224 | psiconv_progress(lev+2,off+len,"Next style: %d",i); |
272 | psiconv_progress(lev+2,off+len,"Next style: %d",i); |
225 | if (i >= psiconv_list_length((*result)->styles)) { |
273 | if (i >= psiconv_list_length((*result)->styles)) { |
226 | style = malloc(sizeof(*style)); |
274 | if (!(style = malloc(sizeof(*style)))) |
|
|
275 | goto ERROR5; |
227 | style->hotkey = 0; |
276 | style->hotkey = 0; |
228 | psiconv_list_add((*result)->styles,style); |
277 | if (psiconv_list_add((*result)->styles,style)) { |
|
|
278 | free(style); |
|
|
279 | goto ERROR5; |
|
|
280 | } |
229 | psiconv_debug(lev+3,off+len,"New entry added in list"); |
281 | psiconv_debug(lev+3,off+len,"New entry added in list"); |
230 | free(style); |
282 | free(style); |
231 | } |
283 | } |
232 | style = psiconv_list_get((*result)->styles,i); |
284 | if (!(style = psiconv_list_get((*result)->styles,i))) |
|
|
285 | goto ERROR5; |
233 | psiconv_progress(lev+3,off+len,"Going to read the style name"); |
286 | psiconv_progress(lev+3,off+len,"Going to read the style name"); |
234 | style->name = psiconv_read_string(buf,lev+3,off+len,&leng); |
287 | style->name = psiconv_read_string(buf,lev+3,off+len,&leng,&res); |
|
|
288 | if (res) |
|
|
289 | goto ERROR5; |
235 | len += leng; |
290 | len += leng; |
236 | psiconv_progress(lev+3,off+len, |
291 | psiconv_progress(lev+3,off+len, |
237 | "Going to read whether this style is built-in"); |
292 | "Going to read whether this style is built-in"); |
238 | temp = psiconv_read_u32(buf,lev+2,off+len); |
293 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
294 | if (res) |
|
|
295 | goto ERROR6; |
|
|
296 | |
239 | if (temp == PSICONV_ID_STYLE_BUILT_IN) { |
297 | if (temp == PSICONV_ID_STYLE_BUILT_IN) { |
240 | style->built_in = psiconv_bool_true; |
298 | style->built_in = psiconv_bool_true; |
241 | psiconv_debug(lev+3,off+len,"Built-in style"); |
299 | psiconv_debug(lev+3,off+len,"Built-in style"); |
242 | } else if (temp == PSICONV_ID_STYLE_REMOVABLE) { |
300 | } else if (temp == PSICONV_ID_STYLE_REMOVABLE) { |
243 | style->built_in = psiconv_bool_false; |
301 | style->built_in = psiconv_bool_false; |
244 | psiconv_debug(lev+3,off+len,"Removable style"); |
302 | psiconv_debug(lev+3,off+len,"Removable style"); |
245 | } else { |
303 | } else { |
246 | psiconv_warn(lev+3,off+len,"Word styles section unknown style id"); |
304 | psiconv_warn(lev+3,off+len, |
|
|
305 | "Word styles section unknown style id (treated as built-in)"); |
247 | psiconv_debug(lev+3,off+len,"Unknown id: %08x",temp); |
306 | psiconv_debug(lev+3,off+len,"Unknown id: %08x",temp); |
248 | style->built_in = psiconv_bool_false; |
307 | style->built_in = psiconv_bool_false; |
249 | res = -1; |
|
|
250 | } |
308 | } |
251 | len += 4; |
309 | len += 4; |
252 | psiconv_progress(lev+3,off+len,"Going to read an unknown long " |
310 | psiconv_progress(lev+3,off+len,"Going to read outline level"); |
253 | "(0x%08x expected)",0x00000000); |
|
|
254 | temp = psiconv_read_u32(buf,lev+3,off+len); |
311 | style->outline_level = psiconv_read_u32(buf,lev+3,off+len,&res); |
255 | if (temp != 0x00000000) { |
312 | if (res) |
256 | psiconv_warn(lev+3,off+len,"Unexpected value in style description"); |
313 | goto ERROR6; |
257 | psiconv_debug(lev+3,off+len,"Unknown long: read %08x, expected %08x", |
314 | psiconv_debug(lev+3,off+len,"Outline Level: %08x", style->outline_level); |
258 | temp, 0x00000000); |
|
|
259 | } |
|
|
260 | len += 4; |
315 | len += 4; |
261 | psiconv_progress(lev+3,off+len,"Going to read the character codes"); |
316 | psiconv_progress(lev+3,off+len,"Going to read the character codes"); |
262 | style->character = psiconv_basic_character_layout(); |
317 | if (!(style->character = psiconv_clone_character_layout((*result)->normal->character))) |
|
|
318 | goto ERROR6; |
263 | res |= psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
319 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
264 | style->character); |
320 | style->character))) |
|
|
321 | goto ERROR7; |
265 | len += leng; |
322 | len += leng; |
266 | psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); |
323 | psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); |
267 | style->paragraph = psiconv_basic_paragraph_layout(); |
324 | if (!(style->paragraph = psiconv_clone_paragraph_layout((*result)->normal->paragraph))) |
|
|
325 | goto ERROR7; |
268 | res |= psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
326 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
269 | style->paragraph); |
327 | style->paragraph))) |
|
|
328 | goto ERROR8; |
270 | len += leng; |
329 | len += leng; |
|
|
330 | } |
|
|
331 | |
|
|
332 | psiconv_progress(lev+2,off+len,"Reading trailing bytes"); |
|
|
333 | for (i = 0; i < psiconv_list_length((*result)->styles); i++) { |
|
|
334 | temp = psiconv_read_u8(buf,lev+3,off+len,&res); |
|
|
335 | if (res) |
|
|
336 | goto ERROR4; |
|
|
337 | if (temp != 0xff) { |
|
|
338 | psiconv_warn(lev+3,off+len,"Unknown trailing style byte"); |
|
|
339 | psiconv_debug(lev+3,off+len,"Trailing byte: %02x expected, read %02x", |
|
|
340 | 0xff,temp); |
|
|
341 | } else |
|
|
342 | psiconv_debug(lev+3,off+len,"Read trailing byte 0xff"); |
|
|
343 | len++; |
271 | } |
344 | } |
272 | |
345 | |
273 | if (length) |
346 | if (length) |
274 | *length = len; |
347 | *length = len; |
275 | |
348 | |
276 | psiconv_progress(lev,off+len-1, |
349 | psiconv_progress(lev,off+len-1, |
277 | "End of word styles section (total length: %08x)", len); |
350 | "End of word styles section (total length: %08x)", len); |
278 | |
351 | |
279 | return res; |
352 | return res; |
|
|
353 | |
|
|
354 | |
|
|
355 | ERROR3_2: |
|
|
356 | free(style); |
|
|
357 | ERROR3_1: |
|
|
358 | psiconv_list_free((*result)->styles); |
|
|
359 | goto ERROR3; |
|
|
360 | |
|
|
361 | ERROR2_3: |
|
|
362 | psiconv_free_character_layout(style->character); |
|
|
363 | ERROR2_2: |
|
|
364 | psiconv_free_paragraph_layout(style->paragraph); |
|
|
365 | ERROR2_1: |
|
|
366 | free (style); |
|
|
367 | goto ERROR2; |
|
|
368 | |
|
|
369 | ERROR8: |
|
|
370 | psiconv_free_paragraph_layout(style->paragraph); |
|
|
371 | ERROR7: |
|
|
372 | psiconv_free_character_layout(style->character); |
|
|
373 | ERROR6: |
|
|
374 | free(style->name); |
|
|
375 | ERROR5: |
|
|
376 | for (j = 0; j < i ;j++) { |
|
|
377 | if (!(style = psiconv_list_get((*result)->styles,j))) { |
|
|
378 | psiconv_warn(lev+1,off,"Massive memory corruption"); |
|
|
379 | goto ERROR4; |
|
|
380 | } |
|
|
381 | psiconv_free_character_layout(style->character); |
|
|
382 | psiconv_free_paragraph_layout(style->paragraph); |
|
|
383 | free(style->name); |
|
|
384 | } |
|
|
385 | ERROR4: |
|
|
386 | psiconv_list_free((*result)->styles); |
|
|
387 | ERROR3: |
|
|
388 | psiconv_free_word_style((*result)->normal); |
|
|
389 | ERROR2: |
|
|
390 | free (*result); |
|
|
391 | ERROR1: |
|
|
392 | psiconv_warn(lev+1,off,"Reading of Word Status Section failed"); |
|
|
393 | if (length) |
|
|
394 | *length = 0; |
|
|
395 | if (!res) |
|
|
396 | return -PSICONV_E_NOMEM; |
|
|
397 | else |
|
|
398 | return res; |
280 | } |
399 | } |
281 | |
400 | |
282 | |
401 | |
|
|
402 | |