Re: opening files whose names contain CRs?

2003-09-15 Thread Chris Nandor
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Peter N Lewis) wrote:

 At 7:23 PM -0700 13/9/03, Rich Morin wrote:
 This is interesting, but it doesn't answer the question of how one
 opens a file with this sort of name weirdness.  Basically, I think
 I've found a bug.  Prolly should check for it in Panther...
 
 There is no problem with opening a file with a CR in its name.
 
 The problem is only with a file who ends in any sequence of carriage 
 returns or line feeds.  It would appear these are stripped from the 
 file name by perl (presumably trying to be helpful so you can open a 
 file even if the name is read from a file and you forget to chomp it).

Yes, open() is magic and will open files similarly to if you passed it the 
name in the shell.  The solution is to use sysopen(), or to add a null to 
the end of the filename.

  $ cat  Icon^M 
  foo 
  ^C
  $ perl -e 'open $fh, Icon\r or die $!; print scalar $fh'
  No such file or directory at -e line 1.
  # add null
  $ perl -e 'open $fh, Icon\r\0 or die $!; print scalar $fh'
  foo
  # use sysopen
  $ perl -e 'sysopen $fh, Icon\r, 0 or die $!; print scalar $fh'
  foo
  $ 

-- 
Chris Nandor  [EMAIL PROTECTED]http://pudge.net/
Open Source Development Network[EMAIL PROTECTED] http://osdn.com/


Re: opening files whose names contain CRs?

2003-09-15 Thread Doug McNutt
At 07:19 -0700 9/15/03, Chris Nandor wrote, and I snipped:
  $ cat  Icon^M
  foo
  ^C
  $ perl -e 'open $fh, Icon\r or die $!; print scalar $fh'
  No such file or directory at -e line 1.
  # add null
  $ perl -e 'open $fh, Icon\r\0 or die $!; print scalar $fh'
  foo

The cat operation creates a text file with foo in the data, and only, fork.

Rich's problem is opening Icon\r files which are surely from Classic icon resource 
files zB (using MPW on a 9.1 box):

directory Ganymede:
files -x br 'Icon'n''  ### OPTION-d n is a return character in classic.
NameData Sz   Rsrc Sz
'Icon'n''   0b 1982b

If 'Icon'n'' is opened in perl in OS neXt, will perl read from the resource fork if 
there is no data fork? Or will it fail to open?  What about a write-enabled open? Will 
it write to the end of the resource fork or will it create a data fork?

  $ perl -e 'open $fh, Icon\r\0 or die'

--

Applescript syntax is like English spelling:
Roughly, but not thoroughly, thought through.


Re: opening files whose names contain CRs?

2003-09-15 Thread Chris Nandor
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Doug McNutt) wrote:

 The cat operation creates a text file with foo in the data, and only, fork.
 
 Rich's problem is opening Icon\r files which are surely from Classic icon 
 resource files zB (using MPW on a 9.1 box):

Yes, but he also was asking generally of how to handle files with the CR in 
them.  And I was just making the point that it is not OS-specific, and you 
can use nulls or sysopen.  Actually, I think there is another good way, too:

  $ perl -e 'open $fh, , Icon\r or die $!'

Yeah, three-arg open, which doesn't have the magic of two-arg open.

But yes, to get the actual data, you need the resource fork, using either 
Mac::Resources or similar, or opening namedfork/rsrc/:

  $ perl -e 'open $fh, , Icon\r/..namedfork/rsrc or die $!'


 If 'Icon'n'' is opened in perl in OS neXt, will perl read from the resource 
 fork if there is no data fork? Or will it fail to open?

This isn't specific to Mac OS X, it is handled by the OS.   open() and 
friends always open the data fork, unless passed a ..namedfork sort of thing 
(or unless you use POSIX open with the O_RSRC flag, which works on Mac OS, 
but NOT on Mac OS X, which is kinda weird, as it seems like it would be of 
use).  It will succeed on the open, but there will be no data.

-- 
Chris Nandor  [EMAIL PROTECTED]http://pudge.net/
Open Source Development Network[EMAIL PROTECTED] http://osdn.com/


Re: opening files whose names contain CRs?

