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