* shell_parse.c */ #include "private.h" #include "lub/string.h" #include <string.h> /*----------------------------------------------------------- */ clish_pargv_status_t clish_shell_parse(const clish_shell_t *this, const char *line, const clish_command_t **cmd, clish_pargv_t **pargv) { clish_pargv_status_t result = clish_BAD_CMD; size_t offset; char *prompt = clish_view__get_prompt(this->view,this->viewid); /* track the offset of each parameter on the command line */ offset = strlen(prompt)+1; /* cleanup */ lub_string_free(prompt); *cmd = clish_shell_resolve_command(this,line); if(NULL != *cmd) { /* * Now construct the parameters for the command */ *pargv = clish_pargv_new(*cmd,line,offset,&result); }
/*-------------------------------------------------------- */ static void clish_shell_renew_prompt(clish_shell_t *this) { clish_context_t prompt_context; char *prompt = NULL; const clish_view_t *view; char *str = NULL; /* Create appropriate context */ clish_context_init(&prompt_context, this); /* Obtain the prompt */ view = clish_shell__get_view(this); assert(view); lub_string_cat(&str, "${_PROMPT_PREFIX}"); lub_string_cat(&str, clish_view__get_prompt(view)); lub_string_cat(&str, "${_PROMPT_SUFFIX}"); prompt = clish_shell_expand(str, SHELL_VAR_NONE, &prompt_context); assert(prompt); lub_string_free(str); tinyrl__set_prompt(this->tinyrl, prompt); lub_string_free(prompt); } /*-------------------------------------------------------- */ static bool_t clish_shell_tinyrl_key_help(tinyrl_t *this, int key) { bool_t result = BOOL_TRUE; if (tinyrl_is_quoting(this)) { /* if we are in the middle of a quote then simply enter a space */