-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmyhx.c
75 lines (61 loc) · 1.75 KB
/
myhx.c
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
// myopen: skeleton for creating a statically-linked hxfile
// record-type. Such files cannot be used with "chx".
#include <assert.h>
#include <string.h>
#include <hx.h>
HXFILE *myopen(char const *name, int mode);
static int
mydiff(char const *lp, char const *rp, char const *udata, int uleng)
{
(void)lp, (void)rp, (void)udata, (void)uleng;
int ret = 0; // keys match
// DO SOMETHING
return ret;
}
static HXHASH
myhash(char const *recp, char const *udata, int uleng)
{
(void)recp, (void)udata, (void)uleng;
unsigned long ret = 0; // 0 is invalid
// DO SOMETHING
return ret;
}
static int
myload(char *recp, int recsize, char const *buf, char const *udata, int uleng)
{
(void)recp, (void)buf, (void)udata, (void)uleng;
int ret = 0; // 0 => fail
// DO SOMETHING
assert(ret >= 0);
assert(ret <= recsize);
return ret;
}
static int
mysave(char const *recp, int reclen, char *buf, int bufsize,
char const *udata, int uleng)
{
(void)recp, (void)reclen, (void)udata, (void)uleng;
assert(!buf || bufsize > 0);
int ret = 0; // 0 => fail
// DO SOMETHING
assert(ret >= 0);
assert(!buf || !(ret < bufsize ? buf[ret] : buf[bufsize - 1]));
assert(!strchr(buf, '\n'));
return ret; // 0 bytes written to buf
}
static int
mytest(char const *recp, int reclen, char const *udata, int uleng)
{
(void)recp, (void)reclen, (void)udata, (void)uleng;
assert(reclen > 0);
int ret = 0; // => fail
// DO SOMETHING
return ! !ret;
}
HXFILE *
myopen(char const *name, int mode)
{
HXFILE *hp = hxopen(name, mode, myhash, mydiff);
hxbind(hp, mydiff, myhash, myload, mysave, mytest);
return hp;
}