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