home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
hypercrd
/
xcmd
/
prctclxf.sit
/
Sources
/
ArrayList
/
Sources
/
ListGlobals.c
< prev
next >
Wrap
Text File
|
1990-08-27
|
4KB
|
139 lines
/*
Copyright ⌐ 1990 Ari I. Halberstadt
This file is part of a free program. For precise terms of distribution
and use please see the files in the folder ╥Legal╙ accompanying this
software. If you make any modifications to this file you must add the
date, your name, and a description of what you have done to the
revision history below. This notice and the copyright notice must
remain intact in all copies of this file. The files in the folder
╥Legal╙ must be available to anyone receiving copies of this file.
Add initials and name here:
Initials Name
AIH Ari I. Halberstadt
Revision History (date format is mm-dd-yy):
Date Name Comments
07-11-90 AIH Version 0.9
*/
/*
Functions for managing the global data used by the program. The data
are stored between invocations in a HyperCard global variable. Each
time the XFCN is executed, it calls InitGlobalData, which creates
the global data and stores a handle to it in the global variable,
or, if the data already exist, simply gets the handle. When the
global data are first created the function does some one time
sanity checks, such as ensuring that all required resources
are available.
*/
#include <MyHeaders>
#include "ListMain.h"
#include "rsrclib.h"
static OSErr init_global_data(ResID procID, XCmdBlockPtr param, GlobalData *gdataPtr);
/*--------------------------------------------------------------------*/
/* Initialize the global data */
/*--------------------------------------------------------------------*/
OSErr InitGlobalData(XCmdBlockPtr param, Handle rsrc, GlobalData *gdataPtr)
{
ResID procID; /* ID of the proc resource */
GlobalData gdata; /* the global data */
OSErr err = noErr;
*gdataPtr = NULL;
/* get ID of this code resource (this is the "base" id) */
if (rsrc) {
err = rsrc_get_id(rsrc, &procID);
if (err) return(err);
}
else
procID = ARRAYLIST_XFCN_ID; /* use default (useful when debugging) */
/* get handle to global data from HyperCard global variable */
gdata = (GlobalData) GetGlobalToNum(param, ARRAYLIST_GLOBAL_NAME);
if (! gdata) {
/* Create new global data and save in a HyperCard global variable.
This is also a chance to do first-time initializations */
err = init_global_data(procID, param, &gdata);
if (err)
return(err);
SetGlobalToNum(param, ARRAYLIST_GLOBAL_NAME, (long) gdata);
}
else if ((**gdata).chksum != CHKSUM)
return(ERR_ALST_CHKSUM);
/* Reinitialize any volatile fields in the global data that may have
changed while the code resource wasn't executing. Especially
important are function pointers, since their addresses may
change every time the code resource is loaded into memory. */
(**gdata).param = param;
*gdataPtr = gdata;
return(noErr);
}
/* get the table of arrays */
ListTableType GetTable(GlobalData gdata)
{
ListTableType table;
table = (**gdata).table;
/* we update the table to make sure all of its fields are valid */
ltable_update(table);
return(table);
}
/* return the actual ID of the resource with the given internal ID */
ResID GetRsrcID(GlobalData gdata, ResID internal_id)
{
return((**gdata).map[internal_id]);
}
/* create and initialize the global data */
static OSErr init_global_data(ResID procID,
XCmdBlockPtr param,
GlobalData *gdataPtr)
{
ListTableType table;
GlobalData gdata;
OSErr err = noErr;
*gdataPtr = NULL;
gdata = (GlobalData) halloc(sizeof(GlobalDataStruct));
if ((err=MemError()) == noErr) {
/* create table of the arrays */
err = ltable_new(&table);
if (err == noErr) {
/* initialize resource map */
err = rsrc_build_map(procID, (**gdata).map);
if (! err) {
/* fill in the rest of the fields */
(**gdata).chksum = CHKSUM;
(**gdata).table = table;
(**gdata).param = param;
(**gdata).baseID = procID;
(**gdata).error = noErr;
*gdataPtr = gdata;
return(noErr);
}
ltable_dispose(table);
}
hfree(gdata);
}
return(err);
}