… | |
… | |
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; |
… | |
… | |
117 | |
114 | |
118 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
115 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
119 | init_txt(); |
116 | init_txt(); |
120 | init_html(); |
117 | init_html(); |
121 | init_html4(); |
118 | init_html4(); |
|
|
119 | init_latex(); |
122 | init_rtf(); |
120 | init_rtf(); |
123 | init_image(); |
121 | init_image(); |
124 | |
122 | |
125 | while(1) { |
123 | while(1) { |
126 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
124 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
… | |
… | |
132 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
130 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
133 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
131 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
134 | break; |
132 | break; |
135 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
133 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
136 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
134 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
137 | case 'e': exact = 1; break; |
|
|
138 | case 'o': outputfilename = strdup(optarg); break; |
135 | case 'o': outputfilename = strdup(optarg); break; |
139 | case 'T': type = strdup(optarg); break; |
136 | case 'T': type = strdup(optarg); break; |
140 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
137 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
141 | exit(1); |
138 | exit(1); |
142 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
139 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
… | |
… | |
165 | exit(1); |
162 | exit(1); |
166 | } |
163 | } |
167 | } else |
164 | } else |
168 | f = stdin; |
165 | f = stdin; |
169 | |
166 | |
170 | buf = psiconv_list_new(sizeof(psiconv_u8)); |
167 | buf = psiconv_buffer_new(); |
171 | while (! feof(f)) |
168 | psiconv_buffer_fread_all(buf,f); |
172 | psiconv_list_fread(buf,1024,f); |
|
|
173 | |
169 | |
174 | if (strlen(inputfilename) != 0) |
170 | if (strlen(inputfilename) != 0) |
175 | if (fclose(f)) { |
171 | if (fclose(f)) { |
176 | perror(inputfilename); |
172 | perror(inputfilename); |
177 | exit(1); |
173 | exit(1); |
178 | } |
174 | } |
179 | |
175 | |
180 | if (psiconv_parse(buf,&file)) |
176 | if (psiconv_parse(buf,&file) || (file->type == psiconv_unknown_file)) |
181 | if(exact) |
177 | { |
|
|
178 | fprintf(stderr,"Parse error\n"); |
182 | exit(1); |
179 | exit(1); |
|
|
180 | } |
183 | |
181 | |
184 | /* Set correct output file */ |
182 | /* Set correct output file */ |
185 | if (strlen(outputfilename) == 0) |
183 | if (strlen(outputfilename) == 0) |
186 | outputfilename = "/dev/stdout"; |
184 | outputfilename = "/dev/stdout"; |
187 | |
185 | |