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

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

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