--- psiconv/trunk/program/psiconv/psiconv.c 1999/11/30 00:26:55 33 +++ psiconv/trunk/program/psiconv/psiconv.c 1999/12/02 17:18:55 34 @@ -25,16 +25,21 @@ #include #include #include +#include +#include #ifdef HAVE_UNISTD_H #include #endif -#include -#include +#ifdef IMAGEMAGICK +#include +#endif + #include "data.h" #include "parse.h" #include "gen.h" +#include "psiconv.h" static void print_help(void); static void print_version(void); @@ -44,6 +49,9 @@ void print_help(void) { + psiconv_fileformat ff; + int i,j; + puts("Syntax: psiconv [OPTIONS..] [FILE]"); puts("Convert the psion Word file FILE to a HTML file"); puts("If FILE is not specified, use stdin"); @@ -57,10 +65,13 @@ puts(" -v, --verbose Show progress indicators on stderr"); puts(""); puts("The following output types are known:"); - puts(" HTML (default)"); - puts(" HTML4"); - puts(" ASCII"); - puts(" RTF"); + for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { + ff = psiconv_list_get(fileformat_list,i); + printf(" %s",ff->name); + for (j = strlen(ff->name); j < 15; j++) + putchar(' '); + puts(ff->description); + } } void print_version(void) @@ -99,9 +110,17 @@ char *type = strdup("HTML"); int exact=0; - int c; + int c,i,res; psiconv_buffer buf; psiconv_file file; + psiconv_fileformat ff; + + fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat)); + init_txt(); + init_html(); + init_html4(); + init_rtf(); + init_image(); while(1) { c = getopt_long(argc,argv,short_options, long_options, &option_index); @@ -118,7 +137,7 @@ case 'e': exact = 1; break; case 'o': outputfilename = strdup(optarg); break; case 'T': type = strdup(optarg); break; - case '?': case ':': fputs("Try `-h' for more information",stderr); + case '?': case ':': fputs("Try `-h' for more information\n",stderr); exit(1); default: fprintf(stderr,"Internal error: getopt_long returned character " "code 0%o ?? (contact the author)\n", c); @@ -171,18 +190,22 @@ } else f = stdout; + strtoupper(type); - if (! strcmp(type,"HTML")) - psiconv_gen_html(f,file); - else if (! strcmp(type,"HTML4")) - psiconv_gen_html4(f,file); - else if (! strcmp(type,"ASCII")) - psiconv_gen_txt(f,file); - else if (! strcmp(type,"RTF")) - psiconv_gen_rtf(f,file); - else if (! strcmp(type,"IMAGE")) - psiconv_gen_image(f,file); - else { + for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { + ff = psiconv_list_get(fileformat_list,i); + if (! strcmp(type,ff->name)) { + res = ff->output(f,file,type); + if (res) { + fprintf(stderr, + "Output format `%s' not permitted for this file type\n",type); + exit(1); + } + break; + } + } + + if (i == psiconv_list_length(fileformat_list)) { fprintf(stderr,"Unknown output type: `%s'\n",type); exit(1); }