Lines Matching full:shell

13  * 2010-03-19     Bernard      fix backspace issue and fix device read in shell.
15 * 2011-02-23 Bernard fix variable section end issue of finsh shell
26 #include "shell.h"
44 struct finsh_shell *shell; variable
81 if (!shell->prompt_mode) in finsh_get_prompt()
112 * This function get the prompt mode of finsh shell.
118 RT_ASSERT(shell != RT_NULL); in finsh_get_prompt_mode()
119 return shell->prompt_mode; in finsh_get_prompt_mode()
125 * This function set the prompt mode of finsh shell.
133 RT_ASSERT(shell != RT_NULL); in finsh_set_prompt_mode()
134 shell->prompt_mode = prompt_mode; in finsh_set_prompt_mode()
144 RT_ASSERT(shell != RT_NULL); in finsh_getchar()
145 while (rt_device_read(shell->device, -1, &ch, 1) != 1) in finsh_getchar()
146 rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); in finsh_getchar()
155 RT_ASSERT(shell != RT_NULL); in finsh_rx_ind()
158 rt_sem_release(&shell->rx_sem); in finsh_rx_ind()
166 * This function sets the input device of finsh shell.
174 RT_ASSERT(shell != RT_NULL); in finsh_set_device()
183 if (dev == shell->device) return; in finsh_set_device()
184 /* open this device and set the new device in finsh shell */ in finsh_set_device()
188 if (shell->device != RT_NULL) in finsh_set_device()
191 rt_device_close(shell->device); in finsh_set_device()
192 rt_device_set_rx_indicate(shell->device, RT_NULL); in finsh_set_device()
196 memset(shell->line, 0, sizeof(shell->line)); in finsh_set_device()
197 shell->line_curpos = shell->line_position = 0; in finsh_set_device()
199 shell->device = dev; in finsh_set_device()
207 * This function returns current finsh shell input device.
209 * @return the finsh shell input device name is returned.
213 RT_ASSERT(shell != RT_NULL); in finsh_get_device()
214 return shell->device->parent.name; in finsh_get_device()
221 * This function set the echo mode of finsh shell.
229 RT_ASSERT(shell != RT_NULL); in finsh_set_echo()
230 shell->echo_mode = (rt_uint8_t)echo; in finsh_set_echo()
236 * This function gets the echo mode of finsh shell.
242 RT_ASSERT(shell != RT_NULL); in finsh_get_echo()
244 return shell->echo_mode; in finsh_get_echo()
264 rt_strncpy(shell->password, password, FINSH_PASSWORD_MAX); in finsh_set_password()
277 return shell->password; in finsh_get_password()
320 if (!rt_strncmp(shell->password, password, FINSH_PASSWORD_MAX)) return; in finsh_wait_auth()
360 if(shell->echo_mode) in finsh_run_line()
402 static rt_bool_t shell_handle_history(struct finsh_shell *shell) in shell_handle_history() argument
415 rt_kprintf("%s%s", FINSH_PROMPT, shell->line); in shell_handle_history()
419 static void shell_push_history(struct finsh_shell *shell) in shell_push_history() argument
421 if (shell->line_position != 0) in shell_push_history()
424 if (shell->history_count >= FINSH_HISTORY_LINES) in shell_push_history()
427 if (memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, FINSH_CMD_SIZE)) in shell_push_history()
433 memcpy(&shell->cmd_history[index][0], in shell_push_history()
434 &shell->cmd_history[index + 1][0], FINSH_CMD_SIZE); in shell_push_history()
436 memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE); in shell_push_history()
437 memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position); in shell_push_history()
440 shell->history_count = FINSH_HISTORY_LINES; in shell_push_history()
446 …if (shell->history_count == 0 || memcmp(&shell->cmd_history[shell->history_count - 1], shell->line… in shell_push_history()
448 shell->current_history = shell->history_count; in shell_push_history()
449 memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE); in shell_push_history()
450 … memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position); in shell_push_history()
453 shell->history_count ++; in shell_push_history()
457 shell->current_history = shell->history_count; in shell_push_history()
467 shell->echo_mode = 1; in finsh_thread_entry()
469 shell->echo_mode = 0; in finsh_thread_entry()
473 finsh_init(&shell->parser); in finsh_thread_entry()
477 /* set console device as shell device */ in finsh_thread_entry()
478 if (shell->device == RT_NULL) in finsh_thread_entry()
516 shell->stat = WAIT_SPEC_KEY; in finsh_thread_entry()
519 else if (shell->stat == WAIT_SPEC_KEY) in finsh_thread_entry()
523 shell->stat = WAIT_FUNC_KEY; in finsh_thread_entry()
527 shell->stat = WAIT_NORMAL; in finsh_thread_entry()
529 else if (shell->stat == WAIT_FUNC_KEY) in finsh_thread_entry()
531 shell->stat = WAIT_NORMAL; in finsh_thread_entry()
537 if (shell->current_history > 0) in finsh_thread_entry()
538 shell->current_history --; in finsh_thread_entry()
541 shell->current_history = 0; in finsh_thread_entry()
546 memcpy(shell->line, &shell->cmd_history[shell->current_history][0], in finsh_thread_entry()
548 shell->line_curpos = shell->line_position = strlen(shell->line); in finsh_thread_entry()
549 shell_handle_history(shell); in finsh_thread_entry()
557 if (shell->current_history < shell->history_count - 1) in finsh_thread_entry()
558 shell->current_history ++; in finsh_thread_entry()
562 if (shell->history_count != 0) in finsh_thread_entry()
563 shell->current_history = shell->history_count - 1; in finsh_thread_entry()
568 memcpy(shell->line, &shell->cmd_history[shell->current_history][0], in finsh_thread_entry()
570 shell->line_curpos = shell->line_position = strlen(shell->line); in finsh_thread_entry()
571 shell_handle_history(shell); in finsh_thread_entry()
577 if (shell->line_curpos) in finsh_thread_entry()
580 shell->line_curpos --; in finsh_thread_entry()
587 if (shell->line_curpos < shell->line_position) in finsh_thread_entry()
589 rt_kprintf("%c", shell->line[shell->line_curpos]); in finsh_thread_entry()
590 shell->line_curpos ++; in finsh_thread_entry()
604 for (i = 0; i < shell->line_curpos; i++) in finsh_thread_entry()
608 shell_auto_complete(&shell->line[0]); in finsh_thread_entry()
610 shell->line_curpos = shell->line_position = strlen(shell->line); in finsh_thread_entry()
617 /* note that shell->line_curpos >= 0 */ in finsh_thread_entry()
618 if (shell->line_curpos == 0) in finsh_thread_entry()
621 shell->line_position--; in finsh_thread_entry()
622 shell->line_curpos--; in finsh_thread_entry()
624 if (shell->line_position > shell->line_curpos) in finsh_thread_entry()
628 rt_memmove(&shell->line[shell->line_curpos], in finsh_thread_entry()
629 &shell->line[shell->line_curpos + 1], in finsh_thread_entry()
630 shell->line_position - shell->line_curpos); in finsh_thread_entry()
631 shell->line[shell->line_position] = 0; in finsh_thread_entry()
633 rt_kprintf("\b%s \b", &shell->line[shell->line_curpos]); in finsh_thread_entry()
636 for (i = shell->line_curpos; i <= shell->line_position; i++) in finsh_thread_entry()
642 shell->line[shell->line_position] = 0; in finsh_thread_entry()
652 shell_push_history(shell); in finsh_thread_entry()
658 if (shell->echo_mode) in finsh_thread_entry()
660 msh_exec(shell->line, shell->line_position); in finsh_thread_entry()
667 shell->line[shell->line_position] = ';'; in finsh_thread_entry()
669 if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line); in finsh_thread_entry()
671 if (shell->echo_mode) rt_kprintf("\n"); in finsh_thread_entry()
676 memset(shell->line, 0, sizeof(shell->line)); in finsh_thread_entry()
677 shell->line_curpos = shell->line_position = 0; in finsh_thread_entry()
682 if (shell->line_position >= FINSH_CMD_SIZE) in finsh_thread_entry()
683 shell->line_position = 0; in finsh_thread_entry()
686 if (shell->line_curpos < shell->line_position) in finsh_thread_entry()
690 rt_memmove(&shell->line[shell->line_curpos + 1], in finsh_thread_entry()
691 &shell->line[shell->line_curpos], in finsh_thread_entry()
692 shell->line_position - shell->line_curpos); in finsh_thread_entry()
693 shell->line[shell->line_curpos] = ch; in finsh_thread_entry()
694 if (shell->echo_mode) in finsh_thread_entry()
695 rt_kprintf("%s", &shell->line[shell->line_curpos]); in finsh_thread_entry()
698 for (i = shell->line_curpos; i < shell->line_position; i++) in finsh_thread_entry()
703 shell->line[shell->line_position] = ch; in finsh_thread_entry()
704 if (shell->echo_mode) in finsh_thread_entry()
709 shell->line_position ++; in finsh_thread_entry()
710 shell->line_curpos++; in finsh_thread_entry()
711 if (shell->line_position >= FINSH_CMD_SIZE) in finsh_thread_entry()
714 shell->line_position = 0; in finsh_thread_entry()
715 shell->line_curpos = 0; in finsh_thread_entry()
769 * This function will initialize finsh shell
805 if(shell) in finsh_system_init()
807 rt_kprintf("finsh shell already init.\n"); in finsh_system_init()
824 /* create or set shell structure */ in finsh_system_init()
825 shell = (struct finsh_shell *)rt_calloc(1, sizeof(struct finsh_shell)); in finsh_system_init()
826 if (shell == RT_NULL) in finsh_system_init()
828 rt_kprintf("no memory for shell\n"); in finsh_system_init()
835 shell = &_shell; in finsh_system_init()
844 rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); in finsh_system_init()