File: wvparse.c

package info (click to toggle)
abiword 0.7.7-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 20,604 kB
  • ctags: 18,358
  • sloc: cpp: 88,791; ansic: 66,296; sh: 7,777; makefile: 3,397; xml: 687; perl: 361; awk: 273; sed: 36; csh: 28
file content (124 lines) | stat: -rw-r--r-- 2,446 bytes parent folder | download
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
#include <stdlib.h>
#include <stdio.h>
#include "wv.h"
#include "utf.h"

int wvInitParser(wvParseStruct *ps,FILE *fp)
	{
	int ret=0,reason=0;
	ps->userData=NULL;
	ps->lst = NULL;
	ps->intable=0;
	ps->endcell=0;
	ps->vmerges=NULL;
	ps->norows=0;
	ps->cellbounds=NULL;
	ps->nocellbounds=0;
	ps->fieldstate=0;
	ps->fieldmiddle=0;

	wvInitError();
	ps->password[0] = 0;
	/* set up the token table tree for faster lookups */
	tokenTreeInit();

	ret = wvOLEDecode(fp,&ps->mainfd,&ps->tablefd0,&ps->tablefd1,
		&ps->data,&ps->summary);

	switch(ret)
		{
		case 0:
			break;
		case 2:
			ret = wvOpenPreOLE(&fp,&ps->mainfd,&ps->tablefd0,&ps->tablefd1,
					&ps->data,&ps->summary);
			if (ret)
				return(ret);
			break;
		case 3:
			wvError(("Bad Ole\n"));
			return(3);
			break;
		default:
			return(-1);
			break;
		}

	if (ps->mainfd == NULL) 
		{
		ret = 4;
		wvOLEFree();
		wvError(("Not a word document\n"));
		return(-1);
		}

	wvGetFIB(&ps->fib,ps->mainfd);

	ps->tablefd = wvWhichTableStream(&ps->fib,ps);

	ret = wvQuerySupported(&ps->fib,&reason);

	if ( (ret&0x7fff) != WORD8 )
		ps->data = ps->mainfd;

	if ( (ret != WORD8) && (ret != WORD7) && (ret!= WORD6) )
		{
		/* return the errors and the encrypted files*/
		if (!(ret & 0x8000))
			wvError(("%s\n",wvReason(reason)));
		return(ret);
		}
	ret = 0;
	return ret;
	}

void wvSetPassword(char *password,wvParseStruct *ps)
	{
	int i=0,len;
	/* at this stage we are passing in an utf-8 password and
	later converting it to unicode, we should use the generic
	available mb to wide char stuff, but that isnt very prevalent
	yet, and this is the only time i think i go from utf to 
	unicode */

	while (*password)
		{
		len = our_mbtowc(&(ps->password[i]), password, 5);
		i++;
		password+=len;
		if (i == 16)
			break;
		}
	ps->password[i]=0;
	}

int wvOpenPreOLE(FILE **input, FILE **mainfd, FILE **tablefd0, FILE **tablefd1,FILE **data, FILE **summary)
	{
	int ret=-1;
	U16 magic;

	*mainfd=*input;
	*tablefd0=*input;
	*tablefd1=*input;
	*data=*input;
	*summary=NULL;

	if (*input)
		rewind(*input);
	else
		return(ret);
	magic = read_16ubit(*input);
	if (0xa5db == magic)
		{
		wvError(("Theres a good change that this is a word 2 doc of nFib %d\n",read_16ubit(*input)));
		rewind(*input);
		return(-1);
		}
	else if (0x37fe == magic)
		{
		wvError(("Theres a good change that this is a word 5 doc of nFib %d\n",read_16ubit(*input)));
		rewind(*input);
		return(0);
		}
	return(ret);
	}