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