/[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 351 - (show annotations)
Wed Oct 22 19:53:40 2014 UTC (9 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 4839 byte(s)
(Frodo) Update copyright year in all source files

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

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