/[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 76 - (hide annotations)
Mon Dec 25 00:26:53 2000 UTC (23 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 8511 byte(s)
(Frodo) Added word-specific generation routines

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     int i,leng;
35     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     "Going to read the first byte (0x01 expected)");
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 2 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 frodo 64 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,
55     &(*result)->on_first_page)))
56     goto ERROR2;
57 frodo 2 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 frodo 64 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
62     if (res)
63     goto ERROR2;
64 frodo 2 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 frodo 64 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 frodo 2 len += leng;
79    
80     psiconv_progress(lev+2,off+len,"Going to read base character layout");
81 frodo 64 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 frodo 2 len += leng;
87    
88    
89     psiconv_progress(lev+2,off+len,"Going to read the TextEd section");
90 frodo 64 if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng,
91 frodo 2 &(*result)->text,
92     (*result)->base_character_layout,
93 frodo 64 (*result)->base_paragraph_layout)))
94     goto ERROR4;
95 frodo 2 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 frodo 64
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 frodo 2 }
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 frodo 64 if (!(*result = malloc(sizeof(**result))))
132     goto ERROR1;
133 frodo 2
134     psiconv_progress(lev+2,off+len,"Going to read first page number");
135 frodo 64 (*result)->first_page_nr = psiconv_read_u32(buf,lev+2,off+len,&res);
136     if (res)
137     goto ERROR2;
138 frodo 2 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 frodo 64 (*result)->header_dist = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
143     if (res)
144     goto ERROR2;
145 frodo 2 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 frodo 64 (*result)->footer_dist = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
150     if (res)
151     goto ERROR2;
152 frodo 2 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 frodo 64 (*result)->left_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
157     if (res)
158     goto ERROR2;
159 frodo 2 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 frodo 64 (*result)->right_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
164     if (res)
165     goto ERROR2;
166 frodo 2 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 frodo 64 (*result)->top_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
171     if (res)
172     goto ERROR2;
173 frodo 2 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 frodo 64 (*result)->bottom_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
178     if (res)
179     goto ERROR2;
180 frodo 2 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 frodo 64 if ((res = psiconv_parse_page_header(buf,lev+2,off+len,&leng,
185     &(*result)->header)))
186     goto ERROR2;
187 frodo 2 len += leng;
188    
189     psiconv_progress(lev+2,off+len,"Going to read the footer");
190 frodo 64 if ((res = psiconv_parse_page_header(buf,lev+2,off+len,&leng,
191     &(*result)->footer)))
192     goto ERROR3;
193 frodo 2 len += leng;
194    
195     psiconv_progress(lev+2,off+len,"Going to read page dimensions id");
196 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
197     if (res)
198     goto ERROR4;
199 frodo 76 if ((temp != PSICONV_ID_PAGE_DIMENSIONS1) &&
200     (temp != PSICONV_ID_PAGE_DIMENSIONS2)) {
201 frodo 2 psiconv_warn(lev+2,off+len,
202     "Page layout section page dimensions marker not found");
203     psiconv_debug(lev+2,off+len,
204 frodo 76 "Page dimensions marker: read %08x, expected %08x or %08x",
205     temp, PSICONV_ID_PAGE_DIMENSIONS1,
206     PSICONV_ID_PAGE_DIMENSIONS2);
207 frodo 2 }
208 frodo 65 len += 4;
209 frodo 2
210     psiconv_progress(lev+2,off+len,"Going to read the page width");
211 frodo 64 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
212 frodo 65 if (res)
213 frodo 64 goto ERROR4;
214 frodo 2 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 frodo 64 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
219 frodo 65 if (res)
220 frodo 64 goto ERROR4;
221 frodo 2 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height);
222     len += leng;
223    
224 frodo 76 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 frodo 2 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 frodo 64
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 2 }

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