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 _STRNGFUN_SOURCE_
00030
00031 #include "setup.h"
00032
00033 #if STRING_FUNCTIONS
00034
00035 #include <stdio.h>
00036 #define _STDIO_INCLUDED_
00037 #include <ctype.h>
00038 #include <string.h>
00039
00040 #include "argacces.h"
00041 #include "commline.h"
00042 #include "constrct.h"
00043 #include "cstrcpsr.h"
00044 #include "engine.h"
00045 #include "envrnmnt.h"
00046 #include "exprnpsr.h"
00047 #include "extnfunc.h"
00048 #include "memalloc.h"
00049 #include "prcdrpsr.h"
00050 #include "router.h"
00051 #include "strngrtr.h"
00052 #include "scanner.h"
00053 #include "sysdep.h"
00054
00055 #if DEFRULE_CONSTRUCT
00056 #include "drive.h"
00057 #endif
00058
00059 #include "strngfun.h"
00060
00061
00062
00063
00064
00065 static void StrOrSymCatFunction(void *,DATA_OBJECT_PTR,unsigned short);
00066
00067
00068
00069
00070
00071 globle void StringFunctionDefinitions(
00072 void *theEnv)
00073 {
00074 #if ! RUN_TIME
00075 EnvDefineFunction2(theEnv,"str-cat", 'k', PTIEF StrCatFunction, "StrCatFunction", "1*");
00076 EnvDefineFunction2(theEnv,"sym-cat", 'k', PTIEF SymCatFunction, "SymCatFunction", "1*");
00077 EnvDefineFunction2(theEnv,"str-length", 'g', PTIEF StrLengthFunction, "StrLengthFunction", "11j");
00078 EnvDefineFunction2(theEnv,"str-compare", 'g', PTIEF StrCompareFunction, "StrCompareFunction", "23*jji");
00079 EnvDefineFunction2(theEnv,"upcase", 'j', PTIEF UpcaseFunction, "UpcaseFunction", "11j");
00080 EnvDefineFunction2(theEnv,"lowcase", 'j', PTIEF LowcaseFunction, "LowcaseFunction", "11j");
00081 EnvDefineFunction2(theEnv,"sub-string", 's', PTIEF SubStringFunction, "SubStringFunction", "33*iij");
00082 EnvDefineFunction2(theEnv,"str-index", 'u', PTIEF StrIndexFunction, "StrIndexFunction", "22j");
00083 EnvDefineFunction2(theEnv,"eval", 'u', PTIEF EvalFunction, "EvalFunction", "11k");
00084 EnvDefineFunction2(theEnv,"build", 'b', PTIEF BuildFunction, "BuildFunction", "11k");
00085 EnvDefineFunction2(theEnv,"string-to-field", 'u', PTIEF StringToFieldFunction, "StringToFieldFunction", "11j");
00086 #else
00087 #if MAC_MCW || WIN_MCW || MAC_XCD
00088 #pragma unused(theEnv)
00089 #endif
00090 #endif
00091 }
00092
00093
00094
00095
00096
00097 globle void StrCatFunction(
00098 void *theEnv,
00099 DATA_OBJECT_PTR returnValue)
00100 {
00101 StrOrSymCatFunction(theEnv,returnValue,STRING);
00102 }
00103
00104
00105
00106
00107
00108 globle void SymCatFunction(
00109 void *theEnv,
00110 DATA_OBJECT_PTR returnValue)
00111 {
00112 StrOrSymCatFunction(theEnv,returnValue,SYMBOL);
00113 }
00114
00115
00116
00117
00118
00119 static void StrOrSymCatFunction(
00120 void *theEnv,
00121 DATA_OBJECT_PTR returnValue,
00122 unsigned short returnType)
00123 {
00124 DATA_OBJECT theArg;
00125 int numArgs, i, total, j;
00126 char *theString;
00127 SYMBOL_HN **arrayOfStrings;
00128 SYMBOL_HN *hashPtr;
00129 char *functionName;
00130
00131
00132
00133
00134
00135
00136
00137 SetpType(returnValue,returnType);
00138 if (returnType == STRING)
00139 {
00140 functionName = "str-cat";
00141 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,""));
00142 }
00143 else
00144 {
00145 functionName = "sym-cat";
00146 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,"nil"));
00147 }
00148
00149
00150
00151
00152
00153
00154
00155 numArgs = EnvRtnArgCount(theEnv);
00156 arrayOfStrings = (SYMBOL_HN **) gm1(theEnv,(int) sizeof(SYMBOL_HN *) * numArgs);
00157 for (i = 0; i < numArgs; i++)
00158 { arrayOfStrings[i] = NULL; }
00159
00160
00161
00162
00163
00164
00165 total = 1;
00166 for (i = 1 ; i <= numArgs ; i++)
00167 {
00168 EnvRtnUnknown(theEnv,i,&theArg);
00169
00170 switch(GetType(theArg))
00171 {
00172 case STRING:
00173 #if OBJECT_SYSTEM
00174 case INSTANCE_NAME:
00175 #endif
00176 case SYMBOL:
00177 hashPtr = (SYMBOL_HN *) GetValue(theArg);
00178 arrayOfStrings[i-1] = hashPtr;
00179 IncrementSymbolCount(hashPtr);
00180 break;
00181
00182 case FLOAT:
00183 hashPtr = (SYMBOL_HN *) EnvAddSymbol(theEnv,FloatToString(theEnv,ValueToDouble(GetValue(theArg))));
00184 arrayOfStrings[i-1] = hashPtr;
00185 IncrementSymbolCount(hashPtr);
00186 break;
00187
00188 case INTEGER:
00189 hashPtr = (SYMBOL_HN *) EnvAddSymbol(theEnv,LongIntegerToString(theEnv,ValueToLong(GetValue(theArg))));
00190 arrayOfStrings[i-1] = hashPtr;
00191 IncrementSymbolCount(hashPtr);
00192 break;
00193
00194 default:
00195 ExpectedTypeError1(theEnv,functionName,i,"string, instance name, symbol, float, or integer");
00196 SetEvaluationError(theEnv,TRUE);
00197 break;
00198 }
00199
00200 if (EvaluationData(theEnv)->EvaluationError)
00201 {
00202 for (i = 0; i < numArgs; i++)
00203 {
00204 if (arrayOfStrings[i] != NULL)
00205 { DecrementSymbolCount(theEnv,arrayOfStrings[i]); }
00206 }
00207
00208 rm(theEnv,arrayOfStrings,sizeof(SYMBOL_HN *) * numArgs);
00209 return;
00210 }
00211
00212 total += (int) strlen(ValueToString(arrayOfStrings[i - 1]));
00213 }
00214
00215
00216
00217
00218
00219
00220
00221 theString = (char *) gm2(theEnv,(sizeof(char) * total));
00222
00223 j = 0;
00224 for (i = 0 ; i < numArgs ; i++)
00225 {
00226 gensprintf(&theString[j],"%s",ValueToString(arrayOfStrings[i]));
00227 j += (int) strlen(ValueToString(arrayOfStrings[i]));
00228 }
00229
00230
00231
00232
00233
00234
00235 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,theString));
00236 rm(theEnv,theString,sizeof(char) * total);
00237
00238 for (i = 0; i < numArgs; i++)
00239 {
00240 if (arrayOfStrings[i] != NULL)
00241 { DecrementSymbolCount(theEnv,arrayOfStrings[i]); }
00242 }
00243
00244 rm(theEnv,arrayOfStrings,sizeof(SYMBOL_HN *) * numArgs);
00245 }
00246
00247
00248
00249
00250
00251 globle long long StrLengthFunction(
00252 void *theEnv)
00253 {
00254 DATA_OBJECT theArg;
00255
00256
00257
00258
00259
00260 if (EnvArgCountCheck(theEnv,"str-length",EXACTLY,1) == -1)
00261 { return(-1LL); }
00262
00263
00264
00265
00266
00267 if (EnvArgTypeCheck(theEnv,"str-length",1,SYMBOL_OR_STRING,&theArg) == FALSE)
00268 { return(-1LL); }
00269
00270
00271
00272
00273
00274 return(UTF8Length(DOToString(theArg)));
00275 }
00276
00277
00278
00279
00280
00281 globle void UpcaseFunction(
00282 void *theEnv,
00283 DATA_OBJECT_PTR returnValue)
00284 {
00285 DATA_OBJECT theArg;
00286 unsigned i;
00287 size_t slen;
00288 char *osptr, *nsptr;
00289
00290
00291
00292
00293
00294 if (EnvArgCountCheck(theEnv,"upcase",EXACTLY,1) == -1)
00295 {
00296 SetpType(returnValue,STRING);
00297 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,""));
00298 return;
00299 }
00300
00301
00302
00303
00304
00305 if (EnvArgTypeCheck(theEnv,"upcase",1,SYMBOL_OR_STRING,&theArg) == FALSE)
00306 {
00307 SetpType(returnValue,STRING);
00308 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,""));
00309 return;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318 osptr = DOToString(theArg);
00319 slen = strlen(osptr) + 1;
00320 nsptr = (char *) gm2(theEnv,slen);
00321
00322 for (i = 0 ; i < slen ; i++)
00323 {
00324 if (islower(osptr[i]))
00325 { nsptr[i] = (char) toupper(osptr[i]); }
00326 else
00327 { nsptr[i] = osptr[i]; }
00328 }
00329
00330
00331
00332
00333
00334
00335 SetpType(returnValue,GetType(theArg));
00336 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,nsptr));
00337 rm(theEnv,nsptr,slen);
00338 }
00339
00340
00341
00342
00343
00344 globle void LowcaseFunction(
00345 void *theEnv,
00346 DATA_OBJECT_PTR returnValue)
00347 {
00348 DATA_OBJECT theArg;
00349 unsigned i;
00350 size_t slen;
00351 char *osptr, *nsptr;
00352
00353
00354
00355
00356
00357 if (EnvArgCountCheck(theEnv,"lowcase",EXACTLY,1) == -1)
00358 {
00359 SetpType(returnValue,STRING);
00360 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,""));
00361 return;
00362 }
00363
00364
00365
00366
00367
00368 if (EnvArgTypeCheck(theEnv,"lowcase",1,SYMBOL_OR_STRING,&theArg) == FALSE)
00369 {
00370 SetpType(returnValue,STRING);
00371 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,""));
00372 return;
00373 }
00374
00375
00376
00377
00378
00379
00380
00381 osptr = DOToString(theArg);
00382 slen = strlen(osptr) + 1;
00383 nsptr = (char *) gm2(theEnv,slen);
00384
00385 for (i = 0 ; i < slen ; i++)
00386 {
00387 if (isupper(osptr[i]))
00388 { nsptr[i] = (char) tolower(osptr[i]); }
00389 else
00390 { nsptr[i] = osptr[i]; }
00391 }
00392
00393
00394
00395
00396
00397
00398 SetpType(returnValue,GetType(theArg));
00399 SetpValue(returnValue,(void *) EnvAddSymbol(theEnv,nsptr));
00400 rm(theEnv,nsptr,slen);
00401 }
00402
00403
00404
00405
00406
00407 globle long long StrCompareFunction(
00408 void *theEnv)
00409 {
00410 int numArgs, length;
00411 DATA_OBJECT arg1, arg2, arg3;
00412 long long returnValue;
00413
00414
00415
00416
00417
00418 if ((numArgs = EnvArgRangeCheck(theEnv,"str-compare",2,3)) == -1) return(0L);
00419
00420
00421
00422
00423
00424 if (EnvArgTypeCheck(theEnv,"str-compare",1,SYMBOL_OR_STRING,&arg1) == FALSE)
00425 { return(0L); }
00426
00427 if (EnvArgTypeCheck(theEnv,"str-compare",2,SYMBOL_OR_STRING,&arg2) == FALSE)
00428 { return(0L); }
00429
00430
00431
00432
00433
00434
00435 if (numArgs == 3)
00436 {
00437 if (EnvArgTypeCheck(theEnv,"str-compare",3,INTEGER,&arg3) == FALSE)
00438 { return(0L); }
00439
00440 length = CoerceToInteger(GetType(arg3),GetValue(arg3));
00441 returnValue = strncmp(DOToString(arg1),DOToString(arg2),
00442 (STD_SIZE) length);
00443 }
00444 else
00445 { returnValue = strcmp(DOToString(arg1),DOToString(arg2)); }
00446
00447
00448
00449
00450
00451
00452
00453
00454 if (returnValue < 0) returnValue = -1;
00455 else if (returnValue > 0) returnValue = 1;
00456 return(returnValue);
00457 }
00458
00459
00460
00461
00462
00463 globle void *SubStringFunction(
00464 void *theEnv)
00465 {
00466 DATA_OBJECT theArgument;
00467 char *tempString, *returnString;
00468 size_t start, end, i, j, length;
00469 void *returnValue;
00470
00471
00472
00473
00474
00475 if (EnvArgCountCheck(theEnv,"sub-string",EXACTLY,3) == -1)
00476 { return((void *) EnvAddSymbol(theEnv,"")); }
00477
00478 if (EnvArgTypeCheck(theEnv,"sub-string",1,INTEGER,&theArgument) == FALSE)
00479 { return((void *) EnvAddSymbol(theEnv,"")); }
00480
00481 if (CoerceToLongInteger(theArgument.type,theArgument.value) < 1)
00482 { start = 0; }
00483 else
00484 { start = (size_t) CoerceToLongInteger(theArgument.type,theArgument.value) - 1; }
00485
00486 if (EnvArgTypeCheck(theEnv,"sub-string",2,INTEGER,&theArgument) == FALSE)
00487 { return((void *) EnvAddSymbol(theEnv,"")); }
00488
00489 if (CoerceToLongInteger(theArgument.type,theArgument.value) < 1)
00490 { return((void *) EnvAddSymbol(theEnv,"")); }
00491 else
00492 { end = (size_t) CoerceToLongInteger(theArgument.type,theArgument.value) - 1; }
00493
00494 if (EnvArgTypeCheck(theEnv,"sub-string",3,SYMBOL_OR_STRING,&theArgument) == FALSE)
00495 { return((void *) EnvAddSymbol(theEnv,"")); }
00496
00497 tempString = DOToString(theArgument);
00498
00499
00500
00501
00502
00503 length = UTF8Length(tempString);
00504
00505 if (end > length)
00506 { end = length; }
00507
00508
00509
00510
00511
00512
00513 if ((start > end) || (length == 0))
00514 { return((void *) EnvAddSymbol(theEnv,"")); }
00515
00516
00517
00518
00519
00520
00521
00522 else
00523 {
00524 start = UTF8Offset(tempString,start);
00525 end = UTF8Offset(tempString,end + 1) - 1;
00526
00527 returnString = (char *) gm2(theEnv,(unsigned) (end - start + 2));
00528 for(j=0, i=start;i <= end; i++, j++)
00529 { *(returnString+j) = *(tempString+i); }
00530 *(returnString+j) = '\0';
00531 }
00532
00533
00534
00535
00536
00537 returnValue = (void *) EnvAddSymbol(theEnv,returnString);
00538 rm(theEnv,returnString,(unsigned) (end - start + 2));
00539 return(returnValue);
00540 }
00541
00542
00543
00544
00545
00546 globle void StrIndexFunction(
00547 void *theEnv,
00548 DATA_OBJECT_PTR result)
00549 {
00550 DATA_OBJECT theArgument1, theArgument2;
00551 char *strg1, *strg2, *strg3;
00552 size_t i, j;
00553
00554 result->type = SYMBOL;
00555 result->value = EnvFalseSymbol(theEnv);
00556
00557
00558
00559
00560
00561 if (EnvArgCountCheck(theEnv,"str-index",EXACTLY,2) == -1) return;
00562
00563 if (EnvArgTypeCheck(theEnv,"str-index",1,SYMBOL_OR_STRING,&theArgument1) == FALSE) return;
00564
00565 if (EnvArgTypeCheck(theEnv,"str-index",2,SYMBOL_OR_STRING,&theArgument2) == FALSE) return;
00566
00567 strg1 = DOToString(theArgument1);
00568 strg2 = DOToString(theArgument2);
00569
00570
00571
00572
00573
00574
00575 if (strlen(strg1) == 0)
00576 {
00577 result->type = INTEGER;
00578 result->value = (void *) EnvAddLong(theEnv,(long long) UTF8Length(strg2) + 1LL);
00579 return;
00580 }
00581
00582 strg3 = strg2;
00583 for (i=1; *strg2; i++, strg2++)
00584 {
00585 for (j=0; *(strg1+j) && *(strg1+j) == *(strg2+j); j++)
00586 { }
00587
00588 if (*(strg1+j) == '\0')
00589 {
00590 result->type = INTEGER;
00591 result->value = (void *) EnvAddLong(theEnv,(long long) UTF8CharNum(strg3,i));
00592 return;
00593 }
00594 }
00595
00596 return;
00597 }
00598
00599
00600
00601
00602
00603 globle void StringToFieldFunction(
00604 void *theEnv,
00605 DATA_OBJECT *returnValue)
00606 {
00607 DATA_OBJECT theArg;
00608
00609
00610
00611
00612
00613 if (EnvArgCountCheck(theEnv,"string-to-field",EXACTLY,1) == -1)
00614 {
00615 returnValue->type = STRING;
00616 returnValue->value = (void *) EnvAddSymbol(theEnv,"*** ERROR ***");
00617 return;
00618 }
00619
00620
00621
00622
00623
00624 if (EnvArgTypeCheck(theEnv,"string-to-field",1,SYMBOL_OR_STRING,&theArg) == FALSE)
00625 {
00626 returnValue->type = STRING;
00627 returnValue->value = (void *) EnvAddSymbol(theEnv,"*** ERROR ***");
00628 return;
00629 }
00630
00631
00632
00633
00634
00635 StringToField(theEnv,DOToString(theArg),returnValue);
00636 }
00637
00638
00639
00640
00641 globle void StringToField(
00642 void *theEnv,
00643 char *theString,
00644 DATA_OBJECT *returnValue)
00645 {
00646 struct token theToken;
00647
00648
00649
00650
00651
00652
00653 OpenStringSource(theEnv,"string-to-field-str",theString,0);
00654 GetToken(theEnv,"string-to-field-str",&theToken);
00655 CloseStringSource(theEnv,"string-to-field-str");
00656
00657
00658
00659
00660
00661 returnValue->type = theToken.type;
00662 if ((theToken.type == FLOAT) || (theToken.type == STRING) ||
00663 #if OBJECT_SYSTEM
00664 (theToken.type == INSTANCE_NAME) ||
00665 #endif
00666 (theToken.type == SYMBOL) || (theToken.type == INTEGER))
00667 { returnValue->value = theToken.value; }
00668 else if (theToken.type == STOP)
00669 {
00670 returnValue->type = SYMBOL;
00671 returnValue->value = (void *) EnvAddSymbol(theEnv,"EOF");
00672 }
00673 else if (theToken.type == UNKNOWN_VALUE)
00674 {
00675 returnValue->type = STRING;
00676 returnValue->value = (void *) EnvAddSymbol(theEnv,"*** ERROR ***");
00677 }
00678 else
00679 {
00680 returnValue->type = STRING;
00681 returnValue->value = (void *) EnvAddSymbol(theEnv,theToken.printForm);
00682 }
00683 }
00684
00685 #if (! RUN_TIME) && (! BLOAD_ONLY)
00686
00687
00688
00689
00690
00691 globle void EvalFunction(
00692 void *theEnv,
00693 DATA_OBJECT_PTR returnValue)
00694 {
00695 DATA_OBJECT theArg;
00696
00697
00698
00699
00700
00701 if (EnvArgCountCheck(theEnv,"eval",EXACTLY,1) == -1)
00702 {
00703 SetpType(returnValue,SYMBOL);
00704 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00705 return;
00706 }
00707
00708
00709
00710
00711
00712 if (EnvArgTypeCheck(theEnv,"eval",1,SYMBOL_OR_STRING,&theArg) == FALSE)
00713 {
00714 SetpType(returnValue,SYMBOL);
00715 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00716 return;
00717 }
00718
00719
00720
00721
00722
00723 EnvEval(theEnv,DOToString(theArg),returnValue);
00724 }
00725
00726
00727
00728
00729
00730 #if ALLOW_ENVIRONMENT_GLOBALS
00731 globle int Eval(
00732 char *theString,
00733 DATA_OBJECT_PTR returnValue)
00734 {
00735 return EnvEval(GetCurrentEnvironment(),theString,returnValue);
00736 }
00737 #endif
00738
00739
00740
00741
00742
00743 globle int EnvEval(
00744 void *theEnv,
00745 char *theString,
00746 DATA_OBJECT_PTR returnValue)
00747 {
00748 struct expr *top;
00749 int ov;
00750 static int depth = 0;
00751 char logicalNameBuffer[20];
00752 struct BindInfo *oldBinds;
00753
00754
00755
00756
00757
00758
00759 depth++;
00760 gensprintf(logicalNameBuffer,"Eval-%d",depth);
00761 if (OpenStringSource(theEnv,logicalNameBuffer,theString,0) == 0)
00762 {
00763 SetpType(returnValue,SYMBOL);
00764 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00765 depth--;
00766 return(FALSE);
00767 }
00768
00769
00770
00771
00772
00773
00774 ov = GetPPBufferStatus(theEnv);
00775 SetPPBufferStatus(theEnv,FALSE);
00776 oldBinds = GetParsedBindNames(theEnv);
00777 SetParsedBindNames(theEnv,NULL);
00778
00779
00780
00781
00782
00783 top = ParseAtomOrExpression(theEnv,logicalNameBuffer,NULL);
00784
00785
00786
00787
00788
00789 SetPPBufferStatus(theEnv,ov);
00790 ClearParsedBindNames(theEnv);
00791 SetParsedBindNames(theEnv,oldBinds);
00792
00793
00794
00795
00796
00797 if (top == NULL)
00798 {
00799 SetEvaluationError(theEnv,TRUE);
00800 CloseStringSource(theEnv,logicalNameBuffer);
00801 SetpType(returnValue,SYMBOL);
00802 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00803 depth--;
00804 return(FALSE);
00805 }
00806
00807
00808
00809
00810
00811
00812 if ((top->type == MF_GBL_VARIABLE) || (top->type == MF_VARIABLE))
00813 {
00814 PrintErrorID(theEnv,"MISCFUN",1,FALSE);
00815 EnvPrintRouter(theEnv,WERROR,"expand$ must be used in the argument list of a function call.\n");
00816 SetEvaluationError(theEnv,TRUE);
00817 CloseStringSource(theEnv,logicalNameBuffer);
00818 SetpType(returnValue,SYMBOL);
00819 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00820 ReturnExpression(theEnv,top);
00821 depth--;
00822 return(FALSE);
00823 }
00824
00825
00826
00827
00828
00829
00830 if (ExpressionContainsVariables(top,FALSE))
00831 {
00832 PrintErrorID(theEnv,"STRNGFUN",2,FALSE);
00833 EnvPrintRouter(theEnv,WERROR,"Some variables could not be accessed by the eval function.\n");
00834 SetEvaluationError(theEnv,TRUE);
00835 CloseStringSource(theEnv,logicalNameBuffer);
00836 SetpType(returnValue,SYMBOL);
00837 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00838 ReturnExpression(theEnv,top);
00839 depth--;
00840 return(FALSE);
00841 }
00842
00843
00844
00845
00846
00847
00848 ExpressionInstall(theEnv,top);
00849 EvaluateExpression(theEnv,top,returnValue);
00850 ExpressionDeinstall(theEnv,top);
00851
00852 depth--;
00853 ReturnExpression(theEnv,top);
00854 CloseStringSource(theEnv,logicalNameBuffer);
00855
00856
00857
00858
00859
00860
00861 if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
00862 (EvaluationData(theEnv)->CurrentExpression == NULL))
00863 {
00864 ValueInstall(theEnv,returnValue);
00865 PeriodicCleanup(theEnv,TRUE,FALSE);
00866 ValueDeinstall(theEnv,returnValue);
00867 }
00868
00869 if (GetEvaluationError(theEnv)) return(FALSE);
00870 return(TRUE);
00871 }
00872
00873 #else
00874
00875
00876
00877
00878
00879 globle void EvalFunction(
00880 void *theEnv,
00881 DATA_OBJECT_PTR returnValue)
00882 {
00883 PrintErrorID(theEnv,"STRNGFUN",1,FALSE);
00884 EnvPrintRouter(theEnv,WERROR,"Function eval does not work in run time modules.\n");
00885 SetpType(returnValue,SYMBOL);
00886 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00887 }
00888
00889
00890
00891
00892
00893 globle int EnvEval(
00894 void *theEnv,
00895 char *theString,
00896 DATA_OBJECT_PTR returnValue)
00897 {
00898 #if (MAC_MCW || WIN_MCW) && (RUN_TIME || BLOAD_ONLY)
00899 #pragma unused(theString)
00900 #endif
00901
00902 PrintErrorID(theEnv,"STRNGFUN",1,FALSE);
00903 EnvPrintRouter(theEnv,WERROR,"Function eval does not work in run time modules.\n");
00904 SetpType(returnValue,SYMBOL);
00905 SetpValue(returnValue,EnvFalseSymbol(theEnv));
00906 return(FALSE);
00907 }
00908
00909 #endif
00910
00911 #if (! RUN_TIME) && (! BLOAD_ONLY)
00912
00913
00914
00915
00916 globle int BuildFunction(
00917 void *theEnv)
00918 {
00919 DATA_OBJECT theArg;
00920
00921
00922
00923
00924
00925 if (EnvArgCountCheck(theEnv,"build",EXACTLY,1) == -1) return(FALSE);
00926
00927
00928
00929
00930
00931 if (EnvArgTypeCheck(theEnv,"build",1,SYMBOL_OR_STRING,&theArg) == FALSE)
00932 { return(FALSE); }
00933
00934
00935
00936
00937
00938 return(EnvBuild(theEnv,DOToString(theArg)));
00939 }
00940
00941
00942
00943
00944
00945 #if ALLOW_ENVIRONMENT_GLOBALS
00946 globle int Build(
00947 char *theString)
00948 {
00949 return EnvBuild(GetCurrentEnvironment(),theString);
00950 }
00951 #endif
00952
00953
00954
00955
00956
00957 globle int EnvBuild(
00958 void *theEnv,
00959 char *theString)
00960 {
00961 char *constructType;
00962 struct token theToken;
00963 int errorFlag;
00964
00965
00966
00967
00968
00969 #if DEFRULE_CONSTRUCT
00970 if (EngineData(theEnv)->JoinOperationInProgress) return(FALSE);
00971 #endif
00972
00973
00974
00975
00976
00977
00978 if (OpenStringSource(theEnv,"build",theString,0) == 0)
00979 { return(FALSE); }
00980
00981
00982
00983
00984
00985
00986 GetToken(theEnv,"build",&theToken);
00987
00988 if (theToken.type != LPAREN)
00989 {
00990 CloseStringSource(theEnv,"build");
00991 return(FALSE);
00992 }
00993
00994
00995
00996
00997
00998 GetToken(theEnv,"build",&theToken);
00999 if (theToken.type != SYMBOL)
01000 {
01001 CloseStringSource(theEnv,"build");
01002 return(FALSE);
01003 }
01004
01005 constructType = ValueToString(theToken.value);
01006
01007
01008
01009
01010
01011 errorFlag = ParseConstruct(theEnv,constructType,"build");
01012
01013
01014
01015
01016
01017 CloseStringSource(theEnv,"build");
01018
01019
01020
01021
01022
01023
01024 if (errorFlag == 1)
01025 {
01026 EnvPrintRouter(theEnv,WERROR,"\nERROR:\n");
01027 PrintInChunks(theEnv,WERROR,GetPPBuffer(theEnv));
01028 EnvPrintRouter(theEnv,WERROR,"\n");
01029 }
01030
01031 DestroyPPBuffer(theEnv);
01032
01033
01034
01035
01036
01037
01038 if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
01039 (EvaluationData(theEnv)->CurrentExpression == NULL))
01040 { PeriodicCleanup(theEnv,TRUE,FALSE); }
01041
01042
01043
01044
01045
01046
01047 if (errorFlag == 0) return(TRUE);
01048
01049 return(FALSE);
01050 }
01051 #else
01052
01053
01054
01055
01056 globle int BuildFunction(
01057 void *theEnv)
01058 {
01059 PrintErrorID(theEnv,"STRNGFUN",1,FALSE);
01060 EnvPrintRouter(theEnv,WERROR,"Function build does not work in run time modules.\n");
01061 return(FALSE);
01062 }
01063
01064
01065
01066
01067
01068 globle int EnvBuild(
01069 void *theEnv,
01070 char *theString)
01071 {
01072 #if (MAC_MCW || WIN_MCW) && (RUN_TIME || BLOAD_ONLY)
01073 #pragma unused(theString)
01074 #endif
01075
01076 PrintErrorID(theEnv,"STRNGFUN",1,FALSE);
01077 EnvPrintRouter(theEnv,WERROR,"Function build does not work in run time modules.\n");
01078 return(FALSE);
01079 }
01080 #endif
01081
01082 #endif