Added new files resulting from directory restructuring.
[pspp-builds.git] / src / expressions / parse.c
index a7064e034c8728b05e3b1264367e7a8075379fe0..fcfd8ef3fb44a7d36ccc028f381feb53766b155f 100644 (file)
@@ -86,6 +86,19 @@ expr_parse (struct dictionary *dict, enum expr_type type)
     }
 }
 
+/* Parses and returns an expression of the given TYPE, as
+   expr_parse(), and sets up so that destroying POOL will free
+   the expression as well. */
+struct expression *
+expr_parse_pool (struct pool *pool,
+                 struct dictionary *dict, enum expr_type type) 
+{
+  struct expression *e = expr_parse (dict, type);
+  if (e != NULL)
+    pool_add_subpool (pool, e->expr_pool);
+  return e;
+}
+
 /* Free expression E. */
 void
 expr_free (struct expression *e)
@@ -718,6 +731,7 @@ parse_sysvar (struct expression *e)
           "JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
         };
 
+      time_t last_vfm_invocation = vfm_last_invocation ();
       struct tm *time;
       char temp_buf[10];
 
@@ -735,21 +749,23 @@ parse_sysvar (struct expression *e)
     return expr_allocate_number (e, SYSMIS);
   else if (lex_match_id ("$JDATE"))
     {
-      struct tm *time = localtime (&last_vfm_invocation);
-      return expr_allocate_number (e, expr_ymd_to_ofs (time->tm_year + 1900,
-                                                       time->tm_mon + 1,
-                                                       time->tm_mday));
+      time_t time = vfm_last_invocation ();
+      struct tm *tm = localtime (&time);
+      return expr_allocate_number (e, expr_ymd_to_ofs (tm->tm_year + 1900,
+                                                       tm->tm_mon + 1,
+                                                       tm->tm_mday));
     }
   else if (lex_match_id ("$TIME"))
     {
-      struct tm *time = localtime (&last_vfm_invocation);
+      time_t time = vfm_last_invocation ();
+      struct tm *tm = localtime (&time);
       return expr_allocate_number (e,
-                                   expr_ymd_to_date (time->tm_year + 1900,
-                                                     time->tm_mon + 1,
-                                                     time->tm_mday)
-                                   + time->tm_hour * 60 * 60.
-                                   + time->tm_min * 60.
-                                   + time->tm_sec);
+                                   expr_ymd_to_date (tm->tm_year + 1900,
+                                                     tm->tm_mon + 1,
+                                                     tm->tm_mday)
+                                   + tm->tm_hour * 60 * 60.
+                                   + tm->tm_min * 60.
+                                   + tm->tm_sec);
     }
   else if (lex_match_id ("$LENGTH"))
     return expr_allocate_number (e, get_viewlength ());
@@ -1033,7 +1049,7 @@ validate_function_args (const struct operation *f, int arg_cnt, int min_valid)
         {
           assert ((f->flags & OPF_MIN_VALID) == 0);
           msg (SE, _("%s function does not accept a minimum valid "
-                     "argument count."));
+                     "argument count."), f->prototype);
           return false;
         }
       else 
@@ -1042,7 +1058,7 @@ validate_function_args (const struct operation *f, int arg_cnt, int min_valid)
           if (array_arg_cnt < f->array_min_elems)
             {
               msg (SE, _("%s requires at least %d valid arguments in list."),
-                   f->prototype);
+                   f->prototype, f->array_min_elems);
               return false;
             }
           else if (min_valid > array_arg_cnt) 
@@ -1158,8 +1174,8 @@ parse_function (struct expression *e)
         if (token == T_ID && lex_look_ahead () == 'T')
           {
             struct variable **vars;
-            int var_cnt;
-            int i;
+            size_t var_cnt;
+            size_t i;
 
             if (!parse_variables (default_dict, &vars, &var_cnt, PV_SINGLE))
               goto fail;