source: trunk/gsdl/packages/mg/lib/bitio_random.c@ 1153

Last change on this file since 1153 was 439, checked in by sjboddie, 25 years ago

renamed mg-1.3d directory mg

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 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 * $Id: bitio_random.c 439 1999-08-10 21:23:37Z sjboddie $
21 *
22 **************************************************************************/
23
24/*
25 $Log$
26 Revision 1.1 1999/08/10 21:16:46 sjboddie
27 renamed mg-1.3d directory mg
28
29 Revision 1.1 1998/11/17 09:31:50 rjmcnab
30 *** empty log message ***
31
32 * Revision 1.1 1994/08/22 00:24:40 tes
33 * Initial placement under CVS.
34 *
35 */
36
37static char *RCSID = "$Id: bitio_random.c 439 1999-08-10 21:23:37Z sjboddie $";
38
39
40
41#include "sysfuncs.h"
42#include "memlib.h"
43
44#include "bitio_m_random.h"
45#include "bitio_m.h"
46
47
48void
49BIO_Random_Start (FILE * f, unsigned long len,
50 random_bitio_state * bs)
51{
52 ENCODE_START (f, len)
53 ENCODE_PAUSE (*bs)
54}
55
56void
57BIO_Random_Done (random_bitio_state * bs)
58{
59 ENCODE_CONTINUE (*bs)
60 ENCODE_DONE
61}
62
63void
64BIO_Random_Encode_Bit (int bit, random_bitio_state * bs)
65{
66 ENCODE_CONTINUE (*bs)
67 ENCODE_BIT (bit);
68 ENCODE_PAUSE (*bs)
69}
70
71int
72BIO_Random_Decode_Bit (random_bitio_state * bs)
73{
74 register int val;
75 DECODE_CONTINUE (*bs)
76 val = DECODE_BIT;
77 DECODE_PAUSE (*bs)
78 return (val);
79}
80
81
82void
83BIO_Random_Unary_Encode (unsigned long val, random_bitio_state * bs,
84 unsigned long *bits)
85{
86 ENCODE_CONTINUE (*bs)
87 if (bits)
88 UNARY_ENCODE_L (val, *bits);
89 else
90 UNARY_ENCODE (val);
91 ENCODE_PAUSE (*bs)
92}
93
94
95unsigned long
96BIO_Random_Unary_Decode (random_bitio_state * bs,
97 unsigned long *bits)
98{
99 register unsigned long val;
100 DECODE_CONTINUE (*bs)
101 if (bits)
102 UNARY_DECODE_L (val, *bits);
103 else
104 UNARY_DECODE (val);
105 DECODE_PAUSE (*bs)
106 return (val);
107}
108
109
110
111
112
113
114
115void
116BIO_Random_Binary_Encode (unsigned long val, unsigned long b,
117 random_bitio_state * bs, unsigned long *bits)
118{
119 ENCODE_CONTINUE (*bs)
120 if (bits)
121 BINARY_ENCODE_L (val, b, *bits);
122 else
123 BINARY_ENCODE (val, b);
124 ENCODE_PAUSE (*bs)
125}
126
127
128unsigned long
129BIO_Random_Binary_Decode (unsigned long b,
130 random_bitio_state * bs,
131 unsigned long *bits)
132{
133 register unsigned long val;
134 DECODE_CONTINUE (*bs)
135 if (bits)
136 BINARY_DECODE_L (val, b, *bits);
137 else
138 BINARY_DECODE (val, b);
139 DECODE_PAUSE (*bs)
140 return (val);
141}
142
143
144
145
146
147
148
149void
150BIO_Random_Gamma_Encode (unsigned long val, random_bitio_state * bs,
151 unsigned long *bits)
152{
153 ENCODE_CONTINUE (*bs)
154 if (bits)
155 GAMMA_ENCODE_L (val, *bits);
156 else
157 GAMMA_ENCODE (val);
158 ENCODE_PAUSE (*bs)
159}
160
161
162unsigned long
163BIO_Random_Gamma_Decode (random_bitio_state * bs,
164 unsigned long *bits)
165{
166 register unsigned long val;
167 DECODE_CONTINUE (*bs)
168 if (bits)
169 GAMMA_DECODE_L (val, *bits);
170 else
171 GAMMA_DECODE (val);
172 DECODE_PAUSE (*bs)
173 return (val);
174}
175
176
177
178
179void
180BIO_Random_Delta_Encode (unsigned long val, random_bitio_state * bs,
181 unsigned long *bits)
182{
183 ENCODE_CONTINUE (*bs)
184 if (bits)
185 DELTA_ENCODE_L (val, *bits);
186 else
187 DELTA_ENCODE (val);
188 ENCODE_PAUSE (*bs)
189}
190
191
192unsigned long
193BIO_Random_Delta_Decode (random_bitio_state * bs,
194 unsigned long *bits)
195{
196 register unsigned long val;
197 DECODE_CONTINUE (*bs)
198 if (bits)
199 DELTA_DECODE_L (val, *bits);
200 else
201 DELTA_DECODE (val);
202 DECODE_PAUSE (*bs)
203 return (val);
204}
205
206void
207BIO_Random_Elias_Encode (unsigned long val, unsigned long b, double s,
208 random_bitio_state * bs, unsigned long *bits)
209{
210 ENCODE_CONTINUE (*bs)
211 if (bits)
212 ELIAS_ENCODE_L (val, b, s, *bits);
213 else
214 ELIAS_ENCODE (val, b, s);
215 ENCODE_PAUSE (*bs)
216}
217
218
219unsigned long
220BIO_Random_Elias_Decode (unsigned long b, double s,
221 random_bitio_state * bs,
222 unsigned long *bits)
223{
224 register unsigned long val;
225 DECODE_CONTINUE (*bs)
226 if (bits)
227 ELIAS_DECODE_L (val, b, s, *bits);
228 else
229 ELIAS_DECODE (val, b, s);
230 DECODE_PAUSE (*bs)
231 return (val);
232}
233
234void
235BIO_Random_Bblock_Encode (unsigned long val, unsigned long b,
236 random_bitio_state * bs, unsigned long *bits)
237{
238 ENCODE_CONTINUE (*bs)
239 if (bits)
240 BBLOCK_ENCODE_L (val, b, *bits);
241 else
242 BBLOCK_ENCODE (val, b);
243 ENCODE_PAUSE (*bs)
244}
245
246
247unsigned long
248BIO_Random_Bblock_Decode (unsigned long b,
249 random_bitio_state * bs,
250 unsigned long *bits)
251{
252 register unsigned long val;
253 DECODE_CONTINUE (*bs)
254 if (bits)
255 BBLOCK_DECODE_L (val, b, *bits);
256 else
257 BBLOCK_DECODE (val, b);
258 DECODE_PAUSE (*bs)
259 return (val);
260}
261
262void
263BIO_Random_Seek (unsigned long pos, random_bitio_state * bs)
264{
265 ENCODE_CONTINUE (*bs)
266 ENCODE_SEEK (pos);
267 ENCODE_PAUSE (*bs)
268}
269void
270BIO_Random_Flush (random_bitio_state * bs)
271{
272 ENCODE_CONTINUE (*bs)
273 ENCODE_FLUSH;
274 ENCODE_PAUSE (*bs)
275}
276
277unsigned long
278BIO_Random_Tell (random_bitio_state * bs)
279{
280 register unsigned long t;
281 ENCODE_CONTINUE (*bs)
282 t = ENCODE_TELL;
283 ENCODE_PAUSE (*bs)
284 return (t);
285}
Note: See TracBrowser for help on using the repository browser.