Skip to content

Commit

Permalink
cleanup wrc code
Browse files Browse the repository at this point in the history
rename symbols to be more readable
  • Loading branch information
jmalak committed Jul 31, 2023
1 parent 6856ffc commit 351d07e
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 143 deletions.
14 changes: 7 additions & 7 deletions bld/rc/rc/c/exeobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@
#include "exeobj.h"


static RcStatus readObjectTable( ExeFileInfo *exe )
static RcStatus readObjectTable( ExeFileInfo *src )
/*************************************************/
{
RcStatus ret;
unsigned objects_size;
pe_exe_header *pehdr;

pehdr = exe->u.PEInfo.WinHead;
pehdr = src->u.PEInfo.WinHead;
objects_size = pehdr->fheader.num_objects * sizeof( pe_object );
exe->u.PEInfo.Objects = RESALLOC( objects_size );
ret = SeekRead( exe->fp, exe->WinHeadOffset + PE_SIZE( *pehdr ), exe->u.PEInfo.Objects, objects_size );
src->u.PEInfo.Objects = RESALLOC( objects_size );
ret = SeekRead( src->fp, src->WinHeadOffset + PE_SIZE( *pehdr ), src->u.PEInfo.Objects, objects_size );
switch( ret ) {
case RS_OK:
break;
case RS_READ_ERROR:
RcError( ERR_READING_EXE, exe->name, strerror( errno ) );
RcError( ERR_READING_EXE, src->name, strerror( errno ) );
break;
case RS_READ_INCMPLT:
RcError( ERR_UNEXPECTED_EOF, exe->name );
RcError( ERR_UNEXPECTED_EOF, src->name );
break;
default:
RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS );
break;
}
CheckDebugOffset( exe );
CheckDebugOffset( src );
return( ret );
}

