
$ssprojname = "$ARGV[0]";

###########
#goto fudge;

# this makes this pattern more useable for matching
$ssprojpat = $ssprojname;
$ssprojpat =~ s%\$%\\\$%;
$ssprojpat =~ s%\/%\\/%g;

system("ss dir -R \"$ssprojname\" -Olshar_dirs");

open(PROJLIST, "< lshar_dirs");

foreach $fileline (<PROJLIST>) {
	chomp $fileline;
	if ($fileline =~ s/^($ssprojpat[^\:]*)\:/\1/) {
		$dirname = $fileline;
	} elsif ( $fileline !~ /^\$| item\(s\)|^No items found|^[\s]*$/ ) {
		system("ss links \"${dirname}/${fileline}\" >> lshar_links");
	}
}

close PROJLIST;

###############
#fudge:

open (LINKSLIST, "<lshar_links");

my @linkbuffer;
my $linkcnt = 0;
my $filename, $linkdir;

open (SHARELIST, "> lshar_multi");

while ($fileline = <LINKSLIST>) {
  if ($fileline =~ /^Projects that file \"([^\"]*)\" is in\.\.\.$/) {
# processing a new file
    if (defined $filename && $linkcnt > 1) {
# the current file has more than one share
      print SHARELIST "$filename\n";
      for ($i = 1; $i <= $linkcnt; $i++) {
# list the shares
        $linkdir = $linkbuffer[$i];
        print SHARELIST "$linkdir\n";
      }
    }
    $filename = $1;
    $linkcnt = 0;
  } elsif ( ($fileline =~ /^  \$\// ) && ($fileline !~ /   \(/) ) {
# piling share names into the list
    $linkcnt++;
    chomp $fileline;
    $linkbuffer[$linkcnt] = $fileline;
  }
}

close SHARELIST;
close LINKSLIST;

