… | |
… | |
19 | */ |
19 | */ |
20 | |
20 | |
21 | #include "config.h" |
21 | #include "config.h" |
22 | #include <stdio.h> |
22 | #include <stdio.h> |
23 | #include <string.h> |
23 | #include <string.h> |
24 | #include "data.h" |
24 | #include "psiconv/data.h" |
25 | #include "list.h" |
25 | #include "psiconv/list.h" |
26 | #include "gen.h" |
26 | #include "gen.h" |
|
|
27 | #include "psiconv.h" |
|
|
28 | |
|
|
29 | #ifdef DMALLOC |
|
|
30 | #include "dmalloc.h" |
|
|
31 | #endif |
27 | |
32 | |
28 | |
33 | |
29 | /* |
34 | /* |
30 | * Various string tables for HTML4 settings |
35 | * Various string tables for HTML4 settings |
31 | */ |
36 | */ |
… | |
… | |
93 | static void psiconv_gen_txt_texted(FILE * of, psiconv_texted_f tf) |
98 | static void psiconv_gen_txt_texted(FILE * of, psiconv_texted_f tf) |
94 | { |
99 | { |
95 | int i; |
100 | int i; |
96 | psiconv_paragraph para; |
101 | psiconv_paragraph para; |
97 | |
102 | |
|
|
103 | if (tf->page_sec->header->text) { |
98 | if (tf->page_sec->header->on_first_page) { |
104 | if (tf->page_sec->header->on_first_page) { |
99 | for (i=0; i < psiconv_list_length(tf->page_sec->header->text->paragraphs); i++) { |
105 | for (i=0; i < psiconv_list_length(tf->page_sec->header->text->paragraphs); i++) { |
100 | para = psiconv_list_get(tf->page_sec->header->text->paragraphs, i); |
106 | para = psiconv_list_get(tf->page_sec->header->text->paragraphs, i); |
101 | fput_text(of, para->text, strlen(para->text)); |
107 | fput_text(of, para->text, strlen(para->text)); |
102 | fputs("\n", of); |
108 | fputs("\n", of); |
|
|
109 | } |
103 | } |
110 | } |
104 | } |
111 | } |
105 | fputs("\n",of); |
112 | fputs("\n",of); |
106 | |
113 | |
107 | for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { |
114 | for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { |
108 | para = psiconv_list_get(tf->texted_sec->paragraphs, i); |
115 | para = psiconv_list_get(tf->texted_sec->paragraphs, i); |
109 | fput_para(of, para,0); |
116 | fput_para(of, para,0); |
110 | } |
117 | } |
111 | |
118 | |
112 | fputs("\n",of); |
119 | fputs("\n",of); |
|
|
120 | if (tf->page_sec->header->text) { |
113 | for (i=0; i < psiconv_list_length(tf->page_sec->footer->text->paragraphs); i++) { |
121 | for (i=0; i < psiconv_list_length(tf->page_sec->footer->text->paragraphs); i++) { |
114 | para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i); |
122 | para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i); |
115 | fput_text(of, para->text, strlen(para->text)); |
123 | fput_text(of, para->text, strlen(para->text)); |
116 | fputs("\n", of); |
124 | fputs("\n", of); |
|
|
125 | } |
117 | } |
126 | } |
118 | } |
127 | } |
119 | |
128 | |
120 | static void psiconv_gen_txt_word(FILE * of, psiconv_word_f wf) |
129 | static void psiconv_gen_txt_word(FILE * of, psiconv_word_f wf) |
121 | { |
130 | { |
… | |
… | |
142 | fput_text(of, para->text, strlen(para->text)); |
151 | fput_text(of, para->text, strlen(para->text)); |
143 | fputs("\n\n", of); |
152 | fputs("\n\n", of); |
144 | } |
153 | } |
145 | } |
154 | } |
146 | |
155 | |
147 | void psiconv_gen_txt(FILE * of, psiconv_file file) |
156 | static int psiconv_gen_txt(const char *filename, const psiconv_file file, |
|
|
157 | const char *dest) |
148 | { |
158 | { |
|
|
159 | FILE *of = fopen(filename,"w"); |
|
|
160 | if (! of) |
|
|
161 | return -1; |
|
|
162 | |
149 | if (file->type == psiconv_word_file) |
163 | if (file->type == psiconv_word_file) { |
150 | psiconv_gen_txt_word(of,(psiconv_word_f) file->file); |
164 | psiconv_gen_txt_word(of,(psiconv_word_f) file->file); |
151 | else if (file->type == psiconv_texted_file) |
165 | } else if (file->type == psiconv_texted_file) { |
152 | psiconv_gen_txt_texted(of,(psiconv_texted_f) file->file); |
166 | psiconv_gen_txt_texted(of,(psiconv_texted_f) file->file); |
153 | else |
167 | } else { |
|
|
168 | fclose(of); |
154 | return; |
169 | return -1; |
|
|
170 | } |
|
|
171 | return fclose(of); |
155 | } |
172 | } |
156 | |
173 | |
|
|
174 | static struct psiconv_fileformat_s ff = |
|
|
175 | { |
|
|
176 | "ASCII", |
|
|
177 | "Plain text without much layout", |
|
|
178 | psiconv_gen_txt |
|
|
179 | }; |
|
|
180 | |
|
|
181 | void init_txt(void) |
|
|
182 | { |
|
|
183 | psiconv_list_add(fileformat_list,&ff); |
|
|
184 | } |
|
|
185 | |