ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/XML-DB/DB.xs
Revision: 1.2
Committed: Sun Apr 21 17:30:08 2002 UTC (22 years ago) by root
Branch: MAIN
Changes since 1.1: +72 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5 root 1.2 #include <string.h>
6    
7     // a compiler supporting C99 is required
8    
9 root 1.1 /* try to be compatible with older perls */
10     /* SvPV_nolen() macro first defined in 5.005_55 */
11     /* this is slow, not threadsafe, but works */
12     #include "patchlevel.h"
13     #if (PATCHLEVEL == 4) || ((PATCHLEVEL == 5) && (SUBVERSION < 55))
14     static STRLEN nolen_na;
15     # define SvPV_nolen(sv) SvPV ((sv), nolen_na)
16     #endif
17     #if PATCHLEVEL < 6
18     # define call_sv perl_call_sv
19     #endif
20    
21 root 1.2 #define KEYLEN 8 // number of bytes in the l, m, r fields
22    
23     static SV *
24     new_key (void)
25     {
26     SV *new = NEWSV(0, KEYLEN);
27     SvPOK_only (new);
28     SvCUR_set (new, KEYLEN);
29    
30     return new;
31     }
32    
33     MODULE = XML::DB PACKAGE = XML::DB::Key
34    
35     PROTOTYPES: ENABLE
36    
37     int
38     KEYLEN()
39     CODE:
40     RETVAL = KEYLEN;
41     OUTPUT:
42     RETVAL
43    
44     SV *
45     0()
46     ALIAS:
47     1 = 255
48     CODE:
49     RETVAL = new_key ();
50     memset (SvPVX (RETVAL), ix, KEYLEN);
51     OUTPUT:
52     RETVAL
53    
54     # calculcate l + r
55     SV *
56     m(ls,rs)
57     SV * ls
58     SV * rs
59     CODE:
60     unsigned char *l, *m, *r, *me;
61     unsigned int mx, carry;
62    
63     RETVAL = new_key ();
64    
65     l = SvPVX (ls ) + KEYLEN;
66     r = SvPVX (rs ) + KEYLEN;
67     m = (me = SvPVX (RETVAL)) + KEYLEN;
68    
69     me [0] = 'U';
70     me [1] = 'U';
71    
72     mx = (unsigned int)*--l + (unsigned int)*--r + 1; *--m = (mx & 0x0ff) >> 1;
73     carry = mx & 0x100;
74    
75     do
76     {
77     mx = (unsigned int)*--l + (unsigned int)*--r + (carry >> 8); *--m = (mx & 0x0ff) >> 1;
78    
79     m[1] |= (mx & 0x001) << 7;
80     carry = (mx & 0x100);
81     }
82     while (me < m);
83    
84     m[0] |= carry >> 1;
85    
86     OUTPUT:
87     RETVAL
88    
89 root 1.1