lexer: Reimplement for better testability and internationalization.
[pspp-builds.git] / src / data / procedure.c
index c79e784e8b70f4d7ced4cabf5414cd76d8baca8c..a45f497afd1268012a77064a5d49b33839c974f8 100644 (file)
@@ -101,6 +101,8 @@ struct dataset {
   void (*callback) (void *); /* Callback for when the dataset changes */
   void *cb_data;
 
+  /* Default encoding for reading syntax files. */
+  char *syntax_encoding;
 }; /* struct dataset */
 
 
@@ -125,6 +127,18 @@ dataset_set_callback (struct dataset *ds, void (*cb) (void *), void *cb_data)
   ds->cb_data = cb_data;
 }
 
+void
+dataset_set_default_syntax_encoding (struct dataset *ds, const char *encoding)
+{
+  free (ds->syntax_encoding);
+  ds->syntax_encoding = xstrdup (encoding);
+}
+
+const char *
+dataset_get_default_syntax_encoding (const struct dataset *ds)
+{
+  return ds->syntax_encoding;
+}
 
 /* Returns the last time the data was read. */
 time_t
@@ -163,10 +177,14 @@ proc_execute (struct dataset *ds)
 
 static const struct casereader_class proc_casereader_class;
 
-/* Opens dataset DS for reading cases with proc_read.
+/* Opens dataset DS for reading cases with proc_read.  If FILTER is true, then
+   cases filtered out with FILTER BY will not be included in the casereader
+   (which is usually desirable).  If FILTER is false, all cases will be
+   included regardless of FILTER BY settings.
+
    proc_commit must be called when done. */
 struct casereader *
-proc_open (struct dataset *ds)
+proc_open_filtering (struct dataset *ds, bool filter)
 {
   struct casereader *reader;
 
@@ -179,7 +197,8 @@ proc_open (struct dataset *ds)
 
   /* Finish up the collection of transformations. */
   add_case_limit_trns (ds);
-  add_filter_trns (ds);
+  if (filter)
+    add_filter_trns (ds);
   trns_chain_finalize (ds->cur_trns_chain);
 
   /* Make permanent_dict refer to the dictionary right before
@@ -237,6 +256,14 @@ proc_open (struct dataset *ds)
   return reader;
 }
 
+/* Opens dataset DS for reading cases with proc_read.
+   proc_commit must be called when done. */
+struct casereader *
+proc_open (struct dataset *ds)
+{
+  return proc_open_filtering (ds, true);
+}
+
 /* Returns true if a procedure is in progress, that is, if
    proc_open has been called but proc_commit has not. */
 bool
@@ -584,6 +611,9 @@ create_dataset (void)
 
   ds->caseinit = caseinit_create ();
   proc_cancel_all_transformations (ds);
+
+  ds->syntax_encoding = xstrdup ("Auto");
+
   return ds;
 }
 
@@ -608,6 +638,8 @@ destroy_dataset (struct dataset *ds)
 
   if ( ds->xform_callback)
     ds->xform_callback (false, ds->xform_callback_aux);
+
+  free (ds->syntax_encoding);
   free (ds);
 }