/[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 185 Revision 196
1/* 1/*
2 psiconv.c - Part of psiconv, a PSION 5 file formats converter 2 psiconv.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20/*
21 2002/Apr. Keita KAWABE
22 * Support for narrow build Asian Psions added.
23
24 Now psiconv understands -u or --UTF8 option.
25 This option is passed to output_function as the fourth parameter
26 (thus the typedef of output_function was changed).
27
28 If a called generator (gen_*.c) can handle UTF8, then it handles
29 the character conversion etc. accordingly.
30
31 * psiconv seemed to want to take the argument of the options
32 case-insensitively (i.e. LaTeX -> LATEX), but that was not working
33 under my environment. Fixed it.
34*/ 18*/
35 19
36/* Driver program */ 20/* Driver program */
37 21
38#include "config.h" 22#include "config.h"
40#include <getopt.h> 24#include <getopt.h>
41#include <stdio.h> 25#include <stdio.h>
42#include <sys/stat.h> 26#include <sys/stat.h>
43#include <stdlib.h> 27#include <stdlib.h>
44#include <string.h> 28#include <string.h>
29#include <strings.h>
45#include <ctype.h> 30#include <ctype.h>
46 31
47#ifdef HAVE_UNISTD_H 32#ifdef HAVE_UNISTD_H
48#include <unistd.h> 33#include <unistd.h>
49#endif 34#endif
69 int i,j; 54 int i,j;
70 55
71 puts("Syntax: psiconv [OPTIONS..] [FILE]"); 56 puts("Syntax: psiconv [OPTIONS..] [FILE]");
72 puts("Convert the psion file FILE to other formats"); 57 puts("Convert the psion file FILE to other formats");
73 puts("If FILE is not specified, use stdin"); 58 puts("If FILE is not specified, use stdin");
74 puts(" -d, --debug Show debug information on stderr");
75 puts(" -e, --encoding Output encoding (default: UTF8)"); 59 puts(" -e, --encoding=ENC Output encoding (default: UTF8)");
76 puts(" -h, --help Display this help and exit"); 60 puts(" -h, --help Display this help and exit");
61 puts(" -n, --noise=LEVEL Select what to print on stderr (overrides psiconv.conf)");
77 puts(" -o, --outputfile Output to file instead of stdout"); 62 puts(" -o, --outputfile Output to file instead of stdout");
78 puts(" -s, --silent Do not even show warnings on stderr");
79 puts(" -T, --type=FILETYPE Output type"); 63 puts(" -T, --type=FILETYPE Output type (default: XHTML or TIFF");
80 puts(" -V, --version Display the program version and exit"); 64 puts(" -V, --version Display the program version and exit");
81 puts(" -v, --verbose Show progress indicators on stderr");
82 puts(""); 65 puts("");
83 puts("The following encodings are currently supported:"); 66 puts("The following encodings are currently supported:");
84 puts(" UTF8 Variable length Unicode encoding"); 67 puts(" UTF8 Variable length Unicode encoding");
85 puts(" UCS2 Fixed 16-bit length Unicode encoding"); 68 puts(" UCS2 Fixed 16-bit length Unicode encoding");
86 puts(" Psion The encoding your Psion uses (as in psiconv.conf)"); 69 puts(" Psion The encoding your Psion uses (as in psiconv.conf)");
87 puts(" ASCII 7-bit ASCII (other symbols are substituted by '?')"); 70 puts(" ASCII 7-bit ASCII (other symbols are substituted by '?')");
88 puts(""); 71 puts("");
72 puts("The following noise levels are currently supported:");
73 puts(" 1 or F: Fatal errors only");
74 puts(" 2 or E: Errors");
75 puts(" 3 or W: Warnings");
76 puts(" 4 or P: Progress indicators");
77 puts(" 5 or D: Debug data");
78 puts("");
79 puts("The following abbreviations are used below:");
80 puts(" C - processes ClipArt files");
81 puts(" c - processes ClipArt files containing only one image");
82 puts(" M - processes MBM files");
83 puts(" m - processes MBM files containing only one image");
84 puts(" S - processes Sketch files");
85 puts(" T - processes TextEd files");
86 puts(" W - processes Word files");
87 puts("");
89 puts("The following output types are known:"); 88 puts("The following output types are known:");
90 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { 89 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) {
91 ff = psiconv_list_get(fileformat_list,i); 90 ff = psiconv_list_get(fileformat_list,i);
92 printf(" %s",ff->name); 91 printf(" %s",ff->name);
93 for (j = strlen(ff->name); j < 15; j++) 92 for (j = strlen(ff->name); j < 10; j++)
94 putchar(' '); 93 putchar(' ');
94 printf("[%c%c%c%c%c] ",
95 ff->supported_format & FORMAT_CLIPART_MULTIPLE?'C':
96 ff->supported_format & FORMAT_CLIPART_SINGLE?'c':' ',
97 ff->supported_format & FORMAT_MBM_MULTIPLE?'M':
98 ff->supported_format & FORMAT_MBM_SINGLE?'m':' ',
99 ff->supported_format & FORMAT_SKETCH?'S':' ',
100 ff->supported_format & FORMAT_TEXTED?'T':' ',
101 ff->supported_format & FORMAT_WORD?'W':' ');
95 puts(ff->description); 102 puts(ff->description);
96 } 103 }
97 puts(""); 104 puts("");
98 puts("When using UTF8 with LaTeX type, the resulting LaTeX source should be converted"); 105 puts("When using UTF8 with LaTeX type, the resulting LaTeX source should be converted");
99 puts(" to a suitable encoding for your LaTeX installation before being typeset"); 106 puts(" to a suitable encoding for your LaTeX installation before being typeset");
115{ 122{
116 struct option long_options[] = 123 struct option long_options[] =
117 { 124 {
118 {"help",no_argument,NULL,'h'}, 125 {"help",no_argument,NULL,'h'},
119 {"version",no_argument,NULL,'V'}, 126 {"version",no_argument,NULL,'V'},
120 {"verbose",no_argument,NULL,'v'}, 127 {"noise",required_argument,NULL,'n'},
121 {"debug",no_argument,NULL,'d'},
122 {"silent",no_argument,NULL,'s'},
123 {"outputfile",required_argument,NULL,'o'}, 128 {"outputfile",required_argument,NULL,'o'},
124 {"type",required_argument,NULL,'T'}, 129 {"type",required_argument,NULL,'T'},
125 {"encoding",no_argument,NULL,'e'}, 130 {"encoding",no_argument,NULL,'e'},
126 {0,0,0,0} 131 {0,0,0,0}
127 }; 132 };
128 const char* short_options = "hVvsdo:e:T:"; 133 const char* short_options = "hVn:o:e:T:";
129 int option_index; 134 int option_index;
130 FILE * f; 135 FILE * f;
131 struct stat fbuf; 136 struct stat fbuf;
132 137
133 const char *inputfilename = ""; 138 const char *inputfilename = "";
134 const char *outputfilename = ""; 139 const char *outputfilename = "";
135 char *type = strdup("HTML3"); 140 char *type = NULL;
136 encoding encoding_type=ENCODING_UTF8; 141 encoding encoding_type=ENCODING_UTF8;
137 psiconv_list outputlist; 142 psiconv_list outputlist;
138 143
139 int c,i,res; 144 int c,i,res;
140 psiconv_buffer buf; 145 psiconv_buffer buf;
148 fputs("Out of memory error",stderr); 153 fputs("Out of memory error",stderr);
149 exit(1); 154 exit(1);
150 } 155 }
151 156
152 init_txt(); 157 init_txt();
153#if 0
154 init_html(); 158 init_xhtml();
155 init_html4(); 159 init_html4();
156 init_latex();
157 init_rtf();
158 init_image(); 160 init_image();
159#endif
160 161
161 while(1) { 162 while(1) {
162 c = getopt_long(argc,argv,short_options, long_options, &option_index); 163 c = getopt_long(argc,argv,short_options, long_options, &option_index);
163 if (c == -1) 164 if (c == -1)
164 break; 165 break;
165 switch(c) { 166 switch(c) {
166 case 'h': print_help(); exit(0); 167 case 'h': print_help(); exit(0);
167 case 'V': print_version(); exit(0); 168 case 'V': print_version(); exit(0);
168 case 'v': if (config->verbosity < PSICONV_VERB_PROGRESS) 169 case 'n': switch(optarg[0]) {
170 case '1': case 'F':case 'f':
171 config->verbosity=PSICONV_VERB_FATAL;
172 break;
173 case '2': case 'E':case 'e':
174 config->verbosity=PSICONV_VERB_ERROR;
175 break;
176 case '3': case 'W':case 'w':
177 config->verbosity=PSICONV_VERB_WARN;
178 break;
179 case '4': case 'P':case 'p':
169 config->verbosity = PSICONV_VERB_PROGRESS; 180 config->verbosity=PSICONV_VERB_PROGRESS;
181 break;
182 case '5': case 'D':case 'd':
183 config->verbosity=PSICONV_VERB_DEBUG;
184 break;
185 default:
186 fputs("Unknown noise level\n",stderr);
187 exit(1);
188 }
170 break; 189 break;
171 case 'd': config->verbosity = PSICONV_VERB_DEBUG; break;
172 case 's': config->verbosity = PSICONV_VERB_ERROR; break;
173 case 'o': outputfilename = strdup(optarg); break; 190 case 'o': outputfilename = strdup(optarg); break;
174 case 'T': type = strdup(optarg); break; 191 case 'T': type = strdup(optarg); break;
175 case 'e': if(!strcmp(optarg,"UTF8")) 192 case 'e': if(!strcmp(optarg,"UTF8"))
176 encoding_type = ENCODING_UTF8; 193 encoding_type = ENCODING_UTF8;
177 else if (!strcmp(optarg,"UCS2")) 194 else if (!strcmp(optarg,"UCS2"))
238 { 255 {
239 fprintf(stderr,"Parse error\n"); 256 fprintf(stderr,"Parse error\n");
240 exit(1); 257 exit(1);
241 } 258 }
242 259
260 if (!type) {
261 switch(file->type) {
262 case psiconv_word_file:
263 case psiconv_texted_file:
264 default:
265 type = "XHTML"; break;
266 case psiconv_mbm_file:
267 case psiconv_clipart_file:
268 case psiconv_sketch_file:
269 type = "TIFF"; break;
270 }
271 } else
243 strtoupper(type); 272 strtoupper(type);
273
244 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { 274 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) {
245 ff = psiconv_list_get(fileformat_list,i); 275 ff = psiconv_list_get(fileformat_list,i);
246 if (! strcasecmp(type,ff->name)) { 276 if (! strcasecmp(type,ff->name)) {
247 break; 277 break;
248 } 278 }

Legend:
Removed from v.185  
changed lines
  Added in v.196

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