Expand Down
32 changes: 14 additions & 18 deletions bld/rc/rc/c/exeres2.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,27 @@ uint_32 ComputeOS2ResSegCount( WResDir dir )
* hence will be nicely aligned.
*/
static RcStatus copyOneResource( WResLangInfo *langinfo, FILE *res_fp,
FILE *out_fp, int shift_count, int *err_code )
FILE *dst_fp, int shift_count, int *err_code )
/*****************************************************************/
{
RcStatus ret;
long out_offset;
long dst_offset;
long align_amount;

/* align the output file to a boundary for shift_count */
ret = RS_OK;
out_offset = RESTELL( out_fp );
if( out_offset == -1 ) {
dst_offset = RESTELL( dst_fp );
if( dst_offset == -1 ) {
ret = RS_WRITE_ERROR;
*err_code = errno;
}
if( ret == RS_OK ) {
align_amount = AlignAmount( out_offset, shift_count );
if( RESSEEK( out_fp, align_amount, SEEK_CUR ) ) {
align_amount = AlignAmount( dst_offset, shift_count );
if( RESSEEK( dst_fp, align_amount, SEEK_CUR ) ) {
ret = RS_WRITE_ERROR;
*err_code = errno;
}
out_offset += align_amount;
dst_offset += align_amount;
}

if( ret == RS_OK ) {
Expand All @@ -216,12 +216,12 @@ static RcStatus copyOneResource( WResLangInfo *langinfo, FILE *res_fp,
}
}
if( ret == RS_OK ) {
ret = CopyExeData( res_fp, out_fp, langinfo->Length );
ret = CopyExeData( res_fp, dst_fp, langinfo->Length );
*err_code = errno;
}
if( ret == RS_OK ) {
align_amount = AlignAmount( RESTELL( out_fp ), shift_count );
ret = PadExeData( out_fp, align_amount );
align_amount = AlignAmount( RESTELL( dst_fp ), shift_count );
ret = PadExeData( dst_fp, align_amount );
*err_code = errno;
}

Expand All @@ -235,8 +235,6 @@ RcStatus CopyOS2Resources( ExeFileInfo *dst, ResFileInfo *res )
WResDirWindow wind;
OS2ResTable *restab;
WResLangInfo *langinfo;
FILE *tmp_fp;
FILE *res_fp;
RcStatus ret;
int err_code;
int shift_count;
Expand All @@ -247,8 +245,6 @@ RcStatus CopyOS2Resources( ExeFileInfo *dst, ResFileInfo *res )
int i;

restab = &(dst->u.NEInfo.OS2Res);
tmp_fp = dst->fp;
res_fp = res->fp;
tmpseg = dst->u.NEInfo.Seg.Segments;
currseg = dst->u.NEInfo.Seg.NumSegs - dst->u.NEInfo.Seg.NumOS2ResSegs;
entry = restab->resources;
Expand All @@ -260,9 +256,9 @@ RcStatus CopyOS2Resources( ExeFileInfo *dst, ResFileInfo *res )
seg_offset = 0; // shut up gcc

/* We may need to add padding before the first resource segment */
align_amount = AlignAmount( RESTELL( tmp_fp ), shift_count );
align_amount = AlignAmount( RESTELL( dst->fp ), shift_count );
if( align_amount ) {
ret = PadExeData( tmp_fp, align_amount );
ret = PadExeData( dst->fp, align_amount );
err_code = errno;
}

Expand All @@ -272,7 +268,7 @@ RcStatus CopyOS2Resources( ExeFileInfo *dst, ResFileInfo *res )
langinfo = WResGetLangInfo( wind );

if( entry->first_part ) {
seg_offset = RESTELL( tmp_fp );
seg_offset = RESTELL( dst->fp );
} else {
seg_offset += 0x10000;
}
Expand All @@ -296,7 +292,7 @@ RcStatus CopyOS2Resources( ExeFileInfo *dst, ResFileInfo *res )
continue;

/* Copy resource data */
ret = copyOneResource( langinfo, res_fp, tmp_fp, shift_count, &err_code );
ret = copyOneResource( langinfo, res->fp, dst->fp, shift_count, &err_code );
if( ret != RS_OK )
break;

Expand Down
32 changes: 16 additions & 16 deletions bld/rc/rc/c/exereslx.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void reportDuplicateResources( WResMergeError *errs )
}


RcStatus WriteLXResourceObjects( ExeFileInfo *exe, ResFileInfo *res )
RcStatus WriteLXResourceObjects( ExeFileInfo *dst, ResFileInfo *res )
/*******************************************************************/
{
RcStatus ret;
Expand All @@ -168,22 +168,22 @@ RcStatus WriteLXResourceObjects( ExeFileInfo *exe, ResFileInfo *res )
int page_shift;
unsigned i;

dir = &exe->u.LXInfo.Res;
dir = &dst->u.LXInfo.Res;

obj_index = (uint_32)-1;
page_index = exe->u.LXInfo.FirstResPage;
page_shift = exe->u.LXInfo.OS2Head.l.page_shift;
page_index = dst->u.LXInfo.FirstResPage;
page_shift = dst->u.LXInfo.OS2Head.l.page_shift;

// Determine starting offset - expects that DebugOffset is pointing where
// resources should be (current end of executable)
file_offset = exe->DebugOffset;
file_offset = dst->DebugOffset;

page_offset = 0;
padded_size = 0;
object = NULL;
map = NULL;

for( i = 0; i < exe->u.LXInfo.OS2Head.num_rsrcs; ++i ) {
for( i = 0; i < dst->u.LXInfo.OS2Head.num_rsrcs; ++i ) {
entry = &dir->resources[i];

// Fill in new object
Expand All @@ -193,7 +193,7 @@ RcStatus WriteLXResourceObjects( ExeFileInfo *exe, ResFileInfo *res )
file_offset = ((file_offset >> page_shift) + 1) << page_shift;
}
obj_index = entry->resource.object;
object = &exe->u.LXInfo.Objects[exe->u.LXInfo.FirstResObj + obj_index];
object = &dst->u.LXInfo.Objects[dst->u.LXInfo.FirstResObj + obj_index];
object->size = 0;
object->addr = 0;
object->flags = OBJ_READABLE | OBJ_RESOURCE | OBJ_DISCARDABLE
Expand All @@ -203,21 +203,21 @@ RcStatus WriteLXResourceObjects( ExeFileInfo *exe, ResFileInfo *res )
object->reserved = 0;

// Point to associated page table entry
map = &exe->u.LXInfo.Pages[page_index];
map = &dst->u.LXInfo.Pages[page_index];
padded_size = 0;
page_offset = file_offset;
}
entry->resource.object += exe->u.LXInfo.FirstResObj + 1;
entry->resource.object += dst->u.LXInfo.FirstResObj + 1;

// Copy resource data
if( RESSEEK( exe->fp, file_offset, SEEK_SET ) )
if( RESSEEK( dst->fp, file_offset, SEEK_SET ) )
return( RS_WRITE_ERROR );

langinfo = WResGetLangInfo( entry->wind );
if( RESSEEK( res->fp, langinfo->Offset, SEEK_SET ) )
return( RS_READ_ERROR );

ret = CopyExeData( res->fp, exe->fp, langinfo->Length );
ret = CopyExeData( res->fp, dst->fp, langinfo->Length );
if( ret != RS_OK ) {
return( ret );
}
Expand All @@ -229,26 +229,26 @@ RcStatus WriteLXResourceObjects( ExeFileInfo *exe, ResFileInfo *res )

// Write padding if necessary (this is critical)
if( padded_res_size > entry->resource.res_size ) {
RcPadFile( exe->fp, padded_res_size - entry->resource.res_size );
RcPadFile( dst->fp, padded_res_size - entry->resource.res_size );
}

// Update page table
map->page_offset = (page_offset - exe->u.LXInfo.OS2Head.page_off) >> page_shift;
map->page_offset = (page_offset - dst->u.LXInfo.OS2Head.page_off) >> page_shift;
map->flags = 0;
while( padded_size > OSF_DEF_PAGE_SIZE ) {
map->page_offset = (page_offset - exe->u.LXInfo.OS2Head.page_off) >> page_shift;
map->page_offset = (page_offset - dst->u.LXInfo.OS2Head.page_off) >> page_shift;
map->data_size = OSF_DEF_PAGE_SIZE;

padded_size -= OSF_DEF_PAGE_SIZE;
page_offset += OSF_DEF_PAGE_SIZE;
++map;
object->mapsize++;
map->page_offset = (page_offset - exe->u.LXInfo.OS2Head.page_off) >> page_shift;
map->page_offset = (page_offset - dst->u.LXInfo.OS2Head.page_off) >> page_shift;
map->flags = 0;
}
map->data_size = padded_size;
}
CheckDebugOffset( exe );
CheckDebugOffset( dst );
return( RS_OK );
}

Expand Down
38 changes: 19 additions & 19 deletions bld/rc/rc/c/exerespe.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ static int ComparePEResIdName( const void *e1, const void *e2 )
#undef PEE
} /* ComparePEResIdName */

