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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.40 07/02/18 */
/* */
/* DEFGLOBAL BASIC COMMANDS HEADER FILE */
/*******************************************************/
/*************************************************************/
/* Purpose: Implements core commands for the defglobal */
/* construct such as clear, reset, save, undefglobal, */
/* ppdefglobal, list-defglobals, and get-defglobals-list. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* Brian L. Dantes */
/* */
/* Revision History: */
/* */
/* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
/* */
/* Corrected compilation errors for files */
/* generated by constructs-to-c. DR0861 */
/* */
/* Changed name of variable log to logName */
/* because of Unix compiler warnings of shadowed */
/* definitions. */
/* */
/* 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). */
/* */
/* Added const qualifiers to remove C++ */
/* deprecation warnings. */
/* */
/* Moved WatchGlobals global to defglobalData. */
/* */
/* Converted API macros to function calls. */
/* */
/* 6.40: Pragma once and other inclusion changes. */
/* */
/* Added support for booleans with <stdbool.h>. */
/* */
/* Removed use of void pointers for specific */
/* data structures. */
/* */
/* ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
/* */
/* UDF redesign. */
/* */
/* Pretty print functions accept optional logical */
/* name argument. */
/* */
/*************************************************************/
#include "setup.h"
#if DEFGLOBAL_CONSTRUCT
#include "constrct.h"
#include "envrnmnt.h"
#include "extnfunc.h"
#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
#include "globlbin.h"
#endif
#if CONSTRUCT_COMPILER && (! RUN_TIME)
#include "globlcmp.h"
#endif
#include "globlcom.h"
#include "globldef.h"
#include "multifld.h"
#include "watch.h"
#include "globlbsc.h"
/***************************************/
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
/***************************************/
static void SaveDefglobals(Environment *,Defmodule *,const char *,void *);
static void ResetDefglobalAction(Environment *,ConstructHeader *,void *);
#if DEBUGGING_FUNCTIONS && (! RUN_TIME)
static bool DefglobalWatchAccess(Environment *,int,bool,struct expr *);
static bool DefglobalWatchPrint(Environment *,const char *,int,struct expr *);
#endif
/*****************************************************************/
/* DefglobalBasicCommands: Initializes basic defglobal commands. */
/*****************************************************************/
void DefglobalBasicCommands(
Environment *theEnv)
{
AddSaveFunction(theEnv,"defglobal",SaveDefglobals,40,NULL);
AddResetFunction(theEnv,"defglobal",ResetDefglobals,50,NULL);
#if ! RUN_TIME
AddUDF(theEnv,"get-defglobal-list","m",0,1,"y",GetDefglobalListFunction,"GetDefglobalListFunction",NULL);
AddUDF(theEnv,"undefglobal","v",1,1,"y",UndefglobalCommand,"UndefglobalCommand",NULL);
AddUDF(theEnv,"defglobal-module","y",1,1,"y",DefglobalModuleFunction,"DefglobalModuleFunction",NULL);
#if DEBUGGING_FUNCTIONS
AddUDF(theEnv,"list-defglobals","v",0,1,"y",ListDefglobalsCommand,"ListDefglobalsCommand",NULL);
AddUDF(theEnv,"ppdefglobal","vs",1,2,";y;ldsyn",PPDefglobalCommand,"PPDefglobalCommand",NULL);
AddWatchItem(theEnv,"globals",0,&DefglobalData(theEnv)->WatchGlobals,0,DefglobalWatchAccess,DefglobalWatchPrint);
#endif
#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
DefglobalBinarySetup(theEnv);
#endif
#if CONSTRUCT_COMPILER && (! RUN_TIME)
DefglobalCompilerSetup(theEnv);
#endif
#endif
}
/*************************************************************/
/* ResetDefglobals: Defglobal reset routine for use with the */
/* reset command. Restores the values of the defglobals. */
/*************************************************************/
void ResetDefglobals(
Environment *theEnv,
void *context)
{
if (! GetResetGlobals(theEnv)) return;
DoForAllConstructs(theEnv,ResetDefglobalAction,
DefglobalData(theEnv)->DefglobalModuleIndex,true,NULL);
}
/******************************************************/
/* ResetDefglobalAction: Action to be applied to each */
/* defglobal construct during a reset command. */
/******************************************************/
static void ResetDefglobalAction(
Environment *theEnv,
ConstructHeader *theConstruct,
void *buffer)
{
#if MAC_XCD
#pragma unused(buffer)
#endif
Defglobal *theDefglobal = (Defglobal *) theConstruct;
UDFValue assignValue;
if (EvaluateExpression(theEnv,theDefglobal->initial,&assignValue))
{
assignValue.value = FalseSymbol(theEnv);
}
QSetDefglobalValue(theEnv,theDefglobal,&assignValue,false);
}
/******************************************/
/* SaveDefglobals: Defglobal save routine */
/* for use with the save command. */
/******************************************/
static void SaveDefglobals(
Environment *theEnv,
Defmodule *theModule,
const char *logicalName,
void *context)
{
SaveConstruct(theEnv,theModule,logicalName,DefglobalData(theEnv)->DefglobalConstruct);
}
/********************************************/
/* UndefglobalCommand: H/L access routine */
/* for the undefglobal command. */
/********************************************/
void UndefglobalCommand(
Environment *theEnv,
UDFContext *context,
UDFValue *returnValue)
{
UndefconstructCommand(context,"undefglobal",DefglobalData(theEnv)->DefglobalConstruct);
}
/**********************************/
/* Undefglobal: C access routine */
/* for the undefglobal command. */
/**********************************/
bool Undefglobal(
Defglobal *theDefglobal,
Environment *allEnv)
{
Environment *theEnv;
if (theDefglobal == NULL)
{
theEnv = allEnv;
return(Undefconstruct(theEnv,NULL,DefglobalData(theEnv)->DefglobalConstruct));
}
else
{
theEnv = theDefglobal->header.env;
return(Undefconstruct(theEnv,&theDefglobal->header,DefglobalData(theEnv)->DefglobalConstruct));
}
}
/**************************************************/
/* GetDefglobalListFunction: H/L access routine */
/* for the get-defglobal-list function. */
/**************************************************/
void GetDefglobalListFunction(
Environment *theEnv,
UDFContext *context,
UDFValue *returnValue)
{
GetConstructListFunction(context,returnValue,DefglobalData(theEnv)->DefglobalConstruct);
}
/******************************************/
/* GetDefglobalList: C access routine */
/* for the get-defglobal-list function. */
/******************************************/
void GetDefglobalList(
Environment *theEnv,
CLIPSValue *returnValue,
Defmodule *theModule)
{
UDFValue result;
GetConstructList(theEnv,&result,DefglobalData(theEnv)->DefglobalConstruct,theModule);
NormalizeMultifield(theEnv,&result);
returnValue->value = result.value;
}
/*************************************************/
/* DefglobalModuleFunction: H/L access routine */
/* for the defglobal-module function. */
/*************************************************/
void DefglobalModuleFunction(
Environment *theEnv,
UDFContext *context,
UDFValue *returnValue)
{
returnValue->value = GetConstructModuleCommand(context,"defglobal-module",DefglobalData(theEnv)->DefglobalConstruct);
}
#if DEBUGGING_FUNCTIONS
/********************************************/
/* PPDefglobalCommand: H/L access routine */
/* for the ppdefglobal command. */
/********************************************/
void PPDefglobalCommand(
Environment *theEnv,
UDFContext *context,
UDFValue *returnValue)
{
PPConstructCommand(context,"ppdefglobal",DefglobalData(theEnv)->DefglobalConstruct,returnValue);
}
/*************************************/
/* PPDefglobal: C access routine for */
/* the ppdefglobal command. */
/*************************************/
bool PPDefglobal(
Environment *theEnv,
const char *defglobalName,
const char *logicalName)
{
return(PPConstruct(theEnv,defglobalName,logicalName,DefglobalData(theEnv)->DefglobalConstruct));
}
/***********************************************/
/* ListDefglobalsCommand: H/L access routine */
/* for the list-defglobals command. */
/***********************************************/
void ListDefglobalsCommand(
Environment *theEnv,
UDFContext *context,
UDFValue *returnValue)
{
ListConstructCommand(context,DefglobalData(theEnv)->DefglobalConstruct);
}
/**************************************/
/* ListDefglobals: C access routine */
/* for the list-defglobals command. */
/**************************************/
void ListDefglobals(
Environment *theEnv,
const char *logicalName,
Defmodule *theModule)
{
ListConstruct(theEnv,DefglobalData(theEnv)->DefglobalConstruct,logicalName,theModule);
}
/******************************************************/
/* DefglobalGetWatch: C access routine for retrieving */
/* the current watch value of a defglobal. */
/******************************************************/
bool DefglobalGetWatch(
Defglobal *theGlobal)
{
return theGlobal->watch;
}
/******************************************************/
/* EnvSetDefglobalWatch: C access routine for setting */
/* the current watch value of a defglobal. */
/******************************************************/
void DefglobalSetWatch(
Defglobal *theGlobal,
bool newState)
{
theGlobal->watch = newState;
}
#if ! RUN_TIME
/********************************************************/
/* DefglobalWatchAccess: Access routine for setting the */
/* watch flag of a defglobal via the watch command. */
/********************************************************/
static bool DefglobalWatchAccess(
Environment *theEnv,
int code,
bool newState,
Expression *argExprs)
{
#if MAC_XCD
#pragma unused(code)
#endif
return(ConstructSetWatchAccess(theEnv,DefglobalData(theEnv)->DefglobalConstruct,newState,argExprs,
(ConstructGetWatchFunction *) DefglobalGetWatch,
(ConstructSetWatchFunction *) DefglobalSetWatch));
}
/*********************************************************************/
/* DefglobalWatchPrint: Access routine for printing which defglobals */
/* have their watch flag set via the list-watch-items command. */
/*********************************************************************/
static bool DefglobalWatchPrint(
Environment *theEnv,
const char *logName,
int code,
Expression *argExprs)
{
#if MAC_XCD
#pragma unused(code)
#endif
return(ConstructPrintWatchAccess(theEnv,DefglobalData(theEnv)->DefglobalConstruct,logName,argExprs,
(ConstructGetWatchFunction *) DefglobalGetWatch,
(ConstructSetWatchFunction *) DefglobalSetWatch));
}
#endif /* ! RUN_TIME */
#endif /* DEBUGGING_FUNCTIONS */
#endif /* DEFGLOBAL_CONSTRUCT */