2 openisis - an open implementation of the CDS/ISIS database
3 Version 0.8.x (patchlevel see file Version)
4 Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 see README for more information
24 $Id: OpenIsis.xs,v 1.5 2003/04/08 00:20:53 kripke Exp $
34 #undef assert /* perl.h assert doesn't really assert */
40 #if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE)
41 # define malloc PerlMem_malloc
42 # define free PerlMem_free
43 but we need to free memory that was acquired by real malloc
45 I don't now wether these should be defined or not,
46 they are on some Serhij's windows box
47 and aren't on my linux !??
49 However, we will have to move to OpenIsisMFree, anyway ...
52 #define PERLFREE PerlMem_free
59 #define OPENISIS_NOPRE09
63 /* turn negative error codes in nice little numbers */
64 static int sherr ( int x ) {
65 return -(1<<OPENISIS_ERR_SHIFT) <= x ? x : -(-x >> OPENISIS_ERR_SHIFT);
68 MODULE = OpenIsis PACKAGE = OpenIsis
77 openIsisCLog( level, *file ? file : 0 );
84 const char **argv = 0;
89 argv = (const char **)malloc( (items-1) * sizeof(argv[0]) );
90 for ( i=1; i<items; i++ )
91 /* TODO: should take care to make 0-term copies */
92 argv[i-1] = (char *)SvPV(ST(i), n_a);
95 RETVAL = sherr( openIsisCDOpenv( name, argv, argc ) );
106 RETVAL = sherr( openIsisDMaxId( db ) );
115 str = openIsisToHtml( str, -1 );
116 RETVAL = newSVpv( str, 0 );
122 read( db, rowid, ... )
128 OpenIsisRec *r = openIsisDRead( db, rowid );
130 union { OpenIsisRec r; char buf[10000]; } x;
132 hv_store( hv, "mfn", 3, newSViv( r->rowid ), 0 );
135 /* 5.6.x has this. see man perlguts for why it's useful. */
136 char *fmt = (char *)SvPV_nolen( ST(2) );
139 char *fmt = (char *)SvPV( ST(2), unused );
143 q = openIsisRFmt( &x.r, fmt, r );
147 for ( i=0; i < r->len; i++ ) {
152 val = newSVpv( (char*)r->field[i].val, r->field[i].len );
153 snprintf( buf, sizeof(buf), "%hu", r->field[i].tag );
154 buf[sizeof(buf)-1] = 0;
155 entry = hv_fetch( hv, buf, strlen(buf), 1 );
156 assert ( entry ); /* out of memory */
157 if ( ! *entry || ! SvROK(*entry) ) {
159 *entry = newRV_noinc((SV*)ar);
161 ar = (AV*)SvRV(*entry);
162 assert( SVt_PVAV == SvTYPE(ar) );
169 RETVAL = newRV_noinc( (SV*)hv );
185 f.len = strlen(field);
186 r = openIsisRSplitf( 0, &f );
190 buf[sizeof(buf)-1] = 0;
191 for ( i=0; i < r->len; i++ ) {
192 buf[0] = (char)r->field[i].tag;
193 hv_store( hv, buf, buf[0] ? 1 : 0,
194 newSVpv( (char*)r->field[i].val, r->field[i].len ), 0 );
198 RETVAL = newRV_noinc( (SV*)hv );
204 query( db, key, ... )
209 int mode = OPENISIS_QRY_SIMPLE;
214 got = (int)openIsisDQuery( &set, db, key, mode, skip );
218 for ( i=0; i<got; i++ )
219 PUSHs(sv_2mortal(newSViv(set.id[i])));
230 union { OpenIsisRec r; char buf[10000]; } x;
232 x.r.bytes = sizeof(x);
233 while ( openIsisDTerm( &x.r, db, key ) && x.r.len ) {
236 /* printf( "%ld terms\n", x.r.len ); */
237 for ( i=0; i<x.r.len; i++ )
238 PUSHs(sv_2mortal(newSVpv( (char*)x.r.field[i].val, x.r.field[i].len )));
247 RETVAL = sherr( openIsisCDClose( db ) );