static int SymbolHashNodesToCode( char *fileName, int version) { int 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(); 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 <= (numberOfEntries / MaxIndices) + 1 ; i++) { fprintf(HeaderFP,"extern struct symbolHashNode S%d_%d[];\n",ImageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(fileName,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",ImageID,arrayVersion); newHeader = FALSE; } if (hashPtr->next == NULL) { fprintf(fp,"{NULL,"); } else { if ((j + 1) >= MaxIndices) { fprintf(fp,"{&S%d_%d[%d],",ImageID,arrayVersion + 1,0); } else { fprintf(fp,"{&S%d_%d[%d],",ImageID,arrayVersion,j + 1); } } fprintf(fp,"%ld,0,0,0,%d,",hashPtr->count + 1,i); PrintCString(fp,hashPtr->contents); count++; j++; if ((count == numberOfEntries) || (j >= MaxIndices)) { fprintf(fp,"}};\n"); fclose(fp); j = 0; arrayVersion++; version++; if (count < numberOfEntries) { if ((fp = NewCFile(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 FuzzyValuesToCode( char *fileName, int version) { int i, j; struct fuzzyValueHashNode *hashPtr; int count; int numberOfEntries; struct fuzzyValueHashNode **fuzzyValueTable; int newHeader = TRUE; int arrayVersion = 1; FILE *fp; int arraySize; int xyArrayPartition = 1, xyArrayPartitionCount = 0; /*====================================*/ /* Count the total number of entries. */ /*====================================*/ fuzzyValueTable = GetFuzzyValueTable(); count = numberOfEntries = 0; for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++) { hashPtr = fuzzyValueTable[i]; while (hashPtr != NULL) { numberOfEntries++; hashPtr = hashPtr->next; } } if (numberOfEntries == 0) return(version); for (i = 1; i <= (numberOfEntries / MaxIndices) + 1 ; i++) { fprintf(HeaderFP,"extern struct fuzzy_value W%d_%d[];\n",ImageID,i); } /*==================*/ /* Create the file. */ /*==================*/ if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(-1); /*=====================*/ /* Fillin the entries. */ /*=====================*/ j = 0; for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++) { hashPtr = fuzzyValueTable[i]; while (hashPtr != NULL) { if (newHeader) { fprintf(fp,"struct fuzzy_value W%d_%d[] = {\n",ImageID,arrayVersion); newHeader = FALSE; } /* fill in the entries of the fuzzy value struct: whichDeftemplate - ptr to deftemplate structure name - char * maxn - int n - int x - ptr to double (will be index into X array) y - ptr to double (will be index into X array) */ fprintf(fp,"{"); DeftemplateCConstructReference(fp, hashPtr->contents->whichDeftemplate, ImageID, MaxIndices); fprintf(fp,","); PrintCString(fp,hashPtr->contents->name); /* NOTE: arraySize twice in next fprintf line is correct! We don't want to store maxn value since we pack the arrays when writing X array out to c file */ arraySize = hashPtr->contents->n; fprintf(fp,",%d,%d", arraySize, arraySize); fprintf(fp,",(double *)&X%d_%d[%d], (double *)&X%d_%d[%d]", ImageID, xyArrayPartition, xyArrayPartitionCount, ImageID, xyArrayPartition, xyArrayPartitionCount+arraySize); xyArrayPartitionCount += arraySize + arraySize; if (xyArrayPartitionCount >= MaxIndices) { xyArrayPartitionCount = 0; xyArrayPartition++; } count++; j++; if ((count == numberOfEntries) || (j >= MaxIndices)) { fprintf(fp,"}};\n"); fclose(fp); j = 0; arrayVersion++; version++; if (count < numberOfEntries) { if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(0); newHeader = TRUE; } } else { fprintf(fp,"},\n"); } hashPtr = hashPtr->next; } } return(version); }