[comp.sys.apple] a few GS programming questions

hartkopf@tramp.Colorado.EDU (Jeff Hartkopf) (09/19/89)

A few GS toolbox programming questions:

1)  How do you convert an icon from the form for DrawIcon() to the form
    for NewDItem(..., iconItem, ...), where the icon is initialized with
    the standard C array initializers?  For example, to make an icon of
    a 2 x 2 square of black dots (each dot 2 640-mode pixels wide) in the
    DrawIcon() format, I'd do

    square_icon = {0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00};
    ...
    DrawIcon(square_icon, 0, 10, 10);  /* or whatever */

    So what do I need to do to make that icon work for NewDItem()?

2)  Is there a toolbox call to find out whether the application is currently
    in 640- or 320-mode?  (For example, if an NDA needs to know.)

3)  Does anyone have a piece of code (Pascal or C) that will copy files (of
    any type, including extended files)?  Or at least an algorithm for me?

Thanks very much for any help.


Jeff Hartkopf

Internet:
hartkopf@tramp.Colorado.EDU

jazzman@claris.com (Sydney R. Polk) (09/19/89)

From article <11770@boulder.Colorado.EDU>, by hartkopf@tramp.Colorado.EDU (Jeff Hartkopf):
> A few GS toolbox programming questions:
> 
> 1)  How do you convert an icon from the form for DrawIcon() to the form
>     for NewDItem(..., iconItem, ...), where the icon is initialized with
>     the standard C array initializers?  For example, to make an icon of
>     a 2 x 2 square of black dots (each dot 2 640-mode pixels wide) in the
>     DrawIcon() format, I'd do
> 
>     square_icon = {0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00};
>     ...
>     DrawIcon(square_icon, 0, 10, 10);  /* or whatever */
Yuch!  I'll let someone else do this.
> 2)  Is there a toolbox call to find out whether the application is currently
>     in 640- or 320-mode?  (For example, if an NDA needs to know.)
_GetMasterSCB in QuickDrawII.

> 3)  Does anyone have a piece of code (Pascal or C) that will copy files (of
>     any type, including extended files)?  Or at least an algorithm for me?
Oh, come on.  This isn't that bad.

Algorithm:
	(Does not take many things into account)
	_GetFileInfo on source
	_NewHandle for a handle that's the size of the larger of the two
	forks.
	_Create the destination
	_Open the source
	_Read the data fork
	_Write the data fork
	_Read the resource fork
	_Write the resource fork
	_Close both files

This is the way I do it in the exerciser when I am buried in an application.
This assumes you have enough memory.  You might want to set up a buffer
that is fixed size and read and write that much at a time.  Copying
directories is a lot trickier.  You have to do a _getdirentry call for
all of the files, and you have to recurse on each of the directories.

And then there is the i/o handling (disk swaps, AppleShare, disk full, etc.)

A good 2-3 month project is to write a simple file utility package, including
backups for hard-drives (splitting files too big for floppies, etc.)

Wish I had the time.  Could be fun.

-- 
Syd Polk           | Wherever you go, there you are.
jazzman@claris.com | Let the music be your light.
GO 'STROS!         | These opinions are mine.  Any resemblence to other
GO RICE!           |  opinions, real or fictitious, is purely coincidence.

dlyons@Apple.COM (David Lyons) (09/22/89)

In article <10560@claris.com> jazzman@claris.com (Sydney R. Polk) writes:
>From article <11770@boulder.Colorado.EDU>, by hartkopf@tramp.Colorado.EDU (Jeff Hartkopf):
>> A few GS toolbox programming questions:
>> [...]
>> 2)  Is there a toolbox call to find out whether the application is currently
>>     in 640- or 320-mode?  (For example, if an NDA needs to know.)
>_GetMasterSCB in QuickDrawII.

Yes.  Specifically, check bit 7 ("AND" the result with $0080; 0 means 320 mode,
nonzero means 640 mode).  Some other bits in the result are used, and the rest
are reserved.

>> 3)  Does anyone have a piece of code (Pascal or C) that will copy files (of
>>     any type, including extended files)?  Or at least an algorithm for me?
>Oh, come on.  This isn't that bad.
>
>Algorithm:
>	(Does not take many things into account)
>	_GetFileInfo on source
>	_NewHandle for a handle that's the size of the larger of the two
>	forks.
>	_Create the destination
>	_Open the source
>	_Read the data fork
>	_Write the data fork
>	_Read the resource fork
>	_Write the resource fork
>	_Close both files
>
Yup, that about does it...you also want to do a SetFileInfo on the destination,
using the same information you got from GetFileInfo on the source.  To allow
for copying a file into an AppleShare "drop box", do the SetFileInfo *before*
closing the destination file.  (Once you close a file in somebody else's drop
box, it becomes invisible to you.)  Doing the SetFileInfo before the Close
works fine in general:  no need to check for AppleShare.
-- 

 --Dave Lyons, Apple Computer, Inc.          |   DAL Systems
   AppleLink--Apple Edition: DAVE.LYONS      |   P.O. Box 875
   AppleLink--Personal Edition: Dave Lyons   |   Cupertino, CA 95015-0875
   GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
   Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons

   My opinions are my own, not Apple's.