~ubuntu-branches/ubuntu/lucid/9base/lucid

« back to all changes in this revision

Viewing changes to cleanname/cleanname.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-01-25 15:33:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060125153300-6hh4p9wx8iqqply5
Tags: upstream-2
ImportĀ upstreamĀ versionĀ 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <u.h>
 
2
#include <libc.h>
 
3
 
 
4
void
 
5
main(int argc, char **argv)
 
6
{
 
7
        char *dir;
 
8
        char *name;
 
9
        int i;
 
10
 
 
11
        dir = nil;
 
12
        ARGBEGIN{
 
13
        case 'd':
 
14
                if((dir=ARGF()) == nil)
 
15
                        goto Usage;
 
16
                break;
 
17
        default:
 
18
                goto Usage;
 
19
        }ARGEND;
 
20
 
 
21
        if(argc < 1) {
 
22
        Usage:
 
23
                fprint(2, "usage: cleanname [-d pwd] name...\n");
 
24
                exits("usage");
 
25
        }
 
26
 
 
27
        for(i=0; i<argc; i++) {
 
28
                if(dir == nil || argv[i][0] == '/') {
 
29
                        cleanname(argv[i]);
 
30
                        print("%s\n", argv[i]);
 
31
                } else {
 
32
                        name = malloc(strlen(argv[i])+1+strlen(dir)+1);
 
33
                        if(name == nil) {
 
34
                                fprint(2, "cleanname: out of memory\n");
 
35
                                exits("out of memory");
 
36
                        }
 
37
                        sprint(name, "%s/%s", dir, argv[i]);
 
38
                        cleanname(name);
 
39
                        print("%s\n", name);
 
40
                        free(name);
 
41
                }
 
42
        }
 
43
        exits(0);
 
44
}