/[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 64 - (show annotations)
Fri Dec 15 00:21:51 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 8112 byte(s)
(Frodo) Massive update: theoretically, all return codes are now checked.
        Untested - may have many typos.

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

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