2 * block - fixed, dynamic, fifo and circular memory blocks
4 * Copyright (C) 1999-2007 Landon Curt Noll and Ernest Bowen
6 * Primary author: Landon Curt Noll
8 * Calc is open software; you can redistribute it and/or modify it under
9 * the terms of the version 2.1 of the GNU Lesser General Public License
10 * as published by the Free Software Foundation.
12 * Calc is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 * Public License for more details.
17 * A copy of version 2.1 of the GNU Lesser General Public License is
18 * distributed with calc under the filename COPYING-LGPL. You should have
19 * received a copy with calc; if not, write to Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * @(#) $Revision: 30.1 $
23 * @(#) $Id: block.h,v 30.1 2007/03/16 11:09:46 chongo Exp $
24 * @(#) $Source: /usr/local/src/bin/calc/RCS/block.h,v $
26 * Under source code control: 1997/02/21 05:03:39
27 * File existed as early as: 1997
29 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
30 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
34 #if !defined(__BLOCK_H__)
39 * block - the basic block structure
41 * A block comes is one of several types. At the moment, only fixed
46 * Block functions and operations:
51 * blk(len [, blkchunk])
54 * blkchunk defaults to BLK_CHUNKSIZE
56 * blk(name, [len [, blkchunk]])
59 * blkchunk defaults to BLK_CHUNKSIZE
62 * Reduce storage down to 0 octetes.
65 * The length of data stored in the block.
67 * sizeof(x) == blk->maxsize
68 * Allocation size in memory
71 * returns 0 is x is not a BLOCK, 1 if x is an
72 * unnamed block, 2 if x is a named BLOCK
74 * blkread(x, size, count, fd [, offset])
75 * blkwrite(x, size, count, fd [, offset])
76 * returns number of items written
77 * offset is restricted in value by block type
79 * blkset(x, val, length [, offset])
80 * only the lower octet of val is used
81 * offset is restricted in value by block type
83 * blkchr(x, val, length [, offset])
84 * only the lower octet of val is used
85 * offset is restricted in value by block type
87 * blkcpy(dest, src, length [, dest_offset [, src_offset]])
88 * 0 <= length <= blksize(x)
89 * offset's are restricted in value by block type
92 * blkmove(dest, src, length [, dest_offset [, src_offset]])
93 * 0 <= length <= blksize(x)
94 * offset's are restricted in value by block type
95 * overlapping moves are handeled correctly
97 * blkccpy(dest, src, stopval, length [, dest_offset [, src_offset]])
98 * 0 <= length <= blksize(x)
99 * offset's are restricted in value by block type
101 * blkcmp(dest, src, length [, dest_offset [, src_offset]])
102 * 0 <= length <= blksize(x)
103 * offset's are restricted in value by block type
106 * swaps groups of 'a' octets within each 'b' octets
108 * b = a*k for some integer k >= 1
110 * scatter(src, dest1, dest2 [, dest3 ] ...)
111 * copy sucessive octets from src into dest1, dest2, ...
112 * restarting with dest1 after end of list
113 * stops at end of src
115 * gather(dest, src1, src2 [, src3 ] ...)
116 * copy first octet from src1, src2, ...
117 * copy next octet from src1, src2, ...
119 * copy last octet from src1, src2, ...
120 * copy 0 when there is no more data from a given source
122 * blkseek(x, offset, {"in","out"})
123 * some seeks may not be allowed by block type
125 * config("blkmaxprint", count)
126 * number of octets of a block to print, 0 means all
128 * config("blkverbose", boolean)
129 * TRUE => print all lines, FALSE => skip dup lines
131 * config("blkbase", "base")
132 * output block base = { "hex", "octal", "char", "binary", "raw" }
133 * binary is base 2, raw is just octet values
135 * config("blkfmt", "style")
136 * style of output = {
137 * "line", lines in blkbase with no spaces between octets
138 * "string", as one long line with no spaces between octets
139 * "od_style", position, spaces between octets
140 * "hd_style"} position, spaces between octets, chars on end
143 LEN blkchunk
; /* allocation chunk size */
144 LEN maxsize
; /* octets actually malloced for this block */
145 LEN datalen
; /* octets of data held this block */
146 USB8
*data
; /* pointer to the 1st octet of the allocated data */
148 typedef struct block BLOCK
;
157 typedef struct nblock NBLOCK
;
163 EXTERN
int blk_debug
; /* 0 => debug off */
169 #define BLK_CHUNKSIZE 256 /* default allocation chunk size for blocks */
171 #define BLK_DEF_MAXPRINT 256 /* default octets to print */
173 #define BLK_BASE_HEX 0 /* output octets in a block in hex */
174 #define BLK_BASE_OCT 1 /* output octets in a block in octal */
175 #define BLK_BASE_CHAR 2 /* output octets in a block in characters */
176 #define BLK_BASE_BINARY 3 /* output octets in a block in base 2 chars */
177 #define BLK_BASE_RAW 4 /* output octets in a block in raw binary */
179 #define BLK_FMT_HD_STYLE 0 /* output in base with chars on end of line */
180 #define BLK_FMT_LINE 1 /* output is lines of up to 79 chars */
181 #define BLK_FMT_STRING 2 /* output is one long string */
182 #define BLK_FMT_OD_STYLE 3 /* output in base with chars */
188 /* length of data stored in a block */
189 #define blklen(blk) ((blk)->datalen)
191 /* block footpint in memory */
192 #define blksizeof(blk) ((blk)->maxsize)
194 /* block allocation chunk size */
195 #define blkchunk(blk) ((blk)->blkchunk)
199 * OCTET - what the INDEXADDR produces from a blk[offset]
207 E_FUNC BLOCK
*blkalloc(int, int);
208 E_FUNC
void blk_free(BLOCK
*);
209 E_FUNC BLOCK
*blkrealloc(BLOCK
*, int, int);
210 E_FUNC
void blktrunc(BLOCK
*);
211 E_FUNC BLOCK
*blk_copy(BLOCK
*);
212 E_FUNC
int blk_cmp(BLOCK
*, BLOCK
*);
213 E_FUNC
void blk_print(BLOCK
*);
214 E_FUNC
void nblock_print(NBLOCK
*);
215 E_FUNC NBLOCK
*createnblock(char *, int, int);
216 E_FUNC NBLOCK
*reallocnblock(int, int, int);
217 E_FUNC
int removenblock(int);
218 E_FUNC
int findnblockid(char *);
219 E_FUNC NBLOCK
*findnblock(int);
220 E_FUNC BLOCK
*copyrealloc(BLOCK
*, int, int);
221 E_FUNC
int countnblocks(void);
222 E_FUNC
void shownblocks(void);
225 #endif /* !__BLOCK_H__ */