static int ConvertMResources( WResFileID infile, WResFileID outfile, WResDir outdir ) /******************************************************************/ { MResResourceHeader * mheader; WResID * name; WResID * type; int error; int lastheader; /*TRUE if lastheader has been read*/ uint_32 offset; int duplicate; mheader = MResReadResourceHeader( infile ); /* assume that any error reading here means end of file */ lastheader = (mheader == NULL); error = FALSE; while (!lastheader && !error) { name = ConvertNameOrOrdToID( mheader->Name ); type = ConvertNameOrOrdToID( mheader->Type ); offset = tell( outfile ); /* copy the resource if it isn't a name table or if the user */ /* requested that name tables be copied */ if (type->IsName || type->ID.Num != RT_NAMETABLE || CmdLineParms.KeepNameTable ) { error = WResAddResource( type, name, mheader->MemoryFlags, offset, mheader->Size, outdir, NULL, &(duplicate) ); if (duplicate) { /* print message and continue */ puts( "Error: duplicate entry" ); error = FALSE; } else { error = BinaryCopy( infile, outfile, mheader->Size ); } } else { lseek( infile, mheader->Size, SEEK_CUR ); } WResIDFree( name ); WResIDFree( type ); MResFreeResourceHeader( mheader ); mheader = MResReadResourceHeader( infile ); /* assume that any error reading here means end of file */ lastheader = (mheader == NULL); } return( error ); } /* ConvertMResources */
static bool ConvertMResources( FILE *in_fp, FILE *out_fp, WResDir outdir ) /************************************************************************/ { MResResourceHeader * mheader; WResID * name; WResID * type; bool error; bool lastheader; /* true if lastheader has been read */ uint_32 offset; bool duplicate; mheader = MResReadResourceHeader( in_fp ); /* assume that any error reading here means end of file */ lastheader = ( mheader == NULL ); error = false; while( !lastheader && !error ) { name = ConvertNameOrOrdToID( mheader->Name ); type = ConvertNameOrOrdToID( mheader->Type ); offset = RESTELL( out_fp ); /* copy the resource if it isn't a name table or if the user */ /* requested that name tables be copied */ if( type->IsName || type->ID.Num != RESOURCE2INT( RT_NAMETABLE ) || CmdLineParms.KeepNameTable ) { error = WResAddResource( type, name, mheader->MemoryFlags, offset, mheader->Size, outdir, NULL, &duplicate ); if( duplicate ) { /* print message and continue */ puts( "Error: duplicate entry" ); error = false; } else { error = BinaryCopy( in_fp, out_fp, mheader->Size ); } } else { RESSEEK( in_fp, mheader->Size, SEEK_CUR ); } WResIDFree( name ); WResIDFree( type ); MResFreeResourceHeader( mheader ); mheader = MResReadResourceHeader( in_fp ); /* assume that any error reading here means end of file */ lastheader = ( mheader == NULL ); } return( error ); } /* ConvertMResources */
static int readMResDir( WResFileID handle, WResDir currdir, int *dup_discarded, char iswin32, void *fileinfo ) /******************************************************************************/ { MResResourceHeader *head = NULL; M32ResResourceHeader *head32 = NULL; WResDirWindow dup; int error; off_t seek_rc; WResID *name; WResID *type; error = FALSE; if( iswin32 ) { /* Read NULL header */ head32 = M32ResReadResourceHeader( handle ); if( head32 != NULL ) { MResFreeResourceHeader( head32->head16 ); WRESFREE( head32 ); } else { error = TRUE; } if( !error ) { head32 = M32ResReadResourceHeader( handle ); if( head32 != NULL ) { head = head32->head16; } else { error = TRUE; } } } else { head = MResReadResourceHeader( handle ); if( head == NULL ) error = TRUE; } if( dup_discarded != NULL ) { *dup_discarded = FALSE; } if( iswin32 ) { currdir->TargetOS = WRES_OS_WIN32; } else { currdir->TargetOS = WRES_OS_WIN16; } /* assume that a NULL head is the EOF which is the only way of detecting */ /* the end of a MS .RES file */ while( head != NULL && !( iswin32 && head32 == NULL ) && !error ) { name = WResIDFromNameOrOrd( head->Name ); type = WResIDFromNameOrOrd( head->Type ); error = (name == NULL || type == NULL); /* MResReadResourceHeader leaves the file at the start of the resource*/ if( !error ) { if( !type->IsName && type->ID.Num == RT_NAMETABLE ) { error = FALSE; } else { error = WResAddResource2( type, name, head->MemoryFlags, WRESTELL( handle ), head->Size, currdir, NULL, &dup, fileinfo ); if( error && !WResIsEmptyWindow( dup ) ) { error = FALSE; if( dup_discarded != NULL ) { *dup_discarded = TRUE; } } } } if( !error ) { seek_rc = WRESSEEK( handle, head->Size, SEEK_CUR ); if( seek_rc == -1L ) { error = TRUE; WRES_ERROR( WRS_SEEK_FAILED ); } } if( name != NULL ) { WRESFREE( name ); name = NULL; } if( type != NULL ) { WRESFREE( type ); type = NULL; } MResFreeResourceHeader( head ); if( iswin32 ) { WRESFREE( head32 ); } if( !error ) { if( iswin32 ) { head32 = M32ResReadResourceHeader( handle ); if( head32 != NULL ) { head = head32->head16; } } else { head = MResReadResourceHeader( handle ); } } } return( error ); } /* readMResDir */