shell_delete.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /* Clear the context */
  57. if (this->context.completion_pargv) {
  58. clish_pargv_delete(this->context.completion_pargv);
  59. this->context.completion_pargv = NULL;
  60. }
  61. }
  62. /*--------------------------------------------------------- */
  63. void clish_shell_delete(clish_shell_t * this)
  64. {
  65. if (this->client_hooks->fini_fn) {
  66. /* now call the client finalisation */
  67. this->client_hooks->fini_fn(this);
  68. }
  69. clish_shell_fini(this);
  70. free(this);
  71. }
  72. /*--------------------------------------------------------- */