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

Contents of /psiconv/trunk/lib/psiconv/generate_common.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (show annotations)
Mon Dec 25 00:26:53 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 3472 byte(s)
(Frodo) Added word-specific generation routines

1 /*
2 generate_common.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 #include <stdlib.h>
23 #include <string.h>
24
25 #include "generate_routines.h"
26 #include "error.h"
27
28
29 /* Maybe use a psiconv_header_section variable instead? */
30 int psiconv_write_header_section(psiconv_buffer buf,psiconv_u32 uid1,
31 psiconv_u32 uid2, psiconv_u32 uid3)
32 {
33 int res;
34 if ((res = psiconv_write_u32(buf,uid1)))
35 return res;
36 if ((res = psiconv_write_u32(buf,uid2)))
37 return res;
38 if ((res = psiconv_write_u32(buf,uid3)))
39 return res;
40 return psiconv_write_u32(buf,psiconv_checkuid(uid1,uid2,uid3));
41 }
42
43 int psiconv_write_section_table_section(psiconv_buffer buf,
44 const psiconv_section_table_section value)
45 {
46 int res,i;
47 psiconv_section_table_entry entry;
48
49 if (!value) {
50 psiconv_warn(0,psiconv_list_length(buf),"Null section table section");
51 return -PSICONV_E_GENERATE;
52 }
53
54 if ((res = psiconv_write_u8(buf,2 * psiconv_list_length(value))))
55 return res;
56 for (i = 0; i < psiconv_list_length(value); i++) {
57 if (!(entry = psiconv_list_get(value,i))) {
58 psiconv_warn(0,psiconv_list_length(buf),"Massive memory corruption");
59 return -PSICONV_E_NOMEM;
60 }
61 if ((res = psiconv_write_u32(buf,entry->id)))
62 return res;
63 if ((res = psiconv_write_u32(buf,entry->offset)))
64 return res;
65 }
66 return -PSICONV_E_OK;
67 }
68
69 int psiconv_write_application_id_section(psiconv_buffer buf,psiconv_u32 id,
70 const psiconv_string_t text)
71 {
72 int res;
73 if ((res = psiconv_write_u32(buf,id)))
74 return res;
75 return psiconv_write_string(buf,text);
76 }
77
78 int psiconv_write_text_section(psiconv_buffer buf,
79 const psiconv_text_and_layout value)
80 {
81 int res;
82 psiconv_buffer extra_buf;
83 int i,j;
84 psiconv_paragraph paragraph;
85
86 if (!value) {
87 psiconv_warn(0,psiconv_list_length(buf),"Null text section");
88 return -PSICONV_E_GENERATE;
89 }
90
91 if (!(extra_buf = psiconv_new_buffer()))
92 return -PSICONV_E_NOMEM;
93 for (i = 0; i < psiconv_list_length(value); i++) {
94 if (!(paragraph = psiconv_list_get(value,i))) {
95 psiconv_warn(0,psiconv_list_length(buf),"Massive memory corruption");
96 res = -PSICONV_E_OTHER;
97 goto ERROR;
98 }
99 for (j = 0; j < strlen(paragraph->text); j++)
100 if ((res = psiconv_write_u8(extra_buf,paragraph->text[j])))
101 goto ERROR;
102 psiconv_write_u8(extra_buf,0x06);
103 }
104 if ((res = psiconv_write_X(buf,psiconv_list_length(extra_buf))))
105 goto ERROR;
106 res = psiconv_list_concat(buf,extra_buf);
107
108 ERROR:
109 psiconv_free_buffer(extra_buf);
110 return res;
111 }

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