Merge branch 'master' of /home/john/Development/pspp-bare
[pspp-builds.git] / perl-module / PSPP.xs
index 254b668c0ae6bf7de323d29b9c98a88932fffa08..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;
 };
 
 
@@ -148,14 +151,17 @@ make_value_from_scalar (SV *val, const struct variable *var)
 
 MODULE = PSPP
 
-BOOT:
+MODULE = PSPP          PACKAGE = PSPP
+
+void
+onBoot (ver)
+ const char *ver
+CODE:
+ assert (0 == strcmp (ver, bare_version));
  msg_init (NULL, message_handler);
  settings_init (0, 0);
  fh_init ();
 
-
-MODULE = PSPP          PACKAGE = PSPP
-
 SV *
 format_value (val, var)
  SV *val
@@ -270,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
 
 
@@ -451,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))
   {
@@ -479,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:
@@ -497,6 +524,7 @@ DESTROY (sfi)
  struct sysfile_info *sfi
 CODE:
  sysfile_close (sfi);
+ SvREFCNT_dec (sfi->dict_sv);
  free (sfi);
 
 int
@@ -563,7 +591,7 @@ CODE:
  }
  RETVAL = casewriter_write (sfi->writer, &c);
  finish:
-// Case_destroy (&c);
+// case_destroy (&c);
  free (vv);
 OUTPUT:
  RETVAL
@@ -634,4 +662,3 @@ CODE:
 OUTPUT:
  RETVAL
 
-