📄 cstrccom.c
字号:
char *constructName,
struct construct *constructClass)
{
struct constructHeader *constructPtr;
int count;
unsigned position;
SYMBOL_HN *theName;
/*====================================================*/
/* If the construct name contains a module specifier, */
/* then get a pointer to the defmodule associated */
/* with the specified name. */
/*====================================================*/
if ((position = FindModuleSeparator(constructName)) != FALSE)
{
theName = ExtractModuleName(theEnv,position,constructName);
if (theName != NULL)
{ return((struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(theName))); }
}
/*============================================*/
/* No module was specified, so search for the */
/* named construct in the current module and */
/* modules from which it imports. */
/*============================================*/
constructPtr = (struct constructHeader *)
FindImportedConstruct(theEnv,constructClass->constructName,NULL,constructName,
&count,TRUE,NULL);
if (constructPtr == NULL) return(NULL);
return(constructPtr->whichModule->theModule);
}
/*************************************/
/* Undefconstruct: Generic C routine */
/* for deleting a construct. */
/*************************************/
globle intBool Undefconstruct(
void *theEnv,
void *theConstruct,
struct construct *constructClass)
{
#if BLOAD_ONLY || RUN_TIME
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theConstruct)
#pragma unused(constructClass)
#pragma unused(theEnv)
#endif
return(FALSE);
#else
void *currentConstruct,*nextConstruct;
intBool success;
/*================================================*/
/* Delete all constructs of the specified type if */
/* the construct pointer is the NULL pointer. */
/*================================================*/
if (theConstruct == NULL)
{
success = TRUE;
/*===================================================*/
/* Loop through all of the constructs in the module. */
/*===================================================*/
currentConstruct = (*constructClass->getNextItemFunction)(theEnv,NULL);
while (currentConstruct != NULL)
{
/*==============================*/
/* Remember the next construct. */
/*==============================*/
nextConstruct = (*constructClass->getNextItemFunction)(theEnv,currentConstruct);
/*=============================*/
/* Try deleting the construct. */
/*=============================*/
if ((*constructClass->isConstructDeletableFunction)(theEnv,currentConstruct))
{
RemoveConstructFromModule(theEnv,(struct constructHeader *) currentConstruct);
(*constructClass->freeFunction)(theEnv,currentConstruct);
}
else
{
CantDeleteItemErrorMessage(theEnv,constructClass->constructName,
ValueToString((*constructClass->getConstructNameFunction)((struct constructHeader *) currentConstruct)));
success = FALSE;
}
/*================================*/
/* Move on to the next construct. */
/*================================*/
currentConstruct = nextConstruct;
}
/*=======================================*/
/* Perform periodic cleanup if embedded. */
/*=======================================*/
if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
(EvaluationData(theEnv)->CurrentExpression == NULL))
{ PeriodicCleanup(theEnv,TRUE,FALSE); }
/*============================================*/
/* Return TRUE if all constructs successfully */
/* deleted, otherwise FALSE. */
/*============================================*/
return(success);
}
/*==================================================*/
/* Return FALSE if the construct cannot be deleted. */
/*==================================================*/
if ((*constructClass->isConstructDeletableFunction)(theEnv,theConstruct) == FALSE)
{ return(FALSE); }
/*===========================*/
/* Remove the construct from */
/* the list in its module. */
/*===========================*/
RemoveConstructFromModule(theEnv,(struct constructHeader *) theConstruct);
/*=======================*/
/* Delete the construct. */
/*=======================*/
(*constructClass->freeFunction)(theEnv,theConstruct);
/*=======================================*/
/* Perform periodic cleanup if embedded. */
/*=======================================*/
if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
(EvaluationData(theEnv)->CurrentExpression == NULL))
{ PeriodicCleanup(theEnv,TRUE,FALSE); }
/*=============================*/
/* Return TRUE to indicate the */
/* construct was deleted. */
/*=============================*/
return(TRUE);
#endif
}
/***********************************/
/* SaveConstruct: Generic routine */
/* for saving a construct class. */
/***********************************/
globle void SaveConstruct(
void *theEnv,
void *theModule,
char *logicalName,
struct construct *constructClass)
{
char *ppform;
struct constructHeader *theConstruct;
/*==========================*/
/* Save the current module. */
/*==========================*/
SaveCurrentModule(theEnv);
/*===========================*/
/* Set the current module to */
/* the one we're examining. */
/*===========================*/
EnvSetCurrentModule(theEnv,theModule);
/*==============================================*/
/* Loop through each construct of the specified */
/* construct class in the module. */
/*==============================================*/
for (theConstruct = (struct constructHeader *)
(*constructClass->getNextItemFunction)(theEnv,NULL);
theConstruct != NULL;
theConstruct = (struct constructHeader *)
(*constructClass->getNextItemFunction)(theEnv,theConstruct))
{
/*==========================================*/
/* Print the construct's pretty print form. */
/*==========================================*/
ppform = (*constructClass->getPPFormFunction)(theEnv,theConstruct);
if (ppform != NULL)
{
PrintInChunks(theEnv,logicalName,ppform);
EnvPrintRouter(theEnv,logicalName,"\n");
}
}
/*=============================*/
/* Restore the current module. */
/*=============================*/
RestoreCurrentModule(theEnv);
}
/*********************************************************/
/* GetConstructModuleName: Generic routine for returning */
/* the name of the module to which a construct belongs */
/*********************************************************/
globle char *GetConstructModuleName(
struct constructHeader *theConstruct)
{ return(EnvGetDefmoduleName(NULL,(void *) theConstruct->whichModule->theModule)); }
/*********************************************************/
/* GetConstructNameString: Generic routine for returning */
/* the name string of a construct. */
/*********************************************************/
globle char *GetConstructNameString(
struct constructHeader *theConstruct)
{ return(ValueToString(theConstruct->name)); }
/**************************************************/
/* EnvGetConstructNameString: Generic routine for */
/* returning the name string of a construct. */
/**************************************************/
#if IBM_TBC
#pragma argsused
#endif
globle char *EnvGetConstructNameString(
void *theEnv,
struct constructHeader *theConstruct)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
return(ValueToString(theConstruct->name));
}
/**********************************************************/
/* GetConstructNamePointer: Generic routine for returning */
/* the name pointer of a construct. */
/**********************************************************/
globle SYMBOL_HN *GetConstructNamePointer(
struct constructHeader *theConstruct)
{ return(theConstruct->name); }
/************************************************/
/* GetConstructListFunction: Generic Routine */
/* for retrieving the constructs in a module. */
/************************************************/
globle void GetConstructListFunction(
void *theEnv,
char *functionName,
DATA_OBJECT_PTR returnValue,
struct construct *constructClass)
{
struct defmodule *theModule;
DATA_OBJECT result;
int numArgs;
/*============================================*/
/* Check for the correct number of arguments. */
/*============================================*/
if ((numArgs = EnvArgCountCheck(theEnv,functionName,NO_MORE_THAN,1)) == -1)
{
EnvSetMultifieldErrorValue(theEnv,returnValue);
return;
}
/*====================================*/
/* If an argument was given, check to */
/* see that it's a valid module name. */
/*====================================*/
if (numArgs == 1)
{
/*======================================*/
/* Only symbols are valid module names. */
/*======================================*/
EnvRtnUnknown(theEnv,1,&result);
if (GetType(result) != SYMBOL)
{
EnvSetMultifieldErrorValue(theEnv,returnValue);
ExpectedTypeError1(theEnv,functionName,1,"defmodule name");
return;
}
/*===========================================*/
/* Verify that the named module exists or is */
/* the symbol * (for obtaining the construct */
/* list for all modules). */
/*===========================================*/
if ((theModule = (struct defmodule *) EnvFindDefmodule(theEnv,DOToString(result))) == NULL)
{
if (strcmp("*",DOToString(result)) != 0)
{
EnvSetMultifieldErrorValue(theEnv,returnValue);
ExpectedTypeError1(theEnv,functionName,1,"defmodule name");
return;
}
theModule = NULL;
}
}
/*=====================================*/
/* Otherwise use the current module to */
/* generate the construct list. */
/*=====================================*/
else
{ theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); }
/*=============================*/
/* Call the driver routine to */
/* get the list of constructs. */
/*=============================*/
GetConstructList(theEnv,returnValue,constructClass,theModule);
}
/********************************************/
/* GetConstructList: Generic C Routine for */
/* retrieving the constructs in a module. */
/********************************************/
globle void GetConstructList(
void *theEnv,
DATA_OBJECT_PTR returnValue,
struct construct *constructClass,
struct defmodule *theModule)
{
void *theConstruct;
unsigned long count = 0;
struct multifield *theList;
SYMBOL_HN *theName;
struct defmodule *loopModule;
int allModules = FALSE;
#if IBM_TBC
unsigned largestConstructNameSize, bufferSize = 80; /* prevents warning */
#else
unsigned largestConstructNameSize = 0, bufferSize = 80; /* prevents warning */
#endif
char *buffer;
/*==========================*/
/* Save the current module. */
/*==========================*/
SaveCurrentModule(theEnv);
/*=======================================*/
/* If the module specified is NULL, then */
/* get all constructs in all modules. */
/*=======================================*/
if (theModule == NULL)
{
theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
allModules = TRUE;
}
/*======================================================*/
/* Count the number of constructs to be retrieved and */
/* determine the buffer size needed to store the */
/* module-name::construct-names that will be generated. */
/*======================================================*/
loopModule = theModule;
while (loopModule != NULL)
{
unsigned tempSize;
/*======================================================*/
/* Set the current module to the module being examined. */
/*======================================================*/
EnvSetCurrentModule(theEnv,(void *) loopModule);
/*===========================================*/
/* Loop over every construct in the module. */
/*===========================================*/
theConstruct = NULL;
largestConstructNameSize = 0;
while ((theConstruct = (*constructClass->getNextItemFunction)(theEnv,theConstruct)) != NULL)
{
/*================================*/
/* Increment the construct count. */
/*================================*/
count++;
/*=================================================*/
/* Is this the largest construct name encountered? */
/*=================================================*/
tempSize = strlen(ValueToString((*constructClass->getConstructNameFunction)((struct constructHeader *) theConstruct)));
if (tempSize > largestConstructNameSize)
{ largestConstructNameSize = tempSize; }
}
/*========================================*/
/* Determine the size of the module name. */
/*========================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -