-//==============================================
-
-void AddSlash(CString& strPath)
-{
- if (strPath.GetLength() > 0)
- {
- if ((strPath.GetAt(strPath.GetLength()-1) != '/') &&
- (strPath.GetAt(strPath.GetLength()-1) != '\\'))
- strPath += '/';
- }
-}
-
-bool ExtractPath_and_Filename(const char* pPath, CString& strPath, CString& strFilename)
-{
- CString strPathName;
- strPathName = pPath;
- int nSlash = strPathName.ReverseFind('\\');
- if (nSlash == -1)
- // TTimo: try forward slash, some are using forward
- nSlash = strPathName.ReverseFind('/');
- if (nSlash >= 0)
- {
- strPath = strPathName.Left(nSlash+1);
- strFilename = strPathName.Right(strPathName.GetLength() - nSlash - 1);
- }
- // TTimo: try forward slash, some are using forward
- else
- strFilename = pPath;
- return true;
-}
-
-//===========================================
-
-//++timo FIXME: no longer used .. remove!
-char *TranslateString (char *buf)
-{
- static char buf2[32768];
- int i, l;
- char *out;
-
- l = strlen(buf);
- out = buf2;
- for (i=0 ; i<l ; i++)
- {
- if (buf[i] == '\n')
- {
- *out++ = '\r';
- *out++ = '\n';
- }
- else
- *out++ = buf[i];
- }
- *out++ = 0;
-
- return buf2;
-}
-
-// called whenever we need to open/close/check the console log file
-void Sys_LogFile (void)
-{
- if (g_PrefsDlg.mGamesDialog.m_bLogConsole && !g_qeglobals.hLogFile)
- {
- // settings say we should be logging and we don't have a log file .. so create it
- // open a file to log the console (if user prefs say so)
- // the file handle is g_qeglobals.hLogFile
- // the log file is erased
- Str name;
- name = g_strTempPath;
- name += "radiant.log";
-#if defined (__linux__) || defined (__APPLE__)
- g_qeglobals.hLogFile = open( name.GetBuffer(), O_TRUNC | O_CREAT | O_WRONLY, S_IREAD | S_IWRITE );
-#endif
-#ifdef _WIN32
- g_qeglobals.hLogFile = _open( name.GetBuffer(), _O_TRUNC | _O_CREAT | _O_WRONLY, _S_IREAD | _S_IWRITE );
-#endif
- if (g_qeglobals.hLogFile)
- {
- Sys_Printf("Started logging to %s\n", name.GetBuffer());
- time_t localtime;
- time(&localtime);
- Sys_Printf("Today is: %s", ctime(&localtime));
- Sys_Printf("This is GtkRadiant '" RADIANT_VERSION "' compiled " __DATE__ "\n");
- Sys_Printf(RADIANT_ABOUTMSG "\n");
- }
- else
- gtk_MessageBox (NULL, "Failed to create log file, check write permissions in Radiant directory.\n",
- "Console logging", MB_OK );
- }
- else if (!g_PrefsDlg.mGamesDialog.m_bLogConsole && g_qeglobals.hLogFile)
- {
- // settings say we should not be logging but still we have an active logfile .. close it
- time_t localtime;
- time(&localtime);
- Sys_Printf("Closing log file at %s\n", ctime(&localtime));
- #ifdef _WIN32
- _close( g_qeglobals.hLogFile );
- #endif
- #if defined (__linux__) || defined (__APPLE__)
- close( g_qeglobals.hLogFile );
- #endif
- g_qeglobals.hLogFile = 0;
- }
-}
-
-void Sys_ClearPrintf (void)
-{
- GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_qeglobals_gui.d_edit));
- gtk_text_buffer_set_text(buffer, "", -1);
-}
-
-// used to be around 32000, that should be way enough already
-#define BUFFER_SIZE 4096
-
-extern "C" void Sys_FPrintf_VA (int level, const char *text, va_list args)
-{
- char buf[BUFFER_SIZE];
-
- buf[0] = 0;
- vsnprintf(buf, BUFFER_SIZE, text, args);
- buf[BUFFER_SIZE-1] = 0;
- const unsigned int length = strlen(buf);
-
- if (g_qeglobals.hLogFile)
- {
-#ifdef _WIN32
- _write(g_qeglobals.hLogFile, buf,length);
- _commit(g_qeglobals.hLogFile);
-#endif
-#if defined (__linux__) || defined (__APPLE__)
- write(g_qeglobals.hLogFile, buf, length);
-#endif
- }
-
- if (level != SYS_NOCON)
- {
- // TTimo: FIXME: killed the console to avoid GDI leak fuckup
- if (g_qeglobals_gui.d_edit != NULL)
- {
- GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_qeglobals_gui.d_edit));
-
- GtkTextIter iter;
- gtk_text_buffer_get_end_iter(buffer, &iter);
-
- static GtkTextMark* end = gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE);
-
- const GdkColor yellow = { 0, 0xb0ff, 0xb0ff, 0x0000 };
- const GdkColor red = { 0, 0xffff, 0x0000, 0x0000 };
- const GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
-
- static GtkTextTag* error_tag = gtk_text_buffer_create_tag (buffer, "red_foreground", "foreground-gdk", &red, NULL);
- static GtkTextTag* warning_tag = gtk_text_buffer_create_tag (buffer, "yellow_foreground", "foreground-gdk", &yellow, NULL);
- static GtkTextTag* standard_tag = gtk_text_buffer_create_tag (buffer, "black_foreground", "foreground-gdk", &black, NULL);
- GtkTextTag* tag;
- switch (level)
- {
- case SYS_WRN:
- tag = warning_tag;
- break;
- case SYS_ERR:
- tag = error_tag;
- break;
- case SYS_STD:
- case SYS_VRB:
- default:
- tag = standard_tag;
- break;
- }
- gtk_text_buffer_insert_with_tags(buffer, &iter, buf, length, tag, NULL);
-
- gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(g_qeglobals_gui.d_edit), end);
-
- // update console widget immediatly if we're doing something time-consuming
- if( !g_bScreenUpdates && GTK_WIDGET_REALIZED( g_qeglobals_gui.d_edit ) )
- {
- gtk_grab_add(g_qeglobals_gui.d_edit);
-
- while(gtk_events_pending())
- gtk_main_iteration();
-
- gtk_grab_remove(g_qeglobals_gui.d_edit);
- }
- }
- }
-}
-
-// NOTE: this is the handler sent to synapse
-// must match PFN_SYN_PRINTF_VA
-extern "C" void Sys_Printf_VA (const char *text, va_list args)
-{
- Sys_FPrintf_VA (SYS_STD, text, args);
-}
-
-extern "C" void Sys_Printf (const char *text, ...)
-{
- va_list args;
-
- va_start (args, text);
- Sys_FPrintf_VA (SYS_STD, text, args);
- va_end (args);
-}
-
-extern "C" void Sys_FPrintf (int level, const char *text, ...)
-{
- va_list args;
-
- va_start (args, text);
- Sys_FPrintf_VA (level, text, args);
- va_end (args);