diff options
author | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
commit | bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d (patch) | |
tree | 8ca0fe4e2418e6aa18dc74a236c577a719f6c6ed /src/cmd/cleanname.c | |
parent | f08fdedcee12c06e3ce9ac9bec363915978e8289 (diff) | |
download | plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.gz plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.bz2 plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.zip |
new utilities.
the .C files compile but are renamed to avoid building automatically.
Diffstat (limited to 'src/cmd/cleanname.c')
-rw-r--r-- | src/cmd/cleanname.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cmd/cleanname.c b/src/cmd/cleanname.c new file mode 100644 index 00000000..8fa18466 --- /dev/null +++ b/src/cmd/cleanname.c @@ -0,0 +1,44 @@ +#include <u.h> +#include <libc.h> + +void +main(int argc, char **argv) +{ + char *dir; + char *name; + int i; + + dir = nil; + ARGBEGIN{ + case 'd': + if((dir=ARGF()) == nil) + goto Usage; + break; + default: + goto Usage; + }ARGEND; + + if(argc < 1) { + Usage: + fprint(2, "usage: cleanname [-d pwd] name...\n"); + exits("usage"); + } + + for(i=0; i<argc; i++) { + if(dir == nil || argv[i][0] == '/') { + cleanname(argv[i]); + print("%s\n", argv[i]); + } else { + name = malloc(strlen(argv[i])+1+strlen(dir)+1); + if(name == nil) { + fprint(2, "cleanname: out of memory\n"); + exits("out of memory"); + } + sprint(name, "%s/%s", dir, argv[i]); + cleanname(name); + print("%s\n", name); + free(name); + } + } + exits(0); +} |