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

📄 bsave.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        biPtr != NULL;        biPtr = biPtr->next)     { if (biPtr->findFunction != NULL) (*biPtr->findFunction)(theEnv); }  }/****************************************************//* WriteNeededFunctions: Writes the names of needed *//*   functions to the binary save file.             *//****************************************************/static void WriteNeededFunctions(  void *theEnv,  FILE *fp)  {   unsigned long int count = 0;   size_t space, length;   struct FunctionDefinition *functionList;   /*================================================*/   /* Assign each function an index if it is needed. */   /*================================================*/   for (functionList = GetFunctionList(theEnv);        functionList != NULL;        functionList = functionList->next)     {      if (functionList->bsaveIndex)        { functionList->bsaveIndex = (short int) count++; }      else        { functionList->bsaveIndex = -1; }     }   /*===================================================*/   /* Write the number of function names to be written. */   /*===================================================*/   GenWrite(&count,(unsigned long) sizeof(unsigned long int),fp);   if (count == 0)     {      GenWrite(&count,(unsigned long) sizeof(unsigned long int),fp);      return;     }   /*================================*/   /* Determine the amount of space  */   /* needed for the function names. */   /*================================*/   space = FunctionBinarySize(theEnv);   GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp);   /*===============================*/   /* Write out the function names. */   /*===============================*/   for (functionList = GetFunctionList(theEnv);        functionList != NULL;        functionList = functionList->next)     {      if (functionList->bsaveIndex >= 0)        {         length = strlen(ValueToString(functionList->callFunctionName)) + 1;         GenWrite(ValueToString(functionList->callFunctionName),(unsigned long) length,fp);        }     }  }/*********************************************//* FunctionBinarySize: Determines the number *//*   of bytes needed to save all of the      *//*   function names in the binary save file. *//*********************************************/static size_t FunctionBinarySize(  void *theEnv)  {   size_t size = 0;   struct FunctionDefinition *functionList;   for (functionList = GetFunctionList(theEnv);        functionList != NULL;        functionList = functionList->next)     {      if (functionList->bsaveIndex >= 0)        { size += strlen(ValueToString(functionList->callFunctionName)) + 1; }     }   return(size);  }/***************************************************//* SaveBloadCount: Used to save the data structure *//*   count values when a binary save command is    *//*   issued when a binary image is loaded.         *//***************************************************/globle void SaveBloadCount(  void *theEnv,  long cnt)  {   BLOADCNTSV *tmp, *prv;   tmp = get_struct(theEnv,bloadcntsv);   tmp->val = cnt;   tmp->nxt = NULL;   if (BsaveData(theEnv)->BloadCountSaveTop == NULL)     { BsaveData(theEnv)->BloadCountSaveTop = tmp; }   else     {      prv = BsaveData(theEnv)->BloadCountSaveTop;      while (prv->nxt != NULL)        { prv = prv->nxt; }      prv->nxt = tmp;     }  }/**************************************************//* RestoreBloadCount: Restores the data structure *//*   count values after a binary save command is  *//*   completed when a binary image is loaded.     *//**************************************************/globle void RestoreBloadCount(  void *theEnv,  long *cnt)  {   BLOADCNTSV *tmp;   *cnt = BsaveData(theEnv)->BloadCountSaveTop->val;   tmp = BsaveData(theEnv)->BloadCountSaveTop;   BsaveData(theEnv)->BloadCountSaveTop = BsaveData(theEnv)->BloadCountSaveTop->nxt;   rtn_struct(theEnv,bloadcntsv,tmp);  }/**********************************************//* MarkNeededItems: Examines an expression to *//*   determine which items are needed to save *//*   an expression as part of a binary image. *//**********************************************/globle void MarkNeededItems(  void *theEnv,  struct expr *testPtr)  {   while (testPtr != NULL)     {      switch (testPtr->type)        {         case SYMBOL:         case STRING:         case GBL_VARIABLE:         case INSTANCE_NAME:            ((SYMBOL_HN *) testPtr->value)->neededSymbol = TRUE;            break;         case FLOAT:            ((FLOAT_HN *) testPtr->value)->neededFloat = TRUE;            break;         case INTEGER:            ((INTEGER_HN *) testPtr->value)->neededInteger = TRUE;            break;         case FCALL:            ((struct FunctionDefinition *) testPtr->value)->bsaveIndex = TRUE;            break;         case RVOID:           break;         default:           if (EvaluationData(theEnv)->PrimitivesArray[testPtr->type] == NULL) break;           if (EvaluationData(theEnv)->PrimitivesArray[testPtr->type]->bitMap)             { ((BITMAP_HN *) testPtr->value)->neededBitMap = TRUE; }           break;        }      if (testPtr->argList != NULL)        { MarkNeededItems(theEnv,testPtr->argList); }      testPtr = testPtr->nextArg;     }  }/******************************************************//* WriteBinaryHeader: Writes a binary header used for *//*   verification when a binary image is loaded.      *//******************************************************/static void WriteBinaryHeader(  void *theEnv,  FILE *fp)  {   GenWrite(BloadData(theEnv)->BinaryPrefixID,(unsigned long) strlen(BloadData(theEnv)->BinaryPrefixID) + 1,fp);   GenWrite(BloadData(theEnv)->BinaryVersionID,(unsigned long) strlen(BloadData(theEnv)->BinaryVersionID) + 1,fp);  }/******************************************************//* WriteBinaryFooter: Writes a binary footer used for *//*   verification when a binary image is loaded.      *//******************************************************/static void WriteBinaryFooter(  void *theEnv,  FILE *fp)  {   char footerBuffer[CONSTRUCT_HEADER_SIZE];   genstrncpy(footerBuffer,BloadData(theEnv)->BinaryPrefixID,CONSTRUCT_HEADER_SIZE);   GenWrite(footerBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE,fp);  }#endif /* BLOAD_AND_BSAVE */#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE/**********************************************************//* AddBinaryItem: Informs the bload/bsave commands of the *//*   appropriate access functions needed to save/load the *//*   data structures of a construct or other "item" to a  *//*   binary file.                                         *//**********************************************************/globle intBool AddBinaryItem(  void *theEnv,  char *name,  int priority,  void (*findFunction)(void *),  void (*expressionFunction)(void *,FILE *),  void (*bsaveStorageFunction)(void *,FILE *),  void (*bsaveFunction)(void *,FILE *),  void (*bloadStorageFunction)(void *),  void (*bloadFunction)(void *),  void (*clearFunction)(void *))  {   struct BinaryItem *newPtr, *currentPtr, *lastPtr = NULL;   /*========================================*/   /* Create the binary item data structure. */   /*========================================*/   newPtr = get_struct(theEnv,BinaryItem);   newPtr->name = name;   newPtr->findFunction = findFunction;   newPtr->expressionFunction = expressionFunction;   newPtr->bsaveStorageFunction = bsaveStorageFunction;   newPtr->bsaveFunction = bsaveFunction;   newPtr->bloadStorageFunction = bloadStorageFunction;   newPtr->bloadFunction = bloadFunction;   newPtr->clearFunction = clearFunction;   newPtr->priority = priority;   /*=================================*/   /* If no binary items are defined, */   /* just put the item on the list.  */   /*=================================*/   if (BsaveData(theEnv)->ListOfBinaryItems == NULL)     {      newPtr->next = NULL;      BsaveData(theEnv)->ListOfBinaryItems = newPtr;      return(TRUE);     }   /*=========================================*/   /* Otherwise, place the binary item at the */   /* appropriate place in the list of binary */   /* items based on its priority.            */   /*=========================================*/   currentPtr = BsaveData(theEnv)->ListOfBinaryItems;   while ((currentPtr != NULL) ? (priority < currentPtr->priority) : FALSE)     {      lastPtr = currentPtr;      currentPtr = currentPtr->next;     }   if (lastPtr == NULL)     {      newPtr->next = BsaveData(theEnv)->ListOfBinaryItems;      BsaveData(theEnv)->ListOfBinaryItems = newPtr;     }   else     {      newPtr->next = currentPtr;      lastPtr->next = newPtr;     }   /*==================================*/   /* Return TRUE to indicate the item */   /* was successfully added.          */   /*==================================*/   return(TRUE);  }#endif /* BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE */

⌨️ 快捷键说明

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