2003-09-14 Thread Peter N Lewis
At 7:23 PM -0700 13/9/03, Rich Morin wrote:
At 8:14 PM -0600 9/13/03, Doug McNutt wrote:
Icon\r files appear when, in earlier Mac OS's, a folder ...
This is interesting, but it doesn't answer the question of how one
opens a file with this sort of name weirdness.  Basically, I think
I've found a bug.  Prolly should check for it in Panther...
There is no problem with opening a file with a CR in its name.

The problem is only with a file who ends in any sequence of carriage 
returns or line feeds.  It would appear these are stripped from the 
file name by perl (presumably trying to be helpful so you can open a 
file even if the name is read from a file and you forget to chomp it).

It looks like the pattern stripped is [\r\n]*$ which is a shame.  If 
it was \r?\n? then you could fix it by appending \r\n to the file 
name to ensure it was stripped and you were left with your name 
unmangled.

The only thing I can think of is:

try sysopen and see if it has the same hack
or
try Mac::Carbon and see if you can use it to access the file some how 
(or potentially rename the file, access it and rename it back).

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


opening files whose names contain CRs?

2003-09-13 Thread Rich Morin
While traversing one of Eudora's subdirectories, I encountered a file
whose name appears to be Icon\r, as:
  % pwd
  /Applications/Eudora Pro X/Eudora Spelling Checker
  % ls Ic*
  Icon?
  % ls Ic* | od -cx
  000I   c   o   n  \r  \n
49636f6e0d0a
  006
When I try to open this file

  open(TMP, $path) or die can't open '$path';

I get an error.  Help?

-r
--
email: [EMAIL PROTECTED]; phone: +1 650-873-7841
http://www.cfcl.com- Canta Forda Computer Laboratory
http://www.cfcl.com/Meta   - The FreeBSD Browser, Meta Project, etc.
http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series


Re: opening files whose names contain CRs?

2003-09-13 Thread Doug McNutt
Icon\r files appear when, in earlier Mac OS's, a folder - directory in UNIX parlance - 
was to be displayed by Finder with a special icon. I'm pretty sure the files are 
resource-only with no data fork.

You might try concatenating /..namedfork/rsrc to the path but if you do open it it 
will be difficult to interpret without the resources of something like ResEdit and I 
don't think that's an aqua APPL yet. . . . .

I am surprised by the 0d0a pair that you see. That doesn't happen in the MPW world of 
classic OS. It's possible that the ls operation adds the 0a prior to the pipe.


At 18:24 -0700 9/13/03, Rich Morin wrote:
While traversing one of Eudora's subdirectories, I encountered a file
whose name appears to be Icon\r, as:

  % pwd
  /Applications/Eudora Pro X/Eudora Spelling Checker
  % ls Ic*
  Icon?
  % ls Ic* | od -cx
  000I   c   o   n  \r  \n
49636f6e0d0a
  006

When I try to open this file

  open(TMP, $path) or die can't open '$path';

I get an error.  Help?


-- 
-- On the eighth day, about 6 kiloyears ago, the Lord realized that free will would 
make man ask what existed before the Creation. So He installed a few gigayears of 
history complete with a big bang and a fossilized record of evolution. --


Re: opening files whose names contain CRs?

2003-09-13 Thread Rich Morin
At 8:14 PM -0600 9/13/03, Doug McNutt wrote:
Icon\r files appear when, in earlier Mac OS's, a folder ...
This is interesting, but it doesn't answer the question of how one
opens a file with this sort of name weirdness.  Basically, I think
I've found a bug.  Prolly should check for it in Panther...
I am surprised by the 0d0a pair that you see. That doesn't happen in
the MPW world of classic OS. It's possible that the ls operation
adds the 0a prior to the pipe.
Well, ls is always going to end its lines with \r...

-r
--
email: [EMAIL PROTECTED]; phone: +1 650-873-7841
http://www.cfcl.com- Canta Forda Computer Laboratory
http://www.cfcl.com/Meta   - The FreeBSD Browser, Meta Project, etc.
http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series


Re: opening files whose names contain CRs?

2003-09-13 Thread Rich Morin
Well, ls is always going to end its lines with \r...
---
Well, ls is always going to end its lines with \n...
Sigh.

-r
--
email: [EMAIL PROTECTED]; phone: +1 650-873-7841
http://www.cfcl.com- Canta Forda Computer Laboratory
http://www.cfcl.com/Meta   - The FreeBSD Browser, Meta Project, etc.
http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series