[net.micro.mac] How to read the scrap for TextEdit

guido@boring.UUCP (10/16/85)

Here is an example of how to get the global Scrap into the TextEdit scrap
in SUMacC.
The global variables TEScrapHandle and TEScrapLen are actually #defines
in <mac/toolintf.h>:

#define	TEScrapHandle	(*(Handle *)0xab4)
#define	TEScrapLen	(*(short *)0xab0)

Note that I use long instead of int for the offset and length returned
by GetScrap; with SUMacC these are identical but other C systems may
have 2-byte ints, and the Toolbox really requires 4-byte longs here.
(Wish the SUMacC header files were more precise in this matter --
this could enhance portability between difference C systems!)

	Guido van Rossum, CWI, Amsterdam (guido@mcvax.UUCP)

static int scrap_count; /* Should be initialized to, e.g.,
			   ! InfoScrap()->scrapCount */

get_scrap (){
    long off, len;
    ScrapStuff *scrap_stuff;

    scrap_stuff = InfoScrap ();
    if (scrap_count == scrap_stuff->scrapCount)
	return;
    scrap_count = scrap_stuff->scrapCount;
    len = GetScrap (TEScrapHandle, "TEXT", &off);
    if (len >= 0)
        TEScrapLen = len;
    /* Else, it was probably a PICT or other type of scrap;
       in this case TEScrapHandle's contents has not been touched. */
}