typedef struct ab_input {
long lTrackId;
char szDescription[80];
} AB_IN;
####
typedef struct {
/* char fn[256]; */
char *fn;
/* char *desc; */
long size;
} cstype;
####
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
typedef struct {
/* char fn[256]; */
char *fn;
/* char *desc; */
long size;
} cstype;
extern char* _open_read(char *fn);
extern char* _open_read_st(cstype *stru);
/* Will convert a Perl HV* to a C cstype* */
cstype *
XS_unpack_cstypePtr( rv )
SV *rv;
{
HV *hv;
SV **ssv;
cstype *abin;
char *temp;
STRLEN len;
if( SvROK( rv ) && (SvTYPE(SvRV(rv)) == SVt_PVHV) )
hv = (HV*)SvRV(rv);
else{
warn("XS_unpack_cstypePtr: rv was not an HV ref");
return( (cstype*)NULL );
}
abin = (cstype*)safemalloc( sizeof( cstype ) );
if( abin == NULL ){
warn("XS_unpack_cstypePtr: unable to malloc cstype");
return( (cstype*)NULL);
}
abin->fn[0] = '\0';
/* abin->desc[0] = '\0'; */
abin->size = 0;
ssv = hv_fetch( hv, "size", 4, 0 );
if( ssv != NULL ){
if( SvIOK( *ssv ) )
abin->size = (long)SvIV( *ssv );
else{
warn("XS_unpack_cstypePtr: hash elem size was not IOK");
}
}
else
warn("XS_unpack_cstypePtr: hash elem size was null");
ssv = hv_fetch( hv, "fn", 2, 0 );
if( ssv != NULL ){
if( SvPOK( *ssv ) )
{
temp = SvPV(*ssv, len);
if ((abin->fn =
(char*) safemalloc((len + 1) * sizeof(char))) == NULL)
return (cstype*)NULL;
strcpy( abin->fn, temp );
}
else{
warn("XS_unpack_cstypePtr: hash elem fn was not POK");
}
}
else
warn("XS_unpack_cstypePtr: hash elem fn was null");
/*
ssv = hv_fetch( hv, "desc", 4, 0 );
if( ssv != NULL ){
if( SvPOK( *ssv ) )
{
temp = SvPV(*ssv, len);
if ((abin->desc =
(char*) safemalloc((len + 1) * sizeof(char))) == NULL)
return (cstype*)NULL;
strcpy( abin->desc, temp );
}
else{
warn("XS_unpack_cstypePtr: hash elem desc was not POK");
}
}
else
warn("XS_unpack_cstypePtr: hash elem desc was null");
*/
return( abin );
}
MODULE = RFile PACKAGE = RFile
PROTOTYPES: DISABLE
SV*
read_file(fn)
char *fn
PREINIT:
char *content;
CODE:
content = _open_read(fn);
if (content == NULL)
XSRETURN_UNDEF;
RETVAL = newSVpv(content, 0);
OUTPUT:
RETVAL
SV*
read_st(stru)
cstype *stru
CODE:
printf("# Hello, string=(%s)\n", stru->fn );
RETVAL = newSVpv(stru->fn, 0);
OUTPUT:
RETVAL
####
package RFile;
use strict;
use Carp;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
require DynaLoader;
require AutoLoader;
@ISA = qw(Exporter DynaLoader);
$VERSION = '0.01';
bootstrap RFile $VERSION;
sub new {
my $class = shift;
my $self = {
m => [
{
fn => 'Makefile.PL',
size => 100,
desc => 'test',
},
{
fn => 'typemap',
size => 100,
desc => 'test',
},
{
fn => 'RFile.c',
size => 100,
desc => 'test',
},
],
};
bless $self, $class;
}
sub dump {
my ($self, $idx) = @_;
return RFile::read_st($self->{m}->[$idx]);
}
1;
####
my $n = new RFile;
for (0..2) {
$c = $n->dump($_);
print $c, "\n";
}