Skip to content

Commit

Permalink
cleanup wlib code to use arch_header more general
Browse files Browse the repository at this point in the history
it is preparation for adding library/object type field to enable module comparision function change in dependency of type to fix issue #1232
  • Loading branch information
jmalak committed Feb 11, 2024
1 parent a42ca07 commit 593b1d5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
7 changes: 4 additions & 3 deletions bld/nwlib/c/inlib.c
Expand Up @@ -2,6 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -37,15 +38,15 @@

static input_lib *InputLibs;

void AddInputLib( libfile io, const char *name )
void AddInputLib( libfile io, arch_header *arch )
{
input_lib *new;

new = MemAllocGlobal( sizeof( *new ) + strlen( name ) );
new = MemAllocGlobal( sizeof( *new ) + strlen( arch->name ) );
new->next = InputLibs;
InputLibs = new;
new->io = io;
strcpy( new->name, name );
strcpy( new->name, arch->name );
}

void CloseOneInputLib( void )
Expand Down
19 changes: 10 additions & 9 deletions bld/nwlib/c/libwalk.c
Expand Up @@ -2,6 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -55,8 +56,8 @@ static void AllocFFNameTab( const char *name, libfile io, arch_header *arch )
}


void LibWalk( libfile io, const char *name, void (*rtn)( arch_header *, libfile io ) )
/************************************************************************************/
void LibWalk( libfile io, arch_header *parch, void (*rtn)( arch_header *, libfile io ) )
/**************************************************************************************/
{
ar_header ar;
arch_header arch;
Expand All @@ -69,10 +70,10 @@ void LibWalk( libfile io, const char *name, void (*rtn)( arch_header *, libfile
arch.ffnametab = NULL;
while( (bytes_read = LibRead( io, &ar, AR_HEADER_SIZE )) != 0 ) {
if( bytes_read != AR_HEADER_SIZE ) {
BadLibrary( name );
BadLibrary( parch->name );
}
if( strncmp( ar.header_ident, AR_HEADER_IDENT, AR_HEADER_IDENT_LEN ) ) {
BadLibrary( name );
BadLibrary( parch->name );
}
GetARHeaderValues( &ar, &arch );
pos = LibTell( io );
Expand All @@ -88,9 +89,9 @@ void LibWalk( libfile io, const char *name, void (*rtn)( arch_header *, libfile
}
*/
} else if( ar.name[0] == '/' && ar.name[1] == '/' && ar.name[2] == ' ' ) {
AllocFNameTab( name, io, &arch );
AllocFNameTab( parch->name, io, &arch );
} else if( ar.name[0] == '/' && ar.name[1] == '/' && ar.name[2] == '/' ) {
AllocFFNameTab( name, io, &arch );
AllocFFNameTab( parch->name, io, &arch );
} else {
arch.name = GetARName( io, &ar, &arch );
arch.ffname = GetFFName( &arch );
Expand All @@ -105,8 +106,8 @@ void LibWalk( libfile io, const char *name, void (*rtn)( arch_header *, libfile
MemFree( arch.ffnametab );
}

void OMFLibWalk( libfile io, char *name, void (*rtn)( arch_header *arch, libfile io ) )
/*************************************************************************************/
void OMFLibWalk( libfile io, arch_header *parch, void (*rtn)( arch_header *arch, libfile io ) )
/*********************************************************************************************/
{
unsigned_16 pagelen;
long offset;
Expand All @@ -127,7 +128,7 @@ void OMFLibWalk( libfile io, char *name, void (*rtn)( arch_header *arch, libfile
Options.page_size = pagelen;
}
LibSeek( io, offset, SEEK_CUR );
NewArchHeader( &arch, name );
arch = *parch;
offset = LibTell( io );
while( LibRead( io, &type, sizeof( type ) ) == sizeof( type ) && ( type == CMD_THEADR ) ) {
LibSeek( io, 2, SEEK_CUR );
Expand Down
24 changes: 12 additions & 12 deletions bld/nwlib/c/proclib.c
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -139,27 +139,27 @@ static void ProcessLibOrObj( char *name, objproc obj, void (*process)( arch_head
arch_header arch;

NewArchHeader( &arch, name );
io = LibOpen( name, LIBOPEN_READ );
io = LibOpen( arch.name, LIBOPEN_READ );
if( LibRead( io, buff, sizeof( buff ) ) != sizeof( buff ) ) {
FatalError( ERR_CANT_READ, name, strerror( errno ) );
FatalError( ERR_CANT_READ, arch.name, strerror( errno ) );
}
if( memcmp( buff, AR_IDENT, sizeof( buff ) ) == 0 ) {
// AR format
AddInputLib( io, name );
LibWalk( io, name, process );
AddInputLib( io, &arch );
LibWalk( io, &arch, process );
if( Options.libtype == WL_LTYPE_NONE ) {
Options.libtype = WL_LTYPE_AR;
}
} else if( memcmp( buff, LIBMAG, LIBMAG_LEN ) == 0 ) {
// MLIB format
if( LibRead( io, buff, sizeof( buff ) ) != sizeof( buff ) ) {
FatalError( ERR_CANT_READ, name, strerror( errno ) );
FatalError( ERR_CANT_READ, arch.name, strerror( errno ) );
}
if( memcmp( buff, LIB_CLASS_DATA_SHOULDBE, LIB_CLASS_LEN + LIB_DATA_LEN ) ) {
BadLibrary( name );
BadLibrary( arch.name );
}
AddInputLib( io, name );
LibWalk( io, name, process );
AddInputLib( io, &arch );
LibWalk( io, &arch, process );
if( Options.libtype == WL_LTYPE_NONE ) {
Options.libtype = WL_LTYPE_MLIB;
}
Expand All @@ -176,19 +176,19 @@ static void ProcessLibOrObj( char *name, objproc obj, void (*process)( arch_head
beaten up with large blunt objects.
*/
// OMF format
AddInputLib( io, name );
AddInputLib( io, &arch );
LibSeek( io, 0, SEEK_SET );
if( Options.libtype == WL_LTYPE_NONE ) {
Options.libtype = WL_LTYPE_OMF;
}
OMFLibWalk( io, name, process );
OMFLibWalk( io, &arch, process );
} else if( obj == OBJ_PROCESS ) {
// Object
LibSeek( io, 0, SEEK_SET );
AddObjectSymbols( &arch, io, 0 );
LibClose( io );
} else if( obj == OBJ_ERROR ) {
BadLibrary( name );
BadLibrary( arch.name );
} else {
LibClose( io );
}
Expand Down
3 changes: 2 additions & 1 deletion bld/nwlib/h/inlib.h
Expand Up @@ -2,6 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -35,7 +36,7 @@ typedef struct input_lib {
char name[1];
} input_lib;

extern void AddInputLib( libfile io, const char *name );
extern void AddInputLib( libfile io, arch_header *arch );
extern void CloseOneInputLib( void );
extern void CloseInputLibs( void );
extern void FiniInputLibs( void );
Expand Down
5 changes: 3 additions & 2 deletions bld/nwlib/h/libwalk.h
Expand Up @@ -2,6 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -30,5 +31,5 @@
****************************************************************************/


extern void LibWalk( libfile io, const char *name, void (*rtn)( arch_header *arch, libfile io ) );
extern void OMFLibWalk( libfile io, char *name, void (*rtn)( arch_header *arch, libfile io ) );
extern void LibWalk( libfile io, arch_header *arch, void (*rtn)( arch_header *arch, libfile io ) );
extern void OMFLibWalk( libfile io, arch_header *arch, void (*rtn)( arch_header *arch, libfile io ) );

0 comments on commit 593b1d5

Please sign in to comment.