Abstract the documents within a dictionary a little better. Thanks to
[pspp-builds.git] / src / language / data-io / get.c
index 8b03ec95f809322e88edff3a47bd1a0d6ba7465f..32b3764ea6f98829c6fe19585dea4e0ea6e52afe 100644 (file)
@@ -137,7 +137,7 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command
     goto error;
 
   case_create (&pgm->bounce, dict_get_next_value_idx (dict));
-  
+
   start_case_map (dict);
 
   while (lex_token (lexer) != '.')
@@ -148,11 +148,10 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command
     }
 
   pgm->map = finish_case_map (dict);
-  
-  dict_destroy (dataset_dict (ds));
+
   dataset_set_dict (ds, dict);
 
-  proc_set_source (ds, 
+  proc_set_source (ds,
                   create_case_source (&case_reader_source_class, pgm));
 
   return CMD_SUCCESS;
@@ -747,7 +746,7 @@ struct mtf_file
     struct mtf_file *next_min; /* Next in the chain of minimums. */
     
     int type;                  /* One of MTF_*. */
-    struct variable **by;      /* List of BY variables for this file. */
+    const struct variable **by;        /* List of BY variables for this file. */
     struct file_handle *handle; /* File handle. */
     struct any_reader *reader;  /* File reader. */
     struct dictionary *dict;   /* Dictionary from system file. */
@@ -944,7 +943,7 @@ cmd_match_files (struct lexer *lexer, struct dataset *ds)
     {
       if (lex_match (lexer, T_BY))
        {
-          struct variable **by;
+          const struct variable **by;
           
          if (mtf.by_cnt)
            {
@@ -953,7 +952,7 @@ cmd_match_files (struct lexer *lexer, struct dataset *ds)
            }
              
          lex_match (lexer, '=');
-         if (!parse_variables (lexer, mtf.dict, &by, &mtf.by_cnt,
+         if (!parse_variables_const (lexer, mtf.dict, &by, &mtf.by_cnt,
                                PV_NO_DUPLICATE | PV_NO_SCRATCH))
            goto error;
 
@@ -1111,14 +1110,19 @@ cmd_match_files (struct lexer *lexer, struct dataset *ds)
   if (used_active_file) 
     {
       proc_set_sink (ds, create_case_sink (&null_sink_class, 
-                                           dataset_dict (ds), NULL));
+                                           dataset_dict (ds),
+                                          dataset_get_casefile_factory (ds),
+                                          NULL));
       proc_open (ds); 
     }
   else
     discard_variables (ds);
 
   dict_compact_values (mtf.dict);
-  mtf.output = fastfile_create (dict_get_next_value_idx (mtf.dict));
+  mtf.output = dataset_get_casefile_factory (ds)->create_casefile
+    (dataset_get_casefile_factory (ds),
+     dict_get_next_value_idx (mtf.dict));
+
   mtf.seq_nums = xcalloc (dict_get_var_cnt (mtf.dict), sizeof *mtf.seq_nums);
   case_create (&mtf.mtf_case, dict_get_next_value_idx (mtf.dict));
 
@@ -1132,14 +1136,13 @@ cmd_match_files (struct lexer *lexer, struct dataset *ds)
 
   discard_variables (ds);
 
-  dict_destroy (dataset_dict (ds));
   dataset_set_dict (ds, mtf.dict);
   mtf.dict = NULL;
   proc_set_source (ds, storage_source_create (mtf.output));
   mtf.output = NULL;
-  
+
   return mtf_free (&mtf) ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
-  
+
  error:
   proc_close (ds);
   mtf_free (&mtf);
@@ -1452,13 +1455,7 @@ mtf_merge_dictionary (struct dictionary *const m, struct mtf_file *f)
         dict_set_documents (m, d_docs);
       else
         {
-          char *new_docs;
-          size_t new_len;
-
-          new_len = strlen (m_docs) + strlen (d_docs);
-          new_docs = xmalloc (new_len + 1);
-          strcpy (new_docs, m_docs);
-          strcat (new_docs, d_docs);
+          char *new_docs = xasprintf ("%s%s", m_docs, d_docs);
           dict_set_documents (m, new_docs);
           free (new_docs);
         }