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