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

📄 bload.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
         if ((objsmaxread / 2) == 0)           {            if ((*oldOutOfMemoryFunction)(space) == CLIPS_TRUE)              {               SetOutOfMemoryFunction(oldOutOfMemoryFunction);               return;              }           }         else           objsmaxread /= 2;        }     }   while (buf == NULL);      SetOutOfMemoryFunction(oldOutOfMemoryFunction);      i = 0L;   do     {      objsread = (objsmaxread > (objcnt - i)) ? (objcnt - i) : objsmaxread;      GenRead((VOID *) buf,objsread * objsz);      for (bi = 0L ; bi < objsread ; bi++ , i++)        (*objupdate)(buf + objsz * bi,i);     }   while (i < objcnt);   genlongfree((VOID *) buf,space);  }/**********************************************//* ReadNeededFunctions: Reads in the names of *//*   functions needed by the binary image.    *//**********************************************/static struct FunctionDefinition * HUGE_ADDR *ReadNeededFunctions(numberOfFunctions,                                                                  error)  long int *numberOfFunctions;  int *error;  {   char *functionNames, *namePtr;   unsigned long int space,temp;   long i;   struct FunctionDefinition * HUGE_ADDR *newFunctionArray, *functionPtr;   int functionsNotFound = 0;   /*===================================================*/   /* Determine the number of function names to be read */   /* and the space required for them.                  */   /*===================================================*/   GenRead(numberOfFunctions,(unsigned long) sizeof(long int));   GenRead(&space,(unsigned long) sizeof(unsigned long int));   if (*numberOfFunctions == 0)     {      *error = CLIPS_FALSE;      return(NULL);     }   /*=======================================*/   /* Allocate area for strings to be read. */   /*=======================================*/   functionNames = (char *) genlongalloc(space);   GenRead((VOID *) functionNames,space);   /*====================================================*/   /* Store the function pointers in the function array. */   /*====================================================*/   temp = (unsigned long) sizeof(struct FunctionDefinition *) * *numberOfFunctions;   newFunctionArray = (struct FunctionDefinition **) genlongalloc(temp);   namePtr = functionNames;   functionPtr = NULL;   for (i = 0; i < *numberOfFunctions; i++)     {      if ((functionPtr = FastFindFunction(namePtr,functionPtr)) == NULL)        {         if (! functionsNotFound)           {            PrintErrorID("BLOAD",6,CLIPS_FALSE);            PrintCLIPS(WERROR,"The following undefined functions are ");            PrintCLIPS(WERROR,"referenced by this binary image:\n");           }         PrintCLIPS(WERROR,"   ");         PrintCLIPS(WERROR,namePtr);         PrintCLIPS(WERROR,"\n");         functionsNotFound = 1;        }      newFunctionArray[i] = functionPtr;      namePtr += strlen(namePtr) + 1;     }   /*==========================================*/   /* Free the memory used by the name buffer. */   /*==========================================*/   genlongfree((VOID *) functionNames,space);   /*==================================================*/   /* If any of the required functions were not found, */   /* then free the memory used by the function array. */   /*==================================================*/   if (functionsNotFound)     {      genlongfree((VOID *) newFunctionArray,temp);      newFunctionArray = NULL;     }   /*===================================*/   /* Set globals to appropriate values */   /* and return the function array.    */   /*===================================*/   *error = functionsNotFound;   return(newFunctionArray);  }/***********************************************//* FastFindFunction: Search the CLIPS function *//*   list for a specific function.             *//***********************************************/static struct FunctionDefinition *FastFindFunction(functionName,lastFunction)  char *functionName;  struct FunctionDefinition *lastFunction;  {   struct FunctionDefinition *theList, *theFunction;   /*==============================*/   /* Get the CLIPS function list. */   /*==============================*/      theList = GetFunctionList();   if (theList == NULL) { return(NULL); }   /*=======================================*/   /* If we completed a previous function   */   /* search, start where we last left off. */   /*=======================================*/      if (lastFunction != NULL)     { theFunction = lastFunction->next; }   else     { theFunction = theList; }   /*======================================================*/   /* Traverse the rest of the function list searching for */   /* the named function wrapping around if necessary.     */   /*======================================================*/      while (strcmp(functionName,ValueToString(theFunction->callFunctionName)) != 0)     {      theFunction = theFunction->next;      if (theFunction == lastFunction) return(NULL);      if (theFunction == NULL) theFunction = theList;     }   /*=======================*/   /* Return the pointer to */   /* the found function.   */   /*=======================*/      return(theFunction);  }/******************************************//* Bloaded: Returns TRUE if the current   *//*   environment is the result of a bload *//*   command, otherwise returns FALSE.    *//******************************************/globle BOOLEAN Bloaded()  {   return(BloadActive);  }/*************************************//* ClearBload: Clears a binary image *//*   from the CLIPS environment.     *//*************************************/static int ClearBload()  {   struct BinaryItem *biPtr;   struct callFunctionItem *bfPtr;   int ready,error;   /*=================================================*/   /* Make sure it's safe to clear the bloaded image. */   /*=================================================*/      error = CLIPS_FALSE;   for (bfPtr = ClearBloadReadyFunctions;        bfPtr != NULL;        bfPtr = bfPtr->next)     {      ready = (* ((int (*)(VOID_ARG)) bfPtr->func))();      if (ready == CLIPS_FALSE)        {         if (! error)           {            PrintErrorID("BLOAD",5,CLIPS_FALSE);             PrintCLIPS(WERROR,                       "Some constructs are still in use by the current binary image:\n");           }         PrintCLIPS(WERROR,"   ");         PrintCLIPS(WERROR,bfPtr->name);         PrintCLIPS(WERROR,"\n");         error = CLIPS_TRUE;        }     }   /*==================================================*/   /* If some constructs are still in use and can't be */   /* cleared, indicate the binary load can't continue */   /* and return FALSE to indicate this condition.     */   /*==================================================*/      if (error == CLIPS_TRUE)     {      PrintCLIPS(WERROR,"Binary clear cannot continue.\n");      return(CLIPS_FALSE);     }   /*=============================*/   /* Call bload clear functions. */   /*=============================*/   for (biPtr = ListOfBinaryItems;        biPtr != NULL;        biPtr = biPtr->next)     { if (biPtr->clearFunction != NULL) (*biPtr->clearFunction)(); }        /*===========================*/   /* Free bloaded expressions. */   /*===========================*/      ClearBloadedExpressions();      /*===========================*/   /* Free bloaded constraints. */   /*===========================*/      ClearBloadedConstraints();      /*==================================*/   /* Remove the bload clear function. */   /*==================================*/   BloadActive = CLIPS_FALSE;   RemoveClearFunction("bload");      /*====================================*/   /* Return TRUE to indicate the binary */   /* image was successfully cleared.    */   /*====================================*/      return(CLIPS_TRUE);  }/*************************************************//* AbortBload: Cleans up effects of before-bload *//*   functions in event of failure.              *//*************************************************/static VOID AbortBload()  {   struct callFunctionItem *bfPtr;   for (bfPtr = AbortBloadFunctions;        bfPtr != NULL;        bfPtr = bfPtr->next)     { (*bfPtr->func)(); }  }/********************************************//* AddBeforeBloadFunction: Adds a function  *//*   to the list of functions called before *//*   a binary load occurs.                  *//********************************************/globle VOID AddBeforeBloadFunction(name,func,priority)  char *name;  VOID (*func)(VOID_ARG);  int priority;  {   BeforeBloadFunctions =      AddFunctionToCallList(name,priority,func,BeforeBloadFunctions);  }/*******************************************//* AddAfterBloadFunction: Adds a function  *//*   to the list of functions called after *//*   a binary load occurs.                 *//*******************************************/globle VOID AddAfterBloadFunction(name,func,priority)  char *name;  VOID (*func)(VOID_ARG);  int priority;  {   AfterBloadFunctions =      AddFunctionToCallList(name,priority,func,AfterBloadFunctions);  }/**************************************************//* AddClearBloadReadyFunction: Adds a function to *//*   the list of functions called to determine if *//*   a binary image can be cleared.               *//**************************************************/globle VOID AddClearBloadReadyFunction(name,func,priority)  char *name;  int (*func)(VOID_ARG);  int priority;  {   ClearBloadReadyFunctions =       AddFunctionToCallList(name,priority,                            (VOID (*)(VOID_ARG)) func,                            ClearBloadReadyFunctions);  }/*********************************************//* AddAbortBloadFunction: Adds a function to *//*   the list of functions called if a bload *//*   has to be aborted.                      *//*********************************************/globle VOID AddAbortBloadFunction(name,func,priority)  char *name;  VOID (*func)(VOID_ARG);  int priority;  {   AbortBloadFunctions = AddFunctionToCallList(name,priority,func,AbortBloadFunctions);  }/*******************************************************  NAME         : BloadOutOfMemoryFunction  DESCRIPTION  : Memory function used by bload to                   force CLIPS not to exit when out                   of memory - used by BloadandRefresh  INPUTS       : The memory request size (unused)  RETURNS      : CLIPS_TRUE (indicates a failure and for                 the CLIPS memory functions to simply                 return a NULL pointer)  SIDE EFFECTS : None  NOTES        : None *******************************************************/#if IBM_TBC#pragma argsused#endifstatic int BloadOutOfMemoryFunction(size)  unsigned long size;  {#if MAC_MPW || MAC_MCW#pragma unused(size)#endif   return(CLIPS_TRUE);  }  /*****************************************************//* CannotLoadWithBloadMessage: Generic error message *//*   for indicating that a construct can't be loaded *//*   when a binary image is active.                  *//*****************************************************/globle VOID CannotLoadWithBloadMessage(constructName)  char *constructName;  {         PrintErrorID("BLOAD",1,CLIPS_TRUE);   PrintCLIPS(WERROR,"Cannot load ");   PrintCLIPS(WERROR,constructName);   PrintCLIPS(WERROR," construct with binary load in effect.\n");  }#endif /* (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) *//**************************************//* BloadCommand: CLIPS access routine *//*   for the bload command.           *//**************************************/globle int BloadCommand()  {#if (! RUN_TIME) && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)   char *fileName;   if (ArgCountCheck("bload",EXACTLY,1) == -1) return(CLIPS_FALSE);   fileName = GetFileName("bload",1);   if (fileName != NULL) return(Bload(fileName));#endif   return(CLIPS_FALSE);  }

⌨️ 快捷键说明

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