Add scratch file handles.
[pspp-builds.git] / src / apply-dict.c
index 4cc8c10379644585db7b33f358854e9d6be59c05..ccfecb9eea5be63ef5617b09c52fcf3dac0d1da9 100644 (file)
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include <stdlib.h>
+#include "any-reader.h"
 #include "command.h"
 #include "dictionary.h"
 #include "error.h"
 #include "file-handle.h"
 #include "hash.h"
 #include "lexer.h"
-#include "sfm-read.h"
 #include "str.h"
 #include "value-labels.h"
 #include "var.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 #include "debug-print.h"
 
 /* Parses and executes APPLY DICTIONARY. */
@@ -37,7 +40,7 @@ int
 cmd_apply_dictionary (void)
 {
   struct file_handle *handle;
-  struct sfm_reader *reader;
+  struct any_reader *reader;
   struct dictionary *dict;
 
   int n_matched = 0;
@@ -46,14 +49,14 @@ cmd_apply_dictionary (void)
   
   lex_match_id ("FROM");
   lex_match ('=');
-  handle = fh_parse ();
+  handle = fh_parse (FH_REF_FILE | FH_REF_SCRATCH);
   if (!handle)
     return CMD_FAILURE;
 
-  reader = sfm_open_reader (handle, &dict, NULL);
+  reader = any_reader_open (handle, &dict);
   if (dict == NULL)
     return CMD_FAILURE;
-  sfm_close_reader (reader);
+  any_reader_close (reader);
 
   for (i = 0; i < dict_get_var_cnt (dict); i++)
     {
@@ -126,31 +129,18 @@ cmd_apply_dictionary (void)
             }
        }
 
-      if (s->miss_type != MISSING_NONE && t->width > MAX_SHORT_STRING)
+      if (!mv_is_empty (&s->miss) && t->width > MAX_SHORT_STRING)
        msg (SW, _("Cannot apply missing values from source file to "
                   "long string variable %s."),
             s->name);
-      else if (s->miss_type != MISSING_NONE)
+      else if (!mv_is_empty (&s->miss))
        {
-         if (t->width < s->width)
-           {
-             static const int miss_count[MISSING_COUNT] = 
-               {
-                 0, 1, 2, 3, 2, 1, 1, 3, 2, 2,
-               };
-
-             int j, k;
-             
-             for (j = 0; j < miss_count[s->miss_type]; j++)
-               for (k = t->width; k < s->width; k++)
-                 if (s->missing[j].s[k] != ' ')
-                   goto skip_missing_values;
-           }
-
-         t->miss_type = s->miss_type;
-         memcpy (t->missing, s->missing, sizeof s->missing);
+          if (mv_is_resizable (&s->miss, t->width)) 
+            {
+              mv_copy (&t->miss, &s->miss);
+              mv_resize (&t->miss, t->width); 
+            }
        }
-    skip_missing_values: ;
 
       if (s->type == NUMERIC)
        {
@@ -173,7 +163,7 @@ cmd_apply_dictionary (void)
         dict_set_weight (default_dict, new_weight);
     }
   
-  sfm_close_reader (reader);
+  any_reader_close (reader);
 
   return lex_end_of_command ();
 }