File: lfo.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 (186 lines) | stat: -rw-r--r-- 4,049 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
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
#include <stdlib.h>
#include <stdio.h>
#include "wv.h"

/*
Word writes out the pllfo first by writing out a PL of LFO structures. 
It then enumerates through each LFO to figure out how many LFOLVLs each 
one has (LFO.clfolvl), and writes out, in order, each LFOLVL structure 
followed by its corresponding LVL structure (if LFOLVL.fFormatting is set).
*/

int wvGetLFO_records(LFO **lfo,LFOLVL **lfolvl,LVL **lvl,U32 *nolfo,U32 *nooflvl,U32 offset,U32 len,FILE *fd)
	{
	U32 i;
	long end;
	*nooflvl=0;
	wvTrace(("lfo begins at %x len %d\n",offset,len));
	fseek(fd, 0, SEEK_END);
	end = ftell(fd);
	wvGetLFO_PLF(lfo,nolfo,offset,len,fd);

	for (i=0;i<*nolfo;i++)
		*nooflvl += (*lfo)[i].clfolvl;
	wvTrace(("pos %x %d\n",ftell(fd),*nooflvl));
	wvTrace(("nolfo is %d nooflvl is %d\n",*nolfo,*nooflvl));

	if (*nooflvl == 0)
		{
		*lfolvl = NULL;
		*lvl = NULL;
		return(0);
		}

	*lfolvl = (LFOLVL *)malloc(sizeof(LFOLVL) * *nooflvl);
	*lvl = (LVL *)malloc(sizeof(LVL) * *nooflvl);
	
	i=0;
	while (i<*nooflvl)
		{
		wvInitLVL(&((*lvl)[i]));
		wvTrace(("%d pos now %x %d\n",i,ftell(fd),*nooflvl));
		if (ftell(fd) == end)
			{
			wvWarning("LFOLVL off the end of the file, continuing anyway\n");
			i++;
			continue;
			}
		wvGetLFOLVL(&((*lfolvl)[i]),fd);
#if 0
		if (wvInvalidLFOLVL(&((*lfolvl)[i])) )
			continue;
#endif
		if ((*lfolvl)[i].fFormatting)
			{
			wvTrace(("formatting set\n"));
			wvGetLVL(&((*lvl)[i]),fd);
			}
		i++;
		}
	return(0);
	}

int wvGetLFO_PLF(LFO **lfo,U32 *nolfo,U32 offset,U32 len,FILE *fd)
	{
	U32 i;
	if (len == 0)
		{
		*lfo = NULL;
		*nolfo = 0;
		}
	else
        {
        fseek(fd,offset,SEEK_SET);
        *nolfo=read_32ubit(fd);
		wvTrace(("%d\n",*nolfo));

        *lfo= (LFO *) malloc(*nolfo* sizeof(LFO));
        if (*lfo== NULL)
            {
            wvError(("NO MEM 1, failed to alloc %d bytes\n",*nolfo* sizeof(LFO)));
            return(1);
            }
        for(i=0;i<*nolfo;i++)
            wvGetLFO(&((*lfo)[i]),fd);
        }
	return(0);
	}

void wvGetLFO(LFO *item,FILE *fd)
	{
	int i;
	item->lsid = read_32ubit(fd);     
    item->reserved1 = read_32ubit(fd);
    item->reserved2 = read_32ubit(fd);  
    item->clfolvl = getc(fd);  
	for(i=0;i<3;i++)
    	item->reserved3[i] = getc(fd);
	}

void wvInitLFO(LFO *item)
	{
	int i;
	item->lsid = 0;
    item->reserved1 = 0;
    item->reserved2 = 0;
    item->clfolvl = 0;
	for(i=0;i<3;i++)
    	item->reserved3[i] = 0;
	}

void wvGetLFOLVL(LFOLVL *item,FILE *fd)
	{
	U8 temp8;
#ifdef PURIFY
	wvInitLFOLVL(item);
#endif
	item->iStartAt = read_32ubit(fd);

	while (wvInvalidLFOLVL(item))
		{
		wvTrace(("pos %x\n",ftell(fd)));
		item->iStartAt = read_32ubit(fd);
		}

	temp8 = getc(fd);
    item->ilvl = temp8 & 0x0F;
    item->fStartAt = (temp8 & 0x10) >> 4;
    item->fFormatting = (temp8 & 0x20) >> 5;
    item->reserved1 = (temp8 & 0xC0) >> 6;
    item->reserved2 = getc(fd);
    item->reserved3 = getc(fd);
    item->reserved4 = getc(fd);
	}

void wvInitLFOLVL(LFOLVL *item)
	{
	item->iStartAt = 0;
    item->ilvl = 0;
    item->fStartAt = 0;
    item->fFormatting = 0;
    item->reserved1 = 0;
    item->reserved2 = 0;
    item->reserved3 = 0;
    item->reserved4 = 0;
	}

int wvInvalidLFOLVL(LFOLVL *item)
	{
	
	if (item->iStartAt != 0xffffffff)
		return(0);
#if 0	
	/* 
	a bloody russian doc, from Sergey V. Udaltsov <svu@pop.convey.ru> caused 
	the removal of this section 
	*/
    if (item->ilvl != 0xf)
		return(0);
    if (item->fStartAt != 1)
		return(0);
    if (item->fFormatting != 1)
		return(0);
    if (item->reserved1 != 0x3) 
		return(0);
    if (item->reserved2 != 0xff) 
		return(0);
    if (item->reserved3 != 0xff) 
		return(0);
    if (item->reserved4 != 0xff) 
		return(0);
#endif
	wvWarning(("invalid list entry, trucking along happily anyway\n"));
	return(1);
	}

int wvReleaseLFO_records(LFO **lfo,LFOLVL **lfolvl,LVL **lvl,U32 nooflvl)
	{
	U32 i;
	wvTrace(("releaseing %d lvl records\n",nooflvl));
	wvFree(*lfo);
	wvFree(*lfolvl);
	for(i=0;i<nooflvl;i++)
		wvReleaseLVL(&((*lvl)[i]));
	wvFree(*lvl);
	return(0);
	}