aboutsummaryrefslogtreecommitdiff
path: root/package/busybox/busybox-1.15.1-lineedit.patch
blob: 20a7a8f37cea5e0236c71660aabdfdbeba36a3ff (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
diff -urpN busybox-1.15.1/libbb/lineedit.c busybox-1.15.1-lineedit/libbb/lineedit.c
--- busybox-1.15.1/libbb/lineedit.c	2009-09-12 17:55:58.000000000 +0200
+++ busybox-1.15.1-lineedit/libbb/lineedit.c	2009-09-28 23:56:03.000000000 +0200
@@ -114,8 +114,8 @@ struct lineedit_statics {
 	unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */
 
 	unsigned cursor;
-	unsigned command_len;
-	/* *int* maxsize: we want x in "if (x > S.maxsize)"
+	int command_len; /* must be signed (^D returns -1 len) */
+	/* signed maxsize: we want x in "if (x > S.maxsize)"
 	 * to _not_ be promoted to unsigned */
 	int maxsize;
 	CHAR_T *command_ps;
@@ -1095,15 +1095,15 @@ static void save_command_ps_at_cur_histo
 		int cur = state->cur_history;
 		free(state->history[cur]);
 
-#if ENABLE_FEATURE_ASSUME_UNICODE
+# if ENABLE_FEATURE_ASSUME_UNICODE
 		{
 			char tbuf[MAX_LINELEN];
 			save_string(tbuf, sizeof(tbuf));
 			state->history[cur] = xstrdup(tbuf);
 		}
-#else
+# else
 		state->history[cur] = xstrdup(command_ps);
-#endif
+# endif
 	}
 }
 
@@ -1131,7 +1131,7 @@ static int get_next_history(void)
 	return 0;
 }
 
-#if ENABLE_FEATURE_EDITING_SAVEHISTORY
+# if ENABLE_FEATURE_EDITING_SAVEHISTORY
 /* We try to ensure that concurrent additions to the history
  * do not overwrite each other.
  * Otherwise shell users get unhappy.
@@ -1256,10 +1256,10 @@ static void save_history(char *str)
 		free_line_input_t(st_temp);
 	}
 }
-#else
-#define load_history(a) ((void)0)
-#define save_history(a) ((void)0)
-#endif /* FEATURE_COMMAND_SAVEHISTORY */
+# else
+#  define load_history(a) ((void)0)
+#  define save_history(a) ((void)0)
+# endif /* FEATURE_COMMAND_SAVEHISTORY */
 
 static void remember_in_history(char *str)
 {
@@ -1290,15 +1290,15 @@ static void remember_in_history(char *st
 	/* i <= MAX_HISTORY */
 	state->cur_history = i;
 	state->cnt_history = i;
-#if ENABLE_FEATURE_EDITING_SAVEHISTORY
+# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
 	if ((state->flags & SAVE_HISTORY) && state->hist_file)
 		save_history(str);
-#endif
+# endif
 	IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
 }
 
 #else /* MAX_HISTORY == 0 */
-#define remember_in_history(a) ((void)0)
+# define remember_in_history(a) ((void)0)
 #endif /* MAX_HISTORY */
 
 
@@ -1476,11 +1476,11 @@ static void parse_and_put_prompt(const c
 				c = *prmt_ptr++;
 
 				switch (c) {
-#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
+# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
 				case 'u':
 					pbuf = user_buf ? user_buf : (char*)"";
 					break;
-#endif
+# endif
 				case 'h':
 					pbuf = free_me = safe_gethostname();
 					*strchrnul(pbuf, '.') = '\0';
@@ -1488,7 +1488,7 @@ static void parse_and_put_prompt(const c
 				case '$':
 					c = (geteuid() == 0 ? '#' : '$');
 					break;
-#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
+# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
 				case 'w':
 					/* /home/user[/something] -> ~[/something] */
 					pbuf = cwd_buf;
@@ -1501,7 +1501,7 @@ static void parse_and_put_prompt(const c
 						pbuf = free_me = xasprintf("~%s", cwd_buf + l);
 					}
 					break;
-#endif
+# endif
 				case 'W':
 					pbuf = cwd_buf;
 					cp = strrchr(pbuf, '/');
@@ -1688,13 +1688,15 @@ int FAST_FUNC read_line_input(const char
 
 	/* With null flags, no other fields are ever used */
 	state = st ? st : (line_input_t*) &const_int_0;
-#if ENABLE_FEATURE_EDITING_SAVEHISTORY
+#if MAX_HISTORY > 0
+# if ENABLE_FEATURE_EDITING_SAVEHISTORY
 	if ((state->flags & SAVE_HISTORY) && state->hist_file)
 		if (state->cnt_history == 0)
 			load_history(state);
-#endif
+# endif
 	if (state->flags & DO_HISTORY)
 		state->cur_history = state->cnt_history;
+#endif
 
 	/* prepare before init handlers */
 	cmdedit_y = 0;  /* quasireal y, not true if line > xt*yt */
@@ -1716,7 +1718,7 @@ int FAST_FUNC read_line_input(const char
 	new_settings.c_cc[VTIME] = 0;
 	/* Turn off CTRL-C, so we can trap it */
 #ifndef _POSIX_VDISABLE
-#define _POSIX_VDISABLE '\0'
+# define _POSIX_VDISABLE '\0'
 #endif
 	new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
 	tcsetattr_stdin_TCSANOW(&new_settings);
@@ -2037,7 +2039,8 @@ int FAST_FUNC read_line_input(const char
  rewrite_line:
 			/* Rewrite the line with the selected history item */
 			/* change command */
-			command_len = load_string(state->history[state->cur_history] ? : "", maxsize);
+			command_len = load_string(state->history[state->cur_history] ?
+					state->history[state->cur_history] : "", maxsize);
 			/* redraw and go to eol (bol, in vi) */
 			redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0);
 			break;
@@ -2121,7 +2124,9 @@ int FAST_FUNC read_line_input(const char
 #undef command
 
 #if ENABLE_FEATURE_ASSUME_UNICODE
-	command_len = save_string(command, maxsize - 1);
+	command[0] = '\0';
+	if (command_len > 0)
+		command_len = save_string(command, maxsize - 1);
 	free(command_ps);
 #endif