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 #define _MISCFUN_SOURCE_
00040
00041 #include <stdio.h>
00042 #define _STDIO_INCLUDED_
00043 #include <string.h>
00044
00045 #include "setup.h"
00046
00047 #include "argacces.h"
00048 #include "envrnmnt.h"
00049 #include "exprnpsr.h"
00050 #include "memalloc.h"
00051 #include "multifld.h"
00052 #include "router.h"
00053 #include "sysdep.h"
00054 #include "utility.h"
00055
00056 #if DEFFUNCTION_CONSTRUCT
00057 #include "dffnxfun.h"
00058 #endif
00059
00060 #include "miscfun.h"
00061
00062 #define MISCFUN_DATA 9
00063
00064 struct miscFunctionData
00065 {
00066 long long GensymNumber;
00067 };
00068
00069 #define MiscFunctionData(theEnv) ((struct miscFunctionData *) GetEnvironmentData(theEnv,MISCFUN_DATA))
00070
00071
00072
00073
00074
00075 static void ExpandFuncMultifield(void *,DATA_OBJECT *,EXPRESSION *,
00076 EXPRESSION **,void *);
00077 static int FindLanguageType(void *,char *);
00078
00079
00080
00081
00082 globle void MiscFunctionDefinitions(
00083 void *theEnv)
00084 {
00085 AllocateEnvironmentData(theEnv,MISCFUN_DATA,sizeof(struct miscFunctionData),NULL);
00086 MiscFunctionData(theEnv)->GensymNumber = 1;
00087
00088 #if ! RUN_TIME
00089 EnvDefineFunction2(theEnv,"gensym", 'w', PTIEF GensymFunction, "GensymFunction", "00");
00090 EnvDefineFunction2(theEnv,"gensym*", 'w', PTIEF GensymStarFunction, "GensymStarFunction", "00");
00091 EnvDefineFunction2(theEnv,"setgen", 'g', PTIEF SetgenFunction, "SetgenFunction", "11i");
00092 EnvDefineFunction2(theEnv,"system", 'v', PTIEF gensystem, "gensystem", "1*k");
00093 EnvDefineFunction2(theEnv,"length", 'g', PTIEF LengthFunction, "LengthFunction", "11q");
00094 EnvDefineFunction2(theEnv,"length$", 'g', PTIEF LengthFunction, "LengthFunction", "11q");
00095 EnvDefineFunction2(theEnv,"time", 'd', PTIEF TimeFunction, "TimeFunction", "00");
00096 EnvDefineFunction2(theEnv,"random", 'g', PTIEF RandomFunction, "RandomFunction", "02i");
00097 EnvDefineFunction2(theEnv,"seed", 'v', PTIEF SeedFunction, "SeedFunction", "11i");
00098 EnvDefineFunction2(theEnv,"conserve-mem", 'v', PTIEF ConserveMemCommand, "ConserveMemCommand", "11w");
00099 EnvDefineFunction2(theEnv,"release-mem", 'g', PTIEF ReleaseMemCommand, "ReleaseMemCommand", "00");
00100 #if DEBUGGING_FUNCTIONS
00101 EnvDefineFunction2(theEnv,"mem-used", 'g', PTIEF MemUsedCommand, "MemUsedCommand", "00");
00102 EnvDefineFunction2(theEnv,"mem-requests", 'g', PTIEF MemRequestsCommand, "MemRequestsCommand", "00");
00103 #endif
00104 EnvDefineFunction2(theEnv,"options", 'v', PTIEF OptionsCommand, "OptionsCommand", "00");
00105 EnvDefineFunction2(theEnv,"operating-system", 'w', PTIEF OperatingSystemFunction,"OperatingSystemFunction", "00");
00106 EnvDefineFunction2(theEnv,"(expansion-call)", 'u', PTIEF ExpandFuncCall, "ExpandFuncCall",NULL);
00107 EnvDefineFunction2(theEnv,"expand$",'u', PTIEF DummyExpandFuncMultifield,
00108 "DummyExpandFuncMultifield","11m");
00109 FuncSeqOvlFlags(theEnv,"expand$",FALSE,FALSE);
00110 EnvDefineFunction2(theEnv,"(set-evaluation-error)",
00111 'w', PTIEF CauseEvaluationError,"CauseEvaluationError",NULL);
00112 EnvDefineFunction2(theEnv,"set-sequence-operator-recognition",
00113 'b', PTIEF SetSORCommand,"SetSORCommand","11w");
00114 EnvDefineFunction2(theEnv,"get-sequence-operator-recognition",'b',
00115 PTIEF EnvGetSequenceOperatorRecognition,"EnvGetSequenceOperatorRecognition","00");
00116 EnvDefineFunction2(theEnv,"get-function-restrictions",'s',
00117 PTIEF GetFunctionRestrictions,"GetFunctionRestrictions","11w");
00118 EnvDefineFunction2(theEnv,"create$", 'm', PTIEF CreateFunction, "CreateFunction", NULL);
00119 EnvDefineFunction2(theEnv,"mv-append", 'm', PTIEF CreateFunction, "CreateFunction", NULL);
00120 EnvDefineFunction2(theEnv,"apropos", 'v', PTIEF AproposCommand, "AproposCommand", "11w");
00121 EnvDefineFunction2(theEnv,"get-function-list", 'm', PTIEF GetFunctionListFunction, "GetFunctionListFunction", "00");
00122 EnvDefineFunction2(theEnv,"funcall",'u', PTIEF FuncallFunction,"FuncallFunction","1**k");
00123 EnvDefineFunction2(theEnv,"new",'u', PTIEF NewFunction,"NewFunction","1*uw");
00124 EnvDefineFunction2(theEnv,"call",'u', PTIEF CallFunction,"CallFunction","1*u");
00125 EnvDefineFunction2(theEnv,"timer",'d', PTIEF TimerFunction,"TimerFunction","**");
00126 #endif
00127 }
00128
00129
00130
00131
00132 globle void CreateFunction(
00133 void *theEnv,
00134 DATA_OBJECT_PTR returnValue)
00135 {
00136 StoreInMultifield(theEnv,returnValue,GetFirstArgument(),TRUE);
00137 }
00138
00139
00140
00141
00142 globle long long SetgenFunction(
00143 void *theEnv)
00144 {
00145 long long theLong;
00146 DATA_OBJECT theValue;
00147
00148
00149
00150
00151
00152 if (EnvArgCountCheck(theEnv,"setgen",EXACTLY,1) == -1) return(MiscFunctionData(theEnv)->GensymNumber);
00153 if (EnvArgTypeCheck(theEnv,"setgen",1,INTEGER,&theValue) == FALSE) return(MiscFunctionData(theEnv)->GensymNumber);
00154
00155
00156
00157
00158
00159 theLong = ValueToLong(theValue.value);
00160
00161 if (theLong < 1LL)
00162 {
00163 ExpectedTypeError1(theEnv,"setgen",1,"number (greater than or equal to 1)");
00164 return(MiscFunctionData(theEnv)->GensymNumber);
00165 }
00166
00167
00168
00169
00170
00171
00172 MiscFunctionData(theEnv)->GensymNumber = theLong;
00173 return(theLong);
00174 }
00175
00176
00177
00178
00179
00180 globle void *GensymFunction(
00181 void *theEnv)
00182 {
00183 char genstring[128];
00184
00185
00186
00187
00188
00189 EnvArgCountCheck(theEnv,"gensym",EXACTLY,0);
00190
00191
00192
00193
00194
00195
00196 gensprintf(genstring,"gen%lld",MiscFunctionData(theEnv)->GensymNumber);
00197 MiscFunctionData(theEnv)->GensymNumber++;
00198
00199
00200
00201
00202
00203 return(EnvAddSymbol(theEnv,genstring));
00204 }
00205
00206
00207
00208
00209
00210 globle void *GensymStarFunction(
00211 void *theEnv)
00212 {
00213
00214
00215
00216
00217 EnvArgCountCheck(theEnv,"gensym*",EXACTLY,0);
00218
00219
00220
00221
00222
00223 return(GensymStar(theEnv));
00224 }
00225
00226
00227
00228
00229
00230 globle void *GensymStar(
00231 void *theEnv)
00232 {
00233 char genstring[128];
00234
00235
00236
00237
00238
00239
00240
00241
00242 do
00243 {
00244 gensprintf(genstring,"gen%lld",MiscFunctionData(theEnv)->GensymNumber);
00245 MiscFunctionData(theEnv)->GensymNumber++;
00246 }
00247 while (FindSymbolHN(theEnv,genstring) != NULL);
00248
00249
00250
00251
00252
00253 return(EnvAddSymbol(theEnv,genstring));
00254 }
00255
00256
00257
00258
00259
00260 globle long long RandomFunction(
00261 void *theEnv)
00262 {
00263 int argCount;
00264 long long rv;
00265 DATA_OBJECT theValue;
00266 long long begin, end;
00267
00268
00269
00270
00271
00272
00273 argCount = EnvRtnArgCount(theEnv);
00274
00275 if ((argCount != 0) && (argCount != 2))
00276 {
00277 PrintErrorID(theEnv,"MISCFUN",2,FALSE);
00278 EnvPrintRouter(theEnv,WERROR,"Function random expected either 0 or 2 arguments\n");
00279 }
00280
00281
00282
00283
00284
00285 rv = genrand();
00286
00287 if (argCount == 2)
00288 {
00289 if (EnvArgTypeCheck(theEnv,"random",1,INTEGER,&theValue) == FALSE) return(rv);
00290 begin = DOToLong(theValue);
00291 if (EnvArgTypeCheck(theEnv,"random",2,INTEGER,&theValue) == FALSE) return(rv);
00292 end = DOToLong(theValue);
00293 if (end < begin)
00294 {
00295 PrintErrorID(theEnv,"MISCFUN",3,FALSE);
00296 EnvPrintRouter(theEnv,WERROR,"Function random expected argument #1 to be less than argument #2\n");
00297 return(rv);
00298 }
00299
00300 rv = begin + (rv % ((end - begin) + 1));
00301 }
00302
00303
00304 return(rv);
00305 }
00306
00307
00308
00309
00310
00311 globle void SeedFunction(
00312 void *theEnv)
00313 {
00314 DATA_OBJECT theValue;
00315
00316
00317
00318
00319
00320 if (EnvArgCountCheck(theEnv,"seed",EXACTLY,1) == -1) return;
00321 if (EnvArgTypeCheck(theEnv,"seed",1,INTEGER,&theValue) == FALSE) return;
00322
00323
00324
00325
00326
00327 genseed((int) DOToLong(theValue));
00328 }
00329
00330
00331
00332
00333
00334 globle long long LengthFunction(
00335 void *theEnv)
00336 {
00337 DATA_OBJECT item;
00338
00339
00340
00341
00342
00343 if (EnvArgCountCheck(theEnv,"length$",EXACTLY,1) == -1) return(-1L);
00344 EnvRtnUnknown(theEnv,1,&item);
00345
00346
00347
00348
00349
00350
00351 if ((GetType(item) == STRING) || (GetType(item) == SYMBOL))
00352 { return( (long) strlen(DOToString(item))); }
00353
00354
00355
00356
00357
00358
00359 if (GetType(item) == MULTIFIELD)
00360 { return ( (long) GetDOLength(item)); }
00361
00362
00363
00364
00365
00366
00367 SetEvaluationError(theEnv,TRUE);
00368 ExpectedTypeError2(theEnv,"length$",1);
00369 return(-1L);
00370 }
00371
00372
00373
00374
00375
00376 globle long long ReleaseMemCommand(
00377 void *theEnv)
00378 {
00379
00380
00381
00382
00383 if (EnvArgCountCheck(theEnv,"release-mem",EXACTLY,0) == -1) return(0LL);
00384
00385
00386
00387
00388
00389
00390 return(EnvReleaseMem(theEnv,-1L,FALSE));
00391 }
00392
00393
00394
00395
00396
00397 globle void ConserveMemCommand(
00398 void *theEnv)
00399 {
00400 char *argument;
00401 DATA_OBJECT theValue;
00402
00403
00404
00405
00406
00407
00408 if (EnvArgCountCheck(theEnv,"conserve-mem",EXACTLY,1) == -1) return;
00409 if (EnvArgTypeCheck(theEnv,"conserve-mem",1,SYMBOL,&theValue) == FALSE) return;
00410
00411 argument = DOToString(theValue);
00412
00413
00414
00415
00416
00417
00418
00419 if (strcmp(argument,"on") == 0)
00420 { EnvSetConserveMemory(theEnv,TRUE); }
00421
00422
00423
00424
00425
00426
00427
00428 else if (strcmp(argument,"off") == 0)
00429 { EnvSetConserveMemory(theEnv,FALSE); }
00430
00431
00432
00433
00434
00435
00436 else
00437 {
00438 ExpectedTypeError1(theEnv,"conserve-mem",1,"symbol with value on or off");
00439 return;
00440 }
00441
00442 return;
00443 }
00444
00445 #if DEBUGGING_FUNCTIONS
00446
00447
00448
00449
00450
00451 globle long long MemUsedCommand(
00452 void *theEnv)
00453 {
00454
00455
00456
00457
00458 if (EnvArgCountCheck(theEnv,"mem-used",EXACTLY,0) == -1) return(0);
00459
00460
00461
00462
00463
00464
00465 return(EnvMemUsed(theEnv));
00466 }
00467
00468
00469
00470
00471
00472 globle long long MemRequestsCommand(
00473 void *theEnv)
00474 {
00475
00476
00477
00478
00479 if (EnvArgCountCheck(theEnv,"mem-requests",EXACTLY,0) == -1) return(0);
00480
00481
00482
00483
00484
00485
00486 return(EnvMemRequests(theEnv));
00487 }
00488
00489 #endif
00490
00491
00492
00493
00494
00495 globle void AproposCommand(
00496 void *theEnv)
00497 {
00498 char *argument;
00499 DATA_OBJECT argPtr;
00500 struct symbolHashNode *hashPtr = NULL;
00501 size_t theLength;
00502
00503
00504
00505
00506
00507 if (EnvArgCountCheck(theEnv,"apropos",EXACTLY,1) == -1) return;
00508 if (EnvArgTypeCheck(theEnv,"apropos",1,SYMBOL,&argPtr) == FALSE) return;
00509
00510
00511
00512
00513
00514 argument = DOToString(argPtr);
00515 theLength = strlen(argument);
00516
00517
00518
00519
00520
00521
00522
00523
00524 while ((hashPtr = GetNextSymbolMatch(theEnv,argument,theLength,hashPtr,TRUE,NULL)) != NULL)
00525 {
00526 EnvPrintRouter(theEnv,WDISPLAY,ValueToString(hashPtr));
00527 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00528 }
00529 }
00530
00531
00532
00533
00534
00535 globle void OptionsCommand(
00536 void *theEnv)
00537 {
00538
00539
00540
00541
00542 if (EnvArgCountCheck(theEnv,"options",EXACTLY,0) == -1) return;
00543
00544
00545
00546
00547
00548
00549 EnvPrintRouter(theEnv,WDISPLAY,"Machine type: ");
00550
00551 #if GENERIC
00552 EnvPrintRouter(theEnv,WDISPLAY,"Generic ");
00553 #endif
00554 #if VAX_VMS
00555 EnvPrintRouter(theEnv,WDISPLAY,"VAX VMS ");
00556 #endif
00557 #if UNIX_V
00558 EnvPrintRouter(theEnv,WDISPLAY,"UNIX System V or 4.2BSD ");
00559 #endif
00560 #if DARWIN
00561 EnvPrintRouter(theEnv,WDISPLAY,"Darwin ");
00562 #endif
00563 #if LINUX
00564 EnvPrintRouter(theEnv,WDISPLAY,"Linux ");
00565 #endif
00566 #if UNIX_7
00567 EnvPrintRouter(theEnv,WDISPLAY,"UNIX System III Version 7 or Sun Unix ");
00568 #endif
00569 #if MAC_MCW
00570 EnvPrintRouter(theEnv,WDISPLAY,"Apple Macintosh with CodeWarrior");
00571 #endif
00572 #if MAC_XCD
00573 EnvPrintRouter(theEnv,WDISPLAY,"Apple Macintosh with Xcode");
00574 #endif
00575 #if WIN_MVC
00576 EnvPrintRouter(theEnv,WDISPLAY,"Microsoft Windows with Microsoft Visual C++");
00577 #endif
00578 #if WIN_BTC
00579 EnvPrintRouter(theEnv,WDISPLAY,"Microsoft Windows with Borland Turbo C++");
00580 #endif
00581 #if WIN_MCW
00582 EnvPrintRouter(theEnv,WDISPLAY,"Microsoft Windows with Metrowerks CodeWarrior");
00583 #endif
00584 #if WIN_GCC
00585 EnvPrintRouter(theEnv,WDISPLAY,"Microsoft Windows with DJGPP");
00586 #endif
00587 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00588
00589 EnvPrintRouter(theEnv,WDISPLAY,"Defrule construct is ");
00590 #if DEFRULE_CONSTRUCT
00591 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00592 #else
00593 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00594 #endif
00595
00596 EnvPrintRouter(theEnv,WDISPLAY,"Defmodule construct is ");
00597 #if DEFMODULE_CONSTRUCT
00598 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00599 #else
00600 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00601 #endif
00602
00603 EnvPrintRouter(theEnv,WDISPLAY,"Deftemplate construct is ");
00604 #if DEFTEMPLATE_CONSTRUCT
00605 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00606 #else
00607 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00608 #endif
00609
00610 EnvPrintRouter(theEnv,WDISPLAY," Fact-set queries are ");
00611 #if FACT_SET_QUERIES
00612 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00613 #else
00614 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00615 #endif
00616
00617 #if DEFTEMPLATE_CONSTRUCT
00618
00619 EnvPrintRouter(theEnv,WDISPLAY," Deffacts construct is ");
00620 #if DEFFACTS_CONSTRUCT
00621 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00622 #else
00623 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00624 #endif
00625
00626 #endif
00627
00628 EnvPrintRouter(theEnv,WDISPLAY,"Defglobal construct is ");
00629 #if DEFGLOBAL_CONSTRUCT
00630 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00631 #else
00632 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00633 #endif
00634
00635 EnvPrintRouter(theEnv,WDISPLAY,"Deffunction construct is ");
00636 #if DEFFUNCTION_CONSTRUCT
00637 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00638 #else
00639 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00640 #endif
00641
00642 EnvPrintRouter(theEnv,WDISPLAY,"Defgeneric/Defmethod constructs are ");
00643 #if DEFGENERIC_CONSTRUCT
00644 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00645 #else
00646 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00647 #endif
00648
00649 EnvPrintRouter(theEnv,WDISPLAY,"Object System is ");
00650 #if OBJECT_SYSTEM
00651 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00652 #else
00653 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00654 #endif
00655
00656 #if OBJECT_SYSTEM
00657
00658 EnvPrintRouter(theEnv,WDISPLAY," Definstances construct is ");
00659 #if DEFINSTANCES_CONSTRUCT
00660 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00661 #else
00662 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00663 #endif
00664
00665 EnvPrintRouter(theEnv,WDISPLAY," Instance-set queries are ");
00666 #if INSTANCE_SET_QUERIES
00667 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00668 #else
00669 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00670 #endif
00671
00672 EnvPrintRouter(theEnv,WDISPLAY," Binary loading of instances is ");
00673 #if BLOAD_INSTANCES
00674 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00675 #else
00676 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00677 #endif
00678
00679 EnvPrintRouter(theEnv,WDISPLAY," Binary saving of instances is ");
00680 #if BSAVE_INSTANCES
00681 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00682 #else
00683 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00684 #endif
00685
00686 #endif
00687
00688 EnvPrintRouter(theEnv,WDISPLAY,"Extended math function package is ");
00689 #if EXTENDED_MATH_FUNCTIONS
00690 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00691 #else
00692 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00693 #endif
00694
00695 EnvPrintRouter(theEnv,WDISPLAY,"Text processing function package is ");
00696 #if TEXTPRO_FUNCTIONS
00697 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00698 #else
00699 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00700 #endif
00701
00702 EnvPrintRouter(theEnv,WDISPLAY,"Help system is ");
00703 #if HELP_FUNCTIONS
00704 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00705 #else
00706 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00707 #endif
00708
00709 EnvPrintRouter(theEnv,WDISPLAY,"Bload capability is ");
00710 #if BLOAD_ONLY
00711 EnvPrintRouter(theEnv,WDISPLAY,"BLOAD ONLY");
00712 #endif
00713 #if BLOAD
00714 EnvPrintRouter(theEnv,WDISPLAY,"BLOAD");
00715 #endif
00716 #if BLOAD_AND_BSAVE
00717 EnvPrintRouter(theEnv,WDISPLAY,"BLOAD AND BSAVE");
00718 #endif
00719 #if (! BLOAD_ONLY) && (! BLOAD) && (! BLOAD_AND_BSAVE)
00720 EnvPrintRouter(theEnv,WDISPLAY,"OFF ");
00721 #endif
00722 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00723
00724 EnvPrintRouter(theEnv,WDISPLAY,"EMACS Editor is ");
00725 #if EMACS_EDITOR
00726 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00727 #else
00728 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00729 #endif
00730
00731 EnvPrintRouter(theEnv,WDISPLAY,"Construct compiler is ");
00732 #if CONSTRUCT_COMPILER
00733 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00734 #else
00735 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00736 #endif
00737
00738 EnvPrintRouter(theEnv,WDISPLAY,"I/O function package is ");
00739 #if IO_FUNCTIONS
00740 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00741 #else
00742 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00743 #endif
00744
00745 EnvPrintRouter(theEnv,WDISPLAY,"String function package is ");
00746 #if STRING_FUNCTIONS
00747 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00748 #else
00749 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00750 #endif
00751
00752 EnvPrintRouter(theEnv,WDISPLAY,"Multifield function package is ");
00753 #if MULTIFIELD_FUNCTIONS
00754 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00755 #else
00756 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00757 #endif
00758
00759 EnvPrintRouter(theEnv,WDISPLAY,"Debugging function package is ");
00760 #if DEBUGGING_FUNCTIONS
00761 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00762 #else
00763 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00764 #endif
00765
00766 EnvPrintRouter(theEnv,WDISPLAY,"Block memory is ");
00767 #if BLOCK_MEMORY
00768 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00769 #else
00770 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00771 #endif
00772
00773 EnvPrintRouter(theEnv,WDISPLAY,"Window Interface flag is ");
00774 #if WINDOW_INTERFACE
00775 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00776 #else
00777 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00778 #endif
00779
00780 EnvPrintRouter(theEnv,WDISPLAY,"Developer flag is ");
00781 #if DEVELOPER
00782 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00783 #else
00784 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00785 #endif
00786
00787 EnvPrintRouter(theEnv,WDISPLAY,"Run time module is ");
00788 #if RUN_TIME
00789 EnvPrintRouter(theEnv,WDISPLAY,"ON\n");
00790 #else
00791 EnvPrintRouter(theEnv,WDISPLAY,"OFF\n");
00792 #endif
00793 }
00794
00795
00796
00797
00798
00799 globle void *OperatingSystemFunction(
00800 void *theEnv)
00801 {
00802 EnvArgCountCheck(theEnv,"operating-system",EXACTLY,0);
00803
00804 #if GENERIC
00805 return(EnvAddSymbol(theEnv,"UNKNOWN"));
00806 #endif
00807
00808 #if VAX_VMS
00809 return(EnvAddSymbol(theEnv,"VMS"));
00810 #endif
00811
00812 #if UNIX_V
00813 return(EnvAddSymbol(theEnv,"UNIX-V"));
00814 #endif
00815
00816 #if UNIX_7
00817 return(EnvAddSymbol(theEnv,"UNIX-7"));
00818 #endif
00819
00820 #if LINUX
00821 return(EnvAddSymbol(theEnv,"LINUX"));
00822 #endif
00823
00824 #if DARWIN
00825 return(EnvAddSymbol(theEnv,"DARWIN"));
00826 #endif
00827
00828 #if MAC_XCD || MAC_MCW
00829 return(EnvAddSymbol(theEnv,"MAC-OS-X"));
00830 #endif
00831
00832 #if IBM && (! WINDOW_INTERFACE)
00833 return(EnvAddSymbol(theEnv,"DOS"));
00834 #endif
00835
00836 #if IBM && WINDOW_INTERFACE
00837 return(EnvAddSymbol(theEnv,"WINDOWS"));
00838 #endif
00839
00840 return(EnvAddSymbol(theEnv,"UNKNOWN"));
00841 }
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 globle void ExpandFuncCall(
00859 void *theEnv,
00860 DATA_OBJECT *result)
00861 {
00862 EXPRESSION *newargexp,*fcallexp;
00863 struct FunctionDefinition *func;
00864
00865
00866
00867
00868
00869
00870
00871 newargexp = CopyExpression(theEnv,GetFirstArgument()->argList);
00872 ExpandFuncMultifield(theEnv,result,newargexp,&newargexp,
00873 (void *) FindFunction(theEnv,"expand$"));
00874
00875
00876
00877
00878
00879 fcallexp = get_struct(theEnv,expr);
00880 fcallexp->type = GetFirstArgument()->type;
00881 fcallexp->value = GetFirstArgument()->value;
00882 fcallexp->nextArg = NULL;
00883 fcallexp->argList = newargexp;
00884 if (fcallexp->type == FCALL)
00885 {
00886 func = (struct FunctionDefinition *) fcallexp->value;
00887 if (CheckFunctionArgCount(theEnv,ValueToString(func->callFunctionName),
00888 func->restrictions,CountArguments(newargexp)) == FALSE)
00889 {
00890 result->type = SYMBOL;
00891 result->value = EnvFalseSymbol(theEnv);
00892 ReturnExpression(theEnv,fcallexp);
00893 return;
00894 }
00895 }
00896 #if DEFFUNCTION_CONSTRUCT
00897 else if (fcallexp->type == PCALL)
00898 {
00899 if (CheckDeffunctionCall(theEnv,fcallexp->value,
00900 CountArguments(fcallexp->argList)) == FALSE)
00901 {
00902 result->type = SYMBOL;
00903 result->value = EnvFalseSymbol(theEnv);
00904 ReturnExpression(theEnv,fcallexp);
00905 SetEvaluationError(theEnv,TRUE);
00906 return;
00907 }
00908 }
00909 #endif
00910
00911 EvaluateExpression(theEnv,fcallexp,result);
00912 ReturnExpression(theEnv,fcallexp);
00913 }
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928 globle void DummyExpandFuncMultifield(
00929 void *theEnv,
00930 DATA_OBJECT *result)
00931 {
00932 result->type = SYMBOL;
00933 result->value = EnvFalseSymbol(theEnv);
00934 SetEvaluationError(theEnv,TRUE);
00935 PrintErrorID(theEnv,"MISCFUN",1,FALSE);
00936 EnvPrintRouter(theEnv,WERROR,"expand$ must be used in the argument list of a function call.\n");
00937 }
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958 static void ExpandFuncMultifield(
00959 void *theEnv,
00960 DATA_OBJECT *result,
00961 EXPRESSION *theExp,
00962 EXPRESSION **sto,
00963 void *expmult)
00964 {
00965 EXPRESSION *newexp,*top,*bot;
00966 register long i;
00967
00968 while (theExp != NULL)
00969 {
00970 if (theExp->value == expmult)
00971 {
00972 EvaluateExpression(theEnv,theExp->argList,result);
00973 ReturnExpression(theEnv,theExp->argList);
00974 if ((EvaluationData(theEnv)->EvaluationError) || (result->type != MULTIFIELD))
00975 {
00976 theExp->argList = NULL;
00977 if ((EvaluationData(theEnv)->EvaluationError == FALSE) && (result->type != MULTIFIELD))
00978 ExpectedTypeError2(theEnv,"expand$",1);
00979 theExp->value = (void *) FindFunction(theEnv,"(set-evaluation-error)");
00980 EvaluationData(theEnv)->EvaluationError = FALSE;
00981 EvaluationData(theEnv)->HaltExecution = FALSE;
00982 return;
00983 }
00984 top = bot = NULL;
00985 for (i = GetpDOBegin(result) ; i <= GetpDOEnd(result) ; i++)
00986 {
00987 newexp = get_struct(theEnv,expr);
00988 newexp->type = GetMFType(result->value,i);
00989 newexp->value = GetMFValue(result->value,i);
00990 newexp->argList = NULL;
00991 newexp->nextArg = NULL;
00992 if (top == NULL)
00993 top = newexp;
00994 else
00995 bot->nextArg = newexp;
00996 bot = newexp;
00997 }
00998 if (top == NULL)
00999 {
01000 *sto = theExp->nextArg;
01001 rtn_struct(theEnv,expr,theExp);
01002 theExp = *sto;
01003 }
01004 else
01005 {
01006 bot->nextArg = theExp->nextArg;
01007 *sto = top;
01008 rtn_struct(theEnv,expr,theExp);
01009 sto = &bot->nextArg;
01010 theExp = bot->nextArg;
01011 }
01012 }
01013 else
01014 {
01015 if (theExp->argList != NULL)
01016 ExpandFuncMultifield(theEnv,result,theExp->argList,&theExp->argList,expmult);
01017 sto = &theExp->nextArg;
01018 theExp = theExp->nextArg;
01019 }
01020 }
01021 }
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 globle void *CauseEvaluationError(
01033 void *theEnv)
01034 {
01035 SetEvaluationError(theEnv,TRUE);
01036 return((SYMBOL_HN *) EnvFalseSymbol(theEnv));
01037 }
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049 globle intBool SetSORCommand(
01050 void *theEnv)
01051 {
01052 #if (! RUN_TIME) && (! BLOAD_ONLY)
01053 DATA_OBJECT arg;
01054
01055 if (EnvArgTypeCheck(theEnv,"set-sequence-operator-recognition",1,SYMBOL,&arg) == FALSE)
01056 return(ExpressionData(theEnv)->SequenceOpMode);
01057 return(EnvSetSequenceOperatorRecognition(theEnv,(arg.value == EnvFalseSymbol(theEnv)) ?
01058 FALSE : TRUE));
01059 #else
01060 return(ExpressionData(theEnv)->SequenceOpMode);
01061 #endif
01062 }
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072 globle void *GetFunctionRestrictions(
01073 void *theEnv)
01074 {
01075 DATA_OBJECT temp;
01076 struct FunctionDefinition *fptr;
01077
01078 if (EnvArgTypeCheck(theEnv,"get-function-restrictions",1,SYMBOL,&temp) == FALSE)
01079 return((SYMBOL_HN *) EnvAddSymbol(theEnv,""));
01080 fptr = FindFunction(theEnv,DOToString(temp));
01081 if (fptr == NULL)
01082 {
01083 CantFindItemErrorMessage(theEnv,"function",DOToString(temp));
01084 SetEvaluationError(theEnv,TRUE);
01085 return((SYMBOL_HN *) EnvAddSymbol(theEnv,""));
01086 }
01087 if (fptr->restrictions == NULL)
01088 return((SYMBOL_HN *) EnvAddSymbol(theEnv,"0**"));
01089 return((SYMBOL_HN *) EnvAddSymbol(theEnv,fptr->restrictions));
01090 }
01091
01092
01093
01094
01095
01096 globle void GetFunctionListFunction(
01097 void *theEnv,
01098 DATA_OBJECT *returnValue)
01099 {
01100 struct FunctionDefinition *theFunction;
01101 struct multifield *theList;
01102 unsigned long functionCount = 0;
01103
01104 if (EnvArgCountCheck(theEnv,"get-function-list",EXACTLY,0) == -1)
01105 {
01106 EnvSetMultifieldErrorValue(theEnv,returnValue);
01107 return;
01108 }
01109
01110 for (theFunction = GetFunctionList(theEnv);
01111 theFunction != NULL;
01112 theFunction = theFunction->next)
01113 { functionCount++; }
01114
01115 SetpType(returnValue,MULTIFIELD);
01116 SetpDOBegin(returnValue,1);
01117 SetpDOEnd(returnValue,functionCount);
01118 theList = (struct multifield *) EnvCreateMultifield(theEnv,functionCount);
01119 SetpValue(returnValue,(void *) theList);
01120
01121 for (theFunction = GetFunctionList(theEnv), functionCount = 1;
01122 theFunction != NULL;
01123 theFunction = theFunction->next, functionCount++)
01124 {
01125 SetMFType(theList,functionCount,SYMBOL);
01126 SetMFValue(theList,functionCount,theFunction->callFunctionName);
01127 }
01128 }
01129
01130
01131
01132
01133
01134 globle void FuncallFunction(
01135 void *theEnv,
01136 DATA_OBJECT *returnValue)
01137 {
01138 int argCount, i, j;
01139 DATA_OBJECT theValue;
01140 FUNCTION_REFERENCE theReference;
01141 char *name;
01142 struct multifield *theMultifield;
01143 struct expr *lastAdd = NULL, *nextAdd, *multiAdd;
01144 struct FunctionDefinition *theFunction;
01145
01146
01147
01148
01149
01150 SetpType(returnValue,SYMBOL);
01151 SetpValue(returnValue,EnvFalseSymbol(theEnv));
01152
01153
01154
01155
01156
01157
01158 if ((argCount = EnvArgCountCheck(theEnv,"funcall",AT_LEAST,1)) == -1) return;
01159
01160
01161
01162
01163
01164 if (EnvArgTypeCheck(theEnv,"funcall",1,SYMBOL_OR_STRING,&theValue) == FALSE)
01165 { return; }
01166
01167
01168
01169
01170
01171 name = DOToString(theValue);
01172 if (! GetFunctionReference(theEnv,name,&theReference))
01173 {
01174 ExpectedTypeError1(theEnv,"funcall",1,"function, deffunction, or generic function name");
01175 return;
01176 }
01177
01178
01179
01180
01181
01182
01183 if (theReference.type == FCALL)
01184 {
01185 theFunction = FindFunction(theEnv,name);
01186 if (theFunction->parser != NULL)
01187 {
01188 ExpectedTypeError1(theEnv,"funcall",1,"function without specialized parser");
01189 return;
01190 }
01191 }
01192
01193
01194
01195
01196
01197 ExpressionInstall(theEnv,&theReference);
01198
01199 for (i = 2; i <= argCount; i++)
01200 {
01201 EnvRtnUnknown(theEnv,i,&theValue);
01202 if (GetEvaluationError(theEnv))
01203 {
01204 ExpressionDeinstall(theEnv,&theReference);
01205 return;
01206 }
01207
01208 switch(GetType(theValue))
01209 {
01210 case MULTIFIELD:
01211 nextAdd = GenConstant(theEnv,FCALL,(void *) FindFunction(theEnv,"create$"));
01212
01213 if (lastAdd == NULL)
01214 { theReference.argList = nextAdd; }
01215 else
01216 { lastAdd->nextArg = nextAdd; }
01217 lastAdd = nextAdd;
01218
01219 multiAdd = NULL;
01220 theMultifield = (struct multifield *) GetValue(theValue);
01221 for (j = GetDOBegin(theValue); j <= GetDOEnd(theValue); j++)
01222 {
01223 nextAdd = GenConstant(theEnv,GetMFType(theMultifield,j),GetMFValue(theMultifield,j));
01224 if (multiAdd == NULL)
01225 { lastAdd->argList = nextAdd; }
01226 else
01227 { multiAdd->nextArg = nextAdd; }
01228 multiAdd = nextAdd;
01229 }
01230
01231 ExpressionInstall(theEnv,lastAdd);
01232 break;
01233
01234 default:
01235 nextAdd = GenConstant(theEnv,GetType(theValue),GetValue(theValue));
01236 if (lastAdd == NULL)
01237 { theReference.argList = nextAdd; }
01238 else
01239 { lastAdd->nextArg = nextAdd; }
01240 lastAdd = nextAdd;
01241 ExpressionInstall(theEnv,lastAdd);
01242 break;
01243 }
01244 }
01245
01246
01247
01248
01249
01250 #if DEFFUNCTION_CONSTRUCT
01251 if (theReference.type == PCALL)
01252 {
01253 if (CheckDeffunctionCall(theEnv,theReference.value,CountArguments(theReference.argList)) == FALSE)
01254 {
01255 PrintErrorID(theEnv,"MISCFUN",4,FALSE);
01256 EnvPrintRouter(theEnv,WERROR,"Function funcall called with the wrong number of arguments for deffunction ");
01257 EnvPrintRouter(theEnv,WERROR,EnvGetDeffunctionName(theEnv,theReference.value));
01258 EnvPrintRouter(theEnv,WERROR,"\n");
01259 ExpressionDeinstall(theEnv,&theReference);
01260 ReturnExpression(theEnv,theReference.argList);
01261 return;
01262 }
01263 }
01264 #endif
01265
01266
01267
01268
01269
01270 EvaluateExpression(theEnv,&theReference,returnValue);
01271
01272
01273
01274
01275
01276 ExpressionDeinstall(theEnv,&theReference);
01277 ReturnExpression(theEnv,theReference.argList);
01278 }
01279
01280
01281
01282
01283
01284 globle void NewFunction(
01285 void *theEnv,
01286 DATA_OBJECT *returnValue)
01287 {
01288 int theType;
01289 DATA_OBJECT theValue;
01290 char *name;
01291
01292
01293
01294
01295
01296 SetpType(returnValue,SYMBOL);
01297 SetpValue(returnValue,EnvFalseSymbol(theEnv));
01298
01299
01300
01301
01302
01303
01304 if (EnvArgCountCheck(theEnv,"new",AT_LEAST,1) == -1) return;
01305
01306
01307
01308
01309
01310 if (EnvArgTypeCheck(theEnv,"new",1,SYMBOL,&theValue) == FALSE)
01311 { return; }
01312
01313
01314
01315
01316
01317 name = DOToString(theValue);
01318
01319 theType = FindLanguageType(theEnv,name);
01320
01321 if (theType == -1)
01322 {
01323 ExpectedTypeError1(theEnv,"new",1,"external language");
01324 return;
01325 }
01326
01327
01328
01329
01330
01331 if ((EvaluationData(theEnv)->ExternalAddressTypes[theType] != NULL) &&
01332 (EvaluationData(theEnv)->ExternalAddressTypes[theType]->newFunction != NULL))
01333 { (*EvaluationData(theEnv)->ExternalAddressTypes[theType]->newFunction)(theEnv,returnValue); }
01334 }
01335
01336
01337
01338
01339
01340 globle void CallFunction(
01341 void *theEnv,
01342 DATA_OBJECT *returnValue)
01343 {
01344 int theType;
01345 DATA_OBJECT theValue;
01346 char *name;
01347 int argumentCount;
01348 struct externalAddressHashNode *theEA;
01349
01350
01351
01352
01353
01354 SetpType(returnValue,SYMBOL);
01355 SetpValue(returnValue,EnvFalseSymbol(theEnv));
01356
01357
01358
01359
01360
01361
01362
01363 if ((argumentCount = EnvArgCountCheck(theEnv,"call",AT_LEAST,1)) == -1) return;
01364
01365
01366
01367
01368
01369 EnvRtnUnknown(theEnv,1,&theValue);
01370
01371
01372
01373
01374
01375
01376 if (GetType(theValue) == SYMBOL)
01377 {
01378 name = DOToString(theValue);
01379
01380 theType = FindLanguageType(theEnv,name);
01381
01382 if (theType == -1)
01383 {
01384 ExpectedTypeError1(theEnv,"call",1,"external language symbol or external address");
01385 return;
01386 }
01387
01388
01389
01390
01391
01392
01393
01394 if ((EvaluationData(theEnv)->ExternalAddressTypes[theType] != NULL) &&
01395 (EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction != NULL))
01396 { (*EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction)(theEnv,&theValue,returnValue); }
01397
01398 return;
01399 }
01400
01401
01402
01403
01404
01405
01406
01407 if (GetType(theValue) == EXTERNAL_ADDRESS)
01408 {
01409 theEA = (struct externalAddressHashNode *) GetValue(theValue);
01410
01411 theType = theEA->type;
01412
01413 if ((EvaluationData(theEnv)->ExternalAddressTypes[theType] != NULL) &&
01414 (EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction != NULL))
01415 { (*EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction)(theEnv,&theValue,returnValue); }
01416
01417 return;
01418 }
01419
01420 ExpectedTypeError1(theEnv,"call",1,"external language symbol or external address");
01421 }
01422
01423
01424
01425
01426 static int FindLanguageType(
01427 void *theEnv,
01428 char *languageName)
01429 {
01430 int theType;
01431
01432 for (theType = 0; theType < EvaluationData(theEnv)->numberOfAddressTypes; theType++)
01433 {
01434 if (strcmp(EvaluationData(theEnv)->ExternalAddressTypes[theType]->name,languageName) == 0)
01435 { return(theType); }
01436 }
01437
01438 return -1;
01439 }
01440
01441
01442
01443
01444
01445 globle double TimeFunction(
01446 void *theEnv)
01447 {
01448
01449
01450
01451
01452 EnvArgCountCheck(theEnv,"time",EXACTLY,0);
01453
01454
01455
01456
01457
01458 return(gentime());
01459 }
01460
01461
01462
01463
01464
01465 globle double TimerFunction(
01466 void *theEnv)
01467 {
01468 int numa, i;
01469 double startTime;
01470 DATA_OBJECT returnValue;
01471
01472 startTime = gentime();
01473
01474 numa = EnvRtnArgCount(theEnv);
01475
01476 i = 1;
01477 while ((i <= numa) && (GetHaltExecution(theEnv) != TRUE))
01478 {
01479 EnvRtnUnknown(theEnv,i,&returnValue);
01480 i++;
01481 }
01482
01483 return(gentime() - startTime);
01484 }