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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71 - (show annotations)
Fri Dec 22 22:31:50 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 4551 byte(s)
(Frodo) First generate routines! Reshuffled a few things to make it all work out

1 /*
2 parse_texted.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 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 "compat.h"
22
23 #include <stdlib.h>
24
25 #include "parse_routines.h"
26 #include "error.h"
27
28 int psiconv_parse_texted_section(const psiconv_buffer buf,int lev,
29 psiconv_u32 off, int *length,
30 psiconv_texted_section *result,
31 psiconv_character_layout base_char,
32 psiconv_paragraph_layout base_para)
33 {
34 int res = 0;
35 int len = 0;
36 psiconv_u32 layout_sec = 0;
37 psiconv_u32 unknown_sec = 0;
38 psiconv_u32 replacement_sec = 0;
39 psiconv_u32 temp;
40 int leng;
41
42 psiconv_progress(lev+1,off,"Going to read a texted section");
43 if (!((*result) = malloc(sizeof(**result))))
44 goto ERROR1;
45
46 psiconv_progress(lev+2,off+len,"Going to read section id");
47 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
48 if (res)
49 goto ERROR2;
50 if (temp != PSICONV_ID_TEXTED_BODY) {
51 psiconv_warn(lev+2,off+len,
52 "Page header section body id not found");
53 psiconv_debug(lev+2,off+len,
54 "Page body id: read %08x, expected %08x",temp,
55 PSICONV_ID_TEXTED);
56 res = -PSICONV_E_PARSE;
57 goto ERROR2;
58 }
59 len += 4;
60
61 psiconv_progress(lev+2,off+len,"Going to read the section jumptable");
62 while (temp = psiconv_read_u32(buf,lev+3,off+len,&res),
63 !res && temp != PSICONV_ID_TEXTED_TEXT) {
64 len += 4;
65 if (temp == PSICONV_ID_TEXTED_LAYOUT) {
66 layout_sec = psiconv_read_u32(buf,lev+3,off+len,&res);
67 if (res)
68 goto ERROR2;
69 psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec);
70 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) {
71 replacement_sec = psiconv_read_u32(buf,lev+3,off+len,&res);
72 if (res)
73 goto ERROR2;
74 psiconv_debug(lev+3,off+len,"Found Replacement section at %08x",
75 replacement_sec);
76 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) {
77 unknown_sec= psiconv_read_u32(buf,lev+3,off+len,&res);
78 if (res)
79 goto ERROR2;
80 if (unknown_sec) {
81 psiconv_warn(lev+3,off+len,
82 "Unknown section in TextEd jumptable has real offset (ignoring)");
83 }
84 psiconv_debug(lev+3,off+len,"Found Unknown section at %08x",
85 unknown_sec);
86 } else {
87 psiconv_warn(lev+3,off+len,
88 "Unknown section in TextEd jumptable (ignoring)");
89 psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp,
90 psiconv_read_u32(buf,lev+3,off+len,NULL));
91 }
92 len += 4;
93 }
94 if (res)
95 goto ERROR2;
96
97 len += 4;
98 psiconv_progress(lev+2,off+len,"Going to read the text");
99 if ((res = psiconv_parse_text_section(buf,lev+2,off+len,&leng,
100 &(*result)->paragraphs)))
101 goto ERROR2;
102 len += leng;
103
104 if (layout_sec) {
105 psiconv_progress(lev+2,off+len,"Going to read the layout");
106 if ((res = psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL,
107 (*result)->paragraphs,
108 base_char,base_para)))
109 goto ERROR3;
110 }
111
112 #if 0
113 if (replacement_sec) {
114 psiconv_progress(lev+2,off+len,"Going to read the replacements");
115 /* WHATEVER */
116 }
117 #endif
118
119 if (length)
120 *length = len;
121
122 psiconv_progress(lev+1,off+len-1,"End of TextEd section "
123 "(total length: %08x", len);
124
125 return 0;
126
127 ERROR3:
128 psiconv_free_text_and_layout((*result)->paragraphs);
129 ERROR2:
130 free (*result);
131 ERROR1:
132 psiconv_warn(lev+1,off,"Reading of TextEd Section failed");
133 if (length)
134 *length = 0;
135 if (!res)
136 return -PSICONV_E_NOMEM;
137 else
138 return res;
139 }
140
141

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