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

Legend:
Removed from v.111  
changed lines
  Added in v.168

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