shell_pwd.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * shell_pwd.c
  3. */
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. #include "lub/string.h"
  7. #include "private.h"
  8. /*--------------------------------------------------------- */
  9. void
  10. clish_shell__set_pwd(clish_shell_t * this, unsigned index,
  11. const char * line, clish_view_t * view, char * viewid)
  12. {
  13. clish_shell_pwd_t **tmp;
  14. size_t new_size = 0;
  15. unsigned i;
  16. /* Create new element */
  17. if (index >= this->cfg_pwdc) {
  18. new_size = (index + 1) * sizeof(clish_shell_pwd_t *);
  19. /* resize the pwd vector */
  20. tmp = realloc(this->cfg_pwdv, new_size);
  21. assert(tmp);
  22. this->cfg_pwdv = tmp;
  23. /* Initialize new elements */
  24. for (i = this->cfg_pwdc; i <= index; i++) {
  25. clish_shell_pwd_t *pwd;
  26. pwd = malloc(sizeof(*pwd));
  27. assert(pwd);
  28. pwd->line = NULL;
  29. pwd->view = NULL;
  30. pwd->viewid = NULL;
  31. this->cfg_pwdv[i] = pwd;
  32. }
  33. this->cfg_pwdc = index + 1;
  34. }
  35. lub_string_free(this->cfg_pwdv[index]->line);
  36. this->cfg_pwdv[index]->line = line ? lub_string_dup(line) : NULL;
  37. this->cfg_pwdv[index]->view = view;
  38. lub_string_free(this->cfg_pwdv[index]->viewid);
  39. this->cfg_pwdv[index]->viewid = viewid ? lub_string_dup(viewid) : NULL;
  40. }
  41. char *clish_shell__get_pwd_line(const clish_shell_t * this, unsigned index)
  42. {
  43. if (index >= this->cfg_pwdc)
  44. return NULL;
  45. return this->cfg_pwdv[index]->line;
  46. }
  47. clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * this, unsigned index)
  48. {
  49. if (index >= this->cfg_pwdc)
  50. return NULL;
  51. return this->cfg_pwdv[index]->view;
  52. }
  53. char *clish_shell__get_pwd_viewid(const clish_shell_t * this, unsigned index)
  54. {
  55. if (index >= this->cfg_pwdc)
  56. return NULL;
  57. return this->cfg_pwdv[index]->viewid;
  58. }
  59. konf_client_t *clish_shell__get_client(const clish_shell_t * this)
  60. {
  61. return this->client;
  62. }