On Sat, Feb 03, 2001 at 07:47:23PM +0000, James Taylor wrote:
> In <URL:news:local.riscos-perl> on Sat 03 Feb, Nicholas Clark wrote:
> >
> > Aagh. In File::Spec I find references to RISCOS::File::Spec but
> > 1: it's buggy ($^O is "riscos", not "RISCOS")
> > 2: I can't find a copy anywhere of RISCOS::File::Spec
> 
> Whoops! :-(

Quite


> Yes, I see the motivation. I've tried reading the RISCOS::FileSpec
> documentation but get very confused when it starts to talk about all
> the different cases under which it does certain things. I decided to
> steer well clear of platform specific modules and write something that
> would work without needing to know what platform it was running on.
> Unfortunately, this does not seem to be possible. I'll try asking the
> folks on comp.lang.perl.misc it's just that they won't be aware of
> problems that might exists in the RISC OS version's implementation of
> supposedly platform independent modules.

The RISC OS version's core modules pass the core regression tests.
[yes, some of the core tests were modified. But the core tests make
assumptions such as the size of a file open for writing is the same
when you ask for the size by filename, or by asking the file handle,
and so forth]

So if you write something that doesn't use any module from the RISCOS::
hierarchy it should be portable, but you will need to pass in ready
mangled filenames on the command line. (but see below for a suggestion
on how to pass in RISC OS filenames with)

(If you hardwire "/" as the directory separator it should work most places.
If you use File::Spec it should work most anywhere)

Yes, if I'd not screwed up and lost where RISCOS::File::Spec you could
pass in RISC OS filenames on the command line, and everything still work
on a given platform. However, as your program wants to write out Unix
pathnames whichever platform it's running on somewhere, even using
File::Spec it is going to have to know how to do conversions.

I think the best way may be (not tested, sorry):

0: Don't "use" anything down the RISCOS tree.
1: Take your command line parameters, which are in RISC OS format and at
   the top of your script go

if ($^O eq 'riscos') {
   foreach (@ARGV) {
     $_ = RISCOS::Filespec::unixify($_)
   }
}

   to launder them into Unix form

2: and then proceed from there as if you're running on Unix, using File::Spec
   I didn't mess about with File::Spec::Unix, so it will be the same as
   anyone else's File::Spec::Unix

[and that code will run on non RISC OS as it never calls the undefined
function RISCOS::Filespec::unixify]

You still have the problem of what happens if you are running on (say) a
Mac, as your nicely File::Spec'd string will have ':' separating the
directories.

I suspect you'll need to do something like

@dirs = File::Spec->splitpath $path;    # $path is in native format
$unix_path = join '/', @dirs;

but I don't know what happens if the Mac directory has a '/' character in its
name.


Nicholas Clark

Reply via email to