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

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

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

Revision 2 Revision 142
1/* 1/*
2 parse_texted.c - Part of psiconv, a PSION 5 file formats converter 2 parse_texted.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>
22 24
23#include "data.h"
24#include "parse_routines.h" 25#include "parse_routines.h"
26#include "error.h"
27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
25 31
26int psiconv_parse_texted_section(const psiconv_buffer buf,int lev, 32int psiconv_parse_texted_section(const psiconv_buffer buf,int lev,
27 psiconv_u32 off, int *length, 33 psiconv_u32 off, int *length,
28 psiconv_texted_section *result, 34 psiconv_texted_section *result,
29 psiconv_character_layout base_char, 35 psiconv_character_layout base_char,
36 psiconv_u32 replacement_sec = 0; 42 psiconv_u32 replacement_sec = 0;
37 psiconv_u32 temp; 43 psiconv_u32 temp;
38 int leng; 44 int leng;
39 45
40 psiconv_progress(lev+1,off,"Going to read a texted section"); 46 psiconv_progress(lev+1,off,"Going to read a texted section");
41 (*result) = malloc(sizeof(**result)); 47 if (!((*result) = malloc(sizeof(**result))))
48 goto ERROR1;
42 49
43 psiconv_progress(lev+2,off+len,"Going to read section id"); 50 psiconv_progress(lev+2,off+len,"Going to read section id");
44 temp = psiconv_read_u32(buf,lev+2,off+len); 51 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
52 if (res)
53 goto ERROR2;
45 if (temp != PSICONV_ID_TEXTED_BODY) { 54 if (temp != PSICONV_ID_TEXTED_BODY) {
46 psiconv_warn(lev+2,off+len, 55 psiconv_warn(lev+2,off+len,
47 "Page header section body id not found"); 56 "Page header section body id not found");
48 psiconv_debug(lev+2,off+len, 57 psiconv_debug(lev+2,off+len,
49 "Page body id: read %08x, expected %08x",temp, 58 "Page body id: read %08x, expected %08x",temp,
50 PSICONV_ID_TEXTED); 59 PSICONV_ID_TEXTED);
51 res = -1; 60 res = -PSICONV_E_PARSE;
61 goto ERROR2;
52 } 62 }
53 len += 4; 63 len += 4;
54 64
55 psiconv_progress(lev+2,off+len,"Going to read the section jumptable"); 65 psiconv_progress(lev+2,off+len,"Going to read the section jumptable");
56 while (temp = psiconv_read_u32(buf,lev+3,off+len), 66 while (temp = psiconv_read_u32(buf,lev+3,off+len,&res),
57 temp != PSICONV_ID_TEXTED_TEXT) { 67 !res && temp != PSICONV_ID_TEXTED_TEXT) {
58 len += 4; 68 len += 4;
59 if (temp == PSICONV_ID_TEXTED_LAYOUT) { 69 if (temp == PSICONV_ID_TEXTED_LAYOUT) {
60 layout_sec = psiconv_read_u32(buf,lev+3,off+len); 70 layout_sec = psiconv_read_u32(buf,lev+3,off+len,&res);
71 if (res)
72 goto ERROR2;
61 psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec); 73 psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec);
62 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { 74 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) {
63 replacement_sec = psiconv_read_u32(buf,lev+3,off+len); 75 replacement_sec = psiconv_read_u32(buf,lev+3,off+len,&res);
76 if (res)
77 goto ERROR2;
64 psiconv_debug(lev+3,off+len,"Found Replacement section at %08x", 78 psiconv_debug(lev+3,off+len,"Found Replacement section at %08x",
65 replacement_sec); 79 replacement_sec);
66 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { 80 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) {
67 unknown_sec= psiconv_read_u32(buf,lev+3,off+len); 81 unknown_sec= psiconv_read_u32(buf,lev+3,off+len,&res);
82 if (res)
83 goto ERROR2;
68 if (unknown_sec) { 84 if (unknown_sec) {
69 psiconv_warn(lev+3,off+len, 85 psiconv_warn(lev+3,off+len,
70 "Unknown section in TextEd jumptable has real offset"); 86 "Unknown section in TextEd jumptable has real offset (ignoring)");
71 res = -1;
72 } 87 }
73 psiconv_debug(lev+3,off+len,"Found Unknown section at %08x", 88 psiconv_debug(lev+3,off+len,"Found Unknown section at %08x",
74 unknown_sec); 89 unknown_sec);
75 } else { 90 } else {
76 psiconv_warn(lev+3,off+len,"Unknown section in TextEd jumptable"); 91 psiconv_warn(lev+3,off+len,
92 "Unknown section in TextEd jumptable (ignoring)");
77 psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp, 93 psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp,
78 psiconv_read_u32(buf,lev+3,off+len)); 94 psiconv_read_u32(buf,lev+3,off+len,NULL));
79 res = -1;
80 } 95 }
81 len += 4; 96 len += 4;
82 } 97 }
98 if (res)
99 goto ERROR2;
83 100
84 len += 4; 101 len += 4;
85 psiconv_progress(lev+2,off+len,"Going to read the text"); 102 psiconv_progress(lev+2,off+len,"Going to read the text");
86 psiconv_parse_text_section(buf,lev+2,off+len,&leng,&(*result)->paragraphs); 103 if ((res = psiconv_parse_text_section(buf,lev+2,off+len,&leng,
104 &(*result)->paragraphs)))
105 goto ERROR2;
87 len += leng; 106 len += leng;
88 107
89 if (layout_sec) { 108 if (layout_sec) {
90 psiconv_progress(lev+2,off+len,"Going to read the layout"); 109 psiconv_progress(lev+2,off+len,"Going to read the layout");
91 psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, 110 if ((res = psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL,
92 (*result)->paragraphs, 111 (*result)->paragraphs,
93 base_char,base_para); 112 base_char,base_para)))
113 goto ERROR3;
94 } 114 }
95 115
96#if 0 116#if 0
97 if (replacement_sec) { 117 if (replacement_sec) {
98 psiconv_progress(lev+2,off+len,"Going to read the replacements"); 118 psiconv_progress(lev+2,off+len,"Going to read the replacements");
104 *length = len; 124 *length = len;
105 125
106 psiconv_progress(lev+1,off+len-1,"End of TextEd section " 126 psiconv_progress(lev+1,off+len-1,"End of TextEd section "
107 "(total length: %08x", len); 127 "(total length: %08x", len);
108 128
129 return 0;
130
131ERROR3:
132 psiconv_free_text_and_layout((*result)->paragraphs);
133ERROR2:
134 free (*result);
135ERROR1:
136 psiconv_warn(lev+1,off,"Reading of TextEd Section failed");
137 if (length)
138 *length = 0;
139 if (!res)
140 return -PSICONV_E_NOMEM;
141 else
109 return res; 142 return res;
110} 143}
111 144
112 145

Legend:
Removed from v.2  
changed lines
  Added in v.142

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