static RcStatus SortDirEntry( PEResEntry * entry, void * dummy )
/*********************************************************/
static RcStatus SortDirEntry( PEResEntry *entry, void *dummy )
/************************************************************/
{
int num_entries;

Expand All @@ -422,8 +422,8 @@ static RcStatus SortDirEntry( PEResEntry * entry, void * dummy )
return( RS_OK );
} /* SortDirEntry */

static void CompleteTree( PEResDir * dir )
/****************************************/
static void CompleteTree( PEResDir *dir )
/***************************************/
{
uint_32 curr_offset;
int num_entries;
Expand Down Expand Up @@ -495,7 +495,7 @@ static RcStatus copyDataEntry( PEResEntry *entry, void *_copy_info )
* copyPEResources
* NB when an error occurs this function MUST return without altering errno
*/
static RcStatus copyPEResources( ExeFileInfo *tmp, ResFileInfo *resfiles,
static RcStatus copyPEResources( ExeFileInfo *dst, ResFileInfo *resfiles,
FILE *to_fp, bool writebyfile,
ResFileInfo **errres )
/****************************************************************/
Expand All @@ -505,31 +505,31 @@ static RcStatus copyPEResources( ExeFileInfo *tmp, ResFileInfo *resfiles,
uint_32 start_off;
RcStatus ret;

// start_rva = tmp->u.PEInfo.Res.ResRVA + tmp->u.PEInfo.Res.DirSize + tmp->u.PEInfo.Res.String.StringBlockSize;
start_off = tmp->u.PEInfo.Res.ResOffset + tmp->u.PEInfo.Res.DirSize + tmp->u.PEInfo.Res.String.StringBlockSize;
// start_rva = dst->u.PEInfo.Res.ResRVA + dst->u.PEInfo.Res.DirSize + dst->u.PEInfo.Res.String.StringBlockSize;
start_off = dst->u.PEInfo.Res.ResOffset + dst->u.PEInfo.Res.DirSize + dst->u.PEInfo.Res.String.StringBlockSize;

copy_info.to_fp = to_fp;
copy_info.errres = NULL;
copy_info.file = tmp; /* for tracking debugging info offset */
copy_info.file = dst; /* for tracking debugging info offset */
start_off = ALIGN_VALUE( start_off, sizeof( uint_32 ) );

if( RESSEEK( to_fp, start_off, SEEK_SET ) )
return( RS_WRITE_ERROR );
if( !writebyfile ) {
copy_info.curres = NULL;
ret = traverseTree( &tmp->u.PEInfo.Res, &copy_info, copyDataEntry );
ret = traverseTree( &dst->u.PEInfo.Res, &copy_info, copyDataEntry );
*errres = copy_info.errres;
} else {
ret = RS_OK;
for( ; resfiles != NULL; resfiles = resfiles->next ) {
copy_info.curres = resfiles;
if( resfiles->fp != NULL ) {
ret = traverseTree( &tmp->u.PEInfo.Res, &copy_info, copyDataEntry );
ret = traverseTree( &dst->u.PEInfo.Res, &copy_info, copyDataEntry );
} else {
ret = RS_OPEN_ERROR;
resfiles->fp = ResOpenFileRO( resfiles->name );
if( resfiles->fp != NULL ) {
ret = traverseTree( &tmp->u.PEInfo.Res, &copy_info, copyDataEntry );
ret = traverseTree( &dst->u.PEInfo.Res, &copy_info, copyDataEntry );
RCCloseFile( &(resfiles->fp) );
}
}
Expand Down Expand Up @@ -699,30 +699,30 @@ bool RcPadFile( FILE *fp, size_t pad )
* padObject
* NB when an error occurs this function MUST return without altering errno
*/
static bool padObject( PEResDir *dir, ExeFileInfo *tmp, long size )
static bool padObject( PEResDir *dir, ExeFileInfo *dst, long size )
{
long pos;
long pad;

pos = RESTELL( tmp->fp );
pos = RESTELL( dst->fp );
if( pos == -1 )
return( true );
pad = dir->ResOffset + size - pos;
if( pad > 0 ) {
RcPadFile( tmp->fp, (size_t)pad );
RcPadFile( dst->fp, (size_t)pad );
}
CheckDebugOffset( tmp );
CheckDebugOffset( dst );
return( false );
#if( 0)
char zero=0;

if( RESSEEK( tmp->fp, dir->ResOffset, SEEK_SET ) )
if( RESSEEK( dst->fp, dir->ResOffset, SEEK_SET ) )
return( true );
if( RESSEEK( tmp->fp, size - 1, SEEK_CUR ) )
if( RESSEEK( dst->fp, size - 1, SEEK_CUR ) )
return( true );
if( RESWRITE( tmp->fp, &zero, 1 ) != 1 )
if( RESWRITE( dst->fp, &zero, 1 ) != 1 )
return( true );
CheckDebugOffset( tmp );
CheckDebugOffset( dst );
return( false );
#endif
}
Expand Down
Loading

0 comments on commit 351d07e

Please sign in to comment.