first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / files / whackem.pl
1 #!/usr/bin/perl
2
3 ###############################################################################
4 #                                                                             #
5 #  Name   : whack_forever                                                     #
6 #  Author : Chris Koeritz                                                     #
7 #  Rights : Copyright (C) 1992-$now by Author                                 #
8 #                                                                             #
9 #  Purpose:                                                                   #
10 #                                                                             #
11 #    Zaps a list of files.  This file exists since the default in the YETI    #
12 #  shell environment is to compress files when deletion is attempted.  Only   #
13 #  the whack_forever command actually deletes the files for real.             #
14 #                                                                             #
15 ###############################################################################
16 # This program is free software; you can redistribute it and/or modify it     #
17 # under the terms of the GNU General Public License as published by the Free  #
18 # Software Foundation; either version 2 of the License, or (at your option)   #
19 # any later version.  See: "http://www.gruntose.com/Info/GNU/GPL.html" for a  #
20 # version of the License.  Please send any updates to "fred@gruntose.com".    #
21 ###############################################################################
22
23 require "filename_helper.pl";
24 require "importenv.pl";
25
26 sub interrupt_handler {
27     # skip doing any deletions.
28     print "\nbailing out due to interrupt.  not doing any remaining deletions.\n";
29     exit(0);
30 }
31
32 $SIG{'INT'} = 'interrupt_handler';  # trigger our function instead of continuing.
33
34 local($flags) = "";
35
36 local(@whackers) = @ARGV;
37
38 while ($whackers[0] =~ /^-/) {
39   # this one is a special flag to pass.  don't try to whack that.
40   $flags = $flags . @whackers[0] . ' ';
41   shift(@whackers);
42 }
43
44 #print "flags are $flags\n";
45
46 @whackers = &glob_list(@whackers);
47
48 if (scalar(@whackers) > 0) {
49   print "ZAPPING FOREVER! @whackers ...\n";
50   system("sleep 4") == 0 || &interrupt_handler;
51   print "\nNow really deleting files! => @whackers\n";
52 }
53
54
55 foreach $i (@whackers) {
56   if (-l $i) {
57     unlink($i) || print "failed to unlink $i\n";
58   } elsif (-d $i) {
59     system("rm $flags \"$i\"");
60   } else {
61     unlink($i) || print "failed to unlink $i\n";
62   }
63 }
64