From: John Darrington Date: Thu, 25 Dec 2008 03:16:35 +0000 (+0900) Subject: New subroutine PSPP::Dict::get_var_by_name X-Git-Tag: v0.7.1~1^2~14 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8e182acade7dc6f008d79221f1274fa1e3003dc;p=pspp-builds.git New subroutine PSPP::Dict::get_var_by_name --- diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index de5cbf7b..3b3dccef 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -273,6 +273,23 @@ CODE: OUTPUT: RETVAL + +struct variable * +pxs_get_var_by_name (dict, name) + struct dictionary *dict + const char *name +INIT: + SV *errstr = get_sv("PSPP::errstr", TRUE); + sv_setpv (errstr, ""); +CODE: + struct variable *var = dict_lookup_var (dict, name); + if ( ! var ) + sv_setpv (errstr, "No such variable."); + RETVAL = var; + OUTPUT: +RETVAL + + MODULE = PSPP PACKAGE = PSPP::Var diff --git a/perl-module/lib/PSPP.pm b/perl-module/lib/PSPP.pm index a000b011..6fbae803 100644 --- a/perl-module/lib/PSPP.pm +++ b/perl-module/lib/PSPP.pm @@ -106,6 +106,28 @@ sub get_var return $var; } +=pod + +=head3 get_var_by_name ($name) + +Returns the variable from the dictionary whose name is C. +If there is no such variable, a null reference will be returned. + +=cut + +sub get_var_by_name +{ + my $dict = shift; + my $name = shift; + my $var = pxs_get_var_by_name ($dict, $name); + + if ( ref $var ) + { + bless ($var, "PSPP::Var"); + } + return $var; +} + package PSPP::Fmt;