/[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 2 - (show annotations)
Sun Oct 3 21:10:47 1999 UTC (24 years, 6 months ago) by frodo
File MIME type: text/plain
File size: 6775 byte(s)
Imported sources

1 /*
2 parse_page.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 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 (*result) = malloc(sizeof(**result));
37
38 psiconv_progress(lev+2,off+len,
39 "Going to read the first byte (0x01 expected)");
40 temp = psiconv_read_u8(buf,lev+2,off+len);
41 if (temp != 0x01) {
42 psiconv_warn(lev+2,off+len,"Page header first byte mismatch");
43 psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x",
44 temp,0x01);
45 res = -1;
46 }
47 len += 1;
48
49 psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag");
50 res |= psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->on_first_page);
51 len += leng;
52
53 psiconv_progress(lev+2,off+len,"Going to read three zero bytes");
54 for (i = 0; i < 0x03; i++,len++) {
55 temp = psiconv_read_u8(buf,lev+2,off+len);
56 if (temp != 0x00) {
57 psiconv_warn(lev+2,off+len,
58 "Page Header unknown value in zero bytes section");
59 psiconv_debug(lev+2,off+len,"Byte %d: read %02x, expected %02x",
60 i,temp,0x00);
61 res = -1;
62 }
63 }
64
65 psiconv_progress(lev+2,off+len,"Going to read base paragraph layout");
66 (*result)->base_paragraph_layout = psiconv_basic_paragraph_layout();
67 res |= psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng,
68 (*result)->base_paragraph_layout);
69 len += leng;
70
71 psiconv_progress(lev+2,off+len,"Going to read base character layout");
72 (*result)->base_character_layout = psiconv_basic_character_layout();
73 res |= psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng,
74 (*result)->base_character_layout);
75 len += leng;
76
77
78 psiconv_progress(lev+2,off+len,"Going to read the TextEd section");
79 res |= psiconv_parse_texted_section(buf,lev+2,off+len,&leng,
80 &(*result)->text,
81 (*result)->base_character_layout,
82 (*result)->base_paragraph_layout);
83 len += leng;
84
85 if (length)
86 *length = len;
87
88 psiconv_progress(lev+1,off+len-1,"End of page header"
89 "(total length: %08x", len);
90
91 return res;
92 }
93
94 int psiconv_parse_page_layout_section(const psiconv_buffer buf,int lev,
95 psiconv_u32 off, int *length,
96 psiconv_page_layout_section *result)
97 {
98 int res = 0;
99 int len = 0;
100 int leng;
101 psiconv_u32 temp;
102
103 psiconv_progress(lev+1,off,"Going to read the page layout section");
104 (*result) = malloc(sizeof(**result));
105
106 psiconv_progress(lev+2,off+len,"Going to read first page number");
107 (*result)->first_page_nr = psiconv_read_u32(buf,lev+2,off+len);
108 psiconv_debug(lev+2,off+len,"First page: %d",(*result)->first_page_nr);
109 len += 4;
110
111 psiconv_progress(lev+2,off+len,"Going to read header distance");
112 (*result)->header_dist = psiconv_read_length(buf,lev+2,off+len,&leng);
113 psiconv_debug(lev+2,off+len,"Header distance: %6.3f",(*result)->header_dist);
114 len += leng;
115
116 psiconv_progress(lev+2,off+len,"Going to read footer distance");
117 (*result)->footer_dist = psiconv_read_length(buf,lev+2,off+len,&leng);
118 psiconv_debug(lev+2,off+len,"Footer distance: %6.3f",(*result)->footer_dist);
119 len += leng;
120
121 psiconv_progress(lev+2,off+len,"Going to read the left margin");
122 (*result)->left_margin = psiconv_read_length(buf,lev+2,off+len,&leng);
123 psiconv_debug(lev+2,off+len,"Left margin: %6.3f",(*result)->left_margin);
124 len += leng;
125
126 psiconv_progress(lev+2,off+len,"Going read the to right margin");
127 (*result)->right_margin = psiconv_read_length(buf,lev+2,off+len,&leng);
128 psiconv_debug(lev+2,off+len,"Right margin: %6.3f",(*result)->right_margin);
129 len += leng;
130
131 psiconv_progress(lev+2,off+len,"Going to read the top margin");
132 (*result)->top_margin = psiconv_read_length(buf,lev+2,off+len,&leng);
133 psiconv_debug(lev+2,off+len,"Top margin: %6.3f",(*result)->top_margin);
134 len += leng;
135
136 psiconv_progress(lev+2,off+len,"Going to read the bottom margin");
137 (*result)->bottom_margin = psiconv_read_length(buf,lev+2,off+len,&leng);
138 psiconv_debug(lev+2,off+len,"Bottom margin: %6.3f",(*result)->bottom_margin);
139 len += leng;
140
141 psiconv_progress(lev+2,off+len,"Going to read the header");
142 res |= psiconv_parse_page_header(buf,lev+2,off+len,&leng,&(*result)->header);
143 len += leng;
144
145 psiconv_progress(lev+2,off+len,"Going to read the footer");
146 res |= psiconv_parse_page_header(buf,lev+2,off+len,&leng,&(*result)->footer);
147 len += leng;
148
149 psiconv_progress(lev+2,off+len,"Going to read page dimensions id");
150 temp = psiconv_read_u32(buf,lev+2,off+len);
151 if (temp != PSICONV_ID_PAGE_DIMENSIONS) {
152 psiconv_warn(lev+2,off+len,
153 "Page layout section page dimensions marker not found");
154 psiconv_debug(lev+2,off+len,
155 "Page dimensions marker: read %08x, expected %08x",temp,
156 PSICONV_ID_PAGE_DIMENSIONS);
157 res = -1;
158 }
159
160 psiconv_progress(lev+2,off+len,"Going to read the page width");
161 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng);
162 psiconv_debug(lev+2,off+len,"Page width: %6.3f",(*result)->page_width);
163 len += leng;
164
165 psiconv_progress(lev+2,off+len,"Going to read the page height");
166 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng);
167 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height);
168 len += leng;
169
170 if (length)
171 *length = len;
172
173 psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)",
174 len);
175
176 return res;
177 }

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