]> sjero.net Git - wget/blob - util/rmold.pl
Documentation fixes for IRI options, and rename --locale -> --local-encoding.
[wget] / util / rmold.pl
1 #! /usr/bin/perl -w
2
3 # Copyright (C) 1995, 1996, 1997, 2007, 2008 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 # This script is a very lame hack to remove local files, until the
20 # time when Wget proper will have this functionality.
21 # Use with utmost care!
22
23 # If the remote server supports BSD-style listings, set this to 0.
24 $sysvlisting = 1;
25
26 $verbose = 0;
27
28 if (@ARGV && ($ARGV[0] eq '-v')) {
29     shift;
30     $verbose = 1;
31 }
32
33 (@dirs = @ARGV) || push (@dirs,'.');
34
35
36 foreach $_ (@dirs) {
37     &procdir($_);
38 }
39
40 # End here
41
42 sub procdir
43 {
44     local $dir = shift;
45     local(@lcfiles, @lcdirs, %files, @fl);
46
47     print STDERR "Processing directory '$dir':\n" if $verbose;
48
49     opendir(DH, $dir) || die("Cannot open $dir: $!\n");
50     @lcfiles = ();
51     @lcdirs = ();
52     # Read local files and directories.
53     foreach $_ (readdir(DH)) {
54         /^(\.listing|\.\.?)$/ && next;
55         lstat ("$dir/$_");
56         if (-d _) {
57             push (@lcdirs, $_);
58         }
59         else {
60             push (@lcfiles, $_);
61         }
62     }
63     closedir(DH);
64     # Parse .listing
65     if (open(FD, "<$dir/.listing")) {
66         while (<FD>)
67         {
68             # Weed out the line beginning with 'total'
69             /^total/ && next;
70             # Weed out everything but plain files and symlinks.
71             /^[-l]/ || next;
72             @fl = split;
73             $files{$fl[7 + $sysvlisting]} = 1;
74         }
75         close FD;
76         foreach $_ (@lcfiles) {
77             if (!$files{$_}) {
78                 print "$dir/$_\n";
79             }
80         }
81     }
82     else {
83         print STDERR "Warning: $dir/.listing: $!\n";
84     }
85     foreach $_ (@lcdirs) {
86         &procdir("$dir/$_");
87     }
88 }
89