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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 73 Revision 79
26#include "generate_routines.h" 26#include "generate_routines.h"
27 27
28 28
29int psiconv_write(psiconv_buffer *buf,const psiconv_file value) 29int psiconv_write(psiconv_buffer *buf,const psiconv_file value)
30{ 30{
31 int allocated = 0;
32 int res; 31 int res;
33 32
34 if (!value) { 33 if (!value) {
35 psiconv_warn(0,0,"Can't parse to an empty buffer!"); 34 psiconv_warn(0,0,"Can't parse to an empty buffer!");
36 return -PSICONV_E_OTHER; 35 return -PSICONV_E_OTHER;
37 } 36 }
38 if (!*buf) {
39 if (!(*buf = psiconv_new_buffer())) 37 if (!(*buf = psiconv_buffer_new(0)))
40 return -PSICONV_E_NOMEM; 38 return -PSICONV_E_NOMEM;
41 allocated = 1;
42 }
43 39
44#if 0 40#if 0
45 if (value->type == psiconv_word_file) { 41 if (value->type == psiconv_word_file) {
46 if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file)))) 42 if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file))))
47 goto ERROR; 43 goto ERROR;
71 goto ERROR; 67 goto ERROR;
72 } 68 }
73 return -PSICONV_E_OK; 69 return -PSICONV_E_OK;
74 70
75ERROR: 71ERROR:
76 if (allocated)
77 psiconv_free_buffer(*buf); 72 psiconv_buffer_free(*buf);
78 return res; 73 return res;
79} 74}
80 75
81int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value) 76int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value)
82{ 77{
100 if (!(entry = malloc(sizeof(*entry)))) { 95 if (!(entry = malloc(sizeof(*entry)))) {
101 res = -PSICONV_E_NOMEM; 96 res = -PSICONV_E_NOMEM;
102 goto ERROR2; 97 goto ERROR2;
103 } 98 }
104 99
100 /* Base offset is 0x18: 0x10 header section plus the section table offset */
105 if (!(extra_buf = psiconv_new_buffer())) { 101 if (!(extra_buf = psiconv_buffer_new(0x14))) {
106 res = -PSICONV_E_NOMEM; 102 res = -PSICONV_E_NOMEM;
107 goto ERROR3; 103 goto ERROR3;
108 } 104 }
109 105
110 if (!(base_char = psiconv_basic_character_layout())) { 106 if (!(base_char = psiconv_basic_character_layout())) {
121 PSICONV_ID_TEXTED))) 117 PSICONV_ID_TEXTED)))
122 goto ERROR6; 118 goto ERROR6;
123 119
124 120
125 entry->id = PSICONV_ID_APPL_ID_SECTION; 121 entry->id = PSICONV_ID_APPL_ID_SECTION;
126 entry->offset = psiconv_list_length(extra_buf) + 0x14; 122 entry->offset = psiconv_buffer_length(extra_buf) +
123 psiconv_buffer_base_offset(extra_buf);
127 if ((res = psiconv_list_add(section_table,&entry))) 124 if ((res = psiconv_list_add(section_table,entry)))
128 goto ERROR6; 125 goto ERROR6;
129 if ((res=psiconv_write_application_id_section(extra_buf, 126 if ((res=psiconv_write_application_id_section(extra_buf,
130 PSICONV_ID_TEXTED,"TextEd.app"))) 127 PSICONV_ID_TEXTED,"TextEd.app")))
131 goto ERROR6; 128 goto ERROR6;
132 129
133 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 130 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
134 entry->offset = psiconv_list_length(extra_buf) + 0x14; 131 entry->offset = psiconv_buffer_length(extra_buf) +
132 psiconv_buffer_base_offset(extra_buf);
135 if ((res = psiconv_list_add(section_table,&entry))) 133 if ((res = psiconv_list_add(section_table,entry)))
136 goto ERROR6; 134 goto ERROR6;
137 if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec))) 135 if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec)))
138 goto ERROR6; 136 goto ERROR6;
139 137
140 entry->id = PSICONV_ID_TEXTED; 138 entry->id = PSICONV_ID_TEXTED;
141 entry->offset = psiconv_list_length(extra_buf) + 0x14; 139 entry->offset = psiconv_buffer_length(extra_buf) +
140 psiconv_buffer_base_offset(extra_buf);
142 if ((res = psiconv_list_add(section_table,&entry))) 141 if ((res = psiconv_list_add(section_table,entry)))
143 goto ERROR6; 142 goto ERROR6;
144 if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec, 143 if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec,
145 base_char,base_para))) 144 base_char,base_para)))
146 goto ERROR6; 145 goto ERROR6;
147 146
148 if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf) + 0x14))) 147 if ((res = psiconv_write_u32(buf,psiconv_buffer_length(extra_buf) +
148 psiconv_buffer_base_offset(extra_buf))))
149 goto ERROR6; 149 goto ERROR6;
150 150
151 if ((res = psiconv_list_concat(buf,extra_buf))) 151 if ((res = psiconv_buffer_concat(buf,extra_buf)))
152 goto ERROR6; 152 goto ERROR6;
153 153
154 res = psiconv_write_section_table_section(buf,section_table); 154 res = psiconv_write_section_table_section(buf,section_table);
155 155
156ERROR6: 156ERROR6:
157 psiconv_free_paragraph_layout(base_para); 157 psiconv_free_paragraph_layout(base_para);
158ERROR5: 158ERROR5:
159 psiconv_free_character_layout(base_char); 159 psiconv_free_character_layout(base_char);
160ERROR4: 160ERROR4:
161 psiconv_free_buffer(extra_buf); 161 psiconv_buffer_free(extra_buf);
162ERROR3: 162ERROR3:
163 free(entry); 163 free(entry);
164ERROR2: 164ERROR2:
165 psiconv_list_free(section_table); 165 psiconv_list_free(section_table);
166ERROR1: 166ERROR1:

Legend:
Removed from v.73  
changed lines
  Added in v.79

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