File: Nilsimsa.xs

package info (click to toggle)
libdigest-nilsimsa-perl 0.06-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 232 kB
  • ctags: 74
  • sloc: ansic: 444; makefile: 47; perl: 6
file content (91 lines) | stat: -rw-r--r-- 1,842 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
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

/* $Id: Nilsimsa.xs,v 1.1 2002/05/20 22:29:07 chad Exp $ */

/* try to be compatible with older perls */
/* SvPV_nolen() macro first defined in 5.005_55 */
/* this is slow, not threadsafe, but works */
#include "patchlevel.h"
#if (PATCHLEVEL == 4) || ((PATCHLEVEL == 5) && (SUBVERSION < 55))
static STRLEN nolen_na;
# define SvPV_nolen(sv) SvPV ((sv), nolen_na)
#endif

#include "nilsimsa.h"

typedef struct nilsimsastate {
  int mode;
  char errmsg[99];
} *Digest__Nilsimsa;

MODULE = Digest::Nilsimsa		PACKAGE = Digest::Nilsimsa

PROTOTYPES: ENABLE


Digest::Nilsimsa
new(class)
        SV *    class
        CODE:
        {
          Newz(0, RETVAL, 1, struct nilsimsastate); 
          RETVAL->mode = 1;  /* placeholder, not used now */
          # dprint(" -- Opening debug file: /tmp/nilsimsa_debug.txt"); 
        }
        OUTPUT:
        RETVAL

char *
testxs(self, str)
        Digest::Nilsimsa	self;
        char *		str;
        CODE:
          RETVAL = str + 1;
	OUTPUT:
        RETVAL

SV *
errmsg(self)
        Digest::Nilsimsa self;
        CODE:
        {
          RETVAL = newSVpv(self->errmsg,0);
        }
	OUTPUT:
        RETVAL

SV *
text2digest(self, text)
        Digest::Nilsimsa self;
        SV *	text;
        CODE:
        {
	  struct nsrecord gunma;
          char str[65];
          unsigned char *rawbytes;
          int ret;
	  STRLEN size;

          rawbytes = SvPV(text,size);
	  clear(&gunma);
	  filltran();

	  ret=accbuf(rawbytes,size,&gunma);

	  makecode(&gunma);
	  codetostr(&gunma,str);

	  if (ret==size) {
	    RETVAL = newSVpv(str,64);
            *(self->errmsg) = 0;
          } else {  
            RETVAL = newSVpv ("", 0);
            sprintf(self->errmsg,"error: accbuf returned %d", ret);
	  }

        }
	OUTPUT:
        RETVAL