forked from mischasan/hx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hx_ch.c
78 lines (67 loc) · 2.02 KB
/
hx_ch.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
76
77
78
// Copyright (C) 2001-2013 Mischa Sandberg <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License Version 2 as
// published by the Free Software Foundation. You may not use, modify or
// distribute this program under any other version of the GNU General
// Public License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// IF YOU HAVE NO WAY OF WORKING WITH GPL, CONTACT ME.
//-------------------------------------------------------------------------------
#include <string.h>
#include "hx_.h"
static inline int
IMIN(int a, int b)
{
return a < b ? a : b;
}
int
diff(char const *a, char const *b,
char const *udata __unused, int uleng __unused)
{
return *(short const *)a - *(short const *)b;
}
HXHASH
hash(char const *recp, char const *udata __unused, int uleng __unused)
{
return *recp;
}
int
load(char *recp, int recsize, char const *buf,
char const *udata __unused, int uleng __unused)
{
int buflen = strlen(buf);
memcpy(recp, buf, IMIN(buflen, recsize));
return buflen;
}
int
save(char const *recp, int reclen, char *buf, int bufsize,
char const *udata __unused, int uleng __unused)
{
if (bufsize > 0) {
int len = IMIN(reclen, bufsize - 1);
memcpy(buf, recp, len);
buf[len] = 0;
}
return reclen + 1;
}
int
test(char const *recp, int reclen,
char const *udata __unused, int uleng __unused)
{
if (reclen < 2)
return 0;
for (; --reclen >= 0; ++recp)
if (*recp < ' ' || *recp > '~')
return 0;
return 1;
}