| 628 | |
| 629 | #ifdef DFS_USING_POSIX |
| 630 | void 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 (;;) |
no test coverage detected