… | |
… | |
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" |
41 | #include "gen.h" |
57 | #include "gen.h" |
… | |
… | |
49 | { |
65 | { |
50 | psiconv_fileformat ff; |
66 | psiconv_fileformat ff; |
51 | int i,j; |
67 | int i,j; |
52 | |
68 | |
53 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
69 | puts("Syntax: psiconv [OPTIONS..] [FILE]"); |
54 | puts("Convert the psion Word file FILE to a HTML file"); |
70 | puts("Convert the psion Word file FILE to other formats"); |
55 | puts("If FILE is not specified, use stdin"); |
71 | puts("If FILE is not specified, use stdin"); |
56 | puts(" -d, --debug Show debug information on stderr"); |
72 | puts(" -d, --debug Show debug information on stderr"); |
57 | puts(" -h, --help Display this help and exit"); |
73 | puts(" -h, --help Display this help and exit"); |
58 | puts(" -o, --outputfile Output to file instead of stdout"); |
74 | puts(" -o, --outputfile Output to file instead of stdout"); |
59 | puts(" -s, --silent Do not even show warnings on stderr"); |
75 | puts(" -s, --silent Do not even show warnings on stderr"); |
60 | puts(" -T, --type=FILETYPE Output type"); |
76 | puts(" -T, --type=FILETYPE Output type"); |
61 | puts(" -V, --version Display the program version and exit"); |
77 | puts(" -V, --version Display the program version and exit"); |
62 | puts(" -v, --verbose Show progress indicators on stderr"); |
78 | puts(" -v, --verbose Show progress indicators on stderr"); |
|
|
79 | puts(" -u, --UTF8 Input file is encoded in UTF8"); |
63 | puts(""); |
80 | puts(""); |
64 | puts("The following output types are known:"); |
81 | puts("The following output types are known:"); |
65 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
82 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
66 | ff = psiconv_list_get(fileformat_list,i); |
83 | ff = psiconv_list_get(fileformat_list,i); |
67 | printf(" %s",ff->name); |
84 | printf(" %s",ff->name); |
68 | for (j = strlen(ff->name); j < 15; j++) |
85 | for (j = strlen(ff->name); j < 15; j++) |
69 | putchar(' '); |
86 | putchar(' '); |
70 | puts(ff->description); |
87 | puts(ff->description); |
71 | } |
88 | } |
|
|
89 | puts(""); |
|
|
90 | puts("When using UTF8 with LaTeX type, the resulting LaTeX source should be converted"); |
|
|
91 | puts(" to a suitable encoding for your LaTeX installation before being typeset"); |
72 | } |
92 | } |
73 | |
93 | |
74 | void print_version(void) |
94 | void print_version(void) |
75 | { |
95 | { |
76 | printf("Version %s\n",VERSION); |
96 | printf("Version %s\n",VERSION); |
… | |
… | |
92 | {"verbose",no_argument,NULL,'v'}, |
112 | {"verbose",no_argument,NULL,'v'}, |
93 | {"debug",no_argument,NULL,'d'}, |
113 | {"debug",no_argument,NULL,'d'}, |
94 | {"silent",no_argument,NULL,'s'}, |
114 | {"silent",no_argument,NULL,'s'}, |
95 | {"outputfile",required_argument,NULL,'o'}, |
115 | {"outputfile",required_argument,NULL,'o'}, |
96 | {"type",required_argument,NULL,'T'}, |
116 | {"type",required_argument,NULL,'T'}, |
|
|
117 | {"UTF8",no_argument,NULL,'u'}, |
97 | {0,0,0,0} |
118 | {0,0,0,0} |
98 | }; |
119 | }; |
99 | const char* short_options = "hVvsdo:eT:"; |
120 | const char* short_options = "hVvsdo:uT:"; |
100 | int option_index; |
121 | int option_index; |
101 | FILE * f; |
122 | FILE * f; |
102 | struct stat fbuf; |
123 | struct stat fbuf; |
103 | |
124 | |
104 | const char *inputfilename = ""; |
125 | const char *inputfilename = ""; |
105 | const char *outputfilename = ""; |
126 | const char *outputfilename = ""; |
106 | char *type = strdup("HTML3"); |
127 | char *type = strdup("HTML3"); |
|
|
128 | psiconv_encoding encoding_type=PSICONV_ENCODING_CP1252; |
107 | |
129 | |
108 | int c,i,res; |
130 | int c,i,res; |
109 | psiconv_buffer buf; |
131 | psiconv_buffer buf; |
110 | psiconv_file file; |
132 | psiconv_file file; |
111 | psiconv_fileformat ff; |
133 | psiconv_fileformat ff; |
… | |
… | |
114 | |
136 | |
115 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
137 | fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); |
116 | init_txt(); |
138 | init_txt(); |
117 | init_html(); |
139 | init_html(); |
118 | init_html4(); |
140 | init_html4(); |
|
|
141 | init_latex(); |
119 | init_rtf(); |
142 | init_rtf(); |
120 | init_image(); |
143 | init_image(); |
121 | |
144 | |
122 | while(1) { |
145 | while(1) { |
123 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
146 | c = getopt_long(argc,argv,short_options, long_options, &option_index); |
… | |
… | |
131 | break; |
154 | break; |
132 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
155 | case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; |
133 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
156 | case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; |
134 | case 'o': outputfilename = strdup(optarg); break; |
157 | case 'o': outputfilename = strdup(optarg); break; |
135 | case 'T': type = strdup(optarg); break; |
158 | case 'T': type = strdup(optarg); break; |
|
|
159 | case 'u': encoding_type = PSICONV_ENCODING_UTF8; break; |
136 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
160 | case '?': case ':': fputs("Try `-h' for more information\n",stderr); |
137 | exit(1); |
161 | exit(1); |
138 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
162 | default: fprintf(stderr,"Internal error: getopt_long returned character " |
139 | "code 0%o ?? (contact the author)\n", c); |
163 | "code 0%o ?? (contact the author)\n", c); |
140 | exit(1); break; |
164 | exit(1); break; |
… | |
… | |
183 | outputfilename = "/dev/stdout"; |
207 | outputfilename = "/dev/stdout"; |
184 | |
208 | |
185 | strtoupper(type); |
209 | strtoupper(type); |
186 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
210 | for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { |
187 | ff = psiconv_list_get(fileformat_list,i); |
211 | ff = psiconv_list_get(fileformat_list,i); |
188 | if (! strcmp(type,ff->name)) { |
212 | if (! strcasecmp(type,ff->name)) { |
189 | res = ff->output(outputfilename,file,type); |
213 | res = ff->output(outputfilename,file,type, encoding_type); |
190 | if (res) { |
214 | if (res) { |
191 | fprintf(stderr, |
215 | fprintf(stderr, |
192 | "Output format `%s' not permitted for this file type\n",type); |
216 | "Output format `%s' not permitted for this file type\n",type); |
193 | exit(1); |
217 | exit(1); |
194 | } |
218 | } |