/[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 64 - (show annotations)
Fri Dec 15 00:21:51 2000 UTC (19 years ago) by frodo
File MIME type: text/plain
File size: 4529 byte(s)
(Frodo) Massive update: theoretically, all return codes are now checked.
        Untested - may have many typos.

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

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