Lines Matching defs:shell
27 "| Parameter shell v"BSH_VERSION" |\r\n"
39 BSH_CHECK(handle != NULL, return "System unknown err", "Invalid shell env");
40 BShellEnv *shell = (BShellEnv *)handle;
41 int len = sprintf_s(shell->data, sizeof(shell->data) - 1, "System unknown err 0x%08x", err);
43 BSH_LOGE("Write shell data size failed.");
45 return shell->data;
64 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
65 BShellEnv *shell = (BShellEnv *)handle;
69 BShellCommand *cmd = shell->command;
82 cmd = shell->command;
100 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
111 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
119 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
120 BSH_CHECK(prompt != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
121 BShellEnv *shell = (BShellEnv *)handle;
122 if (shell->prompt != NULL) {
123 free(shell->prompt);
127 shell->prompt = strdup(prompt + promptLen - BSH_CMD_NAME_END);
128 if (shell->prompt != NULL) {
129 shell->prompt[0] = '.';
130 shell->prompt[1] = '.';
131 shell->prompt[2] = '.'; // 2 index
134 shell->prompt = strdup(prompt);
135 BSH_CHECK(shell->prompt != NULL, return BSH_INVALID_PARAM, "strdup prompt failed.");
142 BSH_CHECK(handle != NULL, return, "Invalid shell env");
170 static void BShellEnvParseParam(BShellEnv *shell)
174 shell->argc = 0;
175 for (uint16_t i = 0; i < shell->length; i++) {
176 char data = *(shell->buffer + i);
182 BSH_CHECK(shell->argc < BSH_PARAMETER_MAX_NUMBER, return, "argc out of range");
183 shell->args[shell->argc++] = shell->buffer + i;
186 if (*(shell->buffer + i) == '\\' && *(shell->buffer + i + 1) != 0) {
190 *(shell->buffer + i) = 0;
196 static int32_t BShellEnvExcuteCmd(BShellEnv *shell, BShellCommand *cmd)
198 return cmd->executer((BShellHandle)shell, shell->argc - cmd->argStart, &shell->args[cmd->argStart]);
203 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
204 BShellEnv *shell = (BShellEnv *)handle;
205 if (shell->length == 0) {
206 BShellEnvOutputString(shell, "\n");
207 BShellEnvOutputString(handle, shell->prompt);
211 *(shell->buffer + shell->length++) = 0;
212 BShellEnvParseParam(shell);
213 shell->length = 0;
214 shell->cursor = 0;
215 if (shell->argc == 0) {
216 BShellEnvOutputString(shell, shell->prompt);
220 BShellEnvOutputString(shell, "\n");
221 if (strcmp((const char *)shell->args[0], "help") == 0) {
222 BShellCmdHelp(handle, shell->argc, shell->args);
223 BShellEnvOutputString(shell, shell->prompt);
226 if (shell->args[0][0] == '$') {
227 BShellEnvOutputParam(shell, shell->args[0]);
228 BShellEnvOutputString(shell, shell->prompt);
232 BShellCommand *cmd = BShellEnvGetCmd(handle, (uint32_t)shell->argc, shell->args);
234 int32_t ret = BShellEnvExcuteCmd(shell, cmd);
235 BShellEnvOutputResult(shell, ret);
237 BShellEnvOutputString(shell, BShellEnvErrString(handle, BSH_CMD_NOT_EXIST));
239 BShellEnvOutputString(shell, shell->prompt);
245 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
246 BShellEnv *shell = (BShellEnv *)handle;
247 if (shell->length == 0) {
250 if (shell->cursor == shell->length) {
251 shell->length--;
252 shell->cursor--;
253 shell->buffer[shell->length] = 0;
255 } else if (shell->cursor > 0) {
256 for (short i = 0; i < shell->length - shell->cursor; i++) {
257 shell->buffer[shell->cursor + i - 1] = shell->buffer[shell->cursor + i];
259 shell->length--;
260 shell->cursor--;
261 shell->buffer[shell->length] = 0;
262 BShellEnvOutputByte(shell, '\b');
263 for (short i = shell->cursor; i < shell->length; i++) {
264 BShellEnvOutputByte(shell, shell->buffer[i]);
266 BShellEnvOutputByte(shell, ' ');
267 for (short i = shell->length - shell->cursor + 1; i > 0; i--) {
268 BShellEnvOutputByte(shell, '\b');
276 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
282 BSH_CHECK(handle != NULL, return, "Invalid shell env");
283 BShellEnv *shell = (BShellEnv *)handle;
287 if (shell->length < BSH_COMMAND_MAX_LENGTH - 1) {
288 if (shell->length == shell->cursor) {
289 shell->buffer[shell->length++] = data;
290 shell->cursor++;
291 BShellEnvOutputByte(shell, data);
293 for (uint16_t i = shell->length - shell->cursor; i > 0; i--) {
294 shell->buffer[shell->cursor + i] = shell->buffer[shell->cursor + i - 1];
296 shell->buffer[shell->cursor++] = data;
297 shell->buffer[++shell->length] = 0;
298 for (uint16_t i = shell->cursor - 1; i < shell->length; i++) {
299 BShellEnvOutputByte(shell, shell->buffer[i]);
301 for (uint16_t i = shell->length - shell->cursor; i > 0; i--) {
302 BShellEnvOutputByte(shell, '\b');
306 BShellEnvOutputString(shell, BShellEnvErrString(handle, BSH_CMD_TOO_LONG));
307 BShellEnvOutputString(shell, shell->prompt);
309 shell->cursor = shell->length;
315 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
325 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
326 BShellEnv *shell = (BShellEnv *)handle;
327 shell->shellState = BSH_ANSI_ESC;
352 BSH_CHECK(handle != NULL, return, "Invalid shell env");
353 BShellEnv *shell = (BShellEnv *)handle;
354 if (shell->shellState == BSH_IN_NORMAL) {
357 key->keyHandle(shell, (uint8_t)data);
362 key->keyHandle(shell, (uint8_t)data);
365 BShellEnvHandleNormal(shell, data);
366 } else if (shell->shellState == BSH_ANSI_CSI) {
373 if (shell->cursor < shell->length) {
374 BShellEnvOutputByte(handle, shell->buffer[shell->cursor]);
375 shell->cursor++;
379 if (shell->cursor > 0) {
380 BShellEnvOutputByte(shell, '\b');
381 shell->cursor--;
387 shell->shellState = BSH_IN_NORMAL;
388 } else if (shell->shellState == BSH_ANSI_ESC) {
390 shell->shellState = BSH_ANSI_CSI;
392 shell->shellState = BSH_IN_NORMAL;
399 BSH_CHECK(handle != NULL, return, "Invalid shell env");
400 BShellEnv *shell = (BShellEnv *)handle;
401 BSH_CHECK(shell->input != NULL, return, "Invalid shell input");
404 if (shell->input(&data, 1) == 1) {
405 BShellEnvProcessInput(shell, data);
412 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
415 BShellEnv *shell = (BShellEnv *)calloc(1, sizeof(BShellEnv));
416 BSH_CHECK(shell != NULL, return BSH_INVALID_PARAM, "Failed to create shell env");
417 shell->length = 0;
418 shell->cursor = 0;
419 shell->shellState = BSH_IN_NORMAL;
420 shell->input = info->input;
421 shell->prompt = strdup(info->prompt);
422 BSH_CHECK(shell->prompt != NULL, free(shell); return BSH_INVALID_PARAM, "Failed to strdup prompt");
423 shell->command = NULL;
424 shell->param = NULL;
425 shell->keyHandle = NULL;
426 shell->execMode = BSH_EXEC_INDEPENDENT;
427 *handle = (BShellHandle)shell;
433 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
434 BShellEnv *shell = (BShellEnv *)handle;
435 shell->execMode = BSH_EXEC_TASK;
437 BShellEnvOutputString(handle, shell->prompt);
440 {"exit", BShellCmdExit, "exit parameter shell", "exit"},
479 BSH_CHECK(handle != NULL, return, "Invalid shell env");
480 BShellEnv *shell = (BShellEnv *)handle;
482 BShellCommand *cmd = shell->command;
484 shell->command = cmd->next;
486 cmd = shell->command;
489 BShellParam *param = shell->param;
491 shell->param = param->next;
493 param = shell->param;
496 BShellKey *key = shell->keyHandle;
498 shell->keyHandle = key->next;
500 key = shell->keyHandle;
502 if (shell->prompt != NULL) {
503 free(shell->prompt);
505 free(shell);
510 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
513 BShellEnv *shell = (BShellEnv *)handle;
551 cmd->next = shell->command;
552 shell->command = cmd;
575 BSH_CHECK(handle != NULL, return NULL, "Invalid shell env");
579 BShellEnv *shell = (BShellEnv *)handle;
580 BShellCommand *cmd = shell->command;
617 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
619 BShellEnv *shell = (BShellEnv *)handle;
625 key->next = shell->keyHandle;
626 shell->keyHandle = key;
632 BSH_CHECK(handle != NULL, return NULL, "Invalid shell env");
633 BShellEnv *shell = (BShellEnv *)handle;
634 BShellKey *key = shell->keyHandle;
664 BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
668 BShellEnv *shell = (BShellEnv *)handle;
690 param->next = shell->param;
691 shell->param = param;
701 BSH_CHECK(handle != NULL, return NULL, "Invalid shell env");
702 BShellEnv *shell = (BShellEnv *)handle;
703 BShellParam *param = shell->param;
715 BSH_CHECK(handle != NULL, return "", "Invalid shell env");
731 BSH_CHECK(handle != NULL, return NULL, "Invalid shell env");
745 BSH_CHECK(handle != NULL, return -1, "Invalid shell env");