-
Notifications
You must be signed in to change notification settings - Fork 1
/
hds1.h
271 lines (233 loc) · 10 KB
/
hds1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#if !defined( HDS1_INCLUDED ) /* hds1.h already included? */
#define HDS1_INCLUDED 1
/* C include files: */
/* =============== */
#include <limits.h>
#include <string.h>
#if HAVE_CONFIG_H /* configure definitions */
#include <config.h>
#endif
/* VMS include files: */
/* ================= */
#if defined( vms )
#include <descrip.h> /* Data descriptor definitions (VMS) */
#endif
/* Global HDS success status. */
/* ========================= */
#define DAT__OK 0
/* Description of file mapping implementation. */
/* ========================================== */
/* This will only need to be extended if new implementations of file */
/* mapping are added (which will normally require coding changes in the */
/* file access routines). The default for new machines is to assume no file */
/* mapping unless the _mmap macro is defined or the configure property */
/* HAVE_MMAP is true */
#if defined( vms ) /* VMS implementation */
#define HDS__CANMAP 1 /* File mapping supported? */
#define HDS__MAPSEQ 0 /* Mapping best for sequential access? */
#define HDS__MAPSPARSE 1 /* Mapping best for sparse access? */
#define HDS__MAPMEM 1 /* Mapping best to reduce memory usage? */
#elif defined( _mmap) || HAVE_MMAP
/* UNIX implementation using mmap: */
#define HDS__CANMAP 1 /* File mapping supported? */
#define HDS__MAPSEQ 1 /* Mapping best for sequential access? */
#define HDS__MAPSPARSE 1 /* Mapping best for sparse access? */
#define HDS__MAPMEM 1 /* Mapping best to reduce memory usage? */
#else /* Everything else: assume no file mapping */
#define HDS__CANMAP 0 /* File mapping supported? */
#define HDS__MAPSEQ 1 /* Mapping best for sequential access? */
#define HDS__MAPSPARSE 1 /* Mapping best for sparse access? */
#define HDS__MAPMEM 1 /* Mapping best to reduce memory usage? */
#endif
/* UNIX shells: */
/* =========== */
/* Note: these numbers correspond to documented tuning parameter values, so */
/* should not be changed. */
#define HDS__NOSHELL -1 /* Don't use a shell to expand file names */
#define HDS__SHSHELL 0 /* Use the "sh" shell */
#define HDS__CSHSHELL 1 /* Use the "csh" shell */
#define HDS__TCSHSHELL 2 /* Use the "tcsh" shell */
#define HDS__MXSHELL 2 /* Max. UNIX shell number supported */
/* Define default command names for activating each UNIX shell (may be */
/* over-ridden by external definitions appropriate to a particular system). */
#if !defined( _sh )
#define _sh "sh"
#endif
#if !defined( _csh )
#define _csh "csh"
#endif
#if !defined( _tcsh )
#define _tcsh "tcsh"
#endif
/* Forking function: */
/* ================ */
/* Use vfork for more efficient child process creation if supported, */
/* otherwise use the POSIX.1 fork function. */
#if defined( _vfork ) || HAVE_WORKING_VFORK
#define _fork vfork
#else
#define _fork fork
#endif
/* Memory Allocation Routines */
/* ===========================*/
/* Define macros here for to allow us to easily fallback to native free/malloc */
#include "star/mem.h"
#define MEM_MALLOC starMalloc
#define MEM_FREE starFree
#define MEM_REALLOC starRealloc
/* Defaults for tuning parameters: */
/* ============================== */
#define HDS__INALQ 2 /* Initial file allocation quantity */
#define HDS__MAP 1 /* Use file mapping if available? */
#define HDS__MAXWPL 32 /* Maximum size of the "working page list" */
#define HDS__NBLOCKS 32 /* Size of the internal "transfer buffer" */
#define HDS__NCOMP 6 /* Optimum number of structure components */
#define HDS__SHELL HDS__SHSHELL /* UNIX "sh" shell used for file expansion */
#define HDS__SYSLCK 0 /* System wide lock flag */
#define HDS__WAIT 0 /* Wait for locked files? */
#define HDS__64BIT 1 /* Create new files in 64-bit HDS format? */
/* Indicate that public include files should use a local search path */
#define HDS_INTERNAL_INCLUDES 1
/* Arithmetic data types: */
/* ===================== */
#include "hds1_types.h"
#include "hds_types.h"
/* Historically, internally we call the 32bit int an INT.
Should make this more namespaced but for now just typedef */
typedef hdsi32_t INT;
/* Historically the 64bit int type was called INT_BIG */
typedef hdsi64_t INT_BIG;
typedef hdsu64_t UINT_BIG;
#define INT_BIG_S HDS_INT_BIG_S
#define INT_BIG_U HDS_INT_BIG_U
/* Fortran index type is defined now in hds1_types.h */
/* Currently the internal interface uses HDS_PTYPE rather than hdsdim */
typedef hdsdim HDS_PTYPE;
#define HDS_PTYPE_FORMAT HDS_DIM_FORMAT
/* Global Structure Definitions: */
/* ============================ */
/* DSC - Fixed length character string descriptor. */
struct DSC
{
unsigned short int length; /* Object length */
unsigned char dtype; /* Object type */
unsigned char class; /* Object class */
unsigned char *body; /* Pointer to object */
};
/* Macros: */
/* ====== */
/* Minimum and maximum. */
#define _min( i, j ) ( ( i ) < ( j ) ? ( i ) : ( j ) )
#define _max( i, j ) ( ( i ) > ( j ) ? ( i ) : ( j ) )
/* Call procedure, exiting if get bad status. */
#define _invoke(proc)\
{\
proc;\
if (!_ok(hds_gl_status)) return hds_gl_status;\
}
/* Test whether status is OK. */
#define _ok(status)\
(status == DAT__OK)
/* Insert an entry at the head of a queue. (Here, a queue is a circular */
/* list of structures with forward and backward links given by components */
/* flink and blink.) The variable queue should initially contain a pointer */
/* to the element designated as the head-of-queue (or NULL if the queue is */
/* empty) it is updated to point at the new element. */
#define _insque( entry, queue )\
{\
if ( (queue) == NULL )\
{\
(entry)->flink = (entry);\
(entry)->blink = (entry);\
}\
else\
{\
(entry)->flink = (queue);\
(entry)->blink = (queue)->blink;\
((queue)->blink)->flink = (entry);\
(queue)->blink = (entry);\
}\
(queue) = (entry);\
}
/* Remove an entry from a queue. The variable queue should initially */
/* contain a pointer to the element designated as the head-of-queue - it */
/* will be updated if necessary, and will be set to NULL if the queue */
/* becomes empty. */
#define _remque( entry, queue )\
{\
if ( (entry)->flink == (entry) )\
{\
(queue) = NULL;\
}\
else\
{\
((entry)->blink)->flink = (entry)->flink;\
((entry)->flink)->blink = (entry)->blink;\
if ( (entry) == (queue) ) (queue) = (entry)->flink;\
}\
}
/* Move chars. */
#define _chmove( n, sptr, dptr )\
( (void) memcpy( (void *) ( dptr ), (const void *) ( sptr ),\
(size_t) ( n ) ) )
/* Move chars with fill. */
#define _chcopy( slen, sptr, fill, dlen, dptr )\
( memcpy( (void *) ( dptr ), (const void *) ( sptr ),\
( slen ) < ( dlen ) ? ( slen ) : ( dlen ) ),\
( slen ) < ( dlen ) ?\
memset( (void *) ( dptr + slen ), ( fill ),\
( dlen ) - ( slen ) ) : 0 )
/* Test char arrays for equality. */
#define _cheql( n, sptr, dptr )\
( !memcmp( (const void *) ( sptr ), (const void *) ( dptr ),\
(size_t) ( n ) ) )
/* Initialise a character string data descriptor. */
#if defined( vms )
#define _dscinit(_name,_length,_body)\
((_name)->length = _length,\
(_name)->dtype = DSC$K_DTYPE_T,\
(_name)->class = DSC$K_CLASS_S,\
(_name)->body = (void *)_body)
#else
#define _dscinit(_name,_length,_body)\
((_name)->length = _length,\
(_name)->dtype = 0,\
(_name)->class = 0,\
(_name)->body = (void *)_body)
#endif
/* Global Variables: */
/* ================ */
extern int hds_gl_active; /* HDS active? */
extern int hds_gl_ntemp; /* Counter for temporary names */
extern int hds_gl_status; /* Global status */
extern unsigned int hds_gl_locseq; /* Locator sequence number */
extern int hds_gl_64bit; /* V4 (64-bit) type records */
/* Global Tuning Variables: */
/* ======================= */
extern int hds_gl_inalq0; /* Default initial file allocation quantity*/
extern int hds_gl_inalq; /* Initial file allocation quantity */
extern int hds_gl_map; /* Use file mapping if available? */
extern int hds_gl_maxwpl; /* Maximum size of the "working page list" */
extern int hds_gl_nblocks; /* Size of the internal "transfer buffer" */
extern int hds_gl_ncomp0; /* Default optimum number of components */
extern int hds_gl_ncomp; /* Optimum number of structure components */
extern int hds_gl_shell; /* UNIX shell used for file name expansion */
extern int hds_gl_syslck; /* System-wide lock flag */
extern int hds_gl_wait; /* Wait for locked files? */
extern int hds_gl_c64bit; /* Create 64-bit (HDS V4) new files? */
extern int hds_gl_longints;/* Default all INTEGERs to 64-bits? */
/* EMS wrapper routines: */
/* ======================================= */
void dat1EmsSetBigi( const char * token, INT_BIG value );
void dat1EmsSetBigu( const char * token, UINT_BIG value );
void dat1EmsSetHdsdim( const char * token, hdsdim value );
/* Fixups for various machine deficiencies: */
/* ======================================= */
#if !HAVE_ATEXIT
int atexit( void (*fcn)( void ) );
#endif
#if !HAVE_MEMMOVE
void *memmove( void *, const void *, size_t );
#endif
/*. */
#endif