#! /usr/bin/perl #--------------------------------------------------------------------- # $Id: prodos 1719 2007-03-24 17:35:39Z cjm $ # Copyright 1996 Christopher J. Madsen # # This program is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the # GNU General Public License or the Artistic License for more details. # # A command-line shell for accessing ProDOS disk images #--------------------------------------------------------------------- use AppleII::ProDOS qw(0.016 shell_wc); use Term::ReadLine; our $VERSION = '0.08'; my $maxscreen = 20; my $pager = $ENV{PAGER}; my $shell = $ENV{SHELL} || '/bin/sh'; #--------------------------------------------------------------------- my @commands = qw(cd dir get lcd ls ll mkdir put pwd quit type); my $term = Term::ReadLine->new('ProDOS Shell'); if ($term->ReadLine eq 'Term::ReadLine::Perl') { $readline::rl_basic_word_break_characters = ". \t\n"; $readline::rl_completer_word_break_characters = $readline::rl_completer_word_break_characters = " \t\n"; $readline::rl_completion_function = $readline::rl_completion_function = \&complete_word; } # end if readline.pl my $vol = AppleII::ProDOS->open($ARGV[0],'w'); print $vol->path,"\n"; while (1) { $_ = $term->readline(']'); next unless /\S/; $term->addhistory($_); my ($cmd, $arg) = /^\s*(\S+)\s*(.+?)?\s*$/; $cmd = lc $cmd; $arg = $arg || ''; last if $cmd =~ /^q(?:uit)?$/; eval { CMD: { print($vol->path,"\n"), next CMD if $cmd eq 'pwd'; print("Use `dir' or `type' instead\a\n"),next CMD if $cmd eq 'cat'; print($vol->path($arg),"\n"), next CMD if $cmd eq 'cd'; display($vol->catalog,"\n"), next CMD if $cmd =~ /^l[sl]$/ or $cmd eq 'dir' or $cmd eq 'v'; display($vol->get_file($arg)->as_text),next CMD if $cmd eq 'type'; get_file($vol,$arg), next CMD if $cmd eq 'get'; put_file($vol,$arg), next CMD if $cmd eq 'put'; $vol->new_dir($arg), next CMD if $cmd eq 'mkdir' or $cmd eq 'md'; (chdir($arg) || print "Bad directory `$arg'\a\n"), next CMD if $cmd eq 'lcd'; system($shell), next CMD if $cmd eq '!'; system(substr("$cmd $arg",1)), next CMD if $cmd =~ /^!/; print "Bad command `$cmd'\a\n"; } # end CMD }; # end eval if ($@) { $@ =~ /^LibA2: (.+) at \S+ line / or die $@; print $1,"\a\n"; } } # end forever exit; #===================================================================== # Subroutines: #--------------------------------------------------------------------- sub complete_word { my ($text, $line, $start) = @_; return grep(/^$text/, @commands) if $start == 0; return &readline::rl_filename_list if $line =~ /^(?:put|lcd)\b/; return $vol->dir->list_matches(shell_wc("$text*"),'DIR') if $line =~ /^cd\b/; $vol->dir->list_matches(shell_wc("$text*"),'!DIR'); } # end complete_word #--------------------------------------------------------------------- sub display { my $text = (scalar(@_) > 1 ? join('',@_) : $_[0]); my $lines = $text =~ tr/\n//; # Count the newlines if ($lines > $maxscreen and $pager) { open(PAGER,"|$pager") or die; print PAGER $text; close(PAGER); } else { print $text; } } # end display #--------------------------------------------------------------------- sub get_file { my ($vol, $arg) = @_; die "$arg already exists" if -e $arg; my $file = $vol->get_file($arg); open(OUT, ">$arg") or die; binmode OUT; print OUT $file->data; close OUT; } # end get_file #--------------------------------------------------------------------- sub put_file { my ($vol, $arg) = @_; open(IN,"<$arg") or die; binmode IN; my $size = (stat IN)[7]; my $data = ''; read(IN, $data, $size) == $size or die; close IN; my $file = AppleII::ProDOS::File->new($arg, $data); if ($arg =~ /\.s[hd]k$/i) { $file->type(0xE0); $file->auxtype(0x8102); } $vol->put_file($file); } # end put_file __END__ =head1 NAME prodos - Manipulate Apple II ProDOS disk image files =head1 SYNOPSIS B IMAGE-FILE =head1 DESCRIPTION B provides a Unix/MS-DOS style command-line shell for manipulating the contents of a disk image file containing an Apple II ProDOS volume. =head1 COMMANDS =over 5 =item B I Change the current directory on the ProDOS volume to I. Use B to change the directory on the native filesystem. =item B, B, B, or B List the contents of the current directory on the ProDOS volume. =item B I Copy I from the ProDOS volume to the native filesystem. =item B I Change the current directory on the native filesystem to I. Use B to change the directory on the ProDOS volume. =item B I Create a new subdirectory on the ProDOS volume. You can use B as an alias to B. =item B I Copy I from the native filesystem to the ProDOS volume. =item B List the name of the current directory on the ProDOS volume. =item B Exit B. =item B I Display the contents of I, which should be a text file. =item B Start a subshell. =back =head1 REQUIREMENTS B requires Term::ReadLine, which is now distributed with Perl. For best results, you should also have Term::ReadLine::Perl, which is available on CPAN. It also requires the modules AppleII::ProDOS and AppleII::Disk, which are included with LibA2. =head1 ENVIRONMENT PAGER The pager to use for long displays SHELL The shell to start with the ! command =head1 BUGS B doesn't have a B command, because under ProDOS that means B and under Unix it means B. To avoid confusion, I left it out. =head1 AUTHOR Christopher J. Madsen C<< >> Please report any bugs or feature requests to C<< >>, or through the web interface at L =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut