static void PatternNodeToCode( FILE *theFile, struct factPatternNode *thePatternNode, int imageID, int maxIndices) { fprintf(theFile,"{"); /*=====================*/ /* Pattern Node Header */ /*=====================*/ PatternNodeHeaderToCode(theFile,&thePatternNode->header,imageID,maxIndices); /*========================*/ /* Field and Slot Indices */ /*========================*/ fprintf(theFile,",0,%d,%d,%d,",thePatternNode->whichField, thePatternNode->whichSlot, thePatternNode->leaveFields); /*===============*/ /* Network Tests */ /*===============*/ PrintHashedExpressionReference(theFile,thePatternNode->networkTest,imageID,maxIndices); /*============*/ /* Next Level */ /*============*/ if (thePatternNode->nextLevel == NULL) { fprintf(theFile,",NULL,"); } else { fprintf(theFile,",&%s%d_%ld[%ld],",FactPrefix(), imageID,(thePatternNode->nextLevel->bsaveID / maxIndices) + 1, thePatternNode->nextLevel->bsaveID % maxIndices); } /*============*/ /* Last Level */ /*============*/ if (thePatternNode->lastLevel == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%ld[%ld],",FactPrefix(), imageID,(thePatternNode->lastLevel->bsaveID / maxIndices) + 1, thePatternNode->lastLevel->bsaveID % maxIndices); } /*===========*/ /* Left Node */ /*===========*/ if (thePatternNode->leftNode == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%ld[%ld],",FactPrefix(), imageID,(thePatternNode->leftNode->bsaveID / maxIndices) + 1, thePatternNode->leftNode->bsaveID % maxIndices); } /*============*/ /* Right Node */ /*============*/ if (thePatternNode->rightNode == NULL) { fprintf(theFile,"NULL}"); } else { fprintf(theFile,"&%s%d_%ld[%ld]}",FactPrefix(), imageID,(thePatternNode->rightNode->bsaveID / maxIndices) + 1, thePatternNode->rightNode->bsaveID % maxIndices); } }
/*********************************************************** 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); }