[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-Toolbox] Bugs in StandardFile.pl? GET/PUT file dialogs



On Mon, Jul 19, 1999 at 01:06:55AM +0900, robinmcf@altern.org wrote:
> (crossposted to both TOOLBOX,and MACPERL lists)
> I've been working on a couple of scripts that needed more flexibility than
> hard coded paths. I dug a couple of examples out of the "mac" folder in the
> MacPerl folder of a GETFILE and  a PUTFILE dialog which I adapted for my
> needs.
> 
> However as soon as the script starts up, I get some odd errors thrown up
> before the GETFILE dialog (the first to be called) appears . Aside from
> this the script does as it's expected it opens the requested file, and
> saves the file according to the choices made in the PUTFILE dialog - with
> the exception that I can't seem to catch the "CANCEL" event from the PUTFILE
> 
> Is this a bug in  StandardFile.pl ?
> 
> ##--the offending dialogs:
> 
>       #!/usr/bin/perl -w
> 
>       use strict;
>       use Mac::Files;
>       require "StandardFile.pl";
>       $|=1; #tells $| to let rip and spew stuff as fast as it can be
> politely received
>       my($text,$path,$output );
> 
> 
> #getfile dialog
>       $text= &StandardFile::GetFile("TEXT");
>       print"$text\n";
> 
> #putfile dialog
>       $path=`pwd`;
>       $output = &StandardFile::PutFile("what shall we call it?", "::new.file");
>       print "$output\n";
> 
> 
> ##--the error messages:

These are actually warnings...


> # Use of uninitialized value.
> File 'HD:MacPerl Ÿ:lib:StandardFile.pl'; Line 42

This is indded because of a bug in StandardFile.pl.

The first argument to GetFile() is the prompt, unless it is four characters
long, in which case it is a type.  The last argument is the default
something-or-other (not documented?) unless, once again, it is four
characters long.  But if there's only one argument, then $default will be
undefined.  (If your default is supposed to be four characters long, I
guess you're screwed.)

This is *very* poor design.  Better design would have @types passed as an
array reference, before the optional arguments, rather than a flat list
_flanked_ by two _optional_ arguments.


Current, broken code:

sub GetFile {
    local($prompt,@types) = @_;
    local($default) = pop(@types);
     
     if (length($prompt) == 4) {
        unshift(@types, $prompt);
        $prompt = "";
    }
     if (length($default) == 4) {
          push(@types, $default);
        $default = "";
    }


Better code:

sub GetFile {
    local($prompt,@types) = @_;
    local($default) = pop(@types);

    if (not defined $default) {
        $default = "";
    }
    
    if (length($prompt) == 4) {
        unshift(@types, $prompt);
        $prompt = "";
    }

    if (length($default) == 4) {
        push(@types, $default);
        $default = "";
    }



> # Use of uninitialized value.
> File 'HD:MacPerl Ÿ:lib:StandardFile.pl'; Line 48
>  (generated at before the GETFILE window is opened)

Same problem: $default is still undefined.


> 
> 
> # Use of uninitialized value.
> File '<AppleEvent>'; Line 18
> (generated by pressing the CANCEL button on the PUTFILE dialog)

Sorry, I don't know enough about how StandardFile.pl works to figure that
one out.


Ronald

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-toolbox-request@macperl.org