summaryrefslogtreecommitdiff
path: root/ipl/progs/duplfile.icn
blob: 5bcdd9c8a676e04fc0e305a40d1958597c6f9bb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
############################################################################
#
#	File:     duplfile.icn
#
#	Subject:  Program to find directories with same files
#
#	Author:   Ralph E. Griswold
#
#	Date:     June 10, 1994
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program lists the file names that occur in more than one
#  subdirectory and the subdirectories in which the names occur.
#
#  This program should be used with caution on large directory
#  structures.
#
############################################################################
#
#  Requires:  UNIX
#
############################################################################

procedure main(args)
   local ext, posit, files, names, name, dir, temp, dirs

   ext := args[1] | ""
   posit := -*ext

   names := table()

   files := open("ls -R", "p")

   while name := read(files) do
      name ? {
         if dir <- tab(-1) & =":" then {
            next
            }
         else if tab(posit) & =ext then {
            /names[name] := []
            put(names[name], dir)
            }
         }

   names := sort(names, 3)

   while name := get(names) do {
      dirs := get(names)
      if *name = 0 then next
      if *dirs > 1 then {
         write("file: ", image(name), " occurs in the following directories")
         every write("\t", image(fix(!sort(dirs))))
         write()
         }
      }

end

procedure fix(s)

   /s := "."

   return s

end