use strict; # list HD directory sub senddir($) { my $pat = shift; my @dir; my ($out, $size, $line, $entry, $l, $m, $title); my ($year, $mon, $mday, $hour, $min, $sec); $pat =~ s/^\$//; # trim $ if (length($pat) > 0) { $pat = "^" . $pat; # convert glob to regexp $pat =~ tr/?/./; $pat =~ s/\*/.*/g; } else { $pat = ".*"; } @dir = getdir(); $out = "\x01\x04"; # load addr $title = "serslave"; if (length($title) < 16) { $title .= substr(" ", 16-length($title)); } $title = atopet($title); $out .= addtitle(2002,"\x12\"$title\" V" . VER); foreach $entry (@dir) { next if ($entry eq "."); next if ($entry !~ /$pat/); ($size) = (stat($entry))[7]; $size = int(($size + 253) / 254); if ($size > 9999) { $size = 9999; } # filenames longer than 16 chars are changed to name* #if (length($entry) > 16) { # $entry = substr($entry, 0, 15) . "*"; #} # add quotes and space padding $line = "\"$entry\""; if (length($line) < 18) { $line .= substr(" ", 0, 18-length($line)); } # choose a file type if (-d $entry) { $line .= " dir"; $size = 0; } elsif (-f $entry && $entry =~ /\.d64$/i) { $line .= " dir"; } elsif (-f $entry) { $line .= " prg"; } else { next; #$line .= " ???"; } $line = atopet($line); $out .= addline($size,$line); } ($year, $mon, $mday, $hour, $min, $sec) = (localtime(time()))[5,4,3,2,1,0]; $out .= addtitle($year+1900, sprintf("%02d %02d %02d:%02d:%02d ", $mon+1, $mday, $hour, $min, $sec)); $out .= "\x00\x00"; send_wsize($out); } # add a cbm basic line sub addline($$) { my $lnum = shift; my $line = shift; my $ret = ""; $ret = ".."; # fake line pointer $ret .= chr($lnum & 255); $ret .= chr($lnum >> 8); $ret .= substr(" ", 0, 4-length($lnum)); $ret .= $line; $ret .= " \x00"; return $ret; } # addtitle doesn't pad with spaces sub addtitle($$) { my $lnum = shift; my $line = shift; my $ret = ""; $ret = ".."; # fake line pointer $ret .= chr($lnum & 255); $ret .= chr($lnum >> 8); $ret .= $line; $ret .= "\x00"; return $ret; } # read current directory sub getdir() { my @d; my $entry; opendir(DH, ".") || die "couldn't read dir"; while ($entry = readdir(DH)) { # next if ($entry =~ /^\.\.?$/); push(@d, $entry); } closedir(DH); return(sort(@d)); } return(1);