/[public]/psiconv/trunk/lib/psiconv/parse_layout.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_layout.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 63 Revision 84
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>
22#include <math.h> 24#include <math.h>
23 25
24#include "data.h"
25#include "parse_routines.h" 26#include "parse_routines.h"
27#include "error.h"
26 28
27int psiconv_parse_color(const psiconv_buffer buf, int lev, psiconv_u32 off, 29int psiconv_parse_color(const psiconv_buffer buf, int lev, psiconv_u32 off,
28 int *length, psiconv_color *result) 30 int *length, psiconv_color *result)
29{ 31{
30 int res = 0; 32 int res = 0;
31 int len = 0; 33 int len = 0;
32 34
33 psiconv_progress(lev+1,off,"Going to parse color"); 35 psiconv_progress(lev+1,off,"Going to parse color");
34 *result = malloc(sizeof(**result)); 36 if (!(*result = malloc(sizeof(**result))))
37 goto ERROR1;
35 38
36 (*result)->red = psiconv_read_u8(buf,lev+2,off+len); 39 (*result)->red = psiconv_read_u8(buf,lev+2,off+len,&res);
40 if (res)
41 goto ERROR2;
37 (*result)->green = psiconv_read_u8(buf,lev+2,off+len+1); 42 (*result)->green = psiconv_read_u8(buf,lev+2,off+len+1,&res);
43 if (res)
44 goto ERROR2;
38 (*result)->blue = psiconv_read_u8(buf,lev+2,off+len+2); 45 (*result)->blue = psiconv_read_u8(buf,lev+2,off+len+2,&res);
46 if (res)
47 goto ERROR2;
39 len += 3; 48 len += 3;
40 49
41 psiconv_debug(lev+2,off,"Color: red %02x, green %02x, blue %02x", 50 psiconv_debug(lev+2,off,"Color: red %02x, green %02x, blue %02x",
42 (*result)->red, (*result)->green, (*result)->blue); 51 (*result)->red, (*result)->green, (*result)->blue);
43 if (length) 52 if (length)
44 *length = len; 53 *length = len;
45 54
46 psiconv_progress(lev+1,off+len-1,"End of color (total length: %08x)",len); 55 psiconv_progress(lev+1,off+len-1,"End of color (total length: %08x)",len);
56 return 0;
57
58ERROR2:
59 free(*result);
60ERROR1:
61 psiconv_warn(lev+1,off,"Reading of Color failed");
62 if (length)
63 *length = 0;
64 if (res == 0)
65 return -PSICONV_E_NOMEM;
66 else
47 return res; 67 return res;
48} 68}
49 69
50 70
51 71
52int psiconv_parse_font(const psiconv_buffer buf, int lev, psiconv_u32 off, 72int psiconv_parse_font(const psiconv_buffer buf, int lev, psiconv_u32 off,
56 int strlength,i; 76 int strlength,i;
57 char *str_copy; 77 char *str_copy;
58 int len; 78 int len;
59 79
60 psiconv_progress(lev+1,off,"Going to parse font"); 80 psiconv_progress(lev+1,off,"Going to parse font");
61 *result = malloc(sizeof(**result)); 81 if (!(*result = malloc(sizeof(**result))))
82 goto ERROR1;
62 83
63 strlength = psiconv_read_u8(buf,lev+2,off); 84 strlength = psiconv_read_u8(buf,lev+2,off,&res);
85 if (res)
86 goto ERROR2;
64 (*result)->name = malloc(strlength); 87 if (!((*result)->name = malloc(strlength))) {
88 goto ERROR2;
89 }
65 for (i = 0; i < strlength-1; i++) 90 for (i = 0; (i < strlength-1) && !res; i++)
66 (*result)->name[i] = psiconv_read_u8(buf,lev+2,off + 1 + i); 91 (*result)->name[i] = psiconv_read_u8(buf,lev+2,off + 1 + i,&res);
92 if (res)
93 goto ERROR3;
67 (*result)->name[strlength-1] = 0; 94 (*result)->name[strlength-1] = 0;
68 (*result)->screenfont = psiconv_read_u8(buf,lev+2,off + strlength); 95 (*result)->screenfont = psiconv_read_u8(buf,lev+2,off + strlength,&res);
96 if (res)
97 goto ERROR3;
69 98
70 str_copy = psiconv_make_printable((*result)->name); 99 if (!(str_copy = psiconv_make_printable((*result)->name)))
100 goto ERROR3;
101
71 psiconv_debug(lev+2,off+1,"Found font `%s', displayed with screen font %02x", 102 psiconv_debug(lev+2,off+1,"Found font `%s', displayed with screen font %02x",
72 str_copy,(*result)->screenfont); 103 str_copy,(*result)->screenfont);
73 free(str_copy); 104 free(str_copy);
74 len = strlength + 1; 105 len = strlength + 1;
75 if (length) 106 if (length)
76 *length = len; 107 *length = len;
77 108
78 psiconv_progress(lev+1,off + len - 1,"End of font (total length: %08x)",len); 109 psiconv_progress(lev+1,off + len - 1,"End of font (total length: %08x)",len);
110 return 0;
111
112ERROR3:
113 free ((*result)->name);
114ERROR2:
115 free (*result);
116ERROR1:
117 psiconv_warn(lev+1,off,"Reading of Font failed");
118 if (length)
119 *length = 0;
120 if (!res)
121 return -PSICONV_E_NOMEM;
122 else
79 return res; 123 return res;
80} 124}
81 125
82int psiconv_parse_border(const psiconv_buffer buf,int lev,psiconv_u32 off, 126int psiconv_parse_border(const psiconv_buffer buf,int lev,psiconv_u32 off,
83 int *length, psiconv_border *result) 127 int *length, psiconv_border *result)
84{ 128{
86 int len = 0; 130 int len = 0;
87 psiconv_u32 temp; 131 psiconv_u32 temp;
88 int leng; 132 int leng;
89 133
90 psiconv_progress(lev+1,off,"Going to parse border data"); 134 psiconv_progress(lev+1,off,"Going to parse border data");
91 *result = malloc(sizeof(**result)); 135 if (!(*result = malloc(sizeof(**result)))) {
136 goto ERROR1;
137 }
92 138
93 psiconv_progress(lev+2,off+len,"Going to read border kind"); 139 psiconv_progress(lev+2,off+len,"Going to read border kind");
94 temp = psiconv_read_u8(buf,lev+2,off+len); 140 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
141 if (res)
142 goto ERROR2;
95 if (temp == 0x00) 143 if (temp == 0x00)
96 (*result)->kind = psiconv_border_none; 144 (*result)->kind = psiconv_border_none;
97 else if (temp == 0x01) 145 else if (temp == 0x01)
98 (*result)->kind = psiconv_border_solid; 146 (*result)->kind = psiconv_border_solid;
99 else if (temp == 0x02) 147 else if (temp == 0x02)
100 (*result)->kind = psiconv_border_double; 148 (*result)->kind = psiconv_border_double;
101 else if (temp == 0x03) 149 else if (temp == 0x03)
102 (*result)->kind = psiconv_border_dotted; 150 (*result)->kind = psiconv_border_dotted;
103 else if (temp == 0x04) 151 else if (temp == 0x04)
104 (*result)->kind = psiconv_border_striped; 152 (*result)->kind = psiconv_border_dashed;
105 else if (temp == 0x05) 153 else if (temp == 0x05)
106 (*result)->kind = psiconv_border_dotstripe; 154 (*result)->kind = psiconv_border_dotdashed;
107 else if (temp == 0x06) 155 else if (temp == 0x06)
108 (*result)->kind = psiconv_border_dotdotstripe; 156 (*result)->kind = psiconv_border_dotdotdashed;
109 else { 157 else {
110 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')"); 158 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')");
111 (*result)->kind = psiconv_border_none; 159 (*result)->kind = psiconv_border_none;
112 res = -1;
113 } 160 }
114 psiconv_debug(lev+2,off+len,"Kind: %02x",temp); 161 psiconv_debug(lev+2,off+len,"Kind: %02x",temp);
115 len ++; 162 len ++;
116 163
117 psiconv_progress(lev+2,off+len,"Going to read border thickness"); 164 psiconv_progress(lev+2,off+len,"Going to read border thickness");
118 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng); 165 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng,&res);
166 if (res)
167 goto ERROR2;
168#if 0
169 /* This seems no longer necessary to test? */
119 if (((*result)->kind != psiconv_border_solid) && 170 if (((*result)->kind != psiconv_border_solid) &&
120 ((*result)->kind != psiconv_border_double) && 171 ((*result)->kind != psiconv_border_double) &&
121 ((*result)->thickness != 0.0) && 172 ((*result)->thickness != 0.0) &&
122 (fabs((*result)->thickness - 1/20) >= 1/1000)) { 173 (fabs((*result)->thickness - 1/20) >= 1/1000)) {
123 psiconv_warn(lev+2,off, 174 psiconv_warn(lev+2,off,
124 "Border thickness specified for unlikely border type"); 175 "Border thickness specified for unlikely border type");
125 res = -1;
126 } 176 }
177#endif
127 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness); 178 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness);
128 len += leng; 179 len += leng;
129 180
130 psiconv_progress(lev+2,off+len,"Going to read the border color"); 181 psiconv_progress(lev+2,off+len,"Going to read the border color");
131 res |= psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color); 182 if ((psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
183 goto ERROR2;
132 len += leng; 184 len += leng;
133 185
134 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte " 186 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte "
135 "(0x01 expected)"); 187 "(0x00 or 0x01 expected)");
136 temp = psiconv_read_u8(buf,lev+2,off + len); 188 temp = psiconv_read_u8(buf,lev+2,off + len,&res);
137 if (temp != 0x01) { 189 if (res)
190 goto ERROR3;
191 if ((temp != 0x01) && (temp != 0x00)) {
138 psiconv_warn(lev+2,off,"Unknown last byte in border specification"); 192 psiconv_warn(lev+2,off,"Unknown last byte in border specification");
139 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x", 193 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x or %02x",
140 temp,0x01); 194 temp,0x00,0x01);
141 res = -1;
142 } 195 }
143 len ++; 196 len ++;
144 197
145 if (length) 198 if (length)
146 *length = len; 199 *length = len;
147 200
148 psiconv_progress(lev+1,off + len - 1, 201 psiconv_progress(lev+1,off + len - 1,
149 "End of border (total length: %08x)",len); 202 "End of border (total length: %08x)",len);
150 203
204 return 0;
205
206ERROR3:
207 psiconv_free_color((*result)->color);
208ERROR2:
209 free (result);
210ERROR1:
211 psiconv_warn(lev+1,off,"Reading of Border failed");
212 if (length)
213 *length = 0;
214 if (!res)
215 return -PSICONV_E_NOMEM;
216 else
151 return res; 217 return res;
152} 218}
153 219
154int psiconv_parse_bullet(const psiconv_buffer buf,int lev,psiconv_u32 off, 220int psiconv_parse_bullet(const psiconv_buffer buf,int lev,psiconv_u32 off,
155 int *length, psiconv_bullet *result) 221 int *length, psiconv_bullet *result)
156{ 222{
157 int res = 0; 223 int res = 0;
158 int len = 0; 224 int len = 0;
159 int leng; 225 int leng;
160 int bullet_length; 226 int bullet_length;
161 227
162 *result = malloc(sizeof(**result)); 228 if (!(*result = malloc(sizeof(**result))))
229 goto ERROR1;
163 (*result)->on = psiconv_bool_true; 230 (*result)->on = psiconv_bool_true;
164 231
165 psiconv_progress(lev+1,off,"Going to parse bullet data"); 232 psiconv_progress(lev+1,off,"Going to parse bullet data");
166 psiconv_progress(lev+2,off+len,"Going to read bullet length"); 233 psiconv_progress(lev+2,off+len,"Going to read bullet length");
167 bullet_length = psiconv_read_u8(buf,lev+2,off+len); 234 bullet_length = psiconv_read_u8(buf,lev+2,off+len,&res);
235 if (res)
236 goto ERROR2;
168 psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length); 237 psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length);
169 len ++; 238 len ++;
170 239
171 psiconv_progress(lev+2,off+len,"Going to read bullet font size"); 240 psiconv_progress(lev+2,off+len,"Going to read bullet font size");
172 (*result)->font_size = psiconv_read_size(buf,lev+2,off+len, &leng); 241 (*result)->font_size = psiconv_read_size(buf,lev+2,off+len, &leng,&res);
242 if (res)
243 goto ERROR2;
173 len +=leng; 244 len +=leng;
174 245
175 psiconv_progress(lev+2,off+len,"Going to read bullet character"); 246 psiconv_progress(lev+2,off+len,"Going to read bullet character");
176 (*result)->character = psiconv_read_u8(buf,lev+2,off+len); 247 (*result)->character = psiconv_read_u8(buf,lev+2,off+len,&res);
248 if (res)
249 goto ERROR2;
177 psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character); 250 psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character);
178 len ++; 251 len ++;
179 252
180 psiconv_progress(lev+2,off+len,"Going to read indent on/off"); 253 psiconv_progress(lev+2,off+len,"Going to read indent on/off");
181 res |= psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->indent); 254 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->indent)))
255 goto ERROR2;
182 psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent); 256 psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent);
183 len += leng; 257 len += leng;
184 258
185 psiconv_progress(lev+2,off+len,"Going to read bullet color"); 259 psiconv_progress(lev+2,off+len,"Going to read bullet color");
186 res |= psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color); 260 if ((res = psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
261 goto ERROR2;
187 len += leng; 262 len += leng;
188 263
189 psiconv_progress(lev+2,off+len,"Going to read bullet font"); 264 psiconv_progress(lev+2,off+len,"Going to read bullet font");
190 res |= psiconv_parse_font(buf,lev+2,off+len,&leng,&(*result)->font); 265 if ((res = psiconv_parse_font(buf,lev+2,off+len,&leng,&(*result)->font)))
266 goto ERROR3;
191 len += leng; 267 len += leng;
192 268
193 if (len != bullet_length + 1) { 269 if (len != bullet_length + 1) {
194 psiconv_warn(lev+2,off,"Bullet data structure length mismatch"); 270 psiconv_warn(lev+2,off,"Bullet data structure length mismatch");
195 psiconv_debug(lev+2,off,"Length: specified %02x, found %02x", 271 psiconv_debug(lev+2,off,"Length: specified %02x, found %02x",
196 bullet_length,len-1); 272 bullet_length,len-1);
197 res = -1;
198 } 273 }
199 274
200 psiconv_progress(lev+1,off + len - 1, 275 psiconv_progress(lev+1,off + len - 1,
201 "End of bullet data (total length: %08x)",len); 276 "End of bullet data (total length: %08x)",len);
202 277
203 if (length) 278 if (length)
204 *length = len; 279 *length = len;
280 return 0;
281
282ERROR3:
283 psiconv_free_color((*result)->color);
284ERROR2:
285 free (result);
286ERROR1:
287 psiconv_warn(lev+1,off,"Reading of Bullet failed");
288 if (length)
289 *length = 0;
290 if (!res)
291 return -PSICONV_E_NOMEM;
292 else
205 return res; 293 return res;
206} 294}
207 295
208int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off, 296int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off,
209 int *length, psiconv_tab *result) 297 int *length, psiconv_tab *result)
210{ 298{
212 int len = 0; 300 int len = 0;
213 int leng; 301 int leng;
214 psiconv_u8 temp; 302 psiconv_u8 temp;
215 303
216 psiconv_progress(lev+1,off,"Going to parse tab"); 304 psiconv_progress(lev+1,off,"Going to parse tab");
217 *result = malloc(sizeof(**result)); 305 if (!(*result = malloc(sizeof(**result))))
306 goto ERROR1;
218 307
219 psiconv_progress(lev+2,off,"Going to read tab location"); 308 psiconv_progress(lev+2,off,"Going to read tab location");
220 (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng); 309 (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
310 if (res)
311 goto ERROR2;
221 len += leng; 312 len += leng;
222 313
223 psiconv_progress(lev+2,off+len,"Going to read the tab kind"); 314 psiconv_progress(lev+2,off+len,"Going to read the tab kind");
224 temp = psiconv_read_u8(buf,lev+2,off+len); 315 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
316 if (res)
317 goto ERROR2;
225 if (temp == 1) 318 if (temp == 1)
226 (*result)->kind = psiconv_tab_left; 319 (*result)->kind = psiconv_tab_left;
227 else if (temp == 2) 320 else if (temp == 2)
228 (*result)->kind = psiconv_tab_centre; 321 (*result)->kind = psiconv_tab_centre;
229 else if (temp == 3) 322 else if (temp == 3)
230 (*result)->kind = psiconv_tab_right; 323 (*result)->kind = psiconv_tab_right;
231 else { 324 else {
232 res = -1;
233 psiconv_warn(lev+2,off+len,"Unknown tab kind argument"); 325 psiconv_warn(lev+2,off+len,"Unknown tab kind argument");
234 psiconv_debug(lev+2,off+len,"Kind found: %02x (defaulted to left tab)", 326 psiconv_debug(lev+2,off+len,"Kind found: %02x (defaulted to left tab)",
235 temp); 327 temp);
236 (*result)->kind = psiconv_tab_left; 328 (*result)->kind = psiconv_tab_left;
237 } 329 }
240 332
241 if (length) 333 if (length)
242 *length = len; 334 *length = len;
243 335
244 psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len); 336 psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len);
245 return res; 337 return 0;
246 338
339ERROR2:
340 free (result);
341ERROR1:
342 psiconv_warn(lev+1,off,"Reading of Tab failed");
343 if (length)
344 *length = 0;
345 if (!res)
346 return -PSICONV_E_NOMEM;
347 else
348 return res;
247} 349}
248 350
249int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev, 351int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev,
250 psiconv_u32 off, int *length, 352 psiconv_u32 off, int *length,
251 psiconv_paragraph_layout result) 353 psiconv_paragraph_layout result)
253 int res=0; 355 int res=0;
254 int len=0; 356 int len=0;
255 int list_length,leng,nr; 357 int list_length,leng,nr;
256 psiconv_u8 id; 358 psiconv_u8 id;
257 psiconv_u32 temp; 359 psiconv_u32 temp;
258 psiconv_tab tab; 360 psiconv_tab temp_tab;
361 psiconv_color temp_color;
362 psiconv_border temp_border;
363 psiconv_bullet temp_bullet;
259 364
260 psiconv_progress(lev+1,off,"Going to read paragraph layout list"); 365 psiconv_progress(lev+1,off,"Going to read paragraph layout list");
261 366
262 psiconv_progress(lev+2,off,"Going to read the list length"); 367 psiconv_progress(lev+2,off,"Going to read the list length");
263 list_length = psiconv_read_u32(buf,lev+2,off + len); 368 list_length = psiconv_read_u32(buf,lev+2,off + len,&res);
369 if (res)
370 goto ERROR1;
264 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); 371 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length);
265 len += 4; 372 len += 4;
266 373
267 nr = 0; 374 nr = 0;
268 while(len - 4 < list_length) { 375 while(len - 4 < list_length) {
269 psiconv_progress(lev+2,off+len,"Going to read element %d",nr); 376 psiconv_progress(lev+2,off+len,"Going to read element %d",nr);
270 psiconv_progress(lev+3,off+len,"Going to read the element id"); 377 psiconv_progress(lev+3,off+len,"Going to read the element id");
271 id = psiconv_read_u8(buf,lev+2,off+len); 378 id = psiconv_read_u8(buf,lev+2,off+len,&res);
379 if (res)
380 goto ERROR1;
272 psiconv_debug(lev+3,off+len,"Id: %02x",id); 381 psiconv_debug(lev+3,off+len,"Id: %02x",id);
273 len ++; 382 len ++;
274 switch(id) { 383 switch(id) {
275 case 0x01: 384 case 0x01:
276 psiconv_progress(lev+3,off+len,"Going to read background color"); 385 psiconv_progress(lev+3,off+len,"Going to read background color");
386 if ((res = psiconv_parse_color(buf,lev+3,off+len,&leng,&temp_color)))
387 goto ERROR1;
277 psiconv_free_color(result->back_color); 388 psiconv_free_color(result->back_color);
278 res |= psiconv_parse_color(buf,lev+3,off+len,&leng, 389 result->back_color = temp_color;
279 &result->back_color);
280 len += leng; 390 len += leng;
281 break; 391 break;
282 case 0x02: 392 case 0x02:
283 psiconv_progress(lev+3,off+len ,"Going to read indent left"); 393 psiconv_progress(lev+3,off+len ,"Going to read indent left");
284 result->indent_left = psiconv_read_length(buf,lev+3,off+len,&leng); 394 result->indent_left = psiconv_read_length(buf,lev+3,off+len,&leng,&res);
395 if (res)
396 goto ERROR1;
285 len += leng; 397 len += leng;
286 break; 398 break;
287 case 0x03: 399 case 0x03:
288 psiconv_progress(lev+3,off+len,"Going to read indent right"); 400 psiconv_progress(lev+3,off+len,"Going to read indent right");
289 result->indent_right = psiconv_read_length(buf,lev+2,off+len,&leng); 401 result->indent_right = psiconv_read_length(buf,lev+2,off+len,&leng,
402 &res);
403 if (res)
404 goto ERROR1;
290 len += leng; 405 len += leng;
291 break; 406 break;
292 case 0x04: 407 case 0x04:
293 psiconv_progress(lev+3,off+len,"Going to read indent left first line"); 408 psiconv_progress(lev+3,off+len,"Going to read indent left first line");
294 result->indent_first = psiconv_read_length(buf,lev+2,off+len, &leng); 409 result->indent_first = psiconv_read_length(buf,lev+2,off+len, &leng,
410 &res);
411 if (res)
412 goto ERROR1;
295 len += leng; 413 len += leng;
296 break; 414 break;
297 case 0x05: 415 case 0x05:
298 psiconv_progress(lev+3,off+len,"Going to read horizontal justify"); 416 psiconv_progress(lev+3,off+len,"Going to read horizontal justify");
299 temp = psiconv_read_u8(buf,lev+3,off+len); 417 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
418 if (res)
419 goto ERROR1;
300 if (temp == 0x00) 420 if (temp == 0x00)
301 result->justify_hor = psiconv_justify_left; 421 result->justify_hor = psiconv_justify_left;
302 else if (temp == 0x01) 422 else if (temp == 0x01)
303 result->justify_hor = psiconv_justify_centre; 423 result->justify_hor = psiconv_justify_centre;
304 else if (temp == 0x02) 424 else if (temp == 0x02)
305 result->justify_hor = psiconv_justify_right; 425 result->justify_hor = psiconv_justify_right;
306 else if (temp == 0x03) 426 else if (temp == 0x03)
307 result->justify_hor = psiconv_justify_full; 427 result->justify_hor = psiconv_justify_full;
308 else { 428 else {
309 res = -1;
310 psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument " 429 psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument "
311 "in paragraph layout codes list"); 430 "in paragraph layout codes list");
431 result->justify_hor = psiconv_justify_left;
312 } 432 }
313 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 433 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
314 len ++; 434 len ++;
315 break; 435 break;
316 case 0x06: 436 case 0x06:
317 psiconv_progress(lev+3,off+len,"Going to read vertical justify"); 437 psiconv_progress(lev+3,off+len,"Going to read vertical justify");
318 temp = psiconv_read_u8(buf,lev+3,off+len); 438 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
439 if (res)
440 goto ERROR1;
319 if (temp == 0x00) 441 if (temp == 0x00)
320 result->justify_ver = psiconv_justify_top; 442 result->justify_ver = psiconv_justify_top;
321 else if (temp == 0x01) 443 else if (temp == 0x01)
322 result->justify_ver = psiconv_justify_middle; 444 result->justify_ver = psiconv_justify_middle;
323 else if (temp == 0x02) 445 else if (temp == 0x02)
324 result->justify_ver = psiconv_justify_bottom; 446 result->justify_ver = psiconv_justify_bottom;
325 else { 447 else {
326 res = -1;
327 psiconv_warn(lev+3,off+len, "Unknown vertical justify argument " 448 psiconv_warn(lev+3,off+len, "Unknown vertical justify argument "
328 "in paragraph layout codes list"); 449 "in paragraph layout codes list");
450 result->justify_ver = psiconv_justify_bottom;
329 } 451 }
330 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 452 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
331 len ++; 453 len ++;
332 case 0x07: 454 case 0x07:
333 psiconv_progress(lev+3,off+len,"Going to read interline distance"); 455 psiconv_progress(lev+3,off+len,"Going to read linespacing distance");
334 result->interline = psiconv_read_size(buf,lev+3,off+len,&leng); 456 result->linespacing = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
457 if (res)
458 goto ERROR1;
335 len += leng; 459 len += leng;
336 break; 460 break;
337 case 0x08: 461 case 0x08:
338 psiconv_progress(lev+3,off+len,"Going to read interline exact"); 462 psiconv_progress(lev+3,off+len,"Going to read linespacing exact");
339 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 463 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
340 &result->interline_exact); 464 &result->linespacing_exact)))
465 goto ERROR1;
341 len += leng; 466 len += leng;
342 break; 467 break;
343 case 0x09: 468 case 0x09:
344 psiconv_progress(lev+3,off+len,"Going to read top space"); 469 psiconv_progress(lev+3,off+len,"Going to read top space");
345 result->top_space = psiconv_read_size(buf,lev+3,off+len,&leng); 470 result->space_above = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
471 if (res)
472 goto ERROR1;
346 len += leng; 473 len += leng;
347 break; 474 break;
348 case 0x0a: 475 case 0x0a:
349 psiconv_progress(lev+3,off+len,"Going to read bottom space"); 476 psiconv_progress(lev+3,off+len,"Going to read bottom space");
350 result->bottom_space = psiconv_read_size(buf,lev+3,off+len,&leng); 477 result->space_below = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
478 if (res)
479 goto ERROR1;
351 len += leng; 480 len += leng;
352 break; 481 break;
353 case 0x0b: 482 case 0x0b:
354 psiconv_progress(lev+3,off+len,"Going to read on one page"); 483 psiconv_progress(lev+3,off+len,"Going to read on one page");
355 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 484 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
356 &result->on_one_page); 485 &result->keep_together)))
486 goto ERROR1;
357 len += leng; 487 len += leng;
358 break; 488 break;
359 case 0x0c: 489 case 0x0c:
360 psiconv_progress(lev+3,off+len,"Going to read together with"); 490 psiconv_progress(lev+3,off+len,"Going to read together with");
361 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 491 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
362 &result->together_with); 492 &result->keep_with_next)))
493 goto ERROR1;
363 len += leng; 494 len += leng;
364 break; 495 break;
365 case 0x0d: 496 case 0x0d:
366 psiconv_progress(lev+3,off+len,"Going to read on next page"); 497 psiconv_progress(lev+3,off+len,"Going to read on next page");
367 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 498 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
368 &result->on_next_page); 499 &result->on_next_page)))
500 goto ERROR1;
369 len += leng; 501 len += leng;
370 break; 502 break;
371 case 0x0e: 503 case 0x0e:
372 psiconv_progress(lev+3,off+len,"Going to read no widow protection"); 504 psiconv_progress(lev+3,off+len,"Going to read no widow protection");
373 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 505 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
374 &result->no_widow_protection); 506 &result->no_widow_protection)))
507 goto ERROR1;
375 len += leng; 508 len += leng;
376 break; 509 break;
377 case 0x10: 510 case 0x10:
378 psiconv_progress(lev+3,off+len,"Going to read border distance to text"); 511 psiconv_progress(lev+3,off+len,"Going to read border distance to text");
379 result->border_distance = psiconv_read_length(buf,lev+3, 512 result->border_distance = psiconv_read_length(buf,lev+3,
380 off+len,&leng); 513 off+len,&leng,&res);
514 if (res)
515 goto ERROR1;
381 len += leng; 516 len += leng;
382 break; 517 break;
383 case 0x11: 518 case 0x11:
384 psiconv_progress(lev+3,off+len,"Going to read top border"); 519 psiconv_progress(lev+3,off+len,"Going to read top border");
520 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
521 goto ERROR1;
385 psiconv_free_border(result->top_border); 522 psiconv_free_border(result->top_border);
386 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 523 result->top_border = temp_border;
387 &result->top_border);
388 len += leng; 524 len += leng;
389 break; 525 break;
390 case 0x12: 526 case 0x12:
391 psiconv_progress(lev+3,off+len,"Going to read bottom border"); 527 psiconv_progress(lev+3,off+len,"Going to read bottom border");
528 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
529 goto ERROR1;
392 psiconv_free_border(result->bottom_border); 530 psiconv_free_border(result->bottom_border);
393 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 531 result->bottom_border = temp_border;
394 &result->bottom_border);
395 len += leng; 532 len += leng;
396 break; 533 break;
397 case 0x13: 534 case 0x13:
398 psiconv_progress(lev+3,off+len,"Going to read left border"); 535 psiconv_progress(lev+3,off+len,"Going to read left border");
536 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
537 goto ERROR1;
399 psiconv_free_border(result->left_border); 538 psiconv_free_border(result->left_border);
400 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 539 result->left_border = temp_border;
401 &result->left_border);
402 len += leng; 540 len += leng;
403 break; 541 break;
404 case 0x14: 542 case 0x14:
405 psiconv_progress(lev+3,off+len,"Going to read right border"); 543 psiconv_progress(lev+3,off+len,"Going to read right border");
544 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
545 goto ERROR1;
406 psiconv_free_border(result->right_border); 546 psiconv_free_border(result->right_border);
407 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 547 result->right_border = temp_border;
408 &result->right_border);
409 len += leng; 548 len += leng;
410 break; 549 break;
411 case 0x15: 550 case 0x15:
412 psiconv_progress(lev+3,off+len,"Going to read bullet"); 551 psiconv_progress(lev+3,off+len,"Going to read bullet");
552 if ((res = psiconv_parse_bullet(buf,lev+3,off+len,&leng,&temp_bullet)))
553 goto ERROR1;
413 psiconv_free_bullet(result->bullet); 554 psiconv_free_bullet(result->bullet);
414 res |= psiconv_parse_bullet(buf,lev+3,off+len,&leng, 555 result->bullet = temp_bullet;
415 &result->bullet);
416 len += leng; 556 len += leng;
417 break; 557 break;
418 case 0x16: 558 case 0x16:
419 psiconv_progress(lev+3,off+len,"Going to read standard tabs"); 559 psiconv_progress(lev+3,off+len,"Going to read standard tabs");
420 result->tabs->normal = psiconv_read_length(buf,lev+3,off+len,&leng); 560 result->tabs->normal = psiconv_read_length(buf,lev+3,off+len,&leng,
561 &res);
562 if (res)
563 goto ERROR1;
421 len += leng; 564 len += leng;
422 break; 565 break;
423 case 0x17: 566 case 0x17:
424 psiconv_progress(lev+3,off+len,"Going to read extra tab"); 567 psiconv_progress(lev+3,off+len,"Going to read extra tab");
425 res |= psiconv_parse_tab(buf,lev+3,off+len,&leng,&tab); 568 if ((res = psiconv_parse_tab(buf,lev+3,off+len,&leng,&temp_tab)))
569 goto ERROR1;
426 psiconv_list_add(result->tabs->extras,tab); 570 if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) {
571 psiconv_free_tab(temp_tab);
572 goto ERROR1;
573 }
427 len += leng; 574 len += leng;
428 break; 575 break;
429 default: 576 default:
430 psiconv_warn(lev+3,off+len, 577 psiconv_warn(lev+3,off+len,
431 "Unknown code in paragraph layout codes list"); 578 "Unknown code in paragraph layout codes list");
432 psiconv_debug(lev+3,off+len,"Code: %02x",id); 579 psiconv_debug(lev+3,off+len,"Code: %02x",id);
433 len ++; 580 len ++;
434 res = -1;
435 break; 581 break;
436 } 582 }
437 nr ++; 583 nr ++;
438 } 584 }
439 585
441 psiconv_warn(lev+2,off+len, 587 psiconv_warn(lev+2,off+len,
442 "Read past end of paragraph layout codes list. I probably lost track" 588 "Read past end of paragraph layout codes list. I probably lost track"
443 "somewhere!"); 589 "somewhere!");
444 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", 590 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d",
445 len-4,list_length); 591 len-4,list_length);
592 res = PSICONV_E_PARSE;
593 goto ERROR1;
446 } 594 }
447 595
448 len = list_length + 4; 596 len = list_length + 4;
449 597
450 psiconv_progress(lev+1,off+len, 598 psiconv_progress(lev+1,off+len,
451 "End of paragraph layout list (total length: %08x)",len); 599 "End of paragraph layout list (total length: %08x)",len);
452 600
453 if (length) 601 if (length)
454 *length = len; 602 *length = len;
603 return 0;
604
605ERROR1:
606 psiconv_warn(lev+1,off,"Reading of paragraph_layout_list failed");
607 if (length)
608 *length = 0;
609 if (!res)
610 return -PSICONV_E_NOMEM;
611 else
455 return res; 612 return res;
456} 613}
457 614
458int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev, 615int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev,
459 psiconv_u32 off, int *length, 616 psiconv_u32 off, int *length,
460 psiconv_character_layout result) 617 psiconv_character_layout result)
462 int res=0; 619 int res=0;
463 int len=0; 620 int len=0;
464 int list_length,leng,nr; 621 int list_length,leng,nr;
465 psiconv_u8 id; 622 psiconv_u8 id;
466 psiconv_u32 temp; 623 psiconv_u32 temp;
624 psiconv_color temp_color;
625 psiconv_font temp_font;
467 626
468 psiconv_progress(lev+1,off,"Going to read character layout codes"); 627 psiconv_progress(lev+1,off,"Going to read character layout codes");
469 628
470 psiconv_progress(lev+2,off,"Going to read the list length"); 629 psiconv_progress(lev+2,off,"Going to read the list length");
471 list_length = psiconv_read_u32(buf,lev+2,off + len); 630 list_length = psiconv_read_u32(buf,lev+2,off + len,&res);
631 if (res)
632 goto ERROR1;
472 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); 633 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length);
473 len += 4; 634 len += 4;
474 635
475 nr = 0; 636 nr = 0;
476 while(len-4 < list_length) { 637 while(len-4 < list_length) {
477 psiconv_progress(lev+2,off+len,"Going to read element %d",nr); 638 psiconv_progress(lev+2,off+len,"Going to read element %d",nr);
478 psiconv_progress(lev+3,off+len,"Going to read the element id"); 639 psiconv_progress(lev+3,off+len,"Going to read the element id");
479 id = psiconv_read_u8(buf,lev+2,off+len); 640 id = psiconv_read_u8(buf,lev+2,off+len,&res);
641 if (res)
642 goto ERROR1;
480 psiconv_debug(lev+3,off+len,"Id: %02x",id); 643 psiconv_debug(lev+3,off+len,"Id: %02x",id);
481 len ++; 644 len ++;
482 switch(id) { 645 switch(id) {
483 case 0x19: 646 case 0x19:
484 psiconv_progress(lev+3,off+len,"Going to read text color"); 647 psiconv_progress(lev+3,off+len,"Going to read text color");
648 if ((res = psiconv_parse_color(buf,lev+3,off+len, &leng,&temp_color)))
649 goto ERROR1;
485 psiconv_free_color(result->color); 650 psiconv_free_color(result->color);
486 res |= psiconv_parse_color(buf,lev+3,off+len, &leng,&result->color); 651 result->color = temp_color;
487 len += leng; 652 len += leng;
488 break; 653 break;
489 case 0x1a: 654 case 0x1a:
490 psiconv_progress(lev+3,off+len,"Going to read background color (?)"); 655 psiconv_progress(lev+3,off+len,"Going to read background color (?)");
656 if ((res = psiconv_parse_color(buf,lev+2,off+len, &leng,&temp_color)))
657 goto ERROR1;
491 psiconv_free_color(result->back_color); 658 psiconv_free_color(result->back_color);
492 res |= psiconv_parse_color(buf,lev+2,off+len, &leng, 659 result->back_color = temp_color;
493 &result->back_color);
494 len += leng; 660 len += leng;
495 break; 661 break;
496 case 0x1c: 662 case 0x1c:
497 psiconv_progress(lev+3,off+len,"Going to read font size"); 663 psiconv_progress(lev+3,off+len,"Going to read font size");
498 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng); 664 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
665 if (res)
666 goto ERROR1;
499 len += leng; 667 len += leng;
500 break; 668 break;
501 case 0x1d: 669 case 0x1d:
502 psiconv_progress(lev+3,off+len,"Going to read italic"); 670 psiconv_progress(lev+3,off+len,"Going to read italic");
503 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic); 671 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic)))
672 goto ERROR1;
504 len += leng; 673 len += leng;
505 break; 674 break;
506 case 0x1e: 675 case 0x1e:
507 psiconv_progress(lev+3,off+len,"Going to read bold"); 676 psiconv_progress(lev+3,off+len,"Going to read bold");
508 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold); 677 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold)))
678 goto ERROR1;
509 len += leng; 679 len += leng;
510 break; 680 break;
511 case 0x1f: 681 case 0x1f:
512 psiconv_progress(lev+3,off+len,"Going to read super_sub"); 682 psiconv_progress(lev+3,off+len,"Going to read super_sub");
513 temp = psiconv_read_u8(buf,lev+3,off+len); 683 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
684 if (res)
685 goto ERROR1;
514 if (temp == 0x00) 686 if (temp == 0x00)
515 result->super_sub = psiconv_normalscript; 687 result->super_sub = psiconv_normalscript;
516 else if (temp == 0x01) 688 else if (temp == 0x01)
517 result->super_sub = psiconv_superscript; 689 result->super_sub = psiconv_superscript;
518 else if (temp == 0x02) 690 else if (temp == 0x02)
519 result->super_sub = psiconv_subscript; 691 result->super_sub = psiconv_subscript;
520 else { 692 else {
521 psiconv_warn(lev+3,off+len, 693 psiconv_warn(lev+3,off+len,
522 "Unknown super_sub argument in character layout codes list"); 694 "Unknown super_sub argument in character layout codes list");
523 res = -1;
524 } 695 }
525 psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp); 696 psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp);
526 len ++; 697 len ++;
527 break; 698 break;
528 case 0x20: 699 case 0x20:
529 psiconv_progress(lev+3,off+len,"Going to read underline"); 700 psiconv_progress(lev+3,off+len,"Going to read underline");
530 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->underline); 701 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
702 &result->underline)))
703 goto ERROR1;
531 len += leng; 704 len += leng;
532 break; 705 break;
533 case 0x21: 706 case 0x21:
534 psiconv_progress(lev+3,off+len,"Going to read strike_out"); 707 psiconv_progress(lev+3,off+len,"Going to read strikethrough");
535 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->strike_out); 708 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
709 &result->strikethrough)))
710 goto ERROR1;
536 len += leng; 711 len += leng;
537 break; 712 break;
538 case 0x22: 713 case 0x22:
539 psiconv_progress(lev+3,off+len,"Going to read font"); 714 psiconv_progress(lev+3,off+len,"Going to read font");
715 if ((res = psiconv_parse_font(buf,lev+3,off+len, &leng, &temp_font)))
716 goto ERROR1;
540 psiconv_free_font(result->font); 717 psiconv_free_font(result->font);
541 res |= psiconv_parse_font(buf,lev+3,off+len, &leng, &result->font); 718 result->font = temp_font;
542 len += leng; 719 len += leng;
543 break; 720 break;
544 case 0x24: 721 case 0x24:
545 psiconv_progress(lev+3,off+len, 722 psiconv_progress(lev+3,off+len,
546 "Going to read unknown code 0x24 (%02x expected)", 0); 723 "Going to read unknown code 0x24 (%02x expected)", 0);
547 temp = psiconv_read_u8(buf,lev+3,off+len); 724 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
725 if (res)
726 goto ERROR1;
548 if (temp != 0) { 727 if (temp != 0) {
549 psiconv_warn(lev+3,off+len, 728 psiconv_warn(lev+3,off+len,
550 "Unknown code 0x24 value != 0x0 (0x%02x)", temp); 729 "Unknown code 0x24 value != 0x0 (0x%02x)", temp);
551 } 730 }
552 len ++; 731 len ++;
553 break; 732 break;
554 default: 733 default:
555 psiconv_warn(lev+3,off+len,"Unknown code in character layout list"); 734 psiconv_warn(lev+3,off+len,"Unknown code in character layout list");
556 psiconv_debug(lev+3,off+len,"Code: %02x",id); 735 psiconv_debug(lev+3,off+len,"Code: %02x",id);
557 len ++; 736 len ++;
558 res = -1;
559 break; 737 break;
560 } 738 }
561 nr ++; 739 nr ++;
562 } 740 }
563 741
565 psiconv_warn(lev+2,off+len, 743 psiconv_warn(lev+2,off+len,
566 "Read past end of character layout codes list. I probably lost track" 744 "Read past end of character layout codes list. I probably lost track"
567 "somewhere!"); 745 "somewhere!");
568 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", 746 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d",
569 len-4,list_length); 747 len-4,list_length);
748 res = PSICONV_E_PARSE;
749 goto ERROR1;
570 } 750 }
571 751
572 len = list_length + 4; 752 len = list_length + 4;
573 753
574 psiconv_progress(lev+1,off+len, 754 psiconv_progress(lev+1,off+len,
575 "End of character layout list (total length: %08x)",len); 755 "End of character layout list (total length: %08x)",len);
576 756
577 if (length) 757 if (length)
578 *length = len; 758 *length = len;
579 return res; 759 return res;
760
761ERROR1:
762 psiconv_warn(lev+1,off,"Reading of character_layout_list failed");
763 if (length)
764 *length = 0;
765 if (!res)
766 return -PSICONV_E_NOMEM;
767 else
768 return res;
580} 769}

Legend:
Removed from v.63  
changed lines
  Added in v.84

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26