|
@@ -1,5 +1,62 @@
|
|
|
#include "esh_deinit.h"
|
|
|
|
|
|
void EShDeinit() {
|
|
|
-
|
|
|
-}
|
|
|
+ EShSaveConfigFile();
|
|
|
+ EShSaveHistoryFile();
|
|
|
+ EShDeinitInfo();
|
|
|
+ printf("\nESh: Goodbye!\n");
|
|
|
+}
|
|
|
+
|
|
|
+void EShDeinitInfo() {
|
|
|
+ // TO BE IMPLEMENTED
|
|
|
+}
|
|
|
+
|
|
|
+void EShSaveConfigFile() {
|
|
|
+ FILE* file = fopen(esh_info_global->config_file_path, "w");
|
|
|
+ if (!file) {
|
|
|
+ printf("\nESh: error, cannot open config file %s, settings may not be saved...\n", esh_info_global->config_file_path);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ fprintf(file, "history_path=%s\n", esh_info_global->history_file_path);
|
|
|
+ fprintf(file, "history_limit=%d\n", esh_info_global->history_limit);
|
|
|
+ fprintf(file, "max_active_jobs=%d\n", esh_info_global->max_jobs_number);
|
|
|
+ fprintf(file, "max_command_length=%d\n", esh_info_global->max_command_length);
|
|
|
+
|
|
|
+ fclose(file);
|
|
|
+}
|
|
|
+
|
|
|
+void EShSaveHistoryFile() {
|
|
|
+ FILE* file = fopen(esh_info_global->history_file_path, "w");
|
|
|
+ if (!file) {
|
|
|
+ printf("\nESh: error, cannot open history file %s, commands may not be saved...\n", esh_info_global->history_file_path);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < esh_info_global->history_command_list_size; ++i) {
|
|
|
+ fprintf(file, "%s\n", esh_info_global->history_command_list[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ fclose(file);
|
|
|
+}
|
|
|
+
|
|
|
+void EShDeinitJob(EShJob* job) {
|
|
|
+ if (!job)
|
|
|
+ return;
|
|
|
+
|
|
|
+ free(job->command);
|
|
|
+
|
|
|
+ for (int i = 0; i < esh_info_global->max_command_tokens; ++i) {
|
|
|
+ if (job->command_tokens[i]) {
|
|
|
+ free(job->command_tokens[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(job->command_tokens);
|
|
|
+}
|
|
|
+
|
|
|
+void EShFreeJobsList(EShJob* jobs_list) {
|
|
|
+ for (int i = 0; i < esh_info_global->max_jobs_number; ++i) {
|
|
|
+ EShDeinitJob(jobs_list + i);
|
|
|
+ }
|
|
|
+ free(jobs_list);
|
|
|
+}
|