#!/usr/bin/env perl

use Modern::Perl;
use ZX81::Tape qw(make_p);
use Getopt::Std;

my $USAGE = "Usage: $0 [-o output_file.p] input_file.bas\n";
getopts( 'o:', \my %opts ) or die $USAGE;
@ARGV == 1                 or die $USAGE;
my $input_file  = shift @ARGV;
my $output_file = $opts{o}
  // do { my $f = $input_file; $f =~ s/\.bas$/.p/; $f };

make_p( $input_file, $output_file );

__END__

#------------------------------------------------------------------------------

=pod

=head1 NAME

zx81_make_p - Make a ZX81 .p file from a .bas file

=head1 USAGE

    zx81_make_p [-o output_file.p] input_file.bas

=head1 DESCRIPTION

This script takes a ZX81 BASIC source file (.bas) and generates a corresponding
ZX81 program file (.p). If the output file is not specified with the -o option,
the output file will have the same name as the input file but with a .p extension.

=head1 SEE ALSO

L<ZX81::Tape>

=head1 AUTHOR

Paulo Custodio

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2026 Paulo Custodio.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut

