Lines Matching refs:shellCB

52 char *GetCmdline(ShellCB *shellCB)
54 CmdKeyLink *cmdkey = shellCB->cmdKeyLink;
57 (void)pthread_mutex_lock(&shellCB->keyMutex);
59 (void)pthread_mutex_unlock(&shellCB->keyMutex);
65 (void)pthread_mutex_unlock(&shellCB->keyMutex);
70 (void)pthread_mutex_unlock(&shellCB->keyMutex);
80 static void ShellSaveHistoryCmd(char *string, ShellCB *shellCB)
82 CmdKeyLink *cmdHistory = shellCB->cmdHistoryKeyLink;
91 (void)pthread_mutex_lock(&shellCB->historyMutex);
96 (void)pthread_mutex_unlock(&shellCB->historyMutex);
106 (void)pthread_mutex_unlock(&shellCB->historyMutex);
113 (void)pthread_mutex_unlock(&shellCB->historyMutex);
117 int ShellPend(ShellCB *shellCB)
119 if (shellCB == NULL) {
123 return sem_wait(&shellCB->shellSem);
126 int ShellNotify(ShellCB *shellCB)
128 if (shellCB == NULL) {
132 return sem_post(&shellCB->shellSem);
141 static int ShellCmdLineCheckUDRL(const char ch, ShellCB *shellCB)
145 shellCB->shellKeyType = STAT_ESC_KEY;
148 if (shellCB->shellKeyType == STAT_ESC_KEY) {
149 shellCB->shellKeyType = STAT_MULTI_KEY;
153 if (shellCB->shellKeyType == STAT_MULTI_KEY) {
154 OsShellHistoryShow(CMD_KEY_UP, shellCB);
155 shellCB->shellKeyType = STAT_NORMAL_KEY;
159 if (shellCB->shellKeyType == STAT_MULTI_KEY) {
160 shellCB->shellKeyType = STAT_NORMAL_KEY;
161 OsShellHistoryShow(CMD_KEY_DOWN, shellCB);
165 if (shellCB->shellKeyType == STAT_MULTI_KEY) {
166 shellCB->shellKeyType = STAT_NORMAL_KEY;
170 if (shellCB->shellKeyType == STAT_MULTI_KEY) {
171 shellCB->shellKeyType = STAT_NORMAL_KEY;
178 void ShellTaskNotify(ShellCB *shellCB)
182 (void)pthread_mutex_lock(&shellCB->keyMutex);
183 OsShellCmdPush(shellCB->shellBuf, shellCB->cmdKeyLink);
184 (void)pthread_mutex_unlock(&shellCB->keyMutex);
186 ret = ShellNotify(shellCB);
188 printf("command execute failed, \"%s\"", shellCB->shellBuf);
192 void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
194 if ((shellCB == NULL) || (outputFunc == NULL)) {
198 if (shellCB->shellBufOffset == 0) {
199 shellCB->shellBuf[shellCB->shellBufOffset] = '\n';
200 shellCB->shellBuf[shellCB->shellBufOffset + 1] = '\0';
204 if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
205 shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
208 shellCB->shellBufOffset = 0;
209 ShellTaskNotify(shellCB);
212 void ParseCancelKey(OutputFunc outputFunc, ShellCB *shellCB)
214 if ((shellCB == NULL) || (outputFunc == NULL)) {
218 if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
219 shellCB->shellBuf[0] = CHAR_CTRL_C;
220 shellCB->shellBuf[1] = '\0';
223 shellCB->shellBufOffset = 0;
224 ShellTaskNotify(shellCB);
227 void ParseDeleteKey(OutputFunc outputFunc, ShellCB *shellCB)
229 if ((shellCB == NULL) || (outputFunc == NULL)) {
233 if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1))) {
234 shellCB->shellBuf[shellCB->shellBufOffset - 1] = '\0';
235 shellCB->shellBufOffset--;
240 void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
244 if ((shellCB == NULL) || (outputFunc == NULL)) {
248 if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) {
249 ret = OsTabCompletion(shellCB->shellBuf, &shellCB->shellBufOffset);
251 outputFunc(SHELL_PROMPT"%s", shellCB->shellBuf);
256 void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
258 if ((shellCB == NULL) || (outputFunc == NULL) || !VISIABLE_CHAR(ch)) {
262 if ((ch != '\0') && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) {
263 shellCB->shellBuf[shellCB->shellBufOffset] = ch;
264 shellCB->shellBufOffset++;
268 shellCB->shellKeyType = STAT_NORMAL_KEY;
271 void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
276 if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != CHAR_CTRL_C) && (ch != '\0')) {
277 (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
283 ParseEnterKey(outputFunc, shellCB);
286 ParseCancelKey(outputFunc, shellCB);
290 ParseDeleteKey(outputFunc, shellCB);
293 ParseTabKey(outputFunc, shellCB);
297 ret = ShellCmdLineCheckUDRL(ch, shellCB);
301 ParseNormalChar(ch, outputFunc, shellCB);
582 static void ShellCmdProcess(ShellCB *shellCB)
585 char *buf = GetCmdline(shellCB);
595 ShellSaveHistoryCmd(buf, shellCB);
596 shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;
604 ShellCB *shellCB = (ShellCB *)argv;
606 if (shellCB == NULL) {
617 ret = ShellPend(shellCB);
619 ShellCmdProcess(shellCB);
628 int ShellTaskInit(ShellCB *shellCB)
635 if (shellCB == NULL) {
645 arg = (void *)shellCB;
646 ret = pthread_create(&shellCB->shellTaskHandle, &attr, &ShellTask, arg);
659 void ShellEntry(ShellCB *shellCB)
666 if (shellCB == NULL) {
670 (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
681 ShellCmdLineParse(ch, (OutputFunc)printf, shellCB);