-
Notifications
You must be signed in to change notification settings - Fork 0
/
lvl.c
177 lines (162 loc) · 4.26 KB
/
lvl.c
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
/* wvWare
* Copyright (C) Caolan McNamara, Dom Lachowicz, and others
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "wv.h"
void
wvInitLVL (LVL * lvl)
{
lvl->grpprlPapx = NULL;
lvl->grpprlChpx = NULL;
lvl->numbertext = NULL;
wvInitLVLF (&(lvl->lvlf));
}
void
wvCopyLVL (LVL * dest, LVL * src)
{
int len;
wvReleaseLVL (dest);
wvInitLVL (dest);
wvCopyLVLF (&(dest->lvlf), &(src->lvlf));
if (src->lvlf.cbGrpprlPapx > 0)
{
dest->grpprlPapx = (U8 *) wvMalloc (src->lvlf.cbGrpprlPapx);
memcpy (dest->grpprlPapx, src->grpprlPapx, src->lvlf.cbGrpprlPapx);
}
else
dest->grpprlPapx = NULL;
if (src->lvlf.cbGrpprlChpx > 0)
{
dest->grpprlChpx = (U8 *) wvMalloc (src->lvlf.cbGrpprlChpx);
memcpy (dest->grpprlChpx, src->grpprlChpx, src->lvlf.cbGrpprlChpx);
}
else
dest->grpprlChpx = NULL;
if (src->numbertext == NULL)
dest->numbertext = NULL;
else
{
len = src->numbertext[0];
dest->numbertext = (U16 *) wvMalloc (sizeof (U16) * (len + 2));
memcpy (dest->numbertext, src->numbertext, len + 2);
}
}
void
wvGetLVL (LVL * lvl, wvStream * fd)
{
int len;
wvGetLVLF (&(lvl->lvlf), fd);
if (lvl->lvlf.cbGrpprlPapx > 0)
{
lvl->grpprlPapx = (U8 *) wvMalloc (lvl->lvlf.cbGrpprlPapx);
wvStream_read (lvl->grpprlPapx, sizeof (U8), lvl->lvlf.cbGrpprlPapx,
fd);
}
else
lvl->grpprlPapx = NULL;
if (lvl->lvlf.cbGrpprlChpx > 0)
{
lvl->grpprlChpx = (U8 *) wvMalloc (lvl->lvlf.cbGrpprlChpx);
wvStream_read (lvl->grpprlChpx, sizeof (U8), lvl->lvlf.cbGrpprlChpx,
fd);
}
else
lvl->grpprlChpx = NULL;
len = read_16ubit (fd);
if (len > 0)
{
int i = 0;
lvl->numbertext = (U16 *) wvMalloc (sizeof (U16) * (len + 2));
lvl->numbertext[0] = len;
for(i = 0; i < len; i++)
lvl->numbertext[i + 1] = read_16ubit (fd);
lvl->numbertext[len + 1] = 0;
}
else
lvl->numbertext = NULL;
wvTrace (("len is %d\n", len));
}
void
wvReleaseLVL (LVL * lvl)
{
if (lvl == NULL)
return;
wvFree (lvl->grpprlPapx);
wvFree (lvl->grpprlChpx);
wvFree (lvl->numbertext);
}
void
wvCopyLVLF (LVLF * dest, LVLF * src)
{
memcpy (dest, src, sizeof (LVLF));
}
void
wvGetLVLF (LVLF * item, wvStream * fd)
{
U8 temp8;
int i;
#ifdef PURIFY
wvInitLVLF (item);
#endif
item->iStartAt = read_32ubit (fd);
wvTrace (("iStartAt is %d\n", item->iStartAt));
item->nfc = read_8ubit (fd);
temp8 = read_8ubit (fd);
item->jc = temp8 & 0x03;
item->fLegal = (temp8 & 0x04) >> 2;
item->fNoRestart = (temp8 & 0x08) >> 3;
item->fPrev = (temp8 & 0x10) >> 4;
item->fPrevSpace = (temp8 & 0x20) >> 5;
item->fWord6 = (temp8 & 0x40) >> 6;
item->reserved1 = (temp8 & 0x80) >> 7;
for (i = 0; i < 9; i++)
item->rgbxchNums[i] = read_8ubit (fd);
item->ixchFollow = read_8ubit (fd);;
item->dxaSpace = read_32ubit (fd);
item->dxaIndent = read_32ubit (fd);
item->cbGrpprlChpx = read_8ubit (fd);
item->cbGrpprlPapx = read_8ubit (fd);
item->reserved2 = read_16ubit (fd);;
}
void
wvInitLVLF (LVLF * item)
{
int i;
item->iStartAt = 1;
item->nfc = 0;
item->jc = 0;
item->fLegal = 0;
item->fNoRestart = 0;
item->fPrev = 0;
item->fPrevSpace = 0;
item->fWord6 = 0;
item->reserved1 = 0;
for (i = 0; i < 9; i++)
item->rgbxchNums[i] = 0;
item->ixchFollow = 0;
item->dxaSpace = 0;
item->dxaIndent = 0;
item->cbGrpprlChpx = 0;
item->cbGrpprlPapx = 0;
item->reserved2 = 0;
}