00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define _CSTRNBIN_SOURCE_
00025
00026 #include "setup.h"
00027
00028 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
00029
00030 #include "constant.h"
00031 #include "envrnmnt.h"
00032 #include "memalloc.h"
00033 #include "router.h"
00034 #include "bload.h"
00035
00036 #if BLOAD_AND_BSAVE
00037 #include "bsave.h"
00038 #endif
00039
00040 #include "cstrnbin.h"
00041
00042
00043
00044
00045
00046 struct bsaveConstraintRecord
00047 {
00048 unsigned int anyAllowed : 1;
00049 unsigned int symbolsAllowed : 1;
00050 unsigned int stringsAllowed : 1;
00051 unsigned int floatsAllowed : 1;
00052 unsigned int integersAllowed : 1;
00053 unsigned int instanceNamesAllowed : 1;
00054 unsigned int instanceAddressesAllowed : 1;
00055 unsigned int externalAddressesAllowed : 1;
00056 unsigned int factAddressesAllowed : 1;
00057 unsigned int anyRestriction : 1;
00058 unsigned int symbolRestriction : 1;
00059 unsigned int stringRestriction : 1;
00060 unsigned int numberRestriction : 1;
00061 unsigned int floatRestriction : 1;
00062 unsigned int integerRestriction : 1;
00063 unsigned int classRestriction : 1;
00064 unsigned int instanceNameRestriction : 1;
00065 unsigned int multifieldsAllowed : 1;
00066 unsigned int singlefieldsAllowed : 1;
00067 long classList;
00068 long restrictionList;
00069 long minValue;
00070 long maxValue;
00071 long minFields;
00072 long maxFields;
00073 };
00074
00075 typedef struct bsaveConstraintRecord BSAVE_CONSTRAINT_RECORD;
00076
00077
00078
00079
00080
00081 #if BLOAD_AND_BSAVE
00082 static void CopyToBsaveConstraintRecord(void *,CONSTRAINT_RECORD *,BSAVE_CONSTRAINT_RECORD *);
00083 #endif
00084 static void CopyFromBsaveConstraintRecord(void *,void *,long);
00085
00086 #if BLOAD_AND_BSAVE
00087
00088
00089
00090
00091
00092
00093 globle void WriteNeededConstraints(
00094 void *theEnv,
00095 FILE *fp)
00096 {
00097 int i;
00098 unsigned short theIndex = 0;
00099 unsigned long int numberOfUsedConstraints = 0;
00100 CONSTRAINT_RECORD *tmpPtr;
00101 BSAVE_CONSTRAINT_RECORD bsaveConstraints;
00102
00103
00104
00105
00106
00107 for (i = 0; i < SIZE_CONSTRAINT_HASH; i++)
00108 {
00109 for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
00110 tmpPtr != NULL;
00111 tmpPtr = tmpPtr->next)
00112 {
00113 tmpPtr->bsaveIndex = theIndex++;
00114 numberOfUsedConstraints++;
00115 }
00116 }
00117
00118
00119
00120
00121
00122
00123 if ((! EnvGetDynamicConstraintChecking(theEnv)) && (numberOfUsedConstraints != 0))
00124 {
00125 numberOfUsedConstraints = 0;
00126 PrintWarningID(theEnv,"CSTRNBIN",1,FALSE);
00127 EnvPrintRouter(theEnv,WWARNING,"Constraints are not saved with a binary image\n");
00128 EnvPrintRouter(theEnv,WWARNING," when dynamic constraint checking is disabled.\n");
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 GenWrite(&numberOfUsedConstraints,sizeof(unsigned long int),fp);
00138 if (numberOfUsedConstraints == 0) return;
00139
00140 for (i = 0 ; i < SIZE_CONSTRAINT_HASH; i++)
00141 {
00142 for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
00143 tmpPtr != NULL;
00144 tmpPtr = tmpPtr->next)
00145 {
00146 CopyToBsaveConstraintRecord(theEnv,tmpPtr,&bsaveConstraints);
00147 GenWrite(&bsaveConstraints,sizeof(BSAVE_CONSTRAINT_RECORD),fp);
00148 }
00149 }
00150 }
00151
00152
00153
00154
00155
00156
00157 static void CopyToBsaveConstraintRecord(
00158 void *theEnv,
00159 CONSTRAINT_RECORD *constraints,
00160 BSAVE_CONSTRAINT_RECORD *bsaveConstraints)
00161 {
00162 bsaveConstraints->anyAllowed = constraints->anyAllowed;
00163 bsaveConstraints->symbolsAllowed = constraints->symbolsAllowed;
00164 bsaveConstraints->stringsAllowed = constraints->stringsAllowed;
00165 bsaveConstraints->floatsAllowed = constraints->floatsAllowed;
00166 bsaveConstraints->integersAllowed = constraints->integersAllowed;
00167 bsaveConstraints->instanceNamesAllowed = constraints->instanceNamesAllowed;
00168 bsaveConstraints->instanceAddressesAllowed = constraints->instanceAddressesAllowed;
00169 bsaveConstraints->externalAddressesAllowed = constraints->externalAddressesAllowed;
00170 bsaveConstraints->multifieldsAllowed = constraints->multifieldsAllowed;
00171 bsaveConstraints->singlefieldsAllowed = constraints->singlefieldsAllowed;
00172 bsaveConstraints->factAddressesAllowed = constraints->factAddressesAllowed;
00173 bsaveConstraints->anyRestriction = constraints->anyRestriction;
00174 bsaveConstraints->symbolRestriction = constraints->symbolRestriction;
00175 bsaveConstraints->stringRestriction = constraints->stringRestriction;
00176 bsaveConstraints->floatRestriction = constraints->floatRestriction;
00177 bsaveConstraints->integerRestriction = constraints->integerRestriction;
00178 bsaveConstraints->classRestriction = constraints->classRestriction;
00179 bsaveConstraints->instanceNameRestriction = constraints->instanceNameRestriction;
00180
00181 bsaveConstraints->restrictionList = HashedExpressionIndex(theEnv,constraints->restrictionList);
00182 bsaveConstraints->classList = HashedExpressionIndex(theEnv,constraints->classList);
00183 bsaveConstraints->minValue = HashedExpressionIndex(theEnv,constraints->minValue);
00184 bsaveConstraints->maxValue = HashedExpressionIndex(theEnv,constraints->maxValue);
00185 bsaveConstraints->minFields = HashedExpressionIndex(theEnv,constraints->minFields);
00186 bsaveConstraints->maxFields = HashedExpressionIndex(theEnv,constraints->maxFields);
00187 }
00188
00189 #endif
00190
00191
00192
00193
00194
00195 globle void ReadNeededConstraints(
00196 void *theEnv)
00197 {
00198 GenReadBinary(theEnv,(void *) &ConstraintData(theEnv)->NumberOfConstraints,sizeof(unsigned long int));
00199 if (ConstraintData(theEnv)->NumberOfConstraints == 0) return;
00200
00201 ConstraintData(theEnv)->ConstraintArray = (CONSTRAINT_RECORD *)
00202 genalloc(theEnv,(sizeof(CONSTRAINT_RECORD) * ConstraintData(theEnv)->NumberOfConstraints));
00203
00204 BloadandRefresh(theEnv,ConstraintData(theEnv)->NumberOfConstraints,sizeof(BSAVE_CONSTRAINT_RECORD),
00205 CopyFromBsaveConstraintRecord);
00206 }
00207
00208
00209
00210
00211
00212
00213 static void CopyFromBsaveConstraintRecord(
00214 void *theEnv,
00215 void *buf,
00216 long theIndex)
00217 {
00218 BSAVE_CONSTRAINT_RECORD *bsaveConstraints;
00219 CONSTRAINT_RECORD *constraints;
00220
00221 bsaveConstraints = (BSAVE_CONSTRAINT_RECORD *) buf;
00222 constraints = (CONSTRAINT_RECORD *) &ConstraintData(theEnv)->ConstraintArray[theIndex];
00223
00224 constraints->anyAllowed = bsaveConstraints->anyAllowed;
00225 constraints->symbolsAllowed = bsaveConstraints->symbolsAllowed;
00226 constraints->stringsAllowed = bsaveConstraints->stringsAllowed;
00227 constraints->floatsAllowed = bsaveConstraints->floatsAllowed;
00228 constraints->integersAllowed = bsaveConstraints->integersAllowed;
00229 constraints->instanceNamesAllowed = bsaveConstraints->instanceNamesAllowed;
00230 constraints->instanceAddressesAllowed = bsaveConstraints->instanceAddressesAllowed;
00231 constraints->externalAddressesAllowed = bsaveConstraints->externalAddressesAllowed;
00232 constraints->voidAllowed = FALSE;
00233 constraints->multifieldsAllowed = bsaveConstraints->multifieldsAllowed;
00234 constraints->singlefieldsAllowed = bsaveConstraints->singlefieldsAllowed;
00235 constraints->factAddressesAllowed = bsaveConstraints->factAddressesAllowed;
00236 constraints->anyRestriction = bsaveConstraints->anyRestriction;
00237 constraints->symbolRestriction = bsaveConstraints->symbolRestriction;
00238 constraints->stringRestriction = bsaveConstraints->stringRestriction;
00239 constraints->floatRestriction = bsaveConstraints->floatRestriction;
00240 constraints->integerRestriction = bsaveConstraints->integerRestriction;
00241 constraints->classRestriction = bsaveConstraints->classRestriction;
00242 constraints->instanceNameRestriction = bsaveConstraints->instanceNameRestriction;
00243
00244 constraints->restrictionList = HashedExpressionPointer(bsaveConstraints->restrictionList);
00245 constraints->classList = HashedExpressionPointer(bsaveConstraints->classList);
00246 constraints->minValue = HashedExpressionPointer(bsaveConstraints->minValue);
00247 constraints->maxValue = HashedExpressionPointer(bsaveConstraints->maxValue);
00248 constraints->minFields = HashedExpressionPointer(bsaveConstraints->minFields);
00249 constraints->maxFields = HashedExpressionPointer(bsaveConstraints->maxFields);
00250 constraints->multifield = NULL;
00251 }
00252
00253
00254
00255
00256
00257 globle void ClearBloadedConstraints(
00258 void *theEnv)
00259 {
00260 if (ConstraintData(theEnv)->NumberOfConstraints != 0)
00261 {
00262 genfree(theEnv,(void *) ConstraintData(theEnv)->ConstraintArray,
00263 (sizeof(CONSTRAINT_RECORD) * ConstraintData(theEnv)->NumberOfConstraints));
00264 ConstraintData(theEnv)->NumberOfConstraints = 0;
00265 }
00266 }
00267
00268 #endif
00269
00270
00271
00272
00273