📄 globldef.c
字号:
{ return FALSE; }
if (((struct defglobal *) ptr)->busyCount) return(FALSE);
return(TRUE);
}
/************************************************************/
/* ReturnDefglobal: Returns the data structures associated */
/* with a defglobal construct to the pool of free memory. */
/************************************************************/
static void ReturnDefglobal(
void *theEnv,
void *vTheDefglobal)
{
#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)
#pragma unused(theEnv,vTheDefglobal)
#endif
#if (! BLOAD_ONLY) && (! RUN_TIME)
struct defglobal *theDefglobal = (struct defglobal *) vTheDefglobal;
if (theDefglobal == NULL) return;
/*====================================*/
/* Return the global's current value. */
/*====================================*/
ValueDeinstall(theEnv,&theDefglobal->current);
if (theDefglobal->current.type == MULTIFIELD)
{ ReturnMultifield(theEnv,(struct multifield *) theDefglobal->current.value); }
/*================================================*/
/* Return the expression representing the initial */
/* value of the defglobal when it was defined. */
/*================================================*/
RemoveHashedExpression(theEnv,theDefglobal->initial);
/*===============================*/
/* Release items stored in the */
/* defglobal's construct header. */
/*===============================*/
DeinstallConstructHeader(theEnv,&theDefglobal->header);
/*======================================*/
/* Return the defglobal data structure. */
/*======================================*/
rtn_struct(theEnv,defglobal,theDefglobal);
/*===========================================*/
/* Set the variable indicating that a change */
/* has been made to a global variable. */
/*===========================================*/
DefglobalData(theEnv)->ChangeToGlobals = TRUE;
#endif
}
/************************************************************/
/* DestroyDefglobal: Returns the data structures associated */
/* with a defglobal construct to the pool of free memory. */
/************************************************************/
static void DestroyDefglobal(
void *theEnv,
void *vTheDefglobal)
{
#if (MAC_MCW || IBM_MCW) && BLOAD_ONLY
#pragma unused(theEnv,vTheDefglobal)
#endif
#if (! BLOAD_ONLY)
struct defglobal *theDefglobal = (struct defglobal *) vTheDefglobal;
if (theDefglobal == NULL) return;
/*====================================*/
/* Return the global's current value. */
/*====================================*/
if (theDefglobal->current.type == MULTIFIELD)
{ ReturnMultifield(theEnv,(struct multifield *) theDefglobal->current.value); }
#if (! RUN_TIME)
/*===============================*/
/* Release items stored in the */
/* defglobal's construct header. */
/*===============================*/
DeinstallConstructHeader(theEnv,&theDefglobal->header);
/*======================================*/
/* Return the defglobal data structure. */
/*======================================*/
rtn_struct(theEnv,defglobal,theDefglobal);
#endif
#endif
}
/************************************************/
/* QSetDefglobalValue: Lowest level routine for */
/* setting a defglobal's value. */
/************************************************/
globle void QSetDefglobalValue(
void *theEnv,
struct defglobal *theGlobal,
DATA_OBJECT_PTR vPtr,
int resetVar)
{
/*====================================================*/
/* If the new value passed for the defglobal is NULL, */
/* then reset the defglobal to the initial value it */
/* had when it was defined. */
/*====================================================*/
if (resetVar)
{
EvaluateExpression(theEnv,theGlobal->initial,vPtr);
if (EvaluationData(theEnv)->EvaluationError)
{
vPtr->type = SYMBOL;
vPtr->value = EnvFalseSymbol(theEnv);
}
}
/*==========================================*/
/* If globals are being watch, then display */
/* the change to the global variable. */
/*==========================================*/
#if DEBUGGING_FUNCTIONS
if (theGlobal->watch)
{
EnvPrintRouter(theEnv,WTRACE,":== ?*");
EnvPrintRouter(theEnv,WTRACE,ValueToString(theGlobal->header.name));
EnvPrintRouter(theEnv,WTRACE,"* ==> ");
PrintDataObject(theEnv,WTRACE,vPtr);
EnvPrintRouter(theEnv,WTRACE," <== ");
PrintDataObject(theEnv,WTRACE,&theGlobal->current);
EnvPrintRouter(theEnv,WTRACE,"\n");
}
#endif
/*==============================================*/
/* Remove the old value of the global variable. */
/*==============================================*/
ValueDeinstall(theEnv,&theGlobal->current);
if (theGlobal->current.type == MULTIFIELD)
{ ReturnMultifield(theEnv,(struct multifield *) theGlobal->current.value); }
/*===========================================*/
/* Set the new value of the global variable. */
/*===========================================*/
theGlobal->current.type = vPtr->type;
if (vPtr->type != MULTIFIELD) theGlobal->current.value = vPtr->value;
else DuplicateMultifield(theEnv,&theGlobal->current,vPtr);
ValueInstall(theEnv,&theGlobal->current);
/*===========================================*/
/* Set the variable indicating that a change */
/* has been made to a global variable. */
/*===========================================*/
DefglobalData(theEnv)->ChangeToGlobals = TRUE;
if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
(EvaluationData(theEnv)->CurrentExpression == NULL))
{ PeriodicCleanup(theEnv,TRUE,FALSE); }
}
/**************************************************************/
/* QFindDefglobal: Searches for a defglobal in the list of */
/* defglobals. Returns a pointer to the defglobal if found, */
/* otherwise NULL. */
/**************************************************************/
globle struct defglobal *QFindDefglobal(
void *theEnv,
SYMBOL_HN *defglobalName)
{
struct defglobal *theDefglobal;
for (theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,NULL);
theDefglobal != NULL;
theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theDefglobal))
{ if (defglobalName == theDefglobal->header.name) return (theDefglobal); }
return(NULL);
}
/*********************************************************************/
/* EnvGetDefglobalValueForm: Returns the pretty print representation */
/* of the current value of the specified defglobal. For example, */
/* if the current value of ?*x* is 5, the string "?*x* = 5" would */
/* be returned. */
/*********************************************************************/
globle void EnvGetDefglobalValueForm(
void *theEnv,
char *buffer,
unsigned bufferLength,
void *vTheGlobal)
{
struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;
OpenStringDestination(theEnv,"GlobalValueForm",buffer,bufferLength);
EnvPrintRouter(theEnv,"GlobalValueForm","?*");
EnvPrintRouter(theEnv,"GlobalValueForm",ValueToString(theGlobal->header.name));
EnvPrintRouter(theEnv,"GlobalValueForm","* = ");
PrintDataObject(theEnv,"GlobalValueForm",&theGlobal->current);
CloseStringDestination(theEnv,"GlobalValueForm");
}
/************************************************************/
/* EnvGetGlobalsChanged: Returns the defglobal change flag. */
/************************************************************/
globle int EnvGetGlobalsChanged(
void *theEnv)
{
return(DefglobalData(theEnv)->ChangeToGlobals);
}
/*********************************************************/
/* EnvSetGlobalsChanged: Sets the defglobal change flag. */
/*********************************************************/
globle void EnvSetGlobalsChanged(
void *theEnv,
int value)
{
DefglobalData(theEnv)->ChangeToGlobals = value;
}
/**********************************************************/
/* GetDefglobalValue2: Returns the value of the specified */
/* global variable in the supplied DATA_OBJECT. */
/**********************************************************/
static intBool GetDefglobalValue2(
void *theEnv,
void *theValue,
DATA_OBJECT_PTR vPtr)
{
struct defglobal *theGlobal;
int count;
/*===========================================*/
/* Search for the specified defglobal in the */
/* modules visible to the current module. */
/*===========================================*/
theGlobal = (struct defglobal *)
FindImportedConstruct(theEnv,"defglobal",NULL,ValueToString(theValue),
&count,TRUE,NULL);
/*=============================================*/
/* If it wasn't found, print an error message. */
/*=============================================*/
if (theGlobal == NULL)
{
PrintErrorID(theEnv,"GLOBLDEF",1,FALSE);
EnvPrintRouter(theEnv,WERROR,"Global variable ?*");
EnvPrintRouter(theEnv,WERROR,ValueToString(theValue));
EnvPrintRouter(theEnv,WERROR,"* is unbound.\n");
vPtr->type = SYMBOL;
vPtr->value = EnvFalseSymbol(theEnv);
SetEvaluationError(theEnv,TRUE);
return(FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -