static void DeallocateFileCommandData( void *theEnv) { struct batchEntry *theEntry, *nextEntry; theEntry = FileCommandData(theEnv)->TopOfBatchList; while (theEntry != NULL) { nextEntry = theEntry->next; if (theEntry->batchType == FILE_BATCH) { GenClose(theEnv,(FILE *) FileCommandData(theEnv)->TopOfBatchList->inputSource); } else { rm(theEnv,theEntry->theString,strlen(theEntry->theString) + 1); } rtn_struct(theEnv,batchEntry,theEntry); theEntry = nextEntry; } if (FileCommandData(theEnv)->BatchBuffer != NULL) { rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); } #if DEBUGGING_FUNCTIONS if (FileCommandData(theEnv)->DribbleBuffer != NULL) { rm(theEnv,FileCommandData(theEnv)->DribbleBuffer,FileCommandData(theEnv)->DribbleMaximumPosition); } if (FileCommandData(theEnv)->DribbleFP != NULL) { GenClose(theEnv,FileCommandData(theEnv)->DribbleFP); } #endif }
globle int CloseFile( void *theEnv, char *fid) { struct fileRouter *fptr, *prev; for (fptr = FileRouterData(theEnv)->ListOfFileRouters, prev = NULL; fptr != NULL; fptr = fptr->next) { if (strcmp(fptr->logicalName,fid) == 0) { GenClose(theEnv,fptr->stream); rm(theEnv,fptr->logicalName,strlen(fptr->logicalName) + 1); if (prev == NULL) { FileRouterData(theEnv)->ListOfFileRouters = fptr->next; } else { prev->next = fptr->next; } rm(theEnv,fptr,(int) sizeof(struct fileRouter)); return(TRUE); } prev = fptr; } return(FALSE); }
globle intBool EnvDribbleOff( void *theEnv) { int rv = 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,FALSE); } /*=======================================*/ /* Close the dribble file and deactivate */ /* the dribble router. */ /*=======================================*/ if (FileCommandData(theEnv)->DribbleFP != NULL) { if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); } EnvDeleteRouter(theEnv,(char*)"dribble"); if (GenClose(theEnv,FileCommandData(theEnv)->DribbleFP) == 0) rv = 1; } else { rv = 1; } FileCommandData(theEnv)->DribbleFP = NULL; /*============================================*/ /* Free the space used by the dribble buffer. */ /*============================================*/ if (FileCommandData(theEnv)->DribbleBuffer != NULL) { rm(theEnv,FileCommandData(theEnv)->DribbleBuffer,FileCommandData(theEnv)->DribbleMaximumPosition); FileCommandData(theEnv)->DribbleBuffer = NULL; } FileCommandData(theEnv)->DribbleCurrentPosition = 0; FileCommandData(theEnv)->DribbleMaximumPosition = 0; /*============================================*/ /* Return TRUE if the dribble file was closed */ /* without error, otherwise return FALSE. */ /*============================================*/ return(rv); }
globle int EnvSave( void *theEnv, EXEC_STATUS, char *fileName) { struct callFunctionItem *saveFunction; FILE *filePtr; void *defmodulePtr; /*=====================*/ /* Open the save file. */ /*=====================*/ if ((filePtr = GenOpen(theEnv,execStatus,fileName,"w")) == NULL) { return(FALSE); } /*===========================*/ /* Bypass the router system. */ /*===========================*/ SetFastSave(theEnv,execStatus,filePtr); /*======================*/ /* Save the constructs. */ /*======================*/ for (defmodulePtr = EnvGetNextDefmodule(theEnv,execStatus,NULL); defmodulePtr != NULL; defmodulePtr = EnvGetNextDefmodule(theEnv,execStatus,defmodulePtr)) { for (saveFunction = ConstructData(theEnv,execStatus)->ListOfSaveFunctions; saveFunction != NULL; saveFunction = saveFunction->next) { ((* (void (*)(void *,EXEC_STATUS,void *,char *)) saveFunction->func))(theEnv,execStatus,defmodulePtr,(char *) filePtr); } } /*======================*/ /* Close the save file. */ /*======================*/ GenClose(theEnv,execStatus,filePtr); /*===========================*/ /* Remove the router bypass. */ /*===========================*/ SetFastSave(theEnv,execStatus,NULL); /*=========================*/ /* Return TRUE to indicate */ /* successful completion. */ /*=========================*/ return(TRUE); }
static int ExitDribble( void *theEnv, int num) { if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); } if (FileCommandData(theEnv)->DribbleFP != NULL) GenClose(theEnv,FileCommandData(theEnv)->DribbleFP); return(1); }
static int ExitDribble( void *theEnv, int num) { #if MAC_XCD #pragma unused(num) #endif if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); } if (FileCommandData(theEnv)->DribbleFP != NULL) GenClose(theEnv,FileCommandData(theEnv)->DribbleFP); return(1); }
static void ExitDribbleCallback( Environment *theEnv, int num, void *context) { #if MAC_XCD #pragma unused(num) #endif if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) { fprintf(FileCommandData(theEnv)->DribbleFP,"%s",FileCommandData(theEnv)->DribbleBuffer); } if (FileCommandData(theEnv)->DribbleFP != NULL) GenClose(theEnv,FileCommandData(theEnv)->DribbleFP); }
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); }
static void DeallocateFileRouterData( void *theEnv) { struct fileRouter *tmpPtr, *nextPtr; tmpPtr = FileRouterData(theEnv)->ListOfFileRouters; while (tmpPtr != NULL) { nextPtr = tmpPtr->next; GenClose(theEnv,tmpPtr->stream); rm(theEnv,tmpPtr->logicalName,strlen(tmpPtr->logicalName) + 1); rtn_struct(theEnv,fileRouter,tmpPtr); tmpPtr = nextPtr; } }
globle int CloseAllFiles( void *theEnv) { struct fileRouter *fptr, *prev; if (FileRouterData(theEnv)->ListOfFileRouters == NULL) return(FALSE); fptr = FileRouterData(theEnv)->ListOfFileRouters; while (fptr != NULL) { GenClose(theEnv,fptr->stream); prev = fptr; rm(theEnv,fptr->logicalName,strlen(fptr->logicalName) + 1); fptr = fptr->next; rm(theEnv,prev,(int) sizeof(struct fileRouter)); } FileRouterData(theEnv)->ListOfFileRouters = NULL; return(TRUE); }
globle int EnvLoad( void *theEnv, char *fileName) { FILE *theFile; int noErrorsDetected; /*=======================================*/ /* Open the file specified by file name. */ /*=======================================*/ if ((theFile = GenOpen(theEnv,fileName,"r")) == NULL) return(0); /*===================================================*/ /* Read in the constructs. Enabling fast load allows */ /* the router system to be bypassed for quicker load */ /* times. */ /*===================================================*/ SetFastLoad(theEnv,theFile); noErrorsDetected = LoadConstructsFromLogicalName(theEnv,(char *) theFile); SetFastLoad(theEnv,NULL); /*=================*/ /* Close the file. */ /*=================*/ GenClose(theEnv,theFile); /*========================================*/ /* If no errors occurred during the load, */ /* return 1, otherwise return -1. */ /*========================================*/ if (noErrorsDetected) return(1); return(-1); }
static int ConstructToCode( void *theEnv, char *fileName, char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices) { struct defmodule *theConstruct; FILE *moduleFile = NULL, *itemsFile; int portItemCount = 0; struct portItem *portItemPtr; int mihCount = 0, moduleCount = 0; int j; struct moduleItem *theItem; int moduleArrayVersion = 1; int fileCount = 2; /*================================================*/ /* Include the appropriate defmodule header file. */ /*================================================*/ fprintf(headerFP,"#include \"moduldef.h\"\n"); /*============================================*/ /* Open up the items file for the defmodules. */ /* Only one file of this type is created so */ /* the maximum number of indices is ignored. */ /*============================================*/ if ((itemsFile = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,1,FALSE)) == NULL) { return(FALSE); } fprintf(itemsFile,"struct defmoduleItemHeader *%s%d_%d[] = {\n",ItemPrefix(),imageID,1); fprintf(headerFP,"extern struct defmoduleItemHeader *%s%d_%d[];\n",ItemPrefix(),imageID,1); /*======================================================*/ /* Loop through all the defmodules writing their C code */ /* representation to the file as they are traversed. */ /*======================================================*/ for (theConstruct = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theConstruct != NULL; theConstruct = (struct defmodule *) EnvGetNextDefmodule(theEnv,theConstruct)) { /*===========================================*/ /* Open a new file to write to if necessary. */ /*===========================================*/ moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID, &fileCount,moduleArrayVersion,headerFP, "struct defmodule",DefmodulePrefix(), FALSE,NULL); if (moduleFile == NULL) { moduleCount = maxIndices; CloseFileIfNeeded(theEnv,moduleFile,&moduleCount, &moduleArrayVersion,maxIndices,NULL,NULL); GenClose(theEnv,itemsFile); return(FALSE); } /*======================================*/ /* Write the construct name and ppform. */ /*======================================*/ fprintf(moduleFile,"{"); PrintSymbolReference(theEnv,moduleFile,theConstruct->name); fprintf(moduleFile,",NULL,"); /*=====================================================*/ /* Write the items array pointers to other constructs. */ /*=====================================================*/ fprintf(moduleFile,"&%s%d_1[%d],",ItemPrefix(),imageID,mihCount); for (j = 0, theItem = GetListOfModuleItems(theEnv); (j < GetNumberOfModuleItems(theEnv)) && (theItem != NULL) ; j++, theItem = theItem->next) { mihCount++; if (theItem->constructsToCModuleReference == NULL) { fprintf(itemsFile,"NULL"); } else { (*theItem->constructsToCModuleReference)(theEnv,itemsFile,(int) theConstruct->bsaveID,imageID,maxIndices); } if ((j + 1) < GetNumberOfModuleItems(theEnv)) fprintf(itemsFile,","); else if (theConstruct->next != NULL) fprintf(itemsFile,",\n"); } /*=================================*/ /* Write the importList reference. */ /*=================================*/ if (theConstruct->importList == NULL) { fprintf(moduleFile,"NULL,"); } else { fprintf(moduleFile,"&%s%d_%d[%d],",PortPrefix(),imageID, (portItemCount / maxIndices) + 1, portItemCount % maxIndices); for (portItemPtr = theConstruct->importList; portItemPtr != NULL; portItemPtr = portItemPtr->next) { portItemCount++; } } /*=================================*/ /* Write the exportList reference. */ /*=================================*/ if (theConstruct->exportList == NULL) { fprintf(moduleFile,"NULL,"); } else { fprintf(moduleFile,"&%s%d_%d[%d],",PortPrefix(),imageID, (portItemCount / maxIndices) + 1, portItemCount % maxIndices); for (portItemPtr = theConstruct->exportList; portItemPtr != NULL; portItemPtr = portItemPtr->next) { portItemCount++; } } /*=====================*/ /* Write the bsave id. */ /*=====================*/ fprintf(moduleFile,"0,%ld,",theConstruct->bsaveID); /*======================*/ /* Write the user data. */ /*======================*/ fprintf(moduleFile,"NULL,"); /*===========================*/ /* Write the next reference. */ /*===========================*/ if (theConstruct->next == NULL) { fprintf(moduleFile,"NULL}"); } else { fprintf(moduleFile,"&%s%d_%d[%d]}",ConstructPrefix(DefmoduleData(theEnv)->DefmoduleCodeItem),imageID, (int) (theConstruct->next->bsaveID / maxIndices) + 1, (int) theConstruct->next->bsaveID % maxIndices); } /*===================================================*/ /* Increment the number of defmodule data structures */ /* written and close the output file if necessary. */ /*===================================================*/ moduleCount++; moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleCount,&moduleArrayVersion, maxIndices,NULL,NULL); } /*=========================*/ /* Close the output files. */ /*=========================*/ moduleCount = maxIndices; CloseFileIfNeeded(theEnv,moduleFile,&moduleCount, &moduleArrayVersion,maxIndices,NULL,NULL); fprintf(itemsFile,"};\n"); GenClose(theEnv,itemsFile); /*=========================================*/ /* Write out the portItem data structures. */ /*=========================================*/ if (portItemCount == 0) return(TRUE); return(PortItemsToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,&fileCount)); }
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); }
bool Save( Environment *theEnv, const char *fileName) { struct saveCallFunctionItem *saveFunction; FILE *filePtr; Defmodule *defmodulePtr; bool updated = false; bool unvisited = true; /*=====================================*/ /* If embedded, clear the error flags. */ /*=====================================*/ if (EvaluationData(theEnv)->CurrentExpression == NULL) { ResetErrorFlags(theEnv); } /*=====================*/ /* Open the save file. */ /*=====================*/ if ((filePtr = GenOpen(theEnv,fileName,"w")) == NULL) { return false; } /*===========================*/ /* Bypass the router system. */ /*===========================*/ SetFastSave(theEnv,filePtr); /*================================*/ /* Mark all modules as unvisited. */ /*================================*/ MarkModulesAsUnvisited(theEnv); /*===============================================*/ /* Save the constructs. Repeatedly loop over the */ /* modules until each module has been save. */ /*===============================================*/ while (unvisited) { unvisited = false; updated = false; for (defmodulePtr = GetNextDefmodule(theEnv,NULL); defmodulePtr != NULL; defmodulePtr = GetNextDefmodule(theEnv,defmodulePtr)) { /*=================================================================*/ /* We only want to save a module if all of the modules it imports */ /* from have already been saved. Since there can't be circular */ /* dependencies in imported modules, this should save the modules */ /* that don't import anything first and then work back from those. */ /*=================================================================*/ if (defmodulePtr->visitedFlag) { /* Module has already been saved. */ } else if (AllImportedModulesVisited(theEnv,defmodulePtr)) { for (saveFunction = ConstructData(theEnv)->ListOfSaveFunctions; saveFunction != NULL; saveFunction = saveFunction->next) { (*saveFunction->func)(theEnv,defmodulePtr,(char *) filePtr,saveFunction->context); } updated = true; defmodulePtr->visitedFlag = true; } else { unvisited = true; } } /*=====================================================================*/ /* At least one module should be saved in every pass. If all have been */ /* visited/saved, then both flags will be false. If all remaining */ /* unvisited/unsaved modules were visited/saved, then unvisited will */ /* be false and updated will be true. If some, but not all, remaining */ /* unvisited/unsaved modules are visited/saved, then unvisited will */ /* be true and updated will be true. This leaves the case where there */ /* are remaining unvisited/unsaved modules, but none were */ /* visited/saved: unvisited is true and updated is false. */ /*=====================================================================*/ if (unvisited && (! updated)) { SystemError(theEnv,"CONSTRCT",2); break; } } /*======================*/ /* Close the save file. */ /*======================*/ GenClose(theEnv,filePtr); /*===========================*/ /* Remove the router bypass. */ /*===========================*/ SetFastSave(theEnv,NULL); /*=========================*/ /* Return true to indicate */ /* successful completion. */ /*=========================*/ return true; }
static int BitMapValuesToCode( void *theEnv, EXEC_STATUS, char *fileName, char *pathName, char *fileNameBuffer, int version) { int i, j, k; unsigned l; struct bitMapHashNode *hashPtr; int count; int numberOfEntries; struct bitMapHashNode **bitMapTable; int newHeader = TRUE; int arrayVersion = 1; FILE *fp; unsigned long tmpLong; int longsReqd; /*====================================*/ /* Count the total number of entries. */ /*====================================*/ bitMapTable = GetBitMapTable(theEnv,execStatus); count = numberOfEntries = 0; for (i = 0; i < BITMAP_HASH_SIZE; i++) { for (hashPtr = bitMapTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { numberOfEntries += (int) (hashPtr->size / sizeof(unsigned long)); if ((hashPtr->size % sizeof(unsigned long)) != 0) { numberOfEntries++; } } } if (numberOfEntries == 0) return(version); for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv,execStatus)->MaxIndices) + 1 ; i++) { fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern unsigned long L%d_%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(-1); /*===================*/ /* List the entries. */ /*===================*/ j = 0; for (i = 0; i < BITMAP_HASH_SIZE; i++) { for (hashPtr = bitMapTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { if (newHeader) { fprintf(fp,"unsigned long L%d_%d[] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion); newHeader = FALSE; } longsReqd = (int) (hashPtr->size / sizeof(unsigned long)); if ((hashPtr->size % sizeof(unsigned long)) != 0) longsReqd++; for (k = 0 ; k < longsReqd ; k++) { if (k > 0) fprintf(fp,","); tmpLong = 0L; for (l = 0 ; ((l < sizeof(unsigned long)) && (((k * sizeof(unsigned long)) + l) < (size_t) hashPtr->size)) ; l++) ((char *) &tmpLong)[l] = hashPtr->contents[(k * sizeof(unsigned long)) + l]; fprintf(fp,"0x%lxL",tmpLong); } count += longsReqd; j += longsReqd; if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv,execStatus)->MaxIndices)) { fprintf(fp,"};\n"); GenClose(theEnv,execStatus,fp); j = 0; arrayVersion++; version++; if (count < numberOfEntries) { if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else { fprintf(fp,",\n"); } } } return(version); }
globle int ConstraintsToCode( void *theEnv, char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices) { int i, j, count; int newHeader = TRUE; FILE *fp; int version = 1; int arrayVersion = 1; unsigned short numberOfConstraints = 0; CONSTRAINT_RECORD *tmpPtr; /*===============================================*/ /* Count the total number of constraint records. */ /*===============================================*/ for (i = 0 ; i < SIZE_CONSTRAINT_HASH; i++) { for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i]; tmpPtr != NULL; tmpPtr = tmpPtr->next) { tmpPtr->bsaveIndex = numberOfConstraints++; } } /*=====================================================*/ /* If dynamic constraint checking is disabled, then */ /* contraints won't be saved. If there are constraints */ /* which could be saved, then issue a warning message. */ /*=====================================================*/ if ((! EnvGetDynamicConstraintChecking(theEnv)) && (numberOfConstraints != 0)) { numberOfConstraints = 0; PrintWarningID(theEnv,"CSTRNCMP",1,FALSE); EnvPrintRouter(theEnv,WWARNING,"Constraints are not saved with a constructs-to-c image\n"); EnvPrintRouter(theEnv,WWARNING," when dynamic constraint checking is disabled.\n"); } if (numberOfConstraints == 0) return(-1); /*=================================================*/ /* Print the extern definition in the header file. */ /*=================================================*/ for (i = 1; i <= (numberOfConstraints / maxIndices) + 1 ; i++) { fprintf(headerFP,"extern CONSTRAINT_RECORD C%d_%d[];\n",imageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(-1); /*===================*/ /* List the entries. */ /*===================*/ j = 0; count = 0; for (i = 0; i < SIZE_CONSTRAINT_HASH; i++) { for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i]; tmpPtr != NULL; tmpPtr = tmpPtr->next) { if (newHeader) { fprintf(fp,"CONSTRAINT_RECORD C%d_%d[] = {\n",imageID,arrayVersion); newHeader = FALSE; } fprintf(fp,"{%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", tmpPtr->anyAllowed, tmpPtr->symbolsAllowed, tmpPtr->stringsAllowed, tmpPtr->floatsAllowed, tmpPtr->integersAllowed, tmpPtr->instanceNamesAllowed, tmpPtr->instanceAddressesAllowed, tmpPtr->externalAddressesAllowed, tmpPtr->factAddressesAllowed, 0, /* void allowed */ tmpPtr->anyRestriction, tmpPtr->symbolRestriction, tmpPtr->stringRestriction, tmpPtr->floatRestriction, tmpPtr->integerRestriction, tmpPtr->instanceNameRestriction, tmpPtr->multifieldsAllowed, tmpPtr->singlefieldsAllowed); fprintf(fp,",0,"); /* bsaveIndex */ PrintHashedExpressionReference(theEnv,fp,tmpPtr->restrictionList,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->minValue,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxValue,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->minFields,imageID,maxIndices); fprintf(fp,","); PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxFields,imageID,maxIndices); /* multifield slot */ fprintf(fp,",NULL"); /* next slot */ if (tmpPtr->next == NULL) { fprintf(fp,",NULL,"); } else { if ((j + 1) >= maxIndices) { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion + 1,0); } else { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion,j + 1); } } fprintf(fp,"%d,%d",tmpPtr->bucket,tmpPtr->count + 1); count++; j++; if ((count == numberOfConstraints) || (j >= maxIndices)) { fprintf(fp,"}};\n"); GenClose(fp); j = 0; version++; arrayVersion++; if (count < numberOfConstraints) { if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else { fprintf(fp,"},\n"); } } } return(version); }
static int SymbolHashNodesToCode( void *theEnv, EXEC_STATUS, char *fileName, char *pathName, char *fileNameBuffer, int version) { unsigned long i, j; struct symbolHashNode *hashPtr; int count; int numberOfEntries; struct symbolHashNode **symbolTable; int newHeader = TRUE; int arrayVersion = 1; FILE *fp; /*====================================*/ /* Count the total number of entries. */ /*====================================*/ symbolTable = GetSymbolTable(theEnv,execStatus); count = numberOfEntries = 0; for (i = 0; i < SYMBOL_HASH_SIZE; i++) { for (hashPtr = symbolTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { numberOfEntries++; } } if (numberOfEntries == 0) return(version); for (i = 1; i <= (unsigned long) (numberOfEntries / ConstructCompilerData(theEnv,execStatus)->MaxIndices) + 1 ; i++) { fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct symbolHashNode S%d_%ld[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(-1); /*===================*/ /* List the entries. */ /*===================*/ j = 0; for (i = 0; i < SYMBOL_HASH_SIZE; i++) { for (hashPtr = symbolTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { if (newHeader) { fprintf(fp,"struct symbolHashNode S%d_%d[] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion); newHeader = FALSE; } if (hashPtr->next == NULL) { fprintf(fp,"{NULL,"); } else { if ((j + 1) >= (unsigned long) ConstructCompilerData(theEnv,execStatus)->MaxIndices) { fprintf(fp,"{&S%d_%d[%d],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion + 1,0); } else { fprintf(fp,"{&S%d_%d[%ld],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion,j + 1); } } fprintf(fp,"%ld,0,1,0,0,%ld,",hashPtr->count + 1,i); PrintCString(fp,hashPtr->contents); count++; j++; if ((count == numberOfEntries) || (j >= (unsigned) ConstructCompilerData(theEnv,execStatus)->MaxIndices)) { fprintf(fp,"}};\n"); GenClose(theEnv,execStatus,fp); j = 0; arrayVersion++; version++; if (count < numberOfEntries) { if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else { fprintf(fp,"},\n"); } } } return(version); }
static int IntegerHashNodesToCode( void *theEnv, const char *fileName, const char *pathName, char *fileNameBuffer, int version) { int i, j; struct integerHashNode *hashPtr; int count; int numberOfEntries; struct integerHashNode **integerTable; bool newHeader = true; FILE *fp; int arrayVersion = 1; /*====================================*/ /* Count the total number of entries. */ /*====================================*/ integerTable = GetIntegerTable(theEnv); count = numberOfEntries = 0; for (i = 0; i < INTEGER_HASH_SIZE; i++) { for (hashPtr = integerTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { numberOfEntries++; } } if (numberOfEntries == 0) return(version); for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++) { fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct integerHashNode I%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,1,version,false)) == NULL) return(-1); /*===================*/ /* List the entries. */ /*===================*/ j = 0; for (i = 0; i < INTEGER_HASH_SIZE; i++) { for (hashPtr = integerTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { if (newHeader) { fprintf(fp,"struct integerHashNode I%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion); newHeader = false; } if (hashPtr->next == NULL) { fprintf(fp,"{NULL,"); } else { if ((j + 1) >= ConstructCompilerData(theEnv)->MaxIndices) { fprintf(fp,"{&I%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion + 1,0); } else { fprintf(fp,"{&I%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion,j + 1); } } fprintf(fp,"%ld,1,0,0,%d,",hashPtr->count + 1,i); fprintf(fp,"%lldLL",hashPtr->contents); count++; j++; if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv)->MaxIndices)) { fprintf(fp,"}};\n"); GenClose(theEnv,fp); j = 0; version++; arrayVersion++; if (count < numberOfEntries) { if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,1,version,false)) == NULL) return(0); newHeader = true; } } else { fprintf(fp,"},\n"); } } } return(version); }
/*********************************************************** NAME : AlphaPatternNodesToCode DESCRIPTION : Writes out data structures for run-time creation of object pattern alpha memories INPUTS : 1) The base image output file name 2) The base image file id 3) A pointer to the header output file 4) The id of constructs-to-c image 5) The maximum number of indices allowed in any single array in the image RETURNS : Next version file to open, 0 if error SIDE EFFECTS : Object patterns code written to files NOTES : None ***********************************************************/ static int AlphaPatternNodesToCode( void *theEnv, char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices, int version) { FILE *fp; int arrayVersion; int newHeader; int i; OBJECT_ALPHA_NODE *thePattern; /* ================ Create the file. ================ */ if (ObjectNetworkTerminalPointer(theEnv) == NULL) return(version); /* ================================= Dump the pattern node structures. ================================= */ if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; arrayVersion = 1; i = 1; thePattern = ObjectNetworkTerminalPointer(theEnv); while (thePattern != NULL) { if (newHeader) { fprintf(fp,"OBJECT_ALPHA_NODE %s%d_%d[] = {\n", ObjectANPrefix(),imageID,arrayVersion); fprintf(headerFP,"extern OBJECT_ALPHA_NODE %s%d_%d[];\n", ObjectANPrefix(),imageID,arrayVersion); newHeader = FALSE; } fprintf(fp,"{"); PatternNodeHeaderToCode(theEnv,fp,&thePattern->header,imageID,maxIndices); fprintf(fp,",0L,"); PrintBitMapReference(theEnv,fp,thePattern->classbmp); fprintf(fp,","); PrintBitMapReference(theEnv,fp,thePattern->slotbmp); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->patternNode,fp,imageID,maxIndices); fprintf(fp,","); ObjectPatternNodeReference(theEnv,thePattern->nxtInGroup,fp,imageID,maxIndices); fprintf(fp,","); ObjectPatternNodeReference(theEnv,thePattern->nxtTerminal,fp,imageID,maxIndices); fprintf(fp,",0L}"); i++; thePattern = thePattern->nxtTerminal; if ((i > maxIndices) || (thePattern == NULL)) { fprintf(fp,"};\n"); GenClose(fp); i = 1; version++; arrayVersion++; if (thePattern != NULL) { if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else if (thePattern != NULL) { fprintf(fp,",\n"); } } return(version); }
/************************************************************* NAME : IntermediatePatternNodesToCode DESCRIPTION : Writes out data structures for run-time creation of object pattern intermediate nodes INPUTS : 1) The base image output file name 2) The base image file id 3) A pointer to the header output file 4) The id of constructs-to-c image 5) The maximum number of indices allowed in any single array in the image RETURNS : Next version file to open, 0 if error SIDE EFFECTS : Object patterns code written to files NOTES : None *************************************************************/ static int IntermediatePatternNodesToCode( void *theEnv, char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices, int version) { FILE *fp; int arrayVersion; int newHeader; int i; OBJECT_PATTERN_NODE *thePattern; /* ================ Create the file. ================ */ if (ObjectNetworkPointer(theEnv) == NULL) return(1); fprintf(headerFP,"#include \"objrtmch.h\"\n"); /* ================================= Dump the pattern node structures. ================================= */ if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; arrayVersion = 1; i = 1; thePattern = ObjectNetworkPointer(theEnv); while (thePattern != NULL) { if (newHeader) { fprintf(fp,"OBJECT_PATTERN_NODE %s%d_%d[] = {\n", ObjectPNPrefix(),imageID,arrayVersion); fprintf(headerFP,"extern OBJECT_PATTERN_NODE %s%d_%d[];\n", ObjectPNPrefix(),imageID,arrayVersion); newHeader = FALSE; } fprintf(fp,"{0,%u,%u,%u,%u,0L,%u,",thePattern->multifieldNode, thePattern->endSlot, thePattern->whichField, thePattern->leaveFields, thePattern->slotNameID); PrintHashedExpressionReference(theEnv,fp,thePattern->networkTest,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->nextLevel,fp,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->lastLevel,fp,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->leftNode,fp,imageID,maxIndices); fprintf(fp,","); IntermediatePatternNodeReference(theEnv,thePattern->rightNode,fp,imageID,maxIndices); fprintf(fp,","); ObjectPatternNodeReference(theEnv,(void *) thePattern->alphaNode,fp,imageID,maxIndices); fprintf(fp,",0L}"); i++; thePattern = GetNextObjectPatternNode(thePattern); if ((i > maxIndices) || (thePattern == NULL)) { fprintf(fp,"};\n"); GenClose(fp); i = 1; version++; arrayVersion++; if (thePattern != NULL) { if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else if (thePattern != NULL) { fprintf(fp,",\n"); } } return(version); }
bool RemoveBatch( Environment *theEnv) { struct batchEntry *bptr; bool rv, fileBatch = false; if (FileCommandData(theEnv)->TopOfBatchList == NULL) return false; /*==================================================*/ /* Close the source from which batch input is read. */ /*==================================================*/ if (FileCommandData(theEnv)->TopOfBatchList->batchType == FILE_BATCH) { fileBatch = true; GenClose(theEnv,FileCommandData(theEnv)->TopOfBatchList->fileSource); #if (! RUN_TIME) && (! BLOAD_ONLY) FlushParsingMessages(theEnv); DeleteErrorCaptureRouter(theEnv); #endif } else { CloseStringSource(theEnv,FileCommandData(theEnv)->TopOfBatchList->logicalSource); rm(theEnv,(void *) FileCommandData(theEnv)->TopOfBatchList->theString, strlen(FileCommandData(theEnv)->TopOfBatchList->theString) + 1); } /*=================================*/ /* Remove the entry from the list. */ /*=================================*/ DeleteString(theEnv,(char *) FileCommandData(theEnv)->TopOfBatchList->fileName); bptr = FileCommandData(theEnv)->TopOfBatchList; FileCommandData(theEnv)->TopOfBatchList = FileCommandData(theEnv)->TopOfBatchList->next; DeleteString(theEnv,(char *) bptr->logicalSource); rtn_struct(theEnv,batchEntry,bptr); /*========================================================*/ /* If there are no batch files remaining to be processed, */ /* then free the space used by the batch buffer. */ /*========================================================*/ if (FileCommandData(theEnv)->TopOfBatchList == NULL) { FileCommandData(theEnv)->BottomOfBatchList = NULL; FileCommandData(theEnv)->BatchFileSource = NULL; FileCommandData(theEnv)->BatchLogicalSource = NULL; if (FileCommandData(theEnv)->BatchBuffer != NULL) { rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); FileCommandData(theEnv)->BatchBuffer = NULL; } FileCommandData(theEnv)->BatchCurrentPosition = 0; FileCommandData(theEnv)->BatchMaximumPosition = 0; rv = false; #if (! RUN_TIME) && (! BLOAD_ONLY) if (fileBatch) { SetParsingFileName(theEnv,FileCommandData(theEnv)->batchPriorParsingFile); DeleteString(theEnv,FileCommandData(theEnv)->batchPriorParsingFile); FileCommandData(theEnv)->batchPriorParsingFile = NULL; } #endif } /*===========================================*/ /* Otherwise move on to the next batch file. */ /*===========================================*/ else { FileCommandData(theEnv)->BatchType = FileCommandData(theEnv)->TopOfBatchList->batchType; FileCommandData(theEnv)->BatchFileSource = FileCommandData(theEnv)->TopOfBatchList->fileSource; FileCommandData(theEnv)->BatchLogicalSource = FileCommandData(theEnv)->TopOfBatchList->logicalSource; FileCommandData(theEnv)->BatchCurrentPosition = 0; rv = true; #if (! RUN_TIME) && (! BLOAD_ONLY) if (FileCommandData(theEnv)->TopOfBatchList->batchType == FILE_BATCH) { SetParsingFileName(theEnv,FileCommandData(theEnv)->TopOfBatchList->fileName); } SetLineCount(theEnv,FileCommandData(theEnv)->TopOfBatchList->lineNumber); #endif } /*====================================================*/ /* Return true if a batch file if there are remaining */ /* batch files to be processed, otherwise false. */ /*====================================================*/ return(rv); }
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; }
globle int RemoveBatch( void *theEnv) { struct batchEntry *bptr; int rv; if (FileCommandData(theEnv)->TopOfBatchList == NULL) return(FALSE); /*==================================================*/ /* Close the source from which batch input is read. */ /*==================================================*/ if (FileCommandData(theEnv)->TopOfBatchList->batchType == FILE_BATCH) { GenClose(theEnv,(FILE *) FileCommandData(theEnv)->TopOfBatchList->inputSource); } else { CloseStringSource(theEnv,(char *) FileCommandData(theEnv)->TopOfBatchList->inputSource); rm(theEnv,FileCommandData(theEnv)->TopOfBatchList->theString,strlen(FileCommandData(theEnv)->TopOfBatchList->theString) + 1); } /*=================================*/ /* Remove the entry from the list. */ /*=================================*/ bptr = FileCommandData(theEnv)->TopOfBatchList; FileCommandData(theEnv)->TopOfBatchList = FileCommandData(theEnv)->TopOfBatchList->next; rtn_struct(theEnv,batchEntry,bptr); /*========================================================*/ /* If there are no batch files remaining to be processed, */ /* then free the space used by the batch buffer. */ /*========================================================*/ if (FileCommandData(theEnv)->TopOfBatchList == NULL) { FileCommandData(theEnv)->BottomOfBatchList = NULL; FileCommandData(theEnv)->BatchSource = NULL; if (FileCommandData(theEnv)->BatchBuffer != NULL) { rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition); FileCommandData(theEnv)->BatchBuffer = NULL; } FileCommandData(theEnv)->BatchCurrentPosition = 0; FileCommandData(theEnv)->BatchMaximumPosition = 0; rv = 0; } /*===========================================*/ /* Otherwise move on to the next batch file. */ /*===========================================*/ else { FileCommandData(theEnv)->BatchType = FileCommandData(theEnv)->TopOfBatchList->batchType; FileCommandData(theEnv)->BatchSource = FileCommandData(theEnv)->TopOfBatchList->inputSource; FileCommandData(theEnv)->BatchCurrentPosition = 0; rv = 1; } /*====================================================*/ /* Return TRUE if a batch file if there are remaining */ /* batch files to be processed, otherwise FALSE. */ /*====================================================*/ return(rv); }
static int BitMapHashNodesToCode( void *theEnv, EXEC_STATUS, char *fileName, char *pathName, char *fileNameBuffer, int version) { int i, j; struct bitMapHashNode *hashPtr; int count; int numberOfEntries; struct bitMapHashNode **bitMapTable; int newHeader = TRUE; int arrayVersion = 1; FILE *fp; int longsReqdPartition = 1,longsReqdPartitionCount = 0; /*====================================*/ /* Count the total number of entries. */ /*====================================*/ bitMapTable = GetBitMapTable(theEnv,execStatus); count = numberOfEntries = 0; for (i = 0; i < BITMAP_HASH_SIZE; i++) { for (hashPtr = bitMapTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { numberOfEntries++; } } if (numberOfEntries == 0) return(version); for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv,execStatus)->MaxIndices) + 1 ; i++) { fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct bitMapHashNode B%d_%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(-1); /*===================*/ /* List the entries. */ /*===================*/ j = 0; for (i = 0; i < BITMAP_HASH_SIZE; i++) { for (hashPtr = bitMapTable[i]; hashPtr != NULL; hashPtr = hashPtr->next) { if (newHeader) { fprintf(fp,"struct bitMapHashNode B%d_%d[] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion); newHeader = FALSE; } if (hashPtr->next == NULL) { fprintf(fp,"{NULL,"); } else { if ((j + 1) >= ConstructCompilerData(theEnv,execStatus)->MaxIndices) { fprintf(fp,"{&B%d_%d[%d],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion + 1,0); } else { fprintf(fp,"{&B%d_%d[%d],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion,j + 1); } } fprintf(fp,"%ld,0,1,0,0,%d,(char *) &L%d_%d[%d],%d", hashPtr->count + 1,i, ConstructCompilerData(theEnv,execStatus)->ImageID,longsReqdPartition,longsReqdPartitionCount, hashPtr->size); longsReqdPartitionCount += (int) (hashPtr->size / sizeof(unsigned long)); if ((hashPtr->size % sizeof(unsigned long)) != 0) longsReqdPartitionCount++; if (longsReqdPartitionCount >= ConstructCompilerData(theEnv,execStatus)->MaxIndices) { longsReqdPartitionCount = 0; longsReqdPartition++; } count++; j++; if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv,execStatus)->MaxIndices)) { fprintf(fp,"}};\n"); GenClose(theEnv,execStatus,fp); j = 0; arrayVersion++; version++; if (count < numberOfEntries) { if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else { fprintf(fp,"},\n"); } } } return(version); }
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 HashTablesToCode( void *theEnv, EXEC_STATUS, char *fileName, char *pathName, char *fileNameBuffer) { unsigned long i; FILE *fp; struct symbolHashNode **symbolTable; struct floatHashNode **floatTable; struct integerHashNode **integerTable; struct bitMapHashNode **bitMapTable; /*======================================*/ /* Write the code for the symbol table. */ /*======================================*/ symbolTable = GetSymbolTable(theEnv,execStatus); if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,1,FALSE)) == NULL) return(0); fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct symbolHashNode *sht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID); fprintf(fp,"struct symbolHashNode *sht%d[%ld] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,SYMBOL_HASH_SIZE); for (i = 0; i < SYMBOL_HASH_SIZE; i++) { PrintSymbolReference(theEnv,execStatus,fp,symbolTable[i]); if (i + 1 != SYMBOL_HASH_SIZE) fprintf(fp,",\n"); } fprintf(fp,"};\n"); GenClose(theEnv,execStatus,fp); /*=====================================*/ /* Write the code for the float table. */ /*=====================================*/ floatTable = GetFloatTable(theEnv,execStatus); if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,2,FALSE)) == NULL) return(0); fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct floatHashNode *fht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID); fprintf(fp,"struct floatHashNode *fht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,FLOAT_HASH_SIZE); for (i = 0; i < FLOAT_HASH_SIZE; i++) { if (floatTable[i] == NULL) { fprintf(fp,"NULL"); } else PrintFloatReference(theEnv,execStatus,fp,floatTable[i]); if (i + 1 != FLOAT_HASH_SIZE) fprintf(fp,",\n"); } fprintf(fp,"};\n"); GenClose(theEnv,execStatus,fp); /*=======================================*/ /* Write the code for the integer table. */ /*=======================================*/ integerTable = GetIntegerTable(theEnv,execStatus); if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,3,FALSE)) == NULL) return(0); fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct integerHashNode *iht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID); fprintf(fp,"struct integerHashNode *iht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,INTEGER_HASH_SIZE); for (i = 0; i < INTEGER_HASH_SIZE; i++) { if (integerTable[i] == NULL) { fprintf(fp,"NULL"); } else PrintIntegerReference(theEnv,execStatus,fp,integerTable[i]); if (i + 1 != INTEGER_HASH_SIZE) fprintf(fp,",\n"); } fprintf(fp,"};\n"); GenClose(theEnv,execStatus,fp); /*======================================*/ /* Write the code for the bitmap table. */ /*======================================*/ bitMapTable = GetBitMapTable(theEnv,execStatus); if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,4,FALSE)) == NULL) return(0); fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct bitMapHashNode *bmht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID); fprintf(fp,"struct bitMapHashNode *bmht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,BITMAP_HASH_SIZE); for (i = 0; i < BITMAP_HASH_SIZE; i++) { PrintBitMapReference(theEnv,execStatus,fp,bitMapTable[i]); if (i + 1 != BITMAP_HASH_SIZE) fprintf(fp,",\n"); } fprintf(fp,"};\n"); GenClose(theEnv,execStatus,fp); return(1); }
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 int EnvSave( void *theEnv, const char *fileName) { struct callFunctionItem *saveFunction; FILE *filePtr; struct defmodule *defmodulePtr; intBool updated = FALSE; intBool unvisited = TRUE; /*=====================*/ /* Open the save file. */ /*=====================*/ if ((filePtr = GenOpen(theEnv,fileName,"w")) == NULL) { return(FALSE); } /*===========================*/ /* Bypass the router system. */ /*===========================*/ SetFastSave(theEnv,filePtr); /*================================*/ /* Mark all modules as unvisited. */ /*================================*/ MarkModulesAsUnvisited(theEnv); /*===============================================*/ /* Save the constructs. Repeatedly loop over the */ /* modules until each module has been save. */ /*===============================================*/ while (unvisited) { unvisited = FALSE; updated = FALSE; for (defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); defmodulePtr != NULL; defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,defmodulePtr)) { /*=================================================================*/ /* We only want to save a module if all of the modules it imports */ /* from have already been saved. Since there can't be circular */ /* dependencies in imported modules, this should save the modules */ /* that don't import anything first and then work back from those. */ /*=================================================================*/ if (defmodulePtr->visitedFlag) { /* Module has already been saved. */ } else if (AllImportedModulesVisited(theEnv,defmodulePtr)) { for (saveFunction = ConstructData(theEnv)->ListOfSaveFunctions; saveFunction != NULL; saveFunction = saveFunction->next) { ((* (void (*)(void *,void *,char *)) saveFunction->func))(theEnv,defmodulePtr,(char *) filePtr); } updated = TRUE; defmodulePtr->visitedFlag = TRUE; } else { unvisited = TRUE; } } /*=====================================================================*/ /* At least one module should be saved in every pass. If all have been */ /* visited/saved, then both flags will be FALSE. If all remaining */ /* unvisited/unsaved modules were visited/saved, then unvisited will */ /* be FALSE and updated will be TRUE. If some, but not all, remaining */ /* unvisited/unsaved modules are visited/saved, then unvisited will */ /* be TRUE and updated will be TRUE. This leaves the case where there */ /* are remaining unvisited/unsaved modules, but none were */ /* visited/saved: unvisited is TRUE and updated is FALSE. */ /*=====================================================================*/ if (unvisited && (! updated)) { SystemError(theEnv,"CONSTRCT",2); break; } } /*======================*/ /* Close the save file. */ /*======================*/ GenClose(theEnv,filePtr); /*===========================*/ /* Remove the router bypass. */ /*===========================*/ SetFastSave(theEnv,NULL); /*=========================*/ /* Return TRUE to indicate */ /* successful completion. */ /*=========================*/ return(TRUE); }
/*********************************************************** NAME : ClassAlphaLinksToCode DESCRIPTION : Writes out data structures for run-time creation of class alpha link INPUTS : 1) The base image output file name 2) The base image file id 3) A pointer to the header output file 4) The id of constructs-to-c image 5) The maximum number of indices allowed in any single array in the image RETURNS : Next version file to open, 0 if error SIDE EFFECTS : Class alpha links code written to files NOTES : None ***********************************************************/ static int ClassAlphaLinksToCode( void *theEnv, const char *fileName, const char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices, int version) { FILE *fp; int arrayVersion; int newHeader; int i; struct defmodule *theModule = NULL; DEFCLASS *theDefclass = NULL; CLASS_ALPHA_LINK *theLink = NULL; /* ================================= Dump the alpha link structures. ================================= */ if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; arrayVersion = 1; i = 1; theLink = GetNextAlphaLink(theEnv,&theModule,&theDefclass,theLink); while (theLink != NULL) { if (newHeader) { fprintf(fp,"CLASS_ALPHA_LINK %s%d_%d[] = {\n", ObjectALPrefix(),imageID,arrayVersion); fprintf(headerFP,"extern CLASS_ALPHA_LINK %s%d_%d[];\n", ObjectALPrefix(),imageID,arrayVersion); newHeader = FALSE; } fprintf(fp,"{"); ObjectPatternNodeReference(theEnv,theLink->alphaNode,fp,imageID,maxIndices); fprintf(fp,","); ClassAlphaLinkReference(theEnv,theLink->next,fp,imageID,maxIndices); fprintf(fp,"}"); theLink = GetNextAlphaLink(theEnv,&theModule,&theDefclass,theLink); if ((i > maxIndices) || (theLink == NULL)) { fprintf(fp,"};\n"); GenClose(theEnv,fp); i = 1; version++; arrayVersion++; if (theLink != NULL) { if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else if (theLink != NULL) { fprintf(fp,",\n"); } } return(version); }