aboutsummaryrefslogtreecommitdiff
blob: 25d5338789e06ea209e8acd1c8399cb2215e5f0a (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
'read -t' support, forward-ported from Gentoo Busybox 1.1.3.
Used during the LiveCD boot when prompting for a keymap.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>

diff -Nuar --exclude '*.orig' busybox-1.7.4/shell/ash.c busybox-1.7.4+gentoo/shell/ash.c
--- busybox-1.7.4/shell/ash.c	2007-11-03 16:06:35.000000000 -0700
+++ busybox-1.7.4+gentoo/shell/ash.c	2008-03-11 10:21:28.000000000 -0700
@@ -11485,11 +11485,13 @@
 	int startword;
 	int status;
 	int i;
+#if ENABLE_ASH_READ_NCHARS || ENABLE_ASH_READ_TIMEOUT
+	struct termios tty, old_tty;
+#endif
 #if ENABLE_ASH_READ_NCHARS
 	int nch_flag = 0;
 	int nchars = 0;
 	int silent = 0;
-	struct termios tty, old_tty;
 #endif
 #if ENABLE_ASH_READ_TIMEOUT
 	fd_set set;
@@ -11566,44 +11568,74 @@
 	ifs = bltinlookup("IFS");
 	if (ifs == NULL)
 		ifs = defifs;
-#if ENABLE_ASH_READ_NCHARS
+#if ENABLE_ASH_READ_NCHARS || ENABLE_ASH_READ_TIMEOUT
+#if ENABLE_ASH_READ_NCHARS && ENABLE_ASH_READ_TIMEOUT
+	if (nch_flag || silent || ts.tv_sec || ts.tv_usec) {
+#elif ENABLE_ASH_READ_TIMEOUT
+	if (ts.tv_sec || ts.tv_usec) {
+#elif ENABLE_ASH_READ_NCHARS
 	if (nch_flag || silent) {
+#endif
 		tcgetattr(0, &tty);
 		old_tty = tty;
-		if (nch_flag) {
+#if ENABLE_ASH_READ_NCHARS && ENABLE_ASH_READ_TIMEOUT
+		if (nch_flag || ts.tv_sec || ts.tv_usec)
+#elif ENABLE_ASH_READ_TIMEOUT
+		if (ts.tv_sec || ts.tv_usec)
+#elif ENABLE_ASH_READ_NCHARS
+		if (nch_flag)
+#endif
 			tty.c_lflag &= ~ICANON;
-			tty.c_cc[VMIN] = nchars;
-		}
-		if (silent) {
-			tty.c_lflag &= ~(ECHO|ECHOK|ECHONL);
 
-		}
+
+#if ENABLE_ASH_READ_NCHARS
+		if (silent)
+		    tty.c_lflag &= ~(ECHO|ECHOK|ECHONL);
+#endif
 		tcsetattr(0, TCSANOW, &tty);
 	}
 #endif
+	i = 1;
+	STARTSTACKSTR(p);
 #if ENABLE_ASH_READ_TIMEOUT
 	if (ts.tv_sec || ts.tv_usec) {
 		FD_ZERO(&set);
 		FD_SET(0, &set);
 
 		i = select(FD_SETSIZE, &set, NULL, NULL, &ts);
-		if (!i) {
+		if (i == 1)
+		{
+			read(0, &c, 1);
+			if(c == '\n' || c == 4) /* Handle newlines and EOF */
+				i = 0; /* Don't read further... */
+			else
+				STPUTC(c, p); /* Ok, keep reading... */
+		}
 #if ENABLE_ASH_READ_NCHARS
-			if (nch_flag)
-				tcsetattr(0, TCSANOW, &old_tty);
+		if (!silent && !nch_flag)
 #endif
-			return 1;
+			tcsetattr(0, TCSANOW, &old_tty);
+
+#if ENABLE_ASH_READ_NCHARS
+		if(i == 0)
+		{
+			nchars = 0;
+			nch_flag = 1;
+		} else
+		{
+			if (nch_flag)
+				nchars--;
 		}
+#endif
 	}
 #endif
 	status = 0;
 	startword = 1;
 	backslash = 0;
-	STARTSTACKSTR(p);
 #if ENABLE_ASH_READ_NCHARS
 	while (!nch_flag || nchars--)
 #else
-	for (;;)
+	for (;i > 0;)
 #endif
 	{
 		if (read(0, &c, 1) != 1) {
@@ -11640,8 +11672,10 @@
 		}
 	}
 #if ENABLE_ASH_READ_NCHARS
-	if (nch_flag || silent)
+	if (silent || nch_flag)
 		tcsetattr(0, TCSANOW, &old_tty);
+	if (!silent && nch_flag)
+		printf("\n");
 #endif
 
 	STACKSTRNUL(p);