-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathclips_or.c
More file actions
250 lines (201 loc) · 6.76 KB
/
Copy pathclips_or.c
File metadata and controls
250 lines (201 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* clips_or.c
* Source of functions from CLIPS explicitly reimplemented for PyCLIPS:
* depending on how CLIPS changes in time, some functions may appear or
* disappear (or be conditionally compiled) from here. Functions defined
* here have the same name as in the CLIPS API followed by _PY, and their
* arguments may be different from the official CLIPS ones. However these
* functions were actually copied from the original CLIPS sources, and
* only slightly changed: therefore I list myself only as a contributing
* programmer. Moreover, the license for this file is the one that covers
* the CLIPS source (which is BSD-like).
* $Id: clips_or.c 323 2007-04-02 22:24:35Z Franz $
*/
/* NOTE: This file used to be split in three parts, one per function */
/*************************************************************/
/* Principal Programmer(s): Gary D. Riley */
/* Brian L. Donnell */
/* */
/* Contributing Programmer(s): Francesco Garosi */
/* */
/*************************************************************/
#define _RULECOM_SOURCE_
#define _CONSTRCT_SOURCE_
#define _INSCOM_SOURCE_
#include <stdio.h>
#define _STDIO_INCLUDED_
#include <string.h>
#include "setup.h"
/* many of these might not be needed but they were in the original sources */
#include "argacces.h"
#include "commline.h"
#include "classcom.h"
#include "classfun.h"
#include "classinf.h"
#include "constant.h"
#include "constrct.h"
#include "crstrtgy.h"
#include "engine.h"
#include "envrnmnt.h"
#include "evaluatn.h"
#include "extnfunc.h"
#include "exprnpsr.h"
#include "insfile.h"
#include "insfun.h"
#include "insmngr.h"
#include "insmoddp.h"
#include "insmult.h"
#include "inspsr.h"
#include "lgcldpnd.h"
#include "memalloc.h"
#include "moduldef.h"
#include "msgcom.h"
#include "msgfun.h"
#include "multifld.h"
#include "pattern.h"
#include "prcdrfun.h"
#include "prcdrpsr.h"
#include "reteutil.h"
#include "router.h"
#include "ruledlt.h"
#include "scanner.h"
#include "sysdep.h"
#include "strngrtr.h"
#include "utility.h"
#include "watch.h"
#if BLOAD || BLOAD_AND_BSAVE || BLOAD_ONLY
#include "rulebin.h"
#endif
#if LOGICAL_DEPENDENCIES
#include "lgcldpnd.h"
#endif
#if INCREMENTAL_RESET
#include "incrrset.h"
#endif
#include "rulecom.h"
#include "constrct.h"
#include "inscom.h"
#include "clips_or.h"
/* EnvMatches_PY
* provides a customized version of the EnvMatches API, that can redirect
* its output to a specified output stream. This will be used instead of the
* Matches() standard API.
*/
#if DEFRULE_CONSTRUCT
/********************************/
/* EnvMatches: C access routine */
/* for the matches command. */
/********************************/
globle BOOLEAN EnvMatches_PY(
void *theEnv,
char *logicalName,
void *theRule)
{
DATA_OBJECT result;
EnvMatches(theEnv, theRule, VERBOSE, &result);
return(TRUE);
}
#endif /* DEFRULE_CONSTRUCT */
/* EnvClear_PY
* Overrides the EnvClear function that would normally conflict with PyCLIPS.
*/
/*****************************************************/
/* EnvClear: C access routine for the clear command. */
/*****************************************************/
globle BOOLEAN EnvClear_PY(
void *theEnv)
{
struct callFunctionItem *theFunction;
/*==========================================*/
/* Activate the watch router which captures */
/* trace output so that it is not displayed */
/* during a clear. */
/*==========================================*/
#if DEBUGGING_FUNCTIONS
EnvActivateRouter(theEnv,WTRACE);
#endif
/*===================================*/
/* Determine if a clear is possible. */
/*===================================*/
ConstructData(theEnv)->ClearReadyInProgress = TRUE;
if (ClearReady(theEnv) == FALSE)
{
PrintErrorID(theEnv,"CONSTRCT",1,FALSE);
EnvPrintRouter(theEnv,WERROR,"Some constructs are still in use. Clear cannot continue.\n");
#if DEBUGGING_FUNCTIONS
EnvDeactivateRouter(theEnv,WTRACE);
#endif
ConstructData(theEnv)->ClearReadyInProgress = FALSE;
return FALSE;
}
ConstructData(theEnv)->ClearReadyInProgress = FALSE;
/*===========================*/
/* Call all clear functions. */
/*===========================*/
ConstructData(theEnv)->ClearInProgress = TRUE;
for (theFunction = ConstructData(theEnv)->ListOfClearFunctions;
theFunction != NULL;
theFunction = theFunction->next)
{
if (theFunction->environmentAware)
{ (*theFunction->func)(theEnv); }
else
{ (* (void (*)(void)) theFunction->func)(); }
}
/*=============================*/
/* Deactivate the watch router */
/* for capturing output. */
/*=============================*/
#if DEBUGGING_FUNCTIONS
EnvDeactivateRouter(theEnv,WTRACE);
#endif
ConstructData(theEnv)->ClearInProgress = FALSE;
return TRUE;
}
/* EnvGetNextInstanceInClassAndSubclasses_PY
* provides a customized version of the EnvGetNextInstanceInClassAndSubclasses
* API, that does not "return" a pointer to the subclass. This will be used
* instead of the EnvGetNextInstanceInClassAndSubclasses() standard API.
*/
#if OBJECT_SYSTEM
/***************************************************
NAME : EnvGetNextInstanceInClassAndSubclasses
DESCRIPTION : Finds next instance of class
(or first instance of class) and
all of its subclasses
INPUTS : 1) Class address (DIRECT POINTER!)
2) Instance address
(NULL to get first instance)
RETURNS : The next or first class instance
SIDE EFFECTS : None
NOTES : None
***************************************************/
globle void *EnvGetNextInstanceInClassAndSubclasses_PY(
void *theEnv,
void *cptr, /* this has changed */
void *iptr,
DATA_OBJECT *iterationInfo)
{
INSTANCE_TYPE *nextInstance;
DEFCLASS *theClass;
theClass = (DEFCLASS *)cptr;
if (iptr == NULL)
{
ClassSubclassAddresses(theEnv,theClass,iterationInfo,TRUE);
nextInstance = theClass->instanceList;
}
else if (((INSTANCE_TYPE *) iptr)->garbage == 1)
{ nextInstance = NULL; }
else
{ nextInstance = ((INSTANCE_TYPE *) iptr)->nxtClass; }
while ((nextInstance == NULL) &&
(GetpDOBegin(iterationInfo) <= GetpDOEnd(iterationInfo)))
{
theClass = (struct defclass *) GetMFValue(DOPToPointer(iterationInfo),
GetpDOBegin(iterationInfo));
SetpDOBegin(iterationInfo,GetpDOBegin(iterationInfo) + 1);
nextInstance = theClass->instanceList;
}
return(nextInstance);
}
#endif /* OBJECT_SYSTEM */
/* end. */