shell_delete.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * shell_delete.c
  3. */
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include "private.h"
  7. #include "lub/string.h"
  8. /*--------------------------------------------------------- */
  9. static void clish_shell_fini(clish_shell_t * this)
  10. {
  11. clish_view_t *view;
  12. clish_ptype_t *ptype;
  13. unsigned i;
  14. /* delete each view held */
  15. while ((view = lub_bintree_findfirst(&this->view_tree))) {
  16. /* remove the view from the tree */
  17. lub_bintree_remove(&this->view_tree, view);
  18. /* release the instance */
  19. clish_view_delete(view);
  20. }
  21. /* delete each ptype held */
  22. while ((ptype = lub_bintree_findfirst(&this->ptype_tree))) {
  23. /* remove the command from the tree */
  24. lub_bintree_remove(&this->ptype_tree, ptype);
  25. /* release the instance */
  26. clish_ptype_delete(ptype);
  27. }
  28. /* free the textual details */
  29. lub_string_free(this->overview);
  30. lub_string_free(this->viewid);
  31. /* remove the startup command */
  32. if (this->startup)
  33. clish_command_delete(this->startup);
  34. /* clean up the file stack */
  35. while (BOOL_TRUE == clish_shell_pop_file(this));
  36. /* delete the tinyrl object */
  37. clish_shell_tinyrl_delete(this->tinyrl);
  38. /* finalize each of the pwd strings */
  39. for (i = 0; i < this->cfg_pwdc; i++) {
  40. lub_string_free(this->cfg_pwdv[i]->line);
  41. lub_string_free(this->cfg_pwdv[i]->viewid);
  42. free(this->cfg_pwdv[i]);
  43. }
  44. /* free the pwd vector */
  45. free(this->cfg_pwdv);
  46. this->cfg_pwdc = 0;
  47. this->cfg_pwdv = NULL;
  48. konf_client_free(this->client);
  49. /* Free internal params */
  50. clish_param_delete(this->param_depth);
  51. clish_param_delete(this->param_pwd);
  52. clish_param_delete(this->param_interactive);
  53. lub_string_free(this->lockfile);
  54. lub_string_free(this->default_shebang);
  55. if (this->fifo_name) {
  56. unlink(this->fifo_name);
  57. lub_string_free(this->fifo_name);
  58. }
  59. /* Clear the context */
  60. if (this->context.completion_pargv) {
  61. clish_pargv_delete(this->context.completion_pargv);
  62. this->context.completion_pargv = NULL;
  63. }
  64. }
  65. /*--------------------------------------------------------- */
  66. void clish_shell_delete(clish_shell_t * this)
  67. {
  68. /* now call the client finalisation */
  69. if (this->client_hooks->fini_fn)
  70. this->client_hooks->fini_fn(this);
  71. clish_shell_fini(this);
  72. free(this);
  73. }
  74. /*--------------------------------------------------------- */