diff options
author | Erwan Velu <erwan.velu@free.fr> | 2009-11-30 12:39:08 +0100 |
---|---|---|
committer | Erwan Velu <erwan.velu@free.fr> | 2009-12-04 10:11:16 +0100 |
commit | e6b0f42c040e00f88bc7a0cdf32abb63c1e80e04 (patch) | |
tree | 1fb74da89056abd204214c21d67044f13098407c | |
parent | a3e36f364d45ef282c3eca535a588b292e8509cb (diff) | |
download | syslinux-e6b0f42c040e00f88bc7a0cdf32abb63c1e80e04.tar.gz syslinux-e6b0f42c040e00f88bc7a0cdf32abb63c1e80e04.tar.xz syslinux-e6b0f42c040e00f88bc7a0cdf32abb63c1e80e04.zip |
hdt: Fixing history cycling
Impact: prior to that commit, cycling the history failed
When we enter more than 32 commands, let's cycle the history
-rw-r--r-- | com32/hdt/hdt-cli.c | 28 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.h | 2 |
2 files changed, 21 insertions, 9 deletions
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index dc0bdffa..69a2b61f 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -782,7 +782,7 @@ void start_auto_mode(struct s_hardware *hardware) void print_history() { reset_more_printf(); - for (int i = 1; i < MAX_HISTORY_SIZE - 1; i++) { + for (int i = 1; i <= MAX_HISTORY_SIZE; i++) { if (i == hdt_cli.history_pos) { more_printf("*%d:'%s'\n", i, hdt_cli.history[i]); continue; @@ -803,7 +803,7 @@ void start_cli_mode(struct s_hardware *hardware) char temp_command[MAX_LINE_SIZE]; hdt_cli.cursor_pos = 0; - memset(hdt_cli.history, '\0', sizeof(hdt_cli.history)); + memset(hdt_cli.history, 0, sizeof(hdt_cli.history)); hdt_cli.history_pos = 1; hdt_cli.max_history_pos = 1; @@ -901,7 +901,7 @@ void start_cli_mode(struct s_hardware *hardware) /* We have to compute the next position */ if (future_history_pos == 1) { - future_history_pos = MAX_HISTORY_SIZE - 1; + future_history_pos = MAX_HISTORY_SIZE; } else { future_history_pos--; } @@ -914,7 +914,7 @@ void start_cli_mode(struct s_hardware *hardware) } /* Let's make that future position the one we use */ - memset(INPUT, '\0', sizeof(INPUT)); + memset(INPUT, 0, sizeof(INPUT)); strncpy(INPUT, hdt_cli.history[future_history_pos], sizeof(INPUT)); /* Clear the line */ @@ -934,7 +934,7 @@ void start_cli_mode(struct s_hardware *hardware) /* Saving future position */ current_future_history_pos = future_history_pos; - if (future_history_pos == MAX_HISTORY_SIZE - 1) { + if (future_history_pos == MAX_HISTORY_SIZE) { future_history_pos = 1; } else { future_history_pos++; @@ -955,7 +955,7 @@ void start_cli_mode(struct s_hardware *hardware) } /* Let's make that future position the one we use */ - memset(INPUT, '\0', sizeof(INPUT)); + memset(INPUT, 0, sizeof(INPUT)); strncpy(INPUT, hdt_cli.history[future_history_pos], sizeof(INPUT)); /* Clear the line */ @@ -1001,9 +1001,21 @@ void start_cli_mode(struct s_hardware *hardware) break; } exec_command(remove_spaces(INPUT), hardware); - if (hdt_cli.history_pos == MAX_HISTORY_SIZE - 1) - hdt_cli.history_pos = 1; hdt_cli.history_pos++; + + /* Did we reach the end of the history ?*/ + if (hdt_cli.history_pos > MAX_HISTORY_SIZE) { + /* Let's return at the beginning */ + hdt_cli.history_pos = 1; + } + + /* Does the next position is already used ? + * If yes, we are cycling in history */ + if (strlen(INPUT) > 0) { + /* Let's clean that entry */ + memset(&INPUT,0,sizeof(INPUT)); + } + future_history_pos = hdt_cli.history_pos; if (hdt_cli.history_pos > hdt_cli.max_history_pos) hdt_cli.max_history_pos = hdt_cli.history_pos; diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index 26fbc208..898b53f8 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -94,7 +94,7 @@ struct s_cli { cli_mode_t mode; char prompt[PROMPT_SIZE]; uint8_t cursor_pos; - char history[MAX_HISTORY_SIZE][MAX_LINE_SIZE]; + char history[MAX_HISTORY_SIZE+1][MAX_LINE_SIZE]; int history_pos; int max_history_pos; }; |