/[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 109 Revision 168
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
44static void print_help(void); 61static void print_help(void);
45static void print_version(void); 62static 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
74void print_version(void) 95void 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_read(NULL);
114 137
115 fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); 138 fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s));
116 init_txt(); 139 init_txt();
117 init_html(); 140 init_html();
118 init_html4(); 141 init_html4();
125 if (c == -1) 148 if (c == -1)
126 break; 149 break;
127 switch(c) { 150 switch(c) {
128 case 'h': print_help(); exit(0); 151 case 'h': print_help(); exit(0);
129 case 'V': print_version(); exit(0); 152 case 'V': print_version(); exit(0);
130 case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) 153 case 'v': if (config->verbosity < PSICONV_VERB_PROGRESS)
131 psiconv_verbosity = PSICONV_VERB_PROGRESS; 154 config->verbosity = PSICONV_VERB_PROGRESS;
132 break; 155 break;
133 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; 156 case 'd': config->verbosity = PSICONV_VERB_DEBUG; break;
134 case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break; 157 case 's': config->verbosity = PSICONV_VERB_FATAL; break;
135 case 'o': outputfilename = strdup(optarg); break; 158 case 'o': outputfilename = strdup(optarg); break;
136 case 'T': type = strdup(optarg); break; 159 case 'T': type = strdup(optarg); break;
160 case 'u': encoding_type = PSICONV_ENCODING_UTF8; break;
137 case '?': case ':': fputs("Try `-h' for more information\n",stderr); 161 case '?': case ':': fputs("Try `-h' for more information\n",stderr);
138 exit(1); 162 exit(1);
139 default: fprintf(stderr,"Internal error: getopt_long returned character " 163 default: fprintf(stderr,"Internal error: getopt_long returned character "
140 "code 0%o ?? (contact the author)\n", c); 164 "code 0%o ?? (contact the author)\n", c);
141 exit(1); break; 165 exit(1); break;
171 if (fclose(f)) { 195 if (fclose(f)) {
172 perror(inputfilename); 196 perror(inputfilename);
173 exit(1); 197 exit(1);
174 } 198 }
175 199
176 if (psiconv_parse(buf,&file) || (file->type == psiconv_unknown_file)) 200 if (psiconv_parse(config,buf,&file) || (file->type == psiconv_unknown_file))
177 { 201 {
178 fprintf(stderr,"Parse error\n"); 202 fprintf(stderr,"Parse error\n");
179 exit(1); 203 exit(1);
180 } 204 }
181 205
184 outputfilename = "/dev/stdout"; 208 outputfilename = "/dev/stdout";
185 209
186 strtoupper(type); 210 strtoupper(type);
187 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) { 211 for (i = 0; i < psiconv_list_length(fileformat_list); i ++) {
188 ff = psiconv_list_get(fileformat_list,i); 212 ff = psiconv_list_get(fileformat_list,i);
189 if (! strcmp(type,ff->name)) { 213 if (! strcasecmp(type,ff->name)) {
190 res = ff->output(outputfilename,file,type); 214 res = ff->output(outputfilename,file,type, encoding_type);
191 if (res) { 215 if (res) {
192 fprintf(stderr, 216 fprintf(stderr,
193 "Output format `%s' not permitted for this file type\n",type); 217 "Output format `%s' not permitted for this file type\n",type);
194 exit(1); 218 exit(1);
195 } 219 }

Legend:
Removed from v.109  
changed lines
  Added in v.168

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