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