root/lang/perl/Senna/trunk/senna-global.c @ 3962

Revision 3962, 2.5 kB (checked in by daisuke, 6 years ago)

lang/perl/Senna; More sorting stuff

Line 
1/* $Id$
2 *
3 * Copyright (c) 2005-2007 Daisuke Maki <daisuke@endeworks.jp>
4 * All rights reserved.
5 */
6#include "senna-perl.h"
7#ifndef  __SENNA_GLOBAL_C__
8#define  __SENNA_GLOBAL_C__
9
10int
11SennaPerl_Global_bootstrap()
12{
13    HV *stash;
14    sen_rc rc;
15
16    rc = sen_init();
17    if (rc != sen_success) {
18        croak("Failed to call sen_init(). sen_init() returned %d", rc);
19    }
20
21    stash = gv_stashpv("Senna::Constants", 1);
22
23    newCONSTSUB(stash, "LIBSENNA_VERSION",
24        newSVpvf("%d.%d.%d",
25            SENNA_MAJOR_VERSION,
26            SENNA_MINOR_VERSION,
27            SENNA_MICRO_VERSION
28        )
29    );
30
31    SennaPerl_Index_bootstrap();
32    SennaPerl_RC_bootstrap();
33    SennaPerl_Encoding_bootstrap();
34    SennaPerl_Records_bootstrap();
35
36    return 1;
37}
38
39SV *
40SennaPerl_Global_sen_rc2obj(rc)
41        sen_rc rc;
42{
43    SV *sv;
44
45    if (GIMME_V == G_VOID) {
46        sv = &PL_sv_undef;
47    } else {
48        dSP;
49        ENTER;
50        SAVETMPS;
51        PUSHMARK(SP);
52        XPUSHs(sv_2mortal(newSVpv("Senna::RC", 9)));
53        XPUSHs(sv_2mortal(newSViv(rc)));
54        PUTBACK;
55
56        if (call_method("Senna::RC::new", G_SCALAR) <= 0) {
57            croak("Senna::RC::new did not return a proper object");
58        }
59
60        SPAGAIN;
61        sv = POPs;
62
63        if (! sv_isobject(sv) || ! sv_isa(sv, "Senna::RC")) {
64            croak("Senna::RC::new did not return a proper object");
65        }
66
67        sv = newSVsv(sv);
68
69        FREETMPS;
70        LEAVE;
71    }
72    return sv;
73}
74
75void *
76SennaPerl_Global_sv2key(sv)
77        SV *sv;
78{
79    STRLEN len;
80    char *key = SvPV(sv, len);
81
82    return (void *) key;
83}
84
85HV *
86SennaPerl_Global_info()
87{
88    HV *hv;
89    char *version;
90    char *config_opts;
91    char *config_path;
92    sen_encoding default_encoding;
93    unsigned int initial_n_segments;
94    unsigned int partial_match_threshold;
95
96    sen_info(&version, &config_opts, &config_path,
97        &default_encoding, &initial_n_segments, &partial_match_threshold);
98
99    hv = newHV();
100
101    hv_store(hv, "version", 7, newSVpv(version, strlen(version)), 0);
102    hv_store(hv, "configure_options", 17, newSVpv(config_opts, strlen(config_opts)), 0);
103    hv_store(hv, "config_path", 11, newSVpv(config_path, strlen(config_path)), 0);
104    hv_store(hv, "default_encoding", 16, newSViv(default_encoding), 0);
105    hv_store(hv, "initial_n_segments", 18, newSViv(initial_n_segments), 0);
106    hv_store(hv, "partial_match_threshold", 24, newSViv(partial_match_threshold), 0);
107
108    return hv;
109}
110
111#endif /*  __SENNA_GLOBAL_C__ */
112
Note: See TracBrowser for help on using the browser.