replace gotos with do/while logic where appropriate

This commit is contained in:
Devin J. Pohly
2013-01-25 17:56:33 -05:00
parent 001ee51242
commit 9237741149
3 changed files with 63 additions and 65 deletions
+3 -4
View File
@@ -751,12 +751,11 @@ void RageSemaphore::Post()
void RageSemaphore::Wait( bool bFailOnTimeout ) void RageSemaphore::Wait( bool bFailOnTimeout )
{ {
retry: do
{
if( m_pSema->Wait() ) if( m_pSema->Wait() )
return; return;
} while( !bFailOnTimeout || RageThread::GetIsShowingDialog() );
if( !bFailOnTimeout || RageThread::GetIsShowingDialog() )
goto retry;
/* We waited too long. We're probably deadlocked, though unlike mutexes, we can't /* We waited too long. We're probably deadlocked, though unlike mutexes, we can't
* tell which thread we're stuck on. */ * tell which thread we're stuck on. */
+3 -4
View File
@@ -390,8 +390,9 @@ bool ScreenSelectMaster::Move( PlayerNumber pn, MenuDir dir )
int iSwitchToIndex = m_iChoice[pn]; int iSwitchToIndex = m_iChoice[pn];
set<int> seen; set<int> seen;
try_again:
do
{
map<int,int>::const_iterator iter = m_mapCurrentChoiceToNextChoice[dir].find( iSwitchToIndex ); map<int,int>::const_iterator iter = m_mapCurrentChoiceToNextChoice[dir].find( iSwitchToIndex );
if( iter != m_mapCurrentChoiceToNextChoice[dir].end() ) if( iter != m_mapCurrentChoiceToNextChoice[dir].end() )
iSwitchToIndex = iter->second; iSwitchToIndex = iter->second;
@@ -401,9 +402,7 @@ try_again:
if( seen.find(iSwitchToIndex) != seen.end() ) if( seen.find(iSwitchToIndex) != seen.end() )
return false; // went full circle and none found return false; // went full circle and none found
seen.insert( iSwitchToIndex ); seen.insert( iSwitchToIndex );
} while( !m_aGameCommands[iSwitchToIndex].IsPlayable() && !DO_SWITCH_ANYWAYS );
if( !m_aGameCommands[iSwitchToIndex].IsPlayable() && !DO_SWITCH_ANYWAYS )
goto try_again;
return ChangeSelection( pn, dir, iSwitchToIndex ); return ChangeSelection( pn, dir, iSwitchToIndex );
} }
+7 -7
View File
@@ -332,8 +332,9 @@ void CSMPackageInstallDlg::OnOK()
ProgressInit = 1; ProgressInit = 1;
} }
retry_unzip: Dialog::Result result;
do
{
// Extract the files // Extract the files
const RString sFile = vs[i]; const RString sFile = vs[i];
LOG->Trace( "Extracting: "+sFile ); LOG->Trace( "Extracting: "+sFile );
@@ -367,23 +368,22 @@ retry_unzip:
SAFE_DELETE( pFileTo ); SAFE_DELETE( pFileTo );
} }
goto done_with_file; break;
show_error: show_error:
switch( Dialog::AbortRetryIgnore(sError) ) Dialog::Result result = Dialog::AbortRetryIgnore(sError);
switch( result )
{ {
case Dialog::abort: case Dialog::abort:
exit(1); // better way to exit? exit(1); // better way to exit?
break; break;
case Dialog::retry: case Dialog::retry:
goto retry_unzip;
break; break;
case Dialog::ignore: case Dialog::ignore:
// do nothing // do nothing
break; break;
} }
} while( result == Dialog::retry );
done_with_file:
pProgress1->StepIt(); //increase the progress bar of 1 step pProgress1->StepIt(); //increase the progress bar of 1 step
} }