📄 globldef.c
字号:
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); } /*========================================================*/ /* The current implementation of the defmodules shouldn't */ /* allow a construct to be defined which would cause an */ /* ambiguous reference, but we'll check for it anyway. */ /*========================================================*/ if (count > 1) { AmbiguousReferenceErrorMessage(theEnv,"defglobal",ValueToString(theValue)); vPtr->type = SYMBOL; vPtr->value = EnvFalseSymbol(theEnv); SetEvaluationError(theEnv,TRUE); return(FALSE); } /*=================================*/ /* Get the value of the defglobal. */ /*=================================*/ QGetDefglobalValue(theEnv,theGlobal,vPtr); return(TRUE); }/***************************************************************//* QGetDefglobalValue: Returns the value of a global variable. *//***************************************************************/globle int QGetDefglobalValue( void *theEnv, void *vTheGlobal, DATA_OBJECT_PTR vPtr) { struct defglobal *theGlobal = (struct defglobal *) vTheGlobal; /*===============================================*/ /* Transfer values which can be copied directly. */ /*===============================================*/ vPtr->type = theGlobal->current.type; vPtr->value = theGlobal->current.value; vPtr->begin = theGlobal->current.begin; vPtr->end = theGlobal->current.end; /*===========================================================*/ /* If the global contains a multifield value, return a copy */ /* of the value so that routines which use this value are */ /* not affected if the value of the global is later changed. */ /*===========================================================*/ if (vPtr->type == MULTIFIELD) { vPtr->value = EnvCreateMultifield(theEnv,(unsigned long) (vPtr->end + 1)); GenCopyMemory(struct field,vPtr->end + 1, &((struct multifield *) vPtr->value)->theFields[0], &((struct multifield *) theGlobal->current.value)->theFields[theGlobal->current.begin]); } return(TRUE); }/************************************************************//* EnvGetDefglobalValue: Returns the value of the specified *//* global variable in the supplied DATA_OBJECT. *//************************************************************/globle intBool EnvGetDefglobalValue( void *theEnv, char *variableName, DATA_OBJECT_PTR vPtr) { struct defglobal *theDefglobal; if ((theDefglobal = (struct defglobal *) EnvFindDefglobal(theEnv,variableName)) == NULL) { return(FALSE); } QGetDefglobalValue(theEnv,theDefglobal,vPtr); return(TRUE); }/****************************************************************//* EnvSetDefglobalValue: Sets the value of the specified global *//* variable to the value stored in the supplied DATA_OBJECT. *//****************************************************************/globle intBool EnvSetDefglobalValue( void *theEnv, char *variableName, DATA_OBJECT_PTR vPtr) { struct defglobal *theGlobal; if ((theGlobal = QFindDefglobal(theEnv,(SYMBOL_HN *) EnvAddSymbol(theEnv,variableName))) == NULL) { return(FALSE); } QSetDefglobalValue(theEnv,theGlobal,vPtr,FALSE); return(TRUE); }/**********************************************************//* DecrementDefglobalBusyCount: Decrements the busy count *//* of a defglobal data structure. *//**********************************************************/static void DecrementDefglobalBusyCount( void *theEnv, void *vTheGlobal) { struct defglobal *theGlobal = (struct defglobal *) vTheGlobal; if (! ConstructData(theEnv)->ClearInProgress) theGlobal->busyCount--; }/**********************************************************//* IncrementDefglobalBusyCount: Increments the busy count *//* of a defglobal data structure. *//**********************************************************/#if IBM_TBC#pragma argsused#endifstatic void IncrementDefglobalBusyCount( void *theEnv, void *vTheGlobal) { struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(theEnv)#endif theGlobal->busyCount++; }/***********************************************************************//* UpdateDefglobalScope: Updates the scope flag of all the defglobals. *//***********************************************************************/globle void UpdateDefglobalScope( void *theEnv) { struct defglobal *theDefglobal; int moduleCount; struct defmodule *theModule; struct defmoduleItemHeader *theItem; /*============================*/ /* Loop through every module. */ /*============================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*============================================================*/ /* Loop through every defglobal in the module being examined. */ /*============================================================*/ theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,theModule,DefglobalData(theEnv)->DefglobalModuleIndex); for (theDefglobal = (struct defglobal *) theItem->firstItem; theDefglobal != NULL ; theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theDefglobal)) { /*====================================================*/ /* If the defglobal is visible to the current module, */ /* then mark it as being in scope, otherwise mark it */ /* as being out of scope. */ /*====================================================*/ if (FindImportedConstruct(theEnv,"defglobal",theModule, ValueToString(theDefglobal->header.name), &moduleCount,TRUE,NULL) != NULL) { theDefglobal->inScope = TRUE; } else { theDefglobal->inScope = FALSE; } } } }/*******************************************************//* GetNextDefglobalInScope: Returns the next defglobal *//* that is scope of the current module. Works in a *//* similar fashion to GetNextDefglobal, but skips *//* defglobals that are out of scope. *//*******************************************************/globle void *GetNextDefglobalInScope( void *theEnv, void *vTheGlobal) { struct defglobal *theGlobal = (struct defglobal *) vTheGlobal; struct defmoduleItemHeader *theItem; /*=======================================*/ /* If we're beginning the search for the */ /* first defglobal in scope, then ... */ /*=======================================*/ if (theGlobal == NULL) { /*==============================================*/ /* If the current module has been changed since */ /* the last time the scopes were computed, then */ /* recompute the scopes. */ /*==============================================*/ if (DefglobalData(theEnv)->LastModuleIndex != DefmoduleData(theEnv)->ModuleChangeIndex) { UpdateDefglobalScope(theEnv); DefglobalData(theEnv)->LastModuleIndex = DefmoduleData(theEnv)->ModuleChangeIndex; } /*==========================================*/ /* Get the first module and first defglobal */ /* to start the search with. */ /*==========================================*/ DefglobalData(theEnv)->TheDefmodule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,DefglobalData(theEnv)->TheDefmodule,DefglobalData(theEnv)->DefglobalModuleIndex); theGlobal = (struct defglobal *) theItem->firstItem; } /*==================================================*/ /* Otherwise, see if the last defglobal returned by */ /* this function has a defglobal following it. */ /*==================================================*/ else { theGlobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theGlobal); } /*======================================*/ /* Continue looping through the modules */ /* until a defglobal in scope is found. */ /*======================================*/ while (DefglobalData(theEnv)->TheDefmodule != NULL) { /*=====================================================*/ /* Loop through the defglobals in the module currently */ /* being examined to see if one is in scope. */ /*=====================================================*/ for (; theGlobal != NULL; theGlobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theGlobal)) { if (theGlobal->inScope) return((void *) theGlobal); } /*================================================*/ /* If a global in scope couldn't be found in this */ /* module, then move on to the next module. */ /*================================================*/ DefglobalData(theEnv)->TheDefmodule = (struct defmodule *) EnvGetNextDefmodule(theEnv,DefglobalData(theEnv)->TheDefmodule); theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,DefglobalData(theEnv)->TheDefmodule,DefglobalData(theEnv)->DefglobalModuleIndex); theGlobal = (struct defglobal *) theItem->firstItem; } /*====================================*/ /* All the globals in scope have been */ /* traversed and there are none left. */ /*====================================*/ return(NULL); }#endif /* DEFGLOBAL_CONSTRUCT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -