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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2 Revision 184
1/* 1/*
2 parse_texted.c - Part of psiconv, a PSION 5 file formats converter 2 parse_texted.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
22
21#include <stdlib.h> 23#include <stdlib.h>
22 24
23#include "data.h"
24#include "parse_routines.h" 25#include "parse_routines.h"
26#include "error.h"
25 27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
31
26int psiconv_parse_texted_section(const psiconv_buffer buf,int lev, 32int psiconv_parse_texted_section(const psiconv_config config,
33 const psiconv_buffer buf,int lev,
27 psiconv_u32 off, int *length, 34 psiconv_u32 off, int *length,
28 psiconv_texted_section *result, 35 psiconv_texted_section *result,
29 psiconv_character_layout base_char, 36 psiconv_character_layout base_char,
30 psiconv_paragraph_layout base_para) 37 psiconv_paragraph_layout base_para)
31{ 38{
35 psiconv_u32 unknown_sec = 0; 42 psiconv_u32 unknown_sec = 0;
36 psiconv_u32 replacement_sec = 0; 43 psiconv_u32 replacement_sec = 0;
37 psiconv_u32 temp; 44 psiconv_u32 temp;
38 int leng; 45 int leng;
39 46
40 psiconv_progress(lev+1,off,"Going to read a texted section"); 47 psiconv_progress(config,lev+1,off,"Going to read a texted section");
41 (*result) = malloc(sizeof(**result)); 48 if (!((*result) = malloc(sizeof(**result))))
49 goto ERROR1;
42 50
43 psiconv_progress(lev+2,off+len,"Going to read section id"); 51 psiconv_progress(config,lev+2,off+len,"Going to read section id");
44 temp = psiconv_read_u32(buf,lev+2,off+len); 52 temp = psiconv_read_u32(config,buf,lev+2,off+len,&res);
53 if (res)
54 goto ERROR2;
45 if (temp != PSICONV_ID_TEXTED_BODY) { 55 if (temp != PSICONV_ID_TEXTED_BODY) {
46 psiconv_warn(lev+2,off+len, 56 psiconv_error(config,lev+2,off+len,
47 "Page header section body id not found"); 57 "Page header section body id not found");
48 psiconv_debug(lev+2,off+len, 58 psiconv_debug(config,lev+2,off+len,
49 "Page body id: read %08x, expected %08x",temp, 59 "Page body id: read %08x, expected %08x",temp,
50 PSICONV_ID_TEXTED); 60 PSICONV_ID_TEXTED);
51 res = -1; 61 res = -PSICONV_E_PARSE;
62 goto ERROR2;
52 } 63 }
53 len += 4; 64 len += 4;
54 65
55 psiconv_progress(lev+2,off+len,"Going to read the section jumptable"); 66 psiconv_progress(config,lev+2,off+len,"Going to read the section jumptable");
56 while (temp = psiconv_read_u32(buf,lev+3,off+len), 67 while (temp = psiconv_read_u32(config,buf,lev+3,off+len,&res),
57 temp != PSICONV_ID_TEXTED_TEXT) { 68 !res && temp != PSICONV_ID_TEXTED_TEXT) {
58 len += 4; 69 len += 4;
59 if (temp == PSICONV_ID_TEXTED_LAYOUT) { 70 if (temp == PSICONV_ID_TEXTED_LAYOUT) {
60 layout_sec = psiconv_read_u32(buf,lev+3,off+len); 71 layout_sec = psiconv_read_u32(config,buf,lev+3,off+len,&res);
72 if (res)
73 goto ERROR2;
61 psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec); 74 psiconv_debug(config,lev+3,off+len,"Found Layout section at %08x",layout_sec);
62 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { 75 } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) {
63 replacement_sec = psiconv_read_u32(buf,lev+3,off+len); 76 replacement_sec = psiconv_read_u32(config,buf,lev+3,off+len,&res);
77 if (res)
78 goto ERROR2;
64 psiconv_debug(lev+3,off+len,"Found Replacement section at %08x", 79 psiconv_debug(config,lev+3,off+len,"Found Replacement section at %08x",
65 replacement_sec); 80 replacement_sec);
66 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { 81 } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) {
67 unknown_sec= psiconv_read_u32(buf,lev+3,off+len); 82 unknown_sec= psiconv_read_u32(config,buf,lev+3,off+len,&res);
83 if (res)
84 goto ERROR2;
68 if (unknown_sec) { 85 if (unknown_sec) {
69 psiconv_warn(lev+3,off+len, 86 psiconv_warn(config,lev+3,off+len,
70 "Unknown section in TextEd jumptable has real offset"); 87 "Unknown section in TextEd jumptable has real offset (ignoring)");
71 res = -1;
72 } 88 }
73 psiconv_debug(lev+3,off+len,"Found Unknown section at %08x", 89 psiconv_debug(config,lev+3,off+len,"Found Unknown section at %08x",
74 unknown_sec); 90 unknown_sec);
75 } else { 91 } else {
76 psiconv_warn(lev+3,off+len,"Unknown section in TextEd jumptable"); 92 psiconv_warn(config,lev+3,off+len,
93 "Unknown section in TextEd jumptable (ignoring)");
77 psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp, 94 psiconv_debug(config,lev+3,off+len,"Section ID %08x at offset %08x",temp,
78 psiconv_read_u32(buf,lev+3,off+len)); 95 psiconv_read_u32(config,buf,lev+3,off+len,NULL));
79 res = -1;
80 } 96 }
81 len += 4; 97 len += 4;
82 } 98 }
99 if (res)
100 goto ERROR2;
83 101
84 len += 4; 102 len += 4;
85 psiconv_progress(lev+2,off+len,"Going to read the text"); 103 psiconv_progress(config,lev+2,off+len,"Going to read the text");
86 psiconv_parse_text_section(buf,lev+2,off+len,&leng,&(*result)->paragraphs); 104 if ((res = psiconv_parse_text_section(config,buf,lev+2,off+len,&leng,
105 &(*result)->paragraphs)))
106 goto ERROR2;
87 len += leng; 107 len += leng;
88 108
89 if (layout_sec) { 109 if (layout_sec) {
90 psiconv_progress(lev+2,off+len,"Going to read the layout"); 110 psiconv_progress(config,lev+2,off+len,"Going to read the layout");
91 psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, 111 if ((res = psiconv_parse_styleless_layout_section(config,buf,lev+2,layout_sec,NULL,
92 (*result)->paragraphs, 112 (*result)->paragraphs,
93 base_char,base_para); 113 base_char,base_para)))
114 goto ERROR3;
94 } 115 }
95 116
96#if 0 117#if 0
97 if (replacement_sec) { 118 if (replacement_sec) {
98 psiconv_progress(lev+2,off+len,"Going to read the replacements"); 119 psiconv_progress(config,lev+2,off+len,"Going to read the replacements");
99 /* WHATEVER */ 120 /* WHATEVER */
100 } 121 }
101#endif 122#endif
102 123
103 if (length) 124 if (length)
104 *length = len; 125 *length = len;
105 126
106 psiconv_progress(lev+1,off+len-1,"End of TextEd section " 127 psiconv_progress(config,lev+1,off+len-1,"End of TextEd section "
107 "(total length: %08x", len); 128 "(total length: %08x", len);
108 129
130 return 0;
131
132ERROR3:
133 psiconv_free_text_and_layout((*result)->paragraphs);
134ERROR2:
135 free (*result);
136ERROR1:
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
109 return res; 143 return res;
110} 144}
111 145
112 146

Legend:
Removed from v.2  
changed lines
  Added in v.184

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