Update.
[pspp] / src / get.c
index ab9bb0ce78a006341ee2e56215f57fe2ca767ebc..fd9492210ab782544186749f1d26ddce7420df37 100644 (file)
--- a/src/get.c
+++ b/src/get.c
@@ -14,8 +14,8 @@
 
    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 "error.h"
@@ -212,17 +212,13 @@ cmd_save_internal (void)
       if (lex_match_id ("VERSION"))
        {
          lex_match ('=');
-         if ( lex_force_num() 
+         if (lex_force_int ()
            {
-             lex_get();
-             version = tokval;
+             version = lex_integer ();
+              lex_get ();
              
-             if ( 0 == strncasecmp (tokid,"x", 1) ) 
-               {
-                 lex_get();
-                 no_name_table = 1;
-               }
-
+             if (lex_match_id ("X")) 
+                no_name_table = 1;
            }
        }
       else if (lex_match_id ("OUTFILE"))
@@ -450,8 +446,6 @@ rename_variables (struct dictionary *dict)
       if (!lex_force_match ('=')
          || !lex_force_id ())
        return 0;
-      if (!strncmp (tokid, v->name, SHORT_NAME_LEN))
-       return 1;
       if (dict_lookup_var (dict, tokid) != NULL)
        {
          msg (SE, _("Cannot rename %s as %s because there already exists "
@@ -686,7 +680,7 @@ struct mtf_proc
     size_t by_cnt;              /* Number of variables on BY subcommand. */
 
     /* Names of FIRST, LAST variables. */
-    char first[SHORT_NAME_LEN + 1], last[SHORT_NAME_LEN + 1];
+    char first[LONG_NAME_LEN + 1], last[LONG_NAME_LEN + 1];
     
     struct dictionary *dict;    /* Dictionary of output file. */
     struct case_sink *sink;     /* Sink to receive output. */
@@ -734,7 +728,8 @@ cmd_match_files (void)
   dict_set_case_limit (mtf.dict, dict_get_case_limit (default_dict));
 
   lex_match ('/');
-  while (lex_id_match ("FILE", tokid) || lex_id_match ("TABLE", tokid)) 
+  while (token == T_ID
+         && (lex_id_match ("FILE", tokid) || lex_id_match ("TABLE", tokid)))
     {
       struct mtf_file *file = xmalloc (sizeof *file);
 
@@ -747,6 +742,7 @@ cmd_match_files (void)
         }
       else
         assert (0);
+      lex_match ('=');
 
       file->by = NULL;
       file->handle = NULL;
@@ -780,9 +776,7 @@ cmd_match_files (void)
             mtf.head = file;
           first_table->prev = file;
         }
-         
-      lex_match ('=');
-         
+
       if (lex_match ('*'))
         {
           file->handle = NULL;
@@ -963,6 +957,8 @@ cmd_match_files (void)
         }
     }
 
+  /* Set up mapping from each file's variables to master
+     variables. */
   for (iter = mtf.head; iter != NULL; iter = iter->next)
     {
       struct dictionary *d = iter->dict;
@@ -977,11 +973,10 @@ cmd_match_files (void)
         }
     }
 
+  /* Add IN variables to master dictionary. */
   for (iter = mtf.head; iter != NULL; iter = iter->next) 
     if (iter->in_name != NULL)
       {
-        static const struct fmt_spec f1_0 = {FMT_F, 1, 0};
-        
         iter->in_var = dict_create_var (mtf.dict, iter->in_name, 0);
         if (iter->in_var == NULL)
           {
@@ -990,7 +985,8 @@ cmd_match_files (void)
                  iter->in_var);
             goto error;
           }
-        iter->in_var->print = iter->in_var->write = f1_0;
+        iter->in_var->print = iter->in_var->write
+          = make_output_format (FMT_F, 1, 0);
       }
     
   /* MATCH FILES performs an n-way merge on all its input files.
@@ -1034,7 +1030,7 @@ cmd_match_files (void)
   if (mtf.sink->class->open != NULL)
     mtf.sink->class->open (mtf.sink);
 
-  mtf.seq_nums = xcalloc (dict_get_var_cnt (mtf.dict) * sizeof *mtf.seq_nums);
+  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));
 
   mtf_read_nonactive_records (&mtf);
@@ -1205,7 +1201,9 @@ mtf_processing (struct ccase *c, void *mtf_)
   bool read_active_file;
 
   assert (mtf->head != NULL);
-  assert (mtf->head->type == MTF_FILE);
+  if (mtf->head->type == MTF_TABLE)
+    return 1;
+  
   do
     {
       struct mtf_file *min_head, *min_tail; /* Files with minimum BY values. */
@@ -1404,13 +1402,14 @@ mtf_merge_dictionary (struct dictionary *const m, struct mtf_file *f)
         }
     }
   
-  dict_compact_values (d);
-
   for (i = 0; i < dict_get_var_cnt (d); i++)
     {
       struct variable *dv = dict_get_var (d, i);
       struct variable *mv = dict_lookup_var (m, dv->name);
 
+      if (dict_class_from_id (dv->name) == DC_SCRATCH)
+        continue;
+
       if (mv != NULL)
         {
           if (mv->width != dv->width) 
@@ -1437,10 +1436,7 @@ mtf_merge_dictionary (struct dictionary *const m, struct mtf_file *f)
             mv->label = xstrdup (dv->label);
         }
       else
-        {
-          mv = dict_clone_var (m, dv, dv->name, dv->longname);
-          assert (mv != NULL);
-        }
+        mv = dict_clone_var_assert (m, dv, dv->name);
     }
 
   return 1;