[comp.sys.mac.hypercard] opening files from an XCMD, revisited

moore@june.cs.washington.edu (Charles Moore) (04/22/89)

Several people responded to my earlier note by saying that I should use
the File Manager routines, FSOpen, FSRead, etc. instead of the Lightspeed
C stdio routines.  Thank you for that help.  Regardless of whether it is
possible to use the stdio routines by including the stdio source code
in the code resource project, I have taken the advice of the majority and
switched to the Toolbox File Manager.  Unfortunately, I still have the
same problem.  In a stand alone application I can use the File Manager
routines just fine to access an existing file.  The same code in an
XCMD, however, results in a "file not found" error.  This is somewhat
baffling.  Could it be that Hypercard has somehow twiddled the default
volume information or is there some other explanation?

Charles Moore

tim@hoptoad.uucp (Tim Maroney) (04/25/89)

In article <7947@june.cs.washington.edu> moore@june.cs.washington.edu (Charles
Moore) writes:
>In a stand alone application I can use the File Manager
>routines just fine to access an existing file.  The same code in an
>XCMD, however, results in a "file not found" error.  This is somewhat
>baffling.  Could it be that Hypercard has somehow twiddled the default
>volume information or is there some other explanation?

Are you getting the volume reference number from Standard File?  If so,
the default volume/directory is irrelevant.  Otherwise, if you are
passing zero as the volume reference number, HyperCard may do whatever
it wants with the defaults, and your code will break.  (My guess is the
default vol/dir is always the same as the vol/dir of the current stack,
but I haven't checked this; even if it's true, you can't count on it
staying the same in future releases.)  You need to pass a correct
volume reference number from Standard File.  If you can't use Standard
File, then you'll have to descend one more level into the file system
and use the HFS calls.  If you are currently using a fixed file name
and reference number zero, I recommend using Standard File for a "Where
is..." dialog when your FSOpen call returns a file not found error.

Changing back to C standard I/O wouldn't work, because unless you pass
a full file name (which takes the HFS calls to generate) fopen works
from the default vol/dir as well, just like an FSOpen with volume
reference number zero.  (Tim Dierks has pointed out that it may be
possible to use stdio by recompiling it, but if it requires an
initialization routine that's normally called invisibly from the
application run-time startup code, then you'll have to call that
yourself.)
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"I see little divinity about them or you.  You talk to me of Christianity
 when you are in the act of hanging your enemies.  Was there ever such
 blasphemous nonsense!" - Shaw, "The Devil's Disciple"