Hello all,

I was too keen to use perltidy (http://perltidy.sourceforge.net)
under MacPerl.

It produces nicely formatted source code plus html output, plus ...
great, a must have.

If you want to use it you have to download the Unix version and
unpack it (probably with the "untarzipme" droplet. I used the
newest 5.6.1b4 version.

Replace the package main at the end of "perltidy" with the code
below.

You can then start the program directly from MacPerl or "Run in
MacPerl" from BBEdit 6 or even better make a droplet yourself
and d&d source files to it. Some useful versions are
  -html Macintosh HD:projects:mytest.pl
  -st Macintosh HD:projects:mytest.pl
  -o=output.pl Macintosh HD:projects:mytest.pl

The command line parsing I added is a quick hack. If you can
improve it - please let me know.


Best regards,
Axel.



### patch to "perltidy"

package main;

# give Macs a chance to provide command line parameters
my $MACOS = ( $^O =~ /Mac/ ) || 0;
if ($MACOS) {
    my $ans =
      MacPerl::Ask( 'Please enter @ARGV (-h for help)',
        defined $ARGV[0] ? $ARGV[0] : "" );
    if ( $ans =~ /\b-h\b/i ) { @ARGV = ('-h') }
    else {
        my $args = main::splitargs($ans);
        @ARGV = @$args;
    }
}

PerlTidy::perltidy();

sub splitargs {
    my @return;

    my $s = shift;
    $s =~ s/^\s*//;
    $s =~ s/\s*$//;

    my @args = split //, $s;
    my $inparam   = 0;
    my $fileparam = 0;
    my $param     = 0;
    my $pos       = 0;
    for (@args) {
        if ( /^-/ and !$inparam and !$fileparam ) {
            $return[$param] = $_;
            $inparam   = 1;
            $fileparam = 0;
            $pos++;
        }
        elsif ( $inparam and !$fileparam ) {
            $return[$param] .= $_;
            if ( $args[ $pos + 1 ] and $args[ $pos + 1 ] eq ' ' ) {
                $inparam   = 0;
                $fileparam = 1;
                $param++;
            }
            $pos++;
        }
        elsif ( !$inparam and $fileparam ) {
            $return[$param] .= $_;
        }
        elsif ( !$inparam and !$fileparam ) {
            $return[$param] .= $_;
            $fileparam = 1;
        }
        else {
            warn "internal logic error\n";
        }
    }
    $return[-1] =~ s/^\s+//;
    return \@return;
}

__END__

--
----------------------------------------------------------------------
Axel Rose, Springer & Jacoby Digital GmbH & Co. KG, mailto:[EMAIL PROTECTED]
  pub PGP key 1024/A21CB825 E0E4 BC69 E001 96E9  2EFD 86CA 9CA1 AAC5
  "... denn alles, was entsteht, ist wert, da� es zugrunde geht ..."

Reply via email to