|
@@ -8,6 +8,7 @@ void EShInit(int argc, char** argv) {
|
|
|
EShInitInfo(argc, argv);
|
|
|
EShParseCommandLineArgs(argc, argv);
|
|
|
EShProcessConfigFile();
|
|
|
+ EShProcessHistoryFile();
|
|
|
|
|
|
printf("===================================\n"
|
|
|
"Hello, %s!\n"
|
|
@@ -65,6 +66,10 @@ void EShInitInfo(int argc, char** argv) {
|
|
|
|
|
|
esh_info_global->jobs_number = 0;
|
|
|
|
|
|
+ esh_info_global->history_command_list = malloc((esh_info_global->history_limit + 1) * sizeof(char*));
|
|
|
+
|
|
|
+ esh_info_global->history_command_list_size = 0;
|
|
|
+
|
|
|
esh_info_global->max_invite_message_len = 2048;
|
|
|
|
|
|
esh_info_global->invite_message = malloc((esh_info_global->max_invite_message_len + 1) * sizeof(char));
|
|
@@ -141,3 +146,27 @@ void EShProcessConfigFile() {
|
|
|
|
|
|
fclose(file);
|
|
|
}
|
|
|
+
|
|
|
+void EShProcessHistoryFile() {
|
|
|
+ FILE* file = fopen(esh_info_global->history_file_path, "r");
|
|
|
+ if (!file) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ char* line = NULL;
|
|
|
+ ssize_t len = 0;
|
|
|
+ int line_length = 0;
|
|
|
+
|
|
|
+ while ((line_length = getline(&line, &len, file)) != -1) {
|
|
|
+ if (line[line_length - 1] == '\n') {
|
|
|
+ line[line_length - 1] = '\0';
|
|
|
+ --line_length;
|
|
|
+ }
|
|
|
+
|
|
|
+ esh_info_global->history_command_list[esh_info_global->history_command_list_size] = malloc(strlen(line) + 1);
|
|
|
+ strcpy(esh_info_global->history_command_list[esh_info_global->history_command_list_size], line);
|
|
|
+ ++esh_info_global->history_command_list_size;
|
|
|
+ }
|
|
|
+
|
|
|
+ fclose(file);
|
|
|
+}
|