| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| /* $Id: Nilsimsa.xs,v 1.1 2002/05/20 22:29:07 chad Exp $ */ |
| 6 |
|
| |
| 7 |
|
| /* try to be compatible with older perls */ |
| 8 |
|
| /* SvPV_nolen() macro first defined in 5.005_55 */ |
| 9 |
|
| /* this is slow, not threadsafe, but works */ |
| 10 |
|
| #include "patchlevel.h" |
| 11 |
|
| #if (PATCHLEVEL == 4) || ((PATCHLEVEL == 5) && (SUBVERSION < 55)) |
| 12 |
|
| static STRLEN nolen_na; |
| 13 |
|
| # define SvPV_nolen(sv) SvPV ((sv), nolen_na) |
| 14 |
|
| #endif |
| 15 |
|
| |
| 16 |
|
| #include "nilsimsa.h" |
| 17 |
|
| |
| 18 |
|
| typedef struct nilsimsastate { |
| 19 |
|
| int mode; |
| 20 |
|
| char errmsg[99]; |
| 21 |
|
| } *Digest__Nilsimsa; |
| 22 |
|
| |
| 23 |
|
| MODULE = Digest::Nilsimsa PACKAGE = Digest::Nilsimsa |
| 24 |
|
| |
| 25 |
|
| PROTOTYPES: ENABLE |
| 26 |
|
| |
| 27 |
|
| |
| 28 |
|
| Digest::Nilsimsa |
| 29 |
|
| new(class) |
| 30 |
|
| SV * class |
| 31 |
|
| CODE: |
| 32 |
|
| { |
| 33 |
1 |
| Newz(0, RETVAL, 1, struct nilsimsastate); |
| 34 |
1 |
| RETVAL->mode = 1; /* placeholder, not used now */ |
| 35 |
|
| # dprint(" -- Opening debug file: /tmp/nilsimsa_debug.txt"); |
| 36 |
|
| } |
| 37 |
|
| OUTPUT: |
| 38 |
|
| RETVAL |
| 39 |
|
| |
| 40 |
|
| char * |
| 41 |
|
| testxs(self, str) |
| 42 |
|
| Digest::Nilsimsa self; |
| 43 |
|
| char * str; |
| 44 |
|
| CODE: |
| 45 |
1 |
| RETVAL = str + 1; |
| 46 |
|
| OUTPUT: |
| 47 |
|
| RETVAL |
| 48 |
|
| |
| 49 |
|
| SV * |
| 50 |
|
| errmsg(self) |
| 51 |
|
| Digest::Nilsimsa self; |
| 52 |
|
| CODE: |
| 53 |
|
| { |
| 54 |
0 |
| RETVAL = newSVpv(self->errmsg,0); |
| 55 |
|
| } |
| 56 |
|
| OUTPUT: |
| 57 |
|
| RETVAL |
| 58 |
|
| |
| 59 |
|
| SV * |
| 60 |
|
| text2digest(self, text) |
| 61 |
|
| Digest::Nilsimsa self; |
| 62 |
|
| SV * text; |
| 63 |
|
| CODE: |
| 64 |
|
| { |
| 65 |
|
| struct nsrecord gunma; |
| 66 |
|
| char str[65]; |
| 67 |
|
| unsigned char *rawbytes; |
| 68 |
|
| int ret; |
| 69 |
|
| STRLEN size; |
| 70 |
|
| |
| 71 |
5 |
| rawbytes = SvPV(text,size); |
| 72 |
5 |
| clear(&gunma); |
| 73 |
5 |
| filltran(); |
| 74 |
|
| |
| 75 |
5 |
| ret=accbuf(rawbytes,size,&gunma); |
| 76 |
|
| |
| 77 |
5 |
| makecode(&gunma); |
| 78 |
5 |
| codetostr(&gunma,str); |
| 79 |
|
| |
| 80 |
5 |
▶ | if (ret==size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret==size) { |
5 |
0 |
5 |
|
| 81 |
5 |
| RETVAL = newSVpv(str,64); |
| 82 |
5 |
| *(self->errmsg) = 0; |
| 83 |
|
| } else { |
| 84 |
0 |
| RETVAL = newSVpv ("", 0); |
| 85 |
0 |
| sprintf(self->errmsg,"error: accbuf returned %d", ret); |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| } |
| 89 |
|
| OUTPUT: |
| 90 |
|
| RETVAL |
| 91 |
|
| |