Skip to content

Commit

Permalink
nwlib: separate dictionary structure from arch_header
Browse files Browse the repository at this point in the history
it is used only by LibWalk and it is always reloaded
  • Loading branch information
jmalak committed Jun 4, 2024
1 parent d053120 commit 8f97687
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
26 changes: 13 additions & 13 deletions bld/nwlib/c/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static size_t ARstrlen( const char * str )
return( c - str );
}

char *GetARName( libfile io, ar_header *header, arch_header *arch )
/*****************************************************************/
char *GetARName( libfile io, ar_header *header, arch_dict *dict )
/***************************************************************/
{
char buffer[AR_NAME_LEN + 1];
char *buf;
Expand All @@ -91,7 +91,7 @@ char *GetARName( libfile io, ar_header *header, arch_header *arch )

if( header->name[0] == '/' ) {
len = GetARNumeric( header->name + 1, AR_NAME_LEN - 1 );
buf = arch->fnametab + len;
buf = dict->fnametab + len;
} else if( header->name[0] == '#'
&& header->name[1] == '1'
&& header->name[2] == '/') {
Expand All @@ -111,20 +111,20 @@ char *GetARName( libfile io, ar_header *header, arch_header *arch )
return( name );
}

char *GetFFName( arch_header *arch )
/**********************************/
char *GetFFName( arch_dict *dict )
/********************************/
{
char *name;

name = NULL;
if( arch->ffnametab != NULL
&& arch->nextffname != NULL ) {
name = MemDupStr( arch->nextffname );
arch->nextffname += strlen( name ) + 1;
if( arch->nextffname >= arch->lastffname
|| ( arch->nextffname[0] == '\n'
&& arch->nextffname + 1 >= arch->lastffname ) ) {
arch->nextffname = NULL;
if( dict->ffnametab != NULL
&& dict->nextffname != NULL ) {
name = MemDupStr( dict->nextffname );
dict->nextffname += strlen( name ) + 1;
if( dict->nextffname >= dict->lastffname
|| ( dict->nextffname[0] == '\n'
&& dict->nextffname + 1 >= dict->lastffname ) ) {
dict->nextffname = NULL;
}
}
return( name );
Expand Down
2 changes: 0 additions & 2 deletions bld/nwlib/c/implib.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,6 @@ void ProcessImportWlib( const char *name )
arch.mode = AR_S_IFREG | (AR_S_IRUSR | AR_S_IWUSR | AR_S_IRGRP | AR_S_IWGRP | AR_S_IROTH | AR_S_IWOTH);
arch.size = 0;
arch.libtype = WL_LTYPE_NONE;
arch.fnametab = NULL;
arch.ffnametab = NULL;

dllName.name = dll_name;
dllName.len = strlen( dll_name );
Expand Down
39 changes: 20 additions & 19 deletions bld/nwlib/c/libwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2024-2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -39,20 +39,20 @@
#include "clibext.h"


static void AllocFNameTab( libfile io, arch_header *arch )
/********************************************************/
static void AllocFNameTab( libfile io, arch_header *arch, arch_dict *dict )
/*************************************************************************/
{
MemFree( arch->fnametab );
GetFileContents( io, arch, &arch->fnametab );
MemFree( dict->fnametab );
GetFileContents( io, arch, &dict->fnametab );
}

static void AllocFFNameTab( libfile io, arch_header *arch )
/*********************************************************/
static void AllocFFNameTab( libfile io, arch_header *arch, arch_dict *dict )
/**************************************************************************/
{
MemFree( arch->ffnametab );
GetFileContents( io, arch, &arch->ffnametab );
arch->nextffname = arch->ffnametab;
arch->lastffname = arch->nextffname + arch->size;
MemFree( dict->ffnametab );
GetFileContents( io, arch, &dict->ffnametab );
dict->nextffname = dict->ffnametab;
dict->lastffname = dict->nextffname + arch->size;
}


Expand Down Expand Up @@ -100,11 +100,12 @@ void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn )
} else {
ar_header ar;
size_t bytes_read;
arch_dict dict;
// int dict_count;

// dict_count = 0;
arch->fnametab = NULL;
arch->ffnametab = NULL;
dict.fnametab = NULL;
dict.ffnametab = NULL;
while( (bytes_read = LibRead( io, &ar, AR_HEADER_SIZE )) != 0 ) {
if( bytes_read != AR_HEADER_SIZE ) {
BadLibrary( io );
Expand All @@ -130,23 +131,23 @@ void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn )
} else if( ar.name[0] == '/'
&& ar.name[1] == '/'
&& ar.name[2] == ' ' ) {
AllocFNameTab( io, arch );
AllocFNameTab( io, arch, &dict );
} else if( ar.name[0] == '/'
&& ar.name[1] == '/'
&& ar.name[2] == '/' ) {
AllocFFNameTab( io, arch );
AllocFFNameTab( io, arch, &dict );
} else {
arch->name = GetARName( io, &ar, arch );
arch->ffname = GetFFName( arch );
arch->name = GetARName( io, &ar, &dict );
arch->ffname = GetFFName( &dict );
rtn( io, arch );
MemFree( arch->name );
MemFree( arch->ffname );
}
pos += __ROUND_UP_SIZE_EVEN( arch->size );
LibSeek( io, pos, SEEK_SET );
}
MemFree( arch->fnametab );
MemFree( arch->ffnametab );
MemFree( dict.fnametab );
MemFree( dict.ffnametab );
}
arch->name = oldname;
}
2 changes: 0 additions & 2 deletions bld/nwlib/c/wlibutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ libfile NewArchLibOpen( arch_header *arch, const char *filename )
arch->mode = buf.st_mode;
arch->size = buf.st_size;
arch->libtype = WL_LTYPE_NONE;
arch->fnametab = NULL;
arch->ffnametab = NULL;
return( LibOpen( filename, LIBOPEN_READ ) );
}

Expand Down
5 changes: 3 additions & 2 deletions bld/nwlib/h/convert.h
Original file line number Diff line number Diff line change
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,7 +31,7 @@
****************************************************************************/


extern char *GetARName( libfile io, ar_header *header, arch_header *arch );
extern char *GetFFName( arch_header *arch );
extern char *GetARName( libfile io, ar_header *header, arch_dict *dict );
extern char *GetFFName( arch_dict *dict );
extern void GetARHeaderValues( ar_header *header, arch_header * arch );
extern void CreateARHeader( ar_header *ar, arch_header * arch );
13 changes: 8 additions & 5 deletions bld/nwlib/h/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2024-2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -78,6 +78,13 @@ typedef enum {
#undef WL_FTYPE
} file_type;

typedef struct arch_dict {
char *fnametab;
char *ffnametab;
char *nextffname;
char *lastffname;
} arch_dict;

typedef struct arch_header {
char *name;
char *ffname; // Full filename
Expand All @@ -86,9 +93,5 @@ typedef struct arch_header {
arch_gid gid;
arch_mode mode;
arch_file_size size;
char *fnametab;
char *ffnametab;
char *nextffname;
char *lastffname;
lib_type libtype;
} arch_header;

0 comments on commit 8f97687

Please sign in to comment.