#! /usr/bin/perl # mkindex - do a recursive directory listing from ARGV in a stylized format # vixie 08apr92 [made compatible with "compromise" format from dave brierley] # vixie 07feb92 [original] @Months = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); $KB = 1024; chop($Cwd = `/bin/pwd`); for (@ARGV) { @Dirs = (); &pushd($_) || die "$_: $!"; &do_dotdir(); } exit 0; sub pushd { local($_) = @_; push(@Dirs, $_); &dir(); &chdir($Dir) || return 0; #d print "push $_ ($Dir)\n"; return 1; } sub popd { pop(@Dirs); &dir(); #d print "pop $Dir\n"; return &chdir($Dir); } sub dir { $Dir = join('/', @Dirs); $Dir =~ s://:/:; $Dir =~ s:/\./:/:; } sub chdir { local($_) = @_; $_ = $Cwd.'/'.$_ unless (m:^/:); return chdir($_); } sub do_dotdir { local($_, @stat, *dot); local(@files, @dirs); opendir(dot, '.') || return; @files = sort(readdir(dot)); closedir(dot); @dirs = (); for (@files) { next if (/^\./); # avoid .files next if (-l $_); # avoid symlinks if (-d _) { # directory - save for later push(@dirs, $_); next; } if (-f _) { # regular file @stat = stat(_); &do_file($_, $stat[7], $stat[9]); } } for (@dirs) { if (&pushd($_)) { &do_dotdir(); &popd() || die "popd [$Dir]: $!"; } } } sub do_file { local($name, $size, $mtime) = @_; local($sec, $min, $hour, $mday, $mon, $year) = localtime($mtime); printf("%02d.%02d.%02d %02d:%02d %7dk %s/%s\n", $year, $mon+1, $mday, $hour, $min, ($size + $KB - 1) / $KB, $Dir, $name); }