Skip to content

Commit

Permalink
wlink: improved separation of processing code from map file output code
Browse files Browse the repository at this point in the history
reformat source files
  • Loading branch information
jmalak committed Apr 26, 2024
1 parent f1db876 commit 389d67c
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 169 deletions.
51 changes: 34 additions & 17 deletions bld/wl/c/cmdline.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 @@ -176,9 +176,12 @@ static bool sysHelp( void )
if( p[0] == '?' ) {
p++; // skip '?'
#if defined( __UNIX__ )
} else if( p[0] == '-' && p[1] == '?' ) {
} else if( p[0] == '-'
&& p[1] == '?' ) {
#else
} else if( ( p[0] == '-' || p[0] == '/' ) && p[1] == '?' ) {
} else if( ( p[0] == '-'
|| p[0] == '/' )
&& p[1] == '?' ) {
#endif
p += 2; // skip '-?' or '/?'
} else if( p[0] == '\0' ) {
Expand Down Expand Up @@ -297,7 +300,8 @@ void DoCmdFile( const char *fname )
const char *namelnk;

ResetCmdFile();
if( fname == NULL || *fname == '\0' ) {
if( fname == NULL
|| *fname == '\0' ) {
NewCommandSource( NULL, NULL, COMMANDLINE );
} else {
NewCommandSource( NULL, fname, ENVIRONMENT );
Expand Down Expand Up @@ -349,7 +353,8 @@ void DoCmdFile( const char *fname )
}
}
}
if( (FmtData.type & (MK_NOVELL | MK_DOS)) && (LinkFlags & LF_INC_LINK_FLAG) ) {
if( (FmtData.type & (MK_NOVELL | MK_DOS))
&& (LinkFlags & LF_INC_LINK_FLAG) ) {
LnkMsg( FTL+MSG_FORMAT_BAD_OPTION, "s", "incremental" );
}
#ifdef _NOVELL
Expand All @@ -368,26 +373,32 @@ void DoCmdFile( const char *fname )
AddObjLib( "wovl.lib", LIB_PRIORITY_MIN ); // add a reference to wovl.lib
}
#endif
if( Name == NULL || (CmdFlags & CF_HAVE_FILES) == 0 ) {
if( Name == NULL
|| (CmdFlags & CF_HAVE_FILES) == 0 ) {
Ignite();
LnkMsg( FTL+MSG_NO_FILES_FOUND, NULL );
}
namelen = strlen( Name );
if( MapFlags & MAP_FLAG ) {
if( namelen > 0
&& MapFlags & MAP_FLAG ) {
if( MapFName == NULL ) {
MapFName = FileName( Name, namelen, E_MAP, true );
}
} else {
MapFlags = 0; // if main isn't set, don't set anything.
}
if( SymFileName == NULL && ( (CmdFlags & CF_SEPARATE_SYM)
|| (FmtData.type & MK_COM) && (LinkFlags & LF_ANY_DBI_FLAG)
|| (FmtData.type & MK_ELF) && (LinkFlags & (LF_OLD_DBI_FLAG | LF_CV_DBI_FLAG))
|| (FmtData.type & MK_RAW) && (LinkFlags & LF_ANY_DBI_FLAG)
) ) {
if( SymFileName == NULL
&& ( (CmdFlags & CF_SEPARATE_SYM)
|| (FmtData.type & MK_COM)
&& (LinkFlags & LF_ANY_DBI_FLAG)
|| (FmtData.type & MK_ELF)
&& (LinkFlags & (LF_OLD_DBI_FLAG | LF_CV_DBI_FLAG))
|| (FmtData.type & MK_RAW)
&& (LinkFlags & LF_ANY_DBI_FLAG) ) ) {
SymFileName = FileName( Name, namelen, E_SYM, true );
}
if( FmtData.make_implib && FmtData.implibname == NULL ) {
if( FmtData.make_implib
&& FmtData.implibname == NULL ) {
if( FmtData.make_impfile ) {
extension = E_LBC;
} else {
Expand Down Expand Up @@ -542,7 +553,8 @@ void FreeFormatStuff( void )
break;
}
}
if( possible != 0 && check->free_func != NULL ) {
if( possible != 0
&& check->free_func != NULL ) {
check->free_func();
}
}
Expand Down Expand Up @@ -602,7 +614,8 @@ void AddLibPaths( const char *path_list, size_t len, bool add_to_front )
void AddLibPathsToEnd( const char *path_list )
/********************************************/
{
if( path_list != NULL && *path_list != '\0' ) {
if( path_list != NULL
&& *path_list != '\0' ) {
AddLibPaths( path_list, strlen( path_list ), false );
}
}
Expand All @@ -613,7 +626,8 @@ void AddLibPathsToEndList( const char *path_list )
size_t len;
path_entry *newpath;

if( path_list != NULL && *path_list != '\0' ) {
if( path_list != NULL
&& *path_list != '\0' ) {
len = strlen( path_list );
_ChkAlloc( newpath, sizeof( path_entry ) + len );
strcpy( newpath->name, path_list );
Expand Down Expand Up @@ -659,7 +673,10 @@ static void CleanSystemList( bool burn )

for( sysown = &SysBlocks; (sys = *sysown) != NULL; ) {
name = sys->name;
if( burn || name == NULL || memcmp( "286", name, 4 ) != 0 && memcmp( "386", name, 4 ) != 0 ) {
if( burn
|| name == NULL
|| memcmp( "286", name, 4 ) != 0
&& memcmp( "386", name, 4 ) != 0 ) {
*sysown = sys->next;
if( name != NULL ) {
_LnkFree( name );
Expand Down
55 changes: 34 additions & 21 deletions bld/wl/c/loadfile.c
Expand Up @@ -198,7 +198,8 @@ static void DoCVPack( void )
int retval;
char *name;

if( (LinkFlags & LF_CVPACK_FLAG) && (LinkState & LS_LINK_ERROR) == 0 ) {
if( (LinkFlags & LF_CVPACK_FLAG)
&& (LinkState & LS_LINK_ERROR) == 0 ) {
if( SymFileName != NULL ) {
name = SymFileName;
} else {
Expand Down Expand Up @@ -281,7 +282,8 @@ static void finiLoad( void )
#endif
#ifdef _OS2
#if 0
if( (FmtData.type & (MK_OS2 | MK_WIN_NE)) && (LinkState & LS_HAVE_PPC_CODE) ) {
if( (FmtData.type & (MK_OS2 | MK_WIN_NE))
&& (LinkState & LS_HAVE_PPC_CODE) ) {
// development temporarly on hold:
FiniELFLoadFile();
return;
Expand Down Expand Up @@ -351,9 +353,6 @@ void FiniLoadFile( void )
OpenOutFiles();
SetupImpLib();
finiLoad();
if( MapFlags & MAP_FLAG ) {
WriteMapSizes();
}
CloseOutFiles();
DoCVPack();
}
Expand Down Expand Up @@ -403,13 +402,15 @@ void GetStkAddr( void )
/*********************/
/* Find the address of the stack */
{
if( (FmtData.type & MK_NOVELL) == 0 && !FmtData.dll ) {
if( (FmtData.type & MK_NOVELL) == 0
&& !FmtData.dll ) {
if( StackSegPtr != NULL ) {
StackAddr.seg = StackSegPtr->seg_addr.seg;
StackAddr.off = StackSegPtr->seg_addr.off + StackSegPtr->size;
} else {
#ifdef _OS2
if( (FmtData.type & MK_WIN_NE) && (LinkFlags & LF_STK_SIZE_FLAG) ) {
if( (FmtData.type & MK_WIN_NE)
&& (LinkFlags & LF_STK_SIZE_FLAG) ) {
PhoneyStack();
} else {
#endif
Expand Down Expand Up @@ -446,7 +447,8 @@ static void DefABSSSym( const char *name )
symbol *sym;

sym = RefISymbol( name );
if( (sym->info & SYM_DEFINED) == 0 || (sym->info & SYM_LINK_GEN) ) {
if( (sym->info & SYM_DEFINED) == 0
|| (sym->info & SYM_LINK_GEN) ) {
sym->info |= SYM_DEFINED | SYM_LINK_GEN;
#ifdef _EXE
if( FmtData.type & MK_OVERLAYS ) {
Expand Down Expand Up @@ -583,7 +585,8 @@ void SetStkSize( void )
StackSegPtr->size = StackSize;
}
} else {
if( !FmtData.dll && StackSegPtr->size >= 0x200 ) {
if( !FmtData.dll
&& StackSegPtr->size >= 0x200 ) {
StackSize = StackSegPtr->size;
} else {
StackSegPtr->size = StackSize;
Expand All @@ -606,7 +609,8 @@ void SetStartSym( const char *name )
if( StartInfo.type != START_UNDEFED ) {
if( StartInfo.type == START_IS_SYM ) {
namelen = strlen( name );
if( namelen != strlen( StartInfo.targ.sym->name.u.ptr ) || CmpRtn( StartInfo.targ.sym->name.u.ptr, name, namelen ) != 0 ) {
if( namelen != strlen( StartInfo.targ.sym->name.u.ptr )
|| CmpRtn( StartInfo.targ.sym->name.u.ptr, name, namelen ) != 0 ) {
LnkMsg( LOC+MILD_ERR+MSG_MULT_START_ADDRS_BY, "12", StartInfo.targ.sym->name.u.ptr, name );
}
} else {
Expand Down Expand Up @@ -639,7 +643,8 @@ void GetStartAddr( void )
case START_UNDEFED: // NOTE: the possible fall through
addoff = false;
if( !FmtData.dll ) {
if( Groups == NULL || (FmtData.type & MK_ELF) ) {
if( Groups == NULL
|| (FmtData.type & MK_ELF) ) {
StartInfo.addr.seg = 0;
StartInfo.addr.off = 0;
} else {
Expand All @@ -654,12 +659,12 @@ void GetStartAddr( void )
/* if startaddr is not in first segment and segment is part of */
/* a group, adjust seg + off relative to start of group */
/* instead of start of seg. This allows far call optimization to work*/
if( (StartInfo.targ.sdata->u.leader->seg_addr.seg > 0) &&
(StartInfo.targ.sdata->u.leader->group != NULL) ) {

if( (StartInfo.targ.sdata->u.leader->seg_addr.seg > 0)
&& (StartInfo.targ.sdata->u.leader->group != NULL) ) {
deltaseg = StartInfo.targ.sdata->u.leader->seg_addr.seg
- StartInfo.targ.sdata->u.leader->group->grp_addr.seg;
if( (deltaseg > 0) && (deltaseg <= StartInfo.targ.sdata->u.leader->seg_addr.seg) ) {
if( (deltaseg > 0)
&& (deltaseg <= StartInfo.targ.sdata->u.leader->seg_addr.seg) ) {
StartInfo.addr.seg -= deltaseg;
StartInfo.addr.off += 16 * deltaseg - StartInfo.targ.sdata->u.leader->group->grp_addr.off;
}
Expand All @@ -680,7 +685,8 @@ offset CalcGroupSize( group_entry *group )
{
offset size;

if(( group == DataGroup ) && ( FmtData.dgroupsplitseg != NULL )) {
if(( group == DataGroup )
&& ( FmtData.dgroupsplitseg != NULL )) {
size = FmtData.dgroupsplitseg->seg_addr.off - group->grp_addr.off - FmtData.bsspad;
DbgAssert( size >= group->size );
} else {
Expand Down Expand Up @@ -952,7 +958,9 @@ static void FlushImpBuffer( void )
void BuildImpLib( void )
/*****************************/
{
if( (LinkState & LS_LINK_ERROR) || ImpLib.handle == NIL_FHANDLE || !FmtData.make_implib )
if( (LinkState & LS_LINK_ERROR)
|| ImpLib.handle == NIL_FHANDLE
|| !FmtData.make_implib )
return;
if( ImpLib.bufsize > 0 ) {
FlushImpBuffer();
Expand Down Expand Up @@ -1095,7 +1103,9 @@ static bool WriteSegData( void *_sdata, void *_info )
unsigned long newpos;
unsigned long oldpos;

if( !sdata->isuninit && !sdata->isdead && ( sdata->length > 0 ) ) {
if( !sdata->isuninit
&& !sdata->isdead
&& ( sdata->length > 0 ) ) {
newpos = info->seg_start + sdata->a.delta;
if( info->repos ) {
SeekLoad( newpos );
Expand Down Expand Up @@ -1139,7 +1149,8 @@ static bool DoGroupLeader( void *_seg, void *_info )
grpwriteinfo *info = _info;

// If class or sector should not be output, skip it
if( EMIT_CLASS( seg->class ) && EMIT_SEG( seg ) ) {
if( EMIT_CLASS( seg->class )
&& EMIT_SEG( seg ) ) {
info->seg_start = info->grp_start + SEG_GROUP_DELTA( seg );
DoWriteLeader( seg, info );
}
Expand Down Expand Up @@ -1364,7 +1375,8 @@ void SeekLoad( unsigned long offset )
outfilelist *outfile;

outfile = CurrSect->outfile;
if( outfile->buffer != NULL && ( outfile->origin + offset ) < outfile->bufpos ) {
if( outfile->buffer != NULL
&& ( outfile->origin + offset ) < outfile->bufpos ) {
FlushBuffFile( outfile );
}
if( outfile->buffer == NULL ) {
Expand All @@ -1381,7 +1393,8 @@ void SeekEndLoad( unsigned long offset )
outfilelist *outfile;

outfile = CurrSect->outfile;
if( outfile->buffer != NULL && offset > 0 ) {
if( outfile->buffer != NULL
&& offset > 0 ) {
FlushBuffFile( outfile );
}
if( outfile->buffer == NULL ) {
Expand Down

0 comments on commit 389d67c

Please sign in to comment.