📄 bload.c
字号:
}
else
objsmaxread /= 2;
}
}
while (buf == NULL);
EnvSetOutOfMemoryFunction(theEnv,oldOutOfMemoryFunction);
i = 0L;
do
{
objsread = (objsmaxread > (objcnt - i)) ? (objcnt - i) : objsmaxread;
GenReadBinary(theEnv,(void *) buf,objsread * objsz);
for (bi = 0L ; bi < objsread ; bi++ , i++)
(*objupdate)(theEnv,buf + objsz * bi,i);
}
while (i < objcnt);
genlongfree(theEnv,(void *) buf,space);
}
/**********************************************/
/* ReadNeededFunctions: Reads in the names of */
/* functions needed by the binary image. */
/**********************************************/
static struct FunctionDefinition **ReadNeededFunctions(
void *theEnv,
long int *numberOfFunctions,
int *error)
{
char *functionNames, *namePtr;
unsigned long int space,temp;
long i;
struct FunctionDefinition **newFunctionArray, *functionPtr;
int functionsNotFound = 0;
/*===================================================*/
/* Determine the number of function names to be read */
/* and the space required for them. */
/*===================================================*/
GenReadBinary(theEnv,numberOfFunctions,(unsigned long) sizeof(long int));
GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long int));
if (*numberOfFunctions == 0)
{
*error = FALSE;
return(NULL);
}
/*=======================================*/
/* Allocate area for strings to be read. */
/*=======================================*/
functionNames = (char *) genlongalloc(theEnv,space);
GenReadBinary(theEnv,(void *) functionNames,space);
/*====================================================*/
/* Store the function pointers in the function array. */
/*====================================================*/
temp = (unsigned long) sizeof(struct FunctionDefinition *) * *numberOfFunctions;
newFunctionArray = (struct FunctionDefinition **) genlongalloc(theEnv,temp);
namePtr = functionNames;
functionPtr = NULL;
for (i = 0; i < *numberOfFunctions; i++)
{
if ((functionPtr = FastFindFunction(theEnv,namePtr,functionPtr)) == NULL)
{
if (! functionsNotFound)
{
PrintErrorID(theEnv,"BLOAD",6,FALSE);
EnvPrintRouter(theEnv,WERROR,"The following undefined functions are ");
EnvPrintRouter(theEnv,WERROR,"referenced by this binary image:\n");
}
EnvPrintRouter(theEnv,WERROR," ");
EnvPrintRouter(theEnv,WERROR,namePtr);
EnvPrintRouter(theEnv,WERROR,"\n");
functionsNotFound = 1;
}
newFunctionArray[i] = functionPtr;
namePtr += strlen(namePtr) + 1;
}
/*==========================================*/
/* Free the memory used by the name buffer. */
/*==========================================*/
genlongfree(theEnv,(void *) functionNames,space);
/*==================================================*/
/* If any of the required functions were not found, */
/* then free the memory used by the function array. */
/*==================================================*/
if (functionsNotFound)
{
genlongfree(theEnv,(void *) newFunctionArray,temp);
newFunctionArray = NULL;
}
/*===================================*/
/* Set globals to appropriate values */
/* and return the function array. */
/*===================================*/
*error = functionsNotFound;
return(newFunctionArray);
}
/*****************************************/
/* FastFindFunction: Search the function */
/* list for a specific function. */
/*****************************************/
static struct FunctionDefinition *FastFindFunction(
void *theEnv,
char *functionName,
struct FunctionDefinition *lastFunction)
{
struct FunctionDefinition *theList, *theFunction;
/*========================*/
/* Get the function list. */
/*========================*/
theList = GetFunctionList(theEnv);
if (theList == NULL) { return(NULL); }
/*=======================================*/
/* If we completed a previous function */
/* search, start where we last left off. */
/*=======================================*/
if (lastFunction != NULL)
{ theFunction = lastFunction->next; }
else
{ theFunction = theList; }
/*======================================================*/
/* Traverse the rest of the function list searching for */
/* the named function wrapping around if necessary. */
/*======================================================*/
while (strcmp(functionName,ValueToString(theFunction->callFunctionName)) != 0)
{
theFunction = theFunction->next;
if (theFunction == lastFunction) return(NULL);
if (theFunction == NULL) theFunction = theList;
}
/*=======================*/
/* Return the pointer to */
/* the found function. */
/*=======================*/
return(theFunction);
}
/******************************************/
/* Bloaded: Returns TRUE if the current */
/* environment is the result of a bload */
/* command, otherwise returns FALSE. */
/******************************************/
globle intBool Bloaded(
void *theEnv)
{
return(BloadData(theEnv)->BloadActive);
}
/*************************************/
/* ClearBload: Clears a binary image */
/* from the KB environment. */
/*************************************/
static int ClearBload(
void *theEnv)
{
struct BinaryItem *biPtr;
struct callFunctionItem *bfPtr;
int ready,error;
/*=================================================*/
/* Make sure it's safe to clear the bloaded image. */
/*=================================================*/
error = FALSE;
for (bfPtr = BloadData(theEnv)->ClearBloadReadyFunctions;
bfPtr != NULL;
bfPtr = bfPtr->next)
{
if (bfPtr->environmentAware)
{ ready = (* ((int (*)(void *)) bfPtr->func))(theEnv); }
else
{ ready = (* ((int (*)(void)) bfPtr->func))(); }
if (ready == FALSE)
{
if (! error)
{
PrintErrorID(theEnv,"BLOAD",5,FALSE);
EnvPrintRouter(theEnv,WERROR,
"Some constructs are still in use by the current binary image:\n");
}
EnvPrintRouter(theEnv,WERROR," ");
EnvPrintRouter(theEnv,WERROR,bfPtr->name);
EnvPrintRouter(theEnv,WERROR,"\n");
error = TRUE;
}
}
/*==================================================*/
/* If some constructs are still in use and can't be */
/* cleared, indicate the binary load can't continue */
/* and return FALSE to indicate this condition. */
/*==================================================*/
if (error == TRUE)
{
EnvPrintRouter(theEnv,WERROR,"Binary clear cannot continue.\n");
return(FALSE);
}
/*=============================*/
/* Call bload clear functions. */
/*=============================*/
for (biPtr = BsaveData(theEnv)->ListOfBinaryItems;
biPtr != NULL;
biPtr = biPtr->next)
{ if (biPtr->clearFunction != NULL) (*biPtr->clearFunction)(theEnv); }
/*===========================*/
/* Free bloaded expressions. */
/*===========================*/
ClearBloadedExpressions(theEnv);
/*===========================*/
/* Free bloaded constraints. */
/*===========================*/
ClearBloadedConstraints(theEnv);
/*==================================*/
/* Remove the bload clear function. */
/*==================================*/
BloadData(theEnv)->BloadActive = FALSE;
EnvRemoveClearFunction(theEnv,"bload");
/*====================================*/
/* Return TRUE to indicate the binary */
/* image was successfully cleared. */
/*====================================*/
return(TRUE);
}
/*************************************************/
/* AbortBload: Cleans up effects of before-bload */
/* functions in event of failure. */
/*************************************************/
static void AbortBload(
void *theEnv)
{
struct callFunctionItem *bfPtr;
for (bfPtr = BloadData(theEnv)->AbortBloadFunctions;
bfPtr != NULL;
bfPtr = bfPtr->next)
{
if (bfPtr->environmentAware)
{ (*bfPtr->func)(theEnv); }
else
{ (* (void (*)(void)) bfPtr->func)(); }
}
}
/********************************************/
/* AddBeforeBloadFunction: Adds a function */
/* to the list of functions called before */
/* a binary load occurs. */
/********************************************/
globle void AddBeforeBloadFunction(
void *theEnv,
char *name,
void (*func)(void *),
int priority)
{
BloadData(theEnv)->BeforeBloadFunctions =
AddFunctionToCallList(theEnv,name,priority,func,BloadData(theEnv)->BeforeBloadFunctions,TRUE);
}
/*******************************************/
/* AddAfterBloadFunction: Adds a function */
/* to the list of functions called after */
/* a binary load occurs. */
/*******************************************/
globle void AddAfterBloadFunction(
void *theEnv,
char *name,
void (*func)(void *),
int priority)
{
BloadData(theEnv)->AfterBloadFunctions =
AddFunctionToCallList(theEnv,name,priority,func,BloadData(theEnv)->AfterBloadFunctions,TRUE);
}
/**************************************************/
/* AddClearBloadReadyFunction: Adds a function to */
/* the list of functions called to determine if */
/* a binary image can be cleared. */
/**************************************************/
globle void AddClearBloadReadyFunction(
void *theEnv,
char *name,
int (*func)(void *),
int priority)
{
BloadData(theEnv)->ClearBloadReadyFunctions =
AddFunctionToCallList(theEnv,name,priority,
(void (*)(void *)) func,
BloadData(theEnv)->ClearBloadReadyFunctions,TRUE);
}
/*********************************************/
/* AddAbortBloadFunction: Adds a function to */
/* the list of functions called if a bload */
/* has to be aborted. */
/*********************************************/
globle void AddAbortBloadFunction(
void *theEnv,
char *name,
void (*func)(void *),
int priority)
{
BloadData(theEnv)->AbortBloadFunctions = AddFunctionToCallList(theEnv,name,priority,func,BloadData(theEnv)->AbortBloadFunctions,TRUE);
}
/*******************************************************
NAME : BloadOutOfMemoryFunction
DESCRIPTION : Memory function used by bload to
prevent exiting when out of
memory - used by BloadandRefresh
INPUTS : The memory request size (unused)
RETURNS : TRUE (indicates a failure and for
the memory functions to simply
return a NULL pointer)
SIDE EFFECTS : None
NOTES : None
*******************************************************/
#if IBM_TBC
#pragma argsused
#endif
static int BloadOutOfMemoryFunction(
void *theEnv,
unsigned long size)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(size,theEnv)
#endif
return(TRUE);
}
/*****************************************************/
/* CannotLoadWithBloadMessage: Generic error message */
/* for indicating that a construct can't be loaded */
/* when a binary image is active. */
/*****************************************************/
globle void CannotLoadWithBloadMessage(
void *theEnv,
char *constructName)
{
PrintErrorID(theEnv,"BLOAD",1,TRUE);
EnvPrintRouter(theEnv,WERROR,"Cannot load ");
EnvPrintRouter(theEnv,WERROR,constructName);
EnvPrintRouter(theEnv,WERROR," construct with binary load in effect.\n");
}
#endif /* (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) */
/**************************************/
/* BloadCommand: H/L access routine */
/* for the bload command. */
/**************************************/
globle int BloadCommand(
void *theEnv)
{
#if (! RUN_TIME) && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
char *fileName;
if (EnvArgCountCheck(theEnv,"bload",EXACTLY,1) == -1) return(FALSE);
fileName = GetFileName(theEnv,"bload",1);
if (fileName != NULL) return(EnvBload(theEnv,fileName));
#else
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
#endif
return(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -