(svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
authorDarkvater
Fri, 23 Feb 2007 12:56:10 +0000
changeset 6450 1c2016673250
parent 6449 e520244dc71e
child 6451 7baba06b4b85
(svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
src/fios.cpp
src/music/bemidi.h
src/music/dmusic.cpp
src/music/extmidi.h
src/music/null_m.cpp
src/music/os2_m.h
src/music/qtmidi.h
src/music/win32_m.cpp
src/music_gui.cpp
src/newgrf_sound.cpp
src/sound/cocoa_s.h
src/sound/sdl_s.cpp
src/sound/win32_s.h
src/video/cocoa_v.h
src/win32.cpp
--- a/src/fios.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/fios.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -186,9 +186,7 @@
 {
 #if defined(WINCE)
 	/* There is always one platform that doesn't support basic commands... */
-	HANDLE hand;
-
-	hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
+	HANDLE hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
 	if (hand == INVALID_HANDLE_VALUE) return 1;
 	CloseHandle(hand);
 	return 0;
--- a/src/music/bemidi.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/bemidi.h	Fri Feb 23 12:56:10 2007 +0000
@@ -7,4 +7,4 @@
 
 extern const HalMusicDriver _bemidi_music_driver;
 
-#endif
+#endif /* MUSIC_BEMIDI_H */
--- a/src/music/dmusic.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/dmusic.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -1,9 +1,8 @@
 /* $Id$ */
 
-#include "../stdafx.h"
-
 #ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
 
+#include "../stdafx.h"
 #include "../debug.h"
 #include "../win32.h"
 #include "dmusic.h"
--- a/src/music/extmidi.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/extmidi.h	Fri Feb 23 12:56:10 2007 +0000
@@ -7,4 +7,4 @@
 
 extern const HalMusicDriver _extmidi_music_driver;
 
-#endif
+#endif /* MUSIC_EXTERNAL_H */
--- a/src/music/null_m.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/null_m.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -1,7 +1,6 @@
 /* $Id$ */
 
 #include "../stdafx.h"
-#include "../openttd.h"
 #include "null_m.h"
 
 static const char* NullMidiStart(const char* const* parm) { return NULL; }
--- a/src/music/os2_m.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/os2_m.h	Fri Feb 23 12:56:10 2007 +0000
@@ -7,4 +7,4 @@
 
 extern const HalMusicDriver _os2_music_driver;
 
-#endif
+#endif /* MUSIC_OS2_H */
--- a/src/music/qtmidi.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/qtmidi.h	Fri Feb 23 12:56:10 2007 +0000
@@ -7,4 +7,4 @@
 
 extern const HalMusicDriver _qtime_music_driver;
 
-#endif /* !MUSIC_MACOSX_QUICKTIME_H */
+#endif /* MUSIC_MACOSX_QUICKTIME_H */
--- a/src/music/win32_m.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music/win32_m.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -1,7 +1,6 @@
 /* $Id$ */
 
 #include "../stdafx.h"
-#include "../openttd.h"
 #include "win32_m.h"
 #include <windows.h>
 #include <mmsystem.h>
@@ -50,7 +49,7 @@
 	char buf[512];
 
 	va_start(va, cmd);
-	vsprintf(buf, cmd, va);
+	vsnprintf(buf, lengthof(buf), cmd, va);
 	va_end(va);
 	return mciSendStringA(buf, NULL, 0, 0);
 }
@@ -58,12 +57,9 @@
 static bool MidiIntPlaySong(const char *filename)
 {
 	MidiSendCommand("close all");
-	if (MidiSendCommand("open \"%s\" type sequencer alias song", filename) != 0)
-		return false;
+	if (MidiSendCommand("open \"%s\" type sequencer alias song", filename) != 0) return false;
 
-	if (MidiSendCommand("play song from 0") != 0)
-		return false;
-	return true;
+	return MidiSendCommand("play song from 0") == 0;
 }
 
 static void MidiIntStopSong(void)
@@ -104,9 +100,7 @@
 			s[0] = '\0';
 
 			// Delay somewhat in case we don't manage to play.
-			if (!_midi.playing) {
-				Sleep(5000);
-			}
+			if (!_midi.playing) Sleep(5000);
 		}
 
 		if (_midi.stop_song && _midi.playing) {
@@ -115,8 +109,7 @@
 			MidiIntStopSong();
 		}
 
-		if (_midi.playing && !MidiIntIsSongPlaying())
-			_midi.playing = false;
+		if (_midi.playing && !MidiIntIsSongPlaying()) _midi.playing = false;
 
 		WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 1000);
 	} while (!_midi.terminate);
