45 fin = fopen( inFile,
"rb" );
59 fin = fopen( inFile,
"r+b" );
73 fout = fopen( outFile,
"wb" );
89 printf(
" MUD_free: freeing:" );
122 printf(
"MUD_encode: buf.size = %d\n", pBuf->
size +
MUD_size( pMUD ) );
123 printf(
"MUD_encode: buf.buf = %08X\n", pBuf->
buf );
160 printf(
"MUD_decode: decoding the core...\n" );
174 printf(
"MUD_decode: done \n" );
175 printf(
" decoding the section-specific...\n" );
184 printf(
"MUD_decode: done\n" );
204 if( pMUD ==
NULL )
return;
227 if( pMUD ==
NULL )
return;
289 bzero( &buf,
sizeof(
BUF ) );
293 fwrite( buf.
buf, buf.
size, 1, fout );
315 pMUD_grp->
pParent = pMUD_parentGrp;
317 pMUD_grp->
pos = ftell( fout );
322 pMUD_grp->
num = numMems;
324 fseek( fout, pMUD_grp->
core.
size, 1 );
337 *ppMUD_index !=
NULL;
338 ppMUD_index = &(*ppMUD_index)->
pNext ) ;
342 (*ppMUD_index)->secID =
MUD_secID( pMUD );
382 fseek( fout, pMUD_grp->
pos, 0 );
384 fseek( fout, pos, 0 );
417 printf(
"MUD_read: reading the section size...\n" );
423 if( ( pos = ftell( fin ) ) == EOF )
return(
NULL );
424 if( fread( &size, 4, 1, fin ) == 0 )
return(
NULL );
426 if( fseek( fin, pos, 0 ) == EOF )
return(
NULL );
429 printf(
"MUD_read: got %lu\n", (
unsigned long)(size) );
430 printf(
" pos = %d\n", pos );
431 printf(
" reading the section ...\n" );
434 bzero( &buf,
sizeof(
BUF ) );
436 if( fread( buf.
buf, (
size_t)size, 1, fin ) == 0 )
443 printf(
"MUD_read: done\n" );
444 printf(
" decoding the section...\n" );
451 if( pMUD_new ==
NULL )
460 printf(
"MUD_read: done\n" );
470 for( i = 0; i < ((
MUD_SEC_GRP*)pMUD_new)->num; i++ )
473 if( pMUD_next ==
NULL )
489 printf(
"MUD_read: Group after reading members:\n" );
501 if( pMUD_next ==
NULL )
569 pGrpIndex = pGrpIndex->
pNext )
571 if( pGrpIndex ==
NULL )
return( offset );
573 pGrpIndex->
offset = offset;
600 if( ( pos = ftell( fin ) ) == EOF )
return(
NULL );
602 bzero( &mud,
sizeof(
MUD_SEC ) );
603 bzero( &buf,
sizeof(
BUF ) );
610 if( fread( buf.
buf, size, 1, fin ) == 0 )
616 fseek( fin, pos, 0 );
652 pMUD_head = va_arg( args,
void* );
654 va_start( args, pMUD_head );
657 ppSeekEntry = &pSeekList;
658 while( ( ( secID = va_arg( args,
UINT32 ) ) != 0 ) &&
659 ( ( instanceID = va_arg( args,
UINT32 ) ) != 0 ) )
662 (*ppSeekEntry)->
secID = secID;
663 (*ppSeekEntry)->instanceID = instanceID;
664 ppSeekEntry = &(*ppSeekEntry)->
pNext;
668 pMUD_start = (
MUD_SEC*)pMUD_head;
671 for( pSeekEntry = pSeekList;
673 pSeekEntry = pSeekEntry->
pNext )
678 for( pMUD = pMUD_start; pMUD !=
NULL; pMUD = pMUD->
core.
pNext )
751 fio = va_arg( args, FILE* );
753 va_start( args, fio );
756 ppSeekEntry = &pSeekList;
757 while( ( ( secID = va_arg( args,
UINT32 ) ) != 0 ) &&
758 ( ( instanceID = va_arg( args,
UINT32 ) ) != 0 ) )
761 (*ppSeekEntry)->
secID = secID;
762 (*ppSeekEntry)->instanceID = instanceID;
763 ppSeekEntry = &(*ppSeekEntry)->
pNext;
767 for( pSeekEntry = pSeekList;
769 pSeekEntry = pSeekEntry->
pNext )
799 if( fseek( fio,
MUD_size( pMUD ), 1 ) == EOF )
808 if( ateof || ( pSeekEntry !=
NULL ) )
return( EOF );
810 return( ftell( fio ) );
823 if( pMUD_parent !=
NULL )
825 for( pMUD_index = pMUD_parent->
pMemIndex;
827 pMUD_index = pMUD_index->
pNext )
829 if( ( pMUD_index->
secID == secID ) &&
832 if( fseek( fio, pMUD_index->
offset, 1 ) == EOF )
854 while( !found && !ateof )
872 if( fseek( fio,
MUD_size( pMUD ), 1 ) == EOF )
878 if( ateof || !found )
return(
NULL );
891 if( fseek( fio, size, 0 ) == EOF )
return( EOF );
893 return( ftell( fio ) );
902 if( pMUD_new ==
NULL )
return;
904 for( ppMUD = (
MUD_SEC**)ppMUD_head;
926 if( pMUD ==
NULL )
return;
931 for( ppMUD = &pMUD_grp->
pMem;
973 printf(
"MUD_CORE_proc: MUD_GET_SIZE returns size=%d\n",size);
977 printf(
" CORE: size=[%lu], secID=[0x%08lX], instanceID=[0x%08lX]\n",
1017 printf(
" INDEX: offset=[%lu], secID=[0x%08lX], instanceID=[0x%08lX]\n",
1018 (
unsigned long)(pMUD->
offset), (
unsigned long)(pMUD->
secID),
void * MUD_read(FILE *fin, MUD_IO_OPT io_opt)
int MUD_getSize(void *pMUD)
int MUD_CORE_proc(MUD_OPT op, BUF *pBuf, MUD_SEC *pMUD)
void MUD_show(void *pMUD, MUD_IO_OPT io_opt)
void * MUD_readFile(FILE *fin)
BOOL MUD_writeGrpMem(FILE *fout, MUD_SEC_GRP *pMUD_grp, void *pMUD)
BOOL MUD_writeGrpStart(FILE *fout, MUD_SEC_GRP *pMUD_parentGrp, MUD_SEC_GRP *pMUD_grp, int numMems)
int MUD_totSize(void *pMUD)
BOOL MUD_encode(BUF *pBuf, void *pMUD, MUD_IO_OPT io_opt)
void MUD_assignCore(MUD_SEC *pMUD1, MUD_SEC *pMUD2)
int MUD_INDEX_proc(MUD_OPT op, BUF *pBuf, MUD_INDEX *pMUD)
FILE * MUD_openInput(char *inFile)
MUD_SEC * fseekNext(FILE *fio, MUD_SEC_GRP *pMUD_parent, UINT32 secID, UINT32 instanceID)
BOOL MUD_write(FILE *fout, void *pMUD, MUD_IO_OPT io_opt)
int MUD_fseekFirst(FILE *fio)
FILE * MUD_openOutput(char *outFile)
void MUD_addToGroup(MUD_SEC_GRP *pMUD_grp, void *pMUD)
FILE * MUD_openInOut(char *inFile)
void MUD_heads(void *pMUD, MUD_IO_OPT io_opt)
BOOL MUD_writeGrpEnd(FILE *fout, MUD_SEC_GRP *pMUD_grp)
BOOL MUD_writeEnd(FILE *fout)
MUD_SEC * MUD_peekCore(FILE *fin)
void MUD_add(void **ppMUD_head, void *pMUD_new)
UINT32 MUD_setSizes(void *pMUD)
void * MUD_decode(BUF *pBuf)
void MUD_free(void *pMUD)
void addIndex(MUD_SEC_GRP *pMUD_grp, void *pMUD)
void * MUD_search(va_alist)
BOOL MUD_writeFile(FILE *fout, void *pMUD_head)
struct _SEEK_ENTRY SEEK_ENTRY
struct _MUD_SEC_GRP MUD_SEC_GRP
struct _MUD_INDEX MUD_INDEX
#define MUD_instanceID(pM)
int MUD_SEC_FIXED_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_FIXED *pMUD)
void bdecode_4(void *b, void *p)
MUD_SEC * MUD_new(UINT32 secID, UINT32 instanceID)
struct _MUD_INDEX * pNext
struct _MUD_SEC_GRP * pParent
struct _SEEK_ENTRY * pNext