| 1 |
|
| #include "hunspell.hxx" |
| 2 |
|
| #include "assert.h" |
| 3 |
|
| |
| 4 |
|
| #ifdef __cplusplus |
| 5 |
|
| extern "C" { |
| 6 |
|
| #endif |
| 7 |
|
| |
| 8 |
|
| #include "EXTERN.h" |
| 9 |
|
| #include "perl.h" |
| 10 |
|
| #include "XSUB.h" |
| 11 |
|
| |
| 12 |
|
| #ifdef __cplusplus |
| 13 |
|
| } |
| 14 |
|
| #endif |
| 15 |
|
| |
| 16 |
|
| |
| 17 |
|
| |
| 18 |
|
| using namespace std; |
| 19 |
|
| /*using namespace Hunspell;*/ |
| 20 |
|
| |
| 21 |
1 |
| static void * get_mortalspace ( size_t nbytes ) { |
| 22 |
|
| SV * mortal; |
| 23 |
1 |
| mortal = sv_2mortal( NEWSV(0, nbytes ) ); |
| 24 |
1 |
| return (void *)SvPVX(mortal); |
| 25 |
|
| } |
| 26 |
|
| |
| 27 |
|
| MODULE = Text::Hunspell PACKAGE = Text::Hunspell |
| 28 |
|
| |
| 29 |
|
| PROTOTYPES: ENABLE |
| 30 |
|
| |
| 31 |
|
| # Make sure that we have at least xsubpp version 1.922. |
| 32 |
|
| REQUIRE: 1.922 |
| 33 |
|
| |
| 34 |
|
| Hunspell * |
| 35 |
|
| Hunspell::new(aff,dic ) |
| 36 |
|
| char *aff; |
| 37 |
|
| char *dic; |
| 38 |
|
| CODE: |
| 39 |
8 |
▶ | RETVAL = new Hunspell(aff, dic); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = new Hunspell(aff, dic); |
8 |
0 |
8 |
| RETVAL = new Hunspell(aff, dic); |
0 |
0 |
0 |
|
| 40 |
|
| |
| 41 |
|
| OUTPUT: |
| 42 |
|
| RETVAL |
| 43 |
|
| |
| 44 |
|
| int |
| 45 |
|
| Hunspell::delete(h) |
| 46 |
|
| Hunspell *h; |
| 47 |
|
| CODE: |
| 48 |
0 |
| warn("Text::Hunspell::delete() is deprecated and no replacement is needed"); |
| 49 |
0 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
0 |
0 |
0 |
|
| 50 |
|
| OUTPUT: |
| 51 |
|
| RETVAL |
| 52 |
|
| |
| 53 |
|
| void |
| 54 |
|
| Hunspell::DESTROY() |
| 55 |
|
| |
| 56 |
|
| int |
| 57 |
|
| Hunspell::add_dic(dic) |
| 58 |
|
| char *dic; |
| 59 |
|
| CODE: |
| 60 |
1 |
▶ | RETVAL = THIS->add_dic(dic); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = THIS->add_dic(dic); |
0 |
1 |
1 |
|
| 61 |
|
| |
| 62 |
|
| OUTPUT: |
| 63 |
|
| RETVAL |
| 64 |
|
| |
| 65 |
|
| int |
| 66 |
|
| Hunspell::check(buf) |
| 67 |
|
| char *buf; |
| 68 |
|
| CODE: |
| 69 |
11 |
▶ | RETVAL = THIS->spell(buf); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = THIS->spell(buf); |
0 |
11 |
11 |
|
| 70 |
|
| |
| 71 |
|
| OUTPUT: |
| 72 |
|
| RETVAL |
| 73 |
|
| |
| 74 |
|
| void |
| 75 |
|
| Hunspell::suggest(buf) |
| 76 |
|
| char *buf; |
| 77 |
|
| PREINIT: |
| 78 |
|
| char **wlsti; |
| 79 |
|
| int i, val; |
| 80 |
|
| PPCODE: |
| 81 |
1 |
▶ | val = THIS->suggest(&wlsti, buf); |
Branch: 1 branch
| Branch | True | False | Total |
| val = THIS->suggest(&wlsti, buf); |
1 |
0 |
1 |
|
| 82 |
4 |
▶ | for (int i = 0; i < val; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (int i = 0; i < val; i++) { |
3 |
1 |
4 |
|
| 83 |
3 |
▶ | PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
3 |
0 |
3 |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
3 |
0 |
3 |
|
| 84 |
|
| } |
| 85 |
1 |
▶ | THIS->free_list(&wlsti, val); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->free_list(&wlsti, val); |
1 |
0 |
1 |
|
| 86 |
|
| |
| 87 |
|
| void |
| 88 |
|
| Hunspell::analyze(buf) |
| 89 |
|
| char *buf; |
| 90 |
|
| PREINIT: |
| 91 |
|
| char **wlsti; |
| 92 |
|
| int i, val; |
| 93 |
|
| PPCODE: |
| 94 |
1 |
▶ | val = THIS->analyze(&wlsti, buf); |
Branch: 1 branch
| Branch | True | False | Total |
| val = THIS->analyze(&wlsti, buf); |
1 |
0 |
1 |
|
| 95 |
2 |
▶ | for (i = 0; i < val; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < val; i++) { |
1 |
1 |
2 |
|
| 96 |
1 |
▶ | PUSHs(sv_2mortal(newSVpv(wlsti[i], 0))); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(sv_2mortal(newSVpv(wlsti[i], 0))); |
1 |
0 |
1 |
| PUSHs(sv_2mortal(newSVpv(wlsti[i], 0))); |
1 |
0 |
1 |
|
| 97 |
|
| } |
| 98 |
1 |
▶ | THIS->free_list(&wlsti, val); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->free_list(&wlsti, val); |
1 |
0 |
1 |
|
| 99 |
|
| |
| 100 |
|
| |
| 101 |
|
| void |
| 102 |
|
| Hunspell::stem( buf) |
| 103 |
|
| char *buf; |
| 104 |
|
| PREINIT: |
| 105 |
|
| char **wlsti; |
| 106 |
|
| int i, val; |
| 107 |
|
| PPCODE: |
| 108 |
0 |
▶ | val = THIS->stem(&wlsti, buf); |
Branch: 1 branch
| Branch | True | False | Total |
| val = THIS->stem(&wlsti, buf); |
0 |
0 |
0 |
|
| 109 |
0 |
▶ | for (int i = 0; i < val; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (int i = 0; i < val; i++) { |
0 |
0 |
0 |
|
| 110 |
0 |
▶ | PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
0 |
0 |
0 |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
0 |
0 |
0 |
|
| 111 |
|
| } |
| 112 |
0 |
▶ | THIS->free_list(&wlsti, val); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->free_list(&wlsti, val); |
0 |
0 |
0 |
|
| 113 |
|
| |
| 114 |
|
| |
| 115 |
|
| void |
| 116 |
|
| Hunspell::generate( buf, sample) |
| 117 |
|
| char *buf; |
| 118 |
|
| char *sample; |
| 119 |
|
| PREINIT: |
| 120 |
|
| char **wlsti; |
| 121 |
|
| int i, val; |
| 122 |
|
| PPCODE: |
| 123 |
16 |
▶ | val = THIS->generate(&wlsti, buf, sample); |
Branch: 1 branch
| Branch | True | False | Total |
| val = THIS->generate(&wlsti, buf, sample); |
16 |
0 |
16 |
|
| 124 |
32 |
▶ | for (int i = 0; i < val; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (int i = 0; i < val; i++) { |
16 |
16 |
32 |
|
| 125 |
16 |
▶ | PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
16 |
0 |
16 |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
16 |
0 |
16 |
|
| 126 |
|
| } |
| 127 |
16 |
▶ | THIS->free_list(&wlsti, val); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->free_list(&wlsti, val); |
16 |
0 |
16 |
|
| 128 |
|
| |
| 129 |
|
| |
| 130 |
|
| void |
| 131 |
|
| Hunspell::generate2( buf, avref) |
| 132 |
|
| AV * avref; |
| 133 |
|
| char *buf; |
| 134 |
|
| PREINIT: |
| 135 |
|
| char ** array; |
| 136 |
|
| char **wlsti; |
| 137 |
|
| int len; |
| 138 |
|
| SV ** elem; |
| 139 |
|
| int i, val; |
| 140 |
|
| PPCODE: |
| 141 |
1 |
▶ | len = av_len(avref) + 1; |
Branch: 1 branch
| Branch | True | False | Total |
| len = av_len(avref) + 1; |
1 |
0 |
1 |
|
| 142 |
|
| |
| 143 |
|
| /* First allocate some memory for the pointers */ |
| 144 |
1 |
▶ | array = (char **) get_mortalspace( len * sizeof( *array )); |
Branch: 1 branch
| Branch | True | False | Total |
| array = (char **) get_mortalspace( len * sizeof( *array )); |
1 |
0 |
1 |
|
| 145 |
|
| |
| 146 |
|
| /* Loop over each element copying pointers to the new array */ |
| 147 |
2 |
▶ | for (i=0; i<len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<len; i++) { |
1 |
1 |
2 |
|
| 148 |
1 |
▶ | elem = av_fetch( avref, i, 0 ); |
Branch: 1 branch
| Branch | True | False | Total |
| elem = av_fetch( avref, i, 0 ); |
1 |
0 |
1 |
|
| 149 |
2 |
| array[i] = SvPV( *elem, PL_na ); |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
1 |
▶ | val = THIS->generate(&wlsti, buf, array, len); |
Branch: 1 branch
| Branch | True | False | Total |
| val = THIS->generate(&wlsti, buf, array, len); |
1 |
0 |
1 |
|
| 153 |
|
| |
| 154 |
2 |
▶ | for (int i = 0; i < val; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (int i = 0; i < val; i++) { |
1 |
1 |
2 |
|
| 155 |
1 |
▶ | PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
1 |
0 |
1 |
| PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 ))); |
1 |
0 |
1 |
|
| 156 |
|
| } |
| 157 |
1 |
▶ | THIS->free_list(&wlsti, val); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->free_list(&wlsti, val); |
1 |
0 |
1 |
|
| 158 |
|
| |