1
0

shell_parse.c 941 B

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