📄 router.c
字号:
currentPtr = currentPtr->next; } /*=====================================================*/ /* The logical name was not recognized by any routers. */ /*=====================================================*/ UnrecognizedRouterMessage(logicalName); return(-1); } /*****************************************************//* ExitCommand: H/L command for exiting the program. *//*****************************************************/globle VOID ExitCommand() { int argCnt; int status; if ((argCnt = ArgCountCheck("exit",NO_MORE_THAN,1)) == -1) return; if (argCnt == 0) {#if VAX_VMS ExitCLIPS(-2); /* Fix for weird VMS com file problem. */#else ExitCLIPS(-1);#endif } else { status = (int) RtnLong(1); if (GetEvaluationError()) return; ExitCLIPS(status); } return; } /*******************************************//* ExitCLIPS: Generic exit function. Calls *//* all of the router exit functions. *//*******************************************/globle VOID ExitCLIPS(num) int num; { struct router *currentPtr, *nextPtr; Abort = CLIPS_FALSE; currentPtr = ListOfRouters; while (currentPtr != NULL) { nextPtr = currentPtr->next; if (currentPtr->active == CLIPS_TRUE) { if (currentPtr->exiter != NULL) (*currentPtr->exiter) (num); } currentPtr = nextPtr; } if (Abort) return; genexit(num); }/********************************************//* AbortExit: Forces ExitCLIPS to terminate *//* after calling all closing routers. *//********************************************/globle VOID AbortExit() { Abort = CLIPS_TRUE; }/*********************************************************//* AddRouter: Adds an I/O router to the list of routers. *//*********************************************************/globle BOOLEAN AddRouter(routerName,priority,queryFunction,printFunction, getcFunction,ungetcFunction,exitFunction) char *routerName; int priority;#if ANSI_COMPILER int (*queryFunction)(char *); int (*printFunction)(char *,char *); int (*getcFunction)(char *); int (*ungetcFunction)(int,char *); int (*exitFunction)(int);#else int (*queryFunction)(); int (*printFunction)(); int (*getcFunction)(); int (*ungetcFunction)(); int (*exitFunction)();#endif { struct router *newPtr, *lastPtr, *currentPtr; newPtr = get_struct(router); newPtr->name = routerName; newPtr->active = CLIPS_TRUE; newPtr->priority = priority; newPtr->query = queryFunction; newPtr->printer = printFunction; newPtr->exiter = exitFunction; newPtr->charget = getcFunction; newPtr->charunget = ungetcFunction; newPtr->next = NULL; if (ListOfRouters == NULL) { ListOfRouters = newPtr; return(1); } lastPtr = NULL; currentPtr = ListOfRouters; while ((currentPtr != NULL) ? (priority < currentPtr->priority) : CLIPS_FALSE) { lastPtr = currentPtr; currentPtr = currentPtr->next; } if (lastPtr == NULL) { newPtr->next = ListOfRouters; ListOfRouters = newPtr; } else { newPtr->next = currentPtr; lastPtr->next = newPtr; } return(1); }/*****************************************************************//* DeleteRouter: Removes an I/O router from the list of routers. *//*****************************************************************/globle int DeleteRouter(routerName) char *routerName; { struct router *currentPtr, *lastPtr; currentPtr = ListOfRouters; lastPtr = NULL; while (currentPtr != NULL) { if (strcmp(currentPtr->name,routerName) == 0) { if (lastPtr == NULL) { ListOfRouters = currentPtr->next; rm(currentPtr,(int) sizeof(struct router)); return(1); } lastPtr->next = currentPtr->next; rm(currentPtr,(int) sizeof(struct router)); return(1); } lastPtr = currentPtr; currentPtr = currentPtr->next; } return(0); }/*********************************************************************//* QueryRouters: Determines if any router recognizes a logical name. *//*********************************************************************/globle int QueryRouters(logicalName) char *logicalName; { struct router *currentPtr; currentPtr = ListOfRouters; while (currentPtr != NULL) { if (QueryRouter(logicalName,currentPtr) == CLIPS_TRUE) return(CLIPS_TRUE); currentPtr = currentPtr->next; } return(CLIPS_FALSE); }/************************************************//* QueryRouter: Determines if a specific router *//* recognizes a logical name. *//************************************************/static int QueryRouter(logicalName,currentPtr) char *logicalName; struct router *currentPtr; { /*===================================================*/ /* If the router is inactive, then it can't respond. */ /*===================================================*/ if (currentPtr->active == CLIPS_FALSE) { return(CLIPS_FALSE); } /*=============================================================*/ /* If the router has no query function, then it can't respond. */ /*=============================================================*/ if (currentPtr->query == NULL) return(CLIPS_FALSE); /*=========================================*/ /* Call the router's query function to see */ /* if it recognizes the logical name. */ /*=========================================*/ if ( (*currentPtr->query) (logicalName) == CLIPS_TRUE ) { return(CLIPS_TRUE); } return(CLIPS_FALSE); }/****************************************************//* DeactivateRouter: Deactivates a specific router. *//****************************************************/globle int DeactivateRouter(routerName) char *routerName; { struct router *currentPtr; currentPtr = ListOfRouters; while (currentPtr != NULL) { if (strcmp(currentPtr->name,routerName) == 0) { currentPtr->active = CLIPS_FALSE; return(CLIPS_TRUE); } currentPtr = currentPtr->next; } return(CLIPS_FALSE); }/************************************************//* ActivateRouter: Activates a specific router. *//************************************************/globle int ActivateRouter(routerName) char *routerName; { struct router *currentPtr; currentPtr = ListOfRouters; while (currentPtr != NULL) { if (strcmp(currentPtr->name,routerName) == 0) { currentPtr->active = CLIPS_TRUE; return(CLIPS_TRUE); } currentPtr = currentPtr->next; } return(CLIPS_FALSE); }/********************************************************//* SetFastLoad: Used to bypass router system for loads. *//********************************************************/globle VOID SetFastLoad(filePtr) FILE *filePtr; { FastLoadFilePtr = filePtr; }/********************************************************//* SetFastSave: Used to bypass router system for saves. *//********************************************************/globle VOID SetFastSave(filePtr) FILE *filePtr; { FastSaveFilePtr = filePtr; }/******************************************************//* GetFastLoad: Returns the "fast load" file pointer. *//******************************************************/globle FILE *GetFastLoad() { return(FastLoadFilePtr); }/******************************************************//* GetFastSave: Returns the "fast save" file pointer. *//******************************************************/globle FILE *GetFastSave() { return(FastSaveFilePtr); }/*****************************************************//* UnrecognizedRouterMessage: Standard error message *//* for an unrecognized router name. *//*****************************************************/globle VOID UnrecognizedRouterMessage(logicalName) char *logicalName; { PrintErrorID("ROUTER",1,CLIPS_FALSE); PrintCLIPS(WERROR,"Logical name "); PrintCLIPS(WERROR,logicalName); PrintCLIPS(WERROR," was not recognized by any routers\n"); } /*****************************************//* PrintNCLIPS: Generic print function. *//*****************************************/globle int PrintNCLIPS(logicalName,str,length) char *logicalName; char *str; long length; { char *tempStr; int rv; tempStr = genlongalloc(length+1); strncpy(tempStr,str,length); tempStr[length] = 0; rv = PrintCLIPS(logicalName,tempStr); genlongfree(tempStr,length+1); return(rv); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -