~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to contrib/dirgraph/dirgraph.pl

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# Create a dot(1) graph file from a directory hierarchy
 
4
#
 
5
# (C) Copyright 2001 Diomidis Spinellis.
 
6
#
 
7
# Permission to use, copy, and distribute this software and its
 
8
# documentation for any purpose and without fee is hereby granted,
 
9
# provided that the above copyright notice appear in all copies and that
 
10
# both that copyright notice and this permission notice appear in
 
11
# supporting documentation.
 
12
 
13
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 
14
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 
15
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
16
#
 
17
# $Id: dirgraph.pl,v 1.1 2001/11/28 18:01:36 ellson Exp $
 
18
#
 
19
 
 
20
print "#!/usr/local/bin/dot
 
21
# Automatically generated file.
 
22
# Contains the directory representation of $ARGV[0] generated by $0
 
23
#
 
24
 
 
25
";
 
26
 
 
27
if ($#ARGV != 0) {
 
28
        print STDERR "$0: usage $0 directory\n";
 
29
        exit(1);
 
30
}
 
31
 
 
32
$unix = (-r '/dev/null');
 
33
 
 
34
if ($unix) {
 
35
        open(IN, $cmd = "find $ARGV[0] -type d -print|") || die "Unable to run $cmd: $!\n";
 
36
} else {
 
37
        # Hopefully Windows
 
38
        open(IN, $cmd = "dir /b/ad/s $ARGV[0]|") || die "Unable to run $cmd: $!\n";
 
39
}
 
40
 
 
41
while (<IN>) {
 
42
        chop;
 
43
        if ($unix) {
 
44
                @paths = split(/\//, $_);
 
45
        } else {
 
46
                @paths = split(/\\/, $_);
 
47
        }
 
48
        undef $op;
 
49
        undef $path;
 
50
        for $p (@paths) {
 
51
                $path .= "/$p";
 
52
                $name = $path;
 
53
                $name =~ s/[^a-zA-Z0-9]/_/g;
 
54
                $node{$name} = $p;
 
55
                $edge{"$op->$name;"} = 1 if ($op);
 
56
                $op = $name;
 
57
        }
 
58
}
 
59
close(IN);
 
60
print 'digraph G {
 
61
        nodesep=.1;
 
62
        rankdir=LR;
 
63
        node [height=.15,shape=box,fontname="Helvetica",fontsize=8];
 
64
        edge [arrowhead=none,arrowtail=none];
 
65
 
 
66
'
 
67
;
 
68
for $i (sort keys %node) {
 
69
        print "\t$i [label=\"$node{$i}\"];\n";
 
70
}
 
71
for $i (sort keys %edge) {
 
72
        print "\t$i\n";
 
73
}
 
74
print "}\n";