Esempio n. 1
0
void ClipsSession::initialize(int argc,char *argv, string sessionID, RouterInterface *router)
#endif
{
	cout<<"ClipsSession::initialize 0 sessionID:"<<sessionID<<endl;
	m_sessionID = sessionID;
		cout<<"ClipsSession::initialize 1"<<endl;
	m_theEnv = CreateEnvironment();
	cout<<"ClipsSession::initialize 2"<<endl;
#ifdef _DEBUG_CLIPS_
    cout<<"ClipsSession::initialize 3"<<endl;

	if (ConfigUtil::GetInstance()->GetConfigStr("CLIPSログ出力パス").length() > 0)
	{
		fw.open(ConfigUtil::GetInstance()->GetConfigStr("CLIPSログ出力パス").c_str(), ios::out);
#if 1
		EnvWatch(m_theEnv,"globals");
		EnvWatch(m_theEnv, "rules");
		EnvWatch(m_theEnv, "facts");
		EnvWatch(m_theEnv,"activations");
		EnvWatch(m_theEnv,"focus");
		EnvWatch(m_theEnv,"deffunctions");
		EnvWatch(m_theEnv,"compilations");
#endif
		EnvAddRouter(m_theEnv,"DEBUG",999,queryFunction,printFunction,NULL,NULL,NULL);
		//EnvAddRouter(m_theEnv,"wtrace",1000,queryFunction,printFunction,NULL,NULL,NULL);
		//EnvActivateRouter(m_theEnv,"wdialog");
		EnvActivateRouter(m_theEnv,"DEBUG");
#endif
#ifdef _PERFORMANCE_
		//for performance
		//EnvWatch(m_theEnv,"statistics");
#endif
	}

 #if 0
	char *tmp[1];
	tmp[0] = argv;
	RerouteStdin(m_theEnv,1,tmp);
#else
    if (router != NULL)
    {
        m_router = router;
        //const char *routerName=m_router->getRouterName().c_str();
        string routerName = m_router->getRouterName();
		EnvAddRouter(m_theEnv,routerName.c_str(),30,queryFunction,printFunction,NULL,NULL,NULL);
		EnvActivateRouter(m_theEnv, routerName.c_str());
    }
#endif	
	cout<<"ClipsSession::initialize 4"<<endl;	
	EnvReset(m_theEnv);

	
	cout<<"ClipsSession::initialize 5"<<endl;
	m_ruleMgr = new ClipsRuleMgr();
	if (m_ruleMgr != NULL) 
		m_ruleMgr->initialize(m_theEnv, m_sessionID);
}
Esempio n. 2
0
globle void WatchFunctionDefinitions(
      void *theEnv)
{
#if ! RUN_TIME
   EnvDefineFunction2(theEnv,name_watch, 'v', 
         PTIEF WatchCommand, 
         fWatchCommand, 
         (char*)"1**w");
   EnvDefineFunction2(theEnv,name_unwatch, 'v', 
         PTIEF UnwatchCommand, 
         fUnwatchCommand, 
         (char*)"1**w");
   EnvDefineFunction2(theEnv, name_getwatchitem, 'b', 
         PTIEF GetWatchItemCommand,  
         fGetWatchItemCommand, 
         (char*)"11w");
   EnvDefineFunction2(theEnv,name_listwatchitems, 'v', 
         PTIEF ListWatchItemsCommand,
         fListWatchItemsCommand,
         (char*)"0**w");
#endif

   EnvAddRouter(theEnv,WTRACE,1000,RecognizeWatchRouters,CaptureWatchPrints,
         NULL,NULL,NULL);
   EnvDeactivateRouter(theEnv,WTRACE);
}
Esempio n. 3
0
globle void InitializeStringRouter(
  void *theEnv)
  {
   AllocateEnvironmentData(theEnv,STRING_ROUTER_DATA,sizeof(struct stringRouterData),DeallocateStringRouterData);

   EnvAddRouter(theEnv,(char*)"string",0,FindString,PrintString,GetcString,UngetcString,NULL);
  }
Esempio n. 4
0
globle void WatchFunctionDefinitions(
      void *theEnv)
{
#if ! RUN_TIME
   EnvDefineFunction2(theEnv,"watch", 'v', 
         PTIEF WatchCommand, 
         "WatchCommand", 
         "1**w");
   EnvDefineFunction2(theEnv,"unwatch", 'v', 
         PTIEF UnwatchCommand, 
         "UnwatchCommand", 
         "1**w");
   EnvDefineFunction2(theEnv, "get-watch-item", 'b', 
         PTIEF GetWatchItemCommand,  
         "GetWatchItemCommand", 
         "11w");
   EnvDefineFunction2(theEnv,"list-watch-items", 'v', 
         PTIEF ListWatchItemsCommand,
         "ListWatchItemsCommand",
         "0**w");
#endif

   EnvAddRouter(theEnv,WTRACE,1000,RecognizeWatchRouters,CaptureWatchPrints,
         NULL,NULL,NULL);
   EnvDeactivateRouter(theEnv,WTRACE);
}
Esempio n. 5
0
globle void InitializeFileRouter(
  void *theEnv)
  {
   AllocateEnvironmentData(theEnv,FILE_ROUTER_DATA,sizeof(struct fileRouterData),DeallocateFileRouterData);

   EnvAddRouter(theEnv,"fileio",0,FindFile,
             PrintFile,GetcFile,
             UngetcFile,ExitFile);
  }
