Added most of the calculations for the ONEWAY command.
[pspp-builds.git] / src / inpt-pgm.c
index dc08f346a9704b7d4dc60f593aa40f1195f5a417..0cbf66f325569d54b828c98eac639c2124ac029b 100644 (file)
    02111-1307, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "error.h"
 #include <float.h>
 #include <stdlib.h>
 #include "alloc.h"
+#include "case.h"
 #include "command.h"
 #include "data-list.h"
 #include "dfm.h"
@@ -59,8 +60,6 @@ static trns_free_func reread_trns_free;
 int
 cmd_input_program (void)
 {
-  lex_match_id ("INPUT");
-  lex_match_id ("PROGRAM");
   discard_variables ();
 
   /* FIXME: we shouldn't do this here, but I'm afraid that other
@@ -77,10 +76,6 @@ cmd_end_input_program (void)
   struct input_program_pgm *inp;
   size_t i;
 
-  lex_match_id ("END");
-  lex_match_id ("INPUT");
-  lex_match_id ("PROGRAM");
-
   if (!case_source_is_class (vfm_source, &input_program_source_class))
     {
       msg (SE, _("No matching INPUT PROGRAM command."));
@@ -136,14 +131,14 @@ init_case (const struct input_program_pgm *inp, struct ccase *c)
     switch (inp->init[i]) 
       {
       case INP_NUMERIC | INP_INIT_ONCE:
-        c->data[i].f = 0.0;
+        case_data_rw (c, i)->f = 0.0;
         break;
       case INP_NUMERIC | INP_REINIT:
-        c->data[i].f = SYSMIS;
+        case_data_rw (c, i)->f = SYSMIS;
         break;
       case INP_STRING | INP_INIT_ONCE:
       case INP_STRING | INP_REINIT:
-        memset (c->data[i].s, ' ', sizeof c->data[i].s);
+        memset (case_data_rw (c, i)->s, ' ', sizeof case_data_rw (c, i)->s);
         break;
       default:
         assert (0);
@@ -162,12 +157,12 @@ clear_case (const struct input_program_pgm *inp, struct ccase *c)
       case INP_NUMERIC | INP_INIT_ONCE:
         break;
       case INP_NUMERIC | INP_REINIT:
-        c->data[i].f = SYSMIS;
+        case_data_rw (c, i)->f = SYSMIS;
         break;
       case INP_STRING | INP_INIT_ONCE:
         break;
       case INP_STRING | INP_REINIT:
-        memset (c->data[i].s, ' ', sizeof c->data[i].s);
+        memset (case_data_rw (c, i)->s, ' ', sizeof case_data_rw (c, i)->s);
         break;
       default:
         assert (0);
@@ -287,9 +282,6 @@ cmd_end_case (void)
 {
   struct trns_header *t;
 
-  lex_match_id ("END");
-  lex_match_id ("CASE");
-
   if (!case_source_is_class (vfm_source, &input_program_source_class))
     {
       msg (SE, _("This command may only be executed between INPUT PROGRAM "
@@ -312,6 +304,7 @@ end_case_trns_proc (struct trns_header *t UNUSED, struct ccase * c UNUSED,
                     int case_num UNUSED)
 {
   assert (0);
+  abort ();
 }
 
 /* REREAD transformation. */
@@ -336,8 +329,6 @@ cmd_reread (void)
   /* Created transformation. */
   struct reread_trns *t;
 
-  lex_match_id ("REREAD");
-
   h = default_handle;
   e = NULL;
   while (token != '.')
@@ -353,21 +344,15 @@ cmd_reread (void)
              return CMD_FAILURE;
            }
          
-         e = expr_parse (PXP_NUMERIC);
+         e = expr_parse (EXPR_NUMERIC);
          if (!e)
            return CMD_FAILURE;
        }
       else if (lex_match_id ("FILE"))
        {
          lex_match ('=');
-         if (token != T_ID)
-           {
-             lex_error (_("expecting file handle name"));
-             expr_free (e);
-             return CMD_FAILURE;
-           }
-         h = fh_get_handle_by_name (tokid);
-         if (!h)
+          h = fh_parse_file_handle ();
+         if (h == NULL)
            {
              expr_free (e);
              return CMD_FAILURE;
@@ -399,7 +384,7 @@ reread_trns_proc (struct trns_header * pt, struct ccase * c,
   struct reread_trns *t = (struct reread_trns *) pt;
 
   if (t->column == NULL)
-    dfm_bkwd_record (t->handle, 1);
+    dfm_reread_record (t->handle, 1);
   else
     {
       union value column;
@@ -409,10 +394,10 @@ reread_trns_proc (struct trns_header * pt, struct ccase * c,
        {
          msg (SE, _("REREAD: Column numbers must be positive finite "
               "numbers.  Column set to 1."));
-         dfm_bkwd_record (t->handle, 1);
+         dfm_reread_record (t->handle, 1);
        }
       else
-       dfm_bkwd_record (t->handle, column.f);
+       dfm_reread_record (t->handle, column.f);
     }
   return -1;
 }
@@ -430,9 +415,6 @@ cmd_end_file (void)
 {
   struct trns_header *t;
 
-  lex_match_id ("END");
-  lex_match_id ("FILE");
-
   if (!case_source_is_class (vfm_source, &input_program_source_class))
     {
       msg (SE, _("This command may only be executed between INPUT PROGRAM "