#!/bin/sh
# -*- perl -*-
# This code allows us to start perl from our path or an environment variable
# rather than hardcoding a path into the #! line.  It works from sh or csh.
(exit $?0) && eval 'exec ${QPERLQ-perl} -x $0 ${1+"$@"}'
if (! $?QPERLQ) setenv QPERLQ perl
exec $QPERLQ -x $0 $argv:q

#!/usr/local/bin/perl -w
#
# $Id: dir_to_attrib,v 1.2 1997/07/12 15:40:53 ejb Exp $
# $Source: /home/ejb/scripts/RCS/dir_to_attrib,v $
# $Author: ejb $
#

require 5.002;
use strict;

my $whoami = ($0 =~ m,([^/\\]*)$,) ? $1 : $0;
#my $dirname = ($0 =~ m,(.*)[/\\][^/\\]+$,) ? $1 : ".";

my $cur_dir = undef;
my %hidden = ();
my %system = ();
my %both = ();

&read_dir_output("hidden", \%hidden);
&read_dir_output("system", \%system);

for (keys %hidden)
{
    if (exists $system{$_})
    {
	delete $system{$_};
	delete $hidden{$_};
	$both{$_} = 1;
    }
}

for (sort keys %system)
{
    &attrib("+s", $_);
}
for (sort keys %hidden)
{
    &attrib("+h", $_);
}
for (sort keys %both)
{
    &attrib("+h +s", $_);
}

sub attrib
{
    my ($args, $file) = @_;
    print "A:\\attrib $args \"$file\"\r\n";
}

sub read_dir_output
{
    my $file = shift;
    my $list = shift;
    open(F, "<$file") or die "$whoami: can't read $file: $!\n";
    while (<F>)
    {
	s/[\r\n]//g;
	if (m,^\s?Directory of .:\\(.*)$,)
	{
	    $cur_dir = $1;
	    $cur_dir =~ s,\\$,,;
	}
	elsif ((m/^\S....... ...................\d\d-\d\d-\d\d ..:..[ap] (.*)$/) ||
	       (m,^\d\d/\d\d/\d\d  \d\d:\d\d[ap].......................(.*)$,))
	{
	    $list->{"$cur_dir\\$1"} = 1;
	}
    }
    close(F);
}
