📄 msgcom.c
字号:
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); hsym = FindSymbolHN(theEnv,hname); if (hsym == NULL) return(0); cls = (DEFCLASS *) ptr; theIndex = FindHandlerByIndex(cls,hsym,(unsigned) htype); return((unsigned) (theIndex+1)); }/*************************************************** NAME : EnvIsDefmessageHandlerDeletable DESCRIPTION : Determines if a message-handler can be deleted INPUTS : 1) Address of the handler's class 2) Index of the handler RETURNS : TRUE if deletable, FALSE otherwise SIDE EFFECTS : None NOTES : None ***************************************************/globle int EnvIsDefmessageHandlerDeletable( void *theEnv, void *ptr, int theIndex) { DEFCLASS *cls; if (! ConstructsDeletable(theEnv)) { return FALSE; } cls = (DEFCLASS *) ptr; if (cls->handlers[theIndex-1].system == 1) return(FALSE);#if (! BLOAD_ONLY) && (! RUN_TIME) return((HandlersExecuting(cls) == FALSE) ? TRUE : FALSE);#else return FALSE;#endif }/****************************************************************************** NAME : UndefmessageHandlerCommand DESCRIPTION : Deletes a handler from a class INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Handler deleted if possible NOTES : H/L Syntax: (undefmessage-handler <class> <handler> [<type>]) ******************************************************************************/globle void UndefmessageHandlerCommand( void *theEnv) {#if RUN_TIME || BLOAD_ONLY PrintErrorID(theEnv,"MSGCOM",3,FALSE); EnvPrintRouter(theEnv,WERROR,"Unable to delete message-handlers.\n");#else SYMBOL_HN *mname; char *tname; DATA_OBJECT tmp; DEFCLASS *cls;#if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) { PrintErrorID(theEnv,"MSGCOM",3,FALSE); EnvPrintRouter(theEnv,WERROR,"Unable to delete message-handlers.\n"); return; }#endif if (EnvArgTypeCheck(theEnv,"undefmessage-handler",1,SYMBOL,&tmp) == FALSE) return; cls = LookupDefclassByMdlOrScope(theEnv,DOToString(tmp)); if ((cls == NULL) ? (strcmp(DOToString(tmp),"*") != 0) : FALSE) { ClassExistError(theEnv,"undefmessage-handler",DOToString(tmp)); return; } if (EnvArgTypeCheck(theEnv,"undefmessage-handler",2,SYMBOL,&tmp) == FALSE) return; mname = (SYMBOL_HN *) tmp.value; if (EnvRtnArgCount(theEnv) == 3) { if (EnvArgTypeCheck(theEnv,"undefmessage-handler",3,SYMBOL,&tmp) == FALSE) return; tname = DOToString(tmp); if (strcmp(tname,"*") == 0) tname = NULL; } else tname = MessageHandlerData(theEnv)->hndquals[MPRIMARY]; WildDeleteHandler(theEnv,cls,mname,tname);#endif }/*********************************************************** NAME : EnvUndefmessageHandler DESCRIPTION : Deletes a handler from a class INPUTS : 1) Class address (Can be NULL) 2) Handler index (can be 0) RETURNS : 1 if successful, 0 otherwise SIDE EFFECTS : Handler deleted if possible NOTES : None ***********************************************************/globle int EnvUndefmessageHandler( void *theEnv, void *vptr, int mhi) {#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(vptr)#pragma unused(mhi)#endif#if RUN_TIME || BLOAD_ONLY PrintErrorID(theEnv,"MSGCOM",3,FALSE); EnvPrintRouter(theEnv,WERROR,"Unable to delete message-handlers.\n"); return(0);#else DEFCLASS *cls;#if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) { PrintErrorID(theEnv,"MSGCOM",3,FALSE); EnvPrintRouter(theEnv,WERROR,"Unable to delete message-handlers.\n"); return(0); }#endif if (vptr == NULL) { if (mhi != 0) { PrintErrorID(theEnv,"MSGCOM",1,FALSE); EnvPrintRouter(theEnv,WERROR,"Incomplete message-handler specification for deletion.\n"); return(0); } return(WildDeleteHandler(theEnv,NULL,NULL,NULL)); } if (mhi == 0) return(WildDeleteHandler(theEnv,(DEFCLASS *) vptr,NULL,NULL)); cls = (DEFCLASS *) vptr; if (HandlersExecuting(cls)) { HandlerDeleteError(theEnv,EnvGetDefclassName(theEnv,(void *) cls)); return(0); } cls->handlers[mhi-1].mark = 1; DeallocateMarkedHandlers(theEnv,cls); return(1);#endif }#if DEBUGGING_FUNCTIONS/******************************************************************************* NAME : PPDefmessageHandlerCommand DESCRIPTION : Displays the pretty-print form (if any) for a handler INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : None NOTES : H/L Syntax: (ppdefmessage-handler <class> <message> [<type>]) *******************************************************************************/globle void PPDefmessageHandlerCommand( void *theEnv) { DATA_OBJECT temp; SYMBOL_HN *csym,*msym; char *tname; DEFCLASS *cls = NULL; unsigned mtype; HANDLER *hnd; if (EnvArgTypeCheck(theEnv,"ppdefmessage-handler",1,SYMBOL,&temp) == FALSE) return; csym = FindSymbolHN(theEnv,DOToString(temp)); if (EnvArgTypeCheck(theEnv,"ppdefmessage-handler",2,SYMBOL,&temp) == FALSE) return; msym = FindSymbolHN(theEnv,DOToString(temp)); if (EnvRtnArgCount(theEnv) == 3) { if (EnvArgTypeCheck(theEnv,"ppdefmessage-handler",3,SYMBOL,&temp) == FALSE) return; tname = DOToString(temp); } else tname = MessageHandlerData(theEnv)->hndquals[MPRIMARY]; mtype = HandlerType(theEnv,"ppdefmessage-handler",tname); if (mtype == MERROR) { SetEvaluationError(theEnv,TRUE); return; } if (csym != NULL) cls = LookupDefclassByMdlOrScope(theEnv,ValueToString(csym)); if (((cls == NULL) || (msym == NULL)) ? TRUE : ((hnd = FindHandlerByAddress(cls,msym,(unsigned) mtype)) == NULL)) { PrintErrorID(theEnv,"MSGCOM",2,FALSE); EnvPrintRouter(theEnv,WERROR,"Unable to find message-handler "); EnvPrintRouter(theEnv,WERROR,ValueToString(msym)); EnvPrintRouter(theEnv,WERROR," "); EnvPrintRouter(theEnv,WERROR,tname); EnvPrintRouter(theEnv,WERROR," for class "); EnvPrintRouter(theEnv,WERROR,ValueToString(csym)); EnvPrintRouter(theEnv,WERROR," in function ppdefmessage-handler.\n"); SetEvaluationError(theEnv,TRUE); return; } if (hnd->ppForm != NULL) PrintInChunks(theEnv,WDISPLAY,hnd->ppForm); }/***************************************************************************** NAME : ListDefmessageHandlersCommand DESCRIPTION : Depending on arguments, does lists handlers which match restrictions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : None NOTES : H/L Syntax: (list-defmessage-handlers [<class> [inherit]])) *****************************************************************************/globle void ListDefmessageHandlersCommand( void *theEnv) { int inhp; void *clsptr; if (EnvRtnArgCount(theEnv) == 0) EnvListDefmessageHandlers(theEnv,WDISPLAY,NULL,0); else { clsptr = ClassInfoFnxArgs(theEnv,"list-defmessage-handlers",&inhp); if (clsptr == NULL) return; EnvListDefmessageHandlers(theEnv,WDISPLAY,clsptr,inhp); } }/******************************************************************** NAME : PreviewSendCommand DESCRIPTION : Displays a list of the core for a message describing shadows,etc. INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Temporary core created and destroyed NOTES : H/L Syntax: (preview-send <class> <msg>) ********************************************************************/globle void PreviewSendCommand( void *theEnv) { DEFCLASS *cls; DATA_OBJECT temp; /* ============================= Get the class for the message ============================= */ if (EnvArgTypeCheck(theEnv,"preview-send",1,SYMBOL,&temp) == FALSE) return; cls = LookupDefclassByMdlOrScope(theEnv,DOToString(temp)); if (cls == NULL) { ClassExistError(theEnv,"preview-send",ValueToString(temp.value)); return; } if (EnvArgTypeCheck(theEnv,"preview-send",2,SYMBOL,&temp) == FALSE) return; EnvPreviewSend(theEnv,WDISPLAY,(void *) cls,DOToString(temp)); }/******************************************************** NAME : EnvGetDefmessageHandlerPPForm DESCRIPTION : Gets a message-handler pretty print form INPUTS : 1) Address of the handler's class 2) Index of the handler RETURNS : TRUE if printable, FALSE otherwise SIDE EFFECTS : None NOTES : None ********************************************************/#if IBM_TBC#pragma argsused#endifgloble char *EnvGetDefmessageHandlerPPForm( void *theEnv, void *ptr, int theIndex) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(theEnv)#endif return(((DEFCLASS *) ptr)->handlers[theIndex-1].ppForm); }/******************************************************************* NAME : EnvListDefmessageHandlers DESCRIPTION : Lists message-handlers for a class INPUTS : 1) The logical name of the output 2) Class name (NULL to display all handlers) 3) A flag indicating whether to list inherited handlers or not RETURNS : Nothing useful SIDE EFFECTS : None NOTES : None *******************************************************************/globle void EnvListDefmessageHandlers( void *theEnv, char *logName, void *vptr, int inhp) { DEFCLASS *cls; long cnt; PACKED_CLASS_LINKS plinks; if (vptr != NULL) { cls = (DEFCLASS *) vptr; if (inhp) cnt = DisplayHandlersInLinks(theEnv,logName,&cls->allSuperclasses,0); else { plinks.classCount = 1; plinks.classArray = &cls; cnt = DisplayHandlersInLinks(theEnv,logName,&plinks,0); } } else { plinks.classCount = 1; cnt = 0L; for (cls = (DEFCLASS *) EnvGetNextDefclass(theEnv,NULL) ; cls != NULL ; cls = (DEFCLASS *) EnvGetNextDefclass(theEnv,(void *) cls)) { plinks.classArray = &cls; cnt += DisplayHandlersInLinks(theEnv,logName,&plinks,0); } } PrintTally(theEnv,logName,cnt,"message-handler","message-handlers"); }/******************************************************************** NAME : EnvPreviewSend DESCRIPTION : Displays a list of the core for a message describing shadows,etc. INPUTS : 1) Logical name of output 2) Class pointer 3) Message name-string RETURNS : Nothing useful SIDE EFFECTS : Temporary core created and destroyed NOTES : None ********************************************************************/globle void EnvPreviewSend( void *theEnv, char *logicalName, void *clsptr, char *msgname) { HANDLER_LINK *core; SYMBOL_HN *msym; msym = FindSymbolHN(theEnv,msgname); if (msym == NULL) return; core = FindPreviewApplicableHandlers(theEnv,(DEFCLASS *) clsptr,msym); if (core != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -