00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define _GLOBLBIN_SOURCE_
00024
00025 #include "setup.h"
00026
00027 #if DEFGLOBAL_CONSTRUCT && (BLOAD || BLOAD_AND_BSAVE || BLOAD_ONLY) && (! RUN_TIME)
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031
00032 #include "memalloc.h"
00033 #include "multifld.h"
00034 #include "globldef.h"
00035 #include "bload.h"
00036 #include "bsave.h"
00037 #include "moduldef.h"
00038 #include "globlbsc.h"
00039 #include "envrnmnt.h"
00040
00041 #include "globlbin.h"
00042
00043
00044
00045
00046
00047 #if BLOAD_AND_BSAVE
00048 static void BsaveFind(void *);
00049 static void BsaveStorage(void *,FILE *);
00050 static void BsaveBinaryItem(void *,FILE *);
00051 #endif
00052 static void BloadStorageDefglobals(void *);
00053 static void BloadBinaryItem(void *);
00054 static void UpdateDefglobalModule(void *,void *,long);
00055 static void UpdateDefglobal(void *,void *,long);
00056 static void ClearBload(void *);
00057 static void DeallocateDefglobalBloadData(void *);
00058
00059
00060
00061
00062
00063 globle void DefglobalBinarySetup(
00064 void *theEnv)
00065 {
00066 AllocateEnvironmentData(theEnv,GLOBLBIN_DATA,sizeof(struct defglobalBinaryData),DeallocateDefglobalBloadData);
00067 #if (BLOAD_AND_BSAVE || BLOAD)
00068 AddAfterBloadFunction(theEnv,"defglobal",ResetDefglobals,50);
00069 #endif
00070
00071 #if BLOAD_AND_BSAVE
00072 AddBinaryItem(theEnv,"defglobal",0,BsaveFind,NULL,
00073 BsaveStorage,BsaveBinaryItem,
00074 BloadStorageDefglobals,BloadBinaryItem,
00075 ClearBload);
00076 #endif
00077
00078 #if (BLOAD || BLOAD_ONLY)
00079 AddBinaryItem(theEnv,"defglobal",0,NULL,NULL,NULL,NULL,
00080 BloadStorageDefglobals,BloadBinaryItem,
00081 ClearBload);
00082 #endif
00083 }
00084
00085
00086
00087
00088
00089 static void DeallocateDefglobalBloadData(
00090 void *theEnv)
00091 {
00092 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
00093 size_t space;
00094 long i;
00095
00096 for (i = 0; i < DefglobalBinaryData(theEnv)->NumberOfDefglobals; i++)
00097 {
00098 if (DefglobalBinaryData(theEnv)->DefglobalArray[i].current.type == MULTIFIELD)
00099 { ReturnMultifield(theEnv,(struct multifield *) DefglobalBinaryData(theEnv)->DefglobalArray[i].current.value); }
00100 }
00101
00102 space = DefglobalBinaryData(theEnv)->NumberOfDefglobals * sizeof(struct defglobal);
00103 if (space != 0)
00104 { genfree(theEnv,(void *) DefglobalBinaryData(theEnv)->DefglobalArray,space); }
00105
00106 space = DefglobalBinaryData(theEnv)->NumberOfDefglobalModules * sizeof(struct defglobalModule);
00107 if (space != 0)
00108 { genfree(theEnv,(void *) DefglobalBinaryData(theEnv)->ModuleArray,space); }
00109 #endif
00110 }
00111
00112 #if BLOAD_AND_BSAVE
00113
00114
00115
00116
00117
00118
00119 static void BsaveFind(
00120 void *theEnv)
00121 {
00122 struct defglobal *defglobalPtr;
00123 struct defmodule *theModule;
00124
00125
00126
00127
00128
00129
00130
00131 SaveBloadCount(theEnv,DefglobalBinaryData(theEnv)->NumberOfDefglobalModules);
00132 SaveBloadCount(theEnv,DefglobalBinaryData(theEnv)->NumberOfDefglobals);
00133
00134
00135
00136
00137
00138
00139 DefglobalBinaryData(theEnv)->NumberOfDefglobals = 0;
00140 DefglobalBinaryData(theEnv)->NumberOfDefglobalModules = 0;
00141
00142 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00143 theModule != NULL;
00144 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00145 {
00146
00147
00148
00149
00150
00151
00152 EnvSetCurrentModule(theEnv,(void *) theModule);
00153 DefglobalBinaryData(theEnv)->NumberOfDefglobalModules++;
00154
00155
00156
00157
00158
00159 for (defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,NULL);
00160 defglobalPtr != NULL;
00161 defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,defglobalPtr))
00162 {
00163
00164
00165
00166
00167 MarkConstructHeaderNeededItems(&defglobalPtr->header,DefglobalBinaryData(theEnv)->NumberOfDefglobals++);
00168 }
00169 }
00170 }
00171
00172
00173
00174
00175
00176 static void BsaveStorage(
00177 void *theEnv,
00178 FILE *fp)
00179 {
00180 size_t space;
00181
00182
00183
00184
00185
00186
00187
00188 space = sizeof(long) * 2;
00189 GenWrite(&space,sizeof(size_t),fp);
00190 GenWrite(&DefglobalBinaryData(theEnv)->NumberOfDefglobals,sizeof(long int),fp);
00191 GenWrite(&DefglobalBinaryData(theEnv)->NumberOfDefglobalModules,sizeof(long int),fp);
00192 }
00193
00194
00195
00196
00197
00198 static void BsaveBinaryItem(
00199 void *theEnv,
00200 FILE *fp)
00201 {
00202 size_t space;
00203 struct defglobal *theDefglobal;
00204 struct bsaveDefglobal newDefglobal;
00205 struct defmodule *theModule;
00206 struct bsaveDefglobalModule tempDefglobalModule;
00207 struct defglobalModule *theModuleItem;
00208
00209
00210
00211
00212
00213
00214 space = DefglobalBinaryData(theEnv)->NumberOfDefglobals * sizeof(struct bsaveDefglobal) +
00215 (DefglobalBinaryData(theEnv)->NumberOfDefglobalModules * sizeof(struct bsaveDefglobalModule));
00216 GenWrite(&space,sizeof(size_t),fp);
00217
00218
00219
00220
00221
00222 DefglobalBinaryData(theEnv)->NumberOfDefglobals = 0;
00223 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00224 theModule != NULL;
00225 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00226 {
00227 EnvSetCurrentModule(theEnv,(void *) theModule);
00228
00229 theModuleItem = (struct defglobalModule *)
00230 GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"defglobal")->moduleIndex);
00231 AssignBsaveDefmdlItemHdrVals(&tempDefglobalModule.header,
00232 &theModuleItem->header);
00233 GenWrite(&tempDefglobalModule,sizeof(struct bsaveDefglobalModule),fp);
00234 }
00235
00236
00237
00238
00239
00240 DefglobalBinaryData(theEnv)->NumberOfDefglobals = 0;
00241 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00242 theModule != NULL;
00243 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00244 {
00245 EnvSetCurrentModule(theEnv,(void *) theModule);
00246
00247 for (theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,NULL);
00248 theDefglobal != NULL;
00249 theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theDefglobal))
00250 {
00251 AssignBsaveConstructHeaderVals(&newDefglobal.header,
00252 &theDefglobal->header);
00253 newDefglobal.initial = HashedExpressionIndex(theEnv,theDefglobal->initial);
00254
00255 GenWrite(&newDefglobal,sizeof(struct bsaveDefglobal),fp);
00256 }
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266 RestoreBloadCount(theEnv,&DefglobalBinaryData(theEnv)->NumberOfDefglobalModules);
00267 RestoreBloadCount(theEnv,&DefglobalBinaryData(theEnv)->NumberOfDefglobals);
00268 }
00269
00270 #endif
00271
00272
00273
00274
00275
00276 static void BloadStorageDefglobals(
00277 void *theEnv)
00278 {
00279 size_t space;
00280
00281
00282
00283
00284
00285
00286 GenReadBinary(theEnv,&space,sizeof(size_t));
00287 GenReadBinary(theEnv,&DefglobalBinaryData(theEnv)->NumberOfDefglobals,sizeof(long int));
00288 GenReadBinary(theEnv,&DefglobalBinaryData(theEnv)->NumberOfDefglobalModules,sizeof(long int));
00289
00290
00291
00292
00293
00294
00295 if (DefglobalBinaryData(theEnv)->NumberOfDefglobalModules == 0)
00296 {
00297 DefglobalBinaryData(theEnv)->DefglobalArray = NULL;
00298 DefglobalBinaryData(theEnv)->ModuleArray = NULL;
00299 }
00300
00301 space = DefglobalBinaryData(theEnv)->NumberOfDefglobalModules * sizeof(struct defglobalModule);
00302 DefglobalBinaryData(theEnv)->ModuleArray = (struct defglobalModule *) genalloc(theEnv,space);
00303
00304
00305
00306
00307
00308
00309 if (DefglobalBinaryData(theEnv)->NumberOfDefglobals == 0)
00310 {
00311 DefglobalBinaryData(theEnv)->DefglobalArray = NULL;
00312 return;
00313 }
00314
00315 space = (DefglobalBinaryData(theEnv)->NumberOfDefglobals * sizeof(struct defglobal));
00316 DefglobalBinaryData(theEnv)->DefglobalArray = (struct defglobal *) genalloc(theEnv,space);
00317 }
00318
00319
00320
00321
00322
00323 static void BloadBinaryItem(
00324 void *theEnv)
00325 {
00326 size_t space;
00327
00328
00329
00330
00331
00332
00333
00334 GenReadBinary(theEnv,&space,sizeof(size_t));
00335
00336
00337
00338
00339
00340
00341 BloadandRefresh(theEnv,DefglobalBinaryData(theEnv)->NumberOfDefglobalModules,
00342 sizeof(struct bsaveDefglobalModule),
00343 UpdateDefglobalModule);
00344
00345
00346
00347
00348
00349
00350 BloadandRefresh(theEnv,DefglobalBinaryData(theEnv)->NumberOfDefglobals,
00351 sizeof(struct bsaveDefglobal),
00352 UpdateDefglobal);
00353 }
00354
00355
00356
00357
00358
00359 static void UpdateDefglobalModule(
00360 void *theEnv,
00361 void *buf,
00362 long obji)
00363 {
00364 struct bsaveDefglobalModule *bdmPtr;
00365
00366 bdmPtr = (struct bsaveDefglobalModule *) buf;
00367
00368 UpdateDefmoduleItemHeader(theEnv,&bdmPtr->header,&DefglobalBinaryData(theEnv)->ModuleArray[obji].header,
00369 (int) sizeof(struct defglobal),
00370 (void *) DefglobalBinaryData(theEnv)->DefglobalArray);
00371 }
00372
00373
00374
00375
00376
00377 static void UpdateDefglobal(
00378 void *theEnv,
00379 void *buf,
00380 long obji)
00381 {
00382 struct bsaveDefglobal *bdp;
00383
00384 bdp = (struct bsaveDefglobal *) buf;
00385 UpdateConstructHeader(theEnv,&bdp->header,&DefglobalBinaryData(theEnv)->DefglobalArray[obji].header,
00386 (int) sizeof(struct defglobalModule),(void *) DefglobalBinaryData(theEnv)->ModuleArray,
00387 (int) sizeof(struct defglobal),(void *) DefglobalBinaryData(theEnv)->DefglobalArray);
00388
00389 #if DEBUGGING_FUNCTIONS
00390 DefglobalBinaryData(theEnv)->DefglobalArray[obji].watch = WatchGlobals;
00391 #endif
00392 DefglobalBinaryData(theEnv)->DefglobalArray[obji].initial = HashedExpressionPointer(bdp->initial);
00393 DefglobalBinaryData(theEnv)->DefglobalArray[obji].current.type = RVOID;
00394
00395 }
00396
00397
00398
00399
00400
00401 static void ClearBload(
00402 void *theEnv)
00403 {
00404 long i;
00405 size_t space;
00406
00407
00408
00409
00410
00411
00412
00413 for (i = 0; i < DefglobalBinaryData(theEnv)->NumberOfDefglobals; i++)
00414 {
00415 UnmarkConstructHeader(theEnv,&DefglobalBinaryData(theEnv)->DefglobalArray[i].header);
00416
00417 ValueDeinstall(theEnv,&(DefglobalBinaryData(theEnv)->DefglobalArray[i].current));
00418 if (DefglobalBinaryData(theEnv)->DefglobalArray[i].current.type == MULTIFIELD)
00419 { ReturnMultifield(theEnv,(struct multifield *) DefglobalBinaryData(theEnv)->DefglobalArray[i].current.value); }
00420 }
00421
00422
00423
00424
00425
00426 space = DefglobalBinaryData(theEnv)->NumberOfDefglobals * sizeof(struct defglobal);
00427 if (space != 0) genfree(theEnv,(void *) DefglobalBinaryData(theEnv)->DefglobalArray,space);
00428 DefglobalBinaryData(theEnv)->NumberOfDefglobals = 0;
00429
00430
00431
00432
00433
00434 space = DefglobalBinaryData(theEnv)->NumberOfDefglobalModules * sizeof(struct defglobalModule);
00435 if (space != 0) genfree(theEnv,(void *) DefglobalBinaryData(theEnv)->ModuleArray,space);
00436 DefglobalBinaryData(theEnv)->NumberOfDefglobalModules = 0;
00437 }
00438
00439
00440
00441
00442
00443 globle void *BloadDefglobalModuleReference(
00444 void *theEnv,
00445 int theIndex)
00446 {
00447 return ((void *) &DefglobalBinaryData(theEnv)->ModuleArray[theIndex]);
00448 }
00449
00450 #endif
00451
00452
00453