globle int LoadCommand( void *theEnv) { #if (! BLOAD_ONLY) && (! RUN_TIME) char *theFileName; int rv; if (EnvArgCountCheck(theEnv,"load",EXACTLY,1) == -1) return(FALSE); if ((theFileName = GetFileName(theEnv,"load",1)) == NULL) return(FALSE); SetPrintWhileLoading(theEnv,TRUE); if ((rv = EnvLoad(theEnv,theFileName)) == FALSE) { SetPrintWhileLoading(theEnv,FALSE); OpenErrorMessage(theEnv,"load",theFileName); return(FALSE); } SetPrintWhileLoading(theEnv,FALSE); if (rv == -1) return(FALSE); return(TRUE); #else EnvPrintRouter(theEnv,WDIALOG,"Load is not available in this environment\n"); return(FALSE); #endif }
globle FILE *NewCFile( char *fileName, int id, int version, int reopenOldFile) { char fname[FSIZE]; FILE *newFP; sprintf(fname,"%s%d_%d.c",fileName,id,version); newFP = fopen(fname,reopenOldFile ? "a" : "w"); if (newFP == NULL) { OpenErrorMessage("constructs-to-c",fname); return(NULL); } if (reopenOldFile == FALSE) { fprintf(newFP,"#include \"%s.h\"\n",fileName); fprintf(newFP,"\n"); } return(newFP); }
globle intBool EnvDribbleOn( void *theEnv, char *fileName) { /*==============================*/ /* If a dribble file is already */ /* open, then close it. */ /*==============================*/ if (FileCommandData(theEnv)->DribbleFP != NULL) { EnvDribbleOff(theEnv); } /*========================*/ /* Open the dribble file. */ /*========================*/ FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,(char*)"w"); if (FileCommandData(theEnv)->DribbleFP == NULL) { OpenErrorMessage(theEnv,(char*)"dribble-on",fileName); return(0); } /*============================*/ /* Create the dribble router. */ /*============================*/ EnvAddRouter(theEnv,(char*)"dribble", 40, FindDribble, PrintDribble, GetcDribble, UngetcDribble, ExitDribble); FileCommandData(theEnv)->DribbleCurrentPosition = 0; /*================================================*/ /* Call the dribble status function. This is used */ /* by some of the machine specific interfaces to */ /* do things such as changing the wording of menu */ /* items from "Turn Dribble On..." to */ /* "Turn Dribble Off..." */ /*================================================*/ if (FileCommandData(theEnv)->DribbleStatusFunction != NULL) { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,TRUE); } /*=====================================*/ /* Return TRUE to indicate the dribble */ /* file was successfully opened. */ /*=====================================*/ return(TRUE); }
globle int GenOpenReadBinary( void *theEnv, char *funcName, char *fileName) { if (SystemDependentData(theEnv)->BeforeOpenFunction != NULL) { (*SystemDependentData(theEnv)->BeforeOpenFunction)(theEnv); } #if WIN_BTC || WIN_MVC #if WIN_MVC SystemDependentData(theEnv)->BinaryFileHandle = _open(fileName,O_RDONLY | O_BINARY); #else SystemDependentData(theEnv)->BinaryFileHandle = open(fileName,O_RDONLY | O_BINARY); #endif if (SystemDependentData(theEnv)->BinaryFileHandle == -1) { if (SystemDependentData(theEnv)->AfterOpenFunction != NULL) { (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); } OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif #if (! WIN_BTC) && (! WIN_MVC) if ((SystemDependentData(theEnv)->BinaryFP = fopen(fileName,"rb")) == NULL) { if (SystemDependentData(theEnv)->AfterOpenFunction != NULL) { (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); } OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif if (SystemDependentData(theEnv)->AfterOpenFunction != NULL) { (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); } return(TRUE); }
bool DribbleOn( Environment *theEnv, const char *fileName) { /*==============================*/ /* If a dribble file is already */ /* open, then close it. */ /*==============================*/ if (FileCommandData(theEnv)->DribbleFP != NULL) { DribbleOff(theEnv); } /*========================*/ /* Open the dribble file. */ /*========================*/ FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,"w"); if (FileCommandData(theEnv)->DribbleFP == NULL) { OpenErrorMessage(theEnv,"dribble-on",fileName); return false; } /*============================*/ /* Create the dribble router. */ /*============================*/ AddRouter(theEnv,"dribble",40, QueryDribbleCallback,WriteDribbleCallback, ReadDribbleCallback,UnreadDribbleCallback, ExitDribbleCallback,NULL); FileCommandData(theEnv)->DribbleCurrentPosition = 0; /*================================================*/ /* Call the dribble status function. This is used */ /* by some of the machine specific interfaces to */ /* do things such as changing the wording of menu */ /* items from "Turn Dribble On..." to */ /* "Turn Dribble Off..." */ /*================================================*/ if (FileCommandData(theEnv)->DribbleStatusFunction != NULL) { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,true); } /*=====================================*/ /* Return true to indicate the dribble */ /* file was successfully opened. */ /*=====================================*/ return true; }
globle intBool EnvLoadFacts( void *theEnv, char *fileName) { FILE *filePtr; struct token theToken; struct expr *testPtr; DATA_OBJECT rv; /*======================================================*/ /* Open the file. Use either "fast save" or I/O Router. */ /*======================================================*/ if ((filePtr = GenOpen(theEnv,fileName,(char*)"r")) == NULL) { OpenErrorMessage(theEnv,(char*)"load-facts",fileName); return(FALSE); } SetFastLoad(theEnv,filePtr); /*=================*/ /* Load the facts. */ /*=================*/ theToken.type = LPAREN; while (theToken.type != STOP) { testPtr = StandardLoadFact(theEnv,(char *) filePtr,&theToken); if (testPtr == NULL) theToken.type = STOP; else EvaluateExpression(theEnv,testPtr,&rv); ReturnExpression(theEnv,testPtr); } /*=================*/ /* Close the file. */ /*=================*/ SetFastLoad(theEnv,NULL); GenClose(theEnv,filePtr); /*================================================*/ /* Return TRUE if no error occurred while loading */ /* the facts, otherwise return FALSE. */ /*================================================*/ if (EvaluationData(theEnv)->EvaluationError) return(FALSE); return(TRUE); }
/* --------------------------------------------------------------------------- * writes PCB to file */ static int WritePCBFile (char *Filename) { FILE *fp; int result; if ((fp = fopen (Filename, "w")) == NULL) { OpenErrorMessage (Filename); return (STATUS_ERROR); } result = WritePCB (fp); fclose (fp); return (result); }
globle int OpenBatch( void *theEnv, char *fileName, int placeAtEnd) { FILE *theFile; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return(FALSE); } /*============================*/ /* Create the batch router if */ /* it doesn't already exist. */ /*============================*/ if (FileCommandData(theEnv)->TopOfBatchList == NULL) { EnvAddRouter(theEnv,"batch", 20, FindBatch, NULL, GetcBatch, UngetcBatch, ExitBatch); } /*====================================*/ /* Add the newly opened batch file to */ /* the list of batch files opened. */ /*====================================*/ AddBatch(theEnv,placeAtEnd,(void *) theFile,FILE_BATCH,NULL); /*===================================*/ /* Return TRUE to indicate the batch */ /* file was successfully opened. */ /*===================================*/ return(TRUE); }
/* --------------------------------------------------------------------------- * opens a file and check if it exists */ FILE * CheckAndOpenFile (char *Filename, bool Confirm, bool AllButton, bool * WasAllButton, bool * WasCancelButton) { FILE *fp = NULL; struct stat buffer; char message[MAXPATHLEN + 80]; int response; if (Filename && *Filename) { if (!stat (Filename, &buffer) && Confirm) { sprintf (message, _("File '%s' exists, use anyway?"), Filename); if (WasAllButton) *WasAllButton = false; if (WasCancelButton) *WasCancelButton = false; if (AllButton) response = gui->confirm_dialog (message, "Cancel", "Ok", AllButton ? "Sequence OK" : 0); else response = gui->confirm_dialog (message, "Cancel", "Ok", "Sequence OK"); switch (response) { case 2: if (WasAllButton) *WasAllButton = true; break; case 0: if (WasCancelButton) *WasCancelButton = true; } } if ((fp = fopen (Filename, "w")) == NULL) OpenErrorMessage (Filename); } return (fp); }
globle int SaveCommand( void *theEnv) { #if (! BLOAD_ONLY) && (! RUN_TIME) char *theFileName; if (EnvArgCountCheck(theEnv,"save",EXACTLY,1) == -1) return(FALSE); if ((theFileName = GetFileName(theEnv,"save",1)) == NULL) return(FALSE); if (EnvSave(theEnv,theFileName) == FALSE) { OpenErrorMessage(theEnv,"save",theFileName); return(FALSE); } return(TRUE); #else EnvPrintRouter(theEnv,WDIALOG,"Save is not available in this environment\n"); return(FALSE); #endif }
globle int GenOpenReadBinary( void *theEnv, char *funcName, char *fileName) { #if MAC Str255 tempName; OSErr resultCode; Str255 volName; short int vRefNum; long vDirNum; FSSpec theFSSpec; resultCode = HGetVol(volName,&vRefNum,&vDirNum); if (resultCode != noErr) { OpenErrorMessage(theEnv,funcName,fileName); return(0); } strcpy((char *) tempName,fileName); CopyCStringToPascal((char *) tempName,tempName); resultCode = FSMakeFSSpec(vRefNum,vDirNum,tempName,&theFSSpec); if (resultCode != noErr) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } resultCode = FSpOpenDF(&theFSSpec,fsCurPerm,&SystemDependentData(theEnv)->BinaryRefNum); if (resultCode != noErr) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif #if IBM_TBC || IBM_MSC || IBM_ICB SystemDependentData(theEnv)->BinaryFileHandle = open(fileName,O_RDONLY | O_BINARY); if (SystemDependentData(theEnv)->BinaryFileHandle == -1) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif #if (! MAC) && (! IBM_TBC) && (! IBM_MSC) && (! IBM_ICB) if ((SystemDependentData(theEnv)->BinaryFP = fopen(fileName,"rb")) == NULL) { OpenErrorMessage(theEnv,funcName,fileName); return(FALSE); } #endif return(TRUE); }
bool BatchStar( Environment *theEnv, const char *fileName) { int inchar; bool done = false; FILE *theFile; char *theString = NULL; size_t position = 0; size_t maxChars = 0; #if (! RUN_TIME) && (! BLOAD_ONLY) char *oldParsingFileName; long oldLineCountValue; #endif /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return false; } /*======================================*/ /* Setup for capturing errors/warnings. */ /*======================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) oldParsingFileName = CopyString(theEnv,GetParsingFileName(theEnv)); SetParsingFileName(theEnv,fileName); CreateErrorCaptureRouter(theEnv); oldLineCountValue = SetLineCount(theEnv,1); #endif /*=====================================*/ /* If embedded, clear the error flags. */ /*=====================================*/ if (EvaluationData(theEnv)->CurrentExpression == NULL) { ResetErrorFlags(theEnv); } /*=============================================*/ /* Evaluate commands from the file one by one. */ /*=============================================*/ while (! done) { inchar = getc(theFile); if (inchar == EOF) { inchar = '\n'; done = true; } theString = ExpandStringWithChar(theEnv,inchar,theString,&position, &maxChars,maxChars+80); if (CompleteCommand(theString) != 0) { FlushPPBuffer(theEnv); SetPPBufferStatus(theEnv,false); RouteCommand(theEnv,theString,false); FlushPPBuffer(theEnv); SetHaltExecution(theEnv,false); SetEvaluationError(theEnv,false); FlushBindList(theEnv,NULL); genfree(theEnv,theString,maxChars); theString = NULL; maxChars = 0; position = 0; #if (! RUN_TIME) && (! BLOAD_ONLY) FlushParsingMessages(theEnv); #endif } if ((inchar == '\r') || (inchar == '\n')) { IncrementLineCount(theEnv); } } if (theString != NULL) { genfree(theEnv,theString,maxChars); } /*=======================*/ /* Close the batch file. */ /*=======================*/ GenClose(theEnv,theFile); /*========================================*/ /* Cleanup for capturing errors/warnings. */ /*========================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) FlushParsingMessages(theEnv); DeleteErrorCaptureRouter(theEnv); SetLineCount(theEnv,oldLineCountValue); SetParsingFileName(theEnv,oldParsingFileName); DeleteString(theEnv,oldParsingFileName); #endif return true; }
bool OpenBatch( Environment *theEnv, const char *fileName, bool placeAtEnd) { FILE *theFile; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return false; } /*============================*/ /* Create the batch router if */ /* it doesn't already exist. */ /*============================*/ if (FileCommandData(theEnv)->TopOfBatchList == NULL) { AddRouter(theEnv,"batch",20,QueryBatchCallback,NULL, ReadBatchCallback,UnreadBatchCallback, ExitBatchCallback,NULL); } /*===============================================================*/ /* If a batch file is already open, save its current line count. */ /*===============================================================*/ if (FileCommandData(theEnv)->TopOfBatchList != NULL) { FileCommandData(theEnv)->TopOfBatchList->lineNumber = GetLineCount(theEnv); } #if (! RUN_TIME) && (! BLOAD_ONLY) /*========================================================================*/ /* If this is the first batch file, remember the prior parsing file name. */ /*========================================================================*/ if (FileCommandData(theEnv)->TopOfBatchList == NULL) { FileCommandData(theEnv)->batchPriorParsingFile = CopyString(theEnv,GetParsingFileName(theEnv)); } /*=======================================================*/ /* Create the error capture router if it does not exist. */ /*=======================================================*/ SetParsingFileName(theEnv,fileName); SetLineCount(theEnv,0); CreateErrorCaptureRouter(theEnv); #endif /*====================================*/ /* Add the newly opened batch file to */ /* the list of batch files opened. */ /*====================================*/ AddBatch(theEnv,placeAtEnd,theFile,NULL,FILE_BATCH,NULL,fileName); /*===================================*/ /* Return true to indicate the batch */ /* file was successfully opened. */ /*===================================*/ return true; }
globle intBool EnvBsave( void *theEnv, EXEC_STATUS, char *fileName) { FILE *fp; struct BinaryItem *biPtr; char constructBuffer[CONSTRUCT_HEADER_SIZE]; long saveExpressionCount; /*===================================*/ /* A bsave can't occur when a binary */ /* image is already loaded. */ /*===================================*/ if (Bloaded(theEnv,execStatus)) { PrintErrorID(theEnv,execStatus,"BSAVE",1,FALSE); EnvPrintRouter(theEnv,execStatus,WERROR, "Cannot perform a binary save while a binary load is in effect.\n"); return(0); } /*================*/ /* Open the file. */ /*================*/ if ((fp = GenOpen(theEnv,execStatus,fileName,"wb")) == NULL) { OpenErrorMessage(theEnv,execStatus,"bsave",fileName); return(0); } /*==============================*/ /* Remember the current module. */ /*==============================*/ SaveCurrentModule(theEnv,execStatus); /*==================================*/ /* Write binary header to the file. */ /*==================================*/ WriteBinaryHeader(theEnv,execStatus,fp); /*===========================================*/ /* Initialize count variables, index values, */ /* and determine some of the data structures */ /* which need to be saved. */ /*===========================================*/ ExpressionData(theEnv,execStatus)->ExpressionCount = 0; InitializeFunctionNeededFlags(theEnv,execStatus); InitAtomicValueNeededFlags(theEnv,execStatus); FindHashedExpressions(theEnv,execStatus); FindNeededItems(theEnv,execStatus); SetAtomicValueIndices(theEnv,execStatus,FALSE); /*===============================*/ /* Save the functions and atoms. */ /*===============================*/ WriteNeededFunctions(theEnv,execStatus,fp); WriteNeededAtomicValues(theEnv,execStatus,fp); /*=========================================*/ /* Write out the number of expression data */ /* structures in the binary image. */ /*=========================================*/ GenWrite((void *) &ExpressionData(theEnv,execStatus)->ExpressionCount,(unsigned long) sizeof(unsigned long),fp); /*===========================================*/ /* Save the numbers indicating the amount of */ /* memory needed to bload the constructs. */ /*===========================================*/ for (biPtr = BsaveData(theEnv,execStatus)->ListOfBinaryItems; biPtr != NULL; biPtr = biPtr->next) { if (biPtr->bsaveStorageFunction != NULL) { genstrncpy(constructBuffer,biPtr->name,CONSTRUCT_HEADER_SIZE); GenWrite(constructBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE,fp); (*biPtr->bsaveStorageFunction)(theEnv,execStatus,fp); } } /*====================================*/ /* Write a binary footer to the file. */ /*====================================*/ WriteBinaryFooter(theEnv,execStatus,fp); /*===================*/ /* Save expressions. */ /*===================*/ ExpressionData(theEnv,execStatus)->ExpressionCount = 0; BsaveHashedExpressions(theEnv,execStatus,fp); saveExpressionCount = ExpressionData(theEnv,execStatus)->ExpressionCount; BsaveConstructExpressions(theEnv,execStatus,fp); ExpressionData(theEnv,execStatus)->ExpressionCount = saveExpressionCount; /*===================*/ /* Save constraints. */ /*===================*/ WriteNeededConstraints(theEnv,execStatus,fp); /*==================*/ /* Save constructs. */ /*==================*/ for (biPtr = BsaveData(theEnv,execStatus)->ListOfBinaryItems; biPtr != NULL; biPtr = biPtr->next) { if (biPtr->bsaveFunction != NULL) { genstrncpy(constructBuffer,biPtr->name,CONSTRUCT_HEADER_SIZE); GenWrite(constructBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE,fp); (*biPtr->bsaveFunction)(theEnv,execStatus,fp); } } /*===================================*/ /* Save a binary footer to the file. */ /*===================================*/ WriteBinaryFooter(theEnv,execStatus,fp); /*===========*/ /* Clean up. */ /*===========*/ RestoreAtomicValueBuckets(theEnv,execStatus); /*=================*/ /* Close the file. */ /*=================*/ GenClose(theEnv,execStatus,fp); /*=============================*/ /* Restore the current module. */ /*=============================*/ RestoreCurrentModule(theEnv,execStatus); /*========================================*/ /* Return TRUE to indicate success. */ /*========================================*/ return(TRUE); }
globle intBool EnvSaveFacts( void *theEnv, char *fileName, int saveCode, struct expr *theList) { int tempValue1, tempValue2, tempValue3; struct fact *theFact; FILE *filePtr; struct defmodule *theModule; DATA_OBJECT_PTR theDOArray; int count, i, printFact, error; /*======================================================*/ /* Open the file. Use either "fast save" or I/O Router. */ /*======================================================*/ if ((filePtr = GenOpen(theEnv,fileName,(char*)"w")) == NULL) { OpenErrorMessage(theEnv,(char*)"save-facts",fileName); return(FALSE); } SetFastSave(theEnv,filePtr); /*===========================================*/ /* Set the print flags so that addresses and */ /* strings are printed properly to the file. */ /*===========================================*/ tempValue1 = PrintUtilityData(theEnv)->PreserveEscapedCharacters; PrintUtilityData(theEnv)->PreserveEscapedCharacters = TRUE; tempValue2 = PrintUtilityData(theEnv)->AddressesToStrings; PrintUtilityData(theEnv)->AddressesToStrings = TRUE; tempValue3 = PrintUtilityData(theEnv)->InstanceAddressesToNames; PrintUtilityData(theEnv)->InstanceAddressesToNames = TRUE; /*===================================================*/ /* Determine the list of specific facts to be saved. */ /*===================================================*/ theDOArray = GetSaveFactsDeftemplateNames(theEnv,theList,saveCode,&count,&error); if (error) { PrintUtilityData(theEnv)->PreserveEscapedCharacters = tempValue1; PrintUtilityData(theEnv)->AddressesToStrings = tempValue2; PrintUtilityData(theEnv)->InstanceAddressesToNames = tempValue3; GenClose(theEnv,filePtr); SetFastSave(theEnv,NULL); return(FALSE); } /*=================*/ /* Save the facts. */ /*=================*/ theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); for (theFact = (struct fact *) GetNextFactInScope(theEnv,NULL); theFact != NULL; theFact = (struct fact *) GetNextFactInScope(theEnv,theFact)) { /*===========================================================*/ /* If we're doing a local save and the facts's corresponding */ /* deftemplate isn't in the current module, then don't save */ /* the fact. */ /*===========================================================*/ if ((saveCode == LOCAL_SAVE) && (theFact->whichDeftemplate->header.whichModule->theModule != theModule)) { printFact = FALSE; } /*=====================================================*/ /* Otherwise, if the list of facts to be printed isn't */ /* restricted, then set the print flag to TRUE. */ /*=====================================================*/ else if (theList == NULL) { printFact = TRUE; } /*=======================================================*/ /* Otherwise see if the fact's corresponding deftemplate */ /* is in the list of deftemplates whose facts are to be */ /* saved. If it's in the list, then set the print flag */ /* to TRUE, otherwise set it to FALSE. */ /*=======================================================*/ else { printFact = FALSE; for (i = 0; i < count; i++) { if (theDOArray[i].value == (void *) theFact->whichDeftemplate) { printFact = TRUE; break; } } } /*===================================*/ /* If the print flag is set to TRUE, */ /* then save the fact to the file. */ /*===================================*/ if (printFact) { PrintFact(theEnv,(char *) filePtr,theFact,FALSE,FALSE); EnvPrintRouter(theEnv,(char *) filePtr,(char*)"\n"); } } /*==========================*/ /* Restore the print flags. */ /*==========================*/ PrintUtilityData(theEnv)->PreserveEscapedCharacters = tempValue1; PrintUtilityData(theEnv)->AddressesToStrings = tempValue2; PrintUtilityData(theEnv)->InstanceAddressesToNames = tempValue3; /*=================*/ /* Close the file. */ /*=================*/ GenClose(theEnv,filePtr); SetFastSave(theEnv,NULL); /*==================================*/ /* Free the deftemplate name array. */ /*==================================*/ if (theList != NULL) rm3(theEnv,theDOArray,(long) sizeof(DATA_OBJECT) * count); /*===================================*/ /* Return TRUE to indicate no errors */ /* occurred while saving the facts. */ /*===================================*/ return(TRUE); }
static int ConstructsToC( char *fileName, int theImageID, int max) { char fname[FSIZE]; int fileVersion; struct CodeGeneratorItem *cgPtr; /*===============================================*/ /* Set the global MaxIndices variable indicating */ /* the maximum number of data structures to save */ /* in each file. */ /*===============================================*/ MaxIndices = max; /*==================================*/ /* Call the list of functions to be */ /* executed before generating code. */ /*==================================*/ for (cgPtr = ListOfCodeGeneratorItems; cgPtr != NULL; cgPtr = cgPtr->next) { if (cgPtr->beforeFunction != NULL) (*cgPtr->beforeFunction)(); } /*=================================================*/ /* Do a periodic cleanup without using heuristics */ /* to get rid of as much garbage as possible so */ /* that it isn't written out as C data structures. */ /*=================================================*/ PeriodicCleanup(FALSE,FALSE); /*=====================================*/ /* Initialize some global information. */ /*=====================================*/ FilePrefix = fileName; ImageID = theImageID; ExpressionFP = NULL; ExpressionVersion = 1; ExpressionHeader = TRUE; ExpressionCount = 0; /*=====================================================*/ /* Open a header file for dumping general information. */ /*=====================================================*/ sprintf(fname,"%s.h",fileName); if ((HeaderFP = fopen(fname,"w")) == NULL) { OpenErrorMessage("constructs-to-c",fname); return(0); } fprintf(HeaderFP,"#ifndef _CONSTRUCT_COMPILER_HEADER_\n"); fprintf(HeaderFP,"#define _CONSTRUCT_COMPILER_HEADER_\n\n"); fprintf(HeaderFP,"#include <stdio.h>\n"); fprintf(HeaderFP,"#include \"setup.h\"\n"); fprintf(HeaderFP,"#include \"expressn.h\"\n"); fprintf(HeaderFP,"#include \"extnfunc.h\"\n"); fprintf(HeaderFP,"#include \"%s\"\n",API_HEADER); fprintf(HeaderFP,"\n#define VS (void *)\n"); fprintf(HeaderFP,"\n"); /*=========================================================*/ /* Give extern declarations for user and system functions. */ /*=========================================================*/ WriteFunctionExternDeclarations(HeaderFP); fprintf(HeaderFP,"\n#endif\n\n"); fprintf(HeaderFP,"/****************************/\n"); fprintf(HeaderFP,"/* EXTERN ARRAY DEFINITIONS */\n"); fprintf(HeaderFP,"/****************************/\n\n"); /*==================================*/ /* Generate code for atomic values, */ /* function definitions, hashed */ /* expressions, and constructs. */ /*==================================*/ AtomicValuesToCode(fileName); FunctionsToCode(fileName); HashedExpressionsToCode(); ConstraintsToCode(fileName,4,HeaderFP,ImageID,MaxIndices); /*===============================*/ /* Call each code generator item */ /* for the various constructs. */ /*===============================*/ fileVersion = 5; for (cgPtr = ListOfCodeGeneratorItems; cgPtr != NULL; cgPtr = cgPtr->next) { if (cgPtr->generateFunction != NULL) { (*cgPtr->generateFunction)(fileName,fileVersion,HeaderFP,ImageID,MaxIndices); fileVersion++; } } /*=========================================*/ /* Restore the atomic data bucket values */ /* (which were set to an index reference). */ /*=========================================*/ RestoreAtomicValueBuckets(); /*============================*/ /* Close the expression file. */ /*============================*/ if (ExpressionFP != NULL) { fprintf(ExpressionFP,"};\n"); fclose(ExpressionFP); } /*====================================*/ /* Write the initialization function. */ /*====================================*/ WriteInitializationFunction(fileName); /*========================*/ /* Close the header file. */ /*========================*/ fclose(HeaderFP); /*==================================================*/ /* Return TRUE to indicate that the constructs-to-c */ /* command was successfully executed. */ /*==================================================*/ return(TRUE); }
globle int EnvBatchStar( void *theEnv, char *fileName) { int inchar; FILE *theFile; char *theString = NULL; size_t position = 0; size_t maxChars = 0; /*======================*/ /* Open the batch file. */ /*======================*/ theFile = GenOpen(theEnv,fileName,"r"); if (theFile == NULL) { OpenErrorMessage(theEnv,"batch",fileName); return(FALSE); } /*========================*/ /* Reset the error state. */ /*========================*/ SetHaltExecution(theEnv,FALSE); SetEvaluationError(theEnv,FALSE); /*=============================================*/ /* Evaluate commands from the file one by one. */ /*=============================================*/ while ((inchar = getc(theFile)) != EOF) { theString = ExpandStringWithChar(theEnv,inchar,theString,&position, &maxChars,maxChars+80); if (CompleteCommand(theString) != 0) { FlushPPBuffer(theEnv); SetPPBufferStatus(theEnv,OFF); RouteCommand(theEnv,theString,FALSE); FlushPPBuffer(theEnv); SetHaltExecution(theEnv,FALSE); SetEvaluationError(theEnv,FALSE); FlushBindList(theEnv); genfree(theEnv,theString,(unsigned) maxChars); theString = NULL; maxChars = 0; position = 0; } } if (theString != NULL) { genfree(theEnv,theString,(unsigned) maxChars); } /*=======================*/ /* Close the batch file. */ /*=======================*/ GenClose(theEnv,theFile); return(TRUE); }
static int WriteInitializationFunction( char *fileName) { char fname[FSIZE]; FILE *fp; struct CodeGeneratorItem *cgPtr; /*===============================*/ /* Open the initialization file. */ /*===============================*/ sprintf(fname,"%s.c",fileName); if ((fp = fopen(fname,"w")) == NULL) { OpenErrorMessage("constructs-to-c",fname); return(FALSE); } /*=====================================*/ /* Write out #includes and prototypes. */ /*=====================================*/ fprintf(fp,"#include \"%s.h\"\n",fileName); fprintf(fp,"\n"); fprintf(fp,"#include \"utility.h\"\n"); fprintf(fp,"#include \"generate.h\"\n"); fprintf(fp,"#include \"expressn.h\"\n"); fprintf(fp,"#include \"extnfunc.h\"\n"); fprintf(fp,"#include \"objrtmch.h\"\n"); fprintf(fp,"#include \"rulebld.h\"\n\n"); fprintf(HeaderFP," void InitCImage_%d(void);\n",ImageID); /*============================================*/ /* Begin writing the initialization function. */ /*============================================*/ fprintf(fp,"\n"); fprintf(fp,"/*******************************************/\n"); fprintf(fp,"/* CONSTRUCT IMAGE INITIALIZATION FUNCTION */\n"); fprintf(fp,"/*******************************************/\n"); fprintf(fp,"\nVOID InitCImage_%d()\n",ImageID); fprintf(fp," {\n"); fprintf(fp," Clear();\n"); fprintf(fp," PeriodicCleanup(TRUE,FALSE);\n"); fprintf(fp," SetSymbolTable(sht%d);\n",ImageID); fprintf(fp," SetFloatTable(fht%d);\n",ImageID); fprintf(fp," SetIntegerTable(iht%d);\n",ImageID); fprintf(fp," SetBitMapTable(bmht%d);\n",ImageID); fprintf(fp," RefreshSpecialSymbols();\n"); fprintf(fp," InstallFunctionList(P%d_1);\n\n",ImageID); fprintf(fp," InitExpressionPointers();\n\n"); /*==========================================*/ /* Write construct specific initialization. */ /*==========================================*/ cgPtr = ListOfCodeGeneratorItems; while (cgPtr != NULL) { if (cgPtr->initFunction != NULL) { (*cgPtr->initFunction)(fp,ImageID,MaxIndices); fprintf(fp,"\n"); } cgPtr = cgPtr->next; } /*================================*/ /* Close the initialization file. */ /*================================*/ fprintf(fp," }\n"); fclose(fp); /*========================================*/ /* Return TRUE to indicate initialization */ /* file was successfully written. */ /*========================================*/ return(TRUE); }