1 /*******************************************************/
2 /* "C" Language Integrated Production System */
3 /* */
4 /* CLIPS Version 6.30 08/16/14 */
5 /* */
6 /* DEFGLOBAL BASIC COMMANDS HEADER FILE */
7 /*******************************************************/
8
9 /*************************************************************/
10 /* Purpose: Implements core commands for the defglobal */
11 /* construct such as clear, reset, save, undefglobal, */
12 /* ppdefglobal, list-defglobals, and get-defglobals-list. */
13 /* */
14 /* Principal Programmer(s): */
15 /* Gary D. Riley */
16 /* */
17 /* Contributing Programmer(s): */
18 /* Brian L. Dantes */
19 /* */
20 /* Revision History: */
21 /* */
22 /* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
23 /* */
24 /* Corrected compilation errors for files */
25 /* generated by constructs-to-c. DR0861 */
26 /* */
27 /* Changed name of variable log to logName */
28 /* because of Unix compiler warnings of shadowed */
29 /* definitions. */
30 /* */
31 /* 6.24: Renamed BOOLEAN macro type to intBool. */
32 /* */
33 /* 6.30: Removed conditional code for unsupported */
34 /* compilers/operating systems (IBM_MCW, */
35 /* MAC_MCW, and IBM_TBC). */
36 /* */
37 /* Added const qualifiers to remove C++ */
38 /* deprecation warnings. */
39 /* */
40 /* Moved WatchGlobals global to defglobalData. */
41 /* */
42 /* Converted API macros to function calls. */
43 /* */
44 /*************************************************************/
45
46 #define _GLOBLBSC_SOURCE_
47
48 #include "setup.h"
49
50 #if DEFGLOBAL_CONSTRUCT
51
52 #include "constrct.h"
53 #include "extnfunc.h"
54 #include "watch.h"
55 #include "envrnmnt.h"
56
57 #include "globlcom.h"
58 #include "globldef.h"
59
60 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
61 #include "globlbin.h"
62 #endif
63
64 #if CONSTRUCT_COMPILER && (! RUN_TIME)
65 #include "globlcmp.h"
66 #endif
67
68 #include "globlbsc.h"
69
70 /***************************************/
71 /* LOCAL INTERNAL FUNCTION DEFINITIONS */
72 /***************************************/
73
74 static void SaveDefglobals(void *,void *,const char *);
75 static void ResetDefglobalAction(void *,struct constructHeader *,void *);
76 #if DEBUGGING_FUNCTIONS && (! RUN_TIME)
77 static unsigned DefglobalWatchAccess(void *,int,unsigned,struct expr *);
78 static unsigned DefglobalWatchPrint(void *,const char *,int,struct expr *);
79 #endif
80
81 /*****************************************************************/
82 /* DefglobalBasicCommands: Initializes basic defglobal commands. */
83 /*****************************************************************/
DefglobalBasicCommands(void * theEnv)84 globle void DefglobalBasicCommands(
85 void *theEnv)
86 {
87 AddSaveFunction(theEnv,"defglobal",SaveDefglobals,40);
88 EnvAddResetFunction(theEnv,"defglobal",ResetDefglobals,50);
89
90 #if ! RUN_TIME
91 EnvDefineFunction2(theEnv,"get-defglobal-list",'m',PTIEF GetDefglobalListFunction,"GetDefglobalListFunction","01w");
92 EnvDefineFunction2(theEnv,"undefglobal",'v',PTIEF UndefglobalCommand,"UndefglobalCommand","11w");
93 EnvDefineFunction2(theEnv,"defglobal-module",'w',PTIEF DefglobalModuleFunction,"DefglobalModuleFunction","11w");
94
95 #if DEBUGGING_FUNCTIONS
96 EnvDefineFunction2(theEnv,"list-defglobals",'v', PTIEF ListDefglobalsCommand,"ListDefglobalsCommand","01w");
97 EnvDefineFunction2(theEnv,"ppdefglobal",'v',PTIEF PPDefglobalCommand,"PPDefglobalCommand","11w");
98 AddWatchItem(theEnv,"globals",0,&DefglobalData(theEnv)->WatchGlobals,0,DefglobalWatchAccess,DefglobalWatchPrint);
99 #endif
100
101 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
102 DefglobalBinarySetup(theEnv);
103 #endif
104
105 #if CONSTRUCT_COMPILER && (! RUN_TIME)
106 DefglobalCompilerSetup(theEnv);
107 #endif
108
109 #endif
110 }
111
112 /*************************************************************/
113 /* ResetDefglobals: Defglobal reset routine for use with the */
114 /* reset command. Restores the values of the defglobals. */
115 /*************************************************************/
ResetDefglobals(void * theEnv)116 globle void ResetDefglobals(
117 void *theEnv)
118 {
119 if (! EnvGetResetGlobals(theEnv)) return;
120 DoForAllConstructs(theEnv,ResetDefglobalAction,DefglobalData(theEnv)->DefglobalModuleIndex,TRUE,NULL);
121 }
122
123 /******************************************************/
124 /* ResetDefglobalAction: Action to be applied to each */
125 /* defglobal construct during a reset command. */
126 /******************************************************/
ResetDefglobalAction(void * theEnv,struct constructHeader * theConstruct,void * buffer)127 static void ResetDefglobalAction(
128 void *theEnv,
129 struct constructHeader *theConstruct,
130 void *buffer)
131 {
132 #if MAC_XCD
133 #pragma unused(buffer)
134 #endif
135 struct defglobal *theDefglobal = (struct defglobal *) theConstruct;
136 DATA_OBJECT assignValue;
137
138 if (EvaluateExpression(theEnv,theDefglobal->initial,&assignValue))
139 {
140 assignValue.type = SYMBOL;
141 assignValue.value = EnvFalseSymbol(theEnv);
142 }
143
144 QSetDefglobalValue(theEnv,theDefglobal,&assignValue,FALSE);
145 }
146
147 /******************************************/
148 /* SaveDefglobals: Defglobal save routine */
149 /* for use with the save command. */
150 /******************************************/
SaveDefglobals(void * theEnv,void * theModule,const char * logicalName)151 static void SaveDefglobals(
152 void *theEnv,
153 void *theModule,
154 const char *logicalName)
155 {
156 SaveConstruct(theEnv,theModule,logicalName,DefglobalData(theEnv)->DefglobalConstruct);
157 }
158
159 /********************************************/
160 /* UndefglobalCommand: H/L access routine */
161 /* for the undefglobal command. */
162 /********************************************/
UndefglobalCommand(void * theEnv)163 globle void UndefglobalCommand(
164 void *theEnv)
165 {
166 UndefconstructCommand(theEnv,"undefglobal",DefglobalData(theEnv)->DefglobalConstruct);
167 }
168
169 /************************************/
170 /* EnvUndefglobal: C access routine */
171 /* for the undefglobal command. */
172 /************************************/
EnvUndefglobal(void * theEnv,void * theDefglobal)173 globle intBool EnvUndefglobal(
174 void *theEnv,
175 void *theDefglobal)
176 {
177 return(Undefconstruct(theEnv,theDefglobal,DefglobalData(theEnv)->DefglobalConstruct));
178 }
179
180 /**************************************************/
181 /* GetDefglobalListFunction: H/L access routine */
182 /* for the get-defglobal-list function. */
183 /**************************************************/
GetDefglobalListFunction(void * theEnv,DATA_OBJECT_PTR returnValue)184 globle void GetDefglobalListFunction(
185 void *theEnv,
186 DATA_OBJECT_PTR returnValue)
187 {
188 GetConstructListFunction(theEnv,"get-defglobal-list",returnValue,DefglobalData(theEnv)->DefglobalConstruct);
189 }
190
191 /******************************************/
192 /* EnvGetDefglobalList: C access routine */
193 /* for the get-defglobal-list function. */
194 /******************************************/
EnvGetDefglobalList(void * theEnv,DATA_OBJECT_PTR returnValue,void * theModule)195 globle void EnvGetDefglobalList(
196 void *theEnv,
197 DATA_OBJECT_PTR returnValue,
198 void *theModule)
199 {
200 GetConstructList(theEnv,returnValue,DefglobalData(theEnv)->DefglobalConstruct,(struct defmodule *) theModule);
201 }
202
203 /*************************************************/
204 /* DefglobalModuleFunction: H/L access routine */
205 /* for the defglobal-module function. */
206 /*************************************************/
DefglobalModuleFunction(void * theEnv)207 globle void *DefglobalModuleFunction(
208 void *theEnv)
209 {
210 return(GetConstructModuleCommand(theEnv,"defglobal-module",DefglobalData(theEnv)->DefglobalConstruct));
211 }
212
213 #if DEBUGGING_FUNCTIONS
214
215 /********************************************/
216 /* PPDefglobalCommand: H/L access routine */
217 /* for the ppdefglobal command. */
218 /********************************************/
PPDefglobalCommand(void * theEnv)219 globle void PPDefglobalCommand(
220 void *theEnv)
221 {
222 PPConstructCommand(theEnv,"ppdefglobal",DefglobalData(theEnv)->DefglobalConstruct);
223 }
224
225 /*************************************/
226 /* PPDefglobal: C access routine for */
227 /* the ppdefglobal command. */
228 /*************************************/
PPDefglobal(void * theEnv,const char * defglobalName,const char * logicalName)229 globle int PPDefglobal(
230 void *theEnv,
231 const char *defglobalName,
232 const char *logicalName)
233 {
234 return(PPConstruct(theEnv,defglobalName,logicalName,DefglobalData(theEnv)->DefglobalConstruct));
235 }
236
237 /***********************************************/
238 /* ListDefglobalsCommand: H/L access routine */
239 /* for the list-defglobals command. */
240 /***********************************************/
ListDefglobalsCommand(void * theEnv)241 globle void ListDefglobalsCommand(
242 void *theEnv)
243 {
244 ListConstructCommand(theEnv,"list-defglobals",DefglobalData(theEnv)->DefglobalConstruct);
245 }
246
247 /***************************************/
248 /* EnvListDefglobals: C access routine */
249 /* for the list-defglobals command. */
250 /***************************************/
EnvListDefglobals(void * theEnv,const char * logicalName,void * vTheModule)251 globle void EnvListDefglobals(
252 void *theEnv,
253 const char *logicalName,
254 void *vTheModule)
255 {
256 struct defmodule *theModule = (struct defmodule *) vTheModule;
257
258 ListConstruct(theEnv,DefglobalData(theEnv)->DefglobalConstruct,logicalName,theModule);
259 }
260
261 /*********************************************************/
262 /* EnvGetDefglobalWatch: C access routine for retrieving */
263 /* the current watch value of a defglobal. */
264 /*********************************************************/
EnvGetDefglobalWatch(void * theEnv,void * theGlobal)265 globle unsigned EnvGetDefglobalWatch(
266 void *theEnv,
267 void *theGlobal)
268 {
269 #if MAC_XCD
270 #pragma unused(theEnv)
271 #endif
272
273 return(((struct defglobal *) theGlobal)->watch);
274 }
275
276 /********************************************************/
277 /* EnvSetDeftemplateWatch: C access routine for setting */
278 /* the current watch value of a deftemplate. */
279 /********************************************************/
EnvSetDefglobalWatch(void * theEnv,unsigned newState,void * theGlobal)280 globle void EnvSetDefglobalWatch(
281 void *theEnv,
282 unsigned newState,
283 void *theGlobal)
284 {
285 #if MAC_XCD
286 #pragma unused(theEnv)
287 #endif
288
289 ((struct defglobal *) theGlobal)->watch = newState;
290 }
291
292 #if ! RUN_TIME
293
294 /********************************************************/
295 /* DefglobalWatchAccess: Access routine for setting the */
296 /* watch flag of a defglobal via the watch command. */
297 /********************************************************/
DefglobalWatchAccess(void * theEnv,int code,unsigned newState,EXPRESSION * argExprs)298 static unsigned DefglobalWatchAccess(
299 void *theEnv,
300 int code,
301 unsigned newState,
302 EXPRESSION *argExprs)
303 {
304 #if MAC_XCD
305 #pragma unused(code)
306 #endif
307
308 return(ConstructSetWatchAccess(theEnv,DefglobalData(theEnv)->DefglobalConstruct,newState,argExprs,
309 EnvGetDefglobalWatch,EnvSetDefglobalWatch));
310 }
311
312 /*********************************************************************/
313 /* DefglobalWatchPrint: Access routine for printing which defglobals */
314 /* have their watch flag set via the list-watch-items command. */
315 /*********************************************************************/
DefglobalWatchPrint(void * theEnv,const char * logName,int code,EXPRESSION * argExprs)316 static unsigned DefglobalWatchPrint(
317 void *theEnv,
318 const char *logName,
319 int code,
320 EXPRESSION *argExprs)
321 {
322 #if MAC_XCD
323 #pragma unused(code)
324 #endif
325
326 return(ConstructPrintWatchAccess(theEnv,DefglobalData(theEnv)->DefglobalConstruct,logName,argExprs,
327 EnvGetDefglobalWatch,EnvSetDefglobalWatch));
328 }
329
330 #endif /* ! RUN_TIME */
331
332 #endif /* DEBUGGING_FUNCTIONS */
333
334 /*#####################################*/
335 /* ALLOW_ENVIRONMENT_GLOBALS Functions */
336 /*#####################################*/
337
338 #if ALLOW_ENVIRONMENT_GLOBALS
339
GetDefglobalList(DATA_OBJECT_PTR returnValue,void * theModule)340 globle void GetDefglobalList(
341 DATA_OBJECT_PTR returnValue,
342 void *theModule)
343 {
344 EnvGetDefglobalList(GetCurrentEnvironment(),returnValue,theModule);
345 }
346
347 #if DEBUGGING_FUNCTIONS
348
GetDefglobalWatch(void * theGlobal)349 globle unsigned GetDefglobalWatch(
350 void *theGlobal)
351 {
352 return EnvGetDefglobalWatch(GetCurrentEnvironment(),theGlobal);
353 }
354
ListDefglobals(const char * logicalName,void * vTheModule)355 globle void ListDefglobals(
356 const char *logicalName,
357 void *vTheModule)
358 {
359 EnvListDefglobals(GetCurrentEnvironment(),logicalName,vTheModule);
360 }
361
SetDefglobalWatch(unsigned newState,void * theGlobal)362 globle void SetDefglobalWatch(
363 unsigned newState,
364 void *theGlobal)
365 {
366 EnvSetDefglobalWatch(GetCurrentEnvironment(),newState,theGlobal);
367 }
368
369 #endif /* DEBUGGING_FUNCTIONS */
370
Undefglobal(void * theDefglobal)371 globle intBool Undefglobal(
372 void *theDefglobal)
373 {
374 return EnvUndefglobal(GetCurrentEnvironment(),theDefglobal);
375 }
376
377 #endif /* ALLOW_ENVIRONMENT_GLOBALS */
378
379 #endif /* DEFGLOBAL_CONSTRUCT */
380
381
382