1
0

shell_delete.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. if (this->completion_pargv) {
  52. clish_pargv_delete(this->completion_pargv);
  53. this->completion_pargv = NULL;
  54. }
  55. /* Free internal params */
  56. clish_param_delete(this->param_depth);
  57. clish_param_delete(this->param_pwd);
  58. }
  59. /*--------------------------------------------------------- */
  60. void clish_shell_delete(clish_shell_t * this)
  61. {
  62. if (this->client_hooks->fini_fn) {
  63. /* now call the client finalisation */
  64. this->client_hooks->fini_fn(this);
  65. }
  66. clish_shell_fini(this);
  67. free(this);
  68. }
  69. /*--------------------------------------------------------- */