shell_view.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * shell_find_create_view.c
  3. */
  4. #include <assert.h>
  5. #include <string.h>
  6. #include "private.h"
  7. static int find_view(const void *key, const void *data)
  8. {
  9. clish_view_t *view = (clish_view_t *)data;
  10. const char *name = key;
  11. return strcmp(name, clish_view__get_name(view));
  12. }
  13. /*--------------------------------------------------------- */
  14. clish_view_t *clish_shell_find_create_view(clish_shell_t *this,
  15. const char *name)
  16. {
  17. clish_view_t *view = clish_shell_find_view(this, name);
  18. if (view)
  19. return view;
  20. view = clish_view_new(name);
  21. lub_list_add(this->view_tree, view);
  22. return view;
  23. }
  24. /*--------------------------------------------------------- */
  25. clish_view_t *clish_shell_find_view(clish_shell_t *this, const char *name)
  26. {
  27. return lub_list_find(this->view_tree, find_view, name);
  28. }
  29. /*--------------------------------------------------------- */
  30. clish_view_t *clish_shell__get_view(const clish_shell_t * this)
  31. {
  32. assert(this);
  33. if (this->depth < 0)
  34. return NULL;
  35. return this->pwdv[this->depth]->view;
  36. }
  37. /*--------------------------------------------------------- */
  38. clish_view_t *clish_shell__set_depth(clish_shell_t *this, unsigned int depth)
  39. {
  40. clish_view_t *tmp;
  41. assert(this);
  42. /* Check if target view is valid = is not NULL */
  43. tmp = this->pwdv[depth]->view;
  44. if (!tmp)
  45. return NULL;
  46. this->depth = depth;
  47. return tmp;
  48. }
  49. CLISH_GET(shell, unsigned int, depth);