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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 184 - (show annotations)
Tue Jan 6 20:15:01 2004 UTC (20 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 26452 byte(s)
(Frodo) Unicode transition

Note: this commit breaks psiconv. The programs in the extra directory should
work properly.

  * Change all datastructures to use unicode for character encodings
  * Added psiconv_error function
  * Called psiconv_error at places where a warning was stupid
  * Added psiconv_progress in all generate functions
  * Added lev parameter to all generate functions
  * Removed general.h from CVS (we have general.h.in, after all)
  * Probably other stuff I forgot

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

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