| 1 |
/* |
| 2 |
parse_texted.c - Part of psiconv, a PSION 5 file formats converter |
| 3 |
Copyright (c) 1999 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 |
(*result) = malloc(sizeof(**result)); |
| 42 |
|
| 43 |
psiconv_progress(lev+2,off+len,"Going to read section id"); |
| 44 |
temp = psiconv_read_u32(buf,lev+2,off+len); |
| 45 |
if (temp != PSICONV_ID_TEXTED_BODY) { |
| 46 |
psiconv_warn(lev+2,off+len, |
| 47 |
"Page header section body id not found"); |
| 48 |
psiconv_debug(lev+2,off+len, |
| 49 |
"Page body id: read %08x, expected %08x",temp, |
| 50 |
PSICONV_ID_TEXTED); |
| 51 |
res = -1; |
| 52 |
} |
| 53 |
len += 4; |
| 54 |
|
| 55 |
psiconv_progress(lev+2,off+len,"Going to read the section jumptable"); |
| 56 |
while (temp = psiconv_read_u32(buf,lev+3,off+len), |
| 57 |
temp != PSICONV_ID_TEXTED_TEXT) { |
| 58 |
len += 4; |
| 59 |
if (temp == PSICONV_ID_TEXTED_LAYOUT) { |
| 60 |
layout_sec = psiconv_read_u32(buf,lev+3,off+len); |
| 61 |
psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec); |
| 62 |
} else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { |
| 63 |
replacement_sec = psiconv_read_u32(buf,lev+3,off+len); |
| 64 |
psiconv_debug(lev+3,off+len,"Found Replacement section at %08x", |
| 65 |
replacement_sec); |
| 66 |
} else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { |
| 67 |
unknown_sec= psiconv_read_u32(buf,lev+3,off+len); |
| 68 |
if (unknown_sec) { |
| 69 |
psiconv_warn(lev+3,off+len, |
| 70 |
"Unknown section in TextEd jumptable has real offset"); |
| 71 |
res = -1; |
| 72 |
} |
| 73 |
psiconv_debug(lev+3,off+len,"Found Unknown section at %08x", |
| 74 |
unknown_sec); |
| 75 |
} else { |
| 76 |
psiconv_warn(lev+3,off+len,"Unknown section in TextEd jumptable"); |
| 77 |
psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp, |
| 78 |
psiconv_read_u32(buf,lev+3,off+len)); |
| 79 |
res = -1; |
| 80 |
} |
| 81 |
len += 4; |
| 82 |
} |
| 83 |
|
| 84 |
len += 4; |
| 85 |
psiconv_progress(lev+2,off+len,"Going to read the text"); |
| 86 |
psiconv_parse_text_section(buf,lev+2,off+len,&leng,&(*result)->paragraphs); |
| 87 |
len += leng; |
| 88 |
|
| 89 |
if (layout_sec) { |
| 90 |
psiconv_progress(lev+2,off+len,"Going to read the layout"); |
| 91 |
psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, |
| 92 |
(*result)->paragraphs, |
| 93 |
base_char,base_para); |
| 94 |
} |
| 95 |
|
| 96 |
#if 0 |
| 97 |
if (replacement_sec) { |
| 98 |
psiconv_progress(lev+2,off+len,"Going to read the replacements"); |
| 99 |
/* WHATEVER */ |
| 100 |
} |
| 101 |
#endif |
| 102 |
|
| 103 |
if (length) |
| 104 |
*length = len; |
| 105 |
|
| 106 |
psiconv_progress(lev+1,off+len-1,"End of TextEd section " |
| 107 |
"(total length: %08x", len); |
| 108 |
|
| 109 |
return res; |
| 110 |
} |
| 111 |
|
| 112 |
|