Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Diff: SimpleShell.cpp
- Revision:
- 34:afe994ca0e49
- Parent:
- 33:84dc443909a0
- Child:
- 35:1a8c5fce8895
diff -r 84dc443909a0 -r afe994ca0e49 SimpleShell.cpp --- a/SimpleShell.cpp Fri Dec 28 20:08:22 2018 +0000 +++ b/SimpleShell.cpp Fri Dec 28 20:34:58 2018 +0000 @@ -185,6 +185,29 @@ return; } + +typedef struct { + char *dir; + char *base; +} filespec_t; + + +char *dirname(char *path) +{ + char *found = strrchr(path, '/'); + char *result = new char[sizeof(path)]; + + char *s = result; + char *t = path; + while (t < found) { + *s++ = *t++; + } + *s = 0; + + return result; +} + + #include "fnmatch.h" list<char*> *scandir(char *pattern, char *path) @@ -214,28 +237,29 @@ for (int i=1; i < argc; i++) { char *arg = canon(argv[i]); char *base = basename(arg); + char *dir = dirname(arg); + + printf("arg=<%s>\nbase=<%s>\ndir=<%s>\n", arg, base, dir); - printf("arg=<%s>\nbase=<%s>\n", arg, base); - return; - } - -/* - if (haswildcard(arg) { - list<char*> *fl = scandir(argv[i], _cwd); + // wildcards only valid in basename for now + if (haswildcard(base)) { + list<char*> *fl = scandir(base, dir); char *s; while (!fl->empty()) { s = fl->front(); printf("<%s>\n", s); fl->pop_front(); - free(s); + delete[] s; } - delete(fl); + delete fl; } else { if (remove(canon(argv[i]))) { printf("%s: cannot remove\n", argv[i]); } } - }*/ + + delete[] dir; + } } else { puts("usage: rm [file1 [file2 ...]]"); }