shell_delete.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. clish_param_delete(this->param_interactive);
  56. lub_string_free(this->lockfile);
  57. lub_string_free(this->default_shebang);
  58. if (this->fifo_name) {
  59. unlink(this->fifo_name);
  60. lub_string_free(this->fifo_name);
  61. }
  62. /* Clear the context */
  63. if (this->context.completion_pargv) {
  64. clish_pargv_delete(this->context.completion_pargv);
  65. this->context.completion_pargv = NULL;
  66. }
  67. }
  68. /*--------------------------------------------------------- */
  69. void clish_shell_delete(clish_shell_t * this)
  70. {
  71. if (this->client_hooks->fini_fn) {
  72. /* now call the client finalisation */
  73. this->client_hooks->fini_fn(this);
  74. }
  75. clish_shell_fini(this);
  76. free(this);
  77. }
  78. /*--------------------------------------------------------- */