My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ricecomp.h
1 /* @(#) buffer.h 1.1 98/07/21 12:34:27 */
2 /* buffer.h: structure for compression to buffer rather than to a file, including
3  * bit I/O buffer
4  *
5  * R. White, 19 June 1998
6  */
7 
8 
9 typedef unsigned char Buffer_t;
10 
11 typedef struct {
12  int bitbuffer; /* bit buffer */
13  int bits_to_go; /* bits to go in buffer */
14  Buffer_t *start; /* start of buffer */
15  Buffer_t *current; /* current position in buffer */
16  Buffer_t *end; /* end of buffer */
17 } Buffer;
18 
19 #define buffree(mf) (free(mf->start), free(mf))
20 #define bufused(mf) (mf->current - mf->start)
21 #define bufreset(mf) (mf->current = mf->start)
22 
23 /*
24  * getcbuf, putcbuf macros for character IO to buffer
25  * putcbuf returns EOF on end of buffer, else returns 0
26  */
27 #define getcbuf(mf) ((mf->current >= mf->end) ? EOF : *(mf->current)++)
28 #define putcbuf(c,mf) \
29  ((mf->current >= mf->end) ? \
30  EOF :\
31  ((*(mf->current)++ = c), 0))
32 
33 /*
34  * bufalloc sets up buffer of length n
35  */
36 
37 /* not needed by CFITSIO
38 
39 static Buffer *bufalloc(int n)
40 {
41 Buffer *mf;
42 
43  mf = (Buffer *) malloc(sizeof(Buffer));
44  if (mf == (Buffer *)NULL) return((Buffer *)NULL);
45 
46  mf->start = (Buffer_t *) malloc(n*sizeof(Buffer_t));
47  if (mf->start == (Buffer_t *)NULL) {
48  free(mf);
49  return((Buffer *)NULL);
50  }
51  mf->bits_to_go = 8;
52  mf->end = mf->start + n;
53  mf->current = mf->start;
54  return(mf);
55 }
56 */
57 
58 /*
59  * bufrealloc extends buffer (or truncates it) by
60  * reallocating memory
61  */
62 
63 /* not needed by CFITSIO
64 static int bufrealloc(Buffer *mf, int n)
65 {
66 int len;
67 
68  len = mf->current - mf->start;
69 
70  * silently throw away data if buffer is already longer than n *
71  if (len>n) len = n;
72  if (len<0) len = 0;
73 
74  mf->start = (Buffer_t *) realloc(mf->start, n*sizeof(Buffer_t));
75  if (mf->start == (Buffer_t *)NULL) return(0);
76 
77  mf->end = mf->start + n;
78  mf->current = mf->start + len;
79  return(n);
80 }
81 */
82 
83 /*
84  * bufdump dumps contents of buffer to outfile and resets
85  * it to be empty. Returns number of bytes written.
86  *
87  * Note we don't write out the bit buffer -- you must call
88  * done_outputing_bits() first to ensure that the bit buffer
89  * is written out. I do it this way to allow incremental
90  * buffer dumps while bit IO is still going on.
91  */
92 
93 /* not needed by CFITSIO
94 
95 static int bufdump(FILE *outfile, Buffer *buffer)
96 {
97 int ndump;
98 
99  ndump = bufused(buffer);
100  if (fwrite(buffer->start, 1, ndump, outfile) != ndump) {
101  fprintf(stderr, "bufdump: error in write\n");
102  exit(1);
103  }
104  bufreset(buffer);
105  return(ndump);
106 }
107 */
Definition: ricecomp.h:11