--- psiconv/trunk/program/psiconv/psiconv.c 2000/10/21 00:49:13 53 +++ psiconv/trunk/program/psiconv/psiconv.c 2003/11/11 18:58:55 152 @@ -17,6 +17,22 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* + 2002/Apr. Keita KAWABE + * Support for narrow build Asian Psions added. + + Now psiconv understands -u or --UTF8 option. + This option is passed to output_function as the fourth parameter + (thus the typedef of output_function was changed). + + If a called generator (gen_*.c) can handle UTF8, then it handles + the character conversion etc. accordingly. + + * psiconv seemed to want to take the argument of the options + case-insensitively (i.e. LaTeX -> LATEX), but that was not working + under my environment. Fixed it. +*/ + /* Driver program */ #include "config.h" @@ -33,11 +49,11 @@ #endif #ifdef IMAGEMAGICK -#include +#include "magick-aux.h" #endif -#include "data.h" -#include "parse.h" +#include "psiconv/data.h" +#include "psiconv/parse.h" #include "gen.h" #include "psiconv.h" @@ -45,24 +61,22 @@ static void print_version(void); static void strtoupper(char *str); -int psiconv_verbosity = PSICONV_VERB_WARN; - 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("Convert the psion Word file FILE to other formats"); puts("If FILE is not specified, use stdin"); puts(" -d, --debug Show debug information on stderr"); - puts(" -e, --exact Quit on any parse errors or warnings"); puts(" -h, --help Display this help and exit"); puts(" -o, --outputfile Output to file instead of stdout"); puts(" -s, --silent Do not even show warnings on stderr"); puts(" -T, --type=FILETYPE Output type"); puts(" -V, --version Display the program version and exit"); puts(" -v, --verbose Show progress indicators on stderr"); + puts(" -u, --UTF8 Input file is encoded in UTF8"); puts(""); puts("The following output types are known:"); for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { @@ -72,6 +86,9 @@ putchar(' '); puts(ff->description); } + puts(""); + puts("When using UTF8 with LaTeX type, the resulting LaTeX source should be converted"); + puts(" to a suitable encoding for your LaTeX installation before being typeset"); } void print_version(void) @@ -97,10 +114,10 @@ {"silent",no_argument,NULL,'s'}, {"outputfile",required_argument,NULL,'o'}, {"type",required_argument,NULL,'T'}, - {"exact",no_argument,NULL,'e'}, + {"UTF8",no_argument,NULL,'u'}, {0,0,0,0} }; - const char* short_options = "hVvsdo:eT:"; + const char* short_options = "hVvsdo:uT:"; int option_index; FILE * f; struct stat fbuf; @@ -108,17 +125,20 @@ const char *inputfilename = ""; const char *outputfilename = ""; char *type = strdup("HTML3"); - int exact=0; + psiconv_encoding encoding_type=PSICONV_ENCODING_CP1252; int c,i,res; psiconv_buffer buf; psiconv_file file; psiconv_fileformat ff; - fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat)); + psiconv_verbosity = PSICONV_VERB_WARN; + + fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); init_txt(); init_html(); init_html4(); + init_latex(); init_rtf(); init_image(); @@ -133,10 +153,10 @@ psiconv_verbosity = PSICONV_VERB_PROGRESS; break; case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; - case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break; - case 'e': exact = 1; break; + case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; case 'o': outputfilename = strdup(optarg); break; case 'T': type = strdup(optarg); break; + case 'u': encoding_type = PSICONV_ENCODING_UTF8; break; case '?': case ':': fputs("Try `-h' for more information\n",stderr); exit(1); default: fprintf(stderr,"Internal error: getopt_long returned character " @@ -151,6 +171,7 @@ } else if (optind == argc-1) inputfilename = strdup(argv[optind]); + /* Open inputfile for reading */ if (strlen(inputfilename) != 0) { @@ -166,9 +187,8 @@ } else f = stdin; - buf = psiconv_list_new(sizeof(psiconv_u8)); - while (! feof(f)) - psiconv_list_fread(buf,1024,f); + buf = psiconv_buffer_new(); + psiconv_buffer_fread_all(buf,f); if (strlen(inputfilename) != 0) if (fclose(f)) { @@ -176,9 +196,11 @@ exit(1); } - if (psiconv_parse(buf,&file)) - if(exact) - exit(1); + if (psiconv_parse(buf,&file) || (file->type == psiconv_unknown_file)) + { + fprintf(stderr,"Parse error\n"); + exit(1); + } /* Set correct output file */ if (strlen(outputfilename) == 0) @@ -187,8 +209,8 @@ strtoupper(type); 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(outputfilename,file,type); + if (! strcasecmp(type,ff->name)) { + res = ff->output(outputfilename,file,type, encoding_type); if (res) { fprintf(stderr, "Output format `%s' not permitted for this file type\n",type);