replace gotos with do/while logic where appropriate
This commit is contained in:
+5
-6
@@ -751,12 +751,11 @@ void RageSemaphore::Post()
|
||||
|
||||
void RageSemaphore::Wait( bool bFailOnTimeout )
|
||||
{
|
||||
retry:
|
||||
if( m_pSema->Wait() )
|
||||
return;
|
||||
|
||||
if( !bFailOnTimeout || RageThread::GetIsShowingDialog() )
|
||||
goto retry;
|
||||
do
|
||||
{
|
||||
if( m_pSema->Wait() )
|
||||
return;
|
||||
} while( !bFailOnTimeout || RageThread::GetIsShowingDialog() );
|
||||
|
||||
/* We waited too long. We're probably deadlocked, though unlike mutexes, we can't
|
||||
* tell which thread we're stuck on. */
|
||||
|
||||
+11
-12
@@ -390,20 +390,19 @@ bool ScreenSelectMaster::Move( PlayerNumber pn, MenuDir dir )
|
||||
|
||||
int iSwitchToIndex = m_iChoice[pn];
|
||||
set<int> seen;
|
||||
try_again:
|
||||
|
||||
map<int,int>::const_iterator iter = m_mapCurrentChoiceToNextChoice[dir].find( iSwitchToIndex );
|
||||
if( iter != m_mapCurrentChoiceToNextChoice[dir].end() )
|
||||
iSwitchToIndex = iter->second;
|
||||
do
|
||||
{
|
||||
map<int,int>::const_iterator iter = m_mapCurrentChoiceToNextChoice[dir].find( iSwitchToIndex );
|
||||
if( iter != m_mapCurrentChoiceToNextChoice[dir].end() )
|
||||
iSwitchToIndex = iter->second;
|
||||
|
||||
if( iSwitchToIndex < 0 || iSwitchToIndex >= (int) m_aGameCommands.size() ) // out of choice range
|
||||
return false; // can't go that way
|
||||
if( seen.find(iSwitchToIndex) != seen.end() )
|
||||
return false; // went full circle and none found
|
||||
seen.insert( iSwitchToIndex );
|
||||
|
||||
if( !m_aGameCommands[iSwitchToIndex].IsPlayable() && !DO_SWITCH_ANYWAYS )
|
||||
goto try_again;
|
||||
if( iSwitchToIndex < 0 || iSwitchToIndex >= (int) m_aGameCommands.size() ) // out of choice range
|
||||
return false; // can't go that way
|
||||
if( seen.find(iSwitchToIndex) != seen.end() )
|
||||
return false; // went full circle and none found
|
||||
seen.insert( iSwitchToIndex );
|
||||
} while( !m_aGameCommands[iSwitchToIndex].IsPlayable() && !DO_SWITCH_ANYWAYS );
|
||||
|
||||
return ChangeSelection( pn, dir, iSwitchToIndex );
|
||||
}
|
||||
|
||||
@@ -332,58 +332,58 @@ void CSMPackageInstallDlg::OnOK()
|
||||
ProgressInit = 1;
|
||||
}
|
||||
|
||||
retry_unzip:
|
||||
|
||||
// Extract the files
|
||||
const RString sFile = vs[i];
|
||||
LOG->Trace( "Extracting: "+sFile );
|
||||
|
||||
RString sError;
|
||||
Dialog::Result result;
|
||||
do
|
||||
{
|
||||
int iErr;
|
||||
RageFileBasic *pFileFrom = zip.Open( sFile, RageFile::READ, iErr );
|
||||
if( pFileFrom == NULL )
|
||||
// Extract the files
|
||||
const RString sFile = vs[i];
|
||||
LOG->Trace( "Extracting: "+sFile );
|
||||
|
||||
RString sError;
|
||||
{
|
||||
sError = ssprintf( ERROR_OPENING_SOURCE_FILE.GetValue(), sFile.c_str(), ssprintf("%d",iErr).c_str() );
|
||||
goto show_error;
|
||||
int iErr;
|
||||
RageFileBasic *pFileFrom = zip.Open( sFile, RageFile::READ, iErr );
|
||||
if( pFileFrom == NULL )
|
||||
{
|
||||
sError = ssprintf( ERROR_OPENING_SOURCE_FILE.GetValue(), sFile.c_str(), ssprintf("%d",iErr).c_str() );
|
||||
goto show_error;
|
||||
}
|
||||
|
||||
int iError;
|
||||
RageFileBasic *pFileTo = dir.Open( sFile, RageFile::WRITE, iError );
|
||||
if( pFileTo == NULL )
|
||||
{
|
||||
sError = ssprintf( ERROR_OPENING_DESTINATION_FILE.GetValue(), sFile.c_str(), pFileTo->GetError().c_str() );
|
||||
goto show_error;
|
||||
}
|
||||
|
||||
RString sErr;
|
||||
if( !FileCopy(*pFileFrom, *pFileTo, sErr) )
|
||||
{
|
||||
sError = ssprintf( ERROR_COPYING_FILE.GetValue(), sFile.c_str(), sErr.c_str() );
|
||||
goto show_error;
|
||||
}
|
||||
|
||||
SAFE_DELETE( pFileFrom );
|
||||
SAFE_DELETE( pFileTo );
|
||||
}
|
||||
|
||||
int iError;
|
||||
RageFileBasic *pFileTo = dir.Open( sFile, RageFile::WRITE, iError );
|
||||
if( pFileTo == NULL )
|
||||
{
|
||||
sError = ssprintf( ERROR_OPENING_DESTINATION_FILE.GetValue(), sFile.c_str(), pFileTo->GetError().c_str() );
|
||||
goto show_error;
|
||||
}
|
||||
|
||||
RString sErr;
|
||||
if( !FileCopy(*pFileFrom, *pFileTo, sErr) )
|
||||
{
|
||||
sError = ssprintf( ERROR_COPYING_FILE.GetValue(), sFile.c_str(), sErr.c_str() );
|
||||
goto show_error;
|
||||
}
|
||||
|
||||
SAFE_DELETE( pFileFrom );
|
||||
SAFE_DELETE( pFileTo );
|
||||
}
|
||||
|
||||
goto done_with_file;
|
||||
break;
|
||||
|
||||
show_error:
|
||||
switch( Dialog::AbortRetryIgnore(sError) )
|
||||
{
|
||||
case Dialog::abort:
|
||||
exit(1); // better way to exit?
|
||||
break;
|
||||
case Dialog::retry:
|
||||
goto retry_unzip;
|
||||
break;
|
||||
case Dialog::ignore:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
done_with_file:
|
||||
Dialog::Result result = Dialog::AbortRetryIgnore(sError);
|
||||
switch( result )
|
||||
{
|
||||
case Dialog::abort:
|
||||
exit(1); // better way to exit?
|
||||
break;
|
||||
case Dialog::retry:
|
||||
break;
|
||||
case Dialog::ignore:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
} while( result == Dialog::retry );
|
||||
|
||||
pProgress1->StepIt(); //increase the progress bar of 1 step
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user