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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 111 - (hide annotations)
Tue Mar 6 23:59:46 2001 UTC (23 years, 1 month ago) by frodo
File MIME type: text/plain
File size: 8773 byte(s)
(Frodo) Many changes to sheets

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

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