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 <stdlib.h>
25 #include <stdio.h>
26 #include "wv.h"
27
28 void
wvGetPCD(PCD * item,wvStream * fd)29 wvGetPCD (PCD * item, wvStream * fd)
30 {
31 U8 temp8;
32 temp8 = read_8ubit (fd);
33 #ifdef PURIFY
34 wvInitPCD (item);
35 #endif
36 item->fNoParaLast = temp8 & 0x01;
37 item->fPaphNil = (temp8 & 0x02) >> 1;
38 item->fCopied = (temp8 & 0x04) >> 2;
39 item->reserved = (temp8 & 0xf8) >> 3;
40 item->fn = read_8ubit (fd);
41 item->fc = read_32ubit (fd);
42 wvGetPRM (&item->prm, fd);
43 }
44
45 void
wvInitPCD(PCD * item)46 wvInitPCD (PCD * item)
47 {
48 item->fNoParaLast = 0;
49 item->fPaphNil = 0;
50 item->fCopied = 0;
51 item->reserved = 0;
52 item->fn = 0;
53 item->fc = 0;
54 wvInitPRM (&item->prm);
55 }
56
57
58 int
wvReleasePCD_PLCF(PCD * pcd,U32 * pos)59 wvReleasePCD_PLCF (PCD * pcd, U32 * pos)
60 {
61 wvFree (pcd);
62 wvFree (pos);
63 return (0);
64 }
65
66
67 int
wvGetPCD_PLCF(PCD ** pcd,U32 ** pos,U32 * nopcd,U32 offset,U32 len,wvStream * fd)68 wvGetPCD_PLCF (PCD ** pcd, U32 ** pos, U32 * nopcd, U32 offset, U32 len,
69 wvStream * fd)
70 {
71 U32 i;
72 if (len == 0)
73 {
74 *pcd = NULL;
75 *pos = NULL;
76 *nopcd = 0;
77 }
78 else
79 {
80 *nopcd = (len - 4) / (cbPCD + 4);
81 *pos = (U32 *) wvMalloc ((*nopcd + 1) * sizeof (U32));
82 if (*pos == NULL)
83 {
84 wvError (
85 ("NO MEM 1, failed to alloc %d bytes\n",
86 (*nopcd + 1) * sizeof (U32)));
87 return (1);
88 }
89
90 *pcd = (PCD *) wvMalloc (*nopcd * sizeof (PCD));
91 if (*pcd == NULL)
92 {
93 wvError (
94 ("NO MEM 1, failed to alloc %d bytes\n",
95 *nopcd * sizeof (PCD)));
96 wvFree (pos);
97 return (1);
98 }
99 wvStream_goto (fd, offset);
100 for (i = 0; i <= *nopcd; i++)
101 {
102 (*pos)[i] = read_32ubit (fd);
103 wvTrace (("pcd pos is %x\n", (*pos)[i]));
104 }
105 for (i = 0; i < *nopcd; i++)
106 {
107 wvGetPCD (&((*pcd)[i]), fd);
108 wvTrace (
109 ("pcd fc is %x, complex is %d, index is %d\n",
110 (*pcd)[i].fc, (*pcd)[i].prm.fComplex,
111 (*pcd)[i].prm.para.var2.igrpprl));
112 }
113 }
114 return (0);
115 }
116