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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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