1 /*  ncbibs.h
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *               National Center for Biotechnology Information
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government have not placed any restriction on its use or reproduction.
13 *
14 *  Although all reasonable efforts have been taken to ensure the accuracy
15 *  and reliability of the software and data, the NLM and the U.S.
16 *  Government do not and cannot warrant the performance or results that
17 *  may be obtained by using this software or data. The NLM and the U.S.
18 *  Government disclaim all warranties, express or implied, including
19 *  warranties of performance, merchantability or fitness for any particular
20 *  purpose.
21 *
22 *  Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name:  ncbibs.h
27 *
28 * Author:  Jim Ostell
29 *
30 * Version Creation Date:  1/1/91
31 *
32 * $Revision: 6.5 $
33 *
34 * File Description:
35 *   ByteStore typedefs, prototypes, and defines
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * Date     Name        Description of modification
40 * -------  ----------  -----------------------------------------------------
41 *
42 * ==========================================================================
43 */
44 
45 #ifndef _NCBIBS_
46 #define _NCBIBS_
47 
48 #undef NLM_EXTERN
49 #ifdef NLM_IMPORT
50 #define NLM_EXTERN NLM_IMPORT
51 #else
52 #define NLM_EXTERN extern
53 #endif
54 
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 typedef struct bsunit {             /* for building multiline strings */
61 	Nlm_Handle str;            /* the string piece */
62 	Nlm_Int2 len_avail,
63 		 len;
64 	struct bsunit PNTR next; }       /* the next one */
65 Nlm_BSUnit, PNTR Nlm_BSUnitPtr;
66 
67 typedef struct bytestore {
68 	Nlm_Int4 seekptr,       /* current position */
69 		totlen,             /* total stored data length in bytes */
70 		chain_offset;       /* offset in ByteStore of first byte in curchain */
71 	Nlm_BSUnitPtr chain,       /* chain of elements */
72 		curchain;           /* the BSUnit containing seekptr */
73 } Nlm_ByteStore, PNTR Nlm_ByteStorePtr;
74 
75 NLM_EXTERN Nlm_VoidPtr LIBCALL Nlm_BSMerge PROTO((Nlm_ByteStorePtr ssp, Nlm_VoidPtr dest));
76 NLM_EXTERN Nlm_ByteStorePtr LIBCALL Nlm_BSNew PROTO((Nlm_Int4 len));
77 NLM_EXTERN Nlm_Int2 LIBCALL Nlm_BSSeek PROTO((Nlm_ByteStorePtr bsp, Nlm_Int4 offset, Nlm_Int2 origin));
78 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSTell PROTO((Nlm_ByteStorePtr bsp));
79 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSDelete PROTO((Nlm_ByteStorePtr bsp, Nlm_Int4 len));
80 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSWrite PROTO((Nlm_ByteStorePtr bsp, Nlm_VoidPtr ptr, Nlm_Int4 len));
81 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSInsert PROTO((Nlm_ByteStorePtr bsp, Nlm_VoidPtr ptr, Nlm_Int4 len));
82 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSInsertFromBS PROTO((Nlm_ByteStorePtr bsp, Nlm_ByteStorePtr bsp2, Nlm_Int4 len));
83 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSRead PROTO((Nlm_ByteStorePtr bsp, Nlm_VoidPtr ptr, Nlm_Int4 len));
84 NLM_EXTERN Nlm_Int2 LIBCALL Nlm_BSGetByte PROTO((Nlm_ByteStorePtr bsp));
85 NLM_EXTERN Nlm_Int2 LIBCALL Nlm_BSPutByte PROTO((Nlm_ByteStorePtr bsp, Nlm_Int2 value));
86 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSLen PROTO((Nlm_ByteStorePtr ssp));
87 NLM_EXTERN Nlm_ByteStorePtr LIBCALL Nlm_BSFree PROTO((Nlm_ByteStorePtr ssp));
88 NLM_EXTERN Nlm_ByteStorePtr LIBCALL Nlm_BSDup PROTO((Nlm_ByteStorePtr source));
89 NLM_EXTERN Nlm_Boolean LIBCALL Nlm_BSEqual PROTO((Nlm_ByteStorePtr bs1, Nlm_ByteStorePtr bs2));
90 /*****************************************************************************
91 *
92 *   Int4 BSAdd(bsp, len, use_min_size)
93 *   	adds len bytes BEFORE current bsp->seekptr
94 *       bsp->seekptr returned pointing at first added byte
95 *   	returns bytes added
96 *       if (use_min_size) then does not add anything smaller than MIN_BSALLOC
97 *
98 *       BSAdd does not change the length of the byte store.  When inserting in
99 *       the middle of the chain, it is up to the calling function to adjust the
100 *       length after writing the bytes.
101 *
102 *****************************************************************************/
103 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSAdd PROTO((Nlm_ByteStorePtr bsp, Nlm_Int4 len, Nlm_Boolean use_min_size));
104 
105 /****************************************************************************
106 *
107 *   Integer storage utilities
108 *      These assume integers are store in BIG_ENDIAN order in the ByteStore
109 *      They read and write Uint2 or Uint4 in the NATIVE endian order
110 *      All work with UNSIGNED 2 or 4 byte integers
111 *         (you should cast to make them signed)
112 *      These are just helper functions. They do no internal consistency
113 *         checking.
114 *      They are primarily to facilitate encoding SEQUENCE OF INTEGER as
115 *         OCTET STRING for ASN.1
116 *
117 ****************************************************************************/
118 
119 NLM_EXTERN Nlm_Uint2 LIBCALL Nlm_BSGetUint2 (Nlm_ByteStorePtr bsp);
120 NLM_EXTERN Nlm_Uint4 LIBCALL Nlm_BSGetUint4 (Nlm_ByteStorePtr bsp);
121 NLM_EXTERN Nlm_Int2 LIBCALL Nlm_BSPutUint2 (Nlm_ByteStorePtr bsp, Nlm_Uint2 value);
122 NLM_EXTERN Nlm_Int2 LIBCALL Nlm_BSPutUint4 (Nlm_ByteStorePtr bsp, Nlm_Uint4 value);
123 
124        /* In functions below, size is 2 or 4
125           Integers are converted from ByteStore to native endian (BSUintXRead)
126 	        or from native endian to ByteStore (BSUintXWrite)
127 	      len is number of INTEGERS, not number of bytes
128 	      returns count of integers put in ptr
129 	      WARNING: On LITTLE_ENDIAN machines the data in ptr is changed to BIG_ENDIAN in the
130 	        XXWrite functions and LEFT THAT WAY
131 	   */
132 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSUint4Read (Nlm_ByteStorePtr bsp, Nlm_Uint4Ptr ptr, Nlm_Int4 len);
133 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSUint4Write (Nlm_ByteStorePtr bsp, Nlm_Uint4Ptr ptr, Nlm_Int4 len);
134 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSUint2Read (Nlm_ByteStorePtr bsp, Nlm_Uint2Ptr ptr, Nlm_Int4 len);
135 NLM_EXTERN Nlm_Int4 LIBCALL Nlm_BSUint2Write (Nlm_ByteStorePtr bsp, Nlm_Uint2Ptr ptr, Nlm_Int4 len);
136 
137 /* for copying and swapping of UID lists passed over network to BIG_ENDIAN server */
138 
139 NLM_EXTERN Nlm_ByteStorePtr LIBCALL Nlm_BSDupAndSwapUint4 (Nlm_ByteStorePtr source);
140 
141 
142 #define ByteStore Nlm_ByteStore
143 #define ByteStorePtr Nlm_ByteStorePtr
144 #define BSMerge Nlm_BSMerge
145 #define BSNew Nlm_BSNew
146 #define BSLen Nlm_BSLen
147 #define BSFree Nlm_BSFree
148 #define BSSeek Nlm_BSSeek
149 #define BSTell Nlm_BSTell
150 #define BSDelete Nlm_BSDelete
151 #define BSWrite Nlm_BSWrite
152 #define BSInsert Nlm_BSInsert
153 #define BSInsertFromBS Nlm_BSInsertFromBS
154 #define BSDup Nlm_BSDup
155 #define BSEqual Nlm_BSEqual
156 #define BSRead Nlm_BSRead
157 #define BSGetByte Nlm_BSGetByte
158 #define BSPutByte Nlm_BSPutByte
159 #define BSDupAndSwapUint4 Nlm_BSDupAndSwapUint4
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 
166 #undef NLM_EXTERN
167 #ifdef NLM_EXPORT
168 #define NLM_EXTERN NLM_EXPORT
169 #else
170 #define NLM_EXTERN
171 #endif
172 
173 #endif
174 
175