shell_delete.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }
  56. /*--------------------------------------------------------- */
  57. void clish_shell_delete(clish_shell_t * this)
  58. {
  59. if (this->client_hooks->fini_fn) {
  60. /* now call the client finalisation */
  61. this->client_hooks->fini_fn(this);
  62. }
  63. clish_shell_fini(this);
  64. free(this);
  65. }
  66. /*--------------------------------------------------------- */