shell_delete.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if (NULL != this->startup) {
  32. /* remove the startup command */
  33. clish_command_delete(this->startup);
  34. }
  35. /* clean up the file stack */
  36. while (BOOL_TRUE == clish_shell_pop_file(this)) {
  37. /* not alot do do here */
  38. }
  39. /* delete the tinyrl object */
  40. clish_shell_tinyrl_delete(this->tinyrl);
  41. /* finalize each of the pwd strings */
  42. for (i = 0; i < this->cfg_pwdc; i++) {
  43. lub_string_free(this->cfg_pwdv[i]->line);
  44. lub_string_free(this->cfg_pwdv[i]->viewid);
  45. free(this->cfg_pwdv[i]);
  46. }
  47. /* free the pwd vector */
  48. free(this->cfg_pwdv);
  49. this->cfg_pwdc = 0;
  50. this->cfg_pwdv = NULL;
  51. konf_client_free(this->client);
  52. /* Free internal params */
  53. clish_param_delete(this->param_depth);
  54. clish_param_delete(this->param_pwd);
  55. lub_string_free(this->lockfile);
  56. lub_string_free(this->default_shebang);
  57. if (this->fifo_name) {
  58. unlink(this->fifo_name);
  59. lub_string_free(this->fifo_name);
  60. }
  61. /* Clear the context */
  62. if (this->context.completion_pargv) {
  63. clish_pargv_delete(this->context.completion_pargv);
  64. this->context.completion_pargv = NULL;
  65. }
  66. }
  67. /*--------------------------------------------------------- */
  68. void clish_shell_delete(clish_shell_t * this)
  69. {
  70. if (this->client_hooks->fini_fn) {
  71. /* now call the client finalisation */
  72. this->client_hooks->fini_fn(this);
  73. }
  74. clish_shell_fini(this);
  75. free(this);
  76. }
  77. /*--------------------------------------------------------- */