00001 /* 00002 openisis - an open implementation of the CDS/ISIS database 00003 Version 0.8.x (patchlevel see file Version) 00004 Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 see README for more information 00021 EOH */ 00022 #ifndef LSTR_H 00023 00024 /* 00025 $Id: lstr.h,v 1.15 2003/04/08 00:20:53 kripke Exp $ 00026 definition of ISIS internal structures for openisis lib implementation. 00027 00028 This header defines the common internal data structures and their members 00029 and external structure and member definition types. 00030 A internal data structure is the common in-memory representation of 00031 ISIS data; it may be backed by different external (in-file) structures. 00032 00033 An in-memory data structure 00034 is a contigous int* chunk of memory, consisting of the sizes (one int), 00035 an array of members (int) and some buffer (array of char). 00036 00037 A data structures sizes consists of the lengths 00038 fix and rep of the fixed and repeated part, resp., 00039 and the number of occurences of the repeated part. 00040 It is used in both an abstract description of a data type 00041 and each instance of a data structure. 00042 If the number of occurences of the repeated part is not fixed, 00043 it is 0 in the abstract case. 00044 The lengths are suitable as offsets into the lmbr array. 00045 This structure is designed to fit within 32 bits. 00046 00047 The sizing is the only common meta-data description of a logical 00048 data type. For readability of code, however, the member indexes 00049 are enum-erated. When actually used, the type has to match the code's 00050 assumptions anyway. 00051 The numbers fix and rep are fixed for a given data structure. 00052 00053 Although the logical data type has more properties, 00054 especially the type of each member (numeric, C-string or raw mem), 00055 a representation of this data is needed only when converting 00056 external data and thus is stored (somewhat redundantly) 00057 with the external properties. 00058 00059 There are only two types of members: 00060 numeric and memory (mostly some character data). 00061 both are represented by a int, which, for memory, 00062 denotes an offset (counted in BYTES, not ints) from the records start 00063 (NOT offset into the data buffer, as with the isis mst record). 00064 00065 The member array consists of a fixed number <emp>fix</emp> of initial 00066 members and a number <emp>occ</emp> of occurences 00067 of member arrays of fixed length <emp>rep</emp>. 00068 While <emp>occ</emp> is usually fixed, 00069 it varies for masterfile records. 00070 00071 Note that this layout somewhat resembles the isis record itself, 00072 which supports a single level of nesting and repetition. 00073 */ 00074 00075 /* id of a structure */ 00076 00077 /* construction 00078 */ 00079 #define LSTRID( set, no, vari ) \ 00080 (((int)(vari))<<16 | (set)<<8 | (no) ) 00081 00082 /* access 00083 */ 00084 #define LSTRNO( l ) (char)(l) /* no of record type in set */ 00085 #define LSTRSET( l ) (char)((l)>>8) /* record set number */ 00086 #define LSTRVAR( l ) (short)((l)>>16) /* variant */ 00087 00088 00089 /* size of a structure */ 00090 00091 /* construction 00092 */ 00093 #define LSTRSIZE( fix, rep, occ ) \ 00094 (((int)(occ))<<16 | (rep)<<8 | (fix)) 00095 00096 /* access 00097 */ 00098 #define LSTRFIX( l ) (char)(l) /* length of fixed part */ 00099 #define LSTRREP( l ) (char)((l)>>8) /* length of repeated part */ 00100 #define LSTROCC( l ) (short)((l)>>16) /* the members */ 00101 /* actual number of members */ 00102 #define LSTRMEMS( l ) (LSTRFIX(l) + LSTRREP(l)*LSTROCC(l)) 00103 /* in-memory size of members (w/o buffer). */ 00104 #define LSTRLEN( t ) ((int)sizeof(int)*(1 + LSTRMEMS(t))) 00105 00106 00132 #define LONG2LEN( l ) ((short)(l)) 00133 #define LONG2OFF( l ) ((short)((l) >> 16)) 00134 00135 /* constants 00136 */ 00137 #define LMBR_FNUM 0x8000 /* flag numeric data */ 00138 #define LMBR_FHIE 0x4000 /* flag high endian data */ 00139 00140 /* construction 00141 */ 00142 #define LMBRNUM( ld ) (LMBR_FNUM | ld) 00143 /* standard nueric types: the world according to Java :) */ 00144 #define LMBRBYTE LMBRNUM(0) 00145 #define LMBRSHORT LMBRNUM(1) 00146 #define LMBRINT LMBRNUM(2) 00147 #define LMBRLONG LMBRNUM(3) 00148 /* bit mask construction for numerical data */ 00149 #define LMBRBITS( off, len, ld ) (LMBR_FNUM | (off)<<8 | (len)<<2 | (ld)) 00150 #define LMBRBITS4( off, len ) (LMBR_FNUM | (off)<<8 | (len)<<2 | 2) 00151 /* if you have to specify the offset explicitly */ 00152 #define LSTRLOFF( len, off ) ((len) | (off)<<16) 00153 00154 /* access 00155 */ 00156 #define LMBRISNUM( f ) (LMBR_FNUM & (f)) 00157 #define LMBRLD( f ) (0x3 & (f)) 00158 /* bit access for numerical data */ 00159 #define LMBRISBITS( f ) (0x3ffc & (f)) 00160 #define LMBRBITLEN( f ) (0x003f & ((f) >> 2)) 00161 #define LMBRBITOFF( f ) (0x003f & ((f) >> 8)) 00162 00170 enum { 00171 LSTR_SIZE, /* sizes */ 00172 LSTR_XRLO, /* repeated part byte length and offset <<16; auto */ 00173 LSTR_XLEN, /* ext. total length of data; auto */ 00174 LSTR_ILEN, /* int. total length of data; auto */ 00175 LSTR_XMBR /* members */ 00176 }; 00177 #define LSTR_AUTOLENGTHS 0,0,0 00178 #define LSTR_LONGS( totmbrs ) (4+(totmbrs)) 00179 00180 /* technical variants of a record */ 00181 typedef enum { 00182 LVAR_PAC, /* packed little endian base variant */ 00183 LVAR_ALI, /* aligned variant */ 00184 LVAR_BIG, /* big endian aligned */ 00185 LVAR_VARI 00186 } lstr_variant; 00187 00188 /* known record sets */ 00189 enum { 00190 LSET_MST, /* isis 1 master file */ 00191 LSET_INV, /* isis 1 inverted file */ 00192 LSET_SETS 00193 }; 00194 00195 00196 typedef struct { 00197 const char ***name; /* an array of names per record type */ 00198 int **desc[LVAR_VARI]; /* an array of descs per variant */ 00199 } LstrSet; 00200 00201 00202 /* data types of ISIS 1 master file */ 00203 typedef enum { 00204 LSTR_MFC, /* MST head */ 00205 LSTR_MFR, /* MST record */ 00206 LSTR_XRF, /* XRF record */ 00207 LSTR_MST /* count */ 00208 } lstr_mst; 00209 00210 00211 enum { /* MFC members */ 00212 LMFC_CTLM = 1, 00213 LMFC_NMFN, /* next available MFN */ 00214 LMFC_NMFB, /* next free block in MF counting from 1 */ 00215 LMFC_NMFP, /* next free pos in MF */ 00216 LMFC_TYPE, /* "0 for user's bases; 1 for messages" */ 00217 LMFC_RCNT, /* record count ? not used by CISIS */ 00218 LMFC_MFX1, 00219 LMFC_MFX2, /* LAN lock */ 00220 LMFC_MFX3, /* LAN lock */ 00221 LMFC__FL 00222 }; 00223 00224 enum { /* XRF members */ 00225 LXRF_XPOS = 1, 00226 LXRF_XREC 00227 }; 00228 00229 /* data types of ISIS 1 inverted file */ 00230 typedef enum { 00231 LSTR_CNT, /* CNT record */ 00232 LSTR_N01, /* N01 record */ 00233 LSTR_L01, /* L01 record */ 00234 LSTR_N02, /* N02 record */ 00235 LSTR_L02, /* L02 record */ 00236 LSTR_IFP, /* IFP record */ 00237 LSTR_INV /* count */ 00238 } lstr_inv; 00239 00240 00241 enum { /* CNT members */ 00242 LCNT_TYPE = 1, /* 1 or 2: N0x */ 00243 LCNT_ORDN, /* fix 5 */ 00244 LCNT_ORDF, /* fix 5 */ 00245 LCNT_N, /* fix 15 */ 00246 LCNT_K, /* fix 5 */ 00247 LCNT_LEV, /* depth of index */ 00248 LCNT_POSR, /* position of root */ 00249 LCNT_NMAX, 00250 LCNT_FMAX, 00251 LCNT_ABNO, 00252 LCNT__FL 00253 }; 00254 00255 enum { /* N0x members */ 00256 LN0X_POS = 1, /* record number */ 00257 LN0X_OCK, /* number of keys */ 00258 LN0X_TYPE, /* type 1 or 2 */ 00259 LN0X__FL, /* offset of repeated part */ 00260 LN0X_KEY = 0, /* key chars */ 00261 LN0X_REF, /* ref to next node (>0) or leaf (<0) */ 00262 LN0X__RL /* length of repeated part */ 00263 }; 00264 00265 enum { /* L0x members */ 00266 LL0X_POS = 1, /* record number */ 00267 LL0X_OCK, /* number of keys */ 00268 LL0X_TYPE, /* type 1 or 2 */ 00269 LL0X_PS, /* type 1 or 2 */ 00270 LL0X__FL, /* offset of repeated part */ 00271 LL0X_KEY = 0, /* key chars */ 00272 LL0X_INFB, /* ifp block */ 00273 LL0X_INFP, /* ifp pos */ 00274 LL0X__RL /* length of repeated part */ 00275 }; 00276 00277 enum { /* IFP members */ 00278 LIFP_NXTB = 1, /* block of next segment */ 00279 LIFP_NXTP, /* pos of next segment */ 00280 LIFP_TOTP, /* total postings */ 00281 LIFP_SEGP, /* postings in this segment */ 00282 LIFP_SEGC, /* postings in this segment */ 00283 LIFP__FL, /* offset of repeated part */ 00284 LIFP_MFN = 0, /* mfn */ 00285 LIFP_ADD, /* additional qualifyers */ 00286 LIFP__RL /* length of repeated part */ 00287 }; 00288 00289 00290 extern const LstrSet lstrlib[LSET_SETS]; 00291 00294 extern int lstr_auto ( int *str ); 00295 00296 #define LSTR_H 00297 #endif /* LSTR_H */