/[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 71 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; 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 first byte (0x01 expected)"); 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 != 0x01) { 52 if (temp == 0x00)
47 psiconv_warn(lev+2,off+len,"Page header first byte mismatch"); 53 has_content = 0;
48 psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x", 54 else if (temp == 0x01)
49 temp,0x01); 55 has_content = 1;
56 else {
57 psiconv_warn(config,lev+2,off+len,
58 "Page header has_content flag unknown value (assumed default)");
59 psiconv_debug(config,lev+2,off+len,"Flag: %02x",temp);
60 has_content = 1;
50 } 61 }
62 psiconv_debug(config,lev+2,off+len,"Has_content flag: %02x",has_content);
51 len += 1; 63 len += 1;
52 64
53 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");
54 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, 66 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,
55 &(*result)->on_first_page))) 67 &(*result)->on_first_page)))
56 goto ERROR2; 68 goto ERROR2;
57 len += leng; 69 len += leng;
58 70
59 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");
60 for (i = 0; i < 0x03; i++,len++) { 72 for (i = 0; i < 0x03; i++,len++) {
61 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 73 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
62 if (res) 74 if (res)
63 goto ERROR2; 75 goto ERROR2;
64 if (temp != 0x00) { 76 if (temp != 0x00) {
65 psiconv_warn(lev+2,off+len, 77 psiconv_warn(config,lev+2,off+len,
66 "Page Header unknown value in zero bytes section"); 78 "Page Header unknown value in zero bytes section");
67 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",
68 i,temp,0x00); 80 i,temp,0x00);
69 } 81 }
70 } 82 }
71 83
72 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");
73 if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout())) 85 if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout()))
74 goto ERROR2; 86 goto ERROR2;
87
88 if (has_content) {
75 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,
76 (*result)->base_paragraph_layout))) 90 (*result)->base_paragraph_layout)))
77 goto ERROR3; 91 goto ERROR3;
78 len += leng; 92 len += leng;
93 }
79 94
80 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");
81 if (!((*result)->base_character_layout = psiconv_basic_character_layout())) 96 if (!((*result)->base_character_layout = psiconv_basic_character_layout()))
82 goto ERROR3; 97 goto ERROR3;
98 if (has_content) {
83 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,
84 (*result)->base_character_layout))) 100 (*result)->base_character_layout)))
85 goto ERROR4; 101 goto ERROR4;
102 }
86 len += leng; 103 len += leng;
87 104
88 105
89 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");
107 if (has_content) {
90 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,
91 &(*result)->text, 109 &(*result)->text,
92 (*result)->base_character_layout, 110 (*result)->base_character_layout,
93 (*result)->base_paragraph_layout))) 111 (*result)->base_paragraph_layout)))
94 goto ERROR4; 112 goto ERROR4;
95 len += leng; 113 len += leng;
114 } else {
115 (*result)->text = NULL;
116 }
96 117
97 if (length) 118 if (length)
98 *length = len; 119 *length = len;
99 120
100 psiconv_progress(lev+1,off+len-1,"End of page header" 121 psiconv_progress(config,lev+1,off+len-1,"End of page header"
101 "(total length: %08x", len); 122 "(total length: %08x", len);
102 123
103 return res; 124 return res;
104 125
105ERROR4: 126ERROR4:
107ERROR3: 128ERROR3:
108 psiconv_free_paragraph_layout((*result)->base_paragraph_layout); 129 psiconv_free_paragraph_layout((*result)->base_paragraph_layout);
109ERROR2: 130ERROR2:
110 free (*result); 131 free (*result);
111ERROR1: 132ERROR1:
112 psiconv_warn(lev+1,off,"Reading of Page Header failed"); 133 psiconv_warn(config,lev+1,off,"Reading of Page Header failed");
113 if (length) 134 if (length)
114 *length = 0; 135 *length = 0;
115 if (!res) 136 if (!res)
116 return -PSICONV_E_NOMEM; 137 return -PSICONV_E_NOMEM;
117 else 138 else
118 return res; 139 return res;
119} 140}
120 141
121int 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,
122 psiconv_u32 off, int *length, 144 psiconv_u32 off, int *length,
123 psiconv_page_layout_section *result) 145 psiconv_page_layout_section *result)
124{ 146{
125 int res = 0; 147 int res = 0;
126 int len = 0; 148 int len = 0;
127 int leng; 149 int leng;
128 psiconv_u32 temp; 150 psiconv_u32 temp;
129 151
130 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");
131 if (!(*result = malloc(sizeof(**result)))) 153 if (!(*result = malloc(sizeof(**result))))
132 goto ERROR1; 154 goto ERROR1;
133 155
134 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");
135 (*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);
136 if (res) 158 if (res)
137 goto ERROR2; 159 goto ERROR2;
138 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);
139 len += 4; 161 len += 4;
140 162
141 psiconv_progress(lev+2,off+len,"Going to read header distance"); 163 psiconv_progress(config,lev+2,off+len,"Going to read header distance");
142 (*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);
143 if (res) 165 if (res)
144 goto ERROR2; 166 goto ERROR2;
145 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);
146 len += leng; 168 len += leng;
147 169
148 psiconv_progress(lev+2,off+len,"Going to read footer distance"); 170 psiconv_progress(config,lev+2,off+len,"Going to read footer distance");
149 (*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);
150 if (res) 172 if (res)
151 goto ERROR2; 173 goto ERROR2;
152 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);
153 len += leng; 175 len += leng;
154 176
155 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");
156 (*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);
157 if (res) 179 if (res)
158 goto ERROR2; 180 goto ERROR2;
159 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);
160 len += leng; 182 len += leng;
161 183
162 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");
163 (*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);
164 if (res) 186 if (res)
165 goto ERROR2; 187 goto ERROR2;
166 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);
167 len += leng; 189 len += leng;
168 190
169 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");
170 (*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);
171 if (res) 193 if (res)
172 goto ERROR2; 194 goto ERROR2;
173 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);
174 len += leng; 196 len += leng;
175 197
176 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");
177 (*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);
178 if (res) 200 if (res)
179 goto ERROR2; 201 goto ERROR2;
180 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);
181 len += leng; 203 len += leng;
182 204
183 psiconv_progress(lev+2,off+len,"Going to read the header"); 205 psiconv_progress(config,lev+2,off+len,"Going to read the header");
184 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,
185 &(*result)->header))) 207 &(*result)->header)))
186 goto ERROR2; 208 goto ERROR2;
187 len += leng; 209 len += leng;
188 210
189 psiconv_progress(lev+2,off+len,"Going to read the footer"); 211 psiconv_progress(config,lev+2,off+len,"Going to read the footer");
190 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,
191 &(*result)->footer))) 213 &(*result)->footer)))
192 goto ERROR3; 214 goto ERROR3;
193 len += leng; 215 len += leng;
194 216
195 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");
196 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 218 temp = psiconv_read_u32(config,buf,lev+2,off+len,&res);
197 if (res) 219 if (res)
198 goto ERROR4; 220 goto ERROR4;
199 if (temp != PSICONV_ID_PAGE_DIMENSIONS) { 221 if ((temp != PSICONV_ID_PAGE_DIMENSIONS1) &&
222 (temp != PSICONV_ID_PAGE_DIMENSIONS2)) {
200 psiconv_warn(lev+2,off+len, 223 psiconv_warn(config,lev+2,off+len,
201 "Page layout section page dimensions marker not found"); 224 "Page layout section page dimensions marker not found");
202 psiconv_debug(lev+2,off+len, 225 psiconv_debug(config,lev+2,off+len,
203 "Page dimensions marker: read %08x, expected %08x",temp, 226 "Page dimensions marker: read %08x, expected %08x or %08x",
227 temp, PSICONV_ID_PAGE_DIMENSIONS1,
204 PSICONV_ID_PAGE_DIMENSIONS); 228 PSICONV_ID_PAGE_DIMENSIONS2);
205 } 229 }
206 len += 4; 230 len += 4;
207 231
208 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");
209 (*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);
210 if (res) 234 if (res)
211 goto ERROR4; 235 goto ERROR4;
212 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);
213 len += leng; 237 len += leng;
214 238
215 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");
216 (*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);
217 if (res) 241 if (res)
218 goto ERROR4; 242 goto ERROR4;
219 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);
220 len += leng; 244 len += leng;
245
246 psiconv_progress(config,lev+2,off+len,"Going to read page portrait/landscape");
247 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,&(*result)->landscape)))
248 goto ERROR4;
249 psiconv_debug(config,lev+2,off+len,"Landscape: %d",(*result)->landscape);
250 len += leng;
251
221 252
222 if (length) 253 if (length)
223 *length = len; 254 *length = len;
224 255
225 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)",
226 len); 257 len);
227 258
228 return res; 259 return res;
229 260
230ERROR4: 261ERROR4:
232ERROR3: 263ERROR3:
233 psiconv_free_page_header((*result)->header); 264 psiconv_free_page_header((*result)->header);
234ERROR2: 265ERROR2:
235 free (*result); 266 free (*result);
236ERROR1: 267ERROR1:
237 psiconv_warn(lev+1,off,"Reading of Page Section failed"); 268 psiconv_warn(config,lev+1,off,"Reading of Page Section failed");
238 if (length) 269 if (length)
239 *length = 0; 270 *length = 0;
240 if (!res) 271 if (!res)
241 return -PSICONV_E_NOMEM; 272 return -PSICONV_E_NOMEM;
242 else 273 else

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

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