MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / msh_auto_complete_path

Function msh_auto_complete_path

components/finsh/msh.c:630–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628
629#ifdef DFS_USING_POSIX
630void msh_auto_complete_path(char *path)
631{
632 DIR *dir = RT_NULL;
633 struct dirent *dirent = RT_NULL;
634 char *full_path, *ptr, *index;
635
636 if (!path)
637 return;
638
639 full_path = (char *)rt_malloc(256);
640 if (full_path == RT_NULL) return; /* out of memory */
641
642 if (*path != '/')
643 {
644 getcwd(full_path, 256);
645 if (full_path[rt_strlen(full_path) - 1] != '/')
646 strcat(full_path, "/");
647 }
648 else *full_path = '\0';
649
650 index = RT_NULL;
651 ptr = path;
652 for (;;)
653 {
654 if (*ptr == '/') index = ptr + 1;
655 if (!*ptr) break;
656
657 ptr ++;
658 }
659 if (index == RT_NULL) index = path;
660
661 if (index != RT_NULL)
662 {
663 char *dest = index;
664
665 /* fill the parent path */
666 ptr = full_path;
667 while (*ptr) ptr ++;
668
669 for (index = path; index != dest;)
670 *ptr++ = *index++;
671 *ptr = '\0';
672
673 dir = opendir(full_path);
674 if (dir == RT_NULL) /* open directory failed! */
675 {
676 rt_free(full_path);
677 return;
678 }
679
680 /* restore the index position */
681 index = dest;
682 }
683
684 /* auto complete the file or directory name */
685 if (*index == '\0') /* display all of files and directories */
686 {
687 for (;;)

Callers 1

msh_auto_completeFunction · 0.85

Calls 12

rt_mallocFunction · 0.85
rt_strlenFunction · 0.85
rt_freeFunction · 0.85
rt_kprintfFunction · 0.85
str_commonFunction · 0.85
rt_memcpyFunction · 0.85
statClass · 0.70
getcwdFunction · 0.50
opendirFunction · 0.50
readdirFunction · 0.50
rewinddirFunction · 0.50
closedirFunction · 0.50

Tested by

no test coverage detected