#include "esh_history.h" void EShAddCommandToHistory(char* command) { int list_size = esh_info_global->history_command_list_size; char** list = esh_info_global->history_command_list; if (list_size == esh_info_global->history_limit) { for (int i = 0; i <= list_size / 2; ++i) { free(list[i]); } for (int i = list_size / 2 + 1; i < list_size; ++i) { list[i - (list_size / 2 + 1)] = list[i]; list[i] = NULL; } esh_info_global->history_command_list_size -= list_size / 2 + 1; list_size -= list_size / 2 + 1; } list[list_size] = malloc((strlen(command) + 1) * sizeof(char)); strcpy(list[list_size], command); ++esh_info_global->history_command_list_size; } const char* EShReceiveCommandFromHistory(int step) { int list_size = esh_info_global->history_command_list_size; char** list = esh_info_global->history_command_list; if (step >= list_size) { return NULL; } return list[list_size - step - 1]; }