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-2004 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
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. |
… | |
… | |
54 | int i,j; |
54 | int i,j; |
55 | |
55 | |
56 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
56 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
57 | puts("Convert the psion file FILE to other formats"); |
57 | puts("Convert the psion file FILE to other formats"); |
58 | puts("If FILE is not specified, use stdin"); |
58 | puts("If FILE is not specified, use stdin"); |
|
|
59 | puts(" -c, --configfile=FILE Read extra configuration file after normal ones"); |
59 | puts(" -e, --encoding=ENC Output encoding (default: UTF8)"); |
60 | puts(" -e, --encoding=ENC Output encoding (default: UTF8)"); |
60 | puts(" -h, --help Display this help and exit"); |
61 | puts(" -h, --help Display this help and exit"); |
61 | puts(" -n, --noise=LEVEL Select what to print on stderr (overrides psiconv.conf)"); |
62 | puts(" -n, --noise=LEVEL Select what to print on stderr (overrides psiconv.conf)"); |
62 | puts(" -o, --outputfile Output to file instead of stdout"); |
63 | puts(" -o, --outputfile Output to file instead of stdout"); |
63 | puts(" -T, --type=FILETYPE Output type (default: XHTML or TIFF"); |
64 | puts(" -T, --type=FILETYPE Output type (default: XHTML or TIFF"); |
64 | puts(" -V, --version Display the program version and exit"); |
65 | puts(" -V, --version Display the program version and exit"); |
65 | puts(""); |
66 | puts(""); |
66 | puts("The following encodings are currently supported:"); |
67 | puts("The following encodings are currently supported:"); |
67 | puts(" UTF8 Variable length Unicode encoding"); |
68 | puts(" UTF8 Variable length Unicode encoding"); |
68 | puts(" UCS2 Fixed 16-bit length Unicode encoding"); |
69 | puts(" UCS2 Fixed 16-bit length Unicode encoding"); |
69 | puts(" Psion The encoding your Psion uses (as in psiconv.conf)"); |
70 | puts(" Psion The encoding your Psion uses (as in psiconv.conf)"); |
… | |
… | |
74 | puts(" 2 or E: Errors"); |
75 | puts(" 2 or E: Errors"); |
75 | puts(" 3 or W: Warnings"); |
76 | puts(" 3 or W: Warnings"); |
76 | puts(" 4 or P: Progress indicators"); |
77 | puts(" 4 or P: Progress indicators"); |
77 | puts(" 5 or D: Debug data"); |
78 | puts(" 5 or D: Debug data"); |
78 | puts(""); |
79 | puts(""); |
79 | puts("The following abbreviations are used below:"); |
80 | puts("The following abbreviations are used in the output types list:"); |
80 | puts(" C - processes ClipArt files"); |
81 | puts(" C - processes ClipArt files"); |
81 | puts(" c - processes ClipArt files containing only one image"); |
82 | puts(" c - processes ClipArt files containing only one image"); |
82 | puts(" M - processes MBM files"); |
83 | puts(" M - processes MBM files"); |
83 | puts(" m - processes MBM files containing only one image"); |
84 | puts(" m - processes MBM files containing only one image"); |
84 | puts(" S - processes Sketch files"); |
85 | puts(" S - processes Sketch files"); |
… | |
… | |
122 | { |
123 | { |
123 | struct option long_options[] = |
124 | struct option long_options[] = |
124 | { |
125 | { |
125 | {"help",no_argument,NULL,'h'}, |
126 | {"help",no_argument,NULL,'h'}, |
126 | {"version",no_argument,NULL,'V'}, |
127 | {"version",no_argument,NULL,'V'}, |
|
|
128 | {"configfile",required_argument,NULL,'c'}, |
127 | {"noise",required_argument,NULL,'n'}, |
129 | {"noise",required_argument,NULL,'n'}, |
128 | {"outputfile",required_argument,NULL,'o'}, |
130 | {"outputfile",required_argument,NULL,'o'}, |
129 | {"type",required_argument,NULL,'T'}, |
131 | {"type",required_argument,NULL,'T'}, |
130 | {"encoding",no_argument,NULL,'e'}, |
132 | {"encoding",no_argument,NULL,'e'}, |
131 | {0,0,0,0} |
133 | {0,0,0,0} |
132 | }; |
134 | }; |
133 | const char* short_options = "hVn:o:e:T:"; |
135 | const char* short_options = "hVn:o:e:T:c:"; |
134 | int option_index; |
136 | int option_index; |
135 | FILE * f; |
137 | FILE * f; |
136 | struct stat fbuf; |
138 | struct stat fbuf; |
137 | |
139 | |
138 | const char *inputfilename = ""; |
140 | const char *inputfilename = ""; |
139 | const char *outputfilename = ""; |
141 | const char *outputfilename = ""; |
|
|
142 | const char *extra_configfile = NULL; |
140 | char *type = NULL; |
143 | char *type = NULL; |
141 | encoding encoding_type=ENCODING_UTF8; |
144 | encoding encoding_type=ENCODING_UTF8; |
142 | psiconv_list outputlist; |
145 | psiconv_list outputlist; |
|
|
146 | int verbosity = 0; |
|
|
147 | psiconv_config config; |
143 | |
148 | |
144 | int c,i,res; |
149 | int c,i,res; |
145 | psiconv_buffer buf; |
150 | psiconv_buffer buf; |
146 | psiconv_file file; |
151 | psiconv_file file; |
147 | fileformat ff = NULL; |
152 | fileformat ff = NULL; |
148 | |
|
|
149 | psiconv_config config = psiconv_config_default(); |
|
|
150 | psiconv_config_read(NULL,&config); |
|
|
151 | |
153 | |
152 | if (!(fileformat_list = psiconv_list_new(sizeof(struct fileformat_s)))) { |
154 | if (!(fileformat_list = psiconv_list_new(sizeof(struct fileformat_s)))) { |
153 | fputs("Out of memory error",stderr); |
155 | fputs("Out of memory error",stderr); |
154 | exit(1); |
156 | exit(1); |
155 | } |
157 | } |
… | |
… | |
166 | switch(c) { |
168 | switch(c) { |
167 | case 'h': print_help(); exit(0); |
169 | case 'h': print_help(); exit(0); |
168 | case 'V': print_version(); exit(0); |
170 | case 'V': print_version(); exit(0); |
169 | case 'n': switch(optarg[0]) { |
171 | case 'n': switch(optarg[0]) { |
170 | case '1': case 'F':case 'f': |
172 | case '1': case 'F':case 'f': |
171 | config->verbosity=PSICONV_VERB_FATAL; |
173 | verbosity=PSICONV_VERB_FATAL; |
172 | break; |
174 | break; |
173 | case '2': case 'E':case 'e': |
175 | case '2': case 'E':case 'e': |
174 | config->verbosity=PSICONV_VERB_ERROR; |
176 | verbosity=PSICONV_VERB_ERROR; |
175 | break; |
177 | break; |
176 | case '3': case 'W':case 'w': |
178 | case '3': case 'W':case 'w': |
177 | config->verbosity=PSICONV_VERB_WARN; |
179 | verbosity=PSICONV_VERB_WARN; |
178 | break; |
180 | break; |
179 | case '4': case 'P':case 'p': |
181 | case '4': case 'P':case 'p': |
180 | config->verbosity=PSICONV_VERB_PROGRESS; |
182 | verbosity=PSICONV_VERB_PROGRESS; |
181 | break; |
183 | break; |
182 | case '5': case 'D':case 'd': |
184 | case '5': case 'D':case 'd': |
183 | config->verbosity=PSICONV_VERB_DEBUG; |
185 | verbosity=PSICONV_VERB_DEBUG; |
184 | break; |
186 | break; |
185 | default: |
187 | default: |
186 | fputs("Unknown noise level\n",stderr); |
188 | fputs("Unknown noise level\n",stderr); |
187 | exit(1); |
189 | exit(1); |
188 | } |
190 | } |
… | |
… | |
201 | fputs("Unknown encoding type " |
203 | fputs("Unknown encoding type " |
202 | "(try '-h' for more information\n",stderr); |
204 | "(try '-h' for more information\n",stderr); |
203 | exit(1); |
205 | exit(1); |
204 | } |
206 | } |
205 | break; |
207 | break; |
|
|
208 | case 'c': extra_configfile = strdup(optarg); break; |
206 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
209 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
207 | exit(1); |
210 | exit(1); |
208 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
211 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
209 | "code 0%o ?? (contact the author)\n", c); |
212 | "code 0%o ?? (contact the author)\n", c); |
210 | exit(1); break; |
213 | exit(1); break; |
… | |
… | |
218 | if (!(inputfilename = strdup(argv[optind]))) { |
221 | if (!(inputfilename = strdup(argv[optind]))) { |
219 | fputs("Out of memory error",stderr); |
222 | fputs("Out of memory error",stderr); |
220 | exit(1); |
223 | exit(1); |
221 | } |
224 | } |
222 | |
225 | |
|
|
226 | config = psiconv_config_default(); |
|
|
227 | psiconv_config_read(extra_configfile,&config); |
|
|
228 | if (verbosity) |
|
|
229 | config->verbosity = verbosity; |
223 | |
230 | |
224 | /* Open inputfile for reading */ |
231 | /* Open inputfile for reading */ |
225 | |
232 | |
226 | if (strlen(inputfilename) != 0) { |
233 | if (strlen(inputfilename) != 0) { |
227 | if(stat(inputfilename,&fbuf) < 0) { |
234 | if(stat(inputfilename,&fbuf) < 0) { |