Check the return value of various calls to lex_force_match.
[pspp] / src / language / expressions / operations.def
index 471fa1d30d331c4cb6e924b6c6822dcbe4570bde..e8f1f781dc29d3bbc0042e55cce0fec3f81f5c1c 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c -*-
 //
 // PSPP - a program for statistical analysis.
-// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012, 2015 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012, 2015, 2016 Free Software Foundation, Inc.
 // 
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -90,7 +90,9 @@ function RND (x, mult != 0, fuzzbits >= 0) = round_nearest (x, mult, fuzzbits);
 function SIN (x) = sin (x);
 function SQRT (x >= 0) = sqrt (x);
 function TAN (x) = check_errno (tan (x));
-function TRUNC (x) = x >= 0. ? floor (x) : -floor (-x);
+function TRUNC (x) = round_zero (x, 1, 0);
+function TRUNC (x, mult != 0) = round_zero (x, mult, 0);
+function TRUNC (x, mult != 0, fuzzbits >= 0) = round_zero (x, mult, fuzzbits);
 
 absorb_miss function MOD (n, d)
 {
@@ -168,6 +170,11 @@ function MEAN.1 (a[n])
   return mean;
 }
 
+function MEDIAN.1 (a[n])
+{
+  return median (a, n);
+}
+
 function MIN.1 (a[n])
 {
   double min;
@@ -399,7 +406,6 @@ function INDEX (string haystack, string needles, needle_len_d)
     }
 }
 
-
 function RINDEX (string haystack, string needle)
 {
   if (needle.length == 0)
@@ -504,6 +510,15 @@ absorb_miss string function LPAD (string s, n, string c)
     }
 }
 
+string function REPLACE (string haystack, string needle, string replacement)
+    expression e;
+  = replace_string (e, haystack, needle, replacement, DBL_MAX);
+
+absorb_miss string function REPLACE (string haystack, string needle,
+                                     string replacement, n)
+    expression e;
+  = replace_string (e, haystack, needle, replacement, n);
+
 absorb_miss string function RPAD (string s, n)
      expression e;
 {
@@ -616,6 +631,18 @@ absorb_miss string function STRING (x, no_format f)
   return dst;
 }
 
+absorb_miss string function STRUNC (string s, n)
+{
+  if (n < 1 || n == SYSMIS)
+    return empty_string;
+
+  if (n < s.length)
+    s.length = n;
+  while (s.length > 0 && s.string[s.length - 1] == ' ')
+    s.length--;
+  return s;
+}
+
 absorb_miss string function SUBSTR (string s, ofs)
      expression e;
 {