/[public]/psiconv/trunk/program/psiconv/psiconv.c
ViewVC logotype

Diff of /psiconv/trunk/program/psiconv/psiconv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 17 Revision 34
18*/ 18*/
19 19
20/* Driver program */ 20/* Driver program */
21 21
22#include "config.h" 22#include "config.h"
23#include "compat.h"
23#include <getopt.h> 24#include <getopt.h>
24#include <stdio.h> 25#include <stdio.h>
25#include <sys/stat.h> 26#include <sys/stat.h>
26#include <stdlib.h> 27#include <stdlib.h>
28#include <string.h>
29#include <ctype.h>
27 30
28#ifdef HAVE_UNISTD_H 31#ifdef HAVE_UNISTD_H
29#include <unistd.h> 32#include <unistd.h>
30#endif 33#endif
31 34
32#include <string.h> 35#ifdef IMAGEMAGICK
33#include <ctype.h> 36#include <magick/magick.h>
37#endif
38
34#include "data.h" 39#include "data.h"
35#include "parse.h" 40#include "parse.h"
36#include "gen.h" 41#include "gen.h"
42#include "psiconv.h"
37 43
38static void print_help(void); 44static void print_help(void);
39static void print_version(void); 45static void print_version(void);
40static void strtoupper(char *str); 46static void strtoupper(char *str);
41 47
42int psiconv_verbosity = PSICONV_VERB_WARN; 48int psiconv_verbosity = PSICONV_VERB_WARN;
43 49
44void print_help(void) 50void print_help(void)
45{ 51{
52 psiconv_fileformat ff;
53 int i,j;
54
46 puts("Syntax: psiconv [OPTIONS..] [FILE]"); 55 puts("Syntax: psiconv [OPTIONS..] [FILE]");
47 puts("Convert the psion Word file FILE to a HTML file"); 56 puts("Convert the psion Word file FILE to a HTML file");
48 puts("If FILE is not specified, use stdin"); 57 puts("If FILE is not specified, use stdin");
49 puts(" -d, --debug Show debug information on stderr"); 58 puts(" -d, --debug Show debug information on stderr");
50 puts(" -e, --exact Quit on any parse errors or warnings"); 59 puts(" -e, --exact Quit on any parse errors or warnings");
54 puts(" -T, --type=FILETYPE Output type"); 63 puts(" -T, --type=FILETYPE Output type");
55 puts(" -V, --version Display the program version and exit"); 64 puts(" -V, --version Display the program version and exit");
56 puts(" -v, --verbose Show progress indicators on stderr"); 65 puts(" -v, --verbose Show progress indicators on stderr");
57 puts(""); 66 puts("");
58 puts("The following output types are known:"); 67 puts("The following output types are known:");
59 puts(" HTML (default)"); 68 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) {
60 puts(" HTML4"); 69 ff = psiconv_list_get(fileformat_list,i);
61 puts(" ASCII"); 70 printf(" %s",ff->name);
62 puts(" RTF"); 71 for (j = strlen(ff->name); j < 15; j++)
72 putchar(' ');
73 puts(ff->description);
74 }
63} 75}
64 76
65void print_version(void) 77void print_version(void)
66{ 78{
67 printf("Version %s\n",VERSION); 79 printf("Version %s\n",VERSION);
96 const char *inputfilename = ""; 108 const char *inputfilename = "";
97 const char *outputfilename = ""; 109 const char *outputfilename = "";
98 char *type = strdup("HTML"); 110 char *type = strdup("HTML");
99 int exact=0; 111 int exact=0;
100 112
101 int c; 113 int c,i,res;
102 psiconv_buffer buf; 114 psiconv_buffer buf;
103 psiconv_file file; 115 psiconv_file file;
116 psiconv_fileformat ff;
117
118 fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat));
119 init_txt();
120 init_html();
121 init_html4();
122 init_rtf();
123 init_image();
104 124
105 while(1) { 125 while(1) {
106 c = getopt_long(argc,argv,short_options, long_options, &option_index); 126 c = getopt_long(argc,argv,short_options, long_options, &option_index);
107 if (c == -1) 127 if (c == -1)
108 break; 128 break;
115 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; 135 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break;
116 case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break; 136 case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break;
117 case 'e': exact = 1; break; 137 case 'e': exact = 1; break;
118 case 'o': outputfilename = strdup(optarg); break; 138 case 'o': outputfilename = strdup(optarg); break;
119 case 'T': type = strdup(optarg); break; 139 case 'T': type = strdup(optarg); break;
120 case '?': case ':': fputs("Try `-h' for more information",stderr); 140 case '?': case ':': fputs("Try `-h' for more information\n",stderr);
121 exit(1); 141 exit(1);
122 default: fprintf(stderr,"Internal error: getopt_long returned character " 142 default: fprintf(stderr,"Internal error: getopt_long returned character "
123 "code 0%o ?? (contact the author)\n", c); 143 "code 0%o ?? (contact the author)\n", c);
124 exit(1); break; 144 exit(1); break;
125 } 145 }
168 exit(1); 188 exit(1);
169 } 189 }
170 } else 190 } else
171 f = stdout; 191 f = stdout;
172 192
193
173 strtoupper(type); 194 strtoupper(type);
174 if (! strcmp(type,"HTML")) 195 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) {
175 psiconv_gen_html(f,file); 196 ff = psiconv_list_get(fileformat_list,i);
176 else if (! strcmp(type,"HTML4")) 197 if (! strcmp(type,ff->name)) {
177 psiconv_gen_html4(f,file); 198 res = ff->output(f,file,type);
178 else if (! strcmp(type,"ASCII")) 199 if (res) {
179 psiconv_gen_txt(f,file); 200 fprintf(stderr,
180 else if (! strcmp(type,"RTF")) 201 "Output format `%s' not permitted for this file type\n",type);
181 psiconv_gen_rtf(f,file); 202 exit(1);
182 else if (! strcmp(type,"IMAGE")) 203 }
183 psiconv_gen_image(f,file); 204 break;
184 else { 205 }
206 }
207
208 if (i == psiconv_list_length(fileformat_list)) {
185 fprintf(stderr,"Unknown output type: `%s'\n",type); 209 fprintf(stderr,"Unknown output type: `%s'\n",type);
186 exit(1); 210 exit(1);
187 } 211 }
188 212
189 if (strlen(outputfilename) != 0) 213 if (strlen(outputfilename) != 0)

Legend:
Removed from v.17  
changed lines
  Added in v.34

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26