From 01c93d0aad6299e7929285cbc14f95ea73917e48 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Wed, 16 Oct 2013 23:28:05 +0000 Subject: Fix OS X’s SysPrintf, when sent strings without a newline. Before, it used NSLog which outputs stuff sent to it one line at a time. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@87500 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/main.m | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/macosx/main.m b/macosx/main.m index d37bf104..ab1707fa 100755 --- a/macosx/main.m +++ b/macosx/main.m @@ -121,7 +121,7 @@ void SysReset() #ifdef EMU_LOG #ifndef LOG_STDOUT -static NSDateFormatter* debugDateFormatter() +static inline NSDateFormatter* debugDateFormatter() { static NSDateFormatter* theFormatter = nil; if (theFormatter == nil) { @@ -133,7 +133,29 @@ static NSDateFormatter* debugDateFormatter() #endif #endif -void SysPrintf(const char *fmt, ...) { +static void AddStringToLogList(const char *themsg) +{ + static NSMutableString *theStr; + NSRange newlineRange, fullLineRange; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + theStr = [[NSMutableString alloc] init]; + }); + [theStr appendString:@(themsg)]; + while ((newlineRange = [theStr rangeOfString:@"\n"]).location != NSNotFound) { + NSString *tmpStr = [theStr substringFromIndex:newlineRange.location]; + if (tmpStr && ![tmpStr isEqualToString:@""]) { + NSLog(@"%@", tmpStr); + } + fullLineRange.location = 0; + fullLineRange.length = newlineRange.location + newlineRange.length; + fullLineRange = [theStr rangeOfComposedCharacterSequencesForRange:fullLineRange]; + [theStr deleteCharactersInRange:fullLineRange]; + } +} + +void SysPrintf(const char *fmt, ...) +{ va_list list; char *msg = calloc(sizeof(char), 512); @@ -142,7 +164,7 @@ void SysPrintf(const char *fmt, ...) { va_end(list); RunOnMainThreadSync(^{ - if (Config.PsxOut) NSLog (@"%s", msg); + if (Config.PsxOut) AddStringToLogList(msg); #ifdef EMU_LOG #ifndef LOG_STDOUT if (emuLog) fprintf(emuLog, "%s %s: %s",[[debugDateFormatter() stringFromDate:[NSDate date]] UTF8String], @@ -214,7 +236,8 @@ void SysUpdate() } // Returns to the Gui -void SysRunGui() { +void SysRunGui() +{ if (powerAssertion != kIOPMNullAssertionID) { IOPMAssertionRelease(powerAssertion); powerAssertion = kIOPMNullAssertionID; @@ -222,7 +245,8 @@ void SysRunGui() { } // Close mem and plugins -void SysClose() { +void SysClose() +{ EmuShutdown(); ReleasePlugins(); -- cgit v1.2.3