示例#1
0
void PackHappyDays(HappyDays *hd, void* recordP)
{
    UInt16 offset = 0;

    DmWrite(recordP, offset, (Char*)&hd->addrRecordNum, sizeof(hd->addrRecordNum));
    offset += sizeof(hd->addrRecordNum);
    DmWrite(recordP, offset, (Char*)&hd->date, sizeof(hd->date));
    offset += sizeof(hd->date);
    DmWrite(recordP, offset, (Char*)&hd->flag, sizeof(hd->flag));
    offset += sizeof(hd->flag);  
    DmWrite(recordP, offset, (Char*)&hd->nth, sizeof(hd->nth));
    offset += sizeof(hd->nth);      // for corealign

    if (hd->name1) {
        DmStrCopy(recordP, offset, (Char*)hd->name1);
        offset += StrLen(hd->name1) +1;
    }
    else {
        DmStrCopy(recordP, offset, "\0");
        offset += 1;
    }
    if (hd->name2) {
        DmStrCopy(recordP, offset, (Char*)hd->name2);
        offset += StrLen(hd->name2) +1;
    }
    else {
        DmStrCopy(recordP, offset,"\0");
        offset += 1;
    }

    if (hd->custom) {
        DmStrCopy(recordP, offset, (Char*)hd->custom);
        offset += StrLen(hd->custom) +1;
    }
    else {
        DmStrCopy(recordP, offset,"\0");
        offset += 1;
    }
}
示例#2
0
/* Add data for bookmark */
void AddBookmark
    (
    Char* name      /* name of bookmark */
    )
    /* THROWS */
{
    MetaRecord*     meta;
    BookmarkData    bookmarkData;
    UInt8*          bookmarkPtr;
    MemHandle       handle;
    UInt32          endOfRecord;
    UInt16          entries;
    UInt16          offset;
    UInt16          newSize;
    UInt16          nameLength;
    UInt16          i;

    THROW_IF( name == NULL || *name == '\0', errNoBookmarkName );

    handle = ReturnMetaHandle( INTERNAL_BOOKMARKS_ID, NO_PARAGRAPHS );
    if ( handle == NULL )
        AddBookmarkRecord( &handle );

    endOfRecord = MemHandleSize( handle );
    TrimText( name, BOOKMARKLISTWIDTH );
    nameLength  = StrLen( name ) + 1;
        
    newSize     = endOfRecord + sizeof( BookmarkData ) + nameLength;

    ResizeMetaRecord( INTERNAL_BOOKMARKS_ID, newSize, &handle );

    bookmarkPtr = MemHandleLock( handle );

    entries = GET_ENTRIES( bookmarkPtr ) + 1;
    offset  = GET_OFFSET( bookmarkPtr ) + nameLength;
    DmWrite( bookmarkPtr, sizeof( UInt16 ), &entries, sizeof( UInt16 ) );
    DmWrite( bookmarkPtr, 2 * sizeof( UInt16 ), &offset, sizeof( UInt16 ) );

    meta = MemHandleLock( GetMetaRecord() );

    bookmarkData.verticalOffset         = meta->verticalOffset;
    bookmarkData.characterPosition      = meta->characterPosition;
    bookmarkData.firstVisibleParagraph  = meta->firstVisibleParagraph;
    bookmarkData.firstParagraphY        = meta->firstParagraphY;
#ifdef STORE_LAST_VISIBLE
    bookmarkData.lastVisibleParagraph   = meta->lastVisibleParagraph;
    bookmarkData.lastParagraphY         = meta->lastParagraphY;
#endif
    bookmarkData.recordId               = GetHistoryCurrent();

    /* Write new block of bookmark data */
    DmWrite( bookmarkPtr, endOfRecord + nameLength, &bookmarkData,
        sizeof( BookmarkData ) );
    endOfRecord -= sizeof( BookmarkData );

    /* Reshuffle old blocks with bookmark data */
    for ( i = 1; i < entries; i++ ) {
        MemMove( &bookmarkData, bookmarkPtr + endOfRecord,
            sizeof( BookmarkData ) );
        DmWrite( bookmarkPtr, endOfRecord + nameLength, &bookmarkData,
            sizeof( BookmarkData ) );
        endOfRecord -= sizeof( BookmarkData );
    }

    /* Write new bookmark name */
    DmStrCopy( bookmarkPtr, offset - nameLength, name );

    MemHandleUnlock( GetMetaRecord() );
    MemHandleUnlock( handle );
}