/[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 71 - (hide annotations)
Fri Dec 22 22:31:50 2000 UTC (23 years, 4 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 frodo 2 /*
2     parse_texted.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 63 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
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     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 frodo 64 if (!((*result) = malloc(sizeof(**result))))
44     goto ERROR1;
45 frodo 2
46     psiconv_progress(lev+2,off+len,"Going to read section id");
47 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
48     if (res)
49     goto ERROR2;
50 frodo 2 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 frodo 64 res = -PSICONV_E_PARSE;
57     goto ERROR2;
58 frodo 2 }
59     len += 4;
60    
61     psiconv_progress(lev+2,off+len,"Going to read the section jumptable");
62 frodo 64 while (temp = psiconv_read_u32(buf,lev+3,off+len,&res),
63     !res && temp != PSICONV_ID_TEXTED_TEXT) {
64 frodo 2 len += 4;
65     if (temp == PSICONV_ID_TEXTED_LAYOUT) {
66 frodo 64 layout_sec = psiconv_read_u32(buf,lev+3,off+len,&res);
67     if (res)
68     goto ERROR2;
69 frodo 2 psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec);
70     } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) {
71 frodo 64 replacement_sec = psiconv_read_u32(buf,lev+3,off+len,&res);
72     if (res)
73     goto ERROR2;
74 frodo 2 psiconv_debug(lev+3,off+len,"Found Replacement section at %08x",
75     replacement_sec);
76     } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) {
77 frodo 64 unknown_sec= psiconv_read_u32(buf,lev+3,off+len,&res);
78     if (res)
79     goto ERROR2;
80 frodo 2 if (unknown_sec) {
81     psiconv_warn(lev+3,off+len,
82 frodo 64 "Unknown section in TextEd jumptable has real offset (ignoring)");
83 frodo 2 }
84     psiconv_debug(lev+3,off+len,"Found Unknown section at %08x",
85     unknown_sec);
86     } else {
87 frodo 64 psiconv_warn(lev+3,off+len,
88     "Unknown section in TextEd jumptable (ignoring)");
89 frodo 2 psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp,
90 frodo 64 psiconv_read_u32(buf,lev+3,off+len,NULL));
91 frodo 2 }
92     len += 4;
93     }
94 frodo 64 if (res)
95     goto ERROR2;
96 frodo 2
97     len += 4;
98     psiconv_progress(lev+2,off+len,"Going to read the text");
99 frodo 64 if ((res = psiconv_parse_text_section(buf,lev+2,off+len,&leng,
100     &(*result)->paragraphs)))
101     goto ERROR2;
102 frodo 2 len += leng;
103    
104     if (layout_sec) {
105     psiconv_progress(lev+2,off+len,"Going to read the layout");
106 frodo 64 if ((res = psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL,
107 frodo 2 (*result)->paragraphs,
108 frodo 64 base_char,base_para)))
109     goto ERROR3;
110 frodo 2 }
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 frodo 64 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 frodo 2 }
140    
141    

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