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