1 /* wvWare
2 * Copyright (C) Caolan McNamara, Dom Lachowicz, and others
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "wv.h"
27 #include "wvinternal.h"
28
29 U32
wvGetFAnchor(FAnchor * item,wvStream * fd)30 wvGetFAnchor (FAnchor * item, wvStream * fd)
31 {
32 /* It is supposed to be a RECT, but its only 4 long so... */
33 item->left = read_8ubit (fd);
34 item->right = read_8ubit (fd);
35 item->top = read_8ubit (fd);
36 item->bottom = read_8ubit (fd);
37 return (4);
38 }
39
40 void
wvInitFOPTEArray(FOPTE ** fopte)41 wvInitFOPTEArray (FOPTE ** fopte)
42 {
43 *fopte = NULL;
44 }
45
46 void
wvReleaseFOPTEArray(FOPTE ** fopte)47 wvReleaseFOPTEArray (FOPTE ** fopte)
48 {
49 U32 i = 0;
50 if (*fopte)
51 {
52 while ((*fopte)[i].pid != 0)
53 {
54 wvFree ((*fopte)[i].entry);
55 i++;
56 }
57 wvFree (*fopte);
58 }
59 }
60
61 U32
wvGetFOPTEArray(FOPTE ** fopte,MSOFBH * msofbh,wvStream * fd)62 wvGetFOPTEArray (FOPTE ** fopte, MSOFBH * msofbh, wvStream * fd)
63 {
64 U32 i, j, count = 0;
65 U32 no = msofbh->cbLength / 6;
66 *fopte = (FOPTE *) wvMalloc (sizeof (FOPTE) * no);
67 no = 0;
68 while (count < msofbh->cbLength)
69 {
70 wvTrace (
71 ("count %x %x, pos %x\n", count, msofbh->cbLength,
72 wvStream_tell (fd)));
73 count += wvGetFOPTE (&(*fopte)[no], fd);
74 no++;
75 }
76 *fopte = (FOPTE *) realloc (*fopte, sizeof (FOPTE) * (no + 1));
77 for (i = 0; i < no; i++)
78 {
79 if ((*fopte)[i].fComplex)
80 for (j = 0; j < (*fopte)[i].op; j++)
81 (*fopte)[i].entry[j] = read_8ubit (fd);
82 }
83 (*fopte)[i].pid = 0;
84 wvTrace (("returning %x\n", count));
85 return (count);
86 }
87
88
89 void
wvReleaseFOPTE(FOPTE * afopte)90 wvReleaseFOPTE (FOPTE * afopte)
91 {
92 wvFree (afopte->entry);
93 }
94
95 U32
wvGetFOPTE(FOPTE * afopte,wvStream * fd)96 wvGetFOPTE (FOPTE * afopte, wvStream * fd)
97 {
98 U16 dtemp;
99 wvTrace (("pos is %x\n", wvStream_tell (fd)));
100 dtemp = read_16ubit (fd);
101 wvTrace (("dtemp is %x\n", dtemp));
102 #ifdef PURIFY
103 afopte->pid = 0;
104 afopte->fBid = 0;
105 afopte->fComplex = 0;
106 #endif
107 afopte->pid = (dtemp & 0x3fff);
108 afopte->entry = 0;
109 afopte->fBid = ((dtemp & 0x4000) >> 14);
110 afopte->fComplex = ((dtemp & 0x8000) >> 15);
111 afopte->op = read_32ubit (fd);
112
113 wvTrace (
114 ("orig %x,pid is %x %d, val is %x\n", dtemp, afopte->pid,
115 afopte->pid, afopte->op));
116 if (afopte->fComplex)
117 {
118 wvTrace (("1 complex len is %d (%x)\n", afopte->op, afopte->op));
119 afopte->entry = (U8 *) wvMalloc (afopte->op);
120 return (afopte->op + 6);
121 }
122
123 afopte->entry = NULL;
124 return (6);
125 }
126
127 void
wvPutFAnchor(FAnchor * item,wvStream * fd)128 wvPutFAnchor (FAnchor * item, wvStream * fd)
129 {
130 /* It is supposed to be a RECT, but its only 4 long so... */
131 write_8ubit (fd, (U8) item->left);
132 write_8ubit (fd, (U8) item->right);
133 write_8ubit (fd, (U8) item->top);
134 write_8ubit (fd, (U8) item->bottom);
135 }
136
137 void
wvPutFOPTE(FOPTE * afopte,wvStream * fd)138 wvPutFOPTE (FOPTE * afopte, wvStream * fd)
139 {
140 U16 dtemp = (U16) 0;
141
142 dtemp |= afopte->pid;
143 dtemp |= afopte->fBid << 14;
144 dtemp |= afopte->fComplex << 15;
145
146 write_16ubit (fd, dtemp);
147 write_32ubit (fd, afopte->op);
148 }
149
150 /* TODO: check to make sure that this is correct */
151
152 void
wvPutFOPTEArray(FOPTE ** fopte,MSOFBH * msofbh,wvStream * fd)153 wvPutFOPTEArray (FOPTE ** fopte, MSOFBH * msofbh, wvStream * fd)
154 {
155 U32 i, j, count = 0;
156 U32 no = 0;
157
158 while (count < msofbh->cbLength)
159 {
160 /*lvm007@aha.ru fix*/
161 count += 6;
162 wvPutFOPTE (&(*fopte)[no], fd);
163 no++;
164 }
165
166 for (i = 0; i < no; i++)
167 {
168 if ((*fopte)[i].fComplex)
169 for (j = 0; j < (*fopte)[i].op; j++)
170 write_8ubit (fd, (*fopte)[i].entry[j]);
171 }
172 }
173