Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / tt / mini_isam / isam.h
1 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
2 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
3 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
4 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
5 /*%%  $XConsortium: isam.h /main/3 1995/10/23 11:33:51 rswiston $                                                        */
6 /*
7 @(#)isam.h
8 1.17 90/01/20
9 SMI */
10
11 /*
12  * Copyright (c) 1988 by Sun Microsystems, Inc.
13  */
14
15 /*
16  * isam.h
17  *
18  * Description:
19  *      isam.h is to be included in NetISAM C application programs.
20  *
21  * Make sure all changes in this file are reflected in lib/db/tt_client_isam.h 
22  */
23
24
25 #ifndef _ISAM_H
26 #define _ISAM_H
27
28 #include <limits.h>
29 #ifndef LONG_BIT
30 #define LONG_BIT 32
31 #endif
32
33 extern short ldint();
34 extern long ldlong();
35 extern float ldfloat();
36 extern double lddbl();
37 extern short ldshort();
38 extern ldchar(), stchar(), stlong(), stint(), stdbl(), stfloat();
39 extern stbin(), ldbin();
40
41 extern int      iserrno;                     /* isam error number code */
42 extern long     isrecnum;                    /* record number of last call */
43 extern int      isreclen;                    /* used for variable length recs */
44 extern char     isstat1;                     /* cobol status characters */
45 extern char     isstat2;
46
47 #define CHARTYPE        0
48 #define CHARSIZE        1
49
50 #define INTTYPE         1
51 #define INTSIZE         2
52
53 #define LONGTYPE        2
54 #define LONGSIZE        LONG_BIT/8
55
56 #define DOUBLETYPE      3
57 #define DOUBLESIZE      8
58
59 #define FLOATTYPE       4
60 #define FLOATSIZE       4
61
62 #define BINTYPE         5
63 #define BINSIZE         1
64
65 #define MINTYPE         0
66 #define MAXTYPE         6
67
68 #define ISDESC          0x80                 /* add to make descending type */
69 #define TYPEMASK        0x7f                 /* type mask */
70
71 #define BYTEMASK        0xff                 /* mask for one byte */
72 #define BYTESHFT        8                    /* shift for one byte */
73
74 /* mode parameter in isread() and isstart() */
75
76 #define ISFIRST         0                    /* first record */
77 #define ISLAST          1                    /* last record */
78 #define ISNEXT          2                    /* next record */
79 #define ISPREV          3                    /* previous record */
80 #define ISCURR          4                    /* current record */
81
82 #define ISEQUAL         5                    /* equal value */
83 #define ISGREAT         6                    /* greater value */
84 #define ISGTEQ          7                    /* >= value */
85 #define ISLESS          8                    /* < */
86 #define ISLTEQ          9                    /* <= */
87
88 /* isopen, isbuild lock modes */
89 #define ISAUTOLOCK      0x200                /* automatic record lock */
90 #define ISMANULOCK      0x400                /* manual record lock */
91 #define ISEXCLLOCK      0x800                /* exclusive isam file lock */
92 #define ISFASTLOCK      0x4000               /* no locking when EXCLLOCK! */
93
94 /* isread lock modes */
95 #define ISLOCK          0x100                /* lock record before reading */
96 #define ISSKIPLOCK      0x1000               /* advance record pointer to */
97                                              /* locked record */
98 /* isstart lock mode for automatic record locking */
99 #define ISKEEPLOCK      0x2000               /* keep record locked */
100
101 /* Fix/Variable length records mode */
102 #define ISFIXLEN        0
103 #define ISVARLEN        0x10000
104
105 /* Access remote file via NFS */
106 #define ISNFS           0x20000
107
108
109 #define ISINPUT         0                    /* open for input only */
110 #define ISOUTPUT        1                    /* open for output only */
111 #define ISINOUT         2                    /* open for input and output */
112
113 #define MAXKEYSIZE      150                  /* max number of bytes in key */
114 #define NPARTS          8                    /* max number of key parts */
115
116 /*#define ISMAXRECLEN   8192    */           /* Maximum number of bytes in record */
117 #define ISMAXRECLEN     32767                /* 32K - 1 */
118 #define ISMINRECLEN        4                 /* Minimum number of bytes in record */
119
120 struct keypart {
121     unsigned short      kp_start;            /* starting byte of key part */
122     short       kp_leng;                     /* length in bytes */
123     short       kp_type;                     /* type of key part */
124 };
125
126 struct keydesc {
127     short       k_flags;                     /* flags */
128     short       k_nparts;                    /* number of parts in key */
129     struct keypart k_part[NPARTS];           /* each part */
130 };
131
132 /* The next three defines are for compatibility with X/OPEN */
133 #define k_start         k_part[0].kp_start
134 #define k_leng          k_part[0].kp_leng
135 #define k_type          k_part[0].kp_type
136
137 #define ISNODUPS        000                  /* no duplicates and  */
138                                              /* no compression */
139 #define ISDUPS          001                  /* duplicates allowed */
140 #define COMPRESS        020                  /* full compression */
141
142 struct dictinfo {
143     short       di_nkeys;                    /* number of keys defined */
144  unsigned short di_recsize;                  /* data record size */
145     short       di_idxsize;                  /* index record size */
146     long        di_nrecords;                 /* number of records in file */
147 };
148
149 /* msb in di_nkeys indicates that ISAM file supports variable length records */
150 #define DICTVARLENBIT   0x8000
151
152 /* mask to access the true number of keys */
153 #define DICTNKEYSMASK      (DICTVARLENBIT - 1) 
154                                                
155
156 #define ENOERROR          0                  /* No error */
157 #define EDUPL           100                  /* duplicate record */
158 #define ENOTOPEN        101                  /* file not open */
159 #define EBADARG         102                  /* illegal argument */
160 #define EBADKEY         103                  /* illegal key desc */
161 #define ETOOMANY        104                  /* too many files open */
162 #define EBADFILE        105                  /* bad ISAM file format */
163 #define ENOTEXCL        106                  /* non-exclusive access */
164 #define ELOCKED         107                  /* record locked */
165 #define EKEXISTS        108                  /* key already exists */
166 #define EPRIMKEY        109                  /* is primary key */
167 #define EENDFILE        110                  /* end/begin of file */
168 #define ENOREC          111                  /* no record found */
169 #define ENOCURR         112                  /* no current record */
170 #define EFLOCKED        113                  /* file locked */
171 #define EFNAME          114                  /* file name too long */
172 #define EBADMEM         116                  /* cannot allocate memory */
173
174 /* NetISAM specific error codes  non XOPEN compliant*/
175 #define ETIMEOUT        1117                 /* RPC timeout */
176 #define ERPC            1118                 /* Broken TCP/IP */
177 #define ETCP            1119                 /* Cannot connect to server */
178 #define EIMPORT         1120                 /* Cannot import */
179 #define ENODAEMON       1121                  /* no local daemon */
180 #define EFATAL          1122                  /* internal fatal error */
181 #define ELANG           1123                  /* Locale/LANG mismatch */
182
183
184 #define ISOK            0                    /* no error return code */
185 #define ISERROR         -1                   /* error return code */
186
187
188 extern struct keydesc *nokey;                /* May be used as parameter
189                                               * to isbuild() if no
190                                               * primary key is to be built
191                                               */
192
193 /* ischeckindex() diagmode values */
194 #define CHK_NODIAG      0                    /* do not print any messages */
195 #define CHK_DIAG        1                    /* Access Level module will print to stderr */
196
197 /* values of corrupt parameter of ischeckindex() */
198 #define CHK_OK          0                    /* ISAM file is not corrupted */
199 #define CHK_DAT         1                    /* .dat file is corrupted */
200 #define CHK_VAR         2                    /* .var file is corrupted */
201 #define CHK_IND         3                    /* .ind file is corrupted */
202
203
204 /* iscntl() definitions */
205 /* For one isfd - use iscntl(isfd, func, ...) */
206 #define ISCNTL_RPCS_TO_SET   1               /* short oper. timeout (in sec) */
207 #define ISCNTL_RPCS_TO_GET   2               /* short oper. timeout (in sec) */
208 #define ISCNTL_RPCL_TO_SET   3               /* long oper. timeout (in sec) */
209 #define ISCNTL_RPCL_TO_GET   4               /* long oper. timeout (in sec) */
210 #define ISCNTL_TCP_TO_SET    5               /* timeout to reconnect TCP?IP */
211 #define ISCNTL_TCP_TO_GET    6               /* timeout to reconnect TCP?IP */
212 #define ISCNTL_APPLMAGIC_WRITE 7             /* Write Appl. Magic */
213 #define ISCNTL_APPLMAGIC_READ  8             /* Read Appl. Magic */
214 #define ISCNTL_FSYNC            9            /* Flush pages to disk */
215 #define ISCNTL_FDLIMIT_SET      10           /* Set UNIX fd usage limit */
216 #define ISCNTL_FDLIMIT_GET      11           /* Get UNIX fd usage limit */
217 #define ISCNTL_FATAL    12                   /* Specify NetISAM fatal error hadler */
218 #define ISCNTL_MASKSIGNALS      13           /* Enable or Disable masking signals during NetISAM operations */
219
220 #define ISAPPLMAGICLEN          32
221
222 /*
223  * ALLISFD in iscntl() calls means that the operation should be done 
224  * on all open file descriptors, or the operation is not related to 
225  * any file descriptor (e.g: maskintg signals)
226  */
227 #define ALLISFD         (-2)    
228
229 /* isshowlocks() and isshowhostlocks() return an array of struct showlock */
230 #define IPADDRLEN       4                    /* IP address length */
231 struct showlock {
232     short       dev;                         /* Major/Minor device number,
233                                               * actually type dev_t */
234     long        inode;                       /* inode number */
235     long        recnum;                      /* record number */
236     char        hostid[IPADDRLEN];           /* IP address of host */
237     short       pid;                         /* UNIX process ID */
238     long        uid;                         /* User ID */
239     short       type;                        /* See below */
240 };
241
242
243 /* NetISAM Programmer Toolkit related definitions */
244         
245 struct isfldmap {
246         char    *flm_fldname;
247         short   flm_recoff;
248         short   flm_bufoff;
249         short   flm_type;
250         short   flm_length;
251 };
252
253 struct istableinfo {
254         char    *tbi_tablename;
255         int     tbi_reclength;
256         int     tbi_nfields;
257         struct isfldmap *tbi_fields;
258         int     tbi_nkeys;
259         struct keydesc *tbi_keys;
260         char    **tbi_keynames;
261 };
262
263 /* record descriptor isreadm/iswritem record descriptor */
264 struct recorddesc {
265         char    *rec_buffer;
266         long    rec_number;
267         short   rec_length;
268         short   rec_locked;
269 };
270
271 /*
272  * The following defines and variable definitions are not used by NetISAM 1.0.
273  * They are defined for compatibility with VSX 2.5.
274  */
275 #define EBADCOLL        (-1)
276
277 #define IO_OPEN         0x10                 /* open() */
278 #define IO_CREA         0x20                 /* creat() */
279 #define IO_SEEK         0x30                 /* lseek() */
280 #define IO_READ         0x40                 /* read() */
281 #define IO_WRIT         0x50                 /* write() */
282 #define IO_LOCK         0x60                 /* lockf() */
283 #define IO_IOCTL        0x70                 /* ioctl() */
284 #define IO_RENAME       0x80                 /* rename() */
285 #define IO_UNLINK       0x90                 /* unlink() */
286
287 extern int iserrio;
288
289
290 #endif /* !_ISAM_H */