⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgfun.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
      if (hnd[arr[i]].type == type)        return(&hnd[arr[i]]);     }   return(NULL);  }  /***********************************************************  NAME         : FindHandlerByAddress  DESCRIPTION  : Uses a binary search on a class's                   handler header array  INPUTS       : 1) The class address                 2) The handler symbolic name                 3) The handler type (MPRIMARY,etc.)  RETURNS      : The index of the found handler,                   -1 if not found  SIDE EFFECTS : None  NOTES        : Assumes array is in ascending order                   1st key: symbolic name of handler                   2nd key: type of handler ***********************************************************/globle int FindHandlerByIndex(cls,name,type)  DEFCLASS *cls;  SYMBOL_HN *name;  unsigned type;  {   register int b,i;   HANDLER *hnd;   unsigned *arr;      if ((b = FindHandlerNameGroup(cls,name)) == -1)     return(-1);   arr = cls->handlerOrderMap;   hnd = cls->handlers;   for (i = b ; i < cls->handlerCount ; i++)     {      if (hnd[arr[i]].name != name)        return(-1);      if (hnd[arr[i]].type == type)        return(arr[i]);     }   return(-1);  }/*****************************************************  NAME         : FindHandlerNameGroup  DESCRIPTION  : Uses a binary search on a class's                   handler header array  INPUTS       : 1) The class address                 2) The handler symbolic name  RETURNS      : The index of the found handler group                   -1 if not found  SIDE EFFECTS : None  NOTES        : Assumes array is in ascending order                   1st key: handler name symbol bucket *****************************************************/globle int FindHandlerNameGroup(cls,name)  DEFCLASS *cls;  SYMBOL_HN *name;  {   register int b,e,i,j;   HANDLER *hnd;   unsigned *arr;   int start;      if (cls->handlerCount == 0)     return(-1);   hnd = cls->handlers;   arr = cls->handlerOrderMap;   b = 0;   e = cls->handlerCount-1;   start = -1;   do      {      i = (b+e)/2;      if (name->bucket == hnd[arr[i]].name->bucket)        {         for (j = i ; j >= b ; j--)           {            if (hnd[arr[j]].name == name)              start = j;            if (hnd[arr[j]].name->bucket != name->bucket)              break;           }         if (start != -1)           return(start);         for (j = i+1 ; j <= e ; j++)           {            if (hnd[arr[j]].name == name)              return(j);            if (hnd[arr[j]].name->bucket != name->bucket)              return(-1);           }         return(-1);        }      else if (name->bucket < hnd[arr[i]].name->bucket)        e = i-1;      else        b = i+1;     }   while (b <= e);   return(-1);  }  /***************************************************  NAME         : HandlerDeleteError  DESCRIPTION  : Prints out an error message when                   handlers cannot be deleted  INPUTS       : Name-string of the class  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : None ***************************************************/globle VOID HandlerDeleteError(cname)  char *cname;  {   PrintErrorID("MSGFUN",8,CLIPS_FALSE);   PrintCLIPS(WERROR,"Unable to delete message-handler(s) from class ");   PrintCLIPS(WERROR,cname);   PrintCLIPS(WERROR,".\n");  }#if DEBUGGING_FUNCTIONS/********************************************************************  NAME         : DisplayCore  DESCRIPTION  : Gives a schematic "printout" of the                   core framework for a message showing                   arounds, primaries, shadows etc.                 This routine uses recursion to print indentation                   to indicate shadowing and where handlers begin                   and end execution wrt one another.  INPUTS       : 1) Logical name of output                 2) The remaining core                 3) The number of handlers this (partial) core                    shadows  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : Expects that the core was created in PREVIEW mode,                   i.e. implicit handlers are SLOT_DESC addresses                   (in PERFORM mode they are INSTANCE_SLOT addresses)                 Assumes (partial) core is not empty ********************************************************************/globle VOID DisplayCore(logicalName,core,sdepth)  char *logicalName;  HANDLER_LINK *core;  int sdepth;  {#if IMPERATIVE_MESSAGE_HANDLERS   if (core->hnd->type == MAROUND)     {      PrintPreviewHandler(logicalName,core,sdepth,BEGIN_TRACE);      if (core->nxt != NULL)        DisplayCore(logicalName,core->nxt,sdepth+1);      PrintPreviewHandler(logicalName,core,sdepth,END_TRACE);     }   else#endif     {#if AUXILIARY_MESSAGE_HANDLERS      while ((core != NULL) ? (core->hnd->type == MBEFORE) : CLIPS_FALSE)        {         PrintPreviewHandler(logicalName,core,sdepth,BEGIN_TRACE);         PrintPreviewHandler(logicalName,core,sdepth,END_TRACE);         core = core->nxt;        }      if ((core != NULL) ? (core->hnd->type == MPRIMARY) : CLIPS_FALSE)#endif        core = DisplayPrimaryCore(logicalName,core,sdepth);#if AUXILIARY_MESSAGE_HANDLERS      while ((core != NULL) ? (core->hnd->type == MAFTER) : CLIPS_FALSE)        {         PrintPreviewHandler(logicalName,core,sdepth,BEGIN_TRACE);         PrintPreviewHandler(logicalName,core,sdepth,END_TRACE);         core = core->nxt;        }#endif     }  }/*******************************************************************  NAME         : FindPreviewApplicableHandlers  DESCRIPTION  : See FindApplicableHandlers                 However, this function only examines classes rather                   than instances for implicit slot-accessors  INPUTS       : 1) The class address                 2) The message name symbol  RETURNS      : The links of applicable handlers, NULL on errors  SIDE EFFECTS : Links are allocated for the list  NOTES        : None ******************************************************************/globle HANDLER_LINK *FindPreviewApplicableHandlers(cls,mname)  DEFCLASS *cls;  SYMBOL_HN *mname;  {   register int i;   HANDLER_LINK *tops[4],*bots[4];      for (i = MAROUND ; i <= MAFTER ; i++)     tops[i] = bots[i] = NULL;      for (i = 0 ; i < cls->allSuperclasses.classCount ; i++)     FindApplicableOfName(cls->allSuperclasses.classArray[i],tops,bots,mname);   return(JoinHandlerLinks(tops,bots,mname));  }  /***********************************************************  NAME         : WatchMessage  DESCRIPTION  : Prints a condensed description of a                   message and its arguments  INPUTS       : 1) The output logical name                 2) BEGIN_TRACE or END_TRACE string  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : Uses the global variables ProcParamArray                   and CurrentMessageName ***********************************************************/globle VOID WatchMessage(log,tstring)  char *log;  char *tstring;  {   PrintCLIPS(log,"MSG ");   PrintCLIPS(log,tstring);   PrintCLIPS(log," ");   PrintCLIPS(log,ValueToString(CurrentMessageName));   PrintCLIPS(log," ED:");   PrintLongInteger(log,(long) CurrentEvaluationDepth);   PrintProcParamArray(log);  }  /***********************************************************  NAME         : WatchHandler  DESCRIPTION  : Prints a condensed description of a                   message-handler and its arguments  INPUTS       : 1) The output logical name                 2) The handler address                 3) BEGIN_TRACE or END_TRACE string  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : Uses the global variables ProcParamArray                   and CurrentMessageName ***********************************************************/globle VOID WatchHandler(log,hndl,tstring)  char *log;  HANDLER_LINK *hndl;  char *tstring;  {   HANDLER *hnd;      PrintCLIPS(log,"HND ");   PrintCLIPS(log,tstring);   PrintCLIPS(log," ");   hnd = hndl->hnd;   PrintHandler(WTRACE,hnd,CLIPS_TRUE);   PrintCLIPS(log,"       ED:");   PrintLongInteger(log,(long) CurrentEvaluationDepth);   PrintProcParamArray(log);  }#endif /* DEBUGGING_FUNCTIONS *//* =========================================   *****************************************          INTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */   #if DEBUGGING_FUNCTIONS/********************************************************************  NAME         : DisplayPrimaryCore  DESCRIPTION  : Gives a schematic "printout" of the primary                   message showing other shadowed primaries                 This routine uses recursion to print indentation                   to indicate shadowing and where handlers begin                   and end execution wrt one another.  INPUTS       : 1) The logical name of the output                 2) The remaining core                 3) The number of handlers this (partial) core                    shadows  RETURNS      : The address of the handler following the primary                   group of handlers in the core  SIDE EFFECTS : None  NOTES        : Expects that the core was created in PREVIEW mode,                   i.e. implicit handlers are SLOT_DESC addresses                   (in PERFORM mode they are INSTANCE_SLOT addresses)                 Assumes (partial) core is not empty ********************************************************************/static HANDLER_LINK *DisplayPrimaryCore(logicalName,core,pdepth)  char *logicalName;  HANDLER_LINK *core;  int pdepth;  {   register HANDLER_LINK *rtn;      PrintPreviewHandler(logicalName,core,pdepth,BEGIN_TRACE);#if IMPERATIVE_MESSAGE_HANDLERS   if ((core->nxt != NULL) ? (core->nxt->hnd->type == MPRIMARY) : CLIPS_FALSE)     rtn = DisplayPrimaryCore(logicalName,core->nxt,pdepth+1);   else#endif     rtn = core->nxt;   PrintPreviewHandler(logicalName,core,pdepth,END_TRACE);   return(rtn);  }  /***************************************************  NAME         : PrintPreviewHandler  DESCRIPTION  : Displays a message preview  INPUTS       : 1) The logical name of the output                 2) Handler-link                 3) Number of handlers shadowed                 4) The trace-string  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : None ***************************************************/static VOID PrintPreviewHandler(logicalName,cptr,sdepth,tstr)  char *logicalName;  HANDLER_LINK *cptr;  int sdepth;  char *tstr;  {   register int i;      for (i = 0 ; i < sdepth ; i++)     PrintCLIPS(logicalName,"| ");   PrintCLIPS(logicalName,tstr);   PrintCLIPS(logicalName," ");   PrintHandler(logicalName,cptr->hnd,CLIPS_TRUE);  }#endif  #endif/***************************************************  NAME         :   DESCRIPTION  :   INPUTS       :   RETURNS      :   SIDE EFFECTS :   NOTES        :  ***************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -