📄 xb.c
字号:
/* -*-Mode:C; tab-width:4; indent-tabs-mode:t; c-file-style:"stroustrup";-*- *//* Code for the ExtraBlock */#include "xb.h"#include "progectRsc.h"#include "task.h"#include "progect.h"/**************************************************************************** * Name : TaskGetExtraBlockHeadPtr * Desc : get the given extra block of the given task * Parm : * -> the task * Out : * Auth : lb, 2001-10-16 ***************************************************************************/static MemPtr TaskGetExtraBlockHeadPtr(TaskExtendedRecordType* pTask){ return &pTask->fields.XB;} // static MemPtr TaskGetExtraBlockHeadPtr(TaskExtendedType* pTask)/**************************************************************************** * Name : TaskGetExtraBlockHeadPtrV022 * Desc : get the given extra block of the given task * Parm : * -> the task * Out : * Auth : lb, 31.08.2000 * seagull, 10.10.2000 ***************************************************************************/static MemPtr TaskGetExtraBlockHeadPtrV022(TaskExtendedRecordType* pTask){ Char* pExtra; pExtra = &pTask->fields.task.description + StrLen(&pTask->fields.task.description) + 1; pExtra += StrLen(pExtra) + 1; return (MemPtr)pExtra;} // static MemPtr TaskGetExtraBlockHeadPtrV022(TaskExtendedType* pTask)/**************************************************************************** * Name : TaskSetExtraBlock * Desc : set the given extra block to the given task * Parm : * -> database pointer * -> index of the record * -> pointer to the block * -> size of the block (pass 0 to remove) * Out : * Auth : lb, 31.08.2000 * seagull, 10.10.2000 * Mod : lb, 2001-09-07 * complete rewrite for 0.23 db format ***************************************************************************/pgErr TaskSetExtraBlock(DmOpenRef dbP, UInt16 index, MemPtr s, UInt16 size){ MemHandle h; TaskExtendedRecordType* p; UInt16 oldSize, newSize, oldXBSize; TaskFormatType format = TaskGetFormat(dbP, index); UInt16 offsetLastPart; MemPtr bak; UInt16 bakSize; // find and lock its record h = DmQueryRecord(dbP, index); p = MemHandleLock(h); offsetLastPart = StdFieldsOffset(p); oldSize = MemPtrSize(p); MemHandleUnlock(h); oldXBSize = TaskGetExtraBlock(dbP, index, NULL); newSize = oldSize - oldXBSize + size; if (oldXBSize == 0 && size > 0) newSize += sizeof(UInt16); // add the size field else if (oldXBSize != 0 && size == 0) newSize -= sizeof(UInt16); // sub the size field if (newSize > oldSize) { h = DmResizeRecord(dbP, index, newSize); if (!h) { MessageBox(StrNoMemorySpaces); return pgError; } } h = DmGetRecord(dbP, index); p = MemHandleLock(h); // move the last part if (oldSize != newSize) { bakSize = oldSize - offsetLastPart;// DEBUGVAL("BakSize : ", bakSize);// DEBUGVAL("OffsetLastPart : ", offsetLastPart);// DEBUGVAL("oldSize : ", oldSize);// DEBUGVAL("newSize : ", newSize); bak = MemPtrNew(bakSize); if (!bak) { MessageBox(StrNoMemorySpaces); MemHandleUnlock(h); DmReleaseRecord(dbP, index, false); return pgError; } MemMove(bak, (MemPtr)p + offsetLastPart, bakSize); // casting is obligatory here, because newsize - oldsize can be < 0 DmWrite(p, (Int16)offsetLastPart + (Int16)newSize - (Int16)oldSize, bak, bakSize); MemPtrFree(bak); } if (size > 0) { // write the new xb// if (DmWriteCheck(p, OffsetOf(TaskExtendedRecordType, fields.XB.data),// size))// {// DEBUG1("Error at write new xb");// } DmWrite(p, OffsetOf(TaskExtendedRecordType, fields.XB.data), s, size); DBGMSG((DBB, "Writing extra block :")); DBGMSGBIN((DBB, s, size)); // write the size// if (DmWriteCheck(p, OffsetOf(TaskExtendedRecordType, fields.XB.size),// sizeof(UInt16)))// {// DEBUG1("Error at write size");// } DmWrite(p, OffsetOf(TaskExtendedRecordType, fields.XB.size), &size, sizeof(UInt16)); format.hasXB = 1; } else { format.hasXB = 0; } MemHandleUnlock(h); if (oldSize > newSize) { h = DmResizeRecord(dbP, index, newSize); } DmReleaseRecord(dbP, index, true); TaskSetFormat(dbP, index, format); return pgOK;} // pgErr TaskSetExtraBlock(DmOpenRef dbP, UInt16 index, MemPtr s, UInt32 size)/**************************************************************************** * Name : TaskGetExtraBlockV022 * Desc : get the given extra block of the given task * Parm : * -> database pointer * -> index of the record * -> pointer to the block, pass NULL if you don't want it * Out : size of the block * Auth : lb, 31.08.2000 * Rem : gives size = 0 if no extra block * XXX : DEPRECATED, use TaskGetExtraBlock * kept for db conversion ***************************************************************************/UInt16 TaskGetExtraBlockV022(DmOpenRef dbP, UInt16 index, MemPtr dest){ MemHandle h; TaskExtendedRecordType* pTask; MemPtr pExtra; UInt16 sizeExtra; h = DmQueryRecord(dbP, index); pTask = MemHandleLock(h); pExtra = TaskGetExtraBlockHeadPtrV022(pTask); sizeExtra = (UInt8*)pTask + MemPtrSize(pTask) - (UInt8*)pExtra; if (sizeExtra && dest) MemMove(dest, pExtra, sizeExtra); MemHandleUnlock(h); return sizeExtra;} // UInt16 TaskGetExtraBlockV022(DmOpenRef dbP, UInt16 index, MemPtr dest)/**************************************************************************** * Name : TaskGetExtraBlock * Desc : get the given extra block of the given task * Parm : * -> database pointer * -> index of the record * -> pointer to the block, pass NULL if you don't want it * Out : size of the block * Auth : lb, 2001-09-08 * Rem : gives size = 0 if no extra block ***************************************************************************/UInt16 TaskGetExtraBlock(DmOpenRef dbP, UInt16 index, MemPtr dest){ MemHandle h; TaskExtendedRecordType* pTask; MemPtr pExtra; UInt16 sizeExtra; h = DmQueryRecord(dbP, index); pTask = MemHandleLock(h); if (pTask->format.bits.hasXB) { pExtra = pTask->fields.XB.data; sizeExtra = pTask->fields.XB.size; if (sizeExtra && dest) MemMove(dest, pExtra, sizeExtra); DBGMSG((DBB, "Getting extra block (index : %hd, size : %hd)", index, sizeExtra)); DBGMSGBIN((DBB, dest, sizeExtra)); } else { sizeExtra = 0; } MemHandleUnlock(h); return sizeExtra;} // UInt16 TaskGetExtraBlock(DmOpenRef dbP, UInt16 index, MemPtr dest)/**************************************************************************** * Name : TaskCopyExtraBlock * Desc : copy an extra block from a task to another * Parm : * -> database pointer * -> index of the source record * -> index of the destination record * Out : * Auth : lb, 31.08.2000 * Rem : ***************************************************************************/pgErr TaskCopyExtraBlock(DmOpenRef dbP, UInt16 source, UInt16 dest){ MemPtr extraBlock; UInt32 extraSize; pgErr status = pgOK; extraSize = TaskGetExtraBlock(dbP, source, NULL); if (extraSize) { extraBlock = MemPtrNew(extraSize); if (!extraBlock) return pgError; TaskGetExtraBlock(dbP, source, extraBlock); status = TaskSetExtraBlock(dbP, dest, extraBlock, extraSize); MemPtrFree(extraBlock); } return status;} // pgErr TaskCopyExtraBlock(DmOpenRef dbP, UInt16 source, UInt16 dest)/**************************************************************************** * Name : TaskFindExtraChunk * Desc : find chunk of extra block * Prm : * -> extra block ptr * -> chunk type * -> sub key. 0xff is wildcard. * Out : headder of it chunk if type was found, otherwith return NULL. * Auth : seagull, 27,09,2000 ***************************************************************************/ExtraChunkHeadType*TaskFindExtraChunkHead(ExtraChunkHeadType* block, UInt8 type, UInt8 subkey){ // always do paranoid checks.... if (NULL == block) return NULL; // NOTE: if type is NULL, this function must be find NULL block. // see TaskSetExtraChunk for (;;) { if (block->type == type && (subkey == 0xff || block->subkey == subkey)) return block; else if (block->type == Extra_NULL) return NULL; block = NextChunk(block);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -