1 |
|
#ifndef __GCDB_H |
2 |
|
#define __GCDB_H |
3 |
< |
#include <stdlib.h> |
3 |
> |
#include "GBase.h" |
4 |
|
#include <stddef.h> |
5 |
|
#include <fcntl.h> |
6 |
– |
#include <sys/stat.h> |
7 |
– |
#include "GBase.h" |
6 |
|
|
7 |
< |
#if defined(__WIN32__) || defined(WIN32) |
7 |
> |
#ifdef __WIN32__ |
8 |
|
#define PROT_READ 1 |
9 |
|
#define PROT_WRITE 2 |
10 |
|
#define PROT_READWRITE 3 |
15 |
|
#define W_OK 2 |
16 |
|
#define RW_OK 6 |
17 |
|
|
18 |
< |
#if !defined(MAP_FAILED) |
18 |
> |
#ifndef MAP_FAILED |
19 |
|
#define MAP_FAILED ((void *) -1) |
20 |
|
#endif |
21 |
|
void *mmap(char *,size_t,int,int,int,off_t); |
24 |
|
#include <sys/mman.h> |
25 |
|
#endif |
26 |
|
|
29 |
– |
#define MAX_UINT 0xFFFFFFFFUL |
30 |
– |
|
31 |
– |
|
27 |
|
//===================================================== |
28 |
|
//------------- buffer stuff ------------------- |
29 |
|
//===================================================== |
30 |
|
#define GCDBUFFER_INSIZE 8192 |
31 |
|
#define GCDBUFFER_OUTSIZE 8192 |
32 |
|
|
38 |
– |
|
33 |
|
typedef int (*opfunc)(int, char*, size_t); |
34 |
|
|
35 |
|
//typedef unsigned long gcdb_seek_pos; |
36 |
|
typedef off_t gcdb_seek_pos; |
37 |
< |
typedef unsigned int (*uint_conv)(void*); //uint conversion function pointer |
38 |
< |
typedef off_t (*offt_conv)(void*); //uint conversion function pointer |
37 |
> |
typedef unsigned int (*uint_conv_func)(void*); //uint conversion function pointer |
38 |
> |
typedef off_t (*offt_conv_func)(void*); //uint conversion function pointer |
39 |
> |
typedef int16_t (*int16_conv_func)(void*); //int16 conversion function pointer |
40 |
|
|
41 |
|
|
42 |
|
//conversion function --> to platform independent uint |
43 |
< |
extern uint_conv gcvt_uint; |
44 |
< |
extern offt_conv gcvt_offt; |
45 |
< |
|
46 |
< |
int endian_test(void); |
43 |
> |
extern uint_conv_func gcvt_uint; |
44 |
> |
extern offt_conv_func gcvt_offt; |
45 |
> |
extern int16_conv_func gcvt_int16; |
46 |
> |
/* |
47 |
|
unsigned int uint32_sun(void* x86int); |
48 |
|
unsigned int uint32_x86(void* x86int); |
49 |
|
//for file offsets: off_t runtime conversions: |
50 |
|
off_t offt_sun(void* offt); |
51 |
|
off_t offt_x86(void* offt); |
52 |
+ |
int16_t int16_sun(void* i16); |
53 |
+ |
int16_t int16_x86(void* i16); |
54 |
+ |
*/ |
55 |
|
|
56 |
+ |
void gcvt_endian_setup(); |
57 |
|
|
58 |
|
class GCDBuffer { |
59 |
|
public: |
68 |
|
fd=0; |
69 |
|
op=NULL; |
70 |
|
n=0; |
72 |
– |
//check endianness |
73 |
– |
gcvt_uint=(endian_test())? &uint32_sun : &uint32_x86; |
74 |
– |
gcvt_offt=(endian_test())? &offt_sun : &offt_x86; |
71 |
|
} |
72 |
|
GCDBuffer(opfunc aop,int afd,char *buf,unsigned int len) { |
73 |
|
//check endianness |
74 |
< |
gcvt_uint=(endian_test())? &uint32_sun : &uint32_x86; |
79 |
< |
gcvt_offt=(endian_test())? &offt_sun : &offt_x86; |
74 |
> |
gcvt_endian_setup(); |
75 |
|
init(aop, afd, buf, len); |
76 |
|
} |
77 |
|
void init(opfunc aop,int afd,char *buf,unsigned int len) { |
115 |
|
#define CDBMSK_OPT_C 0x00000002 |
116 |
|
#define CDBMSK_OPT_CADD 0x00000004 |
117 |
|
#define CDBMSK_OPT_COMPRESS 0x00000008 |
118 |
+ |
#define CDBMSK_OPT_GSEQ 0x00000010 |
119 |
|
//creates a compressed version of the database |
120 |
|
//uses plenty of unions for ensuring compatibility with |
121 |
|
// the old 'CIDX' info structure |
122 |
|
|
123 |
< |
//damn, sun and 64bit machines |
128 |
< |
// align this to 64bit -- so sizeof() is misled! |
123 |
> |
//trying to prevent [64bit] machines to align this to 64bit -- sizeof() gets it wrong! |
124 |
|
#pragma pack(4) |
125 |
< |
// I wish, but stupid gcc 2.95.3 alpha-decosf version does not |
126 |
< |
// recognize this pragma directive !!? |
127 |
< |
// |
125 |
> |
// eek, gcc 2.95.3 alpha-decosf version does not |
126 |
> |
// recognize this pragma directive |
127 |
> |
|
128 |
> |
|
129 |
|
struct cdbInfo { |
130 |
|
uint32 num_keys; |
131 |
|
union { |
151 |
|
uint32 old_dbnamelen; |
152 |
|
}; |
153 |
|
}; |
154 |
+ |
|
155 |
+ |
// for passing around index data: |
156 |
+ |
struct CIdxData32 { |
157 |
+ |
uint32 fpos; |
158 |
+ |
uint32 reclen; |
159 |
+ |
}; |
160 |
+ |
/* |
161 |
+ |
struct CIdxSeqData32 { //4+4+2+1 = 11 bytes |
162 |
+ |
uint32 fpos; |
163 |
+ |
uint32 reclen; |
164 |
+ |
uint16_t linelen; //line length for FASTA-formatted seq |
165 |
+ |
byte elen; //length of end-of-line delimiter: 1 (unix/mac) or 2 (Windows) |
166 |
+ |
}; |
167 |
+ |
*/ |
168 |
+ |
struct CIdxData { |
169 |
+ |
off_t fpos; //64bit value on Linux |
170 |
+ |
uint32 reclen; |
171 |
+ |
}; |
172 |
+ |
/* |
173 |
+ |
struct CIdxSeqData { //8+4+2+1 = 15 bytes |
174 |
+ |
off_t fpos; //64bit value on Linux |
175 |
+ |
uint32 reclen; |
176 |
+ |
uint16_t linelen; //line length for FASTA-formatted seq |
177 |
+ |
byte elen; //length of end-of-line delimiter: 1 (unix/mac) or 2 (Windows) |
178 |
+ |
}; |
179 |
+ |
*/ |
180 |
|
#pragma pack() |
181 |
|
|
182 |
|
extern int cdbInfoSIZE; |
183 |
+ |
extern int IdxDataSIZE; |
184 |
+ |
extern int IdxDataSIZE32; |
185 |
+ |
/* |
186 |
+ |
extern int IdxSeqDataSIZE; |
187 |
+ |
extern int IdxSeqDataSIZE32; |
188 |
+ |
*/ |
189 |
|
|
190 |
|
void uint32_pack(char *,uint32); |
191 |
|
void uint32_pack_big(char *,uint32); |
403 |
|
memcpy((void*)outbuf, (void*)(buf+bufpos), mlen); |
404 |
|
return mlen; |
405 |
|
} |
406 |
< |
|
406 |
> |
char peekChar() { |
407 |
> |
if (eob) return -1; |
408 |
> |
//if (eob || len>buflen) return -1; |
409 |
> |
if (1>bufused-bufpos) refill(true); |
410 |
> |
return *(buf+bufpos); |
411 |
> |
} |
412 |
|
uchar* peekStr(uchar* outbuf, int len) { |
413 |
|
int rd=peek(outbuf,len); |
414 |
|
if (rd>0) { outbuf[rd]='\0'; return outbuf; } |
415 |
|
else return NULL; |
416 |
|
} |
417 |
|
//looks ahead to check if what follows matches |
418 |
< |
int peekCmp(char* cmpstr, int cmplen=0) { |
418 |
> |
int peekCmp(char* cmpstr, int cmplen=-1) { |
419 |
> |
if (cmplen==0) return 0; |
420 |
|
if (eob) //GError("GReadBuf::peekcmp error: eob!\n"); |
421 |
|
return -2; |
422 |
< |
if (!cmplen) cmplen=strlen(cmpstr); |
422 |
> |
if (cmplen<0) cmplen=strlen(cmpstr); |
423 |
|
if (cmplen>bufused-bufpos) { |
424 |
|
refill(true); |
425 |
|
if (cmplen>bufused-bufpos) return -2; |