shell_delete.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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]);
  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. if (this->completion_pargv) {
  50. clish_pargv_delete(this->completion_pargv);
  51. this->completion_pargv = NULL;
  52. }
  53. }
  54. /*--------------------------------------------------------- */
  55. void clish_shell_delete(clish_shell_t * this)
  56. {
  57. if (this->client_hooks->fini_fn) {
  58. /* now call the client finalisation */
  59. this->client_hooks->fini_fn(this);
  60. }
  61. clish_shell_fini(this);
  62. free(this);
  63. }
  64. /*--------------------------------------------------------- */