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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (show annotations)
Mon Dec 25 00:26:53 2000 UTC (18 years, 11 months ago) by frodo
File MIME type: text/plain
File size: 8511 byte(s)
(Frodo) Added word-specific generation routines

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

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