📄 bsave.c
字号:
unsigned long int space, count = 0, length; struct FunctionDefinition *functionList; /*================================================*/ /* Assign each function an index if it is needed. */ /*================================================*/ for (functionList = GetFunctionList(); 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(); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*===============================*/ /* Write out the function names. */ /*===============================*/ for (functionList = GetFunctionList(); 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 unsigned long int FunctionBinarySize() { unsigned long int size = 0; struct FunctionDefinition *functionList; for (functionList = GetFunctionList(); 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(cnt) long cnt; { BLOADCNTSV *tmp, *prv; tmp = get_struct(bloadcntsv); tmp->val = cnt; tmp->nxt = NULL; if (BloadCountSaveTop == NULL) { BloadCountSaveTop = tmp; } else { prv = 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(cnt) long *cnt; { BLOADCNTSV *tmp; *cnt = BloadCountSaveTop->val; tmp = BloadCountSaveTop; BloadCountSaveTop = BloadCountSaveTop->nxt; rtn_struct(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(testPtr) struct expr *testPtr; { while (testPtr != NULL) { switch (testPtr->type) { case SYMBOL: case STRING: case GBL_VARIABLE: case INSTANCE_NAME: ((SYMBOL_HN *) testPtr->value)->neededSymbol = CLIPS_TRUE; break; case FLOAT: ((FLOAT_HN *) testPtr->value)->neededFloat = CLIPS_TRUE; break; case INTEGER: ((INTEGER_HN *) testPtr->value)->neededInteger = CLIPS_TRUE; break; case FCALL: ((struct FunctionDefinition *) testPtr->value)->bsaveIndex = CLIPS_TRUE; break; case RVOID: break; default: if (PrimitivesArray[testPtr->type] == NULL) break; if (PrimitivesArray[testPtr->type]->bitMap) { ((BITMAP_HN *) testPtr->value)->neededBitMap = CLIPS_TRUE; } break; } if (testPtr->argList != NULL) { MarkNeededItems(testPtr->argList); } testPtr = testPtr->nextArg; } } /******************************************************//* WriteBinaryHeader: Writes a binary header used for *//* verification when a binary image is loaded. *//******************************************************/static VOID WriteBinaryHeader(fp) FILE *fp; { GenWrite(BinaryPrefixID,(unsigned long) strlen(BinaryPrefixID) + 1,fp); GenWrite(BinaryVersionID,(unsigned long) strlen(BinaryVersionID) + 1,fp); }/******************************************************//* WriteBinaryFooter: Writes a binary footer used for *//* verification when a binary image is loaded. *//******************************************************/static VOID WriteBinaryFooter(fp) FILE *fp; { char footerBuffer[CONSTRUCT_HEADER_SIZE]; strncpy(footerBuffer,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 BOOLEAN AddBinaryItem(name,priority,findFunction,expressionFunction, bsaveStorageFunction,bsaveFunction, bloadStorageFunction,bloadFunction,clearFunction) char *name; int priority;#if ANSI_COMPILER VOID (*findFunction)(void); VOID (*expressionFunction)(FILE *); VOID (*bsaveStorageFunction)(FILE *); VOID (*bsaveFunction)(FILE *); VOID (*bloadStorageFunction)(void); VOID (*bloadFunction)(void); VOID (*clearFunction)(void);#else VOID (*findFunction)(); VOID (*expressionFunction)(); VOID (*bsaveStorageFunction)(); VOID (*bsaveFunction)(); VOID (*bloadStorageFunction)(); VOID (*bloadFunction)(); VOID (*clearFunction)();#endif { struct BinaryItem *newPtr, *currentPtr, *lastPtr = NULL; /*========================================*/ /* Create the binary item data structure. */ /*========================================*/ newPtr = get_struct(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 (ListOfBinaryItems == NULL) { newPtr->next = NULL; ListOfBinaryItems = newPtr; return(CLIPS_TRUE); } /*=========================================*/ /* Otherwise, place the binary item at the */ /* appropriate place in the list of binary */ /* items based on its priority. */ /*=========================================*/ currentPtr = ListOfBinaryItems; while ((currentPtr != NULL) ? (priority < currentPtr->priority) : CLIPS_FALSE) { lastPtr = currentPtr; currentPtr = currentPtr->next; } if (lastPtr == NULL) { newPtr->next = ListOfBinaryItems; ListOfBinaryItems = newPtr; } else { newPtr->next = currentPtr; lastPtr->next = newPtr; } /*==================================*/ /* Return TRUE to indicate the item */ /* was successfully added. */ /*==================================*/ return(CLIPS_TRUE); }#endif /* BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE */#if BLOAD_AND_BSAVE || BSAVE_INSTANCES/***********************************************//* GenWrite: Generic routine for writing to a *//* file. No machine specific code as of yet. *//***********************************************/globle VOID GenWrite(dataPtr,size,fp) VOID *dataPtr; unsigned long size; FILE *fp; { if (size == 0) return; fwrite(dataPtr,(CLIPS_STD_SIZE) size,1,fp); }#endif /* BLOAD_AND_BSAVE || BSAVE_INSTANCES */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -