aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-03-31 13:16:52 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-03-31 13:16:52 +0200
commit2c4de5b045a79db73052d5b865474a00c9a87e99 (patch)
tree12a5c2c7a0685ab1674e6b07959688a3470359fd /libbb
parenta439fa93f64e6eb34f0633d00d203b4267d58521 (diff)
downloadbusybox-w32-2c4de5b045a79db73052d5b865474a00c9a87e99.tar.gz
busybox-w32-2c4de5b045a79db73052d5b865474a00c9a87e99.tar.bz2
busybox-w32-2c4de5b045a79db73052d5b865474a00c9a87e99.zip
ash,hush: optional support for $HISTFILESIZE.
Based on patch from Alexey Fomenko (ext-alexey.fomenko AT nokia.com) function old new delta size_from_HISTFILESIZE - 44 +44 hush_main 998 1025 +27 ash_main 1348 1374 +26 read_line_input 3361 3372 +11 new_line_input_t 17 24 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Config.src5
-rw-r--r--libbb/lineedit.c44
2 files changed, 32 insertions, 17 deletions
diff --git a/libbb/Config.src b/libbb/Config.src
index a25af23b4..0ea8f43ab 100644
--- a/libbb/Config.src
+++ b/libbb/Config.src
@@ -80,11 +80,12 @@ config FEATURE_EDITING_VI
80 80
81config FEATURE_EDITING_HISTORY 81config FEATURE_EDITING_HISTORY
82 int "History size" 82 int "History size"
83 range 0 99999 83 # Don't allow way too big values here, code uses fixed "char *history[N]" struct member
84 range 0 9999
84 default 255 85 default 255
85 depends on FEATURE_EDITING 86 depends on FEATURE_EDITING
86 help 87 help
87 Specify command history size. 88 Specify command history size (0 - disable).
88 89
89config FEATURE_EDITING_SAVEHISTORY 90config FEATURE_EDITING_SAVEHISTORY
90 bool "History saving" 91 bool "History saving"
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index b7a2b31dc..095ccfbef 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1243,12 +1243,26 @@ line_input_t* FAST_FUNC new_line_input_t(int flags)
1243{ 1243{
1244 line_input_t *n = xzalloc(sizeof(*n)); 1244 line_input_t *n = xzalloc(sizeof(*n));
1245 n->flags = flags; 1245 n->flags = flags;
1246 n->max_history = MAX_HISTORY;
1246 return n; 1247 return n;
1247} 1248}
1248 1249
1249 1250
1250#if MAX_HISTORY > 0 1251#if MAX_HISTORY > 0
1251 1252
1253unsigned size_from_HISTFILESIZE(const char *hp)
1254{
1255 int size = MAX_HISTORY;
1256 if (hp) {
1257 size = atoi(hp);
1258 if (size <= 0)
1259 return 1;
1260 if (size > MAX_HISTORY)
1261 return MAX_HISTORY;
1262 }
1263 return size;
1264}
1265
1252static void save_command_ps_at_cur_history(void) 1266static void save_command_ps_at_cur_history(void)
1253{ 1267{
1254 if (command_ps[0] != BB_NUL) { 1268 if (command_ps[0] != BB_NUL) {
@@ -1339,7 +1353,7 @@ static void load_history(line_input_t *st_parm)
1339 temp_h[idx] = line; 1353 temp_h[idx] = line;
1340 st_parm->cnt_history_in_file++; 1354 st_parm->cnt_history_in_file++;
1341 idx++; 1355 idx++;
1342 if (idx == MAX_HISTORY) 1356 if (idx == st_parm->max_history)
1343 idx = 0; 1357 idx = 0;
1344 } 1358 }
1345 fclose(fp); 1359 fclose(fp);
@@ -1348,18 +1362,18 @@ static void load_history(line_input_t *st_parm)
1348 if (st_parm->cnt_history_in_file) { 1362 if (st_parm->cnt_history_in_file) {
1349 while (temp_h[idx] == NULL) { 1363 while (temp_h[idx] == NULL) {
1350 idx++; 1364 idx++;
1351 if (idx == MAX_HISTORY) 1365 if (idx == st_parm->max_history)
1352 idx = 0; 1366 idx = 0;
1353 } 1367 }
1354 } 1368 }
1355 1369
1356 /* copy temp_h[] to st_parm->history[] */ 1370 /* copy temp_h[] to st_parm->history[] */
1357 for (i = 0; i < MAX_HISTORY;) { 1371 for (i = 0; i < st_parm->max_history;) {
1358 line = temp_h[idx]; 1372 line = temp_h[idx];
1359 if (!line) 1373 if (!line)
1360 break; 1374 break;
1361 idx++; 1375 idx++;
1362 if (idx == MAX_HISTORY) 1376 if (idx == st_parm->max_history)
1363 idx = 0; 1377 idx = 0;
1364 line_len = strlen(line); 1378 line_len = strlen(line);
1365 if (line_len >= MAX_LINELEN) 1379 if (line_len >= MAX_LINELEN)
@@ -1390,7 +1404,7 @@ static void save_history(char *str)
1390 1404
1391 /* did we write so much that history file needs trimming? */ 1405 /* did we write so much that history file needs trimming? */
1392 state->cnt_history_in_file++; 1406 state->cnt_history_in_file++;
1393 if (state->cnt_history_in_file > MAX_HISTORY * 4) { 1407 if (state->cnt_history_in_file > state->max_history * 4) {
1394 char *new_name; 1408 char *new_name;
1395 line_input_t *st_temp; 1409 line_input_t *st_temp;
1396 1410
@@ -1436,20 +1450,20 @@ static void remember_in_history(char *str)
1436 if (i && strcmp(state->history[i-1], str) == 0) 1450 if (i && strcmp(state->history[i-1], str) == 0)
1437 return; 1451 return;
1438 1452
1439 free(state->history[MAX_HISTORY]); /* redundant, paranoia */ 1453 free(state->history[state->max_history]); /* redundant, paranoia */
1440 state->history[MAX_HISTORY] = NULL; /* redundant, paranoia */ 1454 state->history[state->max_history] = NULL; /* redundant, paranoia */
1441 1455
1442 /* If history[] is full, remove the oldest command */ 1456 /* If history[] is full, remove the oldest command */
1443 /* we need to keep history[MAX_HISTORY] empty, hence >=, not > */ 1457 /* we need to keep history[state->max_history] empty, hence >=, not > */
1444 if (i >= MAX_HISTORY) { 1458 if (i >= state->max_history) {
1445 free(state->history[0]); 1459 free(state->history[0]);
1446 for (i = 0; i < MAX_HISTORY-1; i++) 1460 for (i = 0; i < state->max_history-1; i++)
1447 state->history[i] = state->history[i+1]; 1461 state->history[i] = state->history[i+1];
1448 /* i == MAX_HISTORY-1 */ 1462 /* i == state->max_history-1 */
1449 } 1463 }
1450 /* i <= MAX_HISTORY-1 */ 1464 /* i <= state->max_history-1 */
1451 state->history[i++] = xstrdup(str); 1465 state->history[i++] = xstrdup(str);
1452 /* i <= MAX_HISTORY */ 1466 /* i <= state->max_history */
1453 state->cur_history = i; 1467 state->cur_history = i;
1454 state->cnt_history = i; 1468 state->cnt_history = i;
1455# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY 1469# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
@@ -1970,7 +1984,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
1970 maxsize = MAX_LINELEN; 1984 maxsize = MAX_LINELEN;
1971 S.maxsize = maxsize; 1985 S.maxsize = maxsize;
1972 1986
1973 /* With null flags, no other fields are ever used */ 1987 /* With zero flags, no other fields are ever used */
1974 state = st ? st : (line_input_t*) &const_int_0; 1988 state = st ? st : (line_input_t*) &const_int_0;
1975#if MAX_HISTORY > 0 1989#if MAX_HISTORY > 0
1976# if ENABLE_FEATURE_EDITING_SAVEHISTORY 1990# if ENABLE_FEATURE_EDITING_SAVEHISTORY
@@ -2022,7 +2036,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2022#endif 2036#endif
2023 2037
2024#if 0 2038#if 0
2025 for (i = 0; i <= MAX_HISTORY; i++) 2039 for (i = 0; i <= state->max_history; i++)
2026 bb_error_msg("history[%d]:'%s'", i, state->history[i]); 2040 bb_error_msg("history[%d]:'%s'", i, state->history[i]);
2027 bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history); 2041 bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history);
2028#endif 2042#endif