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 #define _FILECOM_SOURCE_
00032
00033 #include <stdio.h>
00034
00035 #define _STDIO_INCLUDED_
00036 #include <string.h>
00037
00038 #include "setup.h"
00039
00040 #include "argacces.h"
00041 #include "constrct.h"
00042 #include "commline.h"
00043 #include "cstrcpsr.h"
00044 #include "envrnmnt.h"
00045 #include "extnfunc.h"
00046 #include "memalloc.h"
00047 #include "prcdrfun.h"
00048 #include "router.h"
00049 #include "strngrtr.h"
00050 #include "sysdep.h"
00051 #include "utility.h"
00052
00053 #include "filecom.h"
00054
00055 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00056 #include "bsave.h"
00057 #include "bload.h"
00058 #endif
00059
00060
00061
00062
00063
00064 struct batchEntry
00065 {
00066 int batchType;
00067 void *inputSource;
00068 char *theString;
00069 struct batchEntry *next;
00070 };
00071
00072
00073
00074
00075
00076 #define FILE_BATCH 0
00077 #define STRING_BATCH 1
00078
00079 #define BUFFER_SIZE 120
00080
00081 #define FILECOM_DATA 14
00082
00083 struct fileCommandData
00084 {
00085 #if DEBUGGING_FUNCTIONS
00086 FILE *DribbleFP;
00087 char *DribbleBuffer;
00088 size_t DribbleCurrentPosition;
00089 size_t DribbleMaximumPosition;
00090 int (*DribbleStatusFunction)(void *,int);
00091 #endif
00092 int BatchType;
00093 void *BatchSource;
00094 char *BatchBuffer;
00095 size_t BatchCurrentPosition;
00096 size_t BatchMaximumPosition;
00097 struct batchEntry *TopOfBatchList;
00098 struct batchEntry *BottomOfBatchList;
00099 };
00100
00101 #define FileCommandData(theEnv) ((struct fileCommandData *) GetEnvironmentData(theEnv,FILECOM_DATA))
00102
00103
00104
00105
00106
00107 #if DEBUGGING_FUNCTIONS
00108 static int FindDribble(void *,char *);
00109 static int GetcDribble(void *,char *);
00110 static int UngetcDribble(void *,int,char *);
00111 static int ExitDribble(void *,int);
00112 static int PrintDribble(void *,char *,char *);
00113 static void PutcDribbleBuffer(void *,int);
00114 #endif
00115 static int FindBatch(void *,char *);
00116 static int GetcBatch(void *,char *);
00117 static int UngetcBatch(void *,int,char *);
00118 static int ExitBatch(void *,int);
00119 static void AddBatch(void *,int,void *,int,char *);
00120 static void DeallocateFileCommandData(void *);
00121
00122
00123
00124
00125
00126 globle void FileCommandDefinitions(
00127 void *theEnv)
00128 {
00129 AllocateEnvironmentData(theEnv,FILECOM_DATA,sizeof(struct fileCommandData),DeallocateFileCommandData);
00130
00131 #if ! RUN_TIME
00132 #if DEBUGGING_FUNCTIONS
00133 EnvDefineFunction2(theEnv,"batch",'b',PTIEF BatchCommand,"BatchCommand","11k");
00134 EnvDefineFunction2(theEnv,"batch*",'b',PTIEF BatchStarCommand,"BatchStarCommand","11k");
00135 EnvDefineFunction2(theEnv,"dribble-on",'b',PTIEF DribbleOnCommand,"DribbleOnCommand","11k");
00136 EnvDefineFunction2(theEnv,"dribble-off",'b',PTIEF DribbleOffCommand,"DribbleOffCommand","00");
00137 EnvDefineFunction2(theEnv,"save",'b',PTIEF SaveCommand,"SaveCommand","11k");
00138 #endif
00139 EnvDefineFunction2(theEnv,"load",'b',PTIEF LoadCommand,"LoadCommand","11k");
00140 EnvDefineFunction2(theEnv,"load*",'b',PTIEF LoadStarCommand,"LoadStarCommand","11k");
00141 #if BLOAD_AND_BSAVE
00142 InitializeBsaveData(theEnv);
00143 EnvDefineFunction2(theEnv,"bsave",'b', PTIEF BsaveCommand,"BsaveCommand","11k");
00144 #endif
00145 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00146 InitializeBloadData(theEnv);
00147 EnvDefineFunction2(theEnv,"bload",'b',PTIEF BloadCommand,"BloadCommand","11k");
00148 #endif
00149 #endif
00150 }
00151
00152
00153
00154
00155
00156 static void DeallocateFileCommandData(
00157 void *theEnv)
00158 {
00159 struct batchEntry *theEntry, *nextEntry;
00160
00161 theEntry = FileCommandData(theEnv)->TopOfBatchList;
00162 while (theEntry != NULL)
00163 {
00164 nextEntry = theEntry->next;
00165
00166 if (theEntry->batchType == FILE_BATCH)
00167 { GenClose(theEnv,(FILE *) FileCommandData(theEnv)->TopOfBatchList->inputSource); }
00168 else
00169 { rm(theEnv,theEntry->theString,strlen(theEntry->theString) + 1); }
00170
00171 rtn_struct(theEnv,batchEntry,theEntry);
00172
00173 theEntry = nextEntry;
00174 }
00175
00176 if (FileCommandData(theEnv)->BatchBuffer != NULL)
00177 { rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); }
00178
00179 #if DEBUGGING_FUNCTIONS
00180 if (FileCommandData(theEnv)->DribbleBuffer != NULL)
00181 { rm(theEnv,FileCommandData(theEnv)->DribbleBuffer,FileCommandData(theEnv)->DribbleMaximumPosition); }
00182
00183 if (FileCommandData(theEnv)->DribbleFP != NULL)
00184 { GenClose(theEnv,FileCommandData(theEnv)->DribbleFP); }
00185 #endif
00186 }
00187
00188 #if DEBUGGING_FUNCTIONS
00189
00190
00191
00192 #if WIN_BTC
00193 #pragma argsused
00194 #endif
00195 static int FindDribble(
00196 void *theEnv,
00197 char *logicalName)
00198 {
00199 #if MAC_MCW || WIN_MCW || MAC_XCD
00200 #pragma unused(theEnv)
00201 #endif
00202
00203 if ( (strcmp(logicalName,"stdout") == 0) ||
00204 (strcmp(logicalName,"stdin") == 0) ||
00205 (strcmp(logicalName,WPROMPT) == 0) ||
00206 (strcmp(logicalName,WTRACE) == 0) ||
00207 (strcmp(logicalName,WERROR) == 0) ||
00208 (strcmp(logicalName,WWARNING) == 0) ||
00209 (strcmp(logicalName,WDISPLAY) == 0) ||
00210 (strcmp(logicalName,WDIALOG) == 0) )
00211 { return(TRUE); }
00212
00213 return(FALSE);
00214 }
00215
00216
00217
00218
00219 static int PrintDribble(
00220 void *theEnv,
00221 char *logicalName,
00222 char *str)
00223 {
00224 int i;
00225
00226
00227
00228
00229
00230 for (i = 0 ; str[i] != EOS ; i++)
00231 { PutcDribbleBuffer(theEnv,str[i]); }
00232
00233
00234
00235
00236
00237 EnvDeactivateRouter(theEnv,"dribble");
00238 EnvPrintRouter(theEnv,logicalName,str);
00239 EnvActivateRouter(theEnv,"dribble");
00240
00241 return(1);
00242 }
00243
00244
00245
00246
00247 static int GetcDribble(
00248 void *theEnv,
00249 char *logicalName)
00250 {
00251 int rv;
00252
00253
00254
00255
00256
00257
00258 EnvDeactivateRouter(theEnv,"dribble");
00259 rv = EnvGetcRouter(theEnv,logicalName);
00260 EnvActivateRouter(theEnv,"dribble");
00261
00262
00263
00264
00265
00266
00267 PutcDribbleBuffer(theEnv,rv);
00268
00269
00270
00271
00272
00273 return(rv);
00274 }
00275
00276
00277
00278
00279 static void PutcDribbleBuffer(
00280 void *theEnv,
00281 int rv)
00282 {
00283
00284
00285
00286
00287
00288 if (rv == EOF)
00289 {
00290 if (FileCommandData(theEnv)->DribbleCurrentPosition > 0)
00291 {
00292 fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer);
00293 FileCommandData(theEnv)->DribbleCurrentPosition = 0;
00294 FileCommandData(theEnv)->DribbleBuffer[0] = EOS;
00295 }
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 else if (RouterData(theEnv)->AwaitingInput == FALSE)
00309 {
00310 if (FileCommandData(theEnv)->DribbleCurrentPosition > 0)
00311 {
00312 fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer);
00313 FileCommandData(theEnv)->DribbleCurrentPosition = 0;
00314 FileCommandData(theEnv)->DribbleBuffer[0] = EOS;
00315 }
00316
00317 fputc(rv,FileCommandData(theEnv)->DribbleFP);
00318 }
00319
00320
00321
00322
00323
00324 else
00325 {
00326 FileCommandData(theEnv)->DribbleBuffer = ExpandStringWithChar(theEnv,rv,FileCommandData(theEnv)->DribbleBuffer,
00327 &FileCommandData(theEnv)->DribbleCurrentPosition,
00328 &FileCommandData(theEnv)->DribbleMaximumPosition,
00329 FileCommandData(theEnv)->DribbleMaximumPosition+BUFFER_SIZE);
00330 }
00331 }
00332
00333
00334
00335
00336 static int UngetcDribble(
00337 void *theEnv,
00338 int ch,
00339 char *logicalName)
00340 {
00341 int rv;
00342
00343
00344
00345
00346
00347 if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) FileCommandData(theEnv)->DribbleCurrentPosition--;
00348 FileCommandData(theEnv)->DribbleBuffer[FileCommandData(theEnv)->DribbleCurrentPosition] = EOS;
00349
00350
00351
00352
00353
00354
00355 EnvDeactivateRouter(theEnv,"dribble");
00356 rv = EnvUngetcRouter(theEnv,ch,logicalName);
00357 EnvActivateRouter(theEnv,"dribble");
00358
00359
00360
00361
00362
00363 return(rv);
00364 }
00365
00366
00367
00368
00369 #if WIN_BTC
00370 #pragma argsused
00371 #endif
00372 static int ExitDribble(
00373 void *theEnv,
00374 int num)
00375 {
00376 #if MAC_MCW || WIN_MCW || MAC_XCD
00377 #pragma unused(num)
00378 #endif
00379
00380 if (FileCommandData(theEnv)->DribbleCurrentPosition > 0)
00381 { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); }
00382
00383 if (FileCommandData(theEnv)->DribbleFP != NULL) GenClose(theEnv,FileCommandData(theEnv)->DribbleFP);
00384 return(1);
00385 }
00386
00387
00388
00389
00390
00391 globle int DribbleOnCommand(
00392 void *theEnv)
00393 {
00394 char *fileName;
00395
00396 if (EnvArgCountCheck(theEnv,"dribble-on",EXACTLY,1) == -1) return(FALSE);
00397 if ((fileName = GetFileName(theEnv,"dribble-on",1)) == NULL) return(FALSE);
00398
00399 return (EnvDribbleOn(theEnv,fileName));
00400 }
00401
00402
00403
00404
00405
00406 globle intBool EnvDribbleOn(
00407 void *theEnv,
00408 char *fileName)
00409 {
00410
00411
00412
00413
00414
00415 if (FileCommandData(theEnv)->DribbleFP != NULL)
00416 { EnvDribbleOff(theEnv); }
00417
00418
00419
00420
00421
00422 FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,"w");
00423 if (FileCommandData(theEnv)->DribbleFP == NULL)
00424 {
00425 OpenErrorMessage(theEnv,"dribble-on",fileName);
00426 return(0);
00427 }
00428
00429
00430
00431
00432
00433 EnvAddRouter(theEnv,"dribble", 40,
00434 FindDribble, PrintDribble,
00435 GetcDribble, UngetcDribble,
00436 ExitDribble);
00437
00438 FileCommandData(theEnv)->DribbleCurrentPosition = 0;
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 if (FileCommandData(theEnv)->DribbleStatusFunction != NULL)
00449 { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,TRUE); }
00450
00451
00452
00453
00454
00455
00456 return(TRUE);
00457 }
00458
00459
00460
00461
00462
00463 globle intBool EnvDribbleActive(
00464 void *theEnv)
00465 {
00466 if (FileCommandData(theEnv)->DribbleFP != NULL) return(TRUE);
00467
00468 return(FALSE);
00469 }
00470
00471
00472
00473
00474
00475 globle int DribbleOffCommand(
00476 void *theEnv)
00477 {
00478 if (EnvArgCountCheck(theEnv,"dribble-off",EXACTLY,0) == -1) return(FALSE);
00479 return(EnvDribbleOff(theEnv));
00480 }
00481
00482
00483
00484
00485
00486 globle intBool EnvDribbleOff(
00487 void *theEnv)
00488 {
00489 int rv = 0;
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 if (FileCommandData(theEnv)->DribbleStatusFunction != NULL)
00500 { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,FALSE); }
00501
00502
00503
00504
00505
00506
00507 if (FileCommandData(theEnv)->DribbleFP != NULL)
00508 {
00509 if (FileCommandData(theEnv)->DribbleCurrentPosition > 0)
00510 { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); }
00511 EnvDeleteRouter(theEnv,"dribble");
00512 if (GenClose(theEnv,FileCommandData(theEnv)->DribbleFP) == 0) rv = 1;
00513 }
00514 else
00515 { rv = 1; }
00516
00517 FileCommandData(theEnv)->DribbleFP = NULL;
00518
00519
00520
00521
00522
00523 if (FileCommandData(theEnv)->DribbleBuffer != NULL)
00524 {
00525 rm(theEnv,FileCommandData(theEnv)->DribbleBuffer,FileCommandData(theEnv)->DribbleMaximumPosition);
00526 FileCommandData(theEnv)->DribbleBuffer = NULL;
00527 }
00528
00529 FileCommandData(theEnv)->DribbleCurrentPosition = 0;
00530 FileCommandData(theEnv)->DribbleMaximumPosition = 0;
00531
00532
00533
00534
00535
00536
00537 return(rv);
00538 }
00539
00540
00541
00542
00543
00544
00545 globle void SetDribbleStatusFunction(
00546 void *theEnv,
00547 int (*fnptr)(void *,int))
00548 {
00549 FileCommandData(theEnv)->DribbleStatusFunction = fnptr;
00550 }
00551 #endif
00552
00553
00554
00555
00556 #if WIN_BTC
00557 #pragma argsused
00558 #endif
00559 static int FindBatch(
00560 void *theEnv,
00561 char *logicalName)
00562 {
00563 #if MAC_MCW || WIN_MCW || MAC_XCD
00564 #pragma unused(theEnv)
00565 #endif
00566
00567 if (strcmp(logicalName,"stdin") == 0)
00568 { return(TRUE); }
00569
00570 return(FALSE);
00571 }
00572
00573
00574
00575
00576 static int GetcBatch(
00577 void *theEnv,
00578 char *logicalName)
00579 {
00580 return(LLGetcBatch(theEnv,logicalName,FALSE));
00581 }
00582
00583
00584
00585
00586
00587 globle int LLGetcBatch(
00588 void *theEnv,
00589 char *logicalName,
00590 int returnOnEOF)
00591 {
00592 int rv = EOF, flag = 1;
00593
00594
00595
00596
00597
00598
00599 while ((rv == EOF) && (flag == 1))
00600 {
00601 if (FileCommandData(theEnv)->BatchType == FILE_BATCH)
00602 { rv = getc((FILE *) FileCommandData(theEnv)->BatchSource); }
00603 else
00604 { rv = EnvGetcRouter(theEnv,(char *) FileCommandData(theEnv)->BatchSource); }
00605
00606 if (rv == EOF)
00607 {
00608 if (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer);
00609 flag = RemoveBatch(theEnv);
00610 }
00611 }
00612
00613
00614
00615
00616
00617
00618
00619 if (rv == EOF)
00620 {
00621 if (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer);
00622 EnvDeleteRouter(theEnv,"batch");
00623 RemoveBatch(theEnv);
00624 if (returnOnEOF == TRUE)
00625 { return (EOF); }
00626 else
00627 { return(EnvGetcRouter(theEnv,logicalName)); }
00628 }
00629
00630
00631
00632
00633
00634 FileCommandData(theEnv)->BatchBuffer = ExpandStringWithChar(theEnv,(char) rv,FileCommandData(theEnv)->BatchBuffer,&FileCommandData(theEnv)->BatchCurrentPosition,
00635 &FileCommandData(theEnv)->BatchMaximumPosition,FileCommandData(theEnv)->BatchMaximumPosition+BUFFER_SIZE);
00636
00637
00638
00639
00640
00641
00642 if ((char) rv == '\n')
00643 {
00644 EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer);
00645 FileCommandData(theEnv)->BatchCurrentPosition = 0;
00646 if ((FileCommandData(theEnv)->BatchBuffer != NULL) && (FileCommandData(theEnv)->BatchMaximumPosition > BUFFER_SIZE))
00647 {
00648 rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition);
00649 FileCommandData(theEnv)->BatchMaximumPosition = 0;
00650 FileCommandData(theEnv)->BatchBuffer = NULL;
00651 }
00652 }
00653
00654
00655
00656
00657
00658 return(rv);
00659 }
00660
00661
00662
00663
00664 #if WIN_BTC
00665 #pragma argsused
00666 #endif
00667 static int UngetcBatch(
00668 void *theEnv,
00669 int ch,
00670 char *logicalName)
00671 {
00672 #if MAC_MCW || WIN_MCW || MAC_XCD
00673 #pragma unused(logicalName)
00674 #endif
00675
00676 if (FileCommandData(theEnv)->BatchCurrentPosition > 0) FileCommandData(theEnv)->BatchCurrentPosition--;
00677 if (FileCommandData(theEnv)->BatchBuffer != NULL) FileCommandData(theEnv)->BatchBuffer[FileCommandData(theEnv)->BatchCurrentPosition] = EOS;
00678 if (FileCommandData(theEnv)->BatchType == FILE_BATCH)
00679 { return(ungetc(ch,(FILE *) FileCommandData(theEnv)->BatchSource)); }
00680
00681 return(EnvUngetcRouter(theEnv,ch,(char *) FileCommandData(theEnv)->BatchSource));
00682 }
00683
00684
00685
00686
00687 #if WIN_BTC
00688 #pragma argsused
00689 #endif
00690 static int ExitBatch(
00691 void *theEnv,
00692 int num)
00693 {
00694 #if MAC_MCW || WIN_MCW || MAC_XCD
00695 #pragma unused(num)
00696 #endif
00697 CloseAllBatchSources(theEnv);
00698 return(1);
00699 }
00700
00701
00702
00703
00704
00705 globle int BatchCommand(
00706 void *theEnv)
00707 {
00708 char *fileName;
00709
00710 if (EnvArgCountCheck(theEnv,"batch",EXACTLY,1) == -1) return(FALSE);
00711 if ((fileName = GetFileName(theEnv,"batch",1)) == NULL) return(FALSE);
00712
00713 return(OpenBatch(theEnv,fileName,FALSE));
00714 }
00715
00716
00717
00718
00719 globle int Batch(
00720 void *theEnv,
00721 char *fileName)
00722 { return(OpenBatch(theEnv,fileName,FALSE)); }
00723
00724
00725
00726
00727
00728 globle int OpenBatch(
00729 void *theEnv,
00730 char *fileName,
00731 int placeAtEnd)
00732 {
00733 FILE *theFile;
00734
00735
00736
00737
00738
00739 theFile = GenOpen(theEnv,fileName,"r");
00740
00741 if (theFile == NULL)
00742 {
00743 OpenErrorMessage(theEnv,"batch",fileName);
00744 return(FALSE);
00745 }
00746
00747
00748
00749
00750
00751
00752 if (FileCommandData(theEnv)->TopOfBatchList == NULL)
00753 {
00754 EnvAddRouter(theEnv,"batch", 20,
00755 FindBatch, NULL,
00756 GetcBatch, UngetcBatch,
00757 ExitBatch);
00758 }
00759
00760
00761
00762
00763
00764
00765 AddBatch(theEnv,placeAtEnd,(void *) theFile,FILE_BATCH,NULL);
00766
00767
00768
00769
00770
00771
00772 return(TRUE);
00773 }
00774
00775
00776
00777
00778
00779
00780
00781
00782 globle int OpenStringBatch(
00783 void *theEnv,
00784 char *stringName,
00785 char *theString,
00786 int placeAtEnd)
00787 {
00788 if (OpenStringSource(theEnv,stringName,theString,0) == 0)
00789 { return(0); }
00790
00791 if (FileCommandData(theEnv)->TopOfBatchList == NULL)
00792 {
00793 EnvAddRouter(theEnv,"batch", 20,
00794 FindBatch, NULL,
00795 GetcBatch, UngetcBatch,
00796 ExitBatch);
00797 }
00798
00799 AddBatch(theEnv,placeAtEnd,(void *) stringName,STRING_BATCH,theString);
00800
00801 return(1);
00802 }
00803
00804
00805
00806
00807
00808 static void AddBatch(
00809 void *theEnv,
00810 int placeAtEnd,
00811 void *theSource,
00812 int type,
00813 char *theString)
00814 {
00815 struct batchEntry *bptr;
00816
00817
00818
00819
00820
00821 bptr = get_struct(theEnv,batchEntry);
00822 bptr->batchType = type;
00823 bptr->inputSource = theSource;
00824 bptr->theString = theString;
00825 bptr->next = NULL;
00826
00827
00828
00829
00830
00831 if (FileCommandData(theEnv)->TopOfBatchList == NULL)
00832 {
00833 FileCommandData(theEnv)->TopOfBatchList = bptr;
00834 FileCommandData(theEnv)->BottomOfBatchList = bptr;
00835 FileCommandData(theEnv)->BatchType = type;
00836 FileCommandData(theEnv)->BatchSource = theSource;
00837 FileCommandData(theEnv)->BatchCurrentPosition = 0;
00838 }
00839 else if (placeAtEnd == FALSE)
00840 {
00841 bptr->next = FileCommandData(theEnv)->TopOfBatchList;
00842 FileCommandData(theEnv)->TopOfBatchList = bptr;
00843 FileCommandData(theEnv)->BatchType = type;
00844 FileCommandData(theEnv)->BatchSource = theSource;
00845 FileCommandData(theEnv)->BatchCurrentPosition = 0;
00846 }
00847 else
00848 {
00849 FileCommandData(theEnv)->BottomOfBatchList->next = bptr;
00850 FileCommandData(theEnv)->BottomOfBatchList = bptr;
00851 }
00852 }
00853
00854
00855
00856
00857 globle int RemoveBatch(
00858 void *theEnv)
00859 {
00860 struct batchEntry *bptr;
00861 int rv;
00862
00863 if (FileCommandData(theEnv)->TopOfBatchList == NULL) return(FALSE);
00864
00865
00866
00867
00868
00869 if (FileCommandData(theEnv)->TopOfBatchList->batchType == FILE_BATCH)
00870 { GenClose(theEnv,(FILE *) FileCommandData(theEnv)->TopOfBatchList->inputSource); }
00871 else
00872 {
00873 CloseStringSource(theEnv,(char *) FileCommandData(theEnv)->TopOfBatchList->inputSource);
00874 rm(theEnv,FileCommandData(theEnv)->TopOfBatchList->theString,strlen(FileCommandData(theEnv)->TopOfBatchList->theString) + 1);
00875 }
00876
00877
00878
00879
00880
00881 bptr = FileCommandData(theEnv)->TopOfBatchList;
00882 FileCommandData(theEnv)->TopOfBatchList = FileCommandData(theEnv)->TopOfBatchList->next;
00883
00884 rtn_struct(theEnv,batchEntry,bptr);
00885
00886
00887
00888
00889
00890
00891 if (FileCommandData(theEnv)->TopOfBatchList == NULL)
00892 {
00893 FileCommandData(theEnv)->BottomOfBatchList = NULL;
00894 FileCommandData(theEnv)->BatchSource = NULL;
00895 if (FileCommandData(theEnv)->BatchBuffer != NULL)
00896 {
00897 rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition);
00898 FileCommandData(theEnv)->BatchBuffer = NULL;
00899 }
00900 FileCommandData(theEnv)->BatchCurrentPosition = 0;
00901 FileCommandData(theEnv)->BatchMaximumPosition = 0;
00902 rv = 0;
00903 }
00904
00905
00906
00907
00908
00909 else
00910 {
00911 FileCommandData(theEnv)->BatchType = FileCommandData(theEnv)->TopOfBatchList->batchType;
00912 FileCommandData(theEnv)->BatchSource = FileCommandData(theEnv)->TopOfBatchList->inputSource;
00913 FileCommandData(theEnv)->BatchCurrentPosition = 0;
00914 rv = 1;
00915 }
00916
00917
00918
00919
00920
00921
00922 return(rv);
00923 }
00924
00925
00926
00927
00928
00929 globle intBool BatchActive(
00930 void *theEnv)
00931 {
00932 if (FileCommandData(theEnv)->TopOfBatchList != NULL) return(TRUE);
00933
00934 return(FALSE);
00935 }
00936
00937
00938
00939
00940 globle void CloseAllBatchSources(
00941 void *theEnv)
00942 {
00943
00944
00945
00946
00947 if (FileCommandData(theEnv)->BatchBuffer != NULL)
00948 {
00949 if (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer);
00950 rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition);
00951 FileCommandData(theEnv)->BatchBuffer = NULL;
00952 FileCommandData(theEnv)->BatchCurrentPosition = 0;
00953 FileCommandData(theEnv)->BatchMaximumPosition = 0;
00954 }
00955
00956
00957
00958
00959
00960 EnvDeleteRouter(theEnv,"batch");
00961
00962
00963
00964
00965
00966 while (RemoveBatch(theEnv))
00967 { }
00968 }
00969
00970
00971
00972
00973
00974 globle int BatchStarCommand(
00975 void *theEnv)
00976 {
00977 char *fileName;
00978
00979 if (EnvArgCountCheck(theEnv,"batch*",EXACTLY,1) == -1) return(FALSE);
00980 if ((fileName = GetFileName(theEnv,"batch*",1)) == NULL) return(FALSE);
00981
00982 return(EnvBatchStar(theEnv,fileName));
00983 }
00984
00985 #if ! RUN_TIME
00986
00987
00988
00989
00990 globle int EnvBatchStar(
00991 void *theEnv,
00992 char *fileName)
00993 {
00994 int inchar;
00995 FILE *theFile;
00996 char *theString = NULL;
00997 size_t position = 0;
00998 size_t maxChars = 0;
00999
01000
01001
01002
01003
01004 theFile = GenOpen(theEnv,fileName,"r");
01005
01006 if (theFile == NULL)
01007 {
01008 OpenErrorMessage(theEnv,"batch",fileName);
01009 return(FALSE);
01010 }
01011
01012
01013
01014
01015
01016 SetHaltExecution(theEnv,FALSE);
01017 SetEvaluationError(theEnv,FALSE);
01018
01019
01020
01021
01022
01023 while ((inchar = getc(theFile)) != EOF)
01024 {
01025 theString = ExpandStringWithChar(theEnv,inchar,theString,&position,
01026 &maxChars,maxChars+80);
01027
01028 if (CompleteCommand(theString) != 0)
01029 {
01030 FlushPPBuffer(theEnv);
01031 SetPPBufferStatus(theEnv,OFF);
01032 RouteCommand(theEnv,theString,FALSE);
01033 FlushPPBuffer(theEnv);
01034 SetHaltExecution(theEnv,FALSE);
01035 SetEvaluationError(theEnv,FALSE);
01036 FlushBindList(theEnv);
01037 genfree(theEnv,theString,(unsigned) maxChars);
01038 theString = NULL;
01039 maxChars = 0;
01040 position = 0;
01041 }
01042 }
01043
01044 if (theString != NULL)
01045 { genfree(theEnv,theString,(unsigned) maxChars); }
01046
01047
01048
01049
01050
01051 GenClose(theEnv,theFile);
01052 return(TRUE);
01053 }
01054
01055 #else
01056
01057
01058
01059
01060
01061 globle int EnvBatchStar(
01062 void *theEnv,
01063 char *fileName)
01064 {
01065 #if (MAC_MCW || WIN_MCW) && RUN_TIME
01066 #pragma unused(fileName)
01067 #endif
01068
01069 PrintErrorID(theEnv,"FILECOM",1,FALSE);
01070 EnvPrintRouter(theEnv,WERROR,"Function batch* does not work in run time modules.\n");
01071 return(FALSE);
01072 }
01073
01074 #endif
01075
01076
01077
01078
01079 globle int LoadCommand(
01080 void *theEnv)
01081 {
01082 #if (! BLOAD_ONLY) && (! RUN_TIME)
01083 char *theFileName;
01084 int rv;
01085
01086 if (EnvArgCountCheck(theEnv,"load",EXACTLY,1) == -1) return(FALSE);
01087 if ((theFileName = GetFileName(theEnv,"load",1)) == NULL) return(FALSE);
01088
01089 SetPrintWhileLoading(theEnv,TRUE);
01090
01091 if ((rv = EnvLoad(theEnv,theFileName)) == FALSE)
01092 {
01093 SetPrintWhileLoading(theEnv,FALSE);
01094 OpenErrorMessage(theEnv,"load",theFileName);
01095 return(FALSE);
01096 }
01097
01098 SetPrintWhileLoading(theEnv,FALSE);
01099 if (rv == -1) return(FALSE);
01100 return(TRUE);
01101 #else
01102 EnvPrintRouter(theEnv,WDIALOG,"Load is not available in this environment\n");
01103 return(FALSE);
01104 #endif
01105 }
01106
01107
01108
01109
01110 globle int LoadStarCommand(
01111 void *theEnv)
01112 {
01113 #if (! BLOAD_ONLY) && (! RUN_TIME)
01114 char *theFileName;
01115 int rv;
01116
01117 if (EnvArgCountCheck(theEnv,"load*",EXACTLY,1) == -1) return(FALSE);
01118 if ((theFileName = GetFileName(theEnv,"load*",1)) == NULL) return(FALSE);
01119
01120 if ((rv = EnvLoad(theEnv,theFileName)) == FALSE)
01121 {
01122 OpenErrorMessage(theEnv,"load*",theFileName);
01123 return(FALSE);
01124 }
01125
01126 if (rv == -1) return(FALSE);
01127 return(TRUE);
01128 #else
01129 EnvPrintRouter(theEnv,WDIALOG,"Load* is not available in this environment\n");
01130 return(FALSE);
01131 #endif
01132 }
01133
01134 #if DEBUGGING_FUNCTIONS
01135
01136
01137
01138 globle int SaveCommand(
01139 void *theEnv)
01140 {
01141 #if (! BLOAD_ONLY) && (! RUN_TIME)
01142 char *theFileName;
01143
01144 if (EnvArgCountCheck(theEnv,"save",EXACTLY,1) == -1) return(FALSE);
01145 if ((theFileName = GetFileName(theEnv,"save",1)) == NULL) return(FALSE);
01146
01147 if (EnvSave(theEnv,theFileName) == FALSE)
01148 {
01149 OpenErrorMessage(theEnv,"save",theFileName);
01150 return(FALSE);
01151 }
01152
01153 return(TRUE);
01154 #else
01155 EnvPrintRouter(theEnv,WDIALOG,"Save is not available in this environment\n");
01156 return(FALSE);
01157 #endif
01158 }
01159 #endif
01160
01161
01162