source: trunk/gsdl3/src/packages/mg/lib/bitio_m_mems.h@ 3745

Last change on this file since 3745 was 3745, checked in by mdewsnip, 21 years ago

Addition of MG package for search and retrieval

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1/**************************************************************************
2 *
3 * bitio_m_mems.h -- Macros for bitio to memory (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_m_mems.h 3745 2003-02-20 21:20:24Z mdewsnip $
21 *
22 **************************************************************************
23 *
24 * This file contains macros for doing bitwise input and output on an array
25 * of chars. These routines are slower than the ones in "mem" files. but
26 * with these routines you can mix reads and writes, or multiple writes, on
27 * the array of chars at the same time and guarantee them to work, also you
28 * can seek to a point and do a write. The decode and encode macros cannot
29 * detect when the end off the character is reached and just continue
30 * processing.
31 *
32 **************************************************************************/
33
34#ifndef H_BITIO_M_MEMS
35#define H_BITIO_M_MEMS
36
37typedef struct mems_bitio_state
38 {
39 unsigned char *Base;
40 unsigned long pos;
41 }
42mems_bitio_state;
43
44
45#define ENCODE_START(b,p) \
46 { \
47 register unsigned char *__base = b; \
48 register unsigned long __pos = p;
49
50#define ENCODE_CONTINUE(b) \
51 { \
52 register unsigned char *__base = (b).Base; \
53 register unsigned long __pos = (b).pos;
54
55#define ENCODE_BIT(b) \
56 do { \
57 if (b) \
58 __base[__pos>>3] |= 0x80 >> (__pos&7); \
59 else \
60 __base[__pos>>3] &= 0xff7f >> (__pos&7); \
61 __pos++; \
62 } while(0)
63
64#define ENCODE_PAUSE(b) \
65 (b).Base = __base; \
66 (b).pos = __pos; \
67 }
68
69#define ENCODE_FLUSH
70
71
72#define ENCODE_DONE \
73 ENCODE_FLUSH; \
74 }
75
76
77#define DECODE_START(b,p) \
78 { \
79 register unsigned char *__base = b; \
80 register unsigned long __pos = p;
81
82#define DECODE_CONTINUE(b) \
83 { \
84 register unsigned char *__base = (b).Base; \
85 register unsigned long __pos = (b).pos;
86
87#define DECODE_ADD_FF(b) \
88 do { \
89 (b) += (b) + (__base[__pos>>3] & (0x80 >> (__pos&7)) != 0); \
90 __pos++; \
91 } while(0)
92
93#define DECODE_ADD_00(b) DECODE_ADD_FF(b)
94
95#define DECODE_BIT \
96 (__pos++, ((__base[(__pos-1)>>3] & (0x80 >> ((__pos-1)&7))) != 0))
97
98#define DECODE_DONE ; \
99 }
100
101#define DECODE_PAUSE(b) \
102 (b).Base = __base; \
103 (b).pos = __pos; \
104 }
105
106#define DECODE_SEEK(pos) __pos = (pos)
107
108#define ENCODE_SEEK(pos) __pos = (pos)
109
110
111
112
113
114#endif
Note: See TracBrowser for help on using the repository browser.