Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Revision 32:fc09f0eb1e8a, committed 2018-12-28
- Comitter:
- shimniok
- Date:
- Fri Dec 28 19:54:48 2018 +0000
- Parent:
- 31:27e8130a0d8f
- Child:
- 33:84dc443909a0
- Commit message:
- try out wildcard file match for rm
Changed in this revision
SimpleShell.cpp | Show annotated file Show diff for this revision Revisions of this file |
fnmatch.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SimpleShell.cpp Fri Dec 28 17:10:31 2018 +0000 +++ b/SimpleShell.cpp Fri Dec 28 19:54:48 2018 +0000 @@ -187,13 +187,47 @@ return; } +#include "fnmatch.h" + +list<char*> *scandir(char *pattern, char *path) +{ + DIR *d; + list<char*> *listp; + + struct dirent *p; + if ((d = opendir(path)) != NULL) { + listp = new list<char*>; + while ((p = readdir(d)) != NULL) { + if (fnmatch(pattern, p->d_name, FNM_PATHNAME|FNM_CASEFOLD) != FNM_NOMATCH) { + char *s = new char[sizeof(p->d_name)]; + strcpy(s, p->d_name); + listp->push_back(s); + } + } + closedir(d); + } + return listp; +} + void SimpleShell::rm(int argc, char **argv) { if (argc >= 2) { for (int i=1; i < argc; i++) { - if (remove(canon(argv[i]))) { - printf("%s: cannot remove\n", argv[i]); + if (haswildcard(argv[i])) { + list<char*> *fl = scandir(argv[i], _cwd); + char *s; + while (!fl->empty()) { + s = fl->front(); + printf("<%s>\n", s); + fl->pop_front(); + free(s); + } + delete(fl); + } else { + if (remove(canon(argv[i]))) { + printf("%s: cannot remove\n", argv[i]); + } } } } else {
--- a/fnmatch.h Fri Dec 28 17:10:31 2018 +0000 +++ b/fnmatch.h Fri Dec 28 19:54:48 2018 +0000 @@ -53,6 +53,9 @@ #define const /* empty */ #endif -int fnmatch(const char *, const char *, int); +#ifdef __cplusplus +extern "C" +#endif +int fnmatch(const char *, const char *, int); #endif /* !_FNMATCH_H_ */ \ No newline at end of file