File: Hunspell.xs

package info (click to toggle)
libtext-hunspell-perl 2.14-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 1,032 kB
  • sloc: perl: 99; makefile: 8
file content (158 lines) | stat: -rw-r--r-- 2,992 bytes parent folder | download
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "hunspell.hxx"
#include "assert.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifdef __cplusplus
}
#endif



using namespace std;
/*using namespace Hunspell;*/

static void * get_mortalspace ( size_t nbytes ) {
    SV * mortal;
    mortal = sv_2mortal( NEWSV(0, nbytes ) );
    return (void *)SvPVX(mortal);
}

MODULE = Text::Hunspell        PACKAGE = Text::Hunspell

PROTOTYPES: ENABLE

# Make sure that we have at least xsubpp version 1.922.
REQUIRE: 1.922

Hunspell *
Hunspell::new(aff,dic )
    char *aff;
    char *dic;
    CODE:
        RETVAL = new Hunspell(aff, dic);

    OUTPUT:
        RETVAL

int
Hunspell::delete(h)
    Hunspell *h;
    CODE:
        warn("Text::Hunspell::delete() is deprecated and no replacement is needed");
        RETVAL = 1;
    OUTPUT:
        RETVAL

void
Hunspell::DESTROY()

int
Hunspell::add_dic(dic)
    char *dic;
    CODE:
        RETVAL = THIS->add_dic(dic);

    OUTPUT:
        RETVAL

int
Hunspell::check(buf)
    char *buf;
    CODE:
        RETVAL = THIS->spell(buf);

    OUTPUT:
        RETVAL

void 
Hunspell::suggest(buf)
    char *buf;
    PREINIT:
        char **wlsti;
	int i, val;
    PPCODE:
        val = THIS->suggest(&wlsti, buf);
	for (int i = 0; i < val; i++) {
            PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
	}
	THIS->free_list(&wlsti, val);

void 
Hunspell::analyze(buf)
    char *buf;
    PREINIT:
        char **wlsti;
        int i, val;
    PPCODE:
        val = THIS->analyze(&wlsti, buf);
        for (i = 0; i < val; i++) {
            PUSHs(sv_2mortal(newSVpv(wlsti[i], 0)));
        }
	THIS->free_list(&wlsti, val);


void 
Hunspell::stem( buf)
    char *buf;
    PREINIT:
        char **wlsti;
	int i, val;
    PPCODE:
        val = THIS->stem(&wlsti, buf);
	for (int i = 0; i < val; i++) {
            PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
	}
	THIS->free_list(&wlsti, val);


void 
Hunspell::generate( buf, sample)
    char *buf;
    char *sample;
    PREINIT:
        char **wlsti;
	int i, val;
    PPCODE:
        val = THIS->generate(&wlsti, buf, sample);
	for (int i = 0; i < val; i++) {
            PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
	}
	THIS->free_list(&wlsti, val);


void 
Hunspell::generate2( buf, avref)
    AV * avref;
    char *buf;
    PREINIT:
        char ** array;
        char **wlsti;
        int len;
        SV ** elem;
        int i, val;
    PPCODE:
        len = av_len(avref) + 1;

        /* First allocate some memory for the pointers */
        array = (char **) get_mortalspace( len * sizeof( *array ));

        /* Loop over each element copying pointers to the new array */
        for (i=0; i<len; i++) {
            elem = av_fetch( avref, i, 0 );
            array[i] = SvPV( *elem, PL_na );
        }

        val = THIS->generate(&wlsti, buf, array,  len);

        for (int i = 0; i < val; i++) {
            PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
        }
	THIS->free_list(&wlsti, val);