@@ -148,8 +141,7 @@
 		}
 	}
 
-	if (CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId) == NULL)
-		return "Failed to create thread";
+	if (CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId) == NULL) return "Failed to create thread";
 
 	return NULL;
 }
--- a/src/music_gui.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/music_gui.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -422,12 +422,11 @@
 		case 5: // start playing
 			msf.playing = true;
 			break;
-		case 6:{ // volume sliders
-			byte *vol,new_vol;
+		case 6: { // volume sliders
+			byte *vol, new_vol;
 			int x = e->we.click.pt.x - 88;
 
-			if (x < 0)
-				return;
+			if (x < 0) return;
 
 			vol = &msf.music_vol;
 			if (x >= 106) {
@@ -435,7 +434,7 @@
 				x -= 106;
 			}
 
-			new_vol = min(max(x-21,0)*2,127);
+			new_vol = min(max(x - 21, 0) * 2, 127);
 			if (new_vol != *vol) {
 				*vol = new_vol;
 				if (vol == &msf.music_vol)
--- a/src/newgrf_sound.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/newgrf_sound.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -37,7 +37,7 @@
 
 FileEntry *GetSound(uint index)
 {
-	if (index >= _sound_count) return NULL;
+	if (index >= GetNumSounds()) return NULL;
 	return GetSoundInternal(index);
 }
 
--- a/src/sound/cocoa_s.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/sound/cocoa_s.h	Fri Feb 23 12:56:10 2007 +0000
@@ -7,4 +7,4 @@
 
 extern const HalSoundDriver _cocoa_sound_driver;
 
-#endif
+#endif /* SOUND_COCOA_H */
--- a/src/sound/sdl_s.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/sound/sdl_s.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -1,10 +1,9 @@
 /* $Id$ */
 
+#ifdef WITH_SDL
+
 #include "../stdafx.h"
 
-#ifdef WITH_SDL
-
-#include "../openttd.h"
 #include "../driver.h"
 #include "../mixer.h"
 #include "../sdl.h"
--- a/src/sound/win32_s.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/sound/win32_s.h	Fri Feb 23 12:56:10 2007 +0000
@@ -7,4 +7,4 @@
 
 extern const HalSoundDriver _win32_sound_driver;
 
-#endif
+#endif /* SOUND_WIN32_H */
--- a/src/video/cocoa_v.h	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/video/cocoa_v.h	Fri Feb 23 12:56:10 2007 +0000
@@ -10,4 +10,4 @@
 
 extern const HalVideoDriver _cocoa_video_driver;
 
-#endif
+#endif /* VIDEO_COCOA_H */
--- a/src/win32.cpp	Fri Feb 23 11:50:43 2007 +0000
+++ b/src/win32.cpp	Fri Feb 23 12:56:10 2007 +0000
@@ -868,12 +868,12 @@
 	int _set_error_mode(int);
 #endif
 
-#if defined(WINCE)
-int APIENTRY WinMain
-#else
-int APIENTRY _tWinMain
-#endif
-        (HINSTANCE hInstance, HINSTANCE hPrevInstance,
+#if defined(WINCE) && !defined(_tWinMain)
+/* GCC crosscompiler for WINCE doesn't support wide version */
+# define _tWinMain WinMain
+#endif /* WINCE */
+
+int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 	LPTSTR lpCmdLine, int nCmdShow)
 {
 	int argc;
@@ -922,12 +922,11 @@
 #if defined(WINCE)
 void GetCurrentDirectoryW(int length, wchar_t *path)
 {
-	wchar_t *pDest = NULL;
 	/* Get the name of this module */
 	GetModuleFileName(NULL, path, length);
 
 	/* Remove the executable name, this we call CurrentDir */
-	pDest = wcsrchr(path, '\\');
+	wchar_t *pDest = wcsrchr(path, '\\');
 	if (pDest != NULL) {
 		int result = pDest - path + 1;
 		path[result] = '\0';