1
0

shell_view.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * shell_find_create_view.c
  3. */
  4. #include <assert.h>
  5. #include "private.h"
  6. /*--------------------------------------------------------- */
  7. clish_view_t *clish_shell_find_create_view(clish_shell_t * this,
  8. const char *name, const char *prompt)
  9. {
  10. clish_view_t *view = lub_bintree_find(&this->view_tree, name);
  11. if (!view) {
  12. /* create a view */
  13. view = clish_view_new(name, prompt);
  14. assert(view);
  15. clish_shell_insert_view(this, view);
  16. } else {
  17. /* set the prompt */
  18. if (prompt)
  19. clish_view__set_prompt(view, prompt);
  20. }
  21. return view;
  22. }
  23. /*--------------------------------------------------------- */
  24. clish_view_t *clish_shell_find_view(clish_shell_t * this, const char *name)
  25. {
  26. return lub_bintree_find(&this->view_tree, name);
  27. }
  28. /*--------------------------------------------------------- */
  29. void clish_shell_insert_view(clish_shell_t * this, clish_view_t * view)
  30. {
  31. (void)lub_bintree_insert(&this->view_tree, view);
  32. }
  33. /*--------------------------------------------------------- */
  34. clish_view_t *clish_shell__get_view(const clish_shell_t * this)
  35. {
  36. assert(this);
  37. if (this->depth < 0)
  38. return NULL;
  39. return this->pwdv[this->depth]->view;
  40. }
  41. /*--------------------------------------------------------- */
  42. unsigned int clish_shell__get_depth(const clish_shell_t *this)
  43. {
  44. assert(this);
  45. return this->depth;
  46. }
  47. /*--------------------------------------------------------- */
  48. clish_view_t *clish_shell__set_depth(clish_shell_t *this, unsigned int depth)
  49. {
  50. clish_view_t *tmp;
  51. assert(this);
  52. /* Check if target view is valid = is not NULL */
  53. tmp = this->pwdv[depth]->view;
  54. if (!tmp)
  55. return NULL;
  56. this->depth = depth;
  57. return tmp;
  58. }
  59. /*--------------------------------------------------------- */