esh_deinit.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "esh_deinit.h"
  2. void EShDeinit() {
  3. EShSaveConfigFile();
  4. EShSaveHistoryFile();
  5. EShDeinitInfo();
  6. printf("\nESh: Goodbye!\n");
  7. }
  8. void EShDeinitInfo() {
  9. // TO BE IMPLEMENTED
  10. }
  11. void EShSaveConfigFile() {
  12. FILE* file = fopen(esh_info_global->config_file_path, "w");
  13. if (!file) {
  14. printf("\nESh: error, cannot open config file %s, settings may not be saved...\n", esh_info_global->config_file_path);
  15. return;
  16. }
  17. fprintf(file, "history_path=%s\n", esh_info_global->history_file_path);
  18. fprintf(file, "history_limit=%d\n", esh_info_global->history_limit);
  19. fprintf(file, "max_active_jobs=%d\n", esh_info_global->max_jobs_number);
  20. fprintf(file, "max_command_length=%d\n", esh_info_global->max_command_length);
  21. fclose(file);
  22. }
  23. void EShSaveHistoryFile() {
  24. FILE* file = fopen(esh_info_global->history_file_path, "w");
  25. if (!file) {
  26. printf("\nESh: error, cannot open history file %s, commands may not be saved...\n", esh_info_global->history_file_path);
  27. return;
  28. }
  29. for (int i = 0; i < esh_info_global->history_command_list_size; ++i) {
  30. fprintf(file, "%s\n", esh_info_global->history_command_list[i]);
  31. }
  32. fclose(file);
  33. }
  34. void EShDeinitJob(EShJob* job) {
  35. if (!job)
  36. return;
  37. free(job->command);
  38. for (int i = 0; i < esh_info_global->max_command_tokens; ++i) {
  39. if (job->command_tokens[i]) {
  40. free(job->command_tokens[i]);
  41. }
  42. }
  43. free(job->command_tokens);
  44. }
  45. void EShFreeJobsList(EShJob* jobs_list) {
  46. for (int i = 0; i < esh_info_global->max_jobs_number; ++i) {
  47. EShDeinitJob(jobs_list + i);
  48. }
  49. free(jobs_list);
  50. }