1
0

shell_delete.c 2.2 KB

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