summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-03 11:12:39 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:14:44 +0000
commit593953c7deabb08cc77c22c08f5c8859bafbcb79 (patch)
tree8a22c17d66e749656a5665e1379d29ca715e219e /src/sys
parent3ffe4805cfebd93a60bf59b582303540b2ec0d80 (diff)
* Merge ioq3-r1233
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/con_tty.c26
-rw-r--r--src/sys/con_win32.c29
-rw-r--r--src/sys/sys_local.h17
-rw-r--r--src/sys/sys_main.c83
-rw-r--r--src/sys/sys_unix.c38
-rw-r--r--src/sys/sys_win32.c40
6 files changed, 139 insertions, 94 deletions
diff --git a/src/sys/con_tty.c b/src/sys/con_tty.c
index f128b0d7..687d1dd4 100644
--- a/src/sys/con_tty.c
+++ b/src/sys/con_tty.c
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"
+#include "sys_local.h"
#include <unistd.h>
#include <signal.h>
@@ -102,7 +103,7 @@ Clear the display of the line currently edited
bring cursor back to beginning of line
==================
*/
-void CON_Hide( void )
+static void CON_Hide( void )
{
if( ttycon_on )
{
@@ -132,7 +133,7 @@ Show the current line
FIXME need to position the cursor if needed?
==================
*/
-void CON_Show( void )
+static void CON_Show( void )
{
if( ttycon_on )
{
@@ -297,10 +298,10 @@ void CON_Init( void )
/*
==================
-CON_ConsoleInput
+CON_Input
==================
*/
-char *CON_ConsoleInput( void )
+char *CON_Input( void )
{
// we use this when sending back commands
static char text[256];
@@ -440,3 +441,20 @@ char *CON_ConsoleInput( void )
return text;
}
}
+
+/*
+==================
+CON_Print
+==================
+*/
+void CON_Print( const char *msg )
+{
+ CON_Hide( );
+
+ if( com_ansiColor && com_ansiColor->integer )
+ Sys_AnsiColorPrint( msg );
+ else
+ fputs( msg, stderr );
+
+ CON_Show( );
+}
diff --git a/src/sys/con_win32.c b/src/sys/con_win32.c
index 71549b7d..a27c9cca 100644
--- a/src/sys/con_win32.c
+++ b/src/sys/con_win32.c
@@ -132,19 +132,10 @@ static void CON_HistNext( void )
/*
==================
-CON_Hide
-==================
-*/
-void CON_Hide( void )
-{
-}
-
-/*
-==================
CON_Show
==================
*/
-void CON_Show( void )
+static void CON_Show( void )
{
CONSOLE_SCREEN_BUFFER_INFO binfo;
COORD writeSize = { MAX_EDIT_LINE, 1 };
@@ -155,7 +146,7 @@ void CON_Show( void )
GetConsoleScreenBufferInfo( qconsole_hout, &binfo );
- // if we' re in the middle of printf, don't bother writing the buffer
+ // if we're in the middle of printf, don't bother writing the buffer
if( binfo.dwCursorPosition.X != 0 )
return;
@@ -249,10 +240,10 @@ void CON_Init( void )
/*
==================
-CON_ConsoleInput
+CON_Input
==================
*/
-char *CON_ConsoleInput( void )
+char *CON_Input( void )
{
INPUT_RECORD buff[ MAX_EDIT_LINE ];
DWORD count = 0, events = 0;
@@ -353,3 +344,15 @@ char *CON_ConsoleInput( void )
return qconsole_line;
}
+
+/*
+==================
+CON_Print
+==================
+*/
+void CON_Print( const char *msg )
+{
+ fputs( msg, stderr );
+
+ CON_Show( );
+}
diff --git a/src/sys/sys_local.h b/src/sys/sys_local.h
index 60c7e63a..40336e3a 100644
--- a/src/sys/sys_local.h
+++ b/src/sys/sys_local.h
@@ -29,19 +29,24 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MINSDL_PATCH 7
// Input subsystem
-void IN_Init (void);
-void IN_Frame (void);
-void IN_Shutdown (void);
+void IN_Init( void );
+void IN_Frame( void );
+void IN_Shutdown( void );
// Console
-void CON_Hide( void );
-void CON_Show( void );
void CON_Shutdown( void );
void CON_Init( void );
-char *CON_ConsoleInput(void);
+char *CON_Input( void );
+void CON_Print( const char *message );
+
+unsigned int CON_LogSize( void );
+unsigned int CON_LogWrite( const char *in );
+unsigned int CON_LogRead( char *out, unsigned int outSize );
#ifdef MACOS_X
char *Sys_StripAppBundle( char *pwd );
#endif
void Sys_SigHandler( int signal );
+void Sys_ErrorDialog( const char *error );
+void Sys_AnsiColorPrint( const char *msg );
diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c
index 512c43b8..284a1194 100644
--- a/src/sys/sys_main.c
+++ b/src/sys/sys_main.c
@@ -108,34 +108,6 @@ void Sys_In_Restart_f( void )
/*
=================
-Sys_ConsoleInputInit
-
-Start the console input subsystem
-=================
-*/
-void Sys_ConsoleInputInit( void )
-{
-#ifdef DEDICATED
- CON_Init( );
-#endif
-}
-
-/*
-=================
-Sys_ConsoleInputShutdown
-
-Shutdown the console input subsystem
-=================
-*/
-void Sys_ConsoleInputShutdown( void )
-{
-#ifdef DEDICATED
- CON_Shutdown( );
-#endif
-}
-
-/*
-=================
Sys_ConsoleInput
Handle new console input
@@ -143,11 +115,7 @@ Handle new console input
*/
char *Sys_ConsoleInput(void)
{
-#ifdef DEDICATED
- return CON_ConsoleInput( );
-#endif
-
- return NULL;
+ return CON_Input( );
}
/*
@@ -159,18 +127,18 @@ Single exit point (regular exit or in case of error)
*/
void Sys_Exit( int ex )
{
- Sys_ConsoleInputShutdown();
+ CON_Shutdown( );
#ifndef DEDICATED
SDL_Quit( );
#endif
#ifdef NDEBUG
- exit(ex);
+ exit( ex );
#else
// Cause a backtrace on error exits
assert( ex == 0 );
- exit(ex);
+ exit( ex );
#endif
}
@@ -179,10 +147,10 @@ void Sys_Exit( int ex )
Sys_Quit
=================
*/
-void Sys_Quit (void)
+void Sys_Quit( void )
{
- CL_Shutdown ();
- Sys_Exit(0);
+ CL_Shutdown( );
+ Sys_Exit( 0 );
}
/*
@@ -227,7 +195,7 @@ Sys_AnsiColorPrint
Transform Q3 colour codes to ANSI escape sequences
=================
*/
-static void Sys_AnsiColorPrint( const char *msg )
+void Sys_AnsiColorPrint( const char *msg )
{
static char buffer[ MAXPRINTMSG ];
int length = 0;
@@ -296,18 +264,8 @@ Sys_Print
*/
void Sys_Print( const char *msg )
{
-#ifdef DEDICATED
- CON_Hide();
-#endif
-
- if( com_ansiColor && com_ansiColor->integer )
- Sys_AnsiColorPrint( msg );
- else
- fputs(msg, stderr);
-
-#ifdef DEDICATED
- CON_Show();
-#endif
+ CON_LogWrite( msg );
+ CON_Print( msg );
}
/*
@@ -320,16 +278,13 @@ void Sys_Error( const char *error, ... )
va_list argptr;
char string[1024];
-#ifdef DEDICATED
- CON_Hide();
-#endif
-
CL_Shutdown ();
va_start (argptr,error);
Q_vsnprintf (string, sizeof(string), error, argptr);
va_end (argptr);
- fprintf(stderr, "Sys_Error: %s\n", string);
+
+ Sys_ErrorDialog( string );
Sys_Exit( 1 );
}
@@ -348,15 +303,7 @@ void Sys_Warn( char *warning, ... )
Q_vsnprintf (string, sizeof(string), warning, argptr);
va_end (argptr);
-#ifdef DEDICATED
- CON_Hide();
-#endif
-
- fprintf(stderr, "Warning: %s", string);
-
-#ifdef DEDICATED
- CON_Show();
-#endif
+ CON_Print( va( "Warning: %s", string ) );
}
/*
@@ -624,9 +571,9 @@ int main( int argc, char **argv )
}
Com_Init( commandLine );
- NET_Init();
+ NET_Init( );
- Sys_ConsoleInputInit();
+ CON_Init( );
#ifndef _WIN32
// Windows doesn't have these signals
diff --git a/src/sys/sys_unix.c b/src/sys/sys_unix.c
index 230d8c44..090e9e43 100644
--- a/src/sys/sys_unix.c
+++ b/src/sys/sys_unix.c
@@ -19,6 +19,11 @@ along with Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
+
+#include "../qcommon/q_shared.h"
+#include "../qcommon/qcommon.h"
+#include "sys_local.h"
+
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@@ -30,9 +35,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <pwd.h>
#include <libgen.h>
-#include "../qcommon/q_shared.h"
-#include "../qcommon/qcommon.h"
-
// Used to determine where to store user-specific files
static char homePath[ MAX_OSPATH ] = { 0 };
@@ -476,3 +478,33 @@ void Sys_Sleep( int msec )
select((fileno(stdin) + 1), &fdset, NULL, NULL, &timeout);
}
}
+
+/*
+==============
+Sys_ErrorDialog
+
+Display an error message
+==============
+*/
+void Sys_ErrorDialog( const char *error )
+{
+ char buffer[ 1024 ];
+ unsigned int size;
+ fileHandle_t f;
+ const char *fileName = "crashlog.txt";
+
+ Sys_Print( va( "%s\n", error ) );
+
+ // Write console log to file
+ f = FS_FOpenFileWrite( fileName );
+ if( !f )
+ {
+ Com_Printf( "ERROR: couldn't open %s\n", fileName );
+ return;
+ }
+
+ while( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 )
+ FS_Write( buffer, size, f );
+
+ FS_FCloseFile( f );
+}
diff --git a/src/sys/sys_win32.c b/src/sys/sys_win32.c
index 36d81a77..df8861d3 100644
--- a/src/sys/sys_win32.c
+++ b/src/sys/sys_win32.c
@@ -525,3 +525,43 @@ void Sys_Sleep( int msec )
WaitForSingleObject( GetStdHandle( STD_INPUT_HANDLE ), msec );
}
+/*
+==============
+Sys_ErrorDialog
+
+Display an error message
+==============
+*/
+void Sys_ErrorDialog( const char *error )
+{
+ if( MessageBox( NULL, va( "%s. Copy console log to clipboard?", error ),
+ NULL, MB_YESNO|MB_ICONERROR ) == IDYES )
+ {
+ HGLOBAL memoryHandle;
+ char *clipMemory;
+
+ memoryHandle = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, CON_LogSize( ) + 1 );
+ clipMemory = (char *)GlobalLock( memoryHandle );
+
+ if( clipMemory )
+ {
+ char *p = clipMemory;
+ char buffer[ 1024 ];
+ unsigned int size;
+
+ while( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 )
+ {
+ Com_Memcpy( p, buffer, size );
+ p += size;
+ }
+
+ *p = '\0';
+
+ if( OpenClipboard( NULL ) && EmptyClipboard( ) )
+ SetClipboardData( CF_TEXT, memoryHandle );
+
+ GlobalUnlock( clipMemory );
+ CloseClipboard( );
+ }
+ }
+}