source: trunk/gsdl/packages/wv-0.5.44-gs/src/lfo.c@ 1468

Last change on this file since 1468 was 1468, checked in by paynter, 24 years ago

The wv Packages from www.wvware.com is used to convert Word documents into
HTML. This is an adaptation of wv version 0.5.44 for greenstone; it is
called by the gsConvert.pl script.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include "wv.h"
4
5/*
6Word writes out the pllfo first by writing out a PL of LFO structures.
7It then enumerates through each LFO to figure out how many LFOLVLs each
8one has (LFO.clfolvl), and writes out, in order, each LFOLVL structure
9followed by its corresponding LVL structure (if LFOLVL.fFormatting is set).
10*/
11
12int wvGetLFO_records(LFO **lfo,LFOLVL **lfolvl,LVL **lvl,U32 *nolfo,U32 *nooflvl,U32 offset,U32 len,FILE *fd)
13 {
14 U32 i;
15 long end;
16 *nooflvl=0;
17 wvTrace(("lfo begins at %x len %d\n",offset,len));
18 fseek(fd, 0, SEEK_END);
19 end = ftell(fd);
20 wvGetLFO_PLF(lfo,nolfo,offset,len,fd);
21
22 for (i=0;i<*nolfo;i++)
23 *nooflvl += (*lfo)[i].clfolvl;
24 wvTrace(("pos %x %d\n",ftell(fd),*nooflvl));
25 wvTrace(("nolfo is %d nooflvl is %d\n",*nolfo,*nooflvl));
26
27 if (*nooflvl == 0)
28 {
29 *lfolvl = NULL;
30 *lvl = NULL;
31 return(0);
32 }
33
34 *lfolvl = (LFOLVL *)malloc(sizeof(LFOLVL) * *nooflvl);
35 *lvl = (LVL *)malloc(sizeof(LVL) * *nooflvl);
36
37 i=0;
38 while (i<*nooflvl)
39 {
40 wvInitLVL(&((*lvl)[i]));
41 wvTrace(("%d pos now %x %d\n",i,ftell(fd),*nooflvl));
42 if (ftell(fd) == end)
43 {
44 wvWarning("LFOLVL off the end of the file, continuing anyway\n");
45 i++;
46 continue;
47 }
48 wvGetLFOLVL(&((*lfolvl)[i]),fd);
49#if 0
50 if (wvInvalidLFOLVL(&((*lfolvl)[i])) )
51 continue;
52#endif
53 if ((*lfolvl)[i].fFormatting)
54 {
55 wvTrace(("formatting set\n"));
56 wvGetLVL(&((*lvl)[i]),fd);
57 }
58 i++;
59 }
60 return(0);
61 }
62
63int wvGetLFO_PLF(LFO **lfo,U32 *nolfo,U32 offset,U32 len,FILE *fd)
64 {
65 U32 i;
66 if (len == 0)
67 {
68 *lfo = NULL;
69 *nolfo = 0;
70 }
71 else
72 {
73 fseek(fd,offset,SEEK_SET);
74 *nolfo=read_32ubit(fd);
75 wvTrace(("%d\n",*nolfo));
76
77 *lfo= (LFO *) malloc(*nolfo* sizeof(LFO));
78 if (*lfo== NULL)
79 {
80 wvError(("NO MEM 1, failed to alloc %d bytes\n",*nolfo* sizeof(LFO)));
81 return(1);
82 }
83 for(i=0;i<*nolfo;i++)
84 wvGetLFO(&((*lfo)[i]),fd);
85 }
86 return(0);
87 }
88
89void wvGetLFO(LFO *item,FILE *fd)
90 {
91 int i;
92 item->lsid = read_32ubit(fd);
93 item->reserved1 = read_32ubit(fd);
94 item->reserved2 = read_32ubit(fd);
95 item->clfolvl = getc(fd);
96 for(i=0;i<3;i++)
97 item->reserved3[i] = getc(fd);
98 }
99
100void wvInitLFO(LFO *item)
101 {
102 int i;
103 item->lsid = 0;
104 item->reserved1 = 0;
105 item->reserved2 = 0;
106 item->clfolvl = 0;
107 for(i=0;i<3;i++)
108 item->reserved3[i] = 0;
109 }
110
111void wvGetLFOLVL(LFOLVL *item,FILE *fd)
112 {
113 U8 temp8;
114#ifdef PURIFY
115 wvInitLFOLVL(item);
116#endif
117 item->iStartAt = read_32ubit(fd);
118
119 while (wvInvalidLFOLVL(item))
120 {
121 wvTrace(("pos %x\n",ftell(fd)));
122 item->iStartAt = read_32ubit(fd);
123 }
124
125 temp8 = getc(fd);
126 item->ilvl = temp8 & 0x0F;
127 item->fStartAt = (temp8 & 0x10) >> 4;
128 item->fFormatting = (temp8 & 0x20) >> 5;
129 item->reserved1 = (temp8 & 0xC0) >> 6;
130 item->reserved2 = getc(fd);
131 item->reserved3 = getc(fd);
132 item->reserved4 = getc(fd);
133 }
134
135void wvInitLFOLVL(LFOLVL *item)
136 {
137 item->iStartAt = 0;
138 item->ilvl = 0;
139 item->fStartAt = 0;
140 item->fFormatting = 0;
141 item->reserved1 = 0;
142 item->reserved2 = 0;
143 item->reserved3 = 0;
144 item->reserved4 = 0;
145 }
146
147int wvInvalidLFOLVL(LFOLVL *item)
148 {
149
150 if (item->iStartAt != 0xffffffff)
151 return(0);
152#if 0
153 /*
154 a bloody russian doc, from Sergey V. Udaltsov <[email protected]> caused
155 the removal of this section
156 */
157 if (item->ilvl != 0xf)
158 return(0);
159 if (item->fStartAt != 1)
160 return(0);
161 if (item->fFormatting != 1)
162 return(0);
163 if (item->reserved1 != 0x3)
164 return(0);
165 if (item->reserved2 != 0xff)
166 return(0);
167 if (item->reserved3 != 0xff)
168 return(0);
169 if (item->reserved4 != 0xff)
170 return(0);
171#endif
172 wvWarning(("invalid list entry, trucking along happily anyway\n"));
173 return(1);
174 }
175
176int wvReleaseLFO_records(LFO **lfo,LFOLVL **lfolvl,LVL **lvl,U32 nooflvl)
177 {
178 U32 i;
179 wvTrace(("releaseing %d lvl records\n",nooflvl));
180 wvFree(*lfo);
181 wvFree(*lfolvl);
182 for(i=0;i<nooflvl;i++)
183 wvReleaseLVL(&((*lvl)[i]));
184 wvFree(*lvl);
185 return(0);
186 }
Note: See TracBrowser for help on using the repository browser.