source: main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/lib/bitio_m_mems.h@ 23508

Last change on this file since 23508 was 23508, checked in by sjm84, 13 years ago

Committing 64 bit changes into the branch

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