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

Re: [MacPerl] input for "run



        Reply to:   RE>[MacPerl] input for "run macperl"?

One way I do it is to have the script have the option of asking or
forcing this file list to exist the way I want for a test.  This may
not be a global fix but it does work.  See the set_options routine
below:

sub set_options{ # set_options or return 0

  local($ans);   # return answer positive for good options (0 for error)
  local($opt_prompt);
  local(@opts);

#
# Get options that apply to all files
#

  $opt_prompt = "-v (verbose)"; # user prompt
  @opts = ('v');    # option spec (see newgetopts)
# @opts = ('c:i','d=s','v'); # sample options (integer,string,single opt)
#   creates opt_c, opt_d and opt_v; opt_d is mandatory, opt_c is optional
#   options may be a word or number, 'file=s' or 'words:i' or '2'

# $ans = &get_options($opt_prompt,"", "-v",@opts); # force options
  $ans = &get_options($opt_prompt,"-v","",@opts);  # prompt user

  return $ans;
}

This requires a slightly different version of the ssUtilities
routine which implements "get_options".  That routine was
changed as shown below:

sub get_options {
#
#   Subroutine for getting simple command line options in Macperl
#   Works unmodified cross-platform on Mac and Unix perls
#     $macprompt    - prompt to display to user to enter options
#     $defprompt    - default options to show on the option line
#     $force_args   - if specified, a MAC will use these arguments
#     @options_spec - list of options given to NGetOpt
#                       see newgetopt.pl for documentation
#                       a list must be last as a param for @_
#       Returns 0 on an error or a Mac Cancel
#
    local($macprompt,$defprompt,$force_args,@options_spec) = @_;     # the
prompt for MacPerl'Ask
#    print "Prompt: $macprompt\nOption spec: @options_spec\nDef:
$defprompt\nForced: $force_args\n";
    if ($MacPerl'Version) {    # are we in MacPerl?
        if ( $force_args ne "" ) { # accept arguments passed in
          $args_user_entered = $force_args; 
        } else {                  # Get command line args by prompt
          $args_user_entered = &MacPerl'Ask($macprompt,$defprompt);
          return 0 if ! defined $args_user_entered;
        }   
        # we shall allow backslashes, so escape them
        $args_user_entered = &escape_backslashes($args_user_entered);
        require 'shellwords.pl';
        local(@options) = &shellwords($args_user_entered); 
        # nb: we add argv to options in case files were passed by a drag'n
drop
        push (@options,@ARGV);    # options must come first
        @ARGV = &putback_backslashes(@options);
        }
    require 'newgetopt.pl';       # use newgetopt library to parse the options
    local($result) = &NGetOpt(@options_spec);
    return ($result);
    }

This gives you a portable version that works in Unix as well.  Note
the usage of newgetopt.pl which does things a little bit different.
It uses a list of options verses a string.

At any rate this give you consistent droplets on the Mac that are
not a problem for the unix side.  The ssUtilities help insolate the
platform differences between the Mac and Unix.

Good luck,

David Scott                             David_Scott@Sequana.com
Sequana Therapeutics
La Jolla, CA
--------------------------------------
Date: 7/11/96 3:15 PM
To: David Scott
From: Branimir Boguraev

is there an easy mechanism for supplying file names to a script, when it 
is being run under the BBEdit "Run MacPerl" extension --- something which 
emulates STDIN or ARGV binding?  

thanks,

bran boguraev
apple computer