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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 80 - (hide annotations)
Wed Dec 27 02:12:23 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 5127 byte(s)
(Frodo) Many changes. Layout sections now work!

* Added list_empty, list_replace
* Added relocation to buffers, removed base address
* Added buffer_resolve, buffer_add_reference, buffer_add_target,
  psiconv_unique_id functions
* Modifified other buffer functions to work with references
* Added comments to buffer.h
* Added write_offset function
* Added reference support in functions where needed
* Corrected extra/rewrite error message
* Corrected numerous bugs to make layouts work.

1 frodo 73 /*
2     generate_driver.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 "error.h"
26     #include "generate_routines.h"
27    
28    
29     int psiconv_write(psiconv_buffer *buf,const psiconv_file value)
30     {
31     int res;
32    
33     if (!value) {
34     psiconv_warn(0,0,"Can't parse to an empty buffer!");
35     return -PSICONV_E_OTHER;
36     }
37 frodo 80 if (!(*buf = psiconv_buffer_new()))
38 frodo 75 return -PSICONV_E_NOMEM;
39 frodo 73
40     #if 0
41     if (value->type == psiconv_word_file) {
42     if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file))))
43     goto ERROR;
44     } else
45     #endif
46     if (value->type == psiconv_texted_file) {
47     if ((res =psiconv_write_texted_file(*buf,
48     (psiconv_texted_f) (value->file))))
49     goto ERROR;
50     #if 0
51     } else if (value->type == psiconv_sketch_file) {
52 frodo 80 if ((res =psiconv_write_sketch_file(*buf,
53 frodo 73 (psiconv_sketch_f) (value->file))))
54     goto ERROR;
55     } else if (value->type == psiconv_mbm_file) {
56 frodo 80 if ((res =psiconv_write_mbm_file(*buf,
57 frodo 73 (psiconv_mbm_f) (value->file))))
58     goto ERROR;
59     } else if (value->type == psiconv_clipart_file) {
60 frodo 80 if ((res =psiconv_write_clipart_file(*buf,
61 frodo 73 (psiconv_clipart_f) (value->file))))
62     goto ERROR;
63     #endif
64     } else {
65     psiconv_warn(0,0,"Unknown or unsupported file type");
66     res = -PSICONV_E_GENERATE;
67     goto ERROR;
68     }
69 frodo 80 if ((res = psiconv_buffer_resolve(*buf)))
70     goto ERROR;
71 frodo 73 return -PSICONV_E_OK;
72    
73     ERROR:
74 frodo 79 psiconv_buffer_free(*buf);
75 frodo 73 return res;
76     }
77    
78     int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value)
79     {
80     psiconv_character_layout base_char;
81     psiconv_paragraph_layout base_para;
82     int res;
83     psiconv_section_table_section section_table;
84     psiconv_section_table_entry entry;
85 frodo 80 psiconv_u32 section_table_id;
86     psiconv_buffer buf_texted;
87 frodo 73
88     if (!value) {
89     psiconv_warn(0,0,"Null TextEd file");
90     return -PSICONV_E_GENERATE;
91     }
92    
93     if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
94     res = -PSICONV_E_NOMEM;
95     goto ERROR1;
96     }
97    
98     if (!(entry = malloc(sizeof(*entry)))) {
99     res = -PSICONV_E_NOMEM;
100     goto ERROR2;
101     }
102    
103 frodo 80 if (!(base_char = psiconv_basic_character_layout())) {
104 frodo 73 res = -PSICONV_E_NOMEM;
105     goto ERROR3;
106     }
107 frodo 80 if (!(base_para = psiconv_basic_paragraph_layout())) {
108 frodo 73 res = -PSICONV_E_NOMEM;
109     goto ERROR4;
110     }
111    
112     if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
113     PSICONV_ID_DATA_FILE,
114     PSICONV_ID_TEXTED)))
115 frodo 80 goto ERROR5;
116 frodo 73
117 frodo 80 section_table_id = psiconv_buffer_unique_id();
118     if ((res = psiconv_write_offset(buf,section_table_id)))
119     goto ERROR5;
120 frodo 73
121     entry->id = PSICONV_ID_APPL_ID_SECTION;
122 frodo 80 entry->offset = psiconv_buffer_unique_id();
123 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
124 frodo 80 goto ERROR5;
125     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
126     goto ERROR5;
127     if ((res=psiconv_write_application_id_section(buf,
128 frodo 73 PSICONV_ID_TEXTED,"TextEd.app")))
129 frodo 80 goto ERROR5;
130 frodo 73
131     entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
132 frodo 80 entry->offset = psiconv_buffer_unique_id();
133 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
134 frodo 80 goto ERROR5;
135     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
136     goto ERROR5;
137     if ((res = psiconv_write_page_layout_section(buf,value->page_sec)))
138     goto ERROR5;
139 frodo 73
140     entry->id = PSICONV_ID_TEXTED;
141 frodo 80 entry->offset = psiconv_buffer_unique_id();
142 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
143 frodo 80 goto ERROR5;
144     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
145     goto ERROR5;
146     if ((res = psiconv_write_texted_section(buf,value->texted_sec,
147     base_char,base_para,&buf_texted)))
148     goto ERROR5;
149 frodo 73
150 frodo 80 if ((res = psiconv_buffer_concat(buf,buf_texted)))
151 frodo 73 goto ERROR6;
152    
153 frodo 80
154     if ((res = psiconv_buffer_add_target(buf,section_table_id)))
155 frodo 73 goto ERROR6;
156    
157     res = psiconv_write_section_table_section(buf,section_table);
158    
159     ERROR6:
160 frodo 80 psiconv_buffer_free(buf_texted);
161     ERROR5:
162 frodo 73 psiconv_free_paragraph_layout(base_para);
163 frodo 80 ERROR4:
164 frodo 73 psiconv_free_character_layout(base_char);
165     ERROR3:
166     free(entry);
167     ERROR2:
168     psiconv_list_free(section_table);
169     ERROR1:
170     return res;
171     }

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