📄 router.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* I/O ROUTER MODULE */ /*******************************************************//*************************************************************//* Purpose: Provides a centralized mechanism for handling *//* input and output requests. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* *//* Revision History: *//* *//*************************************************************/#define _ROUTER_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "setup.h"#include "constant.h"#include "clipsmem.h"#include "filertr.h"#include "strngrtr.h"#include "extnfunc.h"#include "argacces.h"#include "sysdep.h"#include "router.h"struct router { char *name; int active; int priority;#if ANSI_COMPILER int (*query)(char *); int (*printer)(char *,char *); int (*exiter)(int); int (*charget)(char *); int (*charunget)(int,char *);#else int (*query)(); int (*printer)(); int (*exiter)(); int (*charget)(); int (*charunget)();#endif struct router *next; };/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER static int QueryRouter(char *,struct router *);#else static int QueryRouter();#endif/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static struct router *ListOfRouters = NULL; static FILE *FastLoadFilePtr = NULL; static FILE *FastSaveFilePtr = NULL; static int Abort;/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle char *WWARNING = "wwarning"; globle char *WERROR = "werror"; globle char *WTRACE = "wtrace"; globle char *WDIALOG = "wdialog"; globle char *WCLIPS = "wclips"; globle char *WDISPLAY = "wdisplay"; globle int CLIPSInputCount = -1; globle char *LineCountRouter = NULL; globle char *FastCharGetRouter = NULL; globle char *FastCharGetString = NULL; globle long FastCharGetIndex = 0;/*********************************************************//* InitializeDefaultRouters: Initializes output streams. *//*********************************************************/globle VOID InitializeDefaultRouters() {#if (! RUN_TIME) DefineFunction2("exit", 'v', PTIF ExitCommand, "ExitCommand", "*1i");#endif InitializeFileRouter(); InitializeStringRouter(); }/***************************************//* PrintCLIPS: Generic print function. *//***************************************/globle int PrintCLIPS(logicalName, str) char *logicalName; char *str; { struct router *currentPtr; /*===================================================*/ /* If the "fast save" option is being used, then the */ /* logical name is actually a pointer to a file and */ /* fprintf can be called directly to bypass querying */ /* all of the routers. */ /*===================================================*/ if (((char *) FastSaveFilePtr) == logicalName) { fprintf(FastSaveFilePtr,"%s",str); return(2); } /*==============================================*/ /* Search through the list of routers until one */ /* is found that will handle the print request. */ /*==============================================*/ currentPtr = ListOfRouters; while (currentPtr != NULL) { if ((currentPtr->printer != NULL) ? QueryRouter(logicalName,currentPtr) : CLIPS_FALSE) { (*currentPtr->printer) (logicalName,str); return(1); } currentPtr = currentPtr->next; } /*=====================================================*/ /* The logical name was not recognized by any routers. */ /*=====================================================*/ if (strcmp(WERROR,logicalName) != 0) UnrecognizedRouterMessage(logicalName); return(0); } /**********************************************//* GetcCLIPS: Generic get character function. *//**********************************************/globle int GetcCLIPS(logicalName) char *logicalName; { struct router *currentPtr; int inchar; /*===================================================*/ /* If the "fast load" option is being used, then the */ /* logical name is actually a pointer to a file and */ /* getc can be called directly to bypass querying */ /* all of the routers. */ /*===================================================*/ if (((char *) FastLoadFilePtr) == logicalName) { inchar = getc(FastLoadFilePtr); if ((inchar == '\r') || (inchar == '\n')) { if (((char *) FastLoadFilePtr) == LineCountRouter) { IncrementLineCount(); } } if (inchar == '\r') return('\n'); /* if (inchar != '\b') { return(inchar); } */ return(inchar); } /*===============================================*/ /* If the "fast string get" option is being used */ /* for the specified logical name, then bypass */ /* the router system and extract the character */ /* directly from the fast get string. */ /*===============================================*/ if (FastCharGetRouter == logicalName) { inchar = FastCharGetString[FastCharGetIndex]; FastCharGetIndex++; if (inchar == '\0') return(EOF); if ((inchar == '\r') || (inchar == '\n')) { if (FastCharGetRouter == LineCountRouter) { IncrementLineCount(); } } if (inchar == '\r') return('\n'); return(inchar); } /*==============================================*/ /* Search through the list of routers until one */ /* is found that will handle the getc request. */ /*==============================================*/ currentPtr = ListOfRouters; while (currentPtr != NULL) { if ((currentPtr->charget != NULL) ? QueryRouter(logicalName,currentPtr) : CLIPS_FALSE) { inchar = (*currentPtr->charget) (logicalName); if ((inchar == '\r') || (inchar == '\n')) { if ((LineCountRouter != NULL) && (strcmp(logicalName,LineCountRouter) == 0)) { IncrementLineCount(); } } if (inchar == '\r') return('\n'); /* if (inchar != '\b') { return(inchar); } */ return(inchar); } currentPtr = currentPtr->next; } /*=====================================================*/ /* The logical name was not recognized by any routers. */ /*=====================================================*/ UnrecognizedRouterMessage(logicalName); return(-1); }/**************************************************//* UngetcCLIPS: Generic unget character function. *//**************************************************/globle int UngetcCLIPS(ch,logicalName) int ch; char *logicalName; { struct router *currentPtr; /*===================================================*/ /* If the "fast load" option is being used, then the */ /* logical name is actually a pointer to a file and */ /* ungetc can be called directly to bypass querying */ /* all of the routers. */ /*===================================================*/ if (((char *) FastLoadFilePtr) == logicalName) { if ((ch == '\r') || (ch == '\n')) { if (((char *) FastLoadFilePtr) == LineCountRouter) { DecrementLineCount(); } } return(ungetc(ch,FastLoadFilePtr)); } /*===============================================*/ /* If the "fast string get" option is being used */ /* for the specified logical name, then bypass */ /* the router system and unget the character */ /* directly from the fast get string. */ /*===============================================*/ if (FastCharGetRouter == logicalName) { if ((ch == '\r') || (ch == '\n')) { if (FastCharGetRouter == LineCountRouter) { DecrementLineCount(); } } if (FastCharGetIndex > 0) FastCharGetIndex--; return(ch); } /*===============================================*/ /* Search through the list of routers until one */ /* is found that will handle the ungetc request. */ /*===============================================*/ currentPtr = ListOfRouters; while (currentPtr != NULL) { if ((currentPtr->charunget != NULL) ? QueryRouter(logicalName,currentPtr) : FALSE) { if ((ch == '\r') || (ch == '\n')) { if ((LineCountRouter != NULL) && (strcmp(logicalName,LineCountRouter) == 0)) { DecrementLineCount(); } } return((*currentPtr->charunget) (ch,logicalName)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -