… | |
… | |
34 | |
34 | |
35 | #ifdef IMAGEMAGICK |
35 | #ifdef IMAGEMAGICK |
36 | #include <magick/magick.h> |
36 | #include <magick/magick.h> |
37 | #endif |
37 | #endif |
38 | |
38 | |
39 | #include "data.h" |
39 | #include "psiconv/data.h" |
40 | #include "parse.h" |
40 | #include "psiconv/parse.h" |
41 | #include "gen.h" |
41 | #include "gen.h" |
42 | #include "psiconv.h" |
42 | #include "psiconv.h" |
43 | |
43 | |
44 | static void print_help(void); |
44 | static void print_help(void); |
45 | static void print_version(void); |
45 | static void print_version(void); |
46 | static void strtoupper(char *str); |
46 | static void strtoupper(char *str); |
47 | |
|
|
48 | int psiconv_verbosity = PSICONV_VERB_WARN; |
|
|
49 | |
47 | |
50 | void print_help(void) |
48 | void print_help(void) |
51 | { |
49 | { |
52 | psiconv_fileformat ff; |
50 | psiconv_fileformat ff; |
53 | int i,j; |
51 | int i,j; |
… | |
… | |
113 | int c,i,res; |
111 | int c,i,res; |
114 | psiconv_buffer buf; |
112 | psiconv_buffer buf; |
115 | psiconv_file file; |
113 | psiconv_file file; |
116 | psiconv_fileformat ff; |
114 | psiconv_fileformat ff; |
117 | |
115 | |
|
|
116 | psiconv_verbosity = PSICONV_VERB_WARN; |
|
|
117 | |
118 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat)); |
118 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
119 | init_txt(); |
119 | init_txt(); |
120 | init_html(); |
120 | init_html(); |
121 | init_html4(); |
121 | init_html4(); |
122 | init_rtf(); |
122 | init_rtf(); |
123 | init_image(); |
123 | init_image(); |
… | |
… | |
131 | case 'V': print_version(); exit(0); |
131 | case 'V': print_version(); exit(0); |
132 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
132 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
133 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
133 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
134 | break; |
134 | break; |
135 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
135 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
136 | case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break; |
136 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
137 | case 'e': exact = 1; break; |
137 | case 'e': exact = 1; break; |
138 | case 'o': outputfilename = strdup(optarg); break; |
138 | case 'o': outputfilename = strdup(optarg); break; |
139 | case 'T': type = strdup(optarg); break; |
139 | case 'T': type = strdup(optarg); break; |
140 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
140 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
141 | exit(1); |
141 | exit(1); |
… | |
… | |
149 | "Try `-h' for more information\n",stderr); |
149 | "Try `-h' for more information\n",stderr); |
150 | exit(1); |
150 | exit(1); |
151 | } else if (optind == argc-1) |
151 | } else if (optind == argc-1) |
152 | inputfilename = strdup(argv[optind]); |
152 | inputfilename = strdup(argv[optind]); |
153 | |
153 | |
|
|
154 | |
154 | /* Open inputfile for reading */ |
155 | /* Open inputfile for reading */ |
155 | |
156 | |
156 | if (strlen(inputfilename) != 0) { |
157 | if (strlen(inputfilename) != 0) { |
157 | if(stat(inputfilename,&fbuf) < 0) { |
158 | if(stat(inputfilename,&fbuf) < 0) { |
158 | perror(inputfilename); |
159 | perror(inputfilename); |
… | |
… | |
178 | |
179 | |
179 | if (psiconv_parse(buf,&file)) |
180 | if (psiconv_parse(buf,&file)) |
180 | if(exact) |
181 | if(exact) |
181 | exit(1); |
182 | exit(1); |
182 | |
183 | |
183 | /* Open outputfile for writing */ |
184 | /* Set correct output file */ |
184 | if (strlen(outputfilename) != 0) { |
185 | if (strlen(outputfilename) == 0) |
185 | f = fopen(outputfilename,"w"); |
186 | outputfilename = "/dev/stdout"; |
186 | if (! f) { |
|
|
187 | perror(outputfilename); |
|
|
188 | exit(1); |
|
|
189 | } |
|
|
190 | } else |
|
|
191 | f = stdout; |
|
|
192 | |
187 | |
193 | |
|
|
194 | strtoupper(type); |
188 | strtoupper(type); |
195 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
189 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
196 | ff = psiconv_list_get(fileformat_list,i); |
190 | ff = psiconv_list_get(fileformat_list,i); |
197 | if (! strcmp(type,ff->name)) { |
191 | if (! strcmp(type,ff->name)) { |
198 | res = ff->output(f,file,type); |
192 | res = ff->output(outputfilename,file,type); |
199 | if (res) { |
193 | if (res) { |
200 | fprintf(stderr, |
194 | fprintf(stderr, |
201 | "Output format `%s' not permitted for this file type\n",type); |
195 | "Output format `%s' not permitted for this file type\n",type); |
202 | exit(1); |
196 | exit(1); |
203 | } |
197 | } |
… | |
… | |
208 | if (i == psiconv_list_length(fileformat_list)) { |
202 | if (i == psiconv_list_length(fileformat_list)) { |
209 | fprintf(stderr,"Unknown output type: `%s'\n",type); |
203 | fprintf(stderr,"Unknown output type: `%s'\n",type); |
210 | exit(1); |
204 | exit(1); |
211 | } |
205 | } |
212 | |
206 | |
213 | if (strlen(outputfilename) != 0) |
|
|
214 | if (fclose(f)) { |
|
|
215 | perror(outputfilename); |
|
|
216 | exit(1); |
|
|
217 | } |
|
|
218 | |
|
|
219 | psiconv_free_file(file); |
207 | psiconv_free_file(file); |
220 | |
208 | |
221 | exit(0); |
209 | exit(0); |
222 | } |
210 | } |