/[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 218 Revision 219
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;
143 147
144 int c,i,res; 148 int c,i,res;
145 psiconv_buffer buf; 149 psiconv_buffer buf;
146 psiconv_file file; 150 psiconv_file file;
147 fileformat ff = NULL; 151 fileformat ff = NULL;
148
149 psiconv_config config = psiconv_config_default();
150 psiconv_config_read(NULL,&config);
151 152
152 if (!(fileformat_list = psiconv_list_new(sizeof(struct fileformat_s)))) { 153 if (!(fileformat_list = psiconv_list_new(sizeof(struct fileformat_s)))) {
153 fputs("Out of memory error",stderr); 154 fputs("Out of memory error",stderr);
154 exit(1); 155 exit(1);
155 } 156 }
166 switch(c) { 167 switch(c) {
167 case 'h': print_help(); exit(0); 168 case 'h': print_help(); exit(0);
168 case 'V': print_version(); exit(0); 169 case 'V': print_version(); exit(0);
169 case 'n': switch(optarg[0]) { 170 case 'n': switch(optarg[0]) {
170 case '1': case 'F':case 'f': 171 case '1': case 'F':case 'f':
171 config->verbosity=PSICONV_VERB_FATAL; 172 verbosity=PSICONV_VERB_FATAL;
172 break; 173 break;
173 case '2': case 'E':case 'e': 174 case '2': case 'E':case 'e':
174 config->verbosity=PSICONV_VERB_ERROR; 175 verbosity=PSICONV_VERB_ERROR;
175 break; 176 break;
176 case '3': case 'W':case 'w': 177 case '3': case 'W':case 'w':
177 config->verbosity=PSICONV_VERB_WARN; 178 verbosity=PSICONV_VERB_WARN;
178 break; 179 break;
179 case '4': case 'P':case 'p': 180 case '4': case 'P':case 'p':
180 config->verbosity=PSICONV_VERB_PROGRESS; 181 verbosity=PSICONV_VERB_PROGRESS;
181 break; 182 break;
182 case '5': case 'D':case 'd': 183 case '5': case 'D':case 'd':
183 config->verbosity=PSICONV_VERB_DEBUG; 184 verbosity=PSICONV_VERB_DEBUG;
184 break; 185 break;
185 default: 186 default:
186 fputs("Unknown noise level\n",stderr); 187 fputs("Unknown noise level\n",stderr);
187 exit(1); 188 exit(1);
188 } 189 }
201 fputs("Unknown encoding type " 202 fputs("Unknown encoding type "
202 "(try '-h' for more information\n",stderr); 203 "(try '-h' for more information\n",stderr);
203 exit(1); 204 exit(1);
204 } 205 }
205 break; 206 break;
207 case 'c': extra_configfile = strdup(optarg); break;
206 case '?': case ':': fputs("Try `-h' for more information\n",stderr); 208 case '?': case ':': fputs("Try `-h' for more information\n",stderr);
207 exit(1); 209 exit(1);
208 default: fprintf(stderr,"Internal error: getopt_long returned character " 210 default: fprintf(stderr,"Internal error: getopt_long returned character "
209 "code 0%o ?? (contact the author)\n", c); 211 "code 0%o ?? (contact the author)\n", c);
210 exit(1); break; 212 exit(1); break;
218 if (!(inputfilename = strdup(argv[optind]))) { 220 if (!(inputfilename = strdup(argv[optind]))) {
219 fputs("Out of memory error",stderr); 221 fputs("Out of memory error",stderr);
220 exit(1); 222 exit(1);
221 } 223 }
222 224
225 psiconv_config config = psiconv_config_default();
226 psiconv_config_read(extra_configfile,&config);
227 if (verbosity)
228 config->verbosity = verbosity;
223 229
224 /* Open inputfile for reading */ 230 /* Open inputfile for reading */
225 231
226 if (strlen(inputfilename) != 0) { 232 if (strlen(inputfilename) != 0) {
227 if(stat(inputfilename,&fbuf) < 0) { 233 if(stat(inputfilename,&fbuf) < 0) {

Legend:
Removed from v.218  
changed lines
  Added in v.219

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