| 1 |
/* |
| 2 |
generate_word.c - Part of psiconv, a PSION 5 file formats converter |
| 3 |
Copyright (c) 2000 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 "compat.h" |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
|
| 25 |
#include "generate_routines.h" |
| 26 |
#include "error.h" |
| 27 |
|
| 28 |
int psiconv_write_word_status_section(psiconv_buffer buf, |
| 29 |
psiconv_word_status_section value) |
| 30 |
{ |
| 31 |
int res; |
| 32 |
|
| 33 |
if (!value) { |
| 34 |
psiconv_warn(0,psiconv_buffer_length(buf),"Null word status section"); |
| 35 |
return -PSICONV_E_GENERATE; |
| 36 |
} |
| 37 |
|
| 38 |
if ((res = psiconv_write_u8(buf,0x02))) |
| 39 |
return res; |
| 40 |
if ((res = psiconv_write_u8(buf,(value->show_tabs?0x01:0x00) | |
| 41 |
(value->show_spaces?0x02:0x00) | |
| 42 |
(value->show_paragraph_ends?0x04:0x00) | |
| 43 |
(value->show_line_breaks?0x08:0x00) | |
| 44 |
(value->show_hard_minus?0x20:0x00) | |
| 45 |
(value->show_hard_space?0x40:0x00)))) |
| 46 |
return res; |
| 47 |
if ((res = psiconv_write_u8(buf,(value->show_full_pictures?0x01:0x00) | |
| 48 |
(value->show_full_graphs?0x02:0x00)))) |
| 49 |
return res; |
| 50 |
if ((res = psiconv_write_bool(buf,value->show_top_toolbar))) |
| 51 |
return res; |
| 52 |
if ((res = psiconv_write_bool(buf,value->show_side_toolbar))) |
| 53 |
return res; |
| 54 |
if ((res = psiconv_write_u8(buf,(value->fit_lines_to_screen?0x08:0x00)))) |
| 55 |
return res; |
| 56 |
if ((res = psiconv_write_u32(buf,value->cursor_position))) |
| 57 |
return res; |
| 58 |
return psiconv_write_u32(buf,value->display_size); |
| 59 |
} |
| 60 |
|
| 61 |
int psiconv_write_word_styles_section(psiconv_buffer buf, |
| 62 |
psiconv_word_styles_section value) |
| 63 |
{ |
| 64 |
int res,i; |
| 65 |
psiconv_word_style style; |
| 66 |
psiconv_paragraph_layout basepara; |
| 67 |
psiconv_character_layout basechar; |
| 68 |
|
| 69 |
|
| 70 |
if (!value || !value->normal || !value->styles) { |
| 71 |
psiconv_warn(0,psiconv_buffer_length(buf),"Null word styles section"); |
| 72 |
res = -PSICONV_E_GENERATE; |
| 73 |
goto ERROR1; |
| 74 |
} |
| 75 |
|
| 76 |
if (!(basepara=psiconv_basic_paragraph_layout())) { |
| 77 |
res = -PSICONV_E_NOMEM; |
| 78 |
goto ERROR1; |
| 79 |
} |
| 80 |
|
| 81 |
if (!(basechar=psiconv_basic_character_layout())) { |
| 82 |
res = -PSICONV_E_NOMEM; |
| 83 |
goto ERROR2; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
if ((res = psiconv_write_paragraph_layout_list(buf,value->normal->paragraph, |
| 88 |
basepara))) |
| 89 |
goto ERROR3; |
| 90 |
if ((res = psiconv_write_character_layout_list(buf,value->normal->character, |
| 91 |
basechar))) |
| 92 |
goto ERROR3; |
| 93 |
if ((res = psiconv_write_u32(buf,value->normal->hotkey))) |
| 94 |
goto ERROR3; |
| 95 |
if ((res = psiconv_write_u8(buf,psiconv_list_length(value->styles)))) |
| 96 |
goto ERROR3; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
for (i = 0; i < psiconv_list_length(value->styles); i++) { |
| 101 |
if (!(style = psiconv_list_get(value->styles,i))) { |
| 102 |
psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
| 103 |
res = -PSICONV_E_OTHER; |
| 104 |
goto ERROR3; |
| 105 |
} |
| 106 |
if ((res = psiconv_write_u32(buf,style->hotkey))) |
| 107 |
goto ERROR3; |
| 108 |
} |
| 109 |
if ((res = psiconv_write_u8(buf,psiconv_list_length(value->styles)))) |
| 110 |
goto ERROR3; |
| 111 |
for (i = 0; i < psiconv_list_length(value->styles); i++) { |
| 112 |
if (!(style = psiconv_list_get(value->styles,i))) { |
| 113 |
psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
| 114 |
res = -PSICONV_E_OTHER; |
| 115 |
goto ERROR3; |
| 116 |
} |
| 117 |
if (!style->name) { |
| 118 |
psiconv_warn(0,psiconv_buffer_length(buf),"Null style name"); |
| 119 |
res = -PSICONV_E_GENERATE; |
| 120 |
goto ERROR3; |
| 121 |
} |
| 122 |
if ((res = psiconv_write_string(buf,style->name))) |
| 123 |
goto ERROR3; |
| 124 |
if ((res = psiconv_write_u32(buf,style->built_in?PSICONV_ID_STYLE_BUILT_IN: |
| 125 |
PSICONV_ID_STYLE_REMOVABLE))) |
| 126 |
goto ERROR3; |
| 127 |
if ((res = psiconv_write_u32(buf,style->outline_level))) |
| 128 |
goto ERROR3; |
| 129 |
if ((res = psiconv_write_character_layout_list(buf,style->character, |
| 130 |
value->normal->character))) |
| 131 |
goto ERROR3; |
| 132 |
if ((res = psiconv_write_paragraph_layout_list(buf,style->paragraph, |
| 133 |
value->normal->paragraph))) |
| 134 |
goto ERROR3; |
| 135 |
} |
| 136 |
|
| 137 |
for (i = 0; i < psiconv_list_length(value->styles); i++) |
| 138 |
if ((res = psiconv_write_u8(buf,0xff))) |
| 139 |
goto ERROR3; |
| 140 |
res = -PSICONV_E_OK; |
| 141 |
|
| 142 |
ERROR3: |
| 143 |
psiconv_free_character_layout(basechar); |
| 144 |
ERROR2: |
| 145 |
psiconv_free_paragraph_layout(basepara); |
| 146 |
ERROR1: |
| 147 |
return res; |
| 148 |
} |