更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
shcmd.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "shcmd.h"
33#include "show.h"
34#include "stdlib.h"
35#include "unistd.h"
36#include "dirent.h"
37#include "securec.h"
38
39
40#define SHELL_INIT_MAGIC_FLAG 0xABABABAB
41#define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */
42
43static void OsFreeCmdPara(CmdParsed *cmdParsed)
44{
45 unsigned int i;
46 for (i = 0; i < cmdParsed->paramCnt; i++) {
47 if ((cmdParsed->paramArray[i]) != NULL) {
48 free((cmdParsed->paramArray[i]));
49 cmdParsed->paramArray[i] = NULL;
50 }
51 }
52}
53
54static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsigned int tabStrLen)
55{
56 char *shiftStr = NULL;
57 char *tempStr = (char *)malloc(SHOW_MAX_LEN << 1);
58 if (tempStr == NULL) {
59 return (int)SH_ERROR;
60 }
61
62 (void)memset_s(tempStr, SHOW_MAX_LEN << 1, 0, SHOW_MAX_LEN << 1);
63 shiftStr = tempStr + SHOW_MAX_LEN;
64
65 if (strncpy_s(tempStr, SHOW_MAX_LEN - 1, *tabStr, tabStrLen)) {
66 free(tempStr);
67 return (int)SH_ERROR;
68 }
69
70 parsed->cmdType = CMD_TYPE_STD;
71
72 /* cut useless or repeat space */
73 if (OsCmdKeyShift(tempStr, shiftStr, SHOW_MAX_LEN - 1)) {
74 free(tempStr);
75 return (int)SH_ERROR;
76 }
77
78 /* get exact position of string to complete */
79 /* situation different if end space lost or still exist */
80 if ((strlen(shiftStr) == 0) || (tempStr[strlen(tempStr) - 1] != shiftStr[strlen(shiftStr) - 1])) {
81 *tabStr = "";
82 } else {
83 if (OsCmdParse(shiftStr, parsed)) {
84 free(tempStr);
85 return (int)SH_ERROR;
86 }
87 *tabStr = parsed->paramArray[parsed->paramCnt - 1];
88 }
89
90 free(tempStr);
91 return SH_OK;
92}
93
95{
97}
98
99int OsShellSetWorkingDirectory(const char *dir, size_t len)
100{
101 if (dir == NULL) {
102 return SH_NOK;
103 }
104
105 int ret = strncpy_s(OsGetShellCb()->shellWorkingDirectory, sizeof(OsGetShellCb()->shellWorkingDirectory),
106 dir, len);
107 if (ret != SH_OK) {
108 return SH_NOK;
109 }
110 return SH_OK;
111}
112
113static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, unsigned int tabStrLen)
114{
115 char *strEnd = NULL;
116 char *cutPos = NULL;
117 CmdParsed parsed = {0};
118 char *shellWorkingDirectory = OsShellGetWorkingDirectory();
119 int ret;
120
121 ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen);
122 if (ret != SH_OK) {
123 return ret;
124 }
125
126 /* get fullpath str */
127 if (*tabStr != '/') {
128 if (strncpy_s(strPath, CMD_MAX_PATH, shellWorkingDirectory, CMD_MAX_PATH - 1)) {
129 OsFreeCmdPara(&parsed);
130 return (int)SH_ERROR;
131 }
132 if (strcmp(shellWorkingDirectory, "/")) {
133 if (strncat_s(strPath, CMD_MAX_PATH - 1, "/", CMD_MAX_PATH - strlen(strPath) - 1)) {
134 OsFreeCmdPara(&parsed);
135 return (int)SH_ERROR;
136 }
137 }
138 }
139
140 if (strncat_s(strPath, CMD_MAX_PATH - 1, tabStr, CMD_MAX_PATH - strlen(strPath) - 1)) {
141 OsFreeCmdPara(&parsed);
142 return (int)SH_ERROR;
143 }
144
145 /* split str by last '/' */
146 strEnd = strrchr(strPath, '/');
147 if (strEnd != NULL) {
148 if (strncpy_s(nameLooking, CMD_MAX_PATH, strEnd + 1, CMD_MAX_PATH - 1)) { /* get cmp str */
149 OsFreeCmdPara(&parsed);
150 return (int)SH_ERROR;
151 }
152 }
153
154 cutPos = strrchr(strPath, '/');
155 if (cutPos != NULL) {
156 *(cutPos + 1) = '\0';
157 }
158
159 OsFreeCmdPara(&parsed);
160 return SH_OK;
161}
162
164{
165 char readChar;
166
167 while (1) {
168 if (read(STDIN_FILENO, &readChar, 1) != 1) { /* get one char from stdin */
169 printf("\n");
170 return (int)SH_ERROR;
171 }
172 if ((readChar == 'q') || (readChar == 'Q') || (readChar == CTRL_C)) {
173 printf("\n");
174 return 0;
175 } else if (readChar == '\r') {
176 printf("\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b");
177 return 1;
178 }
179 }
180}
181
182static int OsShowPageControl(unsigned int timesPrint, unsigned int lineCap, unsigned int count)
183{
184 if (NEED_NEW_LINE(timesPrint, lineCap)) {
185 printf("\n");
186 if (SCREEN_IS_FULL(timesPrint, lineCap) && (timesPrint < count)) {
187 printf("--More--");
188 return OsShowPageInputControl();
189 }
190 }
191 return 1;
192}
193
194static int OsSurePrintAll(unsigned int count)
195{
196 char readChar = 0;
197 printf("\nDisplay all %u possibilities?(y/n)", count);
198 while (1) {
199 if (read(STDIN_FILENO, &readChar, 1) != 1) {
200 return (int)SH_ERROR;
201 }
202 if ((readChar == 'n') || (readChar == 'N') || (readChar == CTRL_C)) {
203 printf("\n");
204 return 0;
205 } else if ((readChar == 'y') || (readChar == 'Y') || (readChar == '\r')) {
206 return 1;
207 }
208 }
209}
210
211static int OsPrintMatchList(unsigned int count, const char *strPath, const char *nameLooking, unsigned int printLen)
212{
213 unsigned int timesPrint = 0;
214 unsigned int lineCap;
215 int ret;
216 DIR *openDir = NULL;
217 struct dirent *readDir = NULL;
218 char formatChar[10] = {0}; /* 10:for formatChar length */
219
220 printLen = (printLen > (DEFAULT_SCREEN_WIDTH - 2)) ? (DEFAULT_SCREEN_WIDTH - 2) : printLen; /* 2:revered 2 bytes */
221 lineCap = DEFAULT_SCREEN_WIDTH / (printLen + 2); /* 2:DEFAULT_SCREEN_WIDTH revered 2 bytes */
222 if (snprintf_s(formatChar, sizeof(formatChar) - 1, 7, "%%-%us ", printLen) < 0) { /* 7:format-len */
223 return (int)SH_ERROR;
224 }
225
226 if (count > (lineCap * DEFAULT_SCREEN_HEIGHT)) {
227 ret = OsSurePrintAll(count);
228 if (ret != 1) {
229 return ret;
230 }
231 }
232 openDir = opendir(strPath);
233 if (openDir == NULL) {
234 return (int)SH_ERROR;
235 }
236
237 printf("\n");
238 for (readDir = readdir(openDir); readDir != NULL; readDir = readdir(openDir)) {
239 if (strncmp(nameLooking, readDir->d_name, strlen(nameLooking)) != 0) {
240 continue;
241 }
242 printf(formatChar, readDir->d_name);
243 timesPrint++;
244 ret = OsShowPageControl(timesPrint, lineCap, count);
245 if (ret != 1) {
246 if (closedir(openDir) < 0) {
247 return (int)SH_ERROR;
248 }
249 return ret;
250 }
251 }
252
253 printf("\n");
254 if (closedir(openDir) < 0) {
255 return (int)SH_ERROR;
256 }
257
258 return SH_OK;
259}
260
261static void StrncmpCut(const char *s1, char *s2, size_t n)
262{
263 if ((n == 0) || (s1 == NULL) || (s2 == NULL)) {
264 return;
265 }
266 do {
267 if (*s1 && *s2 && (*s1 == *s2)) {
268 s1++;
269 s2++;
270 } else {
271 break;
272 }
273 } while (--n != 0);
274 if (n > 0) {
275 /* NULL pad the remaining n-1 bytes */
276 while (n-- != 0) {
277 *s2++ = 0;
278 }
279 }
280 return;
281}
282
283static void OsCompleteStr(char *result, const char *target, char *cmdKey, unsigned int *len)
284{
285 unsigned int size = strlen(result) - strlen(target);
286 char *des = cmdKey + *len;
287 char *src = result + strlen(target);
288
289 while (size-- > 0) {
290 printf("%c", *src);
291 if (*len == (SHOW_MAX_LEN - 1)) {
292 *des = '\0';
293 break;
294 }
295 *des++ = *src++;
296 (*len)++;
297 }
298}
299
300static int OsExecNameMatch(const char *strPath, const char *nameLooking, char *strObj, unsigned int *maxLen)
301{
302 int count = 0;
303 DIR *openDir = NULL;
304 struct dirent *readDir = NULL;
305
306 openDir = opendir(strPath);
307 if (openDir == NULL) {
308 return (int)SH_ERROR;
309 }
310
311 for (readDir = readdir(openDir); readDir != NULL; readDir = readdir(openDir)) {
312 if (strncmp(nameLooking, readDir->d_name, strlen(nameLooking)) != 0) {
313 continue;
314 }
315 if (count == 0) {
316 if (strncpy_s(strObj, CMD_MAX_PATH, readDir->d_name, CMD_MAX_PATH - 1)) {
317 (void)closedir(openDir);
318 return (int)SH_ERROR;
319 }
320 *maxLen = strlen(readDir->d_name);
321 } else {
322 /* strncmp&cut the same strings of name matched */
323 StrncmpCut(readDir->d_name, strObj, strlen(strObj));
324 if (strlen(readDir->d_name) > *maxLen) {
325 *maxLen = strlen(readDir->d_name);
326 }
327 }
328 count++;
329 }
330
331 if (closedir(openDir) < 0) {
332 return (int)SH_ERROR;
333 }
334
335 return count;
336}
337
338static int OsTabMatchFile(char *cmdKey, unsigned int *len)
339{
340 unsigned int maxLen = 0;
341 int count;
342 char *strOutput = NULL;
343 char *strCmp = NULL;
344 char *dirOpen = (char *)malloc(CMD_MAX_PATH * 3); /* 3:dirOpen\strOutput\strCmp */
345 if (dirOpen == NULL) {
346 return (int)SH_ERROR;
347 }
348
349 (void)memset_s(dirOpen, CMD_MAX_PATH * 3, 0, CMD_MAX_PATH * 3); /* 3:dirOpen\strOutput\strCmp */
350 strOutput = dirOpen + CMD_MAX_PATH;
351 strCmp = strOutput + CMD_MAX_PATH;
352
353 if (OsStrSeparate(cmdKey, dirOpen, strCmp, *len)) {
354 free(dirOpen);
355 return (int)SH_ERROR;
356 }
357
358 count = OsExecNameMatch(dirOpen, strCmp, strOutput, &maxLen);
359 /* one or more matched */
360 if (count >= 1) {
361 OsCompleteStr(strOutput, strCmp, cmdKey, len);
362
363 if (count == 1) {
364 free(dirOpen);
365 return 1;
366 }
367 if (OsPrintMatchList((unsigned int)count, dirOpen, strCmp, maxLen) == -1) {
368 free(dirOpen);
369 return (int)SH_ERROR;
370 }
371 }
372
373 free(dirOpen);
374 return count;
375}
376
377/*
378 * Description: Pass in the string and clear useless space ,which include:
379 * 1) The overmatch space which is not be marked by Quote's area
380 * Squeeze the overmatch space into one space
381 * 2) Clear all space before first valid charatctor
382 * Input: cmdKey : Pass in the buff string, which is ready to be operated
383 * cmdOut : Pass out the buffer string ,which has already been operated
384 * size : cmdKey length
385 */
386unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
387{
388 char *output = NULL;
389 char *outputBak = NULL;
390 unsigned int len;
391 int ret;
392 bool quotes = FALSE;
393
394 if ((cmdKey == NULL) || (cmdOut == NULL)) {
395 return (unsigned int)SH_ERROR;
396 }
397
398 len = strlen(cmdKey);
399 if ((*cmdKey == '\n') || (len >= size)) {
400 return (unsigned int)SH_ERROR;
401 }
402 output = (char *)malloc(len + 1);
403 if (output == NULL) {
404 printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
405 return (unsigned int)SH_ERROR;
406 }
407
408 /* Backup the 'output' start address */
409 outputBak = output;
410 /* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invalid charactor */
411 for (; *cmdKey != '\0'; cmdKey++) {
412 /* Detected a Double Quotes, switch the matching status */
413 if (*(cmdKey) == '\"') {
414 SWITCH_QUOTES_STATUS(quotes);
415 }
416 /* Ignore the current charactor in following situation */
417 /* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */
418 /* 2) Current charactor is a space */
419 /* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */
420 /* 4) Invalid charactor, such as single quotes */
421 if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) {
422 continue;
423 }
424 if (*cmdKey == '\'') {
425 continue;
426 }
427 *output = *cmdKey;
428 output++;
429 }
430 *output = '\0';
431 /* Restore the 'output' start address */
432 output = outputBak;
433 len = strlen(output);
434 /* Clear the space which is located at the first charactor in buffer */
435 if (*output == ' ') {
436 output++;
437 len--;
438 }
439 /* Copy out the buffer which is been operated already */
440 ret = strncpy_s(cmdOut, size, output, len);
441 if (ret != SH_OK) {
442 printf("%s,%d strncpy_s failed, err:%d!\n", __FUNCTION__, __LINE__, ret);
443 free(outputBak);
444 return SH_ERROR;
445 }
446 cmdOut[len] = '\0';
447
448 free(outputBak);
449 return SH_OK;
450}
451
452int OsTabCompletion(char *cmdKey, unsigned int *len)
453{
454 int count;
455
456 if ((cmdKey == NULL) || (len == NULL)) {
457 return (int)SH_ERROR;
458 }
459
460 count = OsTabMatchFile(cmdKey, len);
461
462 return count;
463}
464
465unsigned int OsShellKeyInit(ShellCB *shellCB)
466{
467 CmdKeyLink *cmdKeyLink = NULL;
468 CmdKeyLink *cmdHistoryLink = NULL;
469
470 if (shellCB == NULL) {
471 return SH_ERROR;
472 }
473
474 cmdKeyLink = (CmdKeyLink *)malloc(sizeof(CmdKeyLink));
475 if (cmdKeyLink == NULL) {
476 printf("Shell CmdKeyLink memory alloc error!\n");
477 return SH_ERROR;
478 }
479 cmdHistoryLink = (CmdKeyLink *)malloc(sizeof(CmdKeyLink));
480 if (cmdHistoryLink == NULL) {
481 free(cmdKeyLink);
482 printf("Shell CmdHistoryLink memory alloc error!\n");
483 return SH_ERROR;
484 }
485
486 cmdKeyLink->count = 0;
487 SH_ListInit(&(cmdKeyLink->list));
488 shellCB->cmdKeyLink = (void *)cmdKeyLink;
489
490 cmdHistoryLink->count = 0;
491 SH_ListInit(&(cmdHistoryLink->list));
492 shellCB->cmdHistoryKeyLink = (void *)cmdHistoryLink;
493 shellCB->cmdMaskKeyLink = (void *)cmdHistoryLink;
494 return SH_OK;
495}
496
498{
499 CmdKeyLink *cmdtmp = NULL;
500 if (cmdKeyLink == NULL) {
501 return;
502 }
503
504 while (!SH_ListEmpty(&(cmdKeyLink->list))) {
505 cmdtmp = SH_LIST_ENTRY(cmdKeyLink->list.pstNext, CmdKeyLink, list);
506 SH_ListDelete(&cmdtmp->list);
507 free(cmdtmp);
508 }
509
510 cmdKeyLink->count = 0;
511 free(cmdKeyLink);
512}
513
514void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink)
515{
516 CmdKeyLink *cmdNewNode = NULL;
517 unsigned int len;
518
519 if ((string == NULL) || (strlen(string) == 0)) {
520 return;
521 }
522
523 len = strlen(string);
524 cmdNewNode = (CmdKeyLink *)malloc(sizeof(CmdKeyLink) + len + 1);
525 if (cmdNewNode == NULL) {
526 return;
527 }
528
529 (void)memset_s(cmdNewNode, sizeof(CmdKeyLink) + len + 1, 0, sizeof(CmdKeyLink) + len + 1);
530 if (strncpy_s(cmdNewNode->cmdString, len + 1, string, len)) {
531 free(cmdNewNode);
532 return;
533 }
534
535 SH_ListTailInsert(&(cmdKeyLink->list), &(cmdNewNode->list));
536
537 return;
538}
539
540void OsShellHistoryShow(unsigned int value, ShellCB *shellCB)
541{
542 CmdKeyLink *cmdtmp = NULL;
543 CmdKeyLink *cmdNode = shellCB->cmdHistoryKeyLink;
544 CmdKeyLink *cmdMask = shellCB->cmdMaskKeyLink;
545 int ret;
546
548 if (value == CMD_KEY_DOWN) {
549 if (cmdMask == cmdNode) {
550 goto END;
551 }
552
553 cmdtmp = SH_LIST_ENTRY(cmdMask->list.pstNext, CmdKeyLink, list);
554 if (cmdtmp != cmdNode) {
555 cmdMask = cmdtmp;
556 } else {
557 goto END;
558 }
559 } else if (value == CMD_KEY_UP) {
560 cmdtmp = SH_LIST_ENTRY(cmdMask->list.pstPrev, CmdKeyLink, list);
561 if (cmdtmp != cmdNode) {
562 cmdMask = cmdtmp;
563 } else {
564 goto END;
565 }
566 }
567
568 while (shellCB->shellBufOffset--) {
569 printf("\b \b");
570 }
571 printf("%s", cmdMask->cmdString);
572 shellCB->shellBufOffset = strlen(cmdMask->cmdString);
573 (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
574 ret = memcpy_s(shellCB->shellBuf, SHOW_MAX_LEN, cmdMask->cmdString, shellCB->shellBufOffset);
575 if (ret != SH_OK) {
576 printf("%s, %d memcpy failed!\n", __FUNCTION__, __LINE__);
577 goto END;
578 }
579 shellCB->cmdMaskKeyLink = (void *)cmdMask;
580
581END:
583 return;
584}
585
586unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
587{
588 /* TODO: complete the usrspace command */
589 unsigned int ret = SH_OK;
590 if (cmdParsed && cmdStr) {
591 ret = SH_NOK;
592 }
593
594 return ret;
595}
596
unsigned int OsCmdParse(char *cmdStr, CmdParsed *cmdParsed)
解析cmd命令,将关键字,参数分离出来
Definition: shcmdparse.c:147
@ CMD_KEY_DOWN
方向下键
Definition: shell.h:97
@ CMD_KEY_UP
方向上键
Definition: shell.h:96
@ CMD_TYPE_STD
支持的标准命令参数输入,所有输入的字符都会通过命令解析后被传入。
Definition: shell.h:90
ShellCB * OsGetShellCb(void)
获取shell控制块
Definition: main.c:47
static void OsCompleteStr(char *result, const char *target, char *cmdKey, unsigned int *len)
Definition: shcmd.c:283
unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
Definition: shcmd.c:586
static void OsFreeCmdPara(CmdParsed *cmdParsed)
Definition: shcmd.c:43
int OsShellSetWorkingDirectory(const char *dir, size_t len)
Definition: shcmd.c:99
static int OsTabMatchFile(char *cmdKey, unsigned int *len)
Definition: shcmd.c:338
static int OsSurePrintAll(unsigned int count)
Definition: shcmd.c:194
static int OsShowPageControl(unsigned int timesPrint, unsigned int lineCap, unsigned int count)
Definition: shcmd.c:182
static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, unsigned int tabStrLen)
Definition: shcmd.c:113
unsigned int OsShellKeyInit(ShellCB *shellCB)
Definition: shcmd.c:465
static int OsPrintMatchList(unsigned int count, const char *strPath, const char *nameLooking, unsigned int printLen)
Definition: shcmd.c:211
void OsShellHistoryShow(unsigned int value, ShellCB *shellCB)
Definition: shcmd.c:540
static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsigned int tabStrLen)
Definition: shcmd.c:54
void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink)
Definition: shcmd.c:514
char * OsShellGetWorkingDirectory(void)
Definition: shcmd.c:94
int OsTabCompletion(char *cmdKey, unsigned int *len)
Definition: shcmd.c:452
static int OsShowPageInputControl(void)
Definition: shcmd.c:163
void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink)
Definition: shcmd.c:497
unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
Definition: shcmd.c:386
static void StrncmpCut(const char *s1, char *s2, size_t n)
Definition: shcmd.c:261
static int OsExecNameMatch(const char *strPath, const char *nameLooking, char *strObj, unsigned int *maxLen)
Definition: shcmd.c:300
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
int pthread_mutex_lock(pthread_mutex_t *mutex)
互斥锁加锁操作
int pthread_mutex_unlock(pthread_mutex_t *mutex)
解锁互斥锁
static void SH_ListDelete(SH_List *node)
Definition: shell_list.h:224
static void SH_ListInit(SH_List *list)
Definition: shell_list.h:72
static void SH_ListTailInsert(SH_List *list, SH_List *node)
Insert a node to the tail of a doubly linked list.
Definition: shell_list.h:168
static bool SH_ListEmpty(SH_List *list)
Identify whether a specified doubly linked list is empty.
Definition: shell_list.h:253
char * paramArray[CMD_MAX_PARAS]
Definition: shcmdparse.h:51
unsigned int paramCnt
Definition: shcmdparse.h:48
CmdType cmdType
Definition: shcmdparse.h:49
struct SH_List * pstPrev
Definition: shell_list.h:51
struct SH_List * pstNext
Definition: shell_list.h:52
Definition: shell.h:71
char shellBuf[SHOW_MAX_LEN]
接受shell命令 buf大小
Definition: shell.h:83
void * cmdKeyLink
命令链表,所有敲过的命令链表
Definition: shell.h:75
void * cmdHistoryKeyLink
命令的历史记录链表,去重,10个
Definition: shell.h:76
unsigned int shellBufOffset
buf偏移量
Definition: shell.h:78
pthread_mutex_t historyMutex
操作cmdHistoryKeyLink的互斥量
Definition: shell.h:82
void * cmdMaskKeyLink
主要用于方向键上下遍历历史命令
Definition: shell.h:77
char shellWorkingDirectory[PATH_MAX]
shell工作目录
Definition: shell.h:84
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void