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

Contents of /psiconv/trunk/lib/psiconv/parse_word.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Sun Oct 3 21:10:47 1999 UTC (19 years, 11 months ago) by frodo
File MIME type: text/plain
File size: 11363 byte(s)
Imported sources

1 /*
2 parse_word.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 "parse_routines.h"
23
24 int psiconv_parse_word_status_section(const psiconv_buffer buf, int lev,
25 psiconv_u32 off, int *length,
26 psiconv_word_status_section *result)
27 {
28 int res=0;
29 int len=0;
30 psiconv_u32 temp;
31 int leng;
32
33 psiconv_progress(lev+1,off,"Going to read the word status section");
34 *result = malloc(sizeof(**result));
35
36 psiconv_progress(lev+2,off+len,
37 "Going to read the initial byte (%02x expected)",0x02);
38 temp = psiconv_read_u8(buf,lev+2,off+len);
39 if (temp != 0x02) {
40 psiconv_warn(lev+2,off+len,
41 "Word status section initial byte unknown value");
42 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
43 res = -1;
44 }
45 len ++;
46
47 psiconv_progress(lev+2,off+len,
48 "Going to read the first byte of display flags");
49 temp = psiconv_read_u8(buf,lev+2,off+len);
50
51 (*result)->show_tabs = temp&0x01 ? psiconv_bool_true : psiconv_bool_false;
52 psiconv_debug(lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs);
53 (*result)->show_spaces = temp&0x02 ? psiconv_bool_true : psiconv_bool_false;
54 psiconv_debug(lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces);
55 (*result)->show_paragraph_ends = temp &0x04 ? psiconv_bool_true :
56 psiconv_bool_false;
57 psiconv_debug(lev+2,off+len,"Show paragraph ends: %02x",
58 (*result)->show_paragraph_ends);
59 (*result)->show_line_breaks = temp & 0x08 ? psiconv_bool_true :
60 psiconv_bool_false;
61 psiconv_debug(lev+2,off+len,"Show line breaks: %02x",
62 (*result)->show_line_breaks);
63 (*result)->show_hard_minus = temp & 0x20 ? psiconv_bool_true :
64 psiconv_bool_false;
65 psiconv_debug(lev+2,off+len,"Show hard minus: %02x",
66 (*result)->show_hard_minus);
67 (*result)->show_hard_space = temp & 0x40 ? psiconv_bool_true :
68 psiconv_bool_false;
69 psiconv_debug(lev+2,off+len,"Show hard space: %02x",
70 (*result)->show_hard_space);
71 if (temp & 0x90) {
72 psiconv_warn(lev+2,off+len,"Word status section first byte of display "
73 "flags contains unknown flags");
74 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0x90);
75 res = -1;
76 }
77 len ++;
78
79 psiconv_progress(lev+2,off+len,"Going to read second byte of display flags");
80 temp = psiconv_read_u8(buf,lev+2,off+len);
81
82 (*result)->show_full_pictures = temp & 0x01 ? psiconv_bool_true :
83 psiconv_bool_false;
84 psiconv_debug(lev+2,off+len,"Show full pictures: %02x",
85 (*result)->show_full_pictures);
86 (*result)->show_full_graphs = temp & 0x02 ? psiconv_bool_true :
87 psiconv_bool_false;
88 psiconv_debug(lev+2,off+len,"Show full graphs: %02x",
89 (*result)->show_full_graphs);
90 if (temp & 0xfc) {
91 psiconv_warn(lev+2,off+len,"Word status section second byte of display "
92 "flags contains unknown flags");
93 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc);
94 res = -1;
95 }
96 len ++;
97
98 psiconv_progress(lev+2,off+len,"Going to read top toolbar setting");
99 psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->show_top_toolbar);
100 len += leng;
101
102 psiconv_progress(lev+2,off+len,"Going to read side toolbar setting");
103 psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->show_side_toolbar);
104 len += leng;
105
106 psiconv_progress(lev+2,off+len,"Going to read operational flags");
107 temp = psiconv_read_u8(buf,lev+2,off+len);
108 (*result)->fit_lines_to_screen = temp & 0x08 ? psiconv_bool_true :
109 psiconv_bool_false;
110 psiconv_debug(lev+2,off+len,"Fit lines to screen: %02x",
111 (*result)->fit_lines_to_screen);
112 if (temp & 0xf7) {
113 psiconv_warn(lev+2,off+len,"Word status section operational flags "
114 "contains unknown flags");
115 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc);
116 res = -1;
117 }
118 len ++;
119
120 psiconv_progress(lev+2,off+len,"Going to read cursor position");
121 (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len);
122 psiconv_debug(lev+2,off+len,"Cursor position: %08x",
123 (*result)->cursor_position);
124 len += 0x04;
125
126 psiconv_progress(lev+2,off+len,"Going to read display size");
127 (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len);
128 psiconv_debug(lev+2,off+len,"Display size: %08x",
129 (*result)->cursor_position);
130 len += 0x04;
131
132 if (length)
133 *length = len;
134
135 psiconv_progress(lev,off+len-1,
136 "End of word status section (total length: %08x)", len);
137
138 return res;
139 }
140
141 int psiconv_parse_word_styles_section(const psiconv_buffer buf, int lev,
142 psiconv_u32 off, int *length,
143 psiconv_word_styles_section *result)
144 {
145 int res=0;
146 int len=0;
147 int leng,i,nr;
148 psiconv_word_style style;
149 psiconv_u32 temp;
150
151 psiconv_progress(lev+1,off,"Going to read the word styles section");
152 *result = malloc(sizeof(**result));
153
154 psiconv_progress(lev+2,off+len,"Going to read style normal");
155 style = malloc(sizeof(*style));
156 style->name = NULL;
157 style->paragraph = psiconv_basic_paragraph_layout();
158 psiconv_progress(lev+3,off+len,"Going to read the paragraph codes");
159 res |= psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
160 style->paragraph);
161 len += leng;
162 psiconv_progress(lev+3,off+len,"Going to read the character codes");
163 style->character = psiconv_basic_character_layout();
164 res |= psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
165 style->character);
166 len += leng;
167 psiconv_progress(lev+3,off+len,"Going to read the hotkey");
168 temp = psiconv_read_u32(buf,lev+3,off+len);
169 if (temp & 0xffffff00) {
170 psiconv_warn(lev+3,off+len,"Normal style hotkey has unknown value");
171 psiconv_debug(lev+3,off+len,"Hotkey value %08x",temp);
172 temp = 0;
173 res = -1;
174 }
175 style->hotkey = temp;
176 if ((style->hotkey >= 32) && (style->hotkey < 127))
177 psiconv_debug(lev+3,off+len,"Hotkey: %c",style->hotkey);
178 else if (style->hotkey == 0x00)
179 psiconv_debug(lev+3,off+len,"Hotkey: <none>");
180 else
181 psiconv_debug(lev+3,off+len,"Hotkey: %02x",style->hotkey);
182 (*result)->normal = style;
183 len += 0x04;
184
185 psiconv_progress(lev+2,off+len,"Going to read hotkeys list");
186 (*result)->styles = psiconv_list_new(sizeof(*style));
187 style = malloc(sizeof(*style));
188 psiconv_progress(lev+3,off+len,"Going to read the number of entries");
189 nr = psiconv_read_u8(buf,lev+3,off+len);
190 len ++;
191 psiconv_debug(lev+3,off+len,"Nummer of hotkeys: %02x",nr);
192 for (i = 0; i < nr; i ++) {
193 temp = psiconv_read_u32(buf,lev+2,off+len);
194 if (temp & 0xffffff00) {
195 psiconv_warn(lev+3,off+len,"Style hotkey has unknown value");
196 psiconv_debug(lev+3,off+len,"Hotkey %d value %08x",i,temp);
197 temp = 0;
198 res = -1;
199 }
200 style->hotkey = temp;
201 if ((style->hotkey >= 32) && (style->hotkey < 127))
202 psiconv_debug(lev+3,off+len,"Hotkey %d: %c",i,style->hotkey);
203 else if (style->hotkey == 0x00)
204 psiconv_debug(lev+3,off+len,"Hotkey %d: <none>",i);
205 else
206 psiconv_debug(lev+3,off+len,"Hotkey %d: %02x",i,style->hotkey);
207 psiconv_list_add((*result)->styles,style);
208 len += 0x04;
209 }
210 free(style);
211
212 psiconv_progress(lev+2,off+len,"Going to read all other styles");
213 psiconv_progress(lev+2,off+len,"Going to read the number of styles");
214 nr = psiconv_read_u8(buf,lev+3,off+len);
215 if (nr != psiconv_list_length((*result)->styles)) {
216 psiconv_warn(lev+3,off+len,"Number of styles and hotkeys do not match");
217 psiconv_debug(lev+3,off+len,"%d hotkeys, %d styles",
218 psiconv_list_length((*result)->styles), nr);
219 res = -1;
220 }
221 len ++;
222
223 for (i = 0; i < nr; i++) {
224 psiconv_progress(lev+2,off+len,"Next style: %d",i);
225 if (i >= psiconv_list_length((*result)->styles)) {
226 style = malloc(sizeof(*style));
227 style->hotkey = 0;
228 psiconv_list_add((*result)->styles,style);
229 psiconv_debug(lev+3,off+len,"New entry added in list");
230 free(style);
231 }
232 style = psiconv_list_get((*result)->styles,i);
233 psiconv_progress(lev+3,off+len,"Going to read the style name");
234 style->name = psiconv_read_string(buf,lev+3,off+len,&leng);
235 len += leng;
236 psiconv_progress(lev+3,off+len,
237 "Going to read whether this style is built-in");
238 temp = psiconv_read_u32(buf,lev+2,off+len);
239 if (temp == PSICONV_ID_STYLE_BUILT_IN) {
240 style->built_in = psiconv_bool_true;
241 psiconv_debug(lev+3,off+len,"Built-in style");
242 } else if (temp == PSICONV_ID_STYLE_REMOVABLE) {
243 style->built_in = psiconv_bool_false;
244 psiconv_debug(lev+3,off+len,"Removable style");
245 } else {
246 psiconv_warn(lev+3,off+len,"Word styles section unknown style id");
247 psiconv_debug(lev+3,off+len,"Unknown id: %08x",temp);
248 style->built_in = psiconv_bool_false;
249 res = -1;
250 }
251 len += 4;
252 psiconv_progress(lev+3,off+len,"Going to read an unknown long "
253 "(0x%08x expected)",0x00000000);
254 temp = psiconv_read_u32(buf,lev+3,off+len);
255 if (temp != 0x00000000) {
256 psiconv_warn(lev+3,off+len,"Unexpected value in style description");
257 psiconv_debug(lev+3,off+len,"Unknown long: read %08x, expected %08x",
258 temp, 0x00000000);
259 }
260 len += 4;
261 psiconv_progress(lev+3,off+len,"Going to read the character codes");
262 style->character = psiconv_basic_character_layout();
263 res |= psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
264 style->character);
265 len += leng;
266 psiconv_progress(lev+3,off+len,"Going to read the paragraph codes");
267 style->paragraph = psiconv_basic_paragraph_layout();
268 res |= psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
269 style->paragraph);
270 len += leng;
271 }
272
273 if (length)
274 *length = len;
275
276 psiconv_progress(lev,off+len-1,
277 "End of word styles section (total length: %08x)", len);
278
279 return res;
280 }
281
282

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