[net.micro.mac] Sample SFGetFile filter

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

Here is a sample filter procedure for SFGetFile that will work with SUMacC.
This particular filter makes that SFGetFile will only display files whose
resource fork is not empty.  The last few lines contain an application
in the "ascii" program that prompted this reply.

The following comments apply to all cases where a Toolbox routine calls
on a Pascal routine (this is also explained shortly in the SUMacC
documentation but a working example really helps):

The SUMacC library routine getpargs must be used to get access to the
arguments for the filter, since the Toolbox calls it in Pascal style.
In general, the "struct pargs" must contain declarations for all arguments
IN REVERSE ORDER.  Pascal INTEGERs must be mapped to C shorts, and the usual
transformation for structs, arrays and VAR parameters to pointers apply.
Getpargs returns a pointer where the return value should be stored if
the Pascal routine is a function.  Boolean function results should be
stored as if they were a character.  (The SFGetFile filter must return
TRUE (= 1) to skip a file!)

(On the original wish to check for files with FONT resources: I believe
this can be done by calls to OpenResFile, CountResources and CloseResFile;
however OpenResFile also preloads all resources whose preload bit
is on, so this may cause memory full conditions if there are many such
resources.  Also I see no easy way to restrict CountResources to only
the just opened file, so you must subtract the result of CountResources
before the OpenResFile.)

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

file_filter()
{
	struct pargs {
		FileParam *paramBlock;
	} pargs;
	char *retval= (char *) getpargs(&pargs, sizeof pargs);
	if (pargs.paramBlock->ioFlRLgLen == 0)
		*retval= 1; /* TRUE => skip this file */
	else
		*retval= 0; /* FALSE => show this file*/
}

open_file (){
    Point top_left;

    SetPt (&top_left, 50, 50);
    SFGetFile (&top_left, "", file_filter, -1, "", (ProcPtr) 0, &file_record);
    ...