summaryrefslogtreecommitdiff
path: root/src/rulebsc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rulebsc.c')
-rw-r--r--src/rulebsc.c217
1 files changed, 178 insertions, 39 deletions
diff --git a/src/rulebsc.c b/src/rulebsc.c
index c62b235..7904ab6 100644
--- a/src/rulebsc.c
+++ b/src/rulebsc.c
@@ -1,7 +1,7 @@
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
- /* CLIPS Version 6.24 06/05/06 */
+ /* CLIPS Version 6.30 02/04/15 */
/* */
/* DEFRULE BASIC COMMANDS HEADER FILE */
/*******************************************************/
@@ -16,9 +16,10 @@
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
-/* Brian L. Donnell */
+/* Brian L. Dantes */
/* */
/* Revision History: */
+/* */
/* 6.23: Corrected compilation errors for files */
/* generated by constructs-to-c. DR0861 */
/* */
@@ -28,6 +29,21 @@
/* */
/* 6.24: Renamed BOOLEAN macro type to intBool. */
/* */
+/* 6.30: Removed conditional code for unsupported */
+/* compilers/operating systems (IBM_MCW, */
+/* MAC_MCW, and IBM_TBC). */
+/* */
+/* Support for join network changes. */
+/* */
+/* Added const qualifiers to remove C++ */
+/* deprecation warnings. */
+/* */
+/* Converted API macros to function calls. */
+/* */
+/* Added code to prevent a clear command from */
+/* being executed during fact assertions via */
+/* JoinOperationInProgress mechanism. */
+/* */
/*************************************************************/
#define _RULEBSC_SOURCE_
@@ -47,6 +63,8 @@
#include "extnfunc.h"
#include "ruledef.h"
#include "engine.h"
+#include "drive.h"
+#include "reteutil.h"
#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
#include "rulebin.h"
#endif
@@ -61,7 +79,8 @@
/***************************************/
static void ResetDefrules(void *);
- static void SaveDefrules(void *,void *,char *);
+ static void ResetDefrulesPrime(void *);
+ static void SaveDefrules(void *,void *,const char *);
#if (! RUN_TIME)
static int ClearDefrulesReady(void *);
static void ClearDefrules(void *);
@@ -74,12 +93,13 @@ globle void DefruleBasicCommands(
void *theEnv)
{
EnvAddResetFunction(theEnv,"defrule",ResetDefrules,70);
+ EnvAddResetFunction(theEnv,"defrule",ResetDefrulesPrime,10);
AddSaveFunction(theEnv,"defrule",SaveDefrules,0);
#if (! RUN_TIME)
AddClearReadyFunction(theEnv,"defrule",ClearDefrulesReady,0);
EnvAddClearFunction(theEnv,"defrule",ClearDefrules,0);
#endif
-
+
#if DEBUGGING_FUNCTIONS
AddWatchItem(theEnv,"rules",0,&DefruleData(theEnv)->WatchRules,70,DefruleWatchAccess,DefruleWatchPrint);
#endif
@@ -117,11 +137,81 @@ static void ResetDefrules(
void *theEnv)
{
struct defmodule *theModule;
-
- DefruleData(theEnv)->CurrentEntityTimeTag = 0L;
+ struct joinLink *theLink;
+ struct partialMatch *notParent;
+
+ DefruleData(theEnv)->CurrentEntityTimeTag = 1L;
EnvClearFocusStack(theEnv);
theModule = (struct defmodule *) EnvFindDefmodule(theEnv,"MAIN");
EnvFocus(theEnv,(void *) theModule);
+
+ for (theLink = DefruleData(theEnv)->RightPrimeJoins;
+ theLink != NULL;
+ theLink = theLink->next)
+ { PosEntryRetractAlpha(theEnv,theLink->join->rightMemory->beta[0],NETWORK_ASSERT); }
+
+ for (theLink = DefruleData(theEnv)->LeftPrimeJoins;
+ theLink != NULL;
+ theLink = theLink->next)
+ {
+ if ((theLink->join->patternIsNegated || theLink->join->joinFromTheRight) &&
+ (! theLink->join->patternIsExists))
+ {
+ notParent = theLink->join->leftMemory->beta[0];
+
+ if (notParent->marker)
+ { RemoveBlockedLink(notParent); }
+
+ /*==========================================================*/
+ /* Prevent any retractions from generating partial matches. */
+ /*==========================================================*/
+
+ notParent->marker = notParent;
+
+ if (notParent->children != NULL)
+ { PosEntryRetractBeta(theEnv,notParent,notParent->children,NETWORK_ASSERT); }
+ /*
+ if (notParent->dependents != NULL)
+ { RemoveLogicalSupport(theEnv,notParent); } */
+ }
+ }
+ }
+
+/*****************************************************/
+/* ResetDefrulesPrime: */
+/*****************************************************/
+static void ResetDefrulesPrime(
+ void *theEnv)
+ {
+ struct joinLink *theLink;
+ struct partialMatch *notParent;
+
+ for (theLink = DefruleData(theEnv)->RightPrimeJoins;
+ theLink != NULL;
+ theLink = theLink->next)
+ { NetworkAssert(theEnv,theLink->join->rightMemory->beta[0],theLink->join); }
+
+ for (theLink = DefruleData(theEnv)->LeftPrimeJoins;
+ theLink != NULL;
+ theLink = theLink->next)
+ {
+ if ((theLink->join->patternIsNegated || theLink->join->joinFromTheRight) &&
+ (! theLink->join->patternIsExists))
+ {
+ notParent = theLink->join->leftMemory->beta[0];
+
+ if (theLink->join->secondaryNetworkTest != NULL)
+ {
+ if (EvaluateSecondaryNetworkTest(theEnv,notParent,theLink->join) == FALSE)
+ { continue; }
+ }
+
+ notParent->marker = NULL;
+
+ EPMDrive(theEnv,notParent,theLink->join,NETWORK_ASSERT);
+ }
+ }
+
}
#if (! RUN_TIME)
@@ -133,11 +223,13 @@ static int ClearDefrulesReady(
void *theEnv)
{
if (EngineData(theEnv)->ExecutingRule != NULL) return(FALSE);
-
+
+ if (EngineData(theEnv)->JoinOperationInProgress) return(FALSE);
+
EnvClearFocusStack(theEnv);
if (EnvGetCurrentModule(theEnv) == NULL) return(FALSE);
- DefruleData(theEnv)->CurrentEntityTimeTag = 0L;
+ DefruleData(theEnv)->CurrentEntityTimeTag = 1L;
return(TRUE);
}
@@ -153,6 +245,7 @@ static void ClearDefrules(
theModule = (struct defmodule *) EnvFindDefmodule(theEnv,"MAIN");
EnvFocus(theEnv,(void *) theModule);
}
+
#endif
/**************************************/
@@ -162,9 +255,9 @@ static void ClearDefrules(
static void SaveDefrules(
void *theEnv,
void *theModule,
- char *logicalName)
+ const char *logicalName)
{
- SaveConstruct(theEnv,theModule,logicalName,DefruleData(theEnv)->DefruleConstruct);
+ SaveConstruct(theEnv,theModule,logicalName,DefruleData(theEnv)->DefruleConstruct);
}
/******************************************/
@@ -173,8 +266,8 @@ static void SaveDefrules(
/******************************************/
globle void UndefruleCommand(
void *theEnv)
- {
- UndefconstructCommand(theEnv,"undefrule",DefruleData(theEnv)->DefruleConstruct);
+ {
+ UndefconstructCommand(theEnv,"undefrule",DefruleData(theEnv)->DefruleConstruct);
}
/**********************************/
@@ -185,7 +278,7 @@ globle intBool EnvUndefrule(
void *theEnv,
void *theDefrule)
{
- return(Undefconstruct(theEnv,theDefrule,DefruleData(theEnv)->DefruleConstruct));
+ return(Undefconstruct(theEnv,theDefrule,DefruleData(theEnv)->DefruleConstruct));
}
/************************************************/
@@ -196,7 +289,7 @@ globle void GetDefruleListFunction(
void *theEnv,
DATA_OBJECT_PTR returnValue)
{
- GetConstructListFunction(theEnv,"get-defrule-list",returnValue,DefruleData(theEnv)->DefruleConstruct);
+ GetConstructListFunction(theEnv,"get-defrule-list",returnValue,DefruleData(theEnv)->DefruleConstruct);
}
/****************************************/
@@ -218,7 +311,7 @@ globle void EnvGetDefruleList(
globle void *DefruleModuleFunction(
void *theEnv)
{
- return(GetConstructModuleCommand(theEnv,"defrule-module",DefruleData(theEnv)->DefruleConstruct));
+ return(GetConstructModuleCommand(theEnv,"defrule-module",DefruleData(theEnv)->DefruleConstruct));
}
#if DEBUGGING_FUNCTIONS
@@ -239,8 +332,8 @@ globle void PPDefruleCommand(
/***********************************/
globle int PPDefrule(
void *theEnv,
- char *defruleName,
- char *logicalName)
+ const char *defruleName,
+ const char *logicalName)
{
return(PPConstruct(theEnv,defruleName,logicalName,DefruleData(theEnv)->DefruleConstruct));
}
@@ -252,7 +345,7 @@ globle int PPDefrule(
globle void ListDefrulesCommand(
void *theEnv)
{
- ListConstructCommand(theEnv,"list-defrules",DefruleData(theEnv)->DefruleConstruct);
+ ListConstructCommand(theEnv,"list-defrules",DefruleData(theEnv)->DefruleConstruct);
}
/*************************************/
@@ -261,10 +354,10 @@ globle void ListDefrulesCommand(
/*************************************/
globle void EnvListDefrules(
void *theEnv,
- char *logicalName,
+ const char *logicalName,
void *theModule)
{
- ListConstruct(theEnv,DefruleData(theEnv)->DefruleConstruct,logicalName,(struct defmodule *) theModule);
+ ListConstruct(theEnv,DefruleData(theEnv)->DefruleConstruct,logicalName,(struct defmodule *) theModule);
}
/*******************************************************/
@@ -272,15 +365,12 @@ globle void EnvListDefrules(
/* retrieving the current watch value of a defrule's */
/* activations. */
/*******************************************************/
-#if IBM_TBC
-#pragma argsused
-#endif
globle unsigned EnvGetDefruleWatchActivations(
void *theEnv,
void *rulePtr)
{
struct defrule *thePtr;
-#if MAC_MCW || IBM_MCW || MAC_XCD
+#if MAC_XCD
#pragma unused(theEnv)
#endif
@@ -297,15 +387,12 @@ globle unsigned EnvGetDefruleWatchActivations(
/* for retrieving the current watch value of */
/* a defrule's firings. */
/***********************************************/
-#if IBM_TBC
-#pragma argsused
-#endif
globle unsigned EnvGetDefruleWatchFirings(
void *theEnv,
void *rulePtr)
{
struct defrule *thePtr;
-#if MAC_MCW || IBM_MCW || MAC_XCD
+#if MAC_XCD
#pragma unused(theEnv)
#endif
@@ -322,16 +409,13 @@ globle unsigned EnvGetDefruleWatchFirings(
/* for setting the current watch value of a */
/* defrule's activations. */
/***************************************************/
-#if IBM_TBC
-#pragma argsused
-#endif
globle void EnvSetDefruleWatchActivations(
void *theEnv,
unsigned newState,
void *rulePtr)
{
struct defrule *thePtr;
-#if MAC_MCW || IBM_MCW || MAC_XCD
+#if MAC_XCD
#pragma unused(theEnv)
#endif
@@ -343,19 +427,16 @@ globle void EnvSetDefruleWatchActivations(
/****************************************************/
/* EnvSetDefruleWatchFirings: C access routine for */
-/* setting the current watch value of a defrule's */
+/* setting the current watch value of a defrule's */
/* firings. */
/****************************************************/
-#if IBM_TBC
-#pragma argsused
-#endif
globle void EnvSetDefruleWatchFirings(
void *theEnv,
unsigned newState,
void *rulePtr)
{
struct defrule *thePtr;
-#if MAC_MCW || IBM_MCW || MAC_XCD
+#if MAC_XCD
#pragma unused(theEnv)
#endif
@@ -389,10 +470,10 @@ globle unsigned DefruleWatchAccess(
/*****************************************************************/
globle unsigned DefruleWatchPrint(
void *theEnv,
- char *logName,
+ const char *logName,
int code,
struct expr *argExprs)
- {
+ {
if (code)
return(ConstructPrintWatchAccess(theEnv,DefruleData(theEnv)->DefruleConstruct,logName,argExprs,
EnvGetDefruleWatchActivations,EnvSetDefruleWatchActivations));
@@ -403,6 +484,64 @@ globle unsigned DefruleWatchPrint(
#endif /* DEBUGGING_FUNCTIONS */
+/*#####################################*/
+/* ALLOW_ENVIRONMENT_GLOBALS Functions */
+/*#####################################*/
+
+#if ALLOW_ENVIRONMENT_GLOBALS
+
+globle void GetDefruleList(
+ DATA_OBJECT_PTR returnValue,
+ void *theModule)
+ {
+ EnvGetDefruleList(GetCurrentEnvironment(),returnValue,theModule);
+ }
+
+#if DEBUGGING_FUNCTIONS
+
+globle unsigned GetDefruleWatchActivations(
+ void *rulePtr)
+ {
+ return EnvGetDefruleWatchActivations(GetCurrentEnvironment(),rulePtr);
+ }
+
+globle unsigned GetDefruleWatchFirings(
+ void *rulePtr)
+ {
+ return EnvGetDefruleWatchFirings(GetCurrentEnvironment(),rulePtr);
+ }
+
+globle void ListDefrules(
+ const char *logicalName,
+ void *theModule)
+ {
+ EnvListDefrules(GetCurrentEnvironment(),logicalName,theModule);
+ }
+
+globle void SetDefruleWatchActivations(
+ unsigned newState,
+ void *rulePtr)
+ {
+ EnvSetDefruleWatchActivations(GetCurrentEnvironment(),newState,rulePtr);
+ }
+
+globle void SetDefruleWatchFirings(
+ unsigned newState,
+ void *rulePtr)
+ {
+ EnvSetDefruleWatchFirings(GetCurrentEnvironment(),newState,rulePtr);
+ }
+
+#endif
+
+globle intBool Undefrule(
+ void *theDefrule)
+ {
+ return EnvUndefrule(GetCurrentEnvironment(),theDefrule);
+ }
+
+#endif /* ALLOW_ENVIRONMENT_GLOBALS */
+
#endif /* DEFTEMPLATE_CONSTRUCT */