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

📄 utility.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
static BOOLEAN RemoveCPFunction(name,head)  char *name;  struct cleanupFunction **head;  {   struct cleanupFunction *currentPtr, *lastPtr;   lastPtr = NULL;   currentPtr = *head;   while (currentPtr != NULL)     {      if (strcmp(name,currentPtr->name) == 0)        {         if (lastPtr == NULL)           { *head = currentPtr->next; }         else           { lastPtr->next = currentPtr->next; }         rtn_struct(cleanupFunction,currentPtr);         return(CLIPS_TRUE);        }      lastPtr = currentPtr;      currentPtr = currentPtr->next;     }   return(CLIPS_FALSE);  }/*****************************************************//* StringPrintForm: Generates printed representation *//*   of a string. Replaces / with // and " with /".  *//*****************************************************/globle char *StringPrintForm(str)  char *str;  {   int i = 0, pos = 0, max = 0;   char *theString = NULL;   VOID *thePtr;   theString = ExpandStringWithChar('"',theString,&pos,&max,max+80);   while (str[i] != EOS)     {      if ((str[i] == '"') || (str[i] == '\\'))        {         theString = ExpandStringWithChar('\\',theString,&pos,&max,max+80);         theString = ExpandStringWithChar(str[i],theString,&pos,&max,max+80);        }      else        { theString = ExpandStringWithChar(str[i],theString,&pos,&max,max+80); }      i++;     }   theString = ExpandStringWithChar('"',theString,&pos,&max,max+80);   thePtr = AddSymbol(theString);   rm(theString,max);   return(ValueToString(thePtr));  }/***********************************************************//* AppendStrings: Appends two strings together. The string *//*   created is added to the SymbolTable, so it is not     *//*   necessary to deallocate the string returned.          *//***********************************************************/globle char *AppendStrings(str1,str2)  char *str1, *str2;  {   int pos = 0, max = 0;   char *theString = NULL;   VOID *thePtr;   theString = AppendToString(str1,theString,&pos,&max);   theString = AppendToString(str2,theString,&pos,&max);   thePtr = AddSymbol(theString);   rm(theString,max);   return(ValueToString(thePtr));  }/******************************************************//* AppendToString: Appends a string to another string *//*   (expanding the other string if necessary).       *//******************************************************/globle char *AppendToString(appendStr,oldStr,oldPos,oldMax)  char *appendStr, *oldStr;  int *oldPos, *oldMax;  {   int length;   /*=========================================*/   /* Expand the old string so it can contain */   /* the new string (if necessary).          */   /*=========================================*/      length = strlen(appendStr);   if (length + *oldPos + 1 > *oldMax)     {      oldStr = genrealloc(oldStr,(unsigned) *oldMax,(unsigned) length + *oldPos + 1);      *oldMax = length + *oldPos + 1;     }   /*==============================================================*/   /* Return NULL if the old string was not successfully expanded. */   /*==============================================================*/      if (oldStr == NULL) { return(NULL); }   /*===============================================*/   /* Append the new string to the expanded string. */   /*===============================================*/      strcpy(&oldStr[*oldPos],appendStr);   *oldPos += length;   /*============================================================*/   /* Return the expanded string containing the appended string. */   /*============================================================*/      return(oldStr);  }/*******************************************************//* AppendNToString: Appends a string to another string *//*   (expanding the other string if necessary). Only a *//*   specified number of characters are appended from  *//*   the string.                                       *//*******************************************************/globle char *AppendNToString(appendStr,oldStr,length,oldPos,oldMax)  char *appendStr, *oldStr;  int length;  int *oldPos, *oldMax;  {   int lengthWithEOS;   /*====================================*/   /* Determine the number of characters */   /* to be appended from the string.    */   /*====================================*/      if (appendStr[length-1] != '\0') lengthWithEOS = length + 1;   else lengthWithEOS = length;      /*=========================================*/   /* Expand the old string so it can contain */   /* the new string (if necessary).          */   /*=========================================*/   if (lengthWithEOS + *oldPos > *oldMax)     {      oldStr = genrealloc(oldStr,(unsigned) *oldMax,(unsigned) *oldPos + lengthWithEOS);      *oldMax = *oldPos + lengthWithEOS;     }   /*==============================================================*/   /* Return NULL if the old string was not successfully expanded. */   /*==============================================================*/      if (oldStr == NULL) { return(NULL); }      /*==================================*/   /* Append N characters from the new */   /* string to the expanded string.   */   /*==================================*/   strncpy(&oldStr[*oldPos],appendStr,(CLIPS_STD_SIZE) length);   *oldPos += (lengthWithEOS - 1);   oldStr[*oldPos] = '\0';      /*============================================================*/   /* Return the expanded string containing the appended string. */   /*============================================================*/   return(oldStr);  }/*******************************************************//* ExpandStringWithChar: Adds a character to a string, *//*   reallocating space for the string if it needs to  *//*   be enlarged. The backspace character causes the   *//*   size of the string to reduced if it is "added" to *//*   the string.                                       *//*******************************************************/globle char *ExpandStringWithChar(inchar,str,pos,max,newSize)  int inchar;  char *str;  int *max, *pos, newSize;  {   if (*pos >= (*max - 1))     {      str = genrealloc(str,(unsigned) *max,(unsigned) newSize);      *max = newSize;     }  if (inchar != '\b')    {     str[*pos] = (char) inchar;     (*pos)++;     str[*pos] = '\0';    }  else    {     if (*pos > 0) (*pos)--;     str[*pos] = '\0';    }   return(str);  }/*****************************************************************//* AddFunctionToCallList: Adds a function to a list of functions *//*   which are called to perform certain operations (e.g. clear, *//*   reset, and bload functions).                                *//*****************************************************************/globle struct callFunctionItem *AddFunctionToCallList(name,priority,func,head)  char *name;  int priority;#if ANSI_COMPILER  VOID (*func)(void);#else  VOID (*func)();#endif  struct callFunctionItem *head;  {   struct callFunctionItem *newPtr, *currentPtr, *lastPtr = NULL;   newPtr = get_struct(callFunctionItem);   newPtr->name = name;   newPtr->func = func;   newPtr->priority = priority;   if (head == NULL)     {      newPtr->next = NULL;      return(newPtr);     }   currentPtr = head;   while ((currentPtr != NULL) ? (priority < currentPtr->priority) : CLIPS_FALSE)     {      lastPtr = currentPtr;      currentPtr = currentPtr->next;     }   if (lastPtr == NULL)     {      newPtr->next = head;      head = newPtr;     }   else     {      newPtr->next = currentPtr;      lastPtr->next = newPtr;     }        return(head);  }  /*****************************************************************//* RemoveFunctionFromCallList: Removes a function from a list of *//*   functions which are called to perform certain operations    *//*   (e.g. clear, reset, and bload functions).                   *//*****************************************************************/globle struct callFunctionItem *RemoveFunctionFromCallList(name,head,found)  char *name;  struct callFunctionItem *head;  int *found;  {   struct callFunctionItem *currentPtr, *lastPtr;   *found = CLIPS_FALSE;   lastPtr = NULL;   currentPtr = head;   while (currentPtr != NULL)     {      if (strcmp(name,currentPtr->name) == 0)        {         *found = CLIPS_TRUE;         if (lastPtr == NULL)           { head = currentPtr->next; }         else           { lastPtr->next = currentPtr->next; }                    rtn_struct(callFunctionItem,currentPtr);         return(head);        }              lastPtr = currentPtr;      currentPtr = currentPtr->next;     }   return(head);  }  /********************************************//* YieldTime: Yields time to a user-defined *//*   function. Intended to allow foreground *//*   application responsiveness when CLIPS  *//*   is running in the background.          *//********************************************/void YieldTime()  {   if (YieldTimeFunction != NULL)     { (*YieldTimeFunction)(); }  }

⌨️ 快捷键说明

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