1// Copyright (c) 2014 David J. Shultz <dshultz@cpan.org> 2// This software is covered by the GPL. 3 4#include "EXTERN.h" 5#include "perl.h" 6#include "XSUB.h" 7 8#include "lib/discid.h" 9#include <stdio.h> 10#include <stdlib.h> 11 12static int 13not_here(char *s) 14{ 15 croak("%s not implemented on this architecture", s); 16 return -1; 17} 18 19static double 20constant(char *name, int len, int arg) 21{ 22 errno = EINVAL; 23 return 0; 24} 25 26MODULE = Net::FreeDB PACKAGE = Net::FreeDB 27 28double 29constant(sv,arg) 30 PREINIT: 31 STRLEN len; 32 INPUT: 33 SV * sv 34 char * s = SvPV(sv, len); 35 int arg 36 CODE: 37 RETVAL = constant(s,len,arg); 38 OUTPUT: 39 RETVAL 40 41char* 42xs_discid(int driveNo) 43 INIT: 44 char id[30]; 45 CODE: 46 sprintf(id, "%08x", discid(driveNo)); 47 RETVAL = id; 48 OUTPUT: 49 RETVAL 50 51SV* 52xs_discinfo(int driveNo) 53 INIT: 54 int i; 55 char id[30]; 56 struct discdata data; 57 HV* hash = newHV(); 58 AV* tracks = newAV(); 59 PPCODE: 60 data = get_disc_id(driveNo); 61 62 for (i = 0; i < (data.num_of_trks); i++) { 63 av_push(tracks, newSVnv(data.track_offsets[i])); 64 } 65 66 sprintf(id, "%08x", (unsigned int)data.discid); 67 hv_store(hash, "ID", 2, newSVpv(id, 0), 0); 68 hv_store(hash, "NUM_TRKS", 8, newSVnv(data.num_of_trks), 0); 69 hv_store(hash, "TRACKS", 6, newRV_inc((SV*)tracks), 0); 70 hv_store(hash, "SECONDS", 7, newSVnv(data.seconds), 0); 71 72 XPUSHs(newRV((SV*)hash)); 73 74int 75getNumDrives() 76 INIT: 77 int numDrives; 78 CODE: 79 initTool(); 80 numDrives = getNumDrives(); 81 RETVAL = numDrives; 82 OUTPUT: 83 RETVAL 84 85