Skip to content

Commit

Permalink
cleanup IDE code
Browse files Browse the repository at this point in the history
add OW "Compat" items method to 3-rd switch search pass
  • Loading branch information
jmalak committed Apr 1, 2023
1 parent 86f39a1 commit 2dfaa69
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 52 deletions.
18 changes: 6 additions & 12 deletions bld/ide/lib/cpp/mfamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool WEXPORT MFamily::hasSwitches( bool setable )
return( false );
}

MSwitch* WEXPORT MFamily::findSwitch( WString& switchtag, long fixed_version, int kludge )
MSwitch* WEXPORT MFamily::findSwitch( WString& swtag, long fixed_version, int kludge )
{
//
// Open Watcom IDE configuration/project files are buggy
Expand All @@ -136,15 +136,13 @@ MSwitch* WEXPORT MFamily::findSwitch( WString& switchtag, long fixed_version, in
// It is very hard to detect what was broken in each OW version because
// there vere no change to version number of project files
//
// type of non-exact search is defined by kludge parameter
//
int icount = _switches.count();
if( fixed_version == 0 || !isSetable( switchtag ) ) {
if( fixed_version == 0 || !isSetable( swtag ) ) {
for( int i = 0; i < icount; i++ ) {
MSwitch* sw = (MSwitch*)_switches[i];
if( sw->isTagEqual( switchtag, kludge ) ) {
if( kludge == 1 ) {
// upgrade switchtag to current configuration files version
sw->getTag( switchtag );
}
if( sw->isTagEqual( swtag, kludge ) ) {
return( sw );
}
}
Expand All @@ -153,11 +151,7 @@ MSwitch* WEXPORT MFamily::findSwitch( WString& switchtag, long fixed_version, in
MSwitch* sw = (MSwitch*)_switches[i];
if( !sw->isSetable() )
continue;
if( sw->isTagEqual( switchtag, kludge ) ) {
if( kludge == 1 ) {
// upgrade switchtag to current configuration files version
sw->getTag( switchtag );
}
if( sw->isTagEqual( swtag, kludge ) ) {
return( sw );
}
}
Expand Down
15 changes: 15 additions & 0 deletions bld/ide/lib/cpp/mstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mconfig.hpp"
#include "mstate.hpp"
#include "mrule.hpp" //temp
#include "mtypo.hpp"

Define( MState )

Expand Down Expand Up @@ -87,6 +88,20 @@ void WEXPORT MState::readSelf( WObjectFile& p )
_switch = _tool->findSwitch( _switchTag, p.version() );
if( _switch == NULL ) {
_switch = _tool->findSwitch( _switchTag, p.version(), 1 );
if( _switch == NULL ) {
if( p.version() >= 40 && p.version() < 50 && _config->version() == 4 ) {
//
// hack for buggy version of configuration/project files
//
if( FixTypo( _switchTag ) != NULL ) {
_switch = _tool->findSwitch( _switchTag, p.version() );
}
}
}
if( _switch != NULL ) {
// upgrade swtag to current configuration files version
_switch->getTag( _switchTag );
}
}
if( p.version() > 27 ) {
p.readObject( &_mode );
Expand Down
27 changes: 4 additions & 23 deletions bld/ide/lib/cpp/mswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ void MSwitch::getTag( WString& tag )
tag.concat( _text );
}

bool MSwitch::isTagEqual( WString& switchtag, int kludge )
bool MSwitch::isTagEqual( WString& swtag, int kludge )
{
WString tag;

tag = _mask;
tag.concat( _text );
if( tag == switchtag )
if( tag == swtag )
return( true );
if( kludge == 1 ) {
size_t jcount = switchtag.size();
size_t jcount = swtag.size();
if( jcount > MASK_SIZE && jcount == tag.size() ) {
for( size_t j = 0; j < jcount; j++ ) {
int ct = (unsigned char)tag[j];
int cs = (unsigned char)switchtag[j];
int cs = (unsigned char)swtag[j];
if( ct == cs )
continue;
// mask must be same
Expand All @@ -140,25 +140,6 @@ bool MSwitch::isTagEqual( WString& switchtag, int kludge )
return( false );
}

#if IDE_CFG_VERSION_MAJOR > 4
bool MSwitch::isTagEqual( MTool *tool, WString& switchtag, int kludge )
{
// first check mask
for( int i = 0; i < MASK_SIZE; ++i ) {
if( _mask[i] != switchtag[i] ) {
return( false );
}
}
// second check text/id
WString tag = switchtag;
tag.chop( MASK_SIZE );
if( tool->findSwitchByText( _text, tag, kludge ) == NULL ) {
return( false );
}
return( true );
}
#endif

MSwitch* MSwitch::addSwitch( WVList& list, const char* mask )
{
if( _mask.match( mask ) ) {
Expand Down
13 changes: 3 additions & 10 deletions bld/ide/lib/cpp/mtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "wobjfile.hpp"
#include "mconfig.hpp"
#include "mfamily.hpp"
#include "mtypo.hpp"

Define( MTool )

Expand Down Expand Up @@ -101,7 +100,7 @@ void WEXPORT MTool::writeSelf( WObjectFile& p )
}
#endif

MSwitch* WEXPORT MTool::findSwitch( WString& switchtag, long fixed_version, int kludge )
MSwitch* WEXPORT MTool::findSwitch( WString& swtag, long fixed_version, int kludge )
{
//
// Open Watcom IDE configuration/project files are buggy
Expand All @@ -110,24 +109,18 @@ MSwitch* WEXPORT MTool::findSwitch( WString& switchtag, long fixed_version, int
// It is very hard to detect what was broken in each OW version because
// there vere no change to version number of project files
//
if( fixed_version != 0 && fixed_version < 50 && _config->version() < 5 ) {
//
// hack for buggy version of configuration/project files
//
FixTypo( switchtag );
}
int icount = _families.count();
for( int i = 0; i < icount; i++ ) {
MFamily* family = (MFamily*)_families[i];
MSwitch* sw = family->findSwitch( switchtag, fixed_version, kludge );
MSwitch* sw = family->findSwitch( swtag, fixed_version, kludge );
if( sw != NULL ) {
return( sw );
}
}
icount = _incTools.count();
for( int i = 0; i < icount; i++ ) {
MTool* tool = (MTool*)_incTools[i];
MSwitch* sw = tool->findSwitch( switchtag, fixed_version, kludge );
MSwitch* sw = tool->findSwitch( swtag, fixed_version, kludge );
if( sw != NULL ) {
return( sw );
}
Expand Down
5 changes: 3 additions & 2 deletions bld/ide/lib/cpp/mtypo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ void AddTypo( WString &good, WString &bad )
SwitchTypos.add( t );
}

void FixTypo( WString &word )
WString* FixTypo( WString &word )
{
for( int i = 0; i < SwitchTypos.count(); i++ ) {
WTypo *t = (WTypo *)SwitchTypos[i];
if( t->bad() == word ) {
word = t->good();
break;
return( &word );
}
}
return( NULL );
}
3 changes: 0 additions & 3 deletions bld/ide/lib/h/mswitch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ WCLASS MSwitch : public WObject
bool hasText() { return( _text.size() > 0 ); }
bool isSetable() { return( _text.size() > 0 && *_text != ' ' ); }
bool isTagEqual( WString& tag, int kludge=0 );
#if IDE_CFG_VERSION_MAJOR > 4
bool isTagEqual( MTool *tool, WString& mask, int kludge=0 );
#endif
bool isTextEqual( MSwitch* text )
{ return( text != NULL && _text.size() > 0 && _text == text->text() ); }
MSwitch* addSwitch( WVList& list, const char* mask );
Expand Down
2 changes: 1 addition & 1 deletion bld/ide/lib/h/mtool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ WCLASS MTool : public WObject
WString& tag() { return( _tag ); };
void name( WString& s ) { s = _name; }
const WString& help() { return( _help ); }
MSwitch* findSwitch( WString& switchtag, long fixed_version=0, int kludge=0 );
MSwitch* findSwitch( WString& swtag, long fixed_version=0, int kludge=0 );
#if IDE_CFG_VERSION_MAJOR > 4
WString* findSwitchByText( WString& id, WString& text, int kludge=0 );
#endif
Expand Down
3 changes: 2 additions & 1 deletion bld/ide/lib/h/mtypo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2023 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -51,4 +52,4 @@ WCLASS WTypo : public WObject
#endif //wtypo_class

void AddTypo( WString &good, WString &bad );
void FixTypo( WString &word );
WString* FixTypo( WString &word );

0 comments on commit 2dfaa69

Please sign in to comment.