Merge branch 'master' of /home/john/Development/pspp-bare
[pspp-builds.git] / perl-module / PSPP.xs
index de5cbf7b0a8eef5be89c3f08244d4a7494436c24..7bb36ef3bc7468bd419a8ce2681ea00ba064baf9 100644 (file)
@@ -55,6 +55,9 @@ struct sysfile_info
 
   /* A pointer to the dictionary. Owned externally */
   const struct dictionary *dict;
+
+  /* The scalar containing the dictionary */
+  SV *dict_sv;
 };
 
 
@@ -273,6 +276,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
 
 
@@ -454,11 +474,13 @@ MODULE = PSPP             PACKAGE = PSPP::Sysfile
 
 
 struct sysfile_info *
-pxs_create_sysfile (name, dict, opts_hr)
+pxs_create_sysfile (name, dict_ref, opts_hr)
  char *name
- struct dictionary *dict
+ SV *dict_ref
  SV *opts_hr
 INIT:
+ SV *dict_sv = SvRV (dict_ref);
+ struct dictionary *dict = (void *) SvIV (dict_sv);
  struct sfm_write_options opts;
  if (!SvROK (opts_hr))
   {
@@ -482,6 +504,8 @@ CODE:
  sfi->writer = sfm_open_writer (fh, dict, opts);
  sfi->dict = dict;
  sfi->opened = true;
+ sfi->dict_sv = dict_sv;
+ SvREFCNT_inc (sfi->dict_sv);
  
  RETVAL = sfi;
  OUTPUT:
@@ -500,6 +524,7 @@ DESTROY (sfi)
  struct sysfile_info *sfi
 CODE:
  sysfile_close (sfi);
+ SvREFCNT_dec (sfi->dict_sv);
  free (sfi);
 
 int