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

Legend:
Removed from v.192  
changed lines
  Added in v.270

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