Reform string library.
[pspp-builds.git] / src / language / expressions / parse.c
index f2bc3254224f258a51a938c879df0b2d03a72051..f220509aaabb039cb0eaa847e6895bf69f08f902 100644 (file)
@@ -35,7 +35,6 @@
 #include <data/settings.h>
 #include <libpspp/str.h>
 #include <data/variable.h>
-#include <procedure.h>
 \f
 /* Declarations. */
 
@@ -830,8 +829,8 @@ parse_primary (struct expression *e)
 
     case T_STRING:
       {
-        union any_node *node = expr_allocate_string_buffer (e, ds_c_str (&tokstr),
-                                                       ds_length (&tokstr));
+        union any_node *node = expr_allocate_string_buffer (
+          e, ds_cstr (&tokstr), ds_length (&tokstr));
        lex_get ();
        return node;
       }
@@ -1095,14 +1094,14 @@ put_invocation (struct string *s,
 {
   size_t i;
 
-  ds_printf (s, "%s(", func_name);
+  ds_put_format (s, "%s(", func_name);
   for (i = 0; i < arg_cnt; i++)
     {
       if (i > 0)
-        ds_puts (s, ", ");
-      ds_puts (s, operations[expr_node_returns (args[i])].prototype);
+        ds_put_cstr (s, ", ");
+      ds_put_cstr (s, operations[expr_node_returns (args[i])].prototype);
     }
-  ds_putc (s, ')');
+  ds_put_char (s, ')');
 }
 
 static void
@@ -1113,25 +1112,25 @@ no_match (const char *func_name,
   struct string s;
   const struct operation *f;
 
-  ds_init (&s, 128);
+  ds_init_empty (&s);
 
   if (last - first == 1) 
     {
-      ds_printf (&s, _("Type mismatch invoking %s as "), first->prototype);
+      ds_put_format (&s, _("Type mismatch invoking %s as "), first->prototype);
       put_invocation (&s, func_name, args, arg_cnt);
     }
   else 
     {
-      ds_puts (&s, _("Function invocation "));
+      ds_put_cstr (&s, _("Function invocation "));
       put_invocation (&s, func_name, args, arg_cnt);
-      ds_puts (&s, _(" does not match any known function.  Candidates are:"));
+      ds_put_cstr (&s, _(" does not match any known function.  Candidates are:"));
 
       for (f = first; f < last; f++)
-        ds_printf (&s, "\n%s", f->prototype);
+        ds_put_format (&s, "\n%s", f->prototype);
     }
-  ds_putc (&s, '.');
+  ds_put_char (&s, '.');
 
-  msg (SE, "%s", ds_c_str (&s));
+  msg (SE, "%s", ds_cstr (&s));
     
   ds_destroy (&s);
 }
@@ -1146,23 +1145,23 @@ parse_function (struct expression *e)
   int arg_cnt = 0;
   int arg_cap = 0;
 
-  struct fixed_string func_name;
+  struct string func_name;
 
   union any_node *n;
 
-  ls_create (&func_name, ds_c_str (&tokstr));
-  min_valid = extract_min_valid (ds_c_str (&tokstr));
-  if (!lookup_function (ds_c_str (&tokstr), &first, &last)) 
+  ds_init_string (&func_name, &tokstr);
+  min_valid = extract_min_valid (ds_cstr (&tokstr));
+  if (!lookup_function (ds_cstr (&tokstr), &first, &last)) 
     {
-      msg (SE, _("No function or vector named %s."), ds_c_str (&tokstr));
-      ls_destroy (&func_name);
+      msg (SE, _("No function or vector named %s."), ds_cstr (&tokstr));
+      ds_destroy (&func_name);
       return NULL;
     }
 
   lex_get ();
   if (!lex_force_match ('(')) 
     {
-      ls_destroy (&func_name);
+      ds_destroy (&func_name);
       return NULL; 
     }
   
@@ -1207,7 +1206,7 @@ parse_function (struct expression *e)
       break;
   if (f >= last) 
     {
-      no_match (ls_c_str (&func_name), args, arg_cnt, first, last);
+      no_match (ds_cstr (&func_name), args, arg_cnt, first, last);
       goto fail;
     }
 
@@ -1222,6 +1221,11 @@ parse_function (struct expression *e)
       msg (SE, _("%s is not yet implemented."), f->prototype);
       goto fail;
     }
+  if ((f->flags & OPF_PERM_ONLY) && proc_in_temporary_transformations ()) 
+    {
+      msg (SE, _("%s may not appear after TEMPORARY."), f->prototype);
+      goto fail;
+    }
   
   n = expr_allocate_composite (e, f - operations, args, arg_cnt);
   n->composite.min_valid = min_valid != -1 ? min_valid : f->array_min_elems; 
@@ -1242,12 +1246,12 @@ parse_function (struct expression *e)
     }
   
   free (args);
-  ls_destroy (&func_name);
+  ds_destroy (&func_name);
   return n;
 
 fail:
   free (args);
-  ls_destroy (&func_name);
+  ds_destroy (&func_name);
   return NULL;
 }
 \f
@@ -1417,14 +1421,14 @@ expr_allocate_string_buffer (struct expression *e,
 {
   union any_node *n = pool_alloc (e->expr_pool, sizeof n->string);
   n->type = OP_string;
-  if (length > 255)
-    length = 255;
+  if (length > MAX_STRING)
+    length = MAX_STRING;
   n->string.s = copy_string (e, string, length);
   return n;
 }
 
 union any_node *
-expr_allocate_string (struct expression *e, struct fixed_string s)
+expr_allocate_string (struct expression *e, struct substring s)
 {
   union any_node *n = pool_alloc (e->expr_pool, sizeof n->string);
   n->type = OP_string;