cleanname.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. void
  12. main(int argc, char **argv)
  13. {
  14. char *dir;
  15. char *name;
  16. int i;
  17. dir = nil;
  18. ARGBEGIN{
  19. case 'd':
  20. if((dir=ARGF()) == nil)
  21. goto Usage;
  22. break;
  23. default:
  24. goto Usage;
  25. }ARGEND;
  26. if(argc < 1) {
  27. Usage:
  28. fprint(2, "usage: cleanname [-d pwd] name...\n");
  29. exits("usage");
  30. }
  31. for(i=0; i<argc; i++) {
  32. if(dir == nil || argv[i][0] == '/') {
  33. cleanname(argv[i]);
  34. print("%s\n", argv[i]);
  35. } else {
  36. name = malloc(strlen(argv[i])+1+strlen(dir)+1);
  37. if(name == nil) {
  38. fprint(2, "cleanname: out of memory\n");
  39. exits("out of memory");
  40. }
  41. sprint(name, "%s/%s", dir, argv[i]);
  42. cleanname(name);
  43. print("%s\n", name);
  44. free(name);
  45. }
  46. }
  47. exits(0);
  48. }