mcompon.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 799 行 · 第 1/2 页
CPP
799 行
return FALSE;
}
void MComponent::refresh()
{
updateItemList();
updateAllViews();
}
void MComponent::touchItem( MItem* item )
{
if( item->isMask() ) {
for( int i=0; i<_items.count(); i++ ) {
MItem* m = (MItem*)_items[i];
if( item == m->parent() ) {
m->touchResult();
}
}
} else {
item->touchResult();
}
}
void MComponent::touchTarget( bool all )
{
_target->touchResult();
if( all ) {
initWorkFiles( _workFiles );
for( int i=0; i<_workFiles.count(); i++ ) {
MItem* m = ((MWorkFile*)_workFiles[i])->item();
if( !m->isMask() ) {
m->touchResult();
}
}
finiWorkFiles();
}
}
void MComponent::getTargetCommand( WString& cmd )
{
WFileName fn; _target->absName( fn );
MWorkFile w( fn, _mode, _target, this );
expand( cmd, _before );
w.makeCommand( cmd, NULL );
expand( cmd, _after );
}
void MComponent::getItemCommand( MItem* item, WString& cmd )
{
initWorkFiles( _workFiles );
for( int i=0; i<_workFiles.count(); i++ ) {
MWorkFile* w = (MWorkFile*)_workFiles[i];
if( w->item() == item ) {
w->makeCommand( cmd, NULL );
break;
}
}
finiWorkFiles();
}
bool MComponent::addFromFilename( WFileName& filename, WString& err )
{
if( filename.isMask() ) {
return addFromMask( filename, err );
}
MRule* rule = _config->findMatchingRule( filename, _target->rule(), _mask );
if( rule ) {
if( rule == _config->nilRule() ) {
unsigned cnt;
cnt = _items.count();
for( ; cnt > 0; cnt-- ) {
if( *(MItem *)_items[ cnt - 1 ] == filename ) break;
}
if( cnt == 0 ) {
MItem* item = new MItem( filename, this, rule );
newItem( item );
} else {
return FALSE;
}
} else {
MItem* item = new MItem( filename, this, rule );
MComponent* comp = NULL;
MItem* m = _project->findSameResult( item, &comp );
if( !m ) {
newItem( item );
} else {
delete item;
if( comp != this ) {
err.printf( "Conflicting file '%s' found in target '%s'",
(const char*)*m, (const char*)*comp->target() );
return FALSE;
}
}
}
return TRUE;
}
return FALSE;
}
bool MComponent::addFromMask( WFileName& search, WString& err )
{
bool ok = TRUE;
WFileName asearch( search );
asearch.absoluteTo( _filename );
DIR* dir = opendir( asearch );
if( !dir ) {
err.printf( "no files found for '%s'", (const char*)search );
ok = FALSE;
} else {
for(;;) {
struct dirent* ent = readdir( dir );
if( !ent ) break;
WFileName newfile( ent->d_name );
newfile.setDrive( search.drive() );
newfile.setDir( search.dir() );
// newfile.toLower();
if( !addFromFilename( newfile, err ) ) {
ok = FALSE;
break;
}
}
closedir( dir );
}
return ok;
}
static char makeExt[] = { ".mk1" };
void MComponent::addMakeFile( ContFile& pmak )
{
WFileName mk( _filename );
mk.setExt( makeExt );
if( mk.needQuotes() ) {
mk.addQuotes();
}
pmak.printf( "!include %s\n", (const char*)mk );
}
bool MComponent::makeMakeFile()
{
bool ok = TRUE;
WFileName mk( _filename );
mk.setExt( makeExt );
updateItemList();
if( needsMake() || !mk.attribs() ) {
ContFile tmak;
if( !tmak.open( mk, OStyleWrite ) ) {
ok = FALSE;
} else {
tmak.puts( "!define BLANK \"\"\n" );
initWorkFiles( _workFiles );
// for( int i=0; i<_workFiles.count(); i++ ) {
// ((MWorkFile*)_workFiles[i])->dump( tmak );
// }
writeRule( tmak );
finiWorkFiles();
tmak.close();
ok = tmak.ok();
setNeedsMake( FALSE );
}
}
return ok;
}
void MComponent::addWorkFiles( WVList& workFiles, SwMode mode, MComponent* comp )
{
for( int i=0; i<_items.count(); i++ ) {
MItem* m = (MItem*)_items[i];
WFileName f;
m->absName( f );
MWorkFile* w = new MWorkFile( f, mode, m, comp );
workFiles.add( w );
}
}
void MComponent::initWorkFiles( WVList& workFiles )
{
addWorkFiles( workFiles, _mode, this );
for( int i=0; i<_workFiles.count(); i++ ) {
MWorkFile* w = (MWorkFile*)_workFiles[i];
if( !w->isMask() ) {
for( int j=0; j<_workFiles.count(); j++ ) {
MWorkFile* x = (MWorkFile*)_workFiles[j];
if( x->isMask() && w->match( *x, matchFName|matchExt ) ) {
w->insertStates( x );
}
}
}
}
}
void MComponent::finiWorkFiles()
{
_workFiles.deleteContents();
}
void MComponent::writeTargetCD( ContFile& mak )
{
WFileName path;
_filename.path( path, FALSE );
if( path.match( NULL, matchDir ) ) {
path.concat( "\\" );
}
mak.printf( " @%s\n", path.drive() );
mak.printf( " cd %s\n", (const char*)path );
}
void MComponent::writeRule( ContFile& mak )
{
if( !_target->ismakeable() ) return;
WFileName tgt;
_target->absName( tgt );
for( int i=0; i<_workFiles.count(); i++ ) {
MWorkFile* w = (MWorkFile*)_workFiles[i];
MItem* m = w->item();
if( !m->isMask() && m->ismakeable() ) {
WFileName r;
m->absResult( r );
if( r.needQuotes() ) {
r.addQuotes();
}
if( w->needQuotes() ) {
w->addQuotes();
}
mak.printf( "%s : %s", (const char*)r, (const char*)*w );
r.removeQuotes();
w->removeQuotes();
if( _autodepend ) mak.puts( " .AUTODEPEND" );
mak.puts( "\n" );
WString c;
w->makeCommand( c, NULL );
writeTargetCD( mak );
mak.puts( c );
mak.puts( "\n" );
w->puts( r ); //setup for later use by target-maker
}
}
if( tgt.needQuotes() ) {
tgt.addQuotes();
}
mak.printf( "%s :", (const char*)tgt );
tgt.removeQuotes();
int jcount = _workFiles.count();
for( int j=0; j<jcount; j++ ) {
MWorkFile* w = (MWorkFile*)_workFiles[j];
if( !w->isMask() ) {
if( w->needQuotes() ) {
w->addQuotes();
}
mak.printf( " %s", (const char*)*w );
w->removeQuotes();
w->relativeTo( _filename );
}
}
if( _autodepend ) mak.puts( " .AUTODEPEND" );
mak.puts( "\n" );
bool browseable = writeCBR();
if( _target->ismakeable() ) {
WFileName fn; _target->absName( fn );
MWorkFile w( fn, _mode, _target, this );
WString c;
if( browseable && _config->browseMerge().size() > 0 ) {
MCommand cmd;
cmd.concatf( " %s @$*.cbr", (const char*)_config->browseMerge() );
expand( c, cmd );
}
expand( c, _before );
w.makeCommand( c, &_workFiles );
expand( c, _after );
writeTargetCD( mak );
mak.puts( c );
mak.puts( "\n" );
}
}
void MComponent::setBefore( const MCommand& before )
{
_before = before;
setDirty();
}
void MComponent::setAfter( const MCommand& after )
{
_after = after;
setDirty();
}
void MComponent::expand( WString& c, const MCommand& cmd )
{
if( cmd.size() > 0 ) {
cmd.expand( c, _target, _config->nilTool(), _mask, NULL, _mode );
c.concat( "\n" );
_project->insertBlanks( c );
}
}
bool MComponent::writeCBR( bool mustExist )
{
bool found_a_mbr = FALSE;
if( mustExist ) found_a_mbr = TRUE;
for( int i=0; i<_workFiles.count(); i++ ) {
MWorkFile* w = (MWorkFile*)_workFiles[i];
if( w->browseable() ) {
WFileName browfile( _filename );
browfile.setExt( ".cbr" );
WFile brow;
if( brow.open( browfile, OStyleWrite ) ) {
WFileName tfile;
_target->absResult( tfile );
tfile.setExt( "dbr" );
brow.printf( "d %s\n", (const char*)tfile );
for( ; i<_workFiles.count(); i++ ) {
MWorkFile* w = (MWorkFile*)_workFiles[i];
if( w->browseable() ) {
w->item()->absResult( tfile );
tfile.setExt( "mbr" );
if( mustExist ) {
if( access( (const char*)tfile, F_OK ) == 0 ) {
// file must be there
brow.printf( "f %s\n", (const char*)tfile );
found_a_mbr = TRUE;
}
} else {
brow.printf( "f %s\n", (const char*)tfile );
}
}
}
brow.close();
}
if( found_a_mbr ) return( TRUE );
}
}
return FALSE;
}
void MComponent::resetRuleRefs()
{
_target->resetRuleRefs();
for( int i=0; i<_items.count(); i++ ) {
MItem* m = (MItem*)_items[i];
m->resetRuleRefs();
}
}
void MComponent::setDirty( bool dirty )
{
_dirty = dirty;
if( _dirty ) {
setNeedsMake();
_project->setDirty();
}
}
void MComponent::setNeedsMake( bool needsMake )
{
_needsMake = needsMake;
if( _needsMake ) {
_project->setNeedsMake();
}
}
void MComponent::makeNames( const char* spec, WFileName& filename, WFileName& relname, WFileName& targ )
{
relname = spec;
relname.noPath( targ );
relname.setExt( ".tgt" );
filename = relname;
filename.absoluteTo( _project->filename() );
}
bool MComponent::tryBrowse()
{
bool rc = FALSE;
initWorkFiles( _workFiles );
for( int i=0; i<_workFiles.count(); i++ ) {
MItem* m = ((MWorkFile*)_workFiles[i])->item();
WFileName fn = m->component()->relFilename(); // target file name
fn.setFName( m->fName() );
fn.setExt( ".mbr" );
if( access( (const char *)fn, F_OK ) == 0 ) {
rc = TRUE;
break;
}
}
finiWorkFiles();
return( rc );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?