Esempio n. 6
0
globle intBool EnvDribbleOn(
    void *theEnv,
    char *fileName)
{
    /*==============================*/
    /* If a dribble file is already */
    /* open, then close it.         */
    /*==============================*/

    if (FileCommandData(theEnv)->DribbleFP != NULL)
    {
        EnvDribbleOff(theEnv);
    }

    /*========================*/
    /* Open the dribble file. */
    /*========================*/

    FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,(char*)"w");
    if (FileCommandData(theEnv)->DribbleFP == NULL)
    {
        OpenErrorMessage(theEnv,(char*)"dribble-on",fileName);
        return(0);
    }

    /*============================*/
    /* Create the dribble router. */
    /*============================*/

    EnvAddRouter(theEnv,(char*)"dribble", 40,
                 FindDribble, PrintDribble,
                 GetcDribble, UngetcDribble,
                 ExitDribble);

    FileCommandData(theEnv)->DribbleCurrentPosition = 0;

    /*================================================*/
    /* Call the dribble status function. This is used */
    /* by some of the machine specific interfaces to  */
    /* do things such as changing the wording of menu */
    /* items from "Turn Dribble On..." to             */
    /* "Turn Dribble Off..."                          */
    /*================================================*/

    if (FileCommandData(theEnv)->DribbleStatusFunction != NULL)
    {
        (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,TRUE);
    }

    /*=====================================*/
    /* Return TRUE to indicate the dribble */
    /* file was successfully opened.       */
    /*=====================================*/

    return(TRUE);
}
void InitializeSCUMMVMRouters(void* theEnv) {
   EnvAddRouter(theEnv, 
         (char*)"debug",
         40,
         FindDebug,
         PrintDebug,
         NULL,
         NULL,
         ExitDebug);
}
Esempio n. 8
0
globle int OpenBatch(
  void *theEnv,
  char *fileName,
  int placeAtEnd)
  {
   FILE *theFile;

   /*======================*/
   /* Open the batch file. */
   /*======================*/

   theFile = GenOpen(theEnv,fileName,"r");

   if (theFile == NULL)
     {
      OpenErrorMessage(theEnv,"batch",fileName);
      return(FALSE);
     }

   /*============================*/
   /* Create the batch router if */
   /* it doesn't already exist.  */
   /*============================*/

   if (FileCommandData(theEnv)->TopOfBatchList == NULL)
     {
      EnvAddRouter(theEnv,"batch", 20,
                 FindBatch, NULL,
                 GetcBatch, UngetcBatch,
                 ExitBatch);
     }

   /*====================================*/
   /* Add the newly opened batch file to */
   /* the list of batch files opened.    */
   /*====================================*/

   AddBatch(theEnv,placeAtEnd,(void *) theFile,FILE_BATCH,NULL);

   /*===================================*/
   /* Return TRUE to indicate the batch */
   /* file was successfully opened.     */
   /*===================================*/

   return(TRUE);
  }
Esempio n. 9
0
/*******************************************************************************
          Name:        InitializeInterface
          Description: initializes the the X window interface
          Arguments:   None
          Returns:     None
*******************************************************************************/
void InitializeInterface()
  {
   void *theEnv = GetCurrentEnvironment();

   if (! InitalizeLogTable())
     {
      EnvPrintRouter(theEnv,"werror", "Could not initialize logical name hash table\n");
      XclipsExit(theEnv,0);
      EnvExitRouter(theEnv,0);
     }
     
   //SetDribbleStatusFunction(GetCurrentEnvironment(),NULL);

   /*==================================================================*/
   /* Tell CLIPS which GetEvent function to call when an event needed. */
   /*==================================================================*/

   SetEventFunction(theEnv,GetEvent);

   /*  SetMemoryStatusFunction((int(*)())ActivateTheMenus());*/

   /*=================================================*/
   /* Tell CLIPS which function to call periodically. */
   /*=================================================*/
  
   EnvAddPeriodicFunction(theEnv,"PeriodicUpdate",PeriodicUpdate,90);
   
   /*========================*/
   /* Add a main I/O router. */
   /*========================*/
   
   if (! EnvAddRouter(theEnv,"wclips", 10, XclipsQuery, XclipsPrint, XclipsGetc, XclipsUngetc,
                XclipsExit))
     {
      printf("Could not allocate xclips router!\n");
      XclipsExit(theEnv,0);
      EnvExitRouter(theEnv,0);
     }
     
   EnvPrintRouter(theEnv,"wclips", "                  XCLIPS for:");
  }
Esempio n. 10
0
globle int OpenStringBatch(
  void *theEnv,
  char *stringName,
  char *theString,
  int placeAtEnd)
  {
   if (OpenStringSource(theEnv,stringName,theString,0) == 0)
     { return(0); }

   if (FileCommandData(theEnv)->TopOfBatchList == NULL)
     {
      EnvAddRouter(theEnv,"batch", 20,
                 FindBatch, NULL,
                 GetcBatch, UngetcBatch,
                 ExitBatch);
     }

   AddBatch(theEnv,placeAtEnd,(void *) stringName,STRING_BATCH,theString);

   return(1);
  }
Esempio n. 11
0
globle int CheckSyntax(
  void *theEnv,
  char *theString,
  DATA_OBJECT_PTR returnValue)
  {
   char *name;
   struct token theToken;
   struct expr *top;
   short rv;

   /*==============================*/
   /* Set the default return value */
   /* (TRUE for problems found).   */
   /*==============================*/

   SetpType(returnValue,SYMBOL);
   SetpValue(returnValue,EnvTrueSymbol(theEnv));

   /*===========================================*/
   /* Create a string source router so that the */
   /* string can be used as an input source.    */
   /*===========================================*/

   if (OpenStringSource(theEnv,"check-syntax",theString,0) == 0)
     { return(TRUE); }

   /*=================================*/
   /* Only expressions and constructs */
   /* can have their syntax checked.  */
   /*=================================*/

   GetToken(theEnv,"check-syntax",&theToken);

   if (theToken.type != LPAREN)
     {
      CloseStringSource(theEnv,"check-syntax");
      SetpValue(returnValue,EnvAddSymbol(theEnv,"MISSING-LEFT-PARENTHESIS"));
      return(TRUE);
     }

   /*========================================*/
   /* The next token should be the construct */
   /* type or function name.                 */
   /*========================================*/

   GetToken(theEnv,"check-syntax",&theToken);
   if (theToken.type != SYMBOL)
     {
      CloseStringSource(theEnv,"check-syntax");
      SetpValue(returnValue,EnvAddSymbol(theEnv,"EXPECTED-SYMBOL-AFTER-LEFT-PARENTHESIS"));
      return(TRUE);
     }

   name = ValueToString(theToken.value);

   /*==============================================*/
   /* Set up a router to capture the error output. */
   /*==============================================*/

   EnvAddRouter(theEnv,"error-capture",40,
              FindErrorCapture, PrintErrorCapture,
              NULL, NULL, NULL);

   /*================================*/
   /* Determine if it's a construct. */
   /*================================*/

   if (FindConstruct(theEnv,name))
     {
      ConstructData(theEnv)->CheckSyntaxMode = TRUE;
      rv = (short) ParseConstruct(theEnv,name,"check-syntax");
      GetToken(theEnv,"check-syntax",&theToken);
      ConstructData(theEnv)->CheckSyntaxMode = FALSE;

      if (rv)
        {
         EnvPrintRouter(theEnv,WERROR,"\nERROR:\n");
         PrintInChunks(theEnv,WERROR,GetPPBuffer(theEnv));
         EnvPrintRouter(theEnv,WERROR,"\n");
        }

      DestroyPPBuffer(theEnv);

      CloseStringSource(theEnv,"check-syntax");

      if ((rv != FALSE) || (ParseFunctionData(theEnv)->WarningString != NULL))
        {
         SetErrorCaptureValues(theEnv,returnValue);
         DeactivateErrorCapture(theEnv);
         return(TRUE);
        }

      if (theToken.type != STOP)
        {
         SetpValue(returnValue,EnvAddSymbol(theEnv,"EXTRANEOUS-INPUT-AFTER-LAST-PARENTHESIS"));
         DeactivateErrorCapture(theEnv);
         return(TRUE);
        }

      SetpType(returnValue,SYMBOL);
      SetpValue(returnValue,EnvFalseSymbol(theEnv));
      DeactivateErrorCapture(theEnv);
      return(FALSE);
     }

   /*=======================*/
   /* Parse the expression. */
   /*=======================*/

   top = Function2Parse(theEnv,"check-syntax",name);
   GetToken(theEnv,"check-syntax",&theToken);
   ClearParsedBindNames(theEnv);
   CloseStringSource(theEnv,"check-syntax");

   if (top == NULL)
     {
      SetErrorCaptureValues(theEnv,returnValue);
      DeactivateErrorCapture(theEnv);
      return(TRUE);
     }

   if (theToken.type != STOP)
     {
      SetpValue(returnValue,EnvAddSymbol(theEnv,"EXTRANEOUS-INPUT-AFTER-LAST-PARENTHESIS"));
      DeactivateErrorCapture(theEnv);
      ReturnExpression(theEnv,top);
      return(TRUE);
     }

   DeactivateErrorCapture(theEnv);

   ReturnExpression(theEnv,top);
   SetpType(returnValue,SYMBOL);
   SetpValue(returnValue,EnvFalseSymbol(theEnv));
   return(FALSE);
  }
Esempio n. 12
0
extern "C" void SetupLLVMIORouter(void* theEnv) {
	EnvAddRouter(theEnv, "llvm", 40, FindLLVM, PrintLLVM,
			NULL, NULL, ExitLLVM);
}