/[public]/psiconv/trunk/program/psiconv/psiconv.c
ViewVC logotype

Annotation of /psiconv/trunk/program/psiconv/psiconv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (hide annotations)
Wed Oct 13 19:15:59 1999 UTC (24 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 5402 byte(s)
(Frodo) Crude ImageMagick output

Invoke with -T IMAGE. No selection of image types yet.

1 frodo 2 /*
2     psiconv.c - Part of psiconv, a PSION 5 file formats converter
3     Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl>
4    
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14    
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
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18     */
19    
20     /* Driver program */
21    
22     #include "config.h"
23     #include <getopt.h>
24     #include <stdio.h>
25     #include <sys/stat.h>
26     #include <stdlib.h>
27    
28     #ifdef HAVE_UNISTD_H
29     #include <unistd.h>
30     #endif
31    
32     #include <string.h>
33     #include <ctype.h>
34     #include "data.h"
35     #include "parse.h"
36     #include "gen.h"
37    
38     static void print_help(void);
39     static void print_version(void);
40     static void strtoupper(char *str);
41    
42     int psiconv_verbosity = PSICONV_VERB_WARN;
43    
44     void print_help(void)
45     {
46     puts("Syntax: psiconv [OPTIONS..] [FILE]");
47     puts("Convert the psion Word file FILE to a HTML file");
48     puts("If FILE is not specified, use stdin");
49     puts(" -d, --debug Show debug information on stderr");
50     puts(" -e, --exact Quit on any parse errors or warnings");
51     puts(" -h, --help Display this help and exit");
52     puts(" -o, --outputfile Output to file instead of stdout");
53     puts(" -s, --silent Do not even show warnings on stderr");
54     puts(" -T, --type=FILETYPE Output type");
55     puts(" -V, --version Display the program version and exit");
56     puts(" -v, --verbose Show progress indicators on stderr");
57     puts("");
58     puts("The following output types are known:");
59     puts(" HTML (default)");
60     puts(" HTML4");
61     puts(" ASCII");
62 frodo 5 puts(" RTF");
63 frodo 2 }
64    
65     void print_version(void)
66     {
67     printf("Version %s\n",VERSION);
68     }
69    
70     void strtoupper(char *str)
71     {
72     int i;
73     for (i = 0; i < strlen(str); i ++)
74     str[i] = toupper(str[i]);
75     }
76    
77     int main(int argc, char *argv[])
78     {
79     struct option long_options[] =
80     {
81     {"help",no_argument,NULL,'h'},
82     {"version",no_argument,NULL,'V'},
83     {"verbose",no_argument,NULL,'v'},
84     {"debug",no_argument,NULL,'d'},
85     {"silent",no_argument,NULL,'s'},
86     {"outputfile",required_argument,NULL,'o'},
87     {"type",required_argument,NULL,'T'},
88     {"exact",no_argument,NULL,'e'},
89     {0,0,0,0}
90     };
91     const char* short_options = "hVvsdo:eT:";
92     int option_index;
93     FILE * f;
94     struct stat fbuf;
95    
96     const char *inputfilename = "";
97     const char *outputfilename = "";
98     char *type = strdup("HTML");
99     int exact=0;
100    
101     int c;
102     psiconv_buffer buf;
103     psiconv_file file;
104    
105     while(1) {
106     c = getopt_long(argc,argv,short_options, long_options, &option_index);
107     if (c == -1)
108     break;
109     switch(c) {
110     case 'h': print_help(); exit(0);
111     case 'V': print_version(); exit(0);
112     case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS)
113     psiconv_verbosity = PSICONV_VERB_PROGRESS;
114     break;
115     case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break;
116     case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break;
117     case 'e': exact = 1; break;
118     case 'o': outputfilename = strdup(optarg); break;
119     case 'T': type = strdup(optarg); break;
120     case '?': case ':': fputs("Try `-h' for more information",stderr);
121     exit(1);
122     default: fprintf(stderr,"Internal error: getopt_long returned character "
123     "code 0%o ?? (contact the author)\n", c);
124     exit(1); break;
125     }
126     }
127     if (optind < argc-1) {
128     fputs("I can only convert one file!\n"
129     "Try `-h' for more information\n",stderr);
130     exit(1);
131     } else if (optind == argc-1)
132     inputfilename = strdup(argv[optind]);
133    
134     /* Open inputfile for reading */
135    
136     if (strlen(inputfilename) != 0) {
137     if(stat(inputfilename,&fbuf) < 0) {
138     perror(inputfilename);
139     exit(1);
140     }
141     f = fopen(inputfilename,"r");
142     if (! f) {
143     perror(inputfilename);
144     exit(1);
145     }
146     } else
147     f = stdin;
148    
149     buf = psiconv_list_new(sizeof(psiconv_u8));
150     while (! feof(f))
151     psiconv_list_fread(buf,1024,f);
152    
153     if (strlen(inputfilename) != 0)
154     if (fclose(f)) {
155     perror(inputfilename);
156     exit(1);
157     }
158    
159     if (psiconv_parse(buf,&file))
160     if(exact)
161     exit(1);
162    
163     /* Open outputfile for writing */
164     if (strlen(outputfilename) != 0) {
165     f = fopen(outputfilename,"w");
166     if (! f) {
167     perror(outputfilename);
168     exit(1);
169     }
170     } else
171     f = stdout;
172    
173     strtoupper(type);
174     if (! strcmp(type,"HTML"))
175     psiconv_gen_html(f,file);
176     else if (! strcmp(type,"HTML4"))
177     psiconv_gen_html4(f,file);
178     else if (! strcmp(type,"ASCII"))
179     psiconv_gen_txt(f,file);
180 frodo 5 else if (! strcmp(type,"RTF"))
181     psiconv_gen_rtf(f,file);
182 frodo 17 else if (! strcmp(type,"IMAGE"))
183     psiconv_gen_image(f,file);
184 frodo 2 else {
185     fprintf(stderr,"Unknown output type: `%s'\n",type);
186     exit(1);
187     }
188    
189     if (strlen(outputfilename) != 0)
190     if (fclose(f)) {
191     perror(outputfilename);
192     exit(1);
193     }
194    
195     psiconv_free_file(file);
196    
197     exit(0);
198     }

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