-
Notifications
You must be signed in to change notification settings - Fork 6
/
wvConvert.c
304 lines (276 loc) · 6.59 KB
/
wvConvert.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/* wvWare
* Copyright (C) Caolan McNamara, Dom Lachowicz, and others
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "wv.h"
#include "getopt.h"
/*
Released under GPL, written by Caolan.McNamara@ul.ie.
Copyright (C) 1998,1999
Caolan McNamara
Real Life: Caolan McNamara * Doing: MSc in HCI
Work: Caolan.McNamara@ul.ie * Phone: +353-86-8790257
URL: http://skynet.csn.ul.ie/~caolan * Sig: an oblique strategy
How would you have done it?
*/
/*
returns 1 for not an ole doc
2 ole but not supported word doc
-1 for an error of some unknown kind
0 on success
*/
int myelehandler (wvParseStruct * ps, wvTag tag, void *props, int dirty);
int mydochandler (wvParseStruct * ps, wvTag tag);
int wvOpenConfig (state_data *myhandle,char *config);
void
usage (void)
{
printf
("Usage: wvConvert [--config config.xml] [--password password] filename.doc\n");
exit (-1);
}
int
main (int argc, char **argv)
{
char *config = NULL;
char *password = NULL;
int ret;
state_data myhandle;
expand_data expandhandle;
wvParseStruct ps;
int c, index = 0;
static struct option long_options[] = {
{"config", 1, 0, 'x'},
{"password", 1, 0, 'p'},
{0, 0, 0, 0}
};
if (argc < 2)
usage ();
while (1)
{
c = getopt_long (argc, argv, "x:p:", long_options, &index);
if (c == -1)
break;
switch (c)
{
case 'x':
if (optarg)
config = optarg;
else
wvError (("No config file given to config option"));
break;
case 'p':
if (optarg)
password = optarg;
else
wvError (("No password given to password option"));
break;
default:
usage ();
break;
}
}
wvInit ();
ret = wvInitParser (&ps, argv[optind]);
ps.filename = argv[optind];
if (ret == 4)
{
ret = 0;
if (password == NULL)
{
wvError (
("Password required, this is an encrypted document\n"));
return (-1);
}
else
{
wvSetPassword (password, &ps);
if (wvDecrypt97 (&ps))
{
wvError (("Incorrect Password\n"));
return (-1);
}
}
}
else if (ret == 7)
{
ret = 0;
if (password == NULL)
{
wvError (
("Password required, this is an encrypted document\n"));
return (-1);
}
else
{
wvSetPassword (password, &ps);
if (wvDecrypt95 (&ps))
{
wvError (("Incorrect Password\n"));
return (-1);
}
}
}
if (ret)
{
wvError (("startup error with file %s\n", argv[1]));
wvOLEFree (&ps);
return (2);
}
wvSetElementHandler (&ps, myelehandler);
wvSetDocumentHandler (&ps, mydochandler);
wvInitStateData (&myhandle);
if (wvOpenConfig (&myhandle,config) == 0)
wvError (("config file not found\n"));
else
ret = wvParseConfig (&myhandle);
if (!ret)
{
expandhandle.sd = &myhandle;
ps.userData = &expandhandle;
ret = wvText (&ps);
}
wvReleaseStateData (&myhandle);
if (ret == 2)
return (2);
else if (ret != 0)
ret = -1;
wvOLEFree (&ps);
return (ret);
}
int
myelehandler (wvParseStruct * ps, wvTag tag, void *props, int dirty)
{
expand_data *data = (expand_data *) ps->userData;
data->anSttbfAssoc = &ps->anSttbfAssoc;
data->lfo = &ps->lfo;
data->lfolvl = ps->lfolvl;
data->lvl = ps->lvl;
data->nolfo = &ps->nolfo;
data->nooflvl = &ps->nooflvl;
data->stsh = &ps->stsh;
data->lst = &ps->lst;
data->noofLST = &ps->noofLST;
data->liststartnos = &ps->liststartnos;
data->listnfcs = &ps->listnfcs;
data->finallvl = &ps->finallvl;
data->fib = &ps->fib;
data->dop = &ps->dop;
data->intable = &ps->intable;
data->cellbounds = &ps->cellbounds;
data->nocellbounds = &ps->nocellbounds;
data->endcell = &ps->endcell;
data->vmerges = &ps->vmerges;
data->norows = &ps->norows;
data->nextpap = &ps->nextpap;
data->charset = wvAutoCharset (ps);
data->props = props;
switch (tag)
{
case PARABEGIN:
wvBeginPara (data);
break;
case PARAEND:
wvEndPara (data);
wvCopyPAP (&data->lastpap, (PAP *) (data->props));
break;
case SECTIONBEGIN:
wvBeginSection (data);
break;
case SECTIONEND:
wvEndSection (data);
break;
case CHARPROPBEGIN:
wvBeginCharProp (data, NULL);
break;
case CHARPROPEND:
wvEndCharProp (data);
break;
default:
break;
}
return (0);
}
int
mydochandler (wvParseStruct * ps, wvTag tag)
{
expand_data *data = (expand_data *) ps->userData;
data->anSttbfAssoc = &ps->anSttbfAssoc;
data->lfo = &ps->lfo;
data->lfolvl = ps->lfolvl;
data->lvl = ps->lvl;
data->nolfo = &ps->nolfo;
data->nooflvl = &ps->nooflvl;
data->stsh = &ps->stsh;
data->lst = &ps->lst;
data->noofLST = &ps->noofLST;
data->liststartnos = &ps->liststartnos;
data->listnfcs = &ps->listnfcs;
data->finallvl = &ps->finallvl;
data->fib = &ps->fib;
data->dop = &ps->dop;
data->intable = &ps->intable;
data->cellbounds = &ps->cellbounds;
data->nocellbounds = &ps->nocellbounds;
data->endcell = &ps->endcell;
data->vmerges = &ps->vmerges;
data->norows = &ps->norows;
data->charset = wvAutoCharset (ps);
switch (tag)
{
case DOCBEGIN:
wvBeginDocument (data);
break;
case DOCEND:
wvEndDocument (data);
break;
default:
break;
}
return (0);
}
int
wvOpenConfig (state_data *myhandle,char *config)
{
FILE *tmp;
int i = 0;
if (config == NULL)
config = "wvConfig.xml";
else
i = 1;
tmp = fopen (config, "rb");
if (tmp == NULL)
{
if (i)
wvError (
("Attempt to open %s failed, using %s\n", config,
HTMLCONFIG));
config = XMLCONFIG;
tmp = fopen (config, "rb");
}
myhandle->path = config;
myhandle->fp = tmp;
return (tmp == NULL ? 0 : 1);
}