-
Notifications
You must be signed in to change notification settings - Fork 2
/
calcdb.cc
64 lines (54 loc) · 1.21 KB
/
calcdb.cc
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
#include <string.h>
#include "calcdb.h"
Dbase_Ctrl_Blk::Dbase_Ctrl_Blk(char *infile, int buf_sz)
{
fd = open (infile, O_RDONLY);
if (fd < 0){
printf("ERROR: InvalidFile -- Dbase_Ctrl_Blk()\n");
exit(-1);
}
buf_size = buf_sz;
buf = new int [buf_sz];
cur_buf_pos = 0;
cur_blk_size = 0;
readall = 0;
endpos = lseek(fd,0,SEEK_END);
}
Dbase_Ctrl_Blk::~Dbase_Ctrl_Blk()
{
delete [] buf;
close(fd);
}
void Dbase_Ctrl_Blk::get_next_trans_ext()
{
// Need to get more items from file
int res = cur_blk_size - cur_buf_pos;
if (res > 0)
{
// First copy partial transaction to beginning of buffer
memcpy((void *)buf,
(void *)(buf + cur_buf_pos),
res * ITSZ);
cur_blk_size = res;
}
else
{
// No partial transaction in buffer
cur_blk_size = 0;
}
res = read(fd, (void *)(buf + cur_blk_size),
((buf_size - cur_blk_size)*ITSZ));
if (res < 0){
perror("reading in database");
exit(errno);
}
cur_blk_size += res/ITSZ;
//if (cur_blk_size > 0)
//{
// custid = buf[0];
// tid = buf[1];
// numitem = buf[2];
// cur_buf_pos = 3;
//}
cur_buf_pos = 0;
}