1 |
frodo |
73 |
/* |
2 |
|
|
generate_texted.c - Part of psiconv, a PSION 5 file formats converter |
3 |
frodo |
270 |
Copyright (c) 2000-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 |
frodo |
73 |
|
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 "generate_routines.h" |
26 |
|
|
#include "error.h" |
27 |
|
|
|
28 |
frodo |
142 |
#ifdef DMALLOC |
29 |
|
|
#include <dmalloc.h> |
30 |
|
|
#endif |
31 |
frodo |
73 |
|
32 |
frodo |
142 |
|
33 |
|
|
|
34 |
frodo |
168 |
int psiconv_write_texted_section(const psiconv_config config, |
35 |
frodo |
184 |
psiconv_buffer buf, int lev, |
36 |
frodo |
80 |
const psiconv_texted_section value, |
37 |
|
|
const psiconv_character_layout base_char, |
38 |
|
|
const psiconv_paragraph_layout base_para, |
39 |
|
|
psiconv_buffer *extra_buf) |
40 |
frodo |
73 |
{ |
41 |
frodo |
80 |
int res,with_layout_section=0; |
42 |
|
|
psiconv_u32 layout_id; |
43 |
frodo |
73 |
|
44 |
frodo |
184 |
psiconv_progress(config,lev,0,"Writing texted section"); |
45 |
|
|
|
46 |
frodo |
73 |
if (!value) { |
47 |
frodo |
231 |
psiconv_error(config,lev,0,"Null TextEd section"); |
48 |
frodo |
80 |
res = -PSICONV_E_GENERATE; |
49 |
|
|
goto ERROR1; |
50 |
frodo |
73 |
} |
51 |
|
|
|
52 |
frodo |
80 |
if (!(*extra_buf = psiconv_buffer_new())) { |
53 |
frodo |
233 |
psiconv_error(config,lev+1,0,"Out of memory error"); |
54 |
frodo |
80 |
res = -PSICONV_E_NOMEM; |
55 |
|
|
goto ERROR1; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
layout_id = psiconv_buffer_unique_id(); |
59 |
frodo |
233 |
if ((res = psiconv_buffer_add_target(*extra_buf,layout_id))) { |
60 |
|
|
psiconv_error(config,lev+1,0,"Out of memory error"); |
61 |
|
|
goto ERROR2; |
62 |
|
|
} |
63 |
frodo |
80 |
|
64 |
|
|
if (psiconv_list_length(value->paragraphs)) { |
65 |
|
|
with_layout_section = 1; |
66 |
frodo |
184 |
if ((res = psiconv_write_styleless_layout_section(config,*extra_buf,lev+1, |
67 |
frodo |
80 |
value->paragraphs, |
68 |
|
|
base_char,base_para))) |
69 |
|
|
goto ERROR2; |
70 |
|
|
} |
71 |
|
|
|
72 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_TEXTED_BODY))) |
73 |
frodo |
80 |
goto ERROR2; |
74 |
frodo |
73 |
|
75 |
frodo |
80 |
/* Partly dummy TextEd Jumptable */ |
76 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_TEXTED_REPLACEMENT))) |
77 |
frodo |
80 |
goto ERROR2; |
78 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,0))) |
79 |
frodo |
80 |
goto ERROR2; |
80 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_TEXTED_UNKNOWN))) |
81 |
frodo |
80 |
goto ERROR2; |
82 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,0))) |
83 |
frodo |
80 |
goto ERROR2; |
84 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_TEXTED_LAYOUT))) |
85 |
frodo |
80 |
goto ERROR2; |
86 |
|
|
if (with_layout_section) { |
87 |
frodo |
184 |
if ((res = psiconv_write_offset(config,buf,lev+1,layout_id))) |
88 |
frodo |
80 |
goto ERROR2; |
89 |
|
|
} else { |
90 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,0))) |
91 |
frodo |
80 |
goto ERROR2; |
92 |
|
|
} |
93 |
frodo |
73 |
|
94 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_TEXTED_TEXT))) |
95 |
frodo |
80 |
goto ERROR2; |
96 |
frodo |
73 |
|
97 |
frodo |
231 |
if ((res = psiconv_write_text_section(config,buf,lev+1,value->paragraphs))) |
98 |
|
|
goto ERROR2; |
99 |
|
|
psiconv_progress(config,lev,0,"End of texted section"); |
100 |
|
|
return 0; |
101 |
frodo |
73 |
|
102 |
frodo |
80 |
ERROR2: |
103 |
|
|
psiconv_buffer_free(*extra_buf); |
104 |
|
|
ERROR1: |
105 |
frodo |
231 |
psiconv_error(config,lev,0,"Writing of texted section failed"); |
106 |
frodo |
80 |
return res; |
107 |
frodo |
73 |
} |