From f773da2273b874ee5ec0e66fb06dd89fe207685a Mon Sep 17 00:00:00 2001 From: Eddy Jansson Date: Mon, 27 Oct 2025 16:48:04 +0100 Subject: [PATCH] log: Rework NGAGE logging. (#14321) This moves the NGAGE file logging into SDL_LogOutput(), following the pattern of the 3DS, VITA, PSP, etc. --- src/SDL_log.c | 33 +++++++++++++-------------------- src/core/ngage/SDL_ngage.cpp | 19 ++----------------- src/core/ngage/SDL_ngage.h | 1 + 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/SDL_log.c b/src/SDL_log.c index a77edd602e..ae39c0b7da 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -24,6 +24,10 @@ #include "core/windows/SDL_windows.h" #endif +#if defined(SDL_PLATFORM_NGAGE) +#include "core/ngage/SDL_ngage.h" +#endif + // Simple log messages in SDL #include "SDL_log_c.h" @@ -598,25 +602,6 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S return; } -#if defined(SDL_PLATFORM_NGAGE) - extern void NGAGE_vnprintf(char *buf, size_t size, const char *fmt, va_list ap); - char buf[1024]; - NGAGE_vnprintf(buf, sizeof(buf), fmt, ap); - -#ifdef ENABLE_FILE_LOG - FILE* file; - file = fopen("E:/SDL_Log.txt", "a"); - if (file) - { - vfprintf(file, fmt, ap); - fprintf(file, "\n"); - (void)fclose(file); - } -#endif - - return; -#endif - // Render into stack buffer va_copy(aq, ap); len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq); @@ -799,7 +784,15 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority } #elif defined(SDL_PLATFORM_NGAGE) { - /* Nothing to do here. */ + NGAGE_DebugPrintf("%s%s", GetLogPriorityPrefix(priority), message); +#ifdef ENABLE_FILE_LOG + FILE *pFile; + pFile = fopen("E:/SDL_Log.txt", "a"); + if (pFile) { + (void)fprintf(pFile, "%s%s\n", GetLogPriorityPrefix(priority), message); + (void)fclose(pFile); + } +#endif } #endif #if defined(HAVE_STDIO_H) && \ diff --git a/src/core/ngage/SDL_ngage.cpp b/src/core/ngage/SDL_ngage.cpp index 5f14af1ddc..b52c5d0682 100644 --- a/src/core/ngage/SDL_ngage.cpp +++ b/src/core/ngage/SDL_ngage.cpp @@ -36,13 +36,13 @@ bool NGAGE_IsClassicModel() return (0x101f8c19 == phone_id); } -void NGAGE_printf(const char *fmt, ...) +void NGAGE_DebugPrintf(const char *fmt, ...) { char buffer[512] = { 0 }; va_list ap; va_start(ap, fmt); - vsprintf(buffer, fmt, ap); + (void)SDL_vsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); TBuf<512> buf; @@ -51,21 +51,6 @@ void NGAGE_printf(const char *fmt, ...) RDebug::Print(_L("%S"), &buf); } -void NGAGE_vnprintf(char *buf, size_t size, const char *fmt, va_list ap) -{ - char buffer[512] = { 0 }; - - vsprintf(buffer, fmt, ap); - - TBuf<512> tbuf; - tbuf.Copy(TPtrC8((TText8 *)buffer)); - - RDebug::Print(_L("%S"), &tbuf); - - strncpy(buf, buffer, size - 1); - buf[size - 1] = '\0'; -} - TInt NGAGE_GetFreeHeapMemory() { TInt free = 0; diff --git a/src/core/ngage/SDL_ngage.h b/src/core/ngage/SDL_ngage.h index 66c4c60ec1..b8ad88055e 100644 --- a/src/core/ngage/SDL_ngage.h +++ b/src/core/ngage/SDL_ngage.h @@ -28,6 +28,7 @@ extern "C" { #endif bool NGAGE_IsClassicModel(); +void NGAGE_DebugPrintf(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); #ifdef __cplusplus }