1 |
#include "EXTERN.h" |
2 |
#include "perl.h" |
3 |
#include "XSUB.h" |
4 |
|
5 |
#include <cdb.h> |
6 |
|
7 |
#include "perlmulticore.h" |
8 |
|
9 |
static struct cdb_make make; |
10 |
|
11 |
MODULE = Geo::LatLon2Place PACKAGE = Geo::LatLon2Place |
12 |
|
13 |
PROTOTYPES: ENABLE |
14 |
|
15 |
int |
16 |
cdb_make_start (int fd) |
17 |
CODE: |
18 |
RETVAL = cdb_make_start (&make, fd); |
19 |
OUTPUT: RETVAL |
20 |
|
21 |
int |
22 |
cdb_make_add (SV *k, SV *v) |
23 |
CODE: |
24 |
{ |
25 |
STRLEN klen; const char *kp = SvPVbyte (k, klen); |
26 |
STRLEN vlen; const char *vp = SvPVbyte (v, vlen); |
27 |
RETVAL = cdb_make_add (&make, kp, klen, vp, vlen); |
28 |
} |
29 |
OUTPUT: RETVAL |
30 |
|
31 |
int |
32 |
cdb_make_finish () |
33 |
CODE: |
34 |
RETVAL = cdb_make_finish (&make); |
35 |
OUTPUT: RETVAL |
36 |
|
37 |
int |
38 |
cdb_init (SV *self, int fd) |
39 |
CODE: |
40 |
sv_upgrade (self, SVt_PV); |
41 |
SvCUR_set (self, sizeof (struct cdb)); |
42 |
SvPOK_only (self); |
43 |
RETVAL = cdb_init ((struct cdb *)SvPVX (self), fd); |
44 |
OUTPUT: RETVAL |
45 |
|
46 |
void |
47 |
cdb_free (SV *self) |
48 |
CODE: |
49 |
cdb_free ((struct cdb *)SvPVX (self)); |
50 |
|
51 |
SV * |
52 |
cdb_get (SV *self, SV *key) |
53 |
CODE: |
54 |
{ |
55 |
unsigned int p; |
56 |
STRLEN l; |
57 |
const char *s = SvPVbyte (key, l); |
58 |
struct cdb *db = (struct cdb *)SvPVX (self); |
59 |
|
60 |
if (cdb_find (db, s, l) <= 0) |
61 |
XSRETURN_UNDEF; |
62 |
|
63 |
p = cdb_datapos (db); |
64 |
l = cdb_datalen (db); |
65 |
RETVAL = newSVpvn (cdb_get (db, l, p), l); |
66 |
} |
67 |
OUTPUT: RETVAL |
68 |
|