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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #define _CSTRCCOM_SOURCE_
00042
00043 #include <string.h>
00044
00045 #include "setup.h"
00046
00047 #include "constant.h"
00048 #include "envrnmnt.h"
00049 #include "memalloc.h"
00050 #include "moduldef.h"
00051 #include "argacces.h"
00052 #include "multifld.h"
00053 #include "modulutl.h"
00054 #include "router.h"
00055 #include "utility.h"
00056 #include "commline.h"
00057 #include "sysdep.h"
00058
00059 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00060 #include "bload.h"
00061 #endif
00062
00063 #if (! BLOAD_ONLY) && (! RUN_TIME)
00064 #include "cstrcpsr.h"
00065 #endif
00066
00067 #include "cstrccom.h"
00068
00069
00070
00071
00072
00073 #if DEBUGGING_FUNCTIONS
00074 static void ConstructPrintWatch(void *,char *,struct construct *,void *,
00075 unsigned (*)(void *,void *));
00076 static unsigned ConstructWatchSupport(void *,struct construct *,char *,
00077 char *,EXPRESSION *,intBool,
00078 unsigned,unsigned (*)(void *,void *),
00079 void (*)(void *,unsigned,void *));
00080 #endif
00081
00082 #if (! RUN_TIME)
00083
00084
00085
00086
00087
00088 globle void AddConstructToModule(
00089 struct constructHeader *theConstruct)
00090 {
00091 if (theConstruct->whichModule->lastItem == NULL)
00092 { theConstruct->whichModule->firstItem = theConstruct; }
00093 else
00094 { theConstruct->whichModule->lastItem->next = theConstruct; }
00095
00096 theConstruct->whichModule->lastItem = theConstruct;
00097 theConstruct->next = NULL;
00098 }
00099
00100 #endif
00101
00102
00103
00104
00105
00106 globle intBool DeleteNamedConstruct(
00107 void *theEnv,
00108 char *constructName,
00109 struct construct *constructClass)
00110 {
00111 #if (! BLOAD_ONLY)
00112 void *constructPtr;
00113
00114
00115
00116
00117
00118
00119 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00120 if (Bloaded(theEnv) == TRUE) return(FALSE);
00121 #endif
00122
00123
00124
00125
00126
00127 constructPtr = (*constructClass->findFunction)(theEnv,constructName);
00128
00129
00130
00131
00132
00133 if (constructPtr != NULL)
00134 { return((*constructClass->deleteFunction)(theEnv,constructPtr)); }
00135
00136
00137
00138
00139
00140
00141
00142 if (strcmp("*",constructName) == 0)
00143 {
00144 (*constructClass->deleteFunction)(theEnv,NULL);
00145 return(TRUE);
00146 }
00147
00148
00149
00150
00151
00152
00153 return(FALSE);
00154 #else
00155 #if MAC_MCW || WIN_MCW || MAC_XCD
00156 #pragma unused(theEnv,constructName,constructClass)
00157 #endif
00158 return(FALSE);
00159 #endif
00160 }
00161
00162
00163
00164
00165
00166 globle void *FindNamedConstruct(
00167 void *theEnv,
00168 char *constructName,
00169 struct construct *constructClass)
00170 {
00171 void *theConstruct;
00172 SYMBOL_HN *findValue;
00173
00174
00175
00176
00177
00178 SaveCurrentModule(theEnv);
00179
00180
00181
00182
00183
00184
00185
00186 constructName = ExtractModuleAndConstructName(theEnv,constructName);
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 if ((constructName == NULL) ?
00197 TRUE :
00198 ((findValue = (SYMBOL_HN *) FindSymbolHN(theEnv,constructName)) == NULL))
00199 {
00200 RestoreCurrentModule(theEnv);
00201 return(NULL);
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 for (theConstruct = (*constructClass->getNextItemFunction)(theEnv,NULL);
00213 theConstruct != NULL;
00214 theConstruct = (*constructClass->getNextItemFunction)(theEnv,theConstruct))
00215 {
00216 if (findValue == (*constructClass->getConstructNameFunction)((struct constructHeader *) theConstruct))
00217 {
00218 RestoreCurrentModule(theEnv);
00219 return (theConstruct);
00220 }
00221 }
00222
00223
00224
00225
00226
00227 RestoreCurrentModule(theEnv);
00228
00229
00230
00231
00232
00233
00234 return(NULL);
00235 }
00236
00237
00238
00239
00240
00241 globle void UndefconstructCommand(
00242 void *theEnv,
00243 char *command,
00244 struct construct *constructClass)
00245 {
00246 char *constructName;
00247 char buffer[80];
00248
00249
00250
00251
00252
00253 gensprintf(buffer,"%s name",constructClass->constructName);
00254
00255 constructName = GetConstructName(theEnv,command,buffer);
00256 if (constructName == NULL) return;
00257
00258 #if (! RUN_TIME) && (! BLOAD_ONLY)
00259
00260
00261
00262
00263
00264 if (((*constructClass->findFunction)(theEnv,constructName) == NULL) &&
00265 (strcmp("*",constructName) != 0))
00266 {
00267 CantFindItemErrorMessage(theEnv,constructClass->constructName,constructName);
00268 return;
00269 }
00270
00271
00272
00273
00274
00275 else if (DeleteNamedConstruct(theEnv,constructName,constructClass) == FALSE)
00276 {
00277 CantDeleteItemErrorMessage(theEnv,constructClass->constructName,constructName);
00278 return;
00279 }
00280
00281 return;
00282 #else
00283
00284
00285
00286
00287
00288 CantDeleteItemErrorMessage(theEnv,constructClass->constructName,constructName);
00289 return;
00290 #endif
00291 }
00292
00293
00294
00295
00296
00297 globle void PPConstructCommand(
00298 void *theEnv,
00299 char *command,
00300 struct construct *constructClass)
00301 {
00302 char *constructName;
00303 char buffer[80];
00304
00305
00306
00307
00308
00309
00310 gensprintf(buffer,"%s name",constructClass->constructName);
00311
00312 constructName = GetConstructName(theEnv,command,buffer);
00313 if (constructName == NULL) return;
00314
00315
00316
00317
00318
00319
00320 if (PPConstruct(theEnv,constructName,WDISPLAY,constructClass) == FALSE)
00321 { CantFindItemErrorMessage(theEnv,constructClass->constructName,constructName); }
00322 }
00323
00324
00325
00326
00327
00328 globle int PPConstruct(
00329 void *theEnv,
00330 char *constructName,
00331 char *logicalName,
00332 struct construct *constructClass)
00333 {
00334 void *constructPtr;
00335
00336
00337
00338
00339
00340
00341 constructPtr = (*constructClass->findFunction)(theEnv,constructName);
00342 if (constructPtr == NULL) return(FALSE);
00343
00344
00345
00346
00347
00348
00349
00350 if ((*constructClass->getPPFormFunction)(theEnv,(struct constructHeader *) constructPtr) == NULL)
00351 { return(TRUE); }
00352
00353
00354
00355
00356
00357
00358
00359 PrintInChunks(theEnv,logicalName,(*constructClass->getPPFormFunction)(theEnv,(struct constructHeader *) constructPtr));
00360
00361
00362
00363
00364
00365
00366 return(TRUE);
00367 }
00368
00369
00370
00371
00372
00373 globle SYMBOL_HN *GetConstructModuleCommand(
00374 void *theEnv,
00375 char *command,
00376 struct construct *constructClass)
00377 {
00378 char *constructName;
00379 char buffer[80];
00380 struct defmodule *constructModule;
00381
00382
00383
00384
00385
00386
00387 gensprintf(buffer,"%s name",constructClass->constructName);
00388
00389 constructName = GetConstructName(theEnv,command,buffer);
00390 if (constructName == NULL) return((SYMBOL_HN *) EnvFalseSymbol(theEnv));
00391
00392
00393
00394
00395
00396 constructModule = GetConstructModule(theEnv,constructName,constructClass);
00397 if (constructModule == NULL)
00398 {
00399 CantFindItemErrorMessage(theEnv,constructClass->constructName,constructName);
00400 return((SYMBOL_HN *) EnvFalseSymbol(theEnv));
00401 }
00402
00403
00404
00405
00406
00407 return(constructModule->name);
00408 }
00409
00410
00411
00412
00413
00414 globle struct defmodule *GetConstructModule(
00415 void *theEnv,
00416 char *constructName,
00417 struct construct *constructClass)
00418 {
00419 struct constructHeader *constructPtr;
00420 int count;
00421 unsigned position;
00422 SYMBOL_HN *theName;
00423
00424
00425
00426
00427
00428
00429
00430 if ((position = FindModuleSeparator(constructName)) != FALSE)
00431 {
00432 theName = ExtractModuleName(theEnv,position,constructName);
00433 if (theName != NULL)
00434 { return((struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(theName))); }
00435 }
00436
00437
00438
00439
00440
00441
00442
00443 constructPtr = (struct constructHeader *)
00444 FindImportedConstruct(theEnv,constructClass->constructName,NULL,constructName,
00445 &count,TRUE,NULL);
00446 if (constructPtr == NULL) return(NULL);
00447
00448 return(constructPtr->whichModule->theModule);
00449 }
00450
00451
00452
00453
00454
00455 globle intBool Undefconstruct(
00456 void *theEnv,
00457 void *theConstruct,
00458 struct construct *constructClass)
00459 {
00460 #if BLOAD_ONLY || RUN_TIME
00461 #if MAC_MCW || WIN_MCW || MAC_XCD
00462 #pragma unused(theConstruct)
00463 #pragma unused(constructClass)
00464 #pragma unused(theEnv)
00465 #endif
00466 return(FALSE);
00467 #else
00468 void *currentConstruct,*nextConstruct;
00469 intBool success;
00470
00471
00472
00473
00474
00475
00476 if (theConstruct == NULL)
00477 {
00478 success = TRUE;
00479
00480
00481
00482
00483
00484 currentConstruct = (*constructClass->getNextItemFunction)(theEnv,NULL);
00485 while (currentConstruct != NULL)
00486 {
00487
00488
00489
00490
00491 nextConstruct = (*constructClass->getNextItemFunction)(theEnv,currentConstruct);
00492
00493
00494
00495
00496
00497 if ((*constructClass->isConstructDeletableFunction)(theEnv,currentConstruct))
00498 {
00499 RemoveConstructFromModule(theEnv,(struct constructHeader *) currentConstruct);
00500 (*constructClass->freeFunction)(theEnv,currentConstruct);
00501 }
00502 else
00503 {
00504 CantDeleteItemErrorMessage(theEnv,constructClass->constructName,
00505 ValueToString((*constructClass->getConstructNameFunction)((struct constructHeader *) currentConstruct)));
00506 success = FALSE;
00507 }
00508
00509
00510
00511
00512
00513 currentConstruct = nextConstruct;
00514 }
00515
00516
00517
00518
00519
00520 if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
00521 (EvaluationData(theEnv)->CurrentExpression == NULL))
00522 { PeriodicCleanup(theEnv,TRUE,FALSE); }
00523
00524
00525
00526
00527
00528
00529 return(success);
00530 }
00531
00532
00533
00534
00535
00536 if ((*constructClass->isConstructDeletableFunction)(theEnv,theConstruct) == FALSE)
00537 { return(FALSE); }
00538
00539
00540
00541
00542
00543
00544 RemoveConstructFromModule(theEnv,(struct constructHeader *) theConstruct);
00545
00546
00547
00548
00549
00550 (*constructClass->freeFunction)(theEnv,theConstruct);
00551
00552
00553
00554
00555
00556 if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
00557 (EvaluationData(theEnv)->CurrentExpression == NULL))
00558 { PeriodicCleanup(theEnv,TRUE,FALSE); }
00559
00560
00561
00562
00563
00564
00565 return(TRUE);
00566 #endif
00567 }
00568
00569
00570
00571
00572
00573 globle void SaveConstruct(
00574 void *theEnv,
00575 void *theModule,
00576 char *logicalName,
00577 struct construct *constructClass)
00578 {
00579 char *ppform;
00580 struct constructHeader *theConstruct;
00581
00582
00583
00584
00585
00586 SaveCurrentModule(theEnv);
00587
00588
00589
00590
00591
00592
00593 EnvSetCurrentModule(theEnv,theModule);
00594
00595
00596
00597
00598
00599
00600 for (theConstruct = (struct constructHeader *)
00601 (*constructClass->getNextItemFunction)(theEnv,NULL);
00602 theConstruct != NULL;
00603 theConstruct = (struct constructHeader *)
00604 (*constructClass->getNextItemFunction)(theEnv,theConstruct))
00605 {
00606
00607
00608
00609
00610 ppform = (*constructClass->getPPFormFunction)(theEnv,theConstruct);
00611 if (ppform != NULL)
00612 {
00613 PrintInChunks(theEnv,logicalName,ppform);
00614 EnvPrintRouter(theEnv,logicalName,"\n");
00615 }
00616 }
00617
00618
00619
00620
00621
00622 RestoreCurrentModule(theEnv);
00623 }
00624
00625
00626
00627
00628
00629 globle char *GetConstructModuleName(
00630 struct constructHeader *theConstruct)
00631 { return(EnvGetDefmoduleName(NULL,(void *) theConstruct->whichModule->theModule)); }
00632
00633
00634
00635
00636
00637 globle char *GetConstructNameString(
00638 struct constructHeader *theConstruct)
00639 { return(ValueToString(theConstruct->name)); }
00640
00641
00642
00643
00644
00645 #if WIN_BTC
00646 #pragma argsused
00647 #endif
00648 globle char *EnvGetConstructNameString(
00649 void *theEnv,
00650 struct constructHeader *theConstruct)
00651 {
00652 #if MAC_MCW || WIN_MCW || MAC_XCD
00653 #pragma unused(theEnv)
00654 #endif
00655
00656 return(ValueToString(theConstruct->name));
00657 }
00658
00659
00660
00661
00662
00663 globle SYMBOL_HN *GetConstructNamePointer(
00664 struct constructHeader *theConstruct)
00665 { return(theConstruct->name); }
00666
00667
00668
00669
00670
00671 globle void GetConstructListFunction(
00672 void *theEnv,
00673 char *functionName,
00674 DATA_OBJECT_PTR returnValue,
00675 struct construct *constructClass)
00676 {
00677 struct defmodule *theModule;
00678 DATA_OBJECT result;
00679 int numArgs;
00680
00681
00682
00683
00684
00685 if ((numArgs = EnvArgCountCheck(theEnv,functionName,NO_MORE_THAN,1)) == -1)
00686 {
00687 EnvSetMultifieldErrorValue(theEnv,returnValue);
00688 return;
00689 }
00690
00691
00692
00693
00694
00695
00696 if (numArgs == 1)
00697 {
00698
00699
00700
00701
00702 EnvRtnUnknown(theEnv,1,&result);
00703 if (GetType(result) != SYMBOL)
00704 {
00705 EnvSetMultifieldErrorValue(theEnv,returnValue);
00706 ExpectedTypeError1(theEnv,functionName,1,"defmodule name");
00707 return;
00708 }
00709
00710
00711
00712
00713
00714
00715
00716 if ((theModule = (struct defmodule *) EnvFindDefmodule(theEnv,DOToString(result))) == NULL)
00717 {
00718 if (strcmp("*",DOToString(result)) != 0)
00719 {
00720 EnvSetMultifieldErrorValue(theEnv,returnValue);
00721 ExpectedTypeError1(theEnv,functionName,1,"defmodule name");
00722 return;
00723 }
00724
00725 theModule = NULL;
00726 }
00727 }
00728
00729
00730
00731
00732
00733
00734 else
00735 { theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); }
00736
00737
00738
00739
00740
00741
00742 GetConstructList(theEnv,returnValue,constructClass,theModule);
00743 }
00744
00745
00746
00747
00748
00749 globle void GetConstructList(
00750 void *theEnv,
00751 DATA_OBJECT_PTR returnValue,
00752 struct construct *constructClass,
00753 struct defmodule *theModule)
00754 {
00755 void *theConstruct;
00756 unsigned long count = 0;
00757 struct multifield *theList;
00758 SYMBOL_HN *theName;
00759 struct defmodule *loopModule;
00760 int allModules = FALSE;
00761 #if WIN_BTC
00762 size_t largestConstructNameSize, bufferSize = 80;
00763 #else
00764 size_t largestConstructNameSize = 0, bufferSize = 80;
00765 #endif
00766 char *buffer;
00767
00768
00769
00770
00771
00772 SaveCurrentModule(theEnv);
00773
00774
00775
00776
00777
00778
00779 if (theModule == NULL)
00780 {
00781 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00782 allModules = TRUE;
00783 }
00784
00785
00786
00787
00788
00789
00790
00791 loopModule = theModule;
00792 while (loopModule != NULL)
00793 {
00794 size_t tempSize;
00795
00796
00797
00798
00799
00800 EnvSetCurrentModule(theEnv,(void *) loopModule);
00801
00802
00803
00804
00805
00806 theConstruct = NULL;
00807 largestConstructNameSize = 0;
00808
00809 while ((theConstruct = (*constructClass->getNextItemFunction)(theEnv,theConstruct)) != NULL)
00810 {
00811
00812
00813
00814
00815 count++;
00816
00817
00818
00819
00820
00821 tempSize = strlen(ValueToString((*constructClass->getConstructNameFunction)((struct constructHeader *) theConstruct)));
00822 if (tempSize > largestConstructNameSize)
00823 { largestConstructNameSize = tempSize; }
00824 }
00825
00826
00827
00828
00829
00830 tempSize = strlen(EnvGetDefmoduleName(theEnv,loopModule));
00831
00832
00833
00834
00835
00836
00837 if ((tempSize + largestConstructNameSize + 5) > bufferSize)
00838 { bufferSize = tempSize + largestConstructNameSize + 5; }
00839
00840
00841
00842
00843
00844 if (allModules) loopModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,loopModule);
00845 else loopModule = NULL;
00846 }
00847
00848
00849
00850
00851
00852 buffer = (char *) genalloc(theEnv,bufferSize);
00853
00854
00855
00856
00857
00858
00859 SetpType(returnValue,MULTIFIELD);
00860 SetpDOBegin(returnValue,1);
00861 SetpDOEnd(returnValue,(long) count);
00862 theList = (struct multifield *) EnvCreateMultifield(theEnv,count);
00863 SetpValue(returnValue,(void *) theList);
00864
00865
00866
00867
00868
00869
00870 loopModule = theModule;
00871 count = 1;
00872 while (loopModule != NULL)
00873 {
00874
00875
00876
00877
00878
00879 EnvSetCurrentModule(theEnv,(void *) loopModule);
00880
00881
00882
00883
00884
00885
00886 theConstruct = NULL;
00887 while ((theConstruct = (*constructClass->getNextItemFunction)(theEnv,theConstruct)) != NULL)
00888 {
00889 theName = (*constructClass->getConstructNameFunction)((struct constructHeader *) theConstruct);
00890 SetMFType(theList,count,SYMBOL);
00891 if (allModules)
00892 {
00893 genstrcpy(buffer,EnvGetDefmoduleName(theEnv,loopModule));
00894 genstrcat(buffer,"::");
00895 genstrcat(buffer,ValueToString(theName));
00896 SetMFValue(theList,count,EnvAddSymbol(theEnv,buffer));
00897 }
00898 else
00899 { SetMFValue(theList,count,EnvAddSymbol(theEnv,ValueToString(theName))); }
00900 count++;
00901 }
00902
00903
00904
00905
00906
00907
00908
00909 if (allModules) loopModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,loopModule);
00910 else loopModule = NULL;
00911 }
00912
00913
00914
00915
00916
00917 genfree(theEnv,buffer,bufferSize);
00918
00919
00920
00921
00922
00923 RestoreCurrentModule(theEnv);
00924 }
00925
00926
00927
00928
00929
00930 globle void ListConstructCommand(
00931 void *theEnv,
00932 char *functionName,
00933 struct construct *constructClass)
00934 {
00935 struct defmodule *theModule;
00936 DATA_OBJECT result;
00937 int numArgs;
00938
00939
00940
00941
00942
00943 if ((numArgs = EnvArgCountCheck(theEnv,functionName,NO_MORE_THAN,1)) == -1) return;
00944
00945
00946
00947
00948
00949
00950 if (numArgs == 1)
00951 {
00952
00953
00954
00955
00956 EnvRtnUnknown(theEnv,1,&result);
00957 if (GetType(result) != SYMBOL)
00958 {
00959 ExpectedTypeError1(theEnv,functionName,1,"defmodule name");
00960 return;
00961 }
00962
00963
00964
00965
00966
00967
00968
00969 if ((theModule = (struct defmodule *) EnvFindDefmodule(theEnv,DOToString(result))) == NULL)
00970 {
00971 if (strcmp("*",DOToString(result)) != 0)
00972 {
00973 ExpectedTypeError1(theEnv,functionName,1,"defmodule name");
00974 return;
00975 }
00976
00977 theModule = NULL;
00978 }
00979 }
00980
00981
00982
00983
00984
00985
00986 else
00987 { theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); }
00988
00989
00990
00991
00992
00993
00994 ListConstruct(theEnv,constructClass,WDISPLAY,theModule);
00995 }
00996
00997
00998
00999
01000
01001 globle void ListConstruct(
01002 void *theEnv,
01003 struct construct *constructClass,
01004 char *logicalName,
01005 struct defmodule *theModule)
01006 {
01007 void *constructPtr;
01008 SYMBOL_HN *constructName;
01009 long count = 0;
01010 int allModules = FALSE;
01011
01012
01013
01014
01015
01016 SaveCurrentModule(theEnv);
01017
01018
01019
01020
01021
01022
01023 if (theModule == NULL)
01024 {
01025 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
01026 allModules = TRUE;
01027 }
01028
01029
01030
01031
01032
01033 while (theModule != NULL)
01034 {
01035
01036
01037
01038
01039
01040
01041 if (allModules)
01042 {
01043 EnvPrintRouter(theEnv,logicalName,EnvGetDefmoduleName(theEnv,theModule));
01044 EnvPrintRouter(theEnv,logicalName,":\n");
01045 }
01046
01047
01048
01049
01050
01051
01052 EnvSetCurrentModule(theEnv,(void *) theModule);
01053
01054
01055
01056
01057
01058 for (constructPtr = (*constructClass->getNextItemFunction)(theEnv,NULL);
01059 constructPtr != NULL;
01060 constructPtr = (*constructClass->getNextItemFunction)(theEnv,constructPtr))
01061 {
01062 if (EvaluationData(theEnv)->HaltExecution == TRUE) return;
01063
01064 constructName = (*constructClass->getConstructNameFunction)((struct constructHeader *) constructPtr);
01065
01066 if (constructName != NULL)
01067 {
01068 if (allModules) EnvPrintRouter(theEnv,WDISPLAY," ");
01069 EnvPrintRouter(theEnv,logicalName,ValueToString(constructName));
01070 EnvPrintRouter(theEnv,logicalName,"\n");
01071 }
01072
01073 count++;
01074 }
01075
01076
01077
01078
01079
01080
01081
01082 if (allModules) theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule);
01083 else theModule = NULL;
01084 }
01085
01086
01087
01088
01089
01090 PrintTally(theEnv,WDISPLAY,count,constructClass->constructName,
01091 constructClass->pluralName);
01092
01093 RestoreCurrentModule(theEnv);
01094 }
01095
01096
01097
01098
01099
01100 globle void SetNextConstruct(
01101 struct constructHeader *theConstruct,
01102 struct constructHeader *targetConstruct)
01103 { theConstruct->next = targetConstruct; }
01104
01105
01106
01107
01108
01109
01110
01111 globle struct defmoduleItemHeader *GetConstructModuleItem(
01112 struct constructHeader *theConstruct)
01113 { return(theConstruct->whichModule); }
01114
01115
01116
01117
01118
01119 #if WIN_BTC
01120 #pragma argsused
01121 #endif
01122 globle char *GetConstructPPForm(
01123 void *theEnv,
01124 struct constructHeader *theConstruct)
01125 {
01126 #if MAC_MCW || WIN_MCW || MAC_XCD
01127 #pragma unused(theEnv)
01128 #endif
01129
01130 return(theConstruct->ppForm);
01131 }
01132
01133
01134
01135
01136
01137 globle struct constructHeader *GetNextConstructItem(
01138 void *theEnv,
01139 struct constructHeader *theConstruct,
01140 int moduleIndex)
01141 {
01142 struct defmoduleItemHeader *theModuleItem;
01143
01144 if (theConstruct == NULL)
01145 {
01146 theModuleItem = (struct defmoduleItemHeader *)
01147 GetModuleItem(theEnv,NULL,moduleIndex);
01148 if (theModuleItem == NULL) return(NULL);
01149 return(theModuleItem->firstItem);
01150 }
01151
01152 return(theConstruct->next);
01153 }
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163 globle struct defmoduleItemHeader *GetConstructModuleItemByIndex(
01164 void *theEnv,
01165 struct defmodule *theModule,
01166 int moduleIndex)
01167 {
01168 if (theModule != NULL)
01169 {
01170 return((struct defmoduleItemHeader *)
01171 GetModuleItem(theEnv,theModule,moduleIndex));
01172 }
01173
01174 return((struct defmoduleItemHeader *)
01175 GetModuleItem(theEnv,((struct defmodule *) EnvGetCurrentModule(theEnv)),moduleIndex));
01176 }
01177
01178
01179
01180
01181
01182
01183 globle void FreeConstructHeaderModule(
01184 void *theEnv,
01185 struct defmoduleItemHeader *theModuleItem,
01186 struct construct *constructClass)
01187 {
01188 struct constructHeader *thisOne, *nextOne;
01189
01190 thisOne = theModuleItem->firstItem;
01191
01192 while (thisOne != NULL)
01193 {
01194 nextOne = thisOne->next;
01195 (*constructClass->freeFunction)(theEnv,thisOne);
01196 thisOne = nextOne;
01197 }
01198 }
01199
01200
01201
01202
01203
01204 globle long DoForAllConstructs(
01205 void *theEnv,
01206 void (*actionFunction)(void *,struct constructHeader *,void *),
01207 int moduleItemIndex,
01208 int interruptable,
01209 void *userBuffer)
01210 {
01211 struct constructHeader *theConstruct;
01212 struct defmoduleItemHeader *theModuleItem;
01213 void *theModule;
01214 long moduleCount = 0L;
01215
01216
01217
01218
01219
01220 SaveCurrentModule(theEnv);
01221
01222
01223
01224
01225
01226 for (theModule = EnvGetNextDefmodule(theEnv,NULL);
01227 theModule != NULL;
01228 theModule = EnvGetNextDefmodule(theEnv,theModule), moduleCount++)
01229 {
01230
01231
01232
01233
01234
01235 EnvSetCurrentModule(theEnv,(void *) theModule);
01236
01237
01238
01239
01240
01241 theModuleItem = (struct defmoduleItemHeader *)
01242 GetModuleItem(theEnv,(struct defmodule *) theModule,moduleItemIndex);
01243
01244 for (theConstruct = theModuleItem->firstItem;
01245 theConstruct != NULL;
01246 theConstruct = theConstruct->next)
01247 {
01248 if (interruptable)
01249 {
01250 if (GetHaltExecution(theEnv) == TRUE)
01251 {
01252 RestoreCurrentModule(theEnv);
01253 return(-1L);
01254 }
01255 }
01256
01257 (*actionFunction)(theEnv,theConstruct,userBuffer);
01258 }
01259 }
01260
01261
01262
01263
01264
01265 RestoreCurrentModule(theEnv);
01266
01267
01268
01269
01270
01271 return(moduleCount);
01272 }
01273
01274
01275
01276
01277
01278 globle void DoForAllConstructsInModule(
01279 void *theEnv,
01280 void *theModule,
01281 void (*actionFunction)(void *,struct constructHeader *,void *),
01282 int moduleItemIndex,
01283 int interruptable,
01284 void *userBuffer)
01285 {
01286 struct constructHeader *theConstruct;
01287 struct defmoduleItemHeader *theModuleItem;
01288
01289
01290
01291
01292
01293 SaveCurrentModule(theEnv);
01294
01295
01296
01297
01298
01299
01300 EnvSetCurrentModule(theEnv,(void *) theModule);
01301
01302
01303
01304
01305
01306 theModuleItem = (struct defmoduleItemHeader *)
01307 GetModuleItem(theEnv,(struct defmodule *) theModule,moduleItemIndex);
01308
01309 for (theConstruct = theModuleItem->firstItem;
01310 theConstruct != NULL;
01311 theConstruct = theConstruct->next)
01312 {
01313 if (interruptable)
01314 {
01315 if (GetHaltExecution(theEnv) == TRUE)
01316 {
01317 RestoreCurrentModule(theEnv);
01318 return;
01319 }
01320 }
01321
01322 (*actionFunction)(theEnv,theConstruct,userBuffer);
01323 }
01324
01325
01326
01327
01328
01329 RestoreCurrentModule(theEnv);
01330 }
01331
01332
01333
01334
01335
01336
01337 globle void InitializeConstructHeader(
01338 void *theEnv,
01339 char *constructType,
01340 struct constructHeader *theConstruct,
01341 SYMBOL_HN *theConstructName)
01342 {
01343 struct moduleItem *theModuleItem;
01344 struct defmoduleItemHeader *theItemHeader;
01345
01346 theModuleItem = FindModuleItem(theEnv,constructType);
01347 theItemHeader = (struct defmoduleItemHeader *)
01348 GetModuleItem(theEnv,NULL,theModuleItem->moduleIndex);
01349
01350 theConstruct->whichModule = theItemHeader;
01351 theConstruct->name = theConstructName;
01352 theConstruct->ppForm = NULL;
01353 theConstruct->bsaveID = 0L;
01354 theConstruct->next = NULL;
01355 theConstruct->usrData = NULL;
01356 }
01357
01358
01359
01360
01361
01362 globle void SetConstructPPForm(
01363 void *theEnv,
01364 struct constructHeader *theConstruct,
01365 char *ppForm)
01366 {
01367 if (theConstruct->ppForm != NULL)
01368 {
01369 rm(theEnv,(void *) theConstruct->ppForm,
01370 ((strlen(theConstruct->ppForm) + 1) * sizeof(char)));
01371 }
01372 theConstruct->ppForm = ppForm;
01373 }
01374
01375 #if DEBUGGING_FUNCTIONS
01376
01377
01378
01379
01380
01381 globle unsigned ConstructPrintWatchAccess(
01382 void *theEnv,
01383 struct construct *constructClass,
01384 char *logName,
01385 EXPRESSION *argExprs,
01386 unsigned (*getWatchFunc)(void *,void *),
01387 void (*setWatchFunc)(void *,unsigned,void *))
01388 {
01389 return(ConstructWatchSupport(theEnv,constructClass,"list-watch-items",logName,argExprs,
01390 FALSE,FALSE,getWatchFunc,setWatchFunc));
01391 }
01392
01393
01394
01395
01396
01397 globle unsigned ConstructSetWatchAccess(
01398 void *theEnv,
01399 struct construct *constructClass,
01400 unsigned newState,
01401 EXPRESSION *argExprs,
01402 unsigned (*getWatchFunc)(void *,void *),
01403 void (*setWatchFunc)(void *,unsigned,void *))
01404 {
01405 return(ConstructWatchSupport(theEnv,constructClass,"watch",WERROR,argExprs,
01406 TRUE,newState,getWatchFunc,setWatchFunc));
01407 }
01408
01409
01410
01411
01412
01413 static unsigned ConstructWatchSupport(
01414 void *theEnv,
01415 struct construct *constructClass,
01416 char *funcName,
01417 char *logName,
01418 EXPRESSION *argExprs,
01419 intBool setFlag,
01420 unsigned newState,
01421 unsigned (*getWatchFunc)(void *,void *),
01422 void (*setWatchFunc)(void *,unsigned,void *))
01423 {
01424 struct defmodule *theModule;
01425 void *theConstruct;
01426 DATA_OBJECT constructName;
01427 int argIndex = 2;
01428
01429
01430
01431
01432
01433
01434 if (argExprs == NULL)
01435 {
01436
01437
01438
01439
01440 SaveCurrentModule(theEnv);
01441
01442
01443
01444
01445
01446 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
01447 theModule != NULL;
01448 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule))
01449 {
01450
01451
01452
01453
01454
01455 EnvSetCurrentModule(theEnv,(void *) theModule);
01456
01457
01458
01459
01460
01461
01462
01463 if (setFlag == FALSE)
01464 {
01465 EnvPrintRouter(theEnv,logName,EnvGetDefmoduleName(theEnv,(void *) theModule));
01466 EnvPrintRouter(theEnv,logName,":\n");
01467 }
01468
01469
01470
01471
01472
01473 for (theConstruct = (*constructClass->getNextItemFunction)(theEnv,NULL);
01474 theConstruct != NULL;
01475 theConstruct = (*constructClass->getNextItemFunction)(theEnv,theConstruct))
01476 {
01477
01478
01479
01480
01481
01482 if (setFlag)
01483 { (*setWatchFunc)(theEnv,newState,theConstruct); }
01484 else
01485 {
01486 EnvPrintRouter(theEnv,logName," ");
01487 ConstructPrintWatch(theEnv,logName,constructClass,theConstruct,getWatchFunc);
01488 }
01489 }
01490 }
01491
01492
01493
01494
01495
01496 RestoreCurrentModule(theEnv);
01497
01498
01499
01500
01501
01502
01503 return(TRUE);
01504 }
01505
01506
01507
01508
01509
01510 while (argExprs != NULL)
01511 {
01512
01513
01514
01515
01516
01517
01518 if (EvaluateExpression(theEnv,argExprs,&constructName))
01519 { return(FALSE); }
01520
01521
01522
01523
01524
01525 if ((constructName.type != SYMBOL) ? TRUE :
01526 ((theConstruct = LookupConstruct(theEnv,constructClass,
01527 DOToString(constructName),TRUE)) == NULL))
01528 {
01529 ExpectedTypeError1(theEnv,funcName,argIndex,constructClass->constructName);
01530 return(FALSE);
01531 }
01532
01533
01534
01535
01536
01537
01538 if (setFlag)
01539 { (*setWatchFunc)(theEnv,newState,theConstruct); }
01540 else
01541 { ConstructPrintWatch(theEnv,logName,constructClass,theConstruct,getWatchFunc); }
01542
01543
01544
01545
01546
01547 argIndex++;
01548 argExprs = GetNextArgument(argExprs);
01549 }
01550
01551
01552
01553
01554
01555
01556 return(TRUE);
01557 }
01558
01559
01560
01561
01562
01563 static void ConstructPrintWatch(
01564 void *theEnv,
01565 char *logName,
01566 struct construct *constructClass,
01567 void *theConstruct,
01568 unsigned (*getWatchFunc)(void *,void *))
01569 {
01570 EnvPrintRouter(theEnv,logName,ValueToString((*constructClass->getConstructNameFunction)((struct constructHeader *) theConstruct)));
01571 if ((*getWatchFunc)(theEnv,theConstruct))
01572 EnvPrintRouter(theEnv,logName," = on\n");
01573 else
01574 EnvPrintRouter(theEnv,logName," = off\n");
01575 }
01576
01577 #endif
01578
01579
01580
01581
01582
01583
01584 globle void *LookupConstruct(
01585 void *theEnv,
01586 struct construct *constructClass,
01587 char *constructName,
01588 intBool moduleNameAllowed)
01589 {
01590 void *theConstruct;
01591 char *constructType;
01592 int moduleCount;
01593
01594
01595
01596
01597
01598
01599 constructType = constructClass->constructName;
01600 theConstruct = FindImportedConstruct(theEnv,constructType,NULL,constructName,
01601 &moduleCount,TRUE,NULL);
01602
01603
01604
01605
01606
01607
01608 if (theConstruct != NULL)
01609 {
01610 if (moduleCount > 1)
01611 {
01612 AmbiguousReferenceErrorMessage(theEnv,constructType,constructName);
01613 return(NULL);
01614 }
01615 return(theConstruct);
01616 }
01617
01618
01619
01620
01621
01622
01623 if (moduleNameAllowed && FindModuleSeparator(constructName))
01624 { theConstruct = (*constructClass->findFunction)(theEnv,constructName); }
01625
01626
01627
01628
01629
01630 return(theConstruct);
01631 }
01632
01633
01634
01635
01636
01637 #if WIN_BTC
01638 #pragma argsused
01639 #endif
01640 globle intBool ConstructsDeletable(
01641 void *theEnv)
01642 {
01643 #if BLOAD_ONLY || RUN_TIME || ((! BLOAD) && (! BLOAD_AND_BSAVE))
01644 #if MAC_MCW || WIN_MCW || MAC_XCD
01645 #pragma unused(theEnv)
01646 #endif
01647 #endif
01648
01649 #if BLOAD_ONLY || RUN_TIME
01650 return(FALSE);
01651 #elif BLOAD || BLOAD_AND_BSAVE
01652 if (Bloaded(theEnv))
01653 return(FALSE);
01654 return TRUE;
01655 #else
01656 return(TRUE);
01657 #endif
01658 }