… | |
… | |
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" |
… | |
… | |
69 | int i,j; |
53 | int i,j; |
70 | |
54 | |
71 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
55 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
72 | puts("Convert the psion file FILE to other formats"); |
56 | puts("Convert the psion file FILE to other formats"); |
73 | puts("If FILE is not specified, use stdin"); |
57 | 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)"); |
58 | puts(" -e, --encoding=ENC Output encoding (default: UTF8)"); |
76 | puts(" -h, --help Display this help and exit"); |
59 | puts(" -h, --help Display this help and exit"); |
|
|
60 | puts(" -n, --noise=LEVEL Select what to print on stderr (overrides psiconv.conf)"); |
77 | puts(" -o, --outputfile Output to file instead of stdout"); |
61 | 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"); |
62 | puts(" -T, --type=FILETYPE Output type (default: XHTML or TIFF"); |
80 | puts(" -V, --version Display the program version and exit"); |
63 | puts(" -V, --version Display the program version and exit"); |
81 | puts(" -v, --verbose Show progress indicators on stderr"); |
|
|
82 | puts(""); |
64 | puts(""); |
83 | puts("The following encodings are currently supported:"); |
65 | puts("The following encodings are currently supported:"); |
84 | puts(" UTF8 Variable length Unicode encoding"); |
66 | puts(" UTF8 Variable length Unicode encoding"); |
85 | puts(" UCS2 Fixed 16-bit length Unicode encoding"); |
67 | puts(" UCS2 Fixed 16-bit length Unicode encoding"); |
86 | puts(" Psion The encoding your Psion uses (as in psiconv.conf)"); |
68 | puts(" Psion The encoding your Psion uses (as in psiconv.conf)"); |
87 | puts(" ASCII 7-bit ASCII (other symbols are substituted by '?')"); |
69 | puts(" ASCII 7-bit ASCII (other symbols are substituted by '?')"); |
88 | puts(""); |
70 | puts(""); |
|
|
71 | puts("The following noise levels are currently supported:"); |
|
|
72 | puts(" 1 or F: Fatal errors only"); |
|
|
73 | puts(" 2 or E: Errors"); |
|
|
74 | puts(" 3 or W: Warnings"); |
|
|
75 | puts(" 4 or P: Progress indicators"); |
|
|
76 | puts(" 5 or D: Debug data"); |
|
|
77 | puts(""); |
|
|
78 | puts("The following abbreviations are used below:"); |
|
|
79 | puts(" C - processes ClipArt files"); |
|
|
80 | puts(" c - processes ClipArt files containing only one image"); |
|
|
81 | puts(" M - processes MBM files"); |
|
|
82 | puts(" m - processes MBM files containing only one image"); |
|
|
83 | puts(" S - processes Sketch files"); |
|
|
84 | puts(" T - processes TextEd files"); |
|
|
85 | puts(" W - processes Word files"); |
|
|
86 | puts(""); |
89 | puts("The following output types are known:"); |
87 | puts("The following output types are known:"); |
90 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
88 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
91 | ff = psiconv_list_get(fileformat_list,i); |
89 | ff = psiconv_list_get(fileformat_list,i); |
92 | printf(" %s",ff->name); |
90 | printf(" %s",ff->name); |
93 | for (j = strlen(ff->name); j < 15; j++) |
91 | for (j = strlen(ff->name); j < 10; j++) |
94 | putchar(' '); |
92 | putchar(' '); |
|
|
93 | printf("[%c%c%c%c%c] ", |
|
|
94 | ff->supported_format & FORMAT_CLIPART_MULTIPLE?'C': |
|
|
95 | ff->supported_format & FORMAT_CLIPART_SINGLE?'c':' ', |
|
|
96 | ff->supported_format & FORMAT_MBM_MULTIPLE?'M': |
|
|
97 | ff->supported_format & FORMAT_MBM_SINGLE?'m':' ', |
|
|
98 | ff->supported_format & FORMAT_SKETCH?'S':' ', |
|
|
99 | ff->supported_format & FORMAT_TEXTED?'T':' ', |
|
|
100 | ff->supported_format & FORMAT_WORD?'W':' '); |
95 | puts(ff->description); |
101 | puts(ff->description); |
96 | } |
102 | } |
97 | puts(""); |
103 | puts(""); |
98 | puts("When using UTF8 with LaTeX type, the resulting LaTeX source should be converted"); |
104 | 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"); |
105 | puts(" to a suitable encoding for your LaTeX installation before being typeset"); |
… | |
… | |
115 | { |
121 | { |
116 | struct option long_options[] = |
122 | struct option long_options[] = |
117 | { |
123 | { |
118 | {"help",no_argument,NULL,'h'}, |
124 | {"help",no_argument,NULL,'h'}, |
119 | {"version",no_argument,NULL,'V'}, |
125 | {"version",no_argument,NULL,'V'}, |
120 | {"verbose",no_argument,NULL,'v'}, |
126 | {"noise",required_argument,NULL,'n'}, |
121 | {"debug",no_argument,NULL,'d'}, |
|
|
122 | {"silent",no_argument,NULL,'s'}, |
|
|
123 | {"outputfile",required_argument,NULL,'o'}, |
127 | {"outputfile",required_argument,NULL,'o'}, |
124 | {"type",required_argument,NULL,'T'}, |
128 | {"type",required_argument,NULL,'T'}, |
125 | {"encoding",no_argument,NULL,'e'}, |
129 | {"encoding",no_argument,NULL,'e'}, |
126 | {0,0,0,0} |
130 | {0,0,0,0} |
127 | }; |
131 | }; |
128 | const char* short_options = "hVvsdo:e:T:"; |
132 | const char* short_options = "hVn:o:e:T:"; |
129 | int option_index; |
133 | int option_index; |
130 | FILE * f; |
134 | FILE * f; |
131 | struct stat fbuf; |
135 | struct stat fbuf; |
132 | |
136 | |
133 | const char *inputfilename = ""; |
137 | const char *inputfilename = ""; |
134 | const char *outputfilename = ""; |
138 | const char *outputfilename = ""; |
135 | char *type = strdup("HTML3"); |
139 | char *type = NULL; |
136 | encoding encoding_type=ENCODING_UTF8; |
140 | encoding encoding_type=ENCODING_UTF8; |
137 | psiconv_list outputlist; |
141 | psiconv_list outputlist; |
138 | |
142 | |
139 | int c,i,res; |
143 | int c,i,res; |
140 | psiconv_buffer buf; |
144 | psiconv_buffer buf; |
… | |
… | |
148 | fputs("Out of memory error",stderr); |
152 | fputs("Out of memory error",stderr); |
149 | exit(1); |
153 | exit(1); |
150 | } |
154 | } |
151 | |
155 | |
152 | init_txt(); |
156 | init_txt(); |
153 | #if 0 |
|
|
154 | init_html(); |
157 | init_xhtml(); |
155 | init_html4(); |
158 | init_html4(); |
156 | init_latex(); |
|
|
157 | init_rtf(); |
|
|
158 | init_image(); |
159 | init_image(); |
159 | #endif |
|
|
160 | |
160 | |
161 | while(1) { |
161 | while(1) { |
162 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
162 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
163 | if (c == -1) |
163 | if (c == -1) |
164 | break; |
164 | break; |
165 | switch(c) { |
165 | switch(c) { |
166 | case 'h': print_help(); exit(0); |
166 | case 'h': print_help(); exit(0); |
167 | case 'V': print_version(); exit(0); |
167 | case 'V': print_version(); exit(0); |
168 | case 'v': if (config->verbosity < PSICONV_VERB_PROGRESS) |
168 | case 'n': switch(optarg[0]) { |
|
|
169 | case '1': case 'F':case 'f': |
|
|
170 | config->verbosity=PSICONV_VERB_FATAL; |
|
|
171 | break; |
|
|
172 | case '2': case 'E':case 'e': |
|
|
173 | config->verbosity=PSICONV_VERB_ERROR; |
|
|
174 | break; |
|
|
175 | case '3': case 'W':case 'w': |
|
|
176 | config->verbosity=PSICONV_VERB_WARN; |
|
|
177 | break; |
|
|
178 | case '4': case 'P':case 'p': |
169 | config->verbosity = PSICONV_VERB_PROGRESS; |
179 | config->verbosity=PSICONV_VERB_PROGRESS; |
|
|
180 | break; |
|
|
181 | case '5': case 'D':case 'd': |
|
|
182 | config->verbosity=PSICONV_VERB_DEBUG; |
|
|
183 | break; |
|
|
184 | default: |
|
|
185 | fputs("Unknown noise level\n",stderr); |
|
|
186 | exit(1); |
|
|
187 | } |
170 | break; |
188 | 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; |
189 | case 'o': outputfilename = strdup(optarg); break; |
174 | case 'T': type = strdup(optarg); break; |
190 | case 'T': type = strdup(optarg); break; |
175 | case 'e': if(!strcmp(optarg,"UTF8")) |
191 | case 'e': if(!strcmp(optarg,"UTF8")) |
176 | encoding_type = ENCODING_UTF8; |
192 | encoding_type = ENCODING_UTF8; |
177 | else if (!strcmp(optarg,"UCS2")) |
193 | else if (!strcmp(optarg,"UCS2")) |
… | |
… | |
238 | { |
254 | { |
239 | fprintf(stderr,"Parse error\n"); |
255 | fprintf(stderr,"Parse error\n"); |
240 | exit(1); |
256 | exit(1); |
241 | } |
257 | } |
242 | |
258 | |
|
|
259 | if (!type) { |
|
|
260 | switch(file->type) { |
|
|
261 | case psiconv_word_file: |
|
|
262 | case psiconv_texted_file: |
|
|
263 | default: |
|
|
264 | type = "XHTML"; break; |
|
|
265 | case psiconv_mbm_file: |
|
|
266 | case psiconv_clipart_file: |
|
|
267 | case psiconv_sketch_file: |
|
|
268 | type = "TIFF"; break; |
|
|
269 | } |
|
|
270 | } else |
243 | strtoupper(type); |
271 | strtoupper(type); |
|
|
272 | |
244 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
273 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
245 | ff = psiconv_list_get(fileformat_list,i); |
274 | ff = psiconv_list_get(fileformat_list,i); |
246 | if (! strcasecmp(type,ff->name)) { |
275 | if (! strcasecmp(type,ff->name)) { |
247 | break; |
276 | break; |
248 | } |
277 | } |