shell_parse.c 843 B

12345678910111213141516171819202122232425262728293031323334
  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
  9. clish_shell_parse(const clish_shell_t * this,
  10. const char *line,
  11. const clish_command_t ** cmd, clish_pargv_t ** pargv)
  12. {
  13. clish_pargv_status_t result = clish_BAD_CMD;
  14. size_t offset;
  15. char *prompt = clish_view__get_prompt(this->view, this->viewid);
  16. /* track the offset of each parameter on the command line */
  17. offset = strlen(prompt) + 1;
  18. /* cleanup */
  19. lub_string_free(prompt);
  20. *cmd = clish_shell_resolve_command(this, line);
  21. if (NULL != *cmd) {
  22. /*
  23. * Now construct the parameters for the command
  24. */
  25. *pargv = clish_pargv_new(*cmd, line, offset, &result);
  26. }
  27. return result;
  28. }
  29. /*----------------------------------------------------------- */