source: gsdl/trunk/trunk/mg/lib/bitio_random.c@ 16583

Last change on this file since 16583 was 16583, checked in by davidb, 16 years ago

Undoing change commited in r16582

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/*************************************************************************
2 *
3 * bitio_random.c -- Functions for bitio to a file (random access)
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 **************************************************************************/
21
22#include "sysfuncs.h"
23#include "memlib.h"
24
25#include "longlong.h"
26
27#include "bitio_m_random.h"
28#include "bitio_m.h"
29
30
31void
32BIO_Random_Start (FILE * f, unsigned long len,
33 random_bitio_state * bs)
34{
35 ENCODE_START (f, len)
36 ENCODE_PAUSE (*bs)
37}
38
39void
40BIO_Random_Done (random_bitio_state * bs)
41{
42 ENCODE_CONTINUE (*bs)
43 ENCODE_DONE
44}
45
46void
47BIO_Random_Encode_Bit (int bit, random_bitio_state * bs)
48{
49 ENCODE_CONTINUE (*bs)
50 ENCODE_BIT (bit);
51 ENCODE_PAUSE (*bs)
52}
53
54int
55BIO_Random_Decode_Bit (random_bitio_state * bs)
56{
57 register int val;
58 DECODE_CONTINUE (*bs)
59 val = DECODE_BIT;
60 DECODE_PAUSE (*bs)
61 return (val);
62}
63
64
65void
66BIO_Random_Unary_Encode (unsigned long val, random_bitio_state * bs,
67 unsigned long *bits)
68{
69 ENCODE_CONTINUE (*bs)
70 if (bits)
71 UNARY_ENCODE_L (val, *bits);
72 else
73 UNARY_ENCODE (val);
74 ENCODE_PAUSE (*bs)
75}
76
77
78unsigned long
79BIO_Random_Unary_Decode (random_bitio_state * bs,
80 unsigned long *bits)
81{
82 register unsigned long val;
83 DECODE_CONTINUE (*bs)
84 if (bits)
85 UNARY_DECODE_L (val, *bits);
86 else
87 UNARY_DECODE (val);
88 DECODE_PAUSE (*bs)
89 return (val);
90}
91
92
93
94
95
96
97
98void
99BIO_Random_Binary_Encode (unsigned long val, unsigned long b,
100 random_bitio_state * bs, unsigned long *bits)
101{
102 ENCODE_CONTINUE (*bs)
103 if (bits)
104 BINARY_ENCODE_L (val, b, *bits);
105 else
106 BINARY_ENCODE (val, b);
107 ENCODE_PAUSE (*bs)
108}
109
110
111unsigned long
112BIO_Random_Binary_Decode (unsigned long b,
113 random_bitio_state * bs,
114 unsigned long *bits)
115{
116 register unsigned long val;
117 DECODE_CONTINUE (*bs)
118 if (bits)
119 BINARY_DECODE_L (val, b, *bits);
120 else
121 BINARY_DECODE (val, b);
122 DECODE_PAUSE (*bs)
123 return (val);
124}
125
126
127
128
129
130
131
132void
133BIO_Random_Gamma_Encode (unsigned long val, random_bitio_state * bs,
134 unsigned long *bits)
135{
136 ENCODE_CONTINUE (*bs)
137 if (bits)
138 GAMMA_ENCODE_L (val, *bits);
139 else
140 GAMMA_ENCODE (val);
141 ENCODE_PAUSE (*bs)
142}
143
144
145unsigned long
146BIO_Random_Gamma_Decode (random_bitio_state * bs,
147 unsigned long *bits)
148{
149 register unsigned long val;
150 DECODE_CONTINUE (*bs)
151 if (bits)
152 GAMMA_DECODE_L (val, *bits);
153 else
154 GAMMA_DECODE (val);
155 DECODE_PAUSE (*bs)
156 return (val);
157}
158
159
160
161
162void
163BIO_Random_Delta_Encode (unsigned long val, random_bitio_state * bs,
164 unsigned long *bits)
165{
166 ENCODE_CONTINUE (*bs)
167 if (bits)
168 DELTA_ENCODE_L (val, *bits);
169 else
170 DELTA_ENCODE (val);
171 ENCODE_PAUSE (*bs)
172}
173
174
175unsigned long
176BIO_Random_Delta_Decode (random_bitio_state * bs,
177 unsigned long *bits)
178{
179 register unsigned long val;
180 DECODE_CONTINUE (*bs)
181 if (bits)
182 DELTA_DECODE_L (val, *bits);
183 else
184 DELTA_DECODE (val);
185 DECODE_PAUSE (*bs)
186 return (val);
187}
188
189void
190BIO_Random_Elias_Encode (unsigned long val, unsigned long b, double s,
191 random_bitio_state * bs, unsigned long *bits)
192{
193 ENCODE_CONTINUE (*bs)
194 if (bits)
195 ELIAS_ENCODE_L (val, b, s, *bits);
196 else
197 ELIAS_ENCODE (val, b, s);
198 ENCODE_PAUSE (*bs)
199}
200
201
202unsigned long
203BIO_Random_Elias_Decode (unsigned long b, double s,
204 random_bitio_state * bs,
205 unsigned long *bits)
206{
207 register unsigned long val;
208 DECODE_CONTINUE (*bs)
209 if (bits)
210 ELIAS_DECODE_L (val, b, s, *bits);
211 else
212 ELIAS_DECODE (val, b, s);
213 DECODE_PAUSE (*bs)
214 return (val);
215}
216
217void
218BIO_Random_Bblock_Encode (unsigned long val, unsigned long b,
219 random_bitio_state * bs, unsigned long *bits)
220{
221 ENCODE_CONTINUE (*bs)
222 if (bits)
223 BBLOCK_ENCODE_L (val, b, *bits);
224 else
225 BBLOCK_ENCODE (val, b);
226 ENCODE_PAUSE (*bs)
227}
228
229
230unsigned long
231BIO_Random_Bblock_Decode (unsigned long b,
232 random_bitio_state * bs,
233 unsigned long *bits)
234{
235 register unsigned long val;
236 DECODE_CONTINUE (*bs)
237 if (bits)
238 BBLOCK_DECODE_L (val, b, *bits);
239 else
240 BBLOCK_DECODE (val, b);
241 DECODE_PAUSE (*bs)
242 return (val);
243}
244
245void
246BIO_Random_Seek (unsigned long pos, random_bitio_state * bs)
247{
248 ENCODE_CONTINUE (*bs)
249 ENCODE_SEEK (pos);
250 ENCODE_PAUSE (*bs)
251}
252void
253BIO_Random_Flush (random_bitio_state * bs)
254{
255 ENCODE_CONTINUE (*bs)
256 ENCODE_FLUSH;
257 ENCODE_PAUSE (*bs)
258}
259
260unsigned long
261BIO_Random_Tell (random_bitio_state * bs)
262{
263 register unsigned long t;
264 ENCODE_CONTINUE (*bs)
265 t = ENCODE_TELL;
266 ENCODE_PAUSE (*bs)
267 return (t);
268}
269
270#ifdef USE_LONG_LONG
271
272void
273BIO_Random_Seek_LL (mg_ullong pos, random_bitio_state * bs)
274{
275 ENCODE_CONTINUE(*bs)
276
277 if ((((pos) >> 3) >= (mg_ullong)__base) &&
278 ((((pos)+7) >> 3) < (mg_ullong)(__base + __len)))
279 {
280 __pos = (long)((pos) - (mg_ullong)(__base << 3));
281 }
282 else
283 {
284 ENCODE_FLUSH;
285 __base = (long)(((pos) >> (__sft+3)) << __sft);
286
287 fseek(__file,__base,0);
288 fread(__buf,1,__len,__file);
289 __pos = (long)((pos) & ((8 << __sft)-1));
290 }
291
292 ENCODE_PAUSE(*bs)
293}
294
295mg_ullong
296BIO_Random_Tell_LL (random_bitio_state * bs)
297{
298 mg_ullong t;
299 ENCODE_CONTINUE(*bs)
300 t = (((mg_ullong)__base) << 3ull) + __pos;
301 ENCODE_PAUSE(*bs)
302 return(t);
303}
304
305#endif
Note: See TracBrowser for help on using the repository browser.