Cardinal Idb__BM_Decommit (IDBRecordBufferPtr buffer) { /* * Local variables */ Cardinal result ; /* function results */ if ( ! Idb__BM_Valid(buffer) ) return Urm__UT_Error ("Idb__BM_Decommit", _MrmMMsg_0002, NULL, NULL, MrmNOT_VALID) ; if ((buffer->access == URMWriteAccess) && (buffer->modified == TRUE)) { result = Idb__FU_PutBlock (buffer->cur_file->lowlevel_id, buffer->IDB_record->header.record_num, (char*)buffer->IDB_record) ; if ( result != MrmSUCCESS ) return Urm__UT_Error ("Idb__BM_Decommit", _MrmMMsg_0004, NULL, NULL, MrmNOT_VALID) ; buffer->cur_file->put_count++ ; buffer->activity = 0; buffer->modified = FALSE; } return MrmSUCCESS; }
Cardinal UrmGetResourceContext (char *((*alloc_func) ()), void (*free_func) (), MrmSize size, URMResourceContextPtr *context_id_return) { /* * Set function defaults if NULL */ if ( alloc_func == NULL ) alloc_func = XtMalloc ; if ( free_func == NULL ) free_func = XtFree ; /* * Allocate the context buffer and memory buffer, and set the * context up. */ *context_id_return = (URMResourceContextPtr) (*alloc_func) (sizeof(URMResourceContext)) ; if ( *context_id_return == NULL ) return Urm__UT_Error ("UrmGetResourceContext", _MrmMMsg_0027, NULL, *context_id_return, MrmFAILURE) ; (*context_id_return)->validation = URMResourceContextValid ; (*context_id_return)->data_buffer = NULL ; if ( size > 0 ) { (*context_id_return)->data_buffer = (char *) (*alloc_func) (size) ; if ( (*context_id_return)->data_buffer == NULL ) { (*free_func) (*context_id_return) ; return Urm__UT_Error ("UrmGetResourceContext", _MrmMMsg_0001, NULL, *context_id_return, MrmFAILURE) ; } } (*context_id_return)->buffer_size = size ; (*context_id_return)->resource_size = 0 ; (*context_id_return)->group = URMgNul ; (*context_id_return)->type = URMtNul ; (*context_id_return)->access = 0 ; (*context_id_return)->lock = 0 ; (*context_id_return)->alloc_func = alloc_func ; (*context_id_return)->free_func = free_func ; /* * Context successfully created */ return MrmSUCCESS ; }
Cardinal Idb__INX_GetBtreeRecord ( IDBFile file_id, IDBRecordBufferPtr *buffer_return, MrmCount entry_index, Cardinal order) { /* * Local variables */ Cardinal result ; /* function results */ IDBIndexNodeRecordPtr recptr ; /* node record in buffer */ IDBRecordNumber recno ; /* Record number to read in */ /* * Set buffer pointers */ recptr = (IDBIndexNodeRecordPtr) (*buffer_return)->IDB_record ; /* * Retrieve the record number */ switch ( order ) { case MrmINDEX_GT: recno = recptr->index[entry_index].GT_record ; break ; case MrmINDEX_LT: recno = recptr->index[entry_index].LT_record ; break ; default: return Urm__UT_Error ("Idb__INX_GetBTreeRecord", _MrmMMsg_0010, file_id, NULL, MrmBAD_ORDER) ; } /* * Retrieve and sanity check the record */ result = Idb__BM_GetRecord (file_id, recno, buffer_return) ; if ( result != MrmSUCCESS ) return result ; if ( ! Idb__INX_ValidRecord(*buffer_return) ) return Urm__UT_Error ("Idb__INX_GetBTreeRecord", _MrmMMsg_0010, file_id, NULL, MrmBAD_RECORD) ; /* * Record successfully retrieved */ return MrmSUCCESS ; }
Cardinal Idb__BM_InitBufferVector (void) { /* * Local variables */ Cardinal ndx ; /* loop variable */ IDBRecordBufferPtr bufptr ; /* entry into buffer pool vector */ idb__buffer_pool_vec = (IDBRecordBufferPtr) XtMalloc (idb__buffer_pool_size*sizeof(IDBRecordBuffer)) ; if ( idb__buffer_pool_vec == NULL ) return Urm__UT_Error ("Idb__BM_InitBufferVector", _MrmMMsg_0000, NULL, NULL, MrmFAILURE) ; for ( ndx=0,bufptr=idb__buffer_pool_vec ; ndx<idb__buffer_pool_size ; ndx++,bufptr++ ) { bufptr->validation = IDBRecordBufferValid; bufptr->activity = 0 ; bufptr->access = 0 ; bufptr->cur_file = NULL ; bufptr->modified = FALSE ; bufptr->IDB_record = NULL ; } return MrmSUCCESS; }
Cardinal Idb__BM_MarkActivity (IDBRecordBufferPtr buffer) { if ( ! Idb__BM_Valid(buffer) ) return Urm__UT_Error ("Idb__BM_MarkActivity", _MrmMMsg_0002, NULL, NULL, MrmNOT_VALID) ; buffer->activity = idb__buffer_activity_count++ ; return MrmSUCCESS ; }
Cardinal Idb__INX_ReturnItem (IDBFile file_id, char *index, IDBDataHandle *data_entry) { /* * Local variables */ Cardinal result ; /* function results */ IDBRecordBufferPtr bufptr ; /* buffer containing entry */ MrmCount entndx ; /* entry index */ IDBIndexLeafRecordPtr leafrec ; /* index leaf record */ IDBIndexNodeRecordPtr noderec ; /* index node record */ /* * Attempt to find the index */ result = Idb__INX_FindIndex (file_id, index, &bufptr, &entndx) ; switch ( result ) { case MrmINDEX_GT: case MrmINDEX_LT: return MrmNOT_FOUND ; case MrmSUCCESS: break ; default: return result ; } /* * Point into the buffer, and retrieve the data pointer */ switch ( _IdbBufferRecordType (bufptr) ) { case IDBrtIndexLeaf: leafrec = (IDBIndexLeafRecordPtr) bufptr->IDB_record ; data_entry->rec_no = leafrec->index[entndx].data.internal_id.rec_no ; data_entry->item_offs = leafrec->index[entndx].data.internal_id.item_offs ; return MrmSUCCESS ; case IDBrtIndexNode: noderec = (IDBIndexNodeRecordPtr) bufptr->IDB_record ; data_entry->rec_no = noderec->index[entndx].data.internal_id.rec_no ; data_entry->item_offs = noderec->index[entndx].data.internal_id.item_offs ; return MrmSUCCESS ; default: return Urm__UT_Error ("Idb__INX_ReturnItem", _MrmMMsg_0010, file_id, NULL, MrmBAD_RECORD) ; } }
Cardinal Urm__SwapRGMCallbackDesc (RGMCallbackDescPtr callb_desc, RGMWidgetRecordPtr widget_rec) { Cardinal ndx; /* inner loop index */ RGMResourceDescPtr res_desc; /* resource description literal */ char err_msg[300]; swapbytes( callb_desc->validation ); swapbytes( callb_desc->count ); swapbytes( callb_desc->annex ); swapbytes( callb_desc->unres_ref_count ); for (ndx=0 ; ndx < callb_desc->count ; ndx++) { #ifdef WORD64 swap4bytes( callb_desc->item[ndx].cb_item.routine ); swap4bytes( callb_desc->item[ndx].cb_item.rep_type ); #else swap2bytes( callb_desc->item[ndx].cb_item.routine ); swap2bytes( callb_desc->item[ndx].cb_item.rep_type ); #endif switch (callb_desc->item[ndx].cb_item.rep_type) { case MrmRtypeInteger: case MrmRtypeBoolean: swapbytes( callb_desc->item[ndx].cb_item.datum.ival ); break; case MrmRtypeSingleFloat: swapbytes( callb_desc->item[ndx].cb_item.datum.ival ); _MrmOSIEEEFloatToHost((float *) &(callb_desc->item[ndx].cb_item.datum.ival)); case MrmRtypeNull: break; case MrmRtypeResource: swapbytes( callb_desc->item[ndx].cb_item.datum.offset ); res_desc = (RGMResourceDesc *) ((char *)widget_rec + callb_desc->item[ndx].cb_item.datum.offset); Urm__SwapRGMResourceDesc( res_desc ); /* flag this resource as needing further byte swapping */ res_desc->cvt_type |= MrmResourceUnswapped; break; default: swapbytes( callb_desc->item[ndx].cb_item.datum.offset ); sprintf(err_msg, _MrmMMsg_0021, callb_desc->item[ndx].cb_item.rep_type, ndx); return Urm__UT_Error ("Urm__SwapRGMCallbackDesc", err_msg, NULL, NULL, MrmFAILURE) ; break; } } return MrmSUCCESS; }
Cardinal UrmFreeResourceContext (URMResourceContextPtr context_id) { if ( ! UrmRCValid(context_id) ) return Urm__UT_Error ("UrmFreeResourceContext", _MrmMMsg_0028, NULL, context_id, MrmBAD_CONTEXT) ; context_id->validation = 0 ; if ( context_id->data_buffer != NULL ) (*(context_id->free_func)) (context_id->data_buffer) ; (*(context_id->free_func)) (context_id) ; return MrmSUCCESS ; }
Cardinal Idb__INX_FindIndex (IDBFile file_id, char *index, IDBRecordBufferPtr *buffer_return, MrmCount *index_return) { /* * Local variables */ Cardinal result ; /* function results */ /* * Initialize search at the root of the index, then continue searching * until either the index is found or search terminates at some leaf record. */ if ( !file_id->index_root ) return MrmFAILURE ; result = Idb__BM_GetRecord (file_id, file_id->index_root, buffer_return) ; if ( result != MrmSUCCESS ) return result ; if ( ! Idb__INX_ValidRecord(*buffer_return) ) return Urm__UT_Error ("Idb__INX_FindIndex", _MrmMMsg_0010, file_id, NULL, MrmBAD_RECORD) ; do { result = Idb__INX_SearchIndex (file_id, index, *buffer_return, index_return) ; if ( _IdbBufferRecordType(*buffer_return) == IDBrtIndexLeaf) return result ; switch ( result ) { case MrmINDEX_GT: case MrmINDEX_LT: result = Idb__INX_GetBtreeRecord (file_id, buffer_return, *index_return, result) ; if (result != MrmSUCCESS ) { if (result == MrmNOT_FOUND) result = MrmEOF; return result ; } break ; default: return result ; } } while ( TRUE ) ; }
Cardinal UrmResizeResourceContext (URMResourceContextPtr context_id, int size) { /* * Local variables */ char *newbuf ; /* new buffer */ if ( ! UrmRCValid(context_id) ) return Urm__UT_Error ("UrmResizeResourceContext", _MrmMMsg_0028, NULL, context_id, MrmBAD_CONTEXT) ; if ( size > MrmMaxResourceSize) return Urm__UT_Error ("MrmResizeResourceContext", _MrmMMsg_0029, NULL, context_id, MrmTOO_MANY) ; /* * CR 8391: buffer will eventually be passed to * Urm__CW_EvaluateValOrOffset which is expecting a long. Make sure to * allocate at least a long so that we don't get array bounds read * violations. Ideally Urm__CW_EvaluateValOrOffset and the code that * calls it should be rewritten, but we don't have time for that now. */ if (size < sizeof(long)) size = sizeof(long); /* * Resize unless buffer is bigger than requested size. */ if ( context_id->buffer_size > size ) return MrmSUCCESS ; /* * Allocate the new buffer, copy the old buffer contents, and * update the context. */ if ( context_id->alloc_func == XtMalloc ) { context_id->data_buffer = XtRealloc (context_id->data_buffer, size) ; context_id->buffer_size = size ; } else { newbuf = (char *) (*(context_id->alloc_func)) (size) ; if ( newbuf == NULL ) return Urm__UT_Error ("UrmResizeResourceContext", _MrmMMsg_0001, NULL, context_id, MrmFAILURE) ; if ( context_id->data_buffer != NULL ) { UrmBCopy (context_id->data_buffer, newbuf, context_id->buffer_size) ; (*(context_id->free_func)) (context_id->data_buffer) ; } context_id->data_buffer = newbuf ; context_id->buffer_size = size ; } /* * Resize succeeded */ return MrmSUCCESS ; }
Cardinal Idb__INX_FindResources (IDBFile file_id, IDBRecordNumber recno, MrmGroup group_filter, MrmType type_filter, URMPointerListPtr index_list) { /* * Local variables */ Cardinal result ; /* function results */ IDBRecordBufferPtr bufptr ; /* buffer containing entry */ int entndx ; /* entry loop index */ IDBIndexLeafRecordPtr leafrec ; /* index leaf record */ IDBIndexLeafHdrPtr leafhdr ; /* index leaf header */ IDBIndexNodeRecordPtr noderec ; /* index node record */ IDBIndexNodeHdrPtr nodehdr ; /* index node header */ IDBIndexLeafEntryPtr leaf_ndxvec ; /* index leaf entry vector */ IDBIndexNodeEntryPtr node_ndxvec ; /* index node entry vector */ MrmCount ndxcnt ; /* number of entries in vector */ char *stgbase ; /* base adddress for string offsets */ /* * Read the record in, then bind pointers and process the record. */ result = Idb__BM_GetRecord (file_id, recno, &bufptr) ; if ( result != MrmSUCCESS ) return result ; switch ( _IdbBufferRecordType (bufptr) ) { /* * Simply apply the filter to all entries in the leaf record */ case IDBrtIndexLeaf: leafrec = (IDBIndexLeafRecordPtr) bufptr->IDB_record ; leafhdr = (IDBIndexLeafHdrPtr) &leafrec->leaf_header ; leaf_ndxvec = leafrec->index ; ndxcnt = leafhdr->index_count ; stgbase = (char *) leafrec->index ; for ( entndx=0 ; entndx<ndxcnt ; entndx++ ) { IDBDataHandle entry_data; entry_data.rec_no = leaf_ndxvec[entndx].data.internal_id.rec_no; entry_data.item_offs = leaf_ndxvec[entndx].data.internal_id.item_offs; if ( Idb__DB_MatchFilter(file_id, entry_data, group_filter, type_filter) ) UrmPlistAppendString (index_list, stgbase+leaf_ndxvec[entndx].index_stg) ; Idb__BM_MarkActivity (bufptr) ; } return MrmSUCCESS ; /* * Process the first LT record, then process each index followed by * its GT record. This will produce a correctly ordered list. The * record is read again, and all pointers bound, after each FindResources * call in order to guarantee that buffer turning has not purged the * current record from memory */ case IDBrtIndexNode: noderec = (IDBIndexNodeRecordPtr) bufptr->IDB_record ; nodehdr = (IDBIndexNodeHdrPtr) &noderec->node_header ; node_ndxvec = noderec->index ; ndxcnt = nodehdr->index_count ; stgbase = (char *) noderec->index ; result = Idb__INX_FindResources (file_id, node_ndxvec[0].LT_record, group_filter, type_filter, index_list) ; if ( result != MrmSUCCESS ) return result ; for ( entndx=0 ; entndx<ndxcnt ; entndx++ ) { IDBDataHandle entry_data; entry_data.rec_no = node_ndxvec[entndx].data.internal_id.rec_no; entry_data.item_offs = node_ndxvec[entndx].data.internal_id.item_offs; Idb__BM_GetRecord (file_id, recno, &bufptr) ; noderec = (IDBIndexNodeRecordPtr) bufptr->IDB_record ; nodehdr = (IDBIndexNodeHdrPtr) &noderec->node_header ; node_ndxvec = noderec->index ; stgbase = (char *) noderec->index ; if ( Idb__DB_MatchFilter (file_id, entry_data, group_filter, type_filter) ) UrmPlistAppendString (index_list, stgbase+node_ndxvec[entndx].index_stg) ; result = Idb__INX_FindResources (file_id, node_ndxvec[entndx].GT_record, group_filter, type_filter, index_list) ; if ( result != MrmSUCCESS ) return result ; } return MrmSUCCESS ; default: return Urm__UT_Error ("Idb__INX_FindResources", _MrmMMsg_0010, file_id, NULL, MrmBAD_RECORD) ; } }
Cardinal Idb__INX_SearchIndex (IDBFile file_id, char *index, IDBRecordBufferPtr buffer, MrmCount *index_return) { /* * Local variables */ MrmType buftyp ; /* buffer type */ IDBIndexLeafRecordPtr leafrec ; /* index leaf record */ IDBIndexLeafHdrPtr leafhdr ; /* index leaf header */ IDBIndexNodeRecordPtr noderec ; /* index node record */ IDBIndexNodeHdrPtr nodehdr ; /* index node header */ IDBIndexLeafEntryPtr leaf_ndxvec ; /* index leaf entry vector */ IDBIndexNodeEntryPtr node_ndxvec ; /* index node entry vector */ MrmCount ndxcnt ; /* number of entries in vector */ char *stgbase ; /* base adddress for string offsets */ int lowlim ; /* binary search lower limit index */ int uprlim ; /* binary search upper limit index */ char *ndxstg ; /* pointer to current index string */ int cmpres ; /* strncmp result */ /* * Set up search pointers based on the record type */ buftyp = _IdbBufferRecordType (buffer) ; switch ( buftyp ) { case IDBrtIndexLeaf: leafrec = (IDBIndexLeafRecordPtr) buffer->IDB_record ; leafhdr = (IDBIndexLeafHdrPtr) &leafrec->leaf_header ; leaf_ndxvec = leafrec->index ; ndxcnt = leafhdr->index_count ; stgbase = (char *) leafrec->index ; break ; case IDBrtIndexNode: noderec = (IDBIndexNodeRecordPtr) buffer->IDB_record ; nodehdr = (IDBIndexNodeHdrPtr) &noderec->node_header ; node_ndxvec = noderec->index ; ndxcnt = nodehdr->index_count ; stgbase = (char *) noderec->index ; break ; default: return Urm__UT_Error ("Idb__INX_SearchIndex", _MrmMMsg_0010, file_id, NULL, MrmBAD_RECORD) ; } /* * Search the index vector for the given index (binary search) */ Idb__BM_MarkActivity (buffer) ; for ( lowlim=0,uprlim=ndxcnt-1 ; lowlim<=uprlim ; ) { *index_return = (lowlim+uprlim) / 2 ; ndxstg = (buftyp==IDBrtIndexLeaf) ? (char *) stgbase + leaf_ndxvec[*index_return].index_stg : (char *) stgbase + node_ndxvec[*index_return].index_stg ; cmpres = strncmp (index, ndxstg, IDBMaxIndexLength) ; if ( cmpres == 0 ) return MrmSUCCESS ; if ( cmpres < 0 ) uprlim = *index_return - 1 ; if ( cmpres > 0 ) lowlim = *index_return + 1 ; } /* * Not found, result determined by final ordering. */ return (cmpres>0) ? MrmINDEX_GT : MrmINDEX_LT ; }
Cardinal Idb__BM_GetRecord (IDBFile file_id, IDBRecordNumber record, IDBRecordBufferPtr *buffer_return) { /* * Local variables */ Cardinal result ; /* function results */ int ndx ; /* loop index */ IDBRecordBufferPtr curbuf ; /* current buffer being examined */ unsigned char *buf_src; /* tmp pointer to location in uid buffer */ /* * If buffer pool is unallocated, get a buffer (which WILL allocate it), * and read the record into that. Else see if the record is already in * memory, and return it if so. If the record is not found, get a buffer * to read it into. We exit this if statement with a buffer ready for * the read operation. */ if ( idb__buffer_pool_vec == NULL ) { result = Idb__BM_GetBuffer (file_id, buffer_return) ; if ( result != MrmSUCCESS ) return result ; } else { for ( ndx=0,curbuf=idb__buffer_pool_vec ; ndx<idb__buffer_pool_size ; ndx++,curbuf++ ) { if ( (curbuf->cur_file==file_id) && (curbuf->IDB_record->header.record_num==record) ) { *buffer_return = curbuf ; Idb__BM_MarkActivity (*buffer_return) ; return MrmSUCCESS ; } } result = Idb__BM_GetBuffer (file_id, buffer_return) ; if ( result != MrmSUCCESS ) return result ; } /* * Read the record into the buffer. */ if ( file_id->in_memory ) { buf_src = file_id->uid_buffer + (record-1)*IDBRecordSize; UrmBCopy(buf_src, (*buffer_return)->IDB_record, IDBRecordSize); result = MrmSUCCESS; } else result = Idb__FU_GetBlock(file_id->lowlevel_id, record, (char*)(*buffer_return)->IDB_record) ; if ( result != MrmSUCCESS ) return Urm__UT_Error ("Idb__BM_GetRecord", _MrmMMsg_0003, file_id, NULL, result) ; file_id->get_count++ ; /* * Validate the record, this is the first routine that is called to read * from a newly opened file. If the byte order is different, we find it * here. */ if ( (*buffer_return)->IDB_record->header.validation != IDBRecordHeaderValid ) { swapbytes( (*buffer_return)->IDB_record->header.validation ); if ((*buffer_return)->IDB_record->header.validation == IDBRecordHeaderValid) { /* must be a file needing byte swapping */ file_id->byte_swapped = TRUE; Idb__BM_SwapRecordBytes (*buffer_return); Idb__BM_MarkActivity (*buffer_return); return MrmSUCCESS ; } /* byte swapping has done no good, return error */ return Urm__UT_Error("Idb__BM_GetRecord", _MrmMMsg_0005, file_id, NULL, MrmNOT_VALID) ; } /* * Record successfully read */ Idb__BM_MarkActivity (*buffer_return) ; return MrmSUCCESS ; }
Cardinal Idb__BM_GetBuffer (IDBFile file_id, IDBRecordBufferPtr *buffer_return) { /* * Local macro to complete allocation of a buffer to a file, and * mark its activity. */ #define _IDB_Getbuffer_return() \ { \ (*buffer_return)->cur_file = file_id; \ (*buffer_return)->access = file_id->access; \ Idb__BM_MarkActivity (*buffer_return); \ return MrmSUCCESS; \ } /* * Local variables */ Cardinal result ; /* function results */ int ndx ; /* loop index */ long int lowest ; /* lowest activity count found */ IDBRecordBufferPtr curbuf ; /* current buffer being examined */ /* * If the buffer pool is uninitialized, allocate it and * return the first buffer in the pool. Else search the buffer pool for the * buffer with the lowest activity. Decommited/0 activity buffers can * be returned immediately. */ if (idb__buffer_pool_vec == NULL) { result = Idb__BM_InitBufferVector () ; if ( result != MrmSUCCESS ) return result ; *buffer_return = idb__buffer_pool_vec ; } else { lowest = idb__buffer_activity_count; for ( ndx=0,curbuf=idb__buffer_pool_vec ; ndx<idb__buffer_pool_size ; ndx++,curbuf++ ) { if ( curbuf->activity == 0 ) { *buffer_return = curbuf ; break ; } if ( curbuf->activity < lowest ) { *buffer_return = curbuf ; lowest = curbuf->activity ; } } } /* * Allocate a record buffer if required, and return immediately if * the buffer is decommitted or not yet used. */ if ( (*buffer_return)->IDB_record == NULL ) { (*buffer_return)->IDB_record = (IDBDummyRecord *) XtMalloc(sizeof(IDBDummyRecord)) ; if ( (*buffer_return)->IDB_record == NULL ) return Urm__UT_Error ("Idb__BM_GetBuffer", _MrmMMsg_0001, NULL, NULL, MrmFAILURE) ; _IDB_Getbuffer_return (); } if ( (*buffer_return)->activity == 0 ) _IDB_Getbuffer_return (); /* * We have set the buffer pointer. See if it needs to be updated on * disk, and do so if required. */ if ( ((*buffer_return)->access == URMWriteAccess) && ((*buffer_return)->modified) ) { result = Idb__BM_Decommit (*buffer_return) ; if ( result != MrmSUCCESS ) return result ; } /* * Allocate the buffer to the file, and return. */ _IDB_Getbuffer_return (); }
Cardinal Idb__BM_SwapRecordBytes (IDBRecordBufferPtr buffer) { /* * Local variables */ Cardinal ndx; /* loop index */ IDBDummyRecordPtr idb_record; /* pointer to the generic IDB record */ IDBRecordHeaderPtr idb_header; /* pointer to hdr w/type and record # */ IDBHeaderRecordPtr header_rec; /* pointer to record type IDBrtHeader */ IDBHeaderHdrPtr header_hdr; /* pointer to the header in the header */ IDBIndexLeafRecordPtr leaf_rec; /* pointer to record type IDBrtIndexLeaf */ IDBIndexNodeRecordPtr node_rec; /* pointer to record type IDBrtIndexNode */ IDBridMapRecordPtr ridmap_rec; /* pointer to record type IDBrtRIDMap */ IDBDataRecordPtr data_rec; /* pointer to record type IDBrtData */ char err_msg[300] ; if ( ! Idb__BM_Valid(buffer) ) return Urm__UT_Error("Idb__BM_MarkActivity", _MrmMMsg_0002, NULL, NULL, MrmNOT_VALID) ; /* load pointers to the record and record header */ idb_record = (IDBDummyRecordPtr) buffer->IDB_record ; idb_header = (IDBRecordHeaderPtr)&idb_record->header ; /* swap the remaining record entries in IDBRecordHeader */ swapbytes( idb_header->record_type ) ; swapbytes( idb_header->record_num ) ; /* * Swap IDB record items based on record type */ switch ( idb_header->record_type ) { case IDBrtHeader: header_rec = (IDBHeaderRecordPtr)buffer->IDB_record ; header_hdr = (IDBHeaderHdrPtr)&header_rec->header_hdr ; /* swap the HeaderHdr first */ swapbytes( header_hdr->index_root ); swapbytes( header_hdr->num_indexed ); swapbytes( header_hdr->num_RID ); /* VAR check */ #ifdef WORD64 swap4bytes( header_hdr->next_RID.internal_id.map_rec ); swap4bytes( header_hdr->next_RID.internal_id.res_index ); #else swap2bytes( header_hdr->next_RID.internal_id.map_rec ); swap2bytes( header_hdr->next_RID.internal_id.res_index ); #endif swapbytes( header_hdr->last_record ); swapbytes( header_hdr->last_data_record ); for( ndx=0 ; ndx < URMgVecSize ; ndx++) swapbytes(header_hdr->group_counts[ndx]); for( ndx=0 ; ndx < IDBrtVecSize ; ndx++) swapbytes(header_hdr->rt_counts[ndx]); /* now swap the rest of the header */ /* VAR check */ for( ndx=0 ; ndx < IDBHeaderRIDMax ; ndx++) { swap2bytes(header_rec->RID_pointers[ndx].internal_id.rec_no); swap2bytes(header_rec->RID_pointers[ndx].internal_id.item_offs); } swapbytes( header_rec->num_entry ); swapbytes( header_rec->last_entry ); swapbytes( header_rec->free_ptr ); swapbytes( header_rec->free_count ); break; case IDBrtIndexLeaf: leaf_rec = (IDBIndexLeafRecordPtr)buffer->IDB_record ; swapbytes( leaf_rec->leaf_header.parent ); swapbytes( leaf_rec->leaf_header.index_count ); swapbytes( leaf_rec->leaf_header.heap_start ); swapbytes( leaf_rec->leaf_header.free_bytes ); for( ndx=0 ; ndx < leaf_rec->leaf_header.index_count ; ndx++ ) { swapbytes( leaf_rec->index[ndx].index_stg ); swap2bytes( leaf_rec->index[ndx].data.internal_id.rec_no ); swap2bytes( leaf_rec->index[ndx].data.internal_id.item_offs ); } break; case IDBrtIndexNode: node_rec = (IDBIndexNodeRecordPtr)buffer->IDB_record ; swapbytes( node_rec->node_header.parent ); swapbytes( node_rec->node_header.index_count ); swapbytes( node_rec->node_header.heap_start ); swapbytes( node_rec->node_header.free_bytes ); for( ndx=0 ; ndx < node_rec->node_header.index_count ; ndx++ ) { swapbytes( node_rec->index[ndx].index_stg ); swap2bytes( node_rec->index[ndx].data.internal_id.rec_no ); swap2bytes( node_rec->index[ndx].data.internal_id.item_offs ); swapbytes( node_rec->index[ndx].LT_record ); swapbytes( node_rec->index[ndx].GT_record ); } break; case IDBrtRIDMap: ridmap_rec = (IDBridMapRecordPtr)buffer->IDB_record ; ndx = 0; while ( (ndx < IDBridPtrVecMax) && (ridmap_rec->pointers[ndx].internal_id.rec_no != 0) ) { swap2bytes( ridmap_rec->pointers[ndx].internal_id.rec_no ); swap2bytes( ridmap_rec->pointers[ndx].internal_id.item_offs ); ndx++; } break; case IDBrtData: data_rec = (IDBDataRecordPtr)buffer->IDB_record ; swapbytes( data_rec->data_header.num_entry ); swapbytes( data_rec->data_header.last_entry ); swapbytes( data_rec->data_header.free_ptr ); swapbytes( data_rec->data_header.free_count ); break; default: sprintf(err_msg, _MrmMMsg_0020, idb_header->record_num, idb_header->record_type); return Urm__UT_Error ("Idb__BM_SwapRecordBytes", err_msg, NULL, NULL, MrmFAILURE) ; } return MrmSUCCESS ; }
Cardinal Urm__SwapRGMWidgetRecord(RGMWidgetRecordPtr widget_rec) { /* * Local variables */ RGMArgListDescPtr arg_list; /* pointer to widget arglist */ RGMChildrenDescPtr child_list; /* pointer to the widgets children */ RGMResourceDescPtr res_desc; /* resource description literal */ RGMCallbackDescPtr callb_desc; /* pointer to a callback decriptor */ Cardinal ndx; /* loop index */ IDBridDesc *idb_rid_ptr; void *offset; /* generic offset pointer */ char err_msg[300]; /* Swap the main part of the widget record */ swapbytes( widget_rec->size ); swapbytes( widget_rec->access ); swapbytes( widget_rec->lock ); swapbytes( widget_rec->type ); swapbytes( widget_rec->name_offs ); swapbytes( widget_rec->class_offs ); swapbytes( widget_rec->arglist_offs ); swapbytes( widget_rec->children_offs ); swapbytes( widget_rec->comment_offs ); swapbytes( widget_rec->creation_offs ); swapbytes( widget_rec->variety ); swapbytes( widget_rec->annex ); /* handle the argument list */ if (widget_rec->arglist_offs > 0) { arg_list = (RGMArgListDesc *) ((char *)widget_rec + widget_rec->arglist_offs); swapbytes( arg_list->count ); swapbytes( arg_list->extra ); for ( ndx=0 ; ndx<arg_list->count ; ndx++ ) { swapbytes( arg_list->args[ndx].tag_code ); swapbytes( arg_list->args[ndx].stg_or_relcode.tag_offs ); swapbytes( arg_list->args[ndx].arg_val.rep_type ); switch( arg_list->args[ndx].arg_val.rep_type ) { case MrmRtypeInteger: case MrmRtypeBoolean: swapbytes( arg_list->args[ndx].arg_val.datum.ival ); break; case MrmRtypeSingleFloat: swapbytes( arg_list->args[ndx].arg_val.datum.ival ); _MrmOSIEEEFloatToHost((float *) &(arg_list->args[ndx].arg_val.datum.ival)); default: swapbytes( arg_list->args[ndx].arg_val.datum.offset ); break; } offset = ((char *)widget_rec+ arg_list->args[ndx].arg_val.datum.offset); switch( arg_list->args[ndx].arg_val.rep_type ) { /* these are immediate, do nothing special */ case MrmRtypeInteger: case MrmRtypeBoolean: case MrmRtypeSingleFloat: break; /* these are offsets into the file, handle them specially */ case MrmRtypeCallback: callb_desc = (RGMCallbackDesc * )offset; Urm__SwapRGMCallbackDesc( callb_desc, widget_rec ); break; case MrmRtypeResource: res_desc = (RGMResourceDesc *)offset; Urm__SwapRGMResourceDesc( res_desc ); /* flag this resource as needing further byte swapping */ res_desc->cvt_type |= MrmResourceUnswapped; break; case MrmRtypeHorizontalInteger: case MrmRtypeVerticalInteger: case MrmRtypeHorizontalFloat: case MrmRtypeVerticalFloat: case MrmRtypeChar8: case MrmRtypeChar8Vector: case MrmRtypeCString: case MrmRtypeCStringVector: case MrmRtypeFloat: case MrmRtypePixmapImage: case MrmRtypePixmapDDIF: case MrmRtypeNull: case MrmRtypeAddrName: case MrmRtypeIconImage: case MrmRtypeFont: case MrmRtypeFontList: case MrmRtypeColor: case MrmRtypeColorTable: case MrmRtypeAny: case MrmRtypeTransTable: case MrmRtypeClassRecName: case MrmRtypeIntegerVector: case MrmRtypeXBitmapFile: case MrmRtypeCountedVector: case MrmRtypeKeysym: case MrmRtypeWideCharacter: case MrmRtypeFontSet: sprintf(err_msg,_MrmMMsg_0022, arg_list->args[ndx].arg_val.rep_type); return Urm__UT_Error ("Urm__SwapRGMWidgetRecord", err_msg, NULL, NULL, MrmFAILURE) ; break; } } } /* handle the child list */ if (widget_rec->children_offs > 0) { child_list = (RGMChildrenDesc *) ((char *)widget_rec + widget_rec->children_offs); swapbytes( child_list->count ); swapbytes( child_list->unused1 ); swapbytes( child_list->annex1 ); for ( ndx=0 ; ndx<child_list->count ; ndx++ ) { swapbytes( child_list->child[ndx].annex1 ); if (child_list->child[ndx].type == URMrRID ) { idb_rid_ptr = (IDBridDesc *)&(child_list->child[ndx].key.id); #ifdef WORD64 swap4bytes( idb_rid_ptr->internal_id.map_rec ); swap4bytes( idb_rid_ptr->internal_id.res_index ); #else swap2bytes( idb_rid_ptr->internal_id.map_rec ); swap2bytes( idb_rid_ptr->internal_id.res_index ); #endif } else swapbytes( child_list->child[ndx].key.index_offs ); } } /* handle the creation callback, if any */ if (widget_rec->creation_offs > 0) { callb_desc = (RGMCallbackDesc * ) ((char *)widget_rec + widget_rec->creation_offs); Urm__SwapRGMCallbackDesc( callb_desc, widget_rec ); } return MrmSUCCESS ; }