shell_parse.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * shell_parse.c
  3. */
  4. #include "private.h"
  5. #include "lub/string.h"
  6. #include <string.h>
  7. #include <assert.h>
  8. /*----------------------------------------------------------- */
  9. clish_pargv_status_t clish_shell_parse(
  10. const clish_shell_t * this, const char *line,
  11. const clish_command_t ** cmd, clish_pargv_t ** pargv)
  12. {
  13. clish_pargv_status_t result = CLISH_BAD_CMD;
  14. *cmd = clish_shell_resolve_command(this, line);
  15. /* Now construct the parameters for the command */
  16. if (NULL != *cmd)
  17. *pargv = clish_pargv_new(*cmd, this->viewid, line, 0, &result);
  18. if (*pargv) {
  19. char str[100];
  20. char * tmp;
  21. int depth = clish_shell__get_depth(this);
  22. snprintf(str, sizeof(str) - 1, "%u", depth);
  23. clish_pargv_insert(*pargv, this->param_depth, str);
  24. tmp = clish_shell__get_pwd_full(this, depth);
  25. if (tmp) {
  26. clish_pargv_insert(*pargv, this->param_pwd, tmp);
  27. lub_string_free(tmp);
  28. }
  29. }
  30. return result;
  31. }
  32. /*----------------------------------------------------------- */
  33. clish_shell_state_t clish_shell__get_state(const clish_shell_t * this)
  34. {
  35. return this->state;
  36. }
  37. /*----------------------------------------------------------- */
  38. void clish_shell__set_state(clish_shell_t * this,
  39. clish_shell_state_t state)
  40. {
  41. assert(this);
  42. this->state = state;
  43. }
  44. /*----------------------------------------------------------- */