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