📄 modulcmp.c
字号:
{ 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 next reference. */ /*===========================*/ if (theConstruct->next == NULL) { fprintf(moduleFile,"NULL}"); } else { fprintf(moduleFile,"&%s%d_%d[%d]}",ConstructPrefix(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(moduleFile,&moduleCount,&moduleArrayVersion, maxIndices,NULL,NULL); } /*=========================*/ /* Close the output files. */ /*=========================*/ moduleCount = maxIndices; CloseFileIfNeeded(moduleFile,&moduleCount, &moduleArrayVersion,maxIndices,NULL,NULL); fprintf(itemsFile,"};\n"); fclose(itemsFile); /*=========================================*/ /* Write out the portItem data structures. */ /*=========================================*/ if (portItemCount == 0) return(CLIPS_TRUE); return(PortItemsToCode(fileName,fileID,headerFP,imageID,maxIndices,&fileCount)); } /************************************************************//* PortItemsToCode: Writes the C code representation of all *//* portItem data structure nodes the specified file. *//************************************************************/static int PortItemsToCode(fileName,fileID,headerFP,imageID,maxIndices,fileCount) char *fileName; int fileID; FILE *headerFP; int imageID; int maxIndices; int *fileCount; { struct defmodule *theDefmodule = NULL; struct portItem *thePortItem = NULL; int portItemCount = 0; int importChecked = CLIPS_FALSE; int exportChecked = CLIPS_FALSE; FILE *portItemsFile = NULL; int portItemArrayVersion = 1; /*=================================================================*/ /* Loop through each of the portItem data structures writing their */ /* C code representation to the file as they are traversed. */ /*=================================================================*/ for (thePortItem = GetNextPortItem(&theDefmodule,&thePortItem,&importChecked,&exportChecked); thePortItem != NULL; thePortItem = GetNextPortItem(&theDefmodule,&thePortItem,&importChecked,&exportChecked)) { /*===========================================*/ /* Open a new file to write to if necessary. */ /*===========================================*/ portItemsFile = OpenFileIfNeeded(portItemsFile,fileName,fileID,imageID, fileCount,portItemArrayVersion,headerFP, "struct portItem",PortPrefix(), CLIPS_FALSE,NULL); if (portItemsFile == NULL) { portItemCount = maxIndices; CloseFileIfNeeded(portItemsFile,&portItemCount, &portItemArrayVersion,maxIndices,NULL,NULL); return(CLIPS_FALSE); } /*================================================*/ /* Write the portItem data structure to the file. */ /*================================================*/ fprintf(portItemsFile,"{"); PrintSymbolReference(portItemsFile,thePortItem->moduleName); fprintf(portItemsFile,","); PrintSymbolReference(portItemsFile,thePortItem->constructType); fprintf(portItemsFile,","); PrintSymbolReference(portItemsFile,thePortItem->constructName); fprintf(portItemsFile,","); if (thePortItem->next == NULL) { fprintf(portItemsFile,"NULL}"); } else { fprintf(portItemsFile,"&%s%d_%d[%d]}",PortPrefix(),imageID, ((portItemCount+1) / maxIndices) + 1, (portItemCount+1) % maxIndices); } /*==================================================*/ /* Increment the number of portItem data structures */ /* written and close the output file if necessary. */ /*==================================================*/ portItemCount++; CloseFileIfNeeded(portItemsFile,&portItemCount,&portItemArrayVersion, maxIndices,NULL,NULL); } /*===================================================*/ /* Close the output file and return TRUE to indicate */ /* the data structures were successfully written. */ /*===================================================*/ portItemCount = maxIndices; CloseFileIfNeeded(portItemsFile,&portItemCount, &portItemArrayVersion,maxIndices,NULL,NULL); return(CLIPS_TRUE); }/*********************************************************************//* GetNextPortItem: Given a pointer to a portItem data structure *//* and its defmodule, returns the "next" portItem data structure. *//* If passed a NULL value for both the defmodule and portItem *//* data structure, it returns the "first" portItem data structure. *//*********************************************************************/static struct portItem *GetNextPortItem(theDefmodule,thePortItem, importChecked,exportChecked) struct defmodule **theDefmodule; struct portItem **thePortItem; int *importChecked; int *exportChecked; { /*====================================================*/ /* If the defmodule pointer is NULL, then the "first" */ /* portItem data structure should be returned. Start */ /* the search in the "first" defmodule. */ /*====================================================*/ if (*theDefmodule == NULL) { *theDefmodule = (struct defmodule *) GetNextDefmodule(NULL); *thePortItem = NULL; *importChecked = CLIPS_FALSE; *exportChecked = CLIPS_FALSE; } /*==============================================*/ /* Loop through all of the defmodules until the */ /* "next" portItem data structure is found. */ /*==============================================*/ while (*theDefmodule != NULL) { /*==========================================*/ /* Check to see if there's another portItem */ /* in the import/export list that's being */ /* checked in the module being examined. */ /*==========================================*/ if (*thePortItem != NULL) *thePortItem = (*thePortItem)->next; if (*thePortItem != NULL) return(*thePortItem); /*==================================================*/ /* If we haven't checked the import list yet, begin */ /* checking it. If there aren't any items in the */ /* import list, then check the export list. */ /*==================================================*/ if (! (*importChecked)) { *thePortItem = (*theDefmodule)->importList; *importChecked = CLIPS_TRUE; if (*thePortItem == NULL) { *thePortItem = (*theDefmodule)->exportList; *exportChecked = CLIPS_TRUE; } } /*======================================*/ /* Otherwise, if we haven't checked the */ /* export list yet, begin checking it. */ /*======================================*/ else if (! (*exportChecked)) { *exportChecked = CLIPS_TRUE; *thePortItem = (*theDefmodule)->exportList; } /*==========================================*/ /* If the import or export list contained a */ /* portItem data structure, then return it. */ /*==========================================*/ if (*thePortItem != NULL) return(*thePortItem); /*==================================*/ /* Otherwise, check the next module */ /* for a portItem data structure. */ /*==================================*/ *theDefmodule = (struct defmodule *) GetNextDefmodule(*theDefmodule); *importChecked = CLIPS_FALSE; *exportChecked = CLIPS_FALSE; } /*=======================================================*/ /* All the portItem data structures have been traversed. */ /* Return NULL to indicate that none are left. */ /*=======================================================*/ return(NULL); } #endif /* CONSTRUCT_COMPILER && (! RUN_TIME) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -