--- loncom/homework/caparesponse/capa.i 2004/03/12 21:06:19 1.3 +++ loncom/homework/caparesponse/capa.i 2024/04/29 02:59:19 1.9 @@ -1,34 +1,60 @@ %module capa %{ - +#include "caparesponse.h" %} -%typemap(perl5,in) char** reterror (char** cvalue) { +%typemap(in) char** reterror (char* cvalue) { SV* tempsv; - if (!SvROK($source)) { + long unsigned int len; + if (!SvROK($input)) { croak("expected a reference\n"); } - tempsv = SvRV($source); + tempsv = SvRV($input); if ((!SvPOK(tempsv))) { croak("expected a double reference\n"); } - int len; - char *temp=SvPV(tempsv,len); - cvalue = &temp; - $target = cvalue; + cvalue = SvPV(tempsv,len); + $1 = &cvalue; } -%typemap(perl5,argout) char ** reterror { +%typemap(argout) char ** reterror { SV *tempsv; tempsv = SvRV($arg); - if (($source!=NULL) && (*$source!=NULL)) { - sv_setpv(tempsv, *$source); - free(*$source); + if (($1!=NULL) && (*$1!=NULL)) { + sv_setpv(tempsv, *$1); + free(*$1); + } +} + +%typemap(in) double* scaled { + double *temp; + if (!SvROK($input)) { + croak("expected a reference\n"); + } + SV* tempsv; + tempsv = SvRV($input); + if (!SvPOK(tempsv) && !SvIOK(tempsv) && !SvNOK(tempsv)) { + croak("expected a single reference to a scalar\n"); } + temp = malloc(sizeof(double)); + *temp = SvNV(tempsv); + $1 = temp; } + +%typemap(argout) double* scaled { + SV *tempsv; + tempsv = SvRV($arg); + sv_setnv(tempsv, *$1); + free($1); +} + + extern int caparesponse_capa_check_answer(char *response,char *correct, int type,int tol_type,double tolerance, int sig_lbound,int sig_ubound, char *ans_fmt, char *unit_str, int calc, char *id_list, char *pts_list, char *rndseed, char** reterror); + +extern int caparesponse_get_real_response(char* unit_str, char* answer, + double* scaled);