source: trunk/gsdl/packages/wv-0.5.44-gs/src/bte.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: 2.9 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include "wv.h"
4
5void wvGetBTE(BTE *bte,FILE *fd)
6 {
7 U32 temp32 = read_32ubit(fd);
8#ifdef PURIFY
9 wvInitBTE(bte);
10#endif
11 bte->pn = temp32 & 0x003fffffL;
12 bte->unused = (temp32 & 0xffc00000L)>>22;
13 }
14
15void wvInitBTE(BTE *bte)
16 {
17 bte->pn = 0;
18 bte->unused = 0;
19 }
20
21void wvListBTE_PLCF(BTE **bte,U32 **pos,U32 *nobte)
22 {
23 U32 i=0;
24 for (i=0;i<*nobte;i++)
25 wvError(("range %x %x is pn %d\n",(*pos)[i],(*pos)[i+1],(*bte)[i].pn));
26 }
27
28int wvGetBTE_PLCF6(BTE **bte,U32 **pos,U32 *nobte,U32 offset,U32 len,FILE *fd)
29 {
30 U32 i;
31 if (len == 0)
32 {
33 *bte = NULL;
34 *pos = NULL;
35 *nobte = 0;
36 }
37 else
38 {
39 wvTrace(("offset is %x, len is %d\n",offset,len));
40 *nobte=(len-4)/(cb6BTE+4);
41 wvTrace(("no of bte is %d at %x\n",*nobte,offset));
42 *pos = (U32 *) malloc( (*nobte+1) * sizeof(U32));
43 if (*pos == NULL)
44 {
45 wvError(("NO MEM 1, failed to alloc %d bytes\n",(*nobte+1) * sizeof(U32)));
46 return(1);
47 }
48
49 *bte = (BTE *) malloc(*nobte * sizeof(BTE));
50 if (*bte == NULL)
51 {
52 wvError(("NO MEM 1, failed to alloc %d bytes\n",*nobte * sizeof(BTE)));
53 free(pos);
54 return(1);
55 }
56 fseek(fd,offset,SEEK_SET);
57 for(i=0;i<=*nobte;i++)
58 {
59 (*pos)[i]=read_32ubit(fd);
60 wvTrace(("pos is %x\n",(*pos)[i]));
61 }
62 for(i=0;i<*nobte;i++)
63 {
64 wvInitBTE(&((*bte)[i]));
65 (*bte)[i].pn = read_16ubit(fd);
66 }
67 }
68 return(0);
69 }
70
71int wvGetBTE_PLCF(BTE **bte,U32 **pos,U32 *nobte,U32 offset,U32 len,FILE *fd)
72 {
73 U32 i;
74 if (len == 0)
75 {
76 *bte = NULL;
77 *pos = NULL;
78 *nobte = 0;
79 }
80 else
81 {
82 *nobte=(len-4)/(cbBTE+4);
83 wvTrace(("no of bte is %d at %x\n",*nobte,offset));
84 *pos = (U32 *) malloc( (*nobte+1) * sizeof(U32));
85 if (*pos == NULL)
86 {
87 wvError(("NO MEM 1, failed to alloc %d bytes\n",(*nobte+1) * sizeof(U32)));
88 return(1);
89 }
90
91 *bte = (BTE *) malloc(*nobte * sizeof(BTE));
92 if (*bte == NULL)
93 {
94 wvError(("NO MEM 1, failed to alloc %d bytes\n",*nobte * sizeof(BTE)));
95 free(pos);
96 return(1);
97 }
98 fseek(fd,offset,SEEK_SET);
99 for(i=0;i<=*nobte;i++)
100 (*pos)[i]=read_32ubit(fd);
101 for(i=0;i<*nobte;i++)
102 wvGetBTE(&((*bte)[i]),fd);
103 }
104 return(0);
105 }
106
107void wvCopyBTE(BTE *dest,BTE *src)
108 {
109 memcpy(dest,src,sizeof(BTE));
110 }
111
112int wvGetBTE_FromFC(BTE *bte, U32 currentfc, BTE *list,U32 *fcs, int nobte)
113 {
114 int i=0;
115 while(i<nobte)
116 {
117 wvTrace(("currentfc %x bte %x %x\n",currentfc,wvNormFC(fcs[i],NULL),wvNormFC(fcs[i+1],NULL)));
118 if ( (currentfc >= wvNormFC(fcs[i],NULL)) && (currentfc < wvNormFC(fcs[i+1],NULL)) )
119 {
120 wvTrace(("valid\n"));
121 wvCopyBTE(bte,&list[i]);
122 return(0);
123 }
124 i++;
125 }
126 wvCopyBTE(bte,&list[i-1]);
127 return(0);
128 /*
129 return(1);
130 */
131 }
Note: See TracBrowser for help on using the repository browser.