📄 tmpltfun.c
字号:
/* for the deftemplate-slot-cardinality function. */
/**********************************************************/
globle void DeftemplateSlotCardinalityFunction(
void *theEnv,
DATA_OBJECT_PTR theValue)
{
struct deftemplate *theDeftemplate;
SYMBOL_HN *slotName;
/*===================================================*/
/* Retrieve the deftemplate and slot name arguments. */
/*===================================================*/
slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-cardinality",&theDeftemplate);
if (slotName == NULL)
{
EnvSetMultifieldErrorValue(theEnv,theValue);
return;
}
/*=======================================*/
/* Get the deftemplate slot cardinality. */
/*=======================================*/
EnvDeftemplateSlotCardinality(theEnv,theDeftemplate,ValueToString(slotName),theValue);
}
/****************************************************/
/* EnvDeftemplateSlotCardinality: C access routine */
/* for the deftemplate-slot-cardinality function. */
/****************************************************/
globle void EnvDeftemplateSlotCardinality(
void *theEnv,
void *vTheDeftemplate,
char *slotName,
DATA_OBJECT *result)
{
struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
short position;
struct templateSlot *theSlot;
/*===============================================*/
/* If we're dealing with an implied deftemplate, */
/* then the only slot names is "implied." */
/*===============================================*/
if (theDeftemplate->implied)
{
if (strcmp(slotName,"implied") == 0)
{
result->type = MULTIFIELD;
result->begin = 0;
result->end = 1;
result->value = EnvCreateMultifield(theEnv,2L);
SetMFType(result->value,1,INTEGER);
SetMFValue(result->value,1,SymbolData(theEnv)->Zero);
SetMFType(result->value,2,SYMBOL);
SetMFValue(result->value,2,SymbolData(theEnv)->PositiveInfinity);
return;
}
else
{
EnvSetMultifieldErrorValue(theEnv,result);
SetEvaluationError(theEnv,TRUE);
InvalidDeftemplateSlotMessage(theEnv,slotName,
ValueToString(theDeftemplate->header.name),FALSE);
return;
}
}
/*============================================*/
/* Otherwise search for the slot name in the */
/* list of slots defined for the deftemplate. */
/*============================================*/
else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
{
EnvSetMultifieldErrorValue(theEnv,result);
SetEvaluationError(theEnv,TRUE);
InvalidDeftemplateSlotMessage(theEnv,slotName,
ValueToString(theDeftemplate->header.name),FALSE);
return;
}
/*=====================================*/
/* Return the cardinality of the slot. */
/*=====================================*/
if (theSlot->multislot == 0)
{
EnvSetMultifieldErrorValue(theEnv,result);
return;
}
result->type = MULTIFIELD;
result->begin = 0;
result->end = 1;
result->value = EnvCreateMultifield(theEnv,2L);
if (theSlot->constraints != NULL)
{
SetMFType(result->value,1,theSlot->constraints->minFields->type);
SetMFValue(result->value,1,theSlot->constraints->minFields->value);
SetMFType(result->value,2,theSlot->constraints->maxFields->type);
SetMFValue(result->value,2,theSlot->constraints->maxFields->value);
}
else
{
SetMFType(result->value,1,INTEGER);
SetMFValue(result->value,1,SymbolData(theEnv)->Zero);
SetMFType(result->value,2,SYMBOL);
SetMFValue(result->value,2,SymbolData(theEnv)->PositiveInfinity);
}
}
/************************************************************/
/* DeftemplateSlotAllowedValuesFunction: H/L access routine */
/* for the deftemplate-slot-allowed-values function. */
/************************************************************/
globle void DeftemplateSlotAllowedValuesFunction(
void *theEnv,
DATA_OBJECT_PTR theValue)
{
struct deftemplate *theDeftemplate;
SYMBOL_HN *slotName;
/*===================================================*/
/* Retrieve the deftemplate and slot name arguments. */
/*===================================================*/
slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-allowed-values",&theDeftemplate);
if (slotName == NULL)
{
EnvSetMultifieldErrorValue(theEnv,theValue);
return;
}
/*==========================================*/
/* Get the deftemplate slot allowed values. */
/*==========================================*/
EnvDeftemplateSlotAllowedValues(theEnv,theDeftemplate,ValueToString(slotName),theValue);
}
/*******************************************************/
/* EnvDeftemplateSlotAllowedValues: C access routine */
/* for the deftemplate-slot-allowed-values function. */
/*******************************************************/
globle void EnvDeftemplateSlotAllowedValues(
void *theEnv,
void *vTheDeftemplate,
char *slotName,
DATA_OBJECT *result)
{
struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
short position;
struct templateSlot *theSlot;
int i;
EXPRESSION *theExp;
/*===============================================*/
/* If we're dealing with an implied deftemplate, */
/* then the only slot names is "implied." */
/*===============================================*/
if (theDeftemplate->implied)
{
if (strcmp(slotName,"implied") == 0)
{
result->type = SYMBOL;
result->value = EnvFalseSymbol(theEnv);
return;
}
else
{
EnvSetMultifieldErrorValue(theEnv,result);
SetEvaluationError(theEnv,TRUE);
InvalidDeftemplateSlotMessage(theEnv,slotName,
ValueToString(theDeftemplate->header.name),FALSE);
return;
}
}
/*============================================*/
/* Otherwise search for the slot name in the */
/* list of slots defined for the deftemplate. */
/*============================================*/
else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
{
EnvSetMultifieldErrorValue(theEnv,result);
SetEvaluationError(theEnv,TRUE);
InvalidDeftemplateSlotMessage(theEnv,slotName,
ValueToString(theDeftemplate->header.name),FALSE);
return;
}
/*========================================*/
/* Return the allowed values of the slot. */
/*========================================*/
if ((theSlot->constraints != NULL) ? (theSlot->constraints->restrictionList == NULL) : TRUE)
{
result->type = SYMBOL;
result->value = EnvFalseSymbol(theEnv);
return;
}
result->type = MULTIFIELD;
result->begin = 0;
result->end = ExpressionSize(theSlot->constraints->restrictionList) - 1;
result->value = EnvCreateMultifield(theEnv,(unsigned long) (result->end + 1));
i = 1;
theExp = theSlot->constraints->restrictionList;
while (theExp != NULL)
{
SetMFType(result->value,i,theExp->type);
SetMFValue(result->value,i,theExp->value);
theExp = theExp->nextArg;
i++;
}
}
/****************************************************/
/* DeftemplateSlotRangeFunction: H/L access routine */
/* for the deftemplate-slot-range function. */
/****************************************************/
globle void DeftemplateSlotRangeFunction(
void *theEnv,
DATA_OBJECT_PTR theValue)
{
struct deftemplate *theDeftemplate;
SYMBOL_HN *slotName;
/*===================================================*/
/* Retrieve the deftemplate and slot name arguments. */
/*===================================================*/
slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-range",&theDeftemplate);
if (slotName == NULL)
{
EnvSetMultifieldErrorValue(theEnv,theValue);
return;
}
/*=================================*/
/* Get the deftemplate slot range. */
/*=================================*/
EnvDeftemplateSlotRange(theEnv,theDeftemplate,ValueToString(slotName),theValue);
}
/**********************************************/
/* EnvDeftemplateSlotRange: C access routine */
/* for the deftemplate-slot-range function. */
/**********************************************/
globle void EnvDeftemplateSlotRange(
void *theEnv,
void *vTheDeftemplate,
char *slotName,
DATA_OBJECT *result)
{
struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;
short position;
struct templateSlot *theSlot;
/*===============================================*/
/* If we're dealing with an implied deftemplate, */
/* then the only slot names is "implied." */
/*===============================================*/
if (theDeftemplate->implied)
{
if (strcmp(slotName,"implied") == 0)
{
result->type = MULTIFIELD;
result->begin = 0;
result->end = 1;
result->value = EnvCreateMultifield(theEnv,2L);
SetMFType(result->value,1,SYMBOL);
SetMFValue(result->value,1,SymbolData(theEnv)->NegativeInfinity);
SetMFType(result->value,2,SYMBOL);
SetMFValue(result->value,2,SymbolData(theEnv)->PositiveInfinity);
return;
}
else
{
EnvSetMultifieldErrorValue(theEnv,result);
SetEvaluationError(theEnv,TRUE);
InvalidDeftemplateSlotMessage(theEnv,slotName,
ValueToString(theDeftemplate->header.name),FALSE);
return;
}
}
/*============================================*/
/* Otherwise search for the slot name in the */
/* list of slots defined for the deftemplate. */
/*============================================*/
else if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&position)) == NULL)
{
EnvSetMultifieldErrorValue(theEnv,result);
SetEvaluationError(theEnv,TRUE);
InvalidDeftemplateSlotMessage(theEnv,slotName,
ValueToString(theDeftemplate->header.name),FALSE);
return;
}
/*===============================*/
/* Return the range of the slot. */
/*===============================*/
if ((theSlot->constraints == NULL) ? FALSE :
(theSlot->constraints->anyAllowed || theSlot->constraints->floatsAllowed ||
theSlot->constraints->integersAllowed))
{
result->type = MULTIFIELD;
result->begin = 0;
result->end = 1;
result->value = EnvCreateMultifield(theEnv,2L);
SetMFType(result->value,1,theSlot->constraints->minValue->type);
SetMFValue(result->value,1,theSlot->constraints->minValue->value);
SetMFType(result->value,2,theSlot->constraints->maxValue->type);
SetMFValue(result->value,2,theSlot->constraints->maxValue->value);
}
else
{
result->type = SYMBOL;
result->value = EnvFalseSymbol(theEnv);
return;
}
}
/****************************************************/
/* DeftemplateSlotTypesFunction: H/L access routine */
/* for the deftemplate-slot-types function. */
/****************************************************/
globle void DeftemplateSlotTypesFunction(
void *theEnv,
DATA_OBJECT_PTR theValue)
{
struct deftemplate *theDeftemplate;
SYMBOL_HN *slotName;
/*===================================================*/
/* Retrieve the deftemplate and slot name arguments. */
/*===================================================*/
slotName = CheckDeftemplateAndSlotArguments(theEnv,"deftemplate-slot-types",&theDeftemplate);
if (slotName == NULL)
{
EnvSetMultifieldErrorValue(theEnv,theValue);
return;
}
/*=================================*/
/* Get the deftemplate slot types. */
/*=================================*/
EnvDeftemplateSlotTypes(theEnv,theDeftemplate,ValueToString(slotName),theValue);
}
/**********************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -