src/console.cpp
branchnoai
changeset 10455 22c441f5adf9
parent 9724 b39bc69bb2f2
child 10513 33cb70ff2f5d
--- a/src/console.cpp	Mon May 05 12:35:38 2008 +0000
+++ b/src/console.cpp	Wed May 07 21:09:51 2008 +0000
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-/** @file console.cpp */
+/** @file console.cpp Handling of the in-game console. */
 
 #include "stdafx.h"
 #include "openttd.h"
@@ -18,6 +18,7 @@
 #include "window_func.h"
 #include "string_func.h"
 #include "gfx_func.h"
+#include "rev.h"
 
 #include "table/strings.h"
 
@@ -106,8 +107,7 @@
 			break;
 		}
 		case WE_MOUSELOOP:
-			if (HandleCaret(&_iconsole_cmdline))
-				SetWindowDirty(w);
+			if (HandleCaret(&_iconsole_cmdline)) w->SetDirty();
 			break;
 		case WE_DESTROY:
 			_iconsole_mode = ICONSOLE_CLOSED;
@@ -117,11 +117,11 @@
 			switch (e->we.keypress.keycode) {
 				case WKC_UP:
 					IConsoleHistoryNavigate(+1);
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_DOWN:
 					IConsoleHistoryNavigate(-1);
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_SHIFT | WKC_PAGEUP:
 					if (iconsole_scroll - (w->height / ICON_LINE_HEIGHT) - 1 < 0) {
@@ -129,7 +129,7 @@
 					} else {
 						iconsole_scroll -= (w->height / ICON_LINE_HEIGHT) - 1;
 					}
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_SHIFT | WKC_PAGEDOWN:
 					if (iconsole_scroll + (w->height / ICON_LINE_HEIGHT) - 1 > ICON_BUFFER) {
@@ -137,7 +137,7 @@
 					} else {
 						iconsole_scroll += (w->height / ICON_LINE_HEIGHT) - 1;
 					}
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_SHIFT | WKC_UP:
 					if (iconsole_scroll <= 0) {
@@ -145,7 +145,7 @@
 					} else {
 						--iconsole_scroll;
 					}
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_SHIFT | WKC_DOWN:
 					if (iconsole_scroll >= ICON_BUFFER) {
@@ -153,7 +153,7 @@
 					} else {
 						++iconsole_scroll;
 					}
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_BACKQUOTE:
 					IConsoleSwitch();
@@ -173,7 +173,7 @@
 				case (WKC_CTRL | 'V'):
 					if (InsertTextBufferClipboard(&_iconsole_cmdline)) {
 						IConsoleResetHistoryPos();
-						SetWindowDirty(w);
+						w->SetDirty();
 					}
 					break;
 				case (WKC_CTRL | 'L'):
@@ -181,18 +181,18 @@
 					break;
 				case (WKC_CTRL | 'U'):
 					DeleteTextBufferAll(&_iconsole_cmdline);
-					SetWindowDirty(w);
+					w->SetDirty();
 					break;
 				case WKC_BACKSPACE: case WKC_DELETE:
 					if (DeleteTextBufferChar(&_iconsole_cmdline, e->we.keypress.keycode)) {
 						IConsoleResetHistoryPos();
-						SetWindowDirty(w);
+						w->SetDirty();
 					}
 					break;
 				case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
 					if (MoveTextBufferPos(&_iconsole_cmdline, e->we.keypress.keycode)) {
 						IConsoleResetHistoryPos();
-						SetWindowDirty(w);
+						w->SetDirty();
 					}
 					break;
 				default:
@@ -200,7 +200,7 @@
 						iconsole_scroll = ICON_BUFFER;
 						InsertTextBufferChar(&_iconsole_cmdline, e->we.keypress.key);
 						IConsoleResetHistoryPos();
-						SetWindowDirty(w);
+						w->SetDirty();
 					} else {
 						e->we.keypress.cont = true;
 					}
@@ -223,7 +223,6 @@
 
 void IConsoleInit()
 {
-	extern const char _openttd_revision[];
 	_iconsole_output_file = NULL;
 	_icolour_def  =  1;
 	_icolour_err  =  3;
@@ -271,8 +270,12 @@
 {
 	if (_iconsole_output_file != NULL) {
 		/* if there is an console output file ... also print it there */
-		fwrite(string, strlen(string), 1, _iconsole_output_file);
-		fwrite("\n", 1, 1, _iconsole_output_file);
+		if (fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 ||
+				fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
+			fclose(_iconsole_output_file);
+			_iconsole_output_file = NULL;
+			IConsolePrintF(_icolour_def, "cannot write to log file");
+		}
 	}
 }