📄 msgcom.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 06/02/06 */
/* */
/* OBJECT MESSAGE COMMANDS */
/*******************************************************/
/*************************************************************/
/* Purpose: */
/* */
/* Principal Programmer(s): */
/* Brian L. Donnell */
/* */
/* Contributing Programmer(s): */
/* */
/* Revision History: */
/* 6.23: Changed name of variable log to logName */
/* because of Unix compiler warnings of shadowed */
/* definitions. */
/* */
/* 6.24: Removed IMPERATIVE_MESSAGE_HANDLERS */
/* compilation flag. */
/* */
/* Corrected code to remove run-time program */
/* compiler warnings. */
/* */
/*************************************************************/
/* =========================================
*****************************************
EXTERNAL DEFINITIONS
=========================================
***************************************** */
#include "setup.h"
#if OBJECT_SYSTEM
#include <string.h>
#include "argacces.h"
#include "classcom.h"
#include "classfun.h"
#include "classinf.h"
#include "envrnmnt.h"
#include "insfun.h"
#include "insmoddp.h"
#include "msgfun.h"
#include "prccode.h"
#include "router.h"
#if BLOAD || BLOAD_AND_BSAVE
#include "bload.h"
#endif
#if ! RUN_TIME
#include "extnfunc.h"
#endif
#if (! BLOAD_ONLY) && (! RUN_TIME)
#include "constrct.h"
#include "msgpsr.h"
#endif
#if DEBUGGING_FUNCTIONS
#include "watch.h"
#endif
#define _MSGCOM_SOURCE_
#include "msgcom.h"
/* =========================================
*****************************************
INTERNALLY VISIBLE FUNCTION HEADERS
=========================================
***************************************** */
#if ! RUN_TIME
static void CreateSystemHandlers(void *);
#endif
#if (! BLOAD_ONLY) && (! RUN_TIME)
static int WildDeleteHandler(void *,DEFCLASS *,SYMBOL_HN *,char *);
#endif
#if DEBUGGING_FUNCTIONS
static unsigned DefmessageHandlerWatchAccess(void *,int,unsigned,EXPRESSION *);
static unsigned DefmessageHandlerWatchPrint(void *,char *,int,EXPRESSION *);
static unsigned DefmessageHandlerWatchSupport(void *,char *,char *,int,
void (*)(void *,char *,void *,unsigned),
void (*)(void *,int,void *,unsigned),
EXPRESSION *);
static unsigned WatchClassHandlers(void *,void *,char *,int,char *,int,int,
void (*)(void *,char *,void *,unsigned),
void (*)(void *,int,void *,unsigned));
static void PrintHandlerWatchFlag(void *,char *,void *,unsigned);
#endif
/* =========================================
*****************************************
EXTERNALLY VISIBLE FUNCTIONS
=========================================
***************************************** */
/***************************************************
NAME : SetupMessageHandlers
DESCRIPTION : Sets up internal symbols and
fucntion definitions pertaining to
message-handlers. Also creates
system handlers
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS : Functions and data structures
initialized
NOTES : Should be called before
SetupInstanceModDupCommands() in
INSMODDP.C
***************************************************/
globle void SetupMessageHandlers(
void *theEnv)
{
ENTITY_RECORD handlerGetInfo = { "HANDLER_GET", HANDLER_GET,0,1,1,
PrintHandlerSlotGetFunction,
PrintHandlerSlotGetFunction,NULL,
HandlerSlotGetFunction,
NULL,NULL,NULL,NULL,NULL,NULL },
handlerPutInfo = { "HANDLER_PUT", HANDLER_PUT,0,1,1,
PrintHandlerSlotPutFunction,
PrintHandlerSlotPutFunction,NULL,
HandlerSlotPutFunction,
NULL,NULL,NULL,NULL,NULL,NULL };
AllocateEnvironmentData(theEnv,MESSAGE_HANDLER_DATA,sizeof(struct messageHandlerData),NULL);
memcpy(&MessageHandlerData(theEnv)->HandlerGetInfo,&handlerGetInfo,sizeof(struct entityRecord));
memcpy(&MessageHandlerData(theEnv)->HandlerPutInfo,&handlerPutInfo,sizeof(struct entityRecord));
MessageHandlerData(theEnv)->hndquals[0] = "around";
MessageHandlerData(theEnv)->hndquals[1] = "before";
MessageHandlerData(theEnv)->hndquals[2] = "primary";
MessageHandlerData(theEnv)->hndquals[3] = "after";
InstallPrimitive(theEnv,&MessageHandlerData(theEnv)->HandlerGetInfo,HANDLER_GET);
InstallPrimitive(theEnv,&MessageHandlerData(theEnv)->HandlerPutInfo,HANDLER_PUT);
#if ! RUN_TIME
MessageHandlerData(theEnv)->INIT_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,INIT_STRING);
IncrementSymbolCount(MessageHandlerData(theEnv)->INIT_SYMBOL);
MessageHandlerData(theEnv)->DELETE_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,DELETE_STRING);
IncrementSymbolCount(MessageHandlerData(theEnv)->DELETE_SYMBOL);
MessageHandlerData(theEnv)->CREATE_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,CREATE_STRING);
IncrementSymbolCount(MessageHandlerData(theEnv)->CREATE_SYMBOL);
EnvAddClearFunction(theEnv,"defclass",CreateSystemHandlers,-100);
#if ! BLOAD_ONLY
MessageHandlerData(theEnv)->SELF_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,SELF_STRING);
IncrementSymbolCount(MessageHandlerData(theEnv)->SELF_SYMBOL);
AddConstruct(theEnv,"defmessage-handler","defmessage-handlers",
ParseDefmessageHandler,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
EnvDefineFunction2(theEnv,"undefmessage-handler",'v',PTIEF UndefmessageHandlerCommand,
"UndefmessageHandlerCommand","23w");
#endif
EnvDefineFunction2(theEnv,"send",'u',PTIEF SendCommand,"SendCommand","2*uuw");
#if DEBUGGING_FUNCTIONS
EnvDefineFunction2(theEnv,"preview-send",'v',PTIEF PreviewSendCommand,"PreviewSendCommand","22w");
EnvDefineFunction2(theEnv,"ppdefmessage-handler",'v',PTIEF PPDefmessageHandlerCommand,
"PPDefmessageHandlerCommand","23w");
EnvDefineFunction2(theEnv,"list-defmessage-handlers",'v',PTIEF ListDefmessageHandlersCommand,
"ListDefmessageHandlersCommand","02w");
#endif
EnvDefineFunction2(theEnv,"next-handlerp",'b',PTIEF NextHandlerAvailable,"NextHandlerAvailable","00");
FuncSeqOvlFlags(theEnv,"next-handlerp",TRUE,FALSE);
EnvDefineFunction2(theEnv,"call-next-handler",'u',
PTIEF CallNextHandler,"CallNextHandler","00");
FuncSeqOvlFlags(theEnv,"call-next-handler",TRUE,FALSE);
EnvDefineFunction2(theEnv,"override-next-handler",'u',
PTIEF CallNextHandler,"CallNextHandler",NULL);
FuncSeqOvlFlags(theEnv,"override-next-handler",TRUE,FALSE);
EnvDefineFunction2(theEnv,"dynamic-get",'u',PTIEF DynamicHandlerGetSlot,"DynamicHandlerGetSlot","11w");
EnvDefineFunction2(theEnv,"dynamic-put",'u',PTIEF DynamicHandlerPutSlot,"DynamicHandlerPutSlot","1**w");
EnvDefineFunction2(theEnv,"get",'u',PTIEF DynamicHandlerGetSlot,"DynamicHandlerGetSlot","11w");
EnvDefineFunction2(theEnv,"put",'u',PTIEF DynamicHandlerPutSlot,"DynamicHandlerPutSlot","1**w");
#endif
#if DEBUGGING_FUNCTIONS
AddWatchItem(theEnv,"messages",0,&MessageHandlerData(theEnv)->WatchMessages,36,NULL,NULL);
AddWatchItem(theEnv,"message-handlers",0,&MessageHandlerData(theEnv)->WatchHandlers,35,
DefmessageHandlerWatchAccess,DefmessageHandlerWatchPrint);
#endif
}
/*****************************************************
NAME : EnvGetDefmessageHandlerName
DESCRIPTION : Gets the name of a message-handler
INPUTS : 1) Pointer to a class
2) Array index of handler in class's
message-handler array (+1)
RETURNS : Name-string of message-handler
SIDE EFFECTS : None
NOTES : None
*****************************************************/
#if IBM_TBC
#pragma argsused
#endif
char *EnvGetDefmessageHandlerName(
void *theEnv,
void *ptr,
unsigned theIndex)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
return(ValueToString(((DEFCLASS *) ptr)->handlers[theIndex-1].name));
}
/*****************************************************
NAME : EnvGetDefmessageHandlerType
DESCRIPTION : Gets the type of a message-handler
INPUTS : 1) Pointer to a class
2) Array index of handler in class's
message-handler array (+1)
RETURNS : Type-string of message-handler
SIDE EFFECTS : None
NOTES : None
*****************************************************/
globle char *EnvGetDefmessageHandlerType(
void *theEnv,
void *ptr,
unsigned theIndex)
{
return(MessageHandlerData(theEnv)->hndquals[((DEFCLASS *) ptr)->handlers[theIndex-1].type]);
}
/**************************************************************
NAME : EnvGetNextDefmessageHandler
DESCRIPTION : Finds first or next handler for a class
INPUTS : 1) The address of the handler's class
2) The array index of the current handler (+1)
RETURNS : The array index (+1) of the next handler, or 0
if there is none
SIDE EFFECTS : None
NOTES : If index == 0, the first handler array index
(i.e. 1) returned
**************************************************************/
#if IBM_TBC
#pragma argsused
#endif
globle unsigned EnvGetNextDefmessageHandler(
void *theEnv,
void *ptr,
unsigned theIndex)
{
DEFCLASS *cls;
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
cls = (DEFCLASS *) ptr;
if (theIndex == 0)
return((cls->handlers != NULL) ? 1U : 0U);
if (theIndex == cls->handlerCount)
return(0);
return(theIndex+1);
}
/*****************************************************
NAME : GetDefmessageHandlerPointer
DESCRIPTION : Returns a pointer to a handler
INPUTS : 1) Pointer to a class
2) Array index of handler in class's
message-handler array (+1)
RETURNS : Pointer to the handler.
SIDE EFFECTS : None
NOTES : None
*****************************************************/
globle HANDLER *GetDefmessageHandlerPointer(
void *ptr,
unsigned theIndex)
{
return(&((DEFCLASS *) ptr)->handlers[theIndex-1]);
}
#if DEBUGGING_FUNCTIONS
/*********************************************************
NAME : EnvGetDefmessageHandlerWatch
DESCRIPTION : Determines if trace messages for calls
to this handler will be generated or not
INPUTS : 1) A pointer to the class
2) The index of the handler
RETURNS : TRUE if a trace is active,
FALSE otherwise
SIDE EFFECTS : None
NOTES : None
*********************************************************/
#if IBM_TBC
#pragma argsused
#endif
globle unsigned EnvGetDefmessageHandlerWatch(
void *theEnv,
void *theClass,
unsigned theIndex)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
return(((DEFCLASS *) theClass)->handlers[theIndex-1].trace);
}
/*********************************************************
NAME : EnvSetDefmessageHandlerWatch
DESCRIPTION : Sets the trace to ON/OFF for the
calling of the handler
INPUTS : 1) TRUE to set the trace on,
FALSE to set it off
2) A pointer to the class
3) The index of the handler
RETURNS : Nothing useful
SIDE EFFECTS : Watch flag for the handler set
NOTES : None
*********************************************************/
#if IBM_TBC
#pragma argsused
#endif
globle void EnvSetDefmessageHandlerWatch(
void *theEnv,
int newState,
void *theClass,
unsigned theIndex)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
((DEFCLASS *) theClass)->handlers[theIndex-1].trace = newState;
}
#endif
/***************************************************
NAME : EnvFindDefmessageHandler
DESCRIPTION : Determines the index of a specfied
message-handler
INPUTS : 1) A pointer to the class
2) Name-string of the handler
3) Handler-type: "around","before",
"primary", or "after"
RETURNS : The index of the handler
(0 if not found)
SIDE EFFECTS : None
NOTES : None
***************************************************/
globle unsigned EnvFindDefmessageHandler(
void *theEnv,
void *ptr,
char *hname,
char *htypestr)
{
unsigned htype;
SYMBOL_HN *hsym;
DEFCLASS *cls;
int theIndex;
htype = HandlerType(theEnv,"handler-lookup",htypestr);
if (htype == MERROR)
return(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -