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

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

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

Revision 63 Revision 64
31 int len = 0; 31 int len = 0;
32 int i,leng; 32 int i,leng;
33 psiconv_u32 temp; 33 psiconv_u32 temp;
34 34
35 psiconv_progress(lev+1,off,"Going to read a page header (or footer)"); 35 psiconv_progress(lev+1,off,"Going to read a page header (or footer)");
36 (*result) = malloc(sizeof(**result)); 36 if (!(*result = malloc(sizeof(**result))))
37 goto ERROR1;
37 38
38 psiconv_progress(lev+2,off+len, 39 psiconv_progress(lev+2,off+len,
39 "Going to read the first byte (0x01 expected)"); 40 "Going to read the first byte (0x01 expected)");
40 temp = psiconv_read_u8(buf,lev+2,off+len); 41 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
42 if (!res)
43 goto ERROR2;
41 if (temp != 0x01) { 44 if (temp != 0x01) {
42 psiconv_warn(lev+2,off+len,"Page header first byte mismatch"); 45 psiconv_warn(lev+2,off+len,"Page header first byte mismatch");
43 psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x", 46 psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x",
44 temp,0x01); 47 temp,0x01);
45 res = -1;
46 } 48 }
47 len += 1; 49 len += 1;
48 50
49 psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag"); 51 psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag");
50 res |= psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->on_first_page); 52 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,
53 &(*result)->on_first_page)))
54 goto ERROR2;
51 len += leng; 55 len += leng;
52 56
53 psiconv_progress(lev+2,off+len,"Going to read three zero bytes"); 57 psiconv_progress(lev+2,off+len,"Going to read three zero bytes");
54 for (i = 0; i < 0x03; i++,len++) { 58 for (i = 0; i < 0x03; i++,len++) {
55 temp = psiconv_read_u8(buf,lev+2,off+len); 59 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
60 if (res)
61 goto ERROR2;
56 if (temp != 0x00) { 62 if (temp != 0x00) {
57 psiconv_warn(lev+2,off+len, 63 psiconv_warn(lev+2,off+len,
58 "Page Header unknown value in zero bytes section"); 64 "Page Header unknown value in zero bytes section");
59 psiconv_debug(lev+2,off+len,"Byte %d: read %02x, expected %02x", 65 psiconv_debug(lev+2,off+len,"Byte %d: read %02x, expected %02x",
60 i,temp,0x00); 66 i,temp,0x00);
61 res = -1;
62 } 67 }
63 } 68 }
64 69
65 psiconv_progress(lev+2,off+len,"Going to read base paragraph layout"); 70 psiconv_progress(lev+2,off+len,"Going to read base paragraph layout");
66 (*result)->base_paragraph_layout = psiconv_basic_paragraph_layout(); 71 if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout()))
72 goto ERROR2;
67 res |= psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng, 73 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng,
68 (*result)->base_paragraph_layout); 74 (*result)->base_paragraph_layout)))
75 goto ERROR3;
69 len += leng; 76 len += leng;
70 77
71 psiconv_progress(lev+2,off+len,"Going to read base character layout"); 78 psiconv_progress(lev+2,off+len,"Going to read base character layout");
72 (*result)->base_character_layout = psiconv_basic_character_layout(); 79 if (!((*result)->base_character_layout = psiconv_basic_character_layout()))
80 goto ERROR3;
73 res |= psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng, 81 if ((res = psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng,
74 (*result)->base_character_layout); 82 (*result)->base_character_layout)))
83 goto ERROR4;
75 len += leng; 84 len += leng;
76 85
77 86
78 psiconv_progress(lev+2,off+len,"Going to read the TextEd section"); 87 psiconv_progress(lev+2,off+len,"Going to read the TextEd section");
79 res |= psiconv_parse_texted_section(buf,lev+2,off+len,&leng, 88 if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng,
80 &(*result)->text, 89 &(*result)->text,
81 (*result)->base_character_layout, 90 (*result)->base_character_layout,
82 (*result)->base_paragraph_layout); 91 (*result)->base_paragraph_layout)))
92 goto ERROR4;
83 len += leng; 93 len += leng;
84 94
85 if (length) 95 if (length)
86 *length = len; 96 *length = len;
87 97
88 psiconv_progress(lev+1,off+len-1,"End of page header" 98 psiconv_progress(lev+1,off+len-1,"End of page header"
89 "(total length: %08x", len); 99 "(total length: %08x", len);
90 100
91 return res; 101 return res;
102
103ERROR4:
104 psiconv_free_character_layout((*result)->base_character_layout);
105ERROR3:
106 psiconv_free_paragraph_layout((*result)->base_paragraph_layout);
107ERROR2:
108 free (*result);
109ERROR1:
110 psiconv_warn(lev+1,off,"Reading of Page Header failed");
111 if (length)
112 *length = 0;
113 if (!res)
114 return -PSICONV_E_NOMEM;
115 else
116 return res;
92} 117}
93 118
94int psiconv_parse_page_layout_section(const psiconv_buffer buf,int lev, 119int psiconv_parse_page_layout_section(const psiconv_buffer buf,int lev,
95 psiconv_u32 off, int *length, 120 psiconv_u32 off, int *length,
96 psiconv_page_layout_section *result) 121 psiconv_page_layout_section *result)
99 int len = 0; 124 int len = 0;
100 int leng; 125 int leng;
101 psiconv_u32 temp; 126 psiconv_u32 temp;
102 127
103 psiconv_progress(lev+1,off,"Going to read the page layout section"); 128 psiconv_progress(lev+1,off,"Going to read the page layout section");
104 (*result) = malloc(sizeof(**result)); 129 if (!(*result = malloc(sizeof(**result))))
130 goto ERROR1;
105 131
106 psiconv_progress(lev+2,off+len,"Going to read first page number"); 132 psiconv_progress(lev+2,off+len,"Going to read first page number");
107 (*result)->first_page_nr = psiconv_read_u32(buf,lev+2,off+len); 133 (*result)->first_page_nr = psiconv_read_u32(buf,lev+2,off+len,&res);
134 if (res)
135 goto ERROR2;
108 psiconv_debug(lev+2,off+len,"First page: %d",(*result)->first_page_nr); 136 psiconv_debug(lev+2,off+len,"First page: %d",(*result)->first_page_nr);
109 len += 4; 137 len += 4;
110 138
111 psiconv_progress(lev+2,off+len,"Going to read header distance"); 139 psiconv_progress(lev+2,off+len,"Going to read header distance");
112 (*result)->header_dist = psiconv_read_length(buf,lev+2,off+len,&leng); 140 (*result)->header_dist = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
141 if (res)
142 goto ERROR2;
113 psiconv_debug(lev+2,off+len,"Header distance: %6.3f",(*result)->header_dist); 143 psiconv_debug(lev+2,off+len,"Header distance: %6.3f",(*result)->header_dist);
114 len += leng; 144 len += leng;
115 145
116 psiconv_progress(lev+2,off+len,"Going to read footer distance"); 146 psiconv_progress(lev+2,off+len,"Going to read footer distance");
117 (*result)->footer_dist = psiconv_read_length(buf,lev+2,off+len,&leng); 147 (*result)->footer_dist = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
148 if (res)
149 goto ERROR2;
118 psiconv_debug(lev+2,off+len,"Footer distance: %6.3f",(*result)->footer_dist); 150 psiconv_debug(lev+2,off+len,"Footer distance: %6.3f",(*result)->footer_dist);
119 len += leng; 151 len += leng;
120 152
121 psiconv_progress(lev+2,off+len,"Going to read the left margin"); 153 psiconv_progress(lev+2,off+len,"Going to read the left margin");
122 (*result)->left_margin = psiconv_read_length(buf,lev+2,off+len,&leng); 154 (*result)->left_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
155 if (res)
156 goto ERROR2;
123 psiconv_debug(lev+2,off+len,"Left margin: %6.3f",(*result)->left_margin); 157 psiconv_debug(lev+2,off+len,"Left margin: %6.3f",(*result)->left_margin);
124 len += leng; 158 len += leng;
125 159
126 psiconv_progress(lev+2,off+len,"Going read the to right margin"); 160 psiconv_progress(lev+2,off+len,"Going read the to right margin");
127 (*result)->right_margin = psiconv_read_length(buf,lev+2,off+len,&leng); 161 (*result)->right_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
162 if (res)
163 goto ERROR2;
128 psiconv_debug(lev+2,off+len,"Right margin: %6.3f",(*result)->right_margin); 164 psiconv_debug(lev+2,off+len,"Right margin: %6.3f",(*result)->right_margin);
129 len += leng; 165 len += leng;
130 166
131 psiconv_progress(lev+2,off+len,"Going to read the top margin"); 167 psiconv_progress(lev+2,off+len,"Going to read the top margin");
132 (*result)->top_margin = psiconv_read_length(buf,lev+2,off+len,&leng); 168 (*result)->top_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
169 if (res)
170 goto ERROR2;
133 psiconv_debug(lev+2,off+len,"Top margin: %6.3f",(*result)->top_margin); 171 psiconv_debug(lev+2,off+len,"Top margin: %6.3f",(*result)->top_margin);
134 len += leng; 172 len += leng;
135 173
136 psiconv_progress(lev+2,off+len,"Going to read the bottom margin"); 174 psiconv_progress(lev+2,off+len,"Going to read the bottom margin");
137 (*result)->bottom_margin = psiconv_read_length(buf,lev+2,off+len,&leng); 175 (*result)->bottom_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
176 if (res)
177 goto ERROR2;
138 psiconv_debug(lev+2,off+len,"Bottom margin: %6.3f",(*result)->bottom_margin); 178 psiconv_debug(lev+2,off+len,"Bottom margin: %6.3f",(*result)->bottom_margin);
139 len += leng; 179 len += leng;
140 180
141 psiconv_progress(lev+2,off+len,"Going to read the header"); 181 psiconv_progress(lev+2,off+len,"Going to read the header");
142 res |= psiconv_parse_page_header(buf,lev+2,off+len,&leng,&(*result)->header); 182 if ((res = psiconv_parse_page_header(buf,lev+2,off+len,&leng,
183 &(*result)->header)))
184 goto ERROR2;
143 len += leng; 185 len += leng;
144 186
145 psiconv_progress(lev+2,off+len,"Going to read the footer"); 187 psiconv_progress(lev+2,off+len,"Going to read the footer");
146 res |= psiconv_parse_page_header(buf,lev+2,off+len,&leng,&(*result)->footer); 188 if ((res = psiconv_parse_page_header(buf,lev+2,off+len,&leng,
189 &(*result)->footer)))
190 goto ERROR3;
147 len += leng; 191 len += leng;
148 192
149 psiconv_progress(lev+2,off+len,"Going to read page dimensions id"); 193 psiconv_progress(lev+2,off+len,"Going to read page dimensions id");
150 temp = psiconv_read_u32(buf,lev+2,off+len); 194 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
195 if (res)
196 goto ERROR4;
151 if (temp != PSICONV_ID_PAGE_DIMENSIONS) { 197 if (temp != PSICONV_ID_PAGE_DIMENSIONS) {
152 psiconv_warn(lev+2,off+len, 198 psiconv_warn(lev+2,off+len,
153 "Page layout section page dimensions marker not found"); 199 "Page layout section page dimensions marker not found");
154 psiconv_debug(lev+2,off+len, 200 psiconv_debug(lev+2,off+len,
155 "Page dimensions marker: read %08x, expected %08x",temp, 201 "Page dimensions marker: read %08x, expected %08x",temp,
156 PSICONV_ID_PAGE_DIMENSIONS); 202 PSICONV_ID_PAGE_DIMENSIONS);
157 res = -1;
158 } 203 }
159 204
160 psiconv_progress(lev+2,off+len,"Going to read the page width"); 205 psiconv_progress(lev+2,off+len,"Going to read the page width");
161 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng); 206 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
207 if (!res)
208 goto ERROR4;
162 psiconv_debug(lev+2,off+len,"Page width: %6.3f",(*result)->page_width); 209 psiconv_debug(lev+2,off+len,"Page width: %6.3f",(*result)->page_width);
163 len += leng; 210 len += leng;
164 211
165 psiconv_progress(lev+2,off+len,"Going to read the page height"); 212 psiconv_progress(lev+2,off+len,"Going to read the page height");
166 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng); 213 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
214 if (!res)
215 goto ERROR4;
167 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height); 216 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height);
168 len += leng; 217 len += leng;
169 218
170 if (length) 219 if (length)
171 *length = len; 220 *length = len;
172 221
173 psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)", 222 psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)",
174 len); 223 len);
175 224
176 return res; 225 return res;
226
227ERROR4:
228 psiconv_free_page_header((*result)->footer);
229ERROR3:
230 psiconv_free_page_header((*result)->header);
231ERROR2:
232 free (*result);
233ERROR1:
234 psiconv_warn(lev+1,off,"Reading of Page Section failed");
235 if (length)
236 *length = 0;
237 if (!res)
238 return -PSICONV_E_NOMEM;
239 else
240 return res;
177} 241}

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

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