[comp.sys.apple2] Q: Orca/C and p2cstr

bkahn@archive.webo.dg.com (Bruce Kahn) (10/04/90)

  Ive been trying to finalize some changes to a desktop program Im creating and
have found an oddity w/Orca/C (or so I think).  After returning from a call
to SFGetFile(), I check replyPtr->good and if its TRUE, I attempt to open
the file in replyPtr->filename.  Since Im writing in C and replyPtr->filename
is a Pascal string, I tried to use the following (w/SFReplyPtr replyPtr;):

	fp = fopen(p2cstr(replyPtr->filename,"wb"));

but that didnt work.  I then tried:

	fp = fopen(p2cstr(&replyPtr->filename,"wb"));

but that also failed. 
  In my frustration, I dumped the output of p2cstr(replyPtr->filename) and
p2cstr(&replyPtr->filename) to a log file and got basically garbage or random
junk.  I hacked my own p2cstr() for doing an in-place conversion and things
work just fine.  Can anyone tell me why p2cstr didnt work for me or is there
a known bug w/p2cstr??



--
                                          Bruce (bkahn@archive.webo.dg.com or
                                                 kahn@adam.dg.com)
  
  Standard disclaimers apply, except where prohibited by law...

gwyn@smoke.BRL.MIL (Doug Gwyn) (10/05/90)

In article <1020@dg.dg.com> bkahn@archive.webo.dg.com (Bruce Kahn) writes:
>	fp = fopen(p2cstr(&replyPtr->filename,"wb"));

Did you really include "wb" as a p2cstr() argument rather than an fopen()
argument?  If so, that's one of your problems.

jb10320@uxa.cso.uiuc.edu (Desdinova) (10/05/90)

In article <1020@dg.dg.com> bkahn@archive.webo.dg.com (Bruce Kahn) writes:
>
>  Ive been trying to finalize some changes to a desktop program Im creating and
>have found an oddity w/Orca/C (or so I think).  After returning from a call
>to SFGetFile(), I check replyPtr->good and if its TRUE, I attempt to open
>the file in replyPtr->filename.  Since Im writing in C and replyPtr->filename
>is a Pascal string, I tried to use the following (w/SFReplyPtr replyPtr;):
>
>	fp = fopen(p2cstr(replyPtr->filename,"wb"));
>
>but that didnt work.  I then tried:

   No doubt. I don't believe the Orca "p2cstr" works with Class 1 GS/OS
strings.  I imagine it works only with 1-byte length Pascal-type strings.

>	fp = fopen(p2cstr(&replyPtr->filename,"wb"));

>but that also failed. 
>  In my frustration, I dumped the output of p2cstr(replyPtr->filename) and
>p2cstr(&replyPtr->filename) to a log file and got basically garbage or random
>junk.  I hacked my own p2cstr() for doing an in-place conversion and things
>work just fine.  Can anyone tell me why p2cstr didnt work for me or is there
>a known bug w/p2cstr??

   There's lots of known bugs in Orca/C, but I don't think this is one of
them. I'll check my manual when I get home and make sure.

>                                          Bruce (bkahn@archive.webo.dg.com or
>                                                 kahn@adam.dg.com)
>  Standard disclaimers apply, except where prohibited by law...


--
Jawaid Bazyar               | Blondes in big black cars look better wearing
Senior/Computer Engineering | their dark sunglasses at night. (unk. wierdo)
jb10320@uxa.cso.uiuc.edu    |      The gin, the gin, glows in the Dark!
                            |                             (B O'Cult)
Apple II Users Unite! Storm the New Product Announcement and Demand Justice!

bkahn@dg-rtp.dg.com (Bruce Kahn) (10/08/90)

In article <14026@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
|> In article <1020@dg.dg.com> bkahn@archive.webo.dg.com (Bruce Kahn) writes:
|> >	fp = fopen(p2cstr(&replyPtr->filename,"wb"));
|> 
|> Did you really include "wb" as a p2cstr() argument rather than an fopen()
|> argument?  If so, that's one of your problems.

  Typo on my part.  The line SHOULD have read:

	fp = fopen(p2cstr(&replyPtr->filename),"wb");

Any other ideas??
--
                                          Bruce (bkahn@archive.webo.dg.com or
                                                 kahn@adam.dg.com)
  
  Standard disclaimers apply, except where prohibited by law...

bkahn@archive.webo.dg.com (Bruce Kahn) (10/08/90)

In article <1990Oct5.154015.3147@ux1.cso.uiuc.edu>,
jb10320@uxa.cso.uiuc.edu (Desdinova) writes:
|> In article <1020@dg.dg.com> bkahn@archive.webo.dg.com (Bruce Kahn)
writes:
|> >	fp = fopen(p2cstr(replyPtr->filename,"wb"));
|> >but that didnt work.  I then tried:
|> 
|>    No doubt. I don't believe the Orca "p2cstr" works with Class 1
GS/OS
|> strings.  I imagine it works only with 1-byte length Pascal-type
strings.

  The routine I used to do my in-place conversion was:
	int	nameLen;
	nameLen = replyPtr->filename[0];
	for (loop = 0; loop < nameLen; loop++)
		replyPtr->filename[loop] = replyPtr->filename[loop+1];
	replyPtr->filename[nameLen] = 0;

Since characters are 1 byte, my routine also assumes a 1-byte length
Pascal-type
string.  Since Pascal type strings can be a max of 255 characters long,
they
should only be prefixed by a 1 byte length value.  Of course, things may
have
changed since I took Pascal in college 3 years ago... :)

  For my gratification (I dont have my manuals here), what are the
various
classes of GS/OS strings?  Or better still, which manual should I check
out to
see the actual Apple definitions?

|> --
|> Jawaid Bazyar               | Blondes in big black cars look better
wearing
|> Senior/Computer Engineering | their dark sunglasses at night. (unk.
wierdo)
|> jb10320@uxa.cso.uiuc.edu    |      The gin, the gin, glows in the
Dark!
|>                             |                             (B O'Cult)
|> Apple II Users Unite! Storm the New Product Announcement and Demand
Justice!

--
                                          Bruce
(bkahn@archive.webo.dg.com or
                                                 kahn@adam.dg.com)
  
  Standard disclaimers apply, except where prohibited by law...

jb10320@uxa.cso.uiuc.edu (Desdinova) (10/09/90)

In article <1032@dg.dg.com> bkahn@archive.webo.dg.com (Bruce Kahn) writes:
>In article <1990Oct5.154015.3147@ux1.cso.uiuc.edu>,
>jb10320@uxa.cso.uiuc.edu (Desdinova) writes:
>|> In article <1020@dg.dg.com> bkahn@archive.webo.dg.com (Bruce Kahn)
>writes:
>
>  The routine I used to do my in-place conversion was:
>	int	nameLen;
>	nameLen = replyPtr->filename[0];
>	for (loop = 0; loop < nameLen; loop++)
>		replyPtr->filename[loop] = replyPtr->filename[loop+1];
>	replyPtr->filename[nameLen] = 0;

   I don't see anything wrong with the above code, which is good, since
you said it works.  There may be something wrong with the library after
all. I've never used them since I had to write my own routines to deal
with Class-1 strings.

>Since characters are 1 byte, my routine also assumes a 1-byte length 
>Pascal-type string.  Since Pascal type strings can be a max of 255 characters
>long, they should only be prefixed by a 1 byte length value.  Of course, things
>may have changed since I took Pascal in college 3 years ago... :)

Nope. Are you using and GS/OS specific calls? (NOT Prodos 16, they each have
different call mechanisms).  Prodos 16 uses 1-byte length strings,
GS/OS uses 2-byte lengths.

>  For my gratification (I dont have my manuals here), what are the various
>classes of GS/OS strings?  Or better still, which manual should I check out to
>see the actual Apple definitions?

   Definitely the GS/OS manuals.  Also, check out the ORCA/C header files
for GS/OS, they'll tell you a lot 
>|> --
>|> Jawaid Bazyar               | Blondes in big black cars look better

>                                          Bruce
>(bkahn@archive.webo.dg.com or kahn@adam.dg.com)


--
Jawaid Bazyar               | Blondes in big black cars look better wearing
Senior/Computer Engineering | their dark sunglasses at night. (unk. wierdo)
jb10320@uxa.cso.uiuc.edu    |      The gin, the gin, glows in the Dark!
                            |                             (B O'Cult)
Apple II Users Unite! Storm the New Product Announcement and Demand Justice!