X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=pm2pl;h=699293639bf78381ecd44e2bdc93eb4fe50adcd2;hb=4dc97d117696dc46df00f151808e03a21b637872;hp=5c492606e88b13e5dd3cd34519885469f71e0c28;hpb=4107c18ce17515557235b1ac91ab586b46098727;p=perltidy.git diff --git a/pm2pl b/pm2pl index 5c49260..6992936 100755 --- a/pm2pl +++ b/pm2pl @@ -1,84 +1,146 @@ #!/usr/bin/env perl use strict; +use Getopt::Long; -# This script will recombine the perltidy binary script and all of its -# modules into a single, monolithic script, which is how it was -# originally distributed. It might be useful for users who have -# difficulty installing modules, or prefer not to. +my $usage = < 1 [ for extra testing when debugging ] +EOM + +my @option_string = qw( + h + o:s + D +); + +my %Opts = (); +if ( !GetOptions( \%Opts, @option_string ) ) { + die "Programming Bug: error in setting default options"; +} + +if ( $Opts{h} ) { + print $usage; + exit 1; +} # This should work for a system with File::Spec, # and for older Windows/Unix systems without File::Spec. -my $script = 'bin/perltidy'; -my $module = 'lib/Perl/Tidy.pm'; +my $script = 'bin/perltidy'; +my @modules = qw( + lib/Perl/Tidy.pm + lib/Perl/Tidy/Debugger.pm + lib/Perl/Tidy/DevNull.pm + lib/Perl/Tidy/Diagnostics.pm + lib/Perl/Tidy/FileWriter.pm + lib/Perl/Tidy/Formatter.pm + lib/Perl/Tidy/HtmlWriter.pm + lib/Perl/Tidy/IOScalar.pm + lib/Perl/Tidy/IOScalarArray.pm + lib/Perl/Tidy/IndentationItem.pm + lib/Perl/Tidy/LineBuffer.pm + lib/Perl/Tidy/LineSink.pm + lib/Perl/Tidy/LineSource.pm + lib/Perl/Tidy/Logger.pm + lib/Perl/Tidy/Tokenizer.pm + lib/Perl/Tidy/VerticalAligner.pm + lib/Perl/Tidy/VerticalAligner/Alignment.pm + lib/Perl/Tidy/VerticalAligner/Line.pm +); + +# try to make the pathnames system independent eval "use File::Spec;"; my $missing_file_spec = $@; unless ($missing_file_spec) { - $script = File::Spec->catfile( 'bin', 'perltidy' ); - $module = File::Spec->catfile( 'lib', 'Perl', 'Tidy.pm' ); + $script = File::Spec->catfile( split '/', $script ); + foreach my $module (@modules) { + $module = File::Spec->catfile( split '/', $module ); + } } -my $outfile = "perltidy"; -open OUTFILE, "> $outfile" or die "can't open file '$outfile' : $!\n"; -print "Creating file '$outfile' ....\n "; +my $VERSION = get_version("lib/Perl/Tidy.pm"); +my $outfile = "perltidy-$VERSION.pl"; +if ( $Opts{o} ) { $outfile = $Opts{o} } +my $fh_out; +open( $fh_out,, ">", $outfile ) or die "can't open file '$outfile' : $!\n"; +print "Creating standalone perltidy script '$outfile' ...."; # first, open the script and copy the first (hash-bang) line # (Note: forward slashes in file names here will work in Windows) -open SCRIPT, "< $script" or die "can't open script file '$script' : $!\n"; -my $hash_bang =