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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 75 - (hide annotations)
Sun Dec 24 17:26:24 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 3648 byte(s)
(Frodo) Several things:

 * Added the extra directory to the build process, added a README.
 * Made checkuid compile cleanly
 * Added rewrite utility

1 frodo 73 /*
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 (!(entry = malloc(sizeof(*entry))))
55     return -PSICONV_E_NOMEM;
56    
57     if ((res = psiconv_write_u8(buf,2 * sizeof(psiconv_u32) *
58     psiconv_list_length(value))))
59     goto ERROR;
60     for (i = 0; i < psiconv_list_length(value); i++) {
61     if (!(entry = psiconv_list_get(value,i))) {
62     psiconv_warn(0,psiconv_list_length(buf),"Massive memory corruption");
63     res = -PSICONV_E_NOMEM;
64     goto ERROR;
65     }
66     if ((res = psiconv_write_u32(buf,entry->id)))
67     goto ERROR;
68     if ((res = psiconv_write_u32(buf,entry->offset)))
69     goto ERROR;
70     }
71     res = -PSICONV_E_OK;
72     ERROR:
73     free(entry);
74     return res;
75     }
76    
77     int psiconv_write_application_id_section(psiconv_buffer buf,psiconv_u32 id,
78     const psiconv_string_t text)
79     {
80     int res;
81     if ((res = psiconv_write_u32(buf,id)))
82     return res;
83     return psiconv_write_string(buf,text);
84     }
85    
86     int psiconv_write_text_section(psiconv_buffer buf,
87     const psiconv_text_and_layout value)
88     {
89     int res;
90     psiconv_buffer extra_buf;
91     int i,j;
92     psiconv_paragraph paragraph;
93    
94     if (!value) {
95     psiconv_warn(0,psiconv_list_length(buf),"Null text section");
96     return -PSICONV_E_GENERATE;
97     }
98    
99     if (!(extra_buf = psiconv_new_buffer()))
100     return -PSICONV_E_NOMEM;
101     for (i = 0; i < psiconv_list_length(value); i++) {
102     if (!(paragraph = psiconv_list_get(value,i))) {
103     psiconv_warn(0,psiconv_list_length(buf),"Massive memory corruption");
104     res = -PSICONV_E_OTHER;
105     goto ERROR;
106     }
107     for (j = 0; j < strlen(paragraph->text); j++)
108     if ((res = psiconv_write_u8(extra_buf,paragraph->text[j])))
109     goto ERROR;
110     psiconv_write_u8(extra_buf,0x06);
111     }
112     if ((res = psiconv_write_X(buf,psiconv_list_length(extra_buf))))
113     goto ERROR;
114     res = psiconv_list_concat(buf,extra_buf);
115    
116     ERROR:
117     psiconv_free_buffer(extra_buf);
118 frodo 75 return res;
119 frodo 73 }

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