source: tags/ms_r16q3/SOURCE_TOOLS/find_newest_source.pl

Last change on this file was 11874, checked in by westram, 10 years ago
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use diagnostics;
6
7# --------------------------------------------------------------------------------
8
9# skip files with the following extensions:
10my @boring_extensions = (
11                         'o', 'a', 'so',
12                         'gz', 'tgz',
13                         'class', 'jar',
14                         'elc',
15                         'lnk',
16                        );
17
18# skip files with the following names:
19my @boring_files = (
20                    '.cvsignore',
21                    'TAGS',
22                   );
23
24# skip directories with the following full names:
25my @boring_dirs = ( 
26                   'bin',
27                  );
28
29# skip sub-directories with the following names:
30my @boring_subdirs = (
31                   'CVS',
32                   '.svn',
33                  );
34
35my @boring_namematches = (
36                          qr/^\#.*\#$/, # emacs autosaves
37                          qr/^\.\#.*\.[0-9]+\.[0-9]+$/, # old cvs revisions
38                         );
39my @boring_fullmatches = (
40                         );
41
42my $max_print = 1000; # max lines to print
43
44# --------------------------------------------------------------------------------
45
46my $ARBHOME = $ENV{'ARBHOME'};
47if (defined $ARBHOME) {
48  push @boring_extensions, 'genmenu';
49  push @boring_extensions, 'stamp';
50  push @boring_extensions, 'depends';
51  push @boring_extensions, 'last_gcc';
52  push @boring_extensions, 'last_compiler';
53
54  push @boring_fullmatches, qr/$ARBHOME\/lib\/ARB\.pm$/;
55  push @boring_fullmatches, qr/$ARBHOME\/PERL2ARB\/.*ARB\.(bs|xs|c|3pm)$/;
56  push @boring_fullmatches, qr/$ARBHOME\/PERL2ARB\/(debug|proto)\.h$/;
57  push @boring_fullmatches, qr/$ARBHOME\/PERL2ARB\/Makefile$/;
58  push @boring_fullmatches, qr/$ARBHOME\/TEMPLATES\/arb_build\.h$/;
59  push @boring_fullmatches, qr/$ARBHOME\/HELP_SOURCE\/(date\.xsl|html\.list|_index\.html)$/;
60  push @boring_fullmatches, qr/$ARBHOME\/AISC\/aisc$/;
61  push @boring_fullmatches, qr/$ARBHOME\/AISC_MKPTPS\/aisc_mkpt$/;
62  push @boring_fullmatches, qr/$ARBHOME\/.*\/GEN[CH]\//;
63  push @boring_fullmatches, qr/$ARBHOME\/GDEHELP\/helpfiles\.lst$/;
64
65  push @boring_dirs, $ARBHOME.'/PROBE_SERVER/bin';
66  push @boring_dirs, $ARBHOME.'/PROBE_SET/bin';
67  push @boring_dirs, $ARBHOME.'/ARB_SOURCE_DOC';
68  push @boring_dirs, $ARBHOME.'/HELP_SOURCE/Xml';
69  push @boring_dirs, $ARBHOME.'/HELP_SOURCE/genhelp';
70  push @boring_dirs, $ARBHOME.'/GDEHELP/HELP_GEN';
71  push @boring_dirs, $ARBHOME.'/GDEHELP/HELP_DOC_GEN';
72  push @boring_dirs, $ARBHOME.'/lib/help';
73  push @boring_dirs, $ARBHOME.'/lib/help_html';
74  push @boring_dirs, $ARBHOME.'/bin';
75}
76
77# --------------------------------------------------------------------------------
78
79my @files = ();
80
81my %boring_extensions = map { $_ => 1; } @boring_extensions;
82my %boring_files = map { $_ => 1;      } @boring_files;
83my %boring_subdirs = map { $_ => 1;    } @boring_subdirs;
84my %boring_dirs = map { $_ => 1;       } @boring_dirs;
85
86sub scan_tree_recursive($);
87sub scan_tree_recursive($) {
88  my ($dir) = @_;
89  # print "scan_tree_recursive '$dir'\n";
90  opendir(DIR,$dir) || die "can't read directory '$dir'";
91  my @subdirs = ();
92  foreach (readdir(DIR)) {
93    if (not /^[.]+$/o) { # ignore curr- and up-dir
94      my $fullname = $dir.'/'.$_;
95      if (not -l $fullname) { # ignore links
96        if (-d $fullname) {
97          if (not exists $boring_subdirs{$_} and 
98              not exists $boring_dirs{$fullname})
99            {
100              push @subdirs, $fullname;
101            }
102        }
103        else {
104          my $skip = 0;
105          if (exists $boring_files{$_}) {
106            $skip = 1;
107          }
108          elsif (/\.([^\.]+)$/ and exists $boring_extensions{$1}) {
109            $skip = 1;
110          }
111          else {
112            my $name = $_;
113          TEST1: foreach (@boring_namematches) {
114              if ($name =~ $_) { $skip = 1; last TEST1; }
115            }
116            if ($skip==0) {
117            TEST2: foreach (@boring_fullmatches) {
118                if ($fullname =~ $_) { $skip = 1; last TEST2; }
119              }
120            }
121          }
122
123          if ($skip==0) { push @files, $fullname; }
124        }
125      }
126    }
127  }
128  closedir(DIR);
129  foreach (@subdirs) {
130    scan_tree_recursive($_);
131  }
132}
133
134my $equality = '================';
135my $reg_parse_part = qr/^([ :]*)([^ :]+)/;
136
137sub diff2last_rec($$);
138sub diff2last_rec($$) {
139  my ($this,$last) = @_;
140
141  if (not $this =~ $reg_parse_part) {
142    if ($this =~ /^[ ]*$/) { return $this; }
143    die "can't parse '$this'";
144  }
145  my ($this_space, $this_part, $this_rest) = ($1,$2,$');
146  if (not $last =~ $reg_parse_part) { die "can't parse '$this'"; }
147  my ($last_space, $last_part, $last_rest) = ($1,$2,$');
148
149  my $part;
150  if ($this_part eq $last_part) {
151    $part = substr($equality, 1, length($this_part));
152  }
153  else {
154    # print "'$this_part' ne '$last_part'\n";
155    $part = $this_part;
156  }
157
158  return $this_space.$part.diff2last_rec($this_rest, $last_rest);
159}
160
161my $lastMod = undef;
162sub diff2last($) {
163  my ($mod) = @_;
164  if (defined $lastMod) {
165    my $newmod = diff2last_rec($mod, $lastMod);
166    $lastMod = $mod;
167    $mod = $newmod;
168  }
169  else {
170    $lastMod = $mod;
171  }
172  return $mod;
173}
174
175sub max($$) {
176  my ($a,$b) = @_;
177  return $a if $a>$b;
178  return $b;
179}
180
181sub readable_age($) {
182  my ($modtime) = @_;
183  my $age = time - $modtime;
184  if ($age<60) { return $age.'s'; }
185  $age = int($age/60); if ($age<60) { return $age.'m'; }
186  $age = int($age/60); if ($age<24) { return $age.'h'; }
187  $age = int($age/24); if ($age<14) { return $age.'d'; }
188  my $weeks = int($age/7); if ($weeks<9) { return $weeks.'w'; }
189  my $months = int($age/30); if ($months<12) { return $months.'M'; }
190  my $years = int($age/365);
191  return $years.'Y';
192}
193
194sub perform_search() {
195  my $root = `pwd`;
196  chomp($root);
197  $root =~ s/[\/\\]+$//g;
198
199  scan_tree_recursive($root);
200  my %filedate = ();
201
202  my $del = length($root)+1;
203  @files = map { substr($_,$del); } @files;
204
205  foreach (@files) {
206    my $modtime = (stat($_))[9];
207    if (not defined $modtime) { die "Can't stat file '$_'"; }
208    $filedate{$_} = $modtime;
209    # print scalar(localtime($modtime))." $_\n";
210  }
211
212  my @sorted = sort {
213    $filedate{$b} <=> $filedate{$a};
214  } @files;
215
216  if (scalar(@sorted)<$max_print) { $max_print=scalar(@sorted); }
217
218  my $maxlen = 0;
219  foreach (my $i=0; $i<$max_print; ++$i) {
220    my $len = length($sorted[$i]);
221    if ($len > $maxlen) { $maxlen = $len; }
222  }
223
224  my $spacer = "          ";
225  while (length($spacer) < $maxlen) { $spacer .= $spacer; }
226
227  print "find_newest_source: Entering directory `$root'\n";
228  foreach (my $i=0; $i<$max_print; ++$i) {
229    $_ = $sorted[$i];
230    my $len = length($_);
231    print "$_:1: ".substr($spacer,0,max($maxlen-$len,0)).
232      "mod: ".diff2last(scalar(localtime($filedate{$_}))).
233        "  [ ".sprintf("%3s",readable_age($filedate{$_}))." ]\n";
234  }
235  print "find_newest_source: Leaving directory `$root'\n";
236}
237
238perform_search();
Note: See TracBrowser for help on using the repository browser.