aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/eglibc/eglibc-2.17/tzselect-sh.patch
blob: e9a3691bbb4b76daad54ef8f6e6842f0f2bf75cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
tzselect: eliminate ksh-dependency

This is an adapted version of a patch originally
by Peter Seebach <peter.seebach@windriver.com> found here:
http://www.eglibc.org/archives/patches/msg00671.html

Upstream-Status: Pending

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>

Index: libc/timezone/tzselect.ksh
===================================================================
--- libc.orig/timezone/tzselect.ksh	2012-11-17 09:50:14.000000000 -0800
+++ libc/timezone/tzselect.ksh	2013-01-03 22:46:26.423844259 -0800
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 PKGVERSION='(tzcode) '
 TZVERSION=see_Makefile
@@ -11,23 +11,80 @@
 
 # Porting notes:
 #
-# This script requires a Posix-like shell with the extension of a
-# 'select' statement.  The 'select' statement was introduced in the
-# Korn shell and is available in Bash and other shell implementations.
-# If your host lacks both Bash and the Korn shell, you can get their
-# source from one of these locations:
+# func_select allows this script to run on shells (such as busybox ash)
+# which lack the ksh "select" builtin.
 #
-#	Bash <http://www.gnu.org/software/bash/bash.html>
-#	Korn Shell <http://www.kornshell.com/>
-#	Public Domain Korn Shell <http://www.cs.mun.ca/~michael/pdksh/>
-#
-# This script also uses several features of modern awk programs.
+# This script uses several features of modern awk programs.
 # If your host lacks awk, or has an old awk that does not conform to Posix,
 # you can use either of the following free programs instead:
 #
 #	Gawk (GNU awk) <http://www.gnu.org/software/gawk/>
 #	mawk <http://invisible-island.net/mawk/>
 
+# Implement ksh-style select in POSIX shell
+
+# We need a mostly-portable echo-n.
+case `echo -n "foo\c"` in
+*n*c*)  func_echo_n() { echo "$*"; } ;;
+*n*)    func_echo_n() { echo "$*\c"; } ;;
+*)      func_echo_n() { echo -n "$*"; } ;;
+esac
+
+# Synopsis: Replace "select foo in list" with "while func_select foo in list"
+# and this works just like ksh, so far as I know.
+func_select () {
+	func_select_args=0
+	if expr "$1" : "[_a-zA-Z][_a-zA-Z0-9]*$" > /dev/null; then
+		func_select_var=$1
+	else
+		echo >&2 "func_select: '$1' is not a valid variable name."
+		return 1
+	fi
+	shift 1
+	case $1 in
+		in) shift 1;;
+ *) echo >&2 "func_select: usage: func_select var in ... (you must provide
+arguments)"; return 1;;
+	esac
+	case $# in
+		0) echo >&2 "func_select: usage: func_select var in ..."; return 1;;
+	esac
+	for func_select_arg
+	do
+		func_select_args=`expr $func_select_args + 1`
+		eval func_select_a_$func_select_args=\$func_select_arg
+	done
+	REPLY=""
+	while :
+	do
+		if test -z "$REPLY"; then
+			func_select_i=1
+			while test $func_select_i -le $func_select_args
+			do
+				eval echo "\"\$func_select_i) \$func_select_a_$func_select_i\""
+				func_select_i=`expr $func_select_i + 1`
+			done
+		fi
+		func_echo_n "${PS3-#? }" >&2
+		if read REPLY; then
+			if test -n "${REPLY}"; then
+				if expr "$REPLY" : '[1-9][0-9]*$' > /dev/null; then
+					if test "$REPLY" -ge 1 && test "$REPLY" -le $func_select_args; then
+						eval $func_select_var=\$func_select_a_$REPLY
+					else
+						eval $func_select_var=
+					fi
+				else
+					eval $func_select_var=
+				fi
+				return 0
+			fi
+		else
+			eval $func_select_var=
+			return 1
+		fi
+	done
+}
 
 # Specify default values for environment variables if they are unset.
 : ${AWK=awk}
@@ -72,7 +129,7 @@
 
 
 # Work around a bug in bash 1.14.7 and earlier, where $PS3 is sent to stdout.
-case $(echo 1 | (select x in x; do break; done) 2>/dev/null) in
+case $(echo 1 | (while func_select x in x; do break; done) 2>/dev/null) in
 ?*) PS3=
 esac
 
@@ -92,7 +149,7 @@
 
 	echo >&2 'Please select a continent or ocean.'
 
-	select continent in \
+	while func_select continent in \
 	    Africa \
 	    Americas \
 	    Antarctica \
@@ -172,7 +229,7 @@
 		case $countries in
 		*"$newline"*)
 			echo >&2 'Please select a country.'
-			select country in $countries
+			while func_select country in $countries
 			do
 			    case $country in
 			    '') echo >&2 'Please enter a number in range.';;
@@ -211,7 +268,7 @@
 		*"$newline"*)
 			echo >&2 'Please select one of the following' \
 				'time zone regions.'
-			select region in $regions
+			while func_select region in $regions
 			do
 				case $region in
 				'') echo >&2 'Please enter a number in range.';;
@@ -288,7 +345,7 @@
 	echo >&2 "Is the above information OK?"
 
 	ok=
-	select ok in Yes No
+	while func_select ok in Yes No
 	do
 	    case $ok in
 	    '') echo >&2 'Please enter 1 for Yes, or 2 for No.';;