>From 27bd92aec32f43ecfbe57c1fb17fb5f961bb37ab Mon Sep 17 00:00:00 2001
From: Stefan Kuhn <Wuodan0@gmail.com>
Date: Tue, 25 Nov 2014 18:03:19 +0100
Subject: [PROPOSED PATCH 1/2] tzselect: Removed spaces in calls to
 awk-functions

Explanation:
GNU awk fails when a user-defined-functions is called with a space like in
'myUDF ()'. It does not fail when calling builtin functions, but removed
those spaces too.

Example code:
good_awk='function echo(x) { return x; } BEGIN { print echo("x"); }'
bad_awk_='function echo(x) { return x; } BEGIN { print echo ("x"); }'
sin_awk='BEGIN { print sin (0) }'

mawk -W version 2>/dev/null | head -n1
mawk "${sin_awk}"
mawk "${good_awk}"
mawk "${bad_awk_}"
gawk -V | head -n1
gawk "${sin_awk}"
gawk "${good_awk}"
gawk "${bad_awk_}"

Output:
mawk 1.3.4 20141027
0
x
x
GNU Awk 4.0.2
0
x
gawk: cmd. line:1: error: function `echo' called with space between name
and `(',
---
 tzselect.ksh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tzselect.ksh b/tzselect.ksh
index d5dae17..f924ca8 100644
--- a/tzselect.ksh
+++ b/tzselect.ksh
@@ -228,10 +228,10 @@ output_distances='
   # case of the Vicenty formula for distances on ellipsoids.
   function gcdist(lat1, long1, lat2, long2, dlong, x, y, num, denom) {
     dlong = long2 - long1
-    x = cos (lat2) * sin (dlong)
-    y = cos (lat1) * sin (lat2) - sin (lat1) * cos (lat2) * cos (dlong)
-    num = sqrt (x * x + y * y)
-    denom = sin (lat1) * sin (lat2) + cos (lat1) * cos (lat2) * cos (dlong)
+    x = cos(lat2) * sin(dlong)
+    y = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlong)
+    num = sqrt(x * x + y * y)
+    denom = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(dlong)
     return atan2(num, denom)
   }
   # Parallel distance between points with given latitude and longitude.
@@ -240,12 +240,12 @@ output_distances='
   # I.e., it considers longitudes to be further apart if they are
   # nearer the equator.
   function pardist(lat1, long1, lat2, long2) {
-    return abs (long1 - long2) * min (cos (lat1), cos (lat2))
+    return abs(long1 - long2) * min(cos(lat1), cos(lat2))
   }
   # The distance function is the sum of the great-circle distance and
   # the parallel distance.  It could be weighted.
   function dist(lat1, long1, lat2, long2) {
-    return gcdist (lat1, long1, lat2, long2) + pardist (lat1, long1, lat2, long2)
+    return gcdist(lat1, long1, lat2, long2) + pardist(lat1, long1, lat2, long2)
   }
   BEGIN {
     coord_lat = convert_latitude(coord)
-- 
1.9.3

