/[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 65 - (hide annotations)
Fri Dec 15 01:16:43 2000 UTC (23 years, 11 months ago) by frodo
File MIME type: text/plain
File size: 8121 byte(s)
(Frodo) First typos eliminated. Word files seem to work now. Need to test
        other types.

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     #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 frodo 64 if (!(*result = malloc(sizeof(**result))))
37     goto ERROR1;
38 frodo 2
39     psiconv_progress(lev+2,off+len,
40     "Going to read the first byte (0x01 expected)");
41 frodo 64 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
42 frodo 65 if (res)
43 frodo 64 goto ERROR2;
44 frodo 2 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 frodo 64 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,
53     &(*result)->on_first_page)))
54     goto ERROR2;
55 frodo 2 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 frodo 64 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
60     if (res)
61     goto ERROR2;
62 frodo 2 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 frodo 64 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 frodo 2 len += leng;
77    
78     psiconv_progress(lev+2,off+len,"Going to read base character layout");
79 frodo 64 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 frodo 2 len += leng;
85    
86    
87     psiconv_progress(lev+2,off+len,"Going to read the TextEd section");
88 frodo 64 if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng,
89 frodo 2 &(*result)->text,
90     (*result)->base_character_layout,
91 frodo 64 (*result)->base_paragraph_layout)))
92     goto ERROR4;
93 frodo 2 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 frodo 64
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 frodo 2 }
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 frodo 64 if (!(*result = malloc(sizeof(**result))))
130     goto ERROR1;
131 frodo 2
132     psiconv_progress(lev+2,off+len,"Going to read first page number");
133 frodo 64 (*result)->first_page_nr = psiconv_read_u32(buf,lev+2,off+len,&res);
134     if (res)
135     goto ERROR2;
136 frodo 2 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 frodo 64 (*result)->header_dist = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
141     if (res)
142     goto ERROR2;
143 frodo 2 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 frodo 64 (*result)->footer_dist = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
148     if (res)
149     goto ERROR2;
150 frodo 2 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 frodo 64 (*result)->left_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
155     if (res)
156     goto ERROR2;
157 frodo 2 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 frodo 64 (*result)->right_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
162     if (res)
163     goto ERROR2;
164 frodo 2 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 frodo 64 (*result)->top_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
169     if (res)
170     goto ERROR2;
171 frodo 2 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 frodo 64 (*result)->bottom_margin = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
176     if (res)
177     goto ERROR2;
178 frodo 2 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 frodo 64 if ((res = psiconv_parse_page_header(buf,lev+2,off+len,&leng,
183     &(*result)->header)))
184     goto ERROR2;
185 frodo 2 len += leng;
186    
187     psiconv_progress(lev+2,off+len,"Going to read the footer");
188 frodo 64 if ((res = psiconv_parse_page_header(buf,lev+2,off+len,&leng,
189     &(*result)->footer)))
190     goto ERROR3;
191 frodo 2 len += leng;
192    
193     psiconv_progress(lev+2,off+len,"Going to read page dimensions id");
194 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
195     if (res)
196     goto ERROR4;
197 frodo 2 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 frodo 65 len += 4;
205 frodo 2
206     psiconv_progress(lev+2,off+len,"Going to read the page width");
207 frodo 64 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
208 frodo 65 if (res)
209 frodo 64 goto ERROR4;
210 frodo 2 psiconv_debug(lev+2,off+len,"Page width: %6.3f",(*result)->page_width);
211     len += leng;
212    
213     psiconv_progress(lev+2,off+len,"Going to read the page height");
214 frodo 64 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
215 frodo 65 if (res)
216 frodo 64 goto ERROR4;
217 frodo 2 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height);
218     len += leng;
219    
220     if (length)
221     *length = len;
222    
223     psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)",
224     len);
225    
226     return res;
227 frodo 64
228     ERROR4:
229     psiconv_free_page_header((*result)->footer);
230     ERROR3:
231     psiconv_free_page_header((*result)->header);
232     ERROR2:
233     free (*result);
234     ERROR1:
235     psiconv_warn(lev+1,off,"Reading of Page Section failed");
236     if (length)
237     *length = 0;
238     if (!res)
239     return -PSICONV_E_NOMEM;
240     else
241     return res;
242 frodo 2 }

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