shell_parse.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 (*cmd)
  17. *pargv = clish_pargv_new(*cmd, this->viewid, line, 0, &result);
  18. if (*pargv) {
  19. char str[100];
  20. char * tmp;
  21. /* Variable __cur_depth */
  22. int depth = clish_shell__get_depth(this);
  23. snprintf(str, sizeof(str) - 1, "%u", depth);
  24. clish_pargv_insert(*pargv, this->param_depth, str);
  25. /* Variable __cur_pwd */
  26. tmp = clish_shell__get_pwd_full(this, depth);
  27. if (tmp) {
  28. clish_pargv_insert(*pargv, this->param_pwd, tmp);
  29. lub_string_free(tmp);
  30. }
  31. /* Variable __interactive */
  32. if (clish_shell__get_interactive(this))
  33. tmp = "1";
  34. else
  35. tmp = "0";
  36. clish_pargv_insert(*pargv, this->param_interactive, tmp);
  37. }
  38. return result;
  39. }
  40. /*----------------------------------------------------------- */
  41. clish_shell_state_t clish_shell__get_state(const clish_shell_t * this)
  42. {
  43. return this->state;
  44. }
  45. /*----------------------------------------------------------- */
  46. void clish_shell__set_state(clish_shell_t * this,
  47. clish_shell_state_t state)
  48. {
  49. assert(this);
  50. this->state = state;
  51. }
  52. /*----------------------------------------------------------- */