… | |
… | |
52 | |
52 | |
53 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
53 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
54 | puts("Convert the psion Word file FILE to a HTML file"); |
54 | puts("Convert the psion Word file FILE to a HTML file"); |
55 | puts("If FILE is not specified, use stdin"); |
55 | puts("If FILE is not specified, use stdin"); |
56 | puts(" -d, --debug Show debug information on stderr"); |
56 | puts(" -d, --debug Show debug information on stderr"); |
57 | puts(" -e, --exact Quit on any parse errors or warnings"); |
|
|
58 | puts(" -h, --help Display this help and exit"); |
57 | puts(" -h, --help Display this help and exit"); |
59 | puts(" -o, --outputfile Output to file instead of stdout"); |
58 | puts(" -o, --outputfile Output to file instead of stdout"); |
60 | puts(" -s, --silent Do not even show warnings on stderr"); |
59 | puts(" -s, --silent Do not even show warnings on stderr"); |
61 | puts(" -T, --type=FILETYPE Output type"); |
60 | puts(" -T, --type=FILETYPE Output type"); |
62 | puts(" -V, --version Display the program version and exit"); |
61 | puts(" -V, --version Display the program version and exit"); |
… | |
… | |
93 | {"verbose",no_argument,NULL,'v'}, |
92 | {"verbose",no_argument,NULL,'v'}, |
94 | {"debug",no_argument,NULL,'d'}, |
93 | {"debug",no_argument,NULL,'d'}, |
95 | {"silent",no_argument,NULL,'s'}, |
94 | {"silent",no_argument,NULL,'s'}, |
96 | {"outputfile",required_argument,NULL,'o'}, |
95 | {"outputfile",required_argument,NULL,'o'}, |
97 | {"type",required_argument,NULL,'T'}, |
96 | {"type",required_argument,NULL,'T'}, |
98 | {"exact",no_argument,NULL,'e'}, |
|
|
99 | {0,0,0,0} |
97 | {0,0,0,0} |
100 | }; |
98 | }; |
101 | const char* short_options = "hVvsdo:eT:"; |
99 | const char* short_options = "hVvsdo:eT:"; |
102 | int option_index; |
100 | int option_index; |
103 | FILE * f; |
101 | FILE * f; |
104 | struct stat fbuf; |
102 | struct stat fbuf; |
105 | |
103 | |
106 | const char *inputfilename = ""; |
104 | const char *inputfilename = ""; |
107 | const char *outputfilename = ""; |
105 | const char *outputfilename = ""; |
108 | char *type = strdup("HTML3"); |
106 | char *type = strdup("HTML3"); |
109 | int exact=0; |
|
|
110 | |
107 | |
111 | int c,i,res; |
108 | int c,i,res; |
112 | psiconv_buffer buf; |
109 | psiconv_buffer buf; |
113 | psiconv_file file; |
110 | psiconv_file file; |
114 | psiconv_fileformat ff; |
111 | psiconv_fileformat ff; |
… | |
… | |
132 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
129 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
133 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
130 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
134 | break; |
131 | break; |
135 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
132 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
136 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
133 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
137 | case 'e': exact = 1; break; |
|
|
138 | case 'o': outputfilename = strdup(optarg); break; |
134 | case 'o': outputfilename = strdup(optarg); break; |
139 | case 'T': type = strdup(optarg); break; |
135 | case 'T': type = strdup(optarg); break; |
140 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
136 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
141 | exit(1); |
137 | exit(1); |
142 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
138 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
… | |
… | |
165 | exit(1); |
161 | exit(1); |
166 | } |
162 | } |
167 | } else |
163 | } else |
168 | f = stdin; |
164 | f = stdin; |
169 | |
165 | |
170 | buf = psiconv_list_new(sizeof(psiconv_u8)); |
166 | buf = psiconv_buffer_new(0); |
171 | while (! feof(f)) |
167 | psiconv_buffer_fread_all(buf,f); |
172 | psiconv_list_fread(buf,1024,f); |
|
|
173 | |
168 | |
174 | if (strlen(inputfilename) != 0) |
169 | if (strlen(inputfilename) != 0) |
175 | if (fclose(f)) { |
170 | if (fclose(f)) { |
176 | perror(inputfilename); |
171 | perror(inputfilename); |
177 | exit(1); |
172 | exit(1); |
178 | } |
173 | } |
179 | |
174 | |
180 | if (psiconv_parse(buf,&file)) |
175 | if (psiconv_parse(buf,&file) || (file->type == psiconv_unknown_file)) |
181 | if(exact) |
176 | { |
|
|
177 | fprintf(stderr,"Parse error\n"); |
182 | exit(1); |
178 | exit(1); |
|
|
179 | } |
183 | |
180 | |
184 | /* Set correct output file */ |
181 | /* Set correct output file */ |
185 | if (strlen(outputfilename) == 0) |
182 | if (strlen(outputfilename) == 0) |
186 | outputfilename = "/dev/stdout"; |
183 | outputfilename = "/dev/stdout"; |
187 | |
184 | |