… | |
… | |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | |
14 | |
15 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
18 | */ |
|
|
19 | |
|
|
20 | /* |
|
|
21 | 2002/Apr. Keita KAWABE |
|
|
22 | * Support for narrow build Asian Psions added. |
|
|
23 | |
|
|
24 | Now psiconv understands -u or --UTF8 option. |
|
|
25 | This option is passed to output_function as the fourth parameter |
|
|
26 | (thus the typedef of output_function was changed). |
|
|
27 | |
|
|
28 | If a called generator (gen_*.c) can handle UTF8, then it handles |
|
|
29 | the character conversion etc. accordingly. |
|
|
30 | |
|
|
31 | * psiconv seemed to want to take the argument of the options |
|
|
32 | case-insensitively (i.e. LaTeX -> LATEX), but that was not working |
|
|
33 | under my environment. Fixed it. |
18 | */ |
34 | */ |
19 | |
35 | |
20 | /* Driver program */ |
36 | /* Driver program */ |
21 | |
37 | |
22 | #include "config.h" |
38 | #include "config.h" |
… | |
… | |
31 | #ifdef HAVE_UNISTD_H |
47 | #ifdef HAVE_UNISTD_H |
32 | #include <unistd.h> |
48 | #include <unistd.h> |
33 | #endif |
49 | #endif |
34 | |
50 | |
35 | #ifdef IMAGEMAGICK |
51 | #ifdef IMAGEMAGICK |
36 | #include <magick/magick.h> |
52 | #include "magick-aux.h" |
37 | #endif |
53 | #endif |
38 | |
54 | |
39 | #include "psiconv/data.h" |
55 | #include "psiconv/data.h" |
40 | #include "psiconv/parse.h" |
56 | #include "psiconv/parse.h" |
|
|
57 | #include "psiconv/configuration.h" |
41 | #include "gen.h" |
58 | #include "gen.h" |
42 | #include "psiconv.h" |
59 | #include "psiconv.h" |
43 | |
60 | |
44 | static void print_help(void); |
61 | static void print_help(void); |
45 | static void print_version(void); |
62 | static void print_version(void); |
… | |
… | |
49 | { |
66 | { |
50 | psiconv_fileformat ff; |
67 | psiconv_fileformat ff; |
51 | int i,j; |
68 | int i,j; |
52 | |
69 | |
53 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
70 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
54 | puts("Convert the psion Word file FILE to a HTML file"); |
71 | puts("Convert the psion Word file FILE to other formats"); |
55 | puts("If FILE is not specified, use stdin"); |
72 | puts("If FILE is not specified, use stdin"); |
56 | puts(" -d, --debug Show debug information on stderr"); |
73 | puts(" -d, --debug Show debug information on stderr"); |
57 | puts(" -h, --help Display this help and exit"); |
74 | puts(" -h, --help Display this help and exit"); |
58 | puts(" -o, --outputfile Output to file instead of stdout"); |
75 | puts(" -o, --outputfile Output to file instead of stdout"); |
59 | puts(" -s, --silent Do not even show warnings on stderr"); |
76 | puts(" -s, --silent Do not even show warnings on stderr"); |
60 | puts(" -T, --type=FILETYPE Output type"); |
77 | puts(" -T, --type=FILETYPE Output type"); |
61 | puts(" -V, --version Display the program version and exit"); |
78 | puts(" -V, --version Display the program version and exit"); |
62 | puts(" -v, --verbose Show progress indicators on stderr"); |
79 | puts(" -v, --verbose Show progress indicators on stderr"); |
|
|
80 | puts(" -u, --UTF8 Input file is encoded in UTF8"); |
63 | puts(""); |
81 | puts(""); |
64 | puts("The following output types are known:"); |
82 | puts("The following output types are known:"); |
65 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
83 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
66 | ff = psiconv_list_get(fileformat_list,i); |
84 | ff = psiconv_list_get(fileformat_list,i); |
67 | printf(" %s",ff->name); |
85 | printf(" %s",ff->name); |
68 | for (j = strlen(ff->name); j < 15; j++) |
86 | for (j = strlen(ff->name); j < 15; j++) |
69 | putchar(' '); |
87 | putchar(' '); |
70 | puts(ff->description); |
88 | puts(ff->description); |
71 | } |
89 | } |
|
|
90 | puts(""); |
|
|
91 | puts("When using UTF8 with LaTeX type, the resulting LaTeX source should be converted"); |
|
|
92 | puts(" to a suitable encoding for your LaTeX installation before being typeset"); |
72 | } |
93 | } |
73 | |
94 | |
74 | void print_version(void) |
95 | void print_version(void) |
75 | { |
96 | { |
76 | printf("Version %s\n",VERSION); |
97 | printf("Version %s\n",VERSION); |
… | |
… | |
92 | {"verbose",no_argument,NULL,'v'}, |
113 | {"verbose",no_argument,NULL,'v'}, |
93 | {"debug",no_argument,NULL,'d'}, |
114 | {"debug",no_argument,NULL,'d'}, |
94 | {"silent",no_argument,NULL,'s'}, |
115 | {"silent",no_argument,NULL,'s'}, |
95 | {"outputfile",required_argument,NULL,'o'}, |
116 | {"outputfile",required_argument,NULL,'o'}, |
96 | {"type",required_argument,NULL,'T'}, |
117 | {"type",required_argument,NULL,'T'}, |
|
|
118 | {"UTF8",no_argument,NULL,'u'}, |
97 | {0,0,0,0} |
119 | {0,0,0,0} |
98 | }; |
120 | }; |
99 | const char* short_options = "hVvsdo:eT:"; |
121 | const char* short_options = "hVvsdo:uT:"; |
100 | int option_index; |
122 | int option_index; |
101 | FILE * f; |
123 | FILE * f; |
102 | struct stat fbuf; |
124 | struct stat fbuf; |
103 | |
125 | |
104 | const char *inputfilename = ""; |
126 | const char *inputfilename = ""; |
105 | const char *outputfilename = ""; |
127 | const char *outputfilename = ""; |
106 | char *type = strdup("HTML3"); |
128 | char *type = strdup("HTML3"); |
|
|
129 | psiconv_encoding encoding_type=PSICONV_ENCODING_CP1252; |
107 | |
130 | |
108 | int c,i,res; |
131 | int c,i,res; |
109 | psiconv_buffer buf; |
132 | psiconv_buffer buf; |
110 | psiconv_file file; |
133 | psiconv_file file; |
111 | psiconv_fileformat ff; |
134 | psiconv_fileformat ff; |
112 | |
135 | |
113 | psiconv_verbosity = PSICONV_VERB_WARN; |
136 | psiconv_config config = psiconv_config_default(); |
|
|
137 | psiconv_config_read(NULL,&config); |
114 | |
138 | |
115 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
139 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
116 | init_txt(); |
140 | init_txt(); |
117 | init_html(); |
141 | init_html(); |
118 | init_html4(); |
142 | init_html4(); |
|
|
143 | init_latex(); |
119 | init_rtf(); |
144 | init_rtf(); |
120 | init_image(); |
145 | init_image(); |
121 | |
146 | |
122 | while(1) { |
147 | while(1) { |
123 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
148 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
124 | if (c == -1) |
149 | if (c == -1) |
125 | break; |
150 | break; |
126 | switch(c) { |
151 | switch(c) { |
127 | case 'h': print_help(); exit(0); |
152 | case 'h': print_help(); exit(0); |
128 | case 'V': print_version(); exit(0); |
153 | case 'V': print_version(); exit(0); |
129 | case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) |
154 | case 'v': if (config->verbosity < PSICONV_VERB_PROGRESS) |
130 | psiconv_verbosity = PSICONV_VERB_PROGRESS; |
155 | config->verbosity = PSICONV_VERB_PROGRESS; |
131 | break; |
156 | break; |
132 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
157 | case 'd': config->verbosity = PSICONV_VERB_DEBUG; break; |
133 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
158 | case 's': config->verbosity = PSICONV_VERB_FATAL; break; |
134 | case 'o': outputfilename = strdup(optarg); break; |
159 | case 'o': outputfilename = strdup(optarg); break; |
135 | case 'T': type = strdup(optarg); break; |
160 | case 'T': type = strdup(optarg); break; |
|
|
161 | case 'u': encoding_type = PSICONV_ENCODING_UTF8; break; |
136 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
162 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
137 | exit(1); |
163 | exit(1); |
138 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
164 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
139 | "code 0%o ?? (contact the author)\n", c); |
165 | "code 0%o ?? (contact the author)\n", c); |
140 | exit(1); break; |
166 | exit(1); break; |
… | |
… | |
161 | exit(1); |
187 | exit(1); |
162 | } |
188 | } |
163 | } else |
189 | } else |
164 | f = stdin; |
190 | f = stdin; |
165 | |
191 | |
166 | buf = psiconv_buffer_new(0); |
192 | buf = psiconv_buffer_new(); |
167 | psiconv_buffer_fread_all(buf,f); |
193 | psiconv_buffer_fread_all(buf,f); |
168 | |
194 | |
169 | if (strlen(inputfilename) != 0) |
195 | if (strlen(inputfilename) != 0) |
170 | if (fclose(f)) { |
196 | if (fclose(f)) { |
171 | perror(inputfilename); |
197 | perror(inputfilename); |
172 | exit(1); |
198 | exit(1); |
173 | } |
199 | } |
174 | |
200 | |
175 | if (psiconv_parse(buf,&file) || (file->type == psiconv_unknown_file)) |
201 | if (psiconv_parse(config,buf,&file) || (file->type == psiconv_unknown_file)) |
176 | { |
202 | { |
177 | fprintf(stderr,"Parse error\n"); |
203 | fprintf(stderr,"Parse error\n"); |
178 | exit(1); |
204 | exit(1); |
179 | } |
205 | } |
180 | |
206 | |
… | |
… | |
183 | outputfilename = "/dev/stdout"; |
209 | outputfilename = "/dev/stdout"; |
184 | |
210 | |
185 | strtoupper(type); |
211 | strtoupper(type); |
186 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
212 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
187 | ff = psiconv_list_get(fileformat_list,i); |
213 | ff = psiconv_list_get(fileformat_list,i); |
188 | if (! strcmp(type,ff->name)) { |
214 | if (! strcasecmp(type,ff->name)) { |
189 | res = ff->output(outputfilename,file,type); |
215 | res = ff->output(outputfilename,file,type, encoding_type); |
190 | if (res) { |
216 | if (res) { |
191 | fprintf(stderr, |
217 | fprintf(stderr, |
192 | "Output format `%s' not permitted for this file type\n",type); |
218 | "Output format `%s' not permitted for this file type\n",type); |
193 | exit(1); |
219 | exit(1); |
194 | } |
220 | } |