00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #define _DFFCTDEF_SOURCE_
00030
00031 #include "setup.h"
00032
00033 #if DEFFACTS_CONSTRUCT
00034
00035 #include <stdio.h>
00036 #define _STDIO_INCLUDED_
00037
00038 #include "memalloc.h"
00039 #include "dffctpsr.h"
00040 #include "dffctbsc.h"
00041 #include "envrnmnt.h"
00042
00043 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00044 #include "bload.h"
00045 #include "dffctbin.h"
00046 #endif
00047
00048 #if CONSTRUCT_COMPILER && (! RUN_TIME)
00049 #include "dffctcmp.h"
00050 #endif
00051
00052 #include "dffctdef.h"
00053
00054
00055
00056
00057
00058 static void *AllocateModule(void *);
00059 static void ReturnModule(void *,void *);
00060 static void ReturnDeffacts(void *,void *);
00061 static void InitializeDeffactsModules(void *);
00062 static void DeallocateDeffactsData(void *);
00063 #if ! RUN_TIME
00064 static void DestroyDeffactsAction(void *,struct constructHeader *,void *);
00065 #endif
00066
00067
00068
00069
00070 globle void InitializeDeffacts(
00071 void *theEnv)
00072 {
00073 AllocateEnvironmentData(theEnv,DEFFACTS_DATA,sizeof(struct deffactsData),DeallocateDeffactsData);
00074
00075 InitializeDeffactsModules(theEnv);
00076
00077 DeffactsBasicCommands(theEnv);
00078
00079 DeffactsData(theEnv)->DeffactsConstruct =
00080 AddConstruct(theEnv,"deffacts","deffacts",ParseDeffacts,EnvFindDeffacts,
00081 GetConstructNamePointer,GetConstructPPForm,
00082 GetConstructModuleItem,EnvGetNextDeffacts,SetNextConstruct,
00083 EnvIsDeffactsDeletable,EnvUndeffacts,ReturnDeffacts);
00084 }
00085
00086
00087
00088
00089
00090 static void DeallocateDeffactsData(
00091 void *theEnv)
00092 {
00093 #if ! RUN_TIME
00094 struct deffactsModule *theModuleItem;
00095 void *theModule;
00096
00097 #if BLOAD || BLOAD_AND_BSAVE
00098 if (Bloaded(theEnv)) return;
00099 #endif
00100
00101 DoForAllConstructs(theEnv,DestroyDeffactsAction,DeffactsData(theEnv)->DeffactsModuleIndex,FALSE,NULL);
00102
00103 for (theModule = EnvGetNextDefmodule(theEnv,NULL);
00104 theModule != NULL;
00105 theModule = EnvGetNextDefmodule(theEnv,theModule))
00106 {
00107 theModuleItem = (struct deffactsModule *)
00108 GetModuleItem(theEnv,(struct defmodule *) theModule,
00109 DeffactsData(theEnv)->DeffactsModuleIndex);
00110 rtn_struct(theEnv,deffactsModule,theModuleItem);
00111 }
00112 #else
00113 #if MAC_MCW || WIN_MCW || MAC_XCD
00114 #pragma unused(theEnv)
00115 #endif
00116 #endif
00117 }
00118
00119 #if ! RUN_TIME
00120
00121
00122
00123
00124 #if WIN_BTC
00125 #pragma argsused
00126 #endif
00127 static void DestroyDeffactsAction(
00128 void *theEnv,
00129 struct constructHeader *theConstruct,
00130 void *buffer)
00131 {
00132 #if MAC_MCW || WIN_MCW || MAC_XCD
00133 #pragma unused(buffer)
00134 #endif
00135 #if (! BLOAD_ONLY) && (! RUN_TIME)
00136 struct deffacts *theDeffacts = (struct deffacts *) theConstruct;
00137
00138 if (theDeffacts == NULL) return;
00139
00140 ReturnPackedExpression(theEnv,theDeffacts->assertList);
00141
00142 DestroyConstructHeader(theEnv,&theDeffacts->header);
00143
00144 rtn_struct(theEnv,deffacts,theDeffacts);
00145 #else
00146 #if MAC_MCW || WIN_MCW || MAC_XCD
00147 #pragma unused(theEnv,theConstruct)
00148 #endif
00149 #endif
00150 }
00151 #endif
00152
00153
00154
00155
00156
00157 static void InitializeDeffactsModules(
00158 void *theEnv)
00159 {
00160 DeffactsData(theEnv)->DeffactsModuleIndex =
00161 RegisterModuleItem(theEnv,"deffacts",
00162 AllocateModule,
00163 ReturnModule,
00164 #if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
00165 BloadDeffactsModuleReference,
00166 #else
00167 NULL,
00168 #endif
00169 #if CONSTRUCT_COMPILER && (! RUN_TIME)
00170 DeffactsCModuleReference,
00171 #else
00172 NULL,
00173 #endif
00174 EnvFindDeffacts);
00175 }
00176
00177
00178
00179
00180 static void *AllocateModule(
00181 void *theEnv)
00182 {
00183 return((void *) get_struct(theEnv,deffactsModule));
00184 }
00185
00186
00187
00188
00189 static void ReturnModule(
00190 void *theEnv,
00191 void *theItem)
00192 {
00193 FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DeffactsData(theEnv)->DeffactsConstruct);
00194 rtn_struct(theEnv,deffactsModule,theItem);
00195 }
00196
00197
00198
00199
00200
00201 globle struct deffactsModule *GetDeffactsModuleItem(
00202 void *theEnv,
00203 struct defmodule *theModule)
00204 {
00205 return((struct deffactsModule *) GetConstructModuleItemByIndex(theEnv,theModule,DeffactsData(theEnv)->DeffactsModuleIndex));
00206 }
00207
00208
00209
00210
00211
00212
00213 globle void *EnvFindDeffacts(
00214 void *theEnv,
00215 char *deffactsName)
00216 {
00217 return(FindNamedConstruct(theEnv,deffactsName,DeffactsData(theEnv)->DeffactsConstruct));
00218 }
00219
00220
00221
00222
00223
00224
00225
00226 globle void *EnvGetNextDeffacts(
00227 void *theEnv,
00228 void *deffactsPtr)
00229 {
00230 return((void *) GetNextConstructItem(theEnv,(struct constructHeader *) deffactsPtr,DeffactsData(theEnv)->DeffactsModuleIndex));
00231 }
00232
00233
00234
00235
00236
00237 #if WIN_BTC
00238 #pragma argsused
00239 #endif
00240 globle intBool EnvIsDeffactsDeletable(
00241 void *theEnv,
00242 void *ptr)
00243 {
00244 #if MAC_MCW || WIN_MCW || MAC_XCD
00245 #pragma unused(ptr)
00246 #endif
00247 if (! ConstructsDeletable(theEnv))
00248 { return FALSE; }
00249
00250 if (ConstructData(theEnv)->ResetInProgress) return(FALSE);
00251
00252 return(TRUE);
00253 }
00254
00255
00256
00257
00258
00259 static void ReturnDeffacts(
00260 void *theEnv,
00261 void *vTheDeffacts)
00262 {
00263 #if (MAC_MCW || WIN_MCW) && (RUN_TIME || BLOAD_ONLY)
00264 #pragma unused(theEnv,vTheDeffacts)
00265 #endif
00266
00267 #if (! BLOAD_ONLY) && (! RUN_TIME)
00268 struct deffacts *theDeffacts = (struct deffacts *) vTheDeffacts;
00269
00270 if (theDeffacts == NULL) return;
00271
00272 ExpressionDeinstall(theEnv,theDeffacts->assertList);
00273 ReturnPackedExpression(theEnv,theDeffacts->assertList);
00274
00275 DeinstallConstructHeader(theEnv,&theDeffacts->header);
00276
00277 rtn_struct(theEnv,deffacts,theDeffacts);
00278 #endif
00279 }
00280
00281 #endif
00282
00283