diff options
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/macosx/crashlog_osx.cpp | 16 | ||||
-rw-r--r-- | src/os/macosx/splash.cpp | 16 | ||||
-rw-r--r-- | src/os/macosx/string_osx.cpp | 34 | ||||
-rw-r--r-- | src/os/os2/os2.cpp | 8 | ||||
-rw-r--r-- | src/os/unix/crashlog_unix.cpp | 2 | ||||
-rw-r--r-- | src/os/unix/unix.cpp | 14 | ||||
-rw-r--r-- | src/os/windows/crashlog_win.cpp | 42 | ||||
-rw-r--r-- | src/os/windows/string_uniscribe.cpp | 46 | ||||
-rw-r--r-- | src/os/windows/win32.cpp | 82 |
9 files changed, 130 insertions, 130 deletions
diff --git a/src/os/macosx/crashlog_osx.cpp b/src/os/macosx/crashlog_osx.cpp index c1b321340..16c029639 100644 --- a/src/os/macosx/crashlog_osx.cpp +++ b/src/os/macosx/crashlog_osx.cpp @@ -66,7 +66,7 @@ class CrashLogOSX : public CrashLog { " Machine: %s\n" " Min Ver: %d\n", ver_maj, ver_min, ver_bug, - arch != NULL ? arch->description : "unknown", + arch != nullptr ? arch->description : "unknown", MAC_OS_X_VERSION_MIN_REQUIRED ); } @@ -79,7 +79,7 @@ class CrashLogOSX : public CrashLog { " Message: %s\n\n", strsignal(this->signum), this->signum, - message == NULL ? "<none>" : message + message == nullptr ? "<none>" : message ); } @@ -99,14 +99,14 @@ class CrashLogOSX : public CrashLog { frame = (void **)__builtin_frame_address(0); #endif - for (int i = 0; frame != NULL && i < MAX_STACK_FRAMES; i++) { + for (int i = 0; frame != nullptr && i < MAX_STACK_FRAMES; i++) { /* Get IP for current stack frame. */ #if defined(__ppc__) || defined(__ppc64__) void *ip = frame[2]; #else void *ip = frame[1]; #endif - if (ip == NULL) break; + if (ip == nullptr) break; /* Print running index. */ buffer += seprintf(buffer, last, " [%02d]", i); @@ -118,7 +118,7 @@ class CrashLogOSX : public CrashLog { if (dl_valid && dli.dli_fname) { /* Valid image name? Extract filename from the complete path. */ const char *s = strrchr(dli.dli_fname, '/'); - if (s != NULL) { + if (s != nullptr) { fname = s + 1; } else { fname = dli.dli_fname; @@ -128,13 +128,13 @@ class CrashLogOSX : public CrashLog { buffer += seprintf(buffer, last, " %-20s " PRINTF_PTR, fname, (uintptr_t)ip); /* Print function offset if information is available. */ - if (dl_valid && dli.dli_sname != NULL && dli.dli_saddr != NULL) { + if (dl_valid && dli.dli_sname != nullptr && dli.dli_saddr != nullptr) { /* Try to demangle a possible C++ symbol. */ int status = -1; - char *func_name = abi::__cxa_demangle(dli.dli_sname, NULL, 0, &status); + char *func_name = abi::__cxa_demangle(dli.dli_sname, nullptr, 0, &status); long int offset = (intptr_t)ip - (intptr_t)dli.dli_saddr; - buffer += seprintf(buffer, last, " (%s + %ld)", func_name != NULL ? func_name : dli.dli_sname, offset); + buffer += seprintf(buffer, last, " (%s + %ld)", func_name != nullptr ? func_name : dli.dli_sname, offset); free(func_name); } diff --git a/src/os/macosx/splash.cpp b/src/os/macosx/splash.cpp index eadb78510..1ddb165b3 100644 --- a/src/os/macosx/splash.cpp +++ b/src/os/macosx/splash.cpp @@ -54,7 +54,7 @@ static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) void DisplaySplashImage() { FILE *f = FioFOpenFile(SPLASH_IMAGE_FILE, "r", BASESET_DIR); - if (f == NULL) return; + if (f == nullptr) return; png_byte header[8]; fread(header, sizeof(png_byte), 8, f); @@ -63,23 +63,23 @@ void DisplaySplashImage() return; } - png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, png_my_error, png_my_warning); + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) nullptr, png_my_error, png_my_warning); - if (png_ptr == NULL) { + if (png_ptr == nullptr) { fclose(f); return; } png_infop info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) { - png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); + if (info_ptr == nullptr) { + png_destroy_read_struct(&png_ptr, (png_infopp)nullptr, (png_infopp)nullptr); fclose(f); return; } png_infop end_info = png_create_info_struct(png_ptr); - if (end_info == NULL) { - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); + if (end_info == nullptr) { + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)nullptr); fclose(f); return; } @@ -93,7 +93,7 @@ void DisplaySplashImage() png_init_io(png_ptr, f); png_set_sig_bytes(png_ptr, 8); - png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, nullptr); uint width = png_get_image_width(png_ptr, info_ptr); uint height = png_get_image_height(png_ptr, info_ptr); diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 580be3520..6d90b91a8 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -22,7 +22,7 @@ #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) /** Cached current locale. */ -static CFLocaleRef _osx_locale = NULL; +static CFLocaleRef _osx_locale = nullptr; /** CoreText cache for font information, cleared when OTTD changes fonts. */ static CTFontRef _font_cache[FS_END]; @@ -125,21 +125,21 @@ static CGFloat SpriteFontGetWidth(void *ref_con) } static CTRunDelegateCallbacks _sprite_font_callback = { - kCTRunDelegateCurrentVersion, NULL, NULL, NULL, + kCTRunDelegateCurrentVersion, nullptr, nullptr, nullptr, &SpriteFontGetWidth }; /* static */ ParagraphLayouter *CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping) { - if (!MacOSVersionIsAtLeast(10, 5, 0)) return NULL; + if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; /* Can't layout an empty string. */ ptrdiff_t length = buff_end - buff; - if (length == 0) return NULL; + if (length == 0) return nullptr; /* Can't layout our in-built sprite fonts. */ for (const auto &i : fontMapping) { - if (i.second->fc->IsBuiltInFont()) return NULL; + if (i.second->fc->IsBuiltInFont()) return nullptr; } /* Make attributed string with embedded font information. */ @@ -156,10 +156,10 @@ static CTRunDelegateCallbacks _sprite_font_callback = { for (const auto &i : fontMapping) { if (i.first - last == 0) continue; - if (_font_cache[i.second->fc->GetSize()] == NULL) { + if (_font_cache[i.second->fc->GetSize()] == nullptr) { /* Cache font information. */ CFStringRef font_name = CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8); - _font_cache[i.second->fc->GetSize()] = CTFontCreateWithName(font_name, i.second->fc->GetFontSize(), NULL); + _font_cache[i.second->fc->GetSize()] = CTFontCreateWithName(font_name, i.second->fc->GetFontSize(), nullptr); CFRelease(font_name); } CFAttributedStringSetAttribute(str, CFRangeMake(last, i.first - last), kCTFontAttributeName, _font_cache[i.second->fc->GetSize()]); @@ -185,12 +185,12 @@ static CTRunDelegateCallbacks _sprite_font_callback = { CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString(str); CFRelease(str); - return typesetter != NULL ? new CoreTextParagraphLayout(typesetter, buff, length, fontMapping) : NULL; + return typesetter != nullptr ? new CoreTextParagraphLayout(typesetter, buff, length, fontMapping) : nullptr; } /* virtual */ std::unique_ptr<const ParagraphLayouter::Line> CoreTextParagraphLayout::NextLine(int max_width) { - if (this->cur_offset >= this->length) return NULL; + if (this->cur_offset >= this->length) return nullptr; /* Get line break position, trying word breaking first and breaking somewhere if that doesn't work. */ CFIndex len = CTTypesetterSuggestLineBreak(this->typesetter, this->cur_offset, max_width); @@ -200,7 +200,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = { CTLineRef line = CTTypesetterCreateLine(this->typesetter, CFRangeMake(this->cur_offset, len)); this->cur_offset += len; - return std::unique_ptr<const Line>(line != NULL ? new CoreTextLine(line, this->font_map, this->text_buffer) : NULL); + return std::unique_ptr<const Line>(line != nullptr ? new CoreTextLine(line, this->font_map, this->text_buffer) : nullptr); } CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff) : font(font) @@ -233,7 +233,7 @@ CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font this->positions[i * 2 + 1] = pts[i].y; } } - this->total_advance = (int)CTRunGetTypographicBounds(run, CFRangeMake(0, 0), NULL, NULL, NULL); + this->total_advance = (int)CTRunGetTypographicBounds(run, CFRangeMake(0, 0), nullptr, nullptr, nullptr); this->positions[this->glyphs.size() * 2] = this->positions[0] + this->total_advance; } @@ -271,9 +271,9 @@ int CoreTextParagraphLayout::CoreTextLine::GetWidth() const /** Delete CoreText font reference for a specific font size. */ void MacOSResetScriptCache(FontSize size) { - if (_font_cache[size] != NULL) { + if (_font_cache[size] != nullptr) { CFRelease(_font_cache[size]); - _font_cache[size] = NULL; + _font_cache[size] = nullptr; } } @@ -282,7 +282,7 @@ void MacOSSetCurrentLocaleName(const char *iso_code) { if (!MacOSVersionIsAtLeast(10, 5, 0)) return; - if (_osx_locale != NULL) CFRelease(_osx_locale); + if (_osx_locale != nullptr) CFRelease(_osx_locale); CFStringRef iso = CFStringCreateWithCString(kCFAllocatorNull, iso_code, kCFStringEncodingUTF8); _osx_locale = CFLocaleCreate(kCFAllocatorDefault, iso); @@ -425,7 +425,7 @@ int MacOSStringCompare(const char *s1, const char *s2) /* static */ StringIterator *OSXStringIterator::Create() { - if (!MacOSVersionIsAtLeast(10, 5, 0)) return NULL; + if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; return new OSXStringIterator(); } @@ -441,11 +441,11 @@ int MacOSStringCompare(const char *s1, const char *s2) /* static */ StringIterator *OSXStringIterator::Create() { - return NULL; + return nullptr; } /* static */ ParagraphLayouter *CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping) { - return NULL; + return nullptr; } #endif /* (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) */ diff --git a/src/os/os2/os2.cpp b/src/os/os2/os2.cpp index 70c75a410..9ba6f8ef9 100644 --- a/src/os/os2/os2.cpp +++ b/src/os/os2/os2.cpp @@ -102,7 +102,7 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot) struct diskfree_t free; char drive = path[0] - 'A' + 1; - if (tot != NULL && _getdiskfree(drive, &free) == 0) { + if (tot != nullptr && _getdiskfree(drive, &free) == 0) { *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; return true; } @@ -119,7 +119,7 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot) free = (uint64)s.f_frsize * s.f_bavail; } #endif - if (tot != NULL) *tot = free; + if (tot != nullptr) *tot = free; return true; #endif } @@ -173,7 +173,7 @@ void ShowOSErrorBox(const char *buf, bool system) int CDECL main(int argc, char *argv[]) { - SetRandomSeed(time(NULL)); + SetRandomSeed(time(nullptr)); /* Make sure our arguments contain only valid UTF-8 characters. */ for (int i = 0; i < argc; i++) ValidateString(argv[i]); @@ -191,7 +191,7 @@ bool GetClipboardContents(char *buffer, const char *last) { const char *text = (const char*)WinQueryClipbrdData(hab, CF_TEXT); - if (text != NULL) + if (text != nullptr) { strecpy(buffer, text, last); WinCloseClipbrd(hab); diff --git a/src/os/unix/crashlog_unix.cpp b/src/os/unix/crashlog_unix.cpp index 2e9f4215f..005babebd 100644 --- a/src/os/unix/crashlog_unix.cpp +++ b/src/os/unix/crashlog_unix.cpp @@ -68,7 +68,7 @@ class CrashLogUnix : public CrashLog { " Message: %s\n\n", strsignal(this->signum), this->signum, - message == NULL ? "<none>" : message + message == nullptr ? "<none>" : message ); } diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index aa63019f6..430e3770f 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -84,7 +84,7 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot) if (statvfs(path, &s) != 0) return false; free = (uint64)s.f_frsize * s.f_bavail; #endif - if (tot != NULL) *tot = free; + if (tot != nullptr) *tot = free; return true; } @@ -130,9 +130,9 @@ static const char *GetLocalCode() #else /* Strip locale (eg en_US.UTF-8) to only have UTF-8 */ const char *locale = GetCurrentLocale("LC_CTYPE"); - if (locale != NULL) locale = strchr(locale, '.'); + if (locale != nullptr) locale = strchr(locale, '.'); - return (locale == NULL) ? "" : locale + 1; + return (locale == nullptr) ? "" : locale + 1; #endif } @@ -158,7 +158,7 @@ static const char *convert_tofrom_fs(iconv_t convd, const char *name) strecpy(outbuf, name, outbuf + outlen); - iconv(convd, NULL, NULL, NULL, NULL); + iconv(convd, nullptr, nullptr, nullptr, nullptr); if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == (size_t)(-1)) { DEBUG(misc, 0, "[iconv] error converting '%s'. Errno %d", name, errno); } @@ -246,13 +246,13 @@ int CDECL main(int argc, char *argv[]) cocoaSetupAutoreleasePool(); /* This is passed if we are launched by double-clicking */ if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) { - argv[1] = NULL; + argv[1] = nullptr; argc = 1; } #endif CrashLog::InitialiseCrashLog(); - SetRandomSeed(time(NULL)); + SetRandomSeed(time(nullptr)); signal(SIGPIPE, SIG_IGN); @@ -282,7 +282,7 @@ void OSOpenBrowser(const char *url) const char *args[3]; args[0] = "xdg-open"; args[1] = url; - args[2] = NULL; + args[2] = nullptr; execvp(args[0], const_cast<char * const *>(args)); DEBUG(misc, 0, "Failed to open url: %s", url); exit(0); diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 458a76163..a19789976 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -66,7 +66,7 @@ public: * A crash log is always generated when it's generated. * @param ep the data related to the exception. */ - CrashLogWindows(EXCEPTION_POINTERS *ep = NULL) : + CrashLogWindows(EXCEPTION_POINTERS *ep = nullptr) : ep(ep) { this->crashlog[0] = '\0'; @@ -81,7 +81,7 @@ public: static CrashLogWindows *current; }; -/* static */ CrashLogWindows *CrashLogWindows::current = NULL; +/* static */ CrashLogWindows *CrashLogWindows::current = nullptr; /* virtual */ char *CrashLogWindows::LogOSVersion(char *buffer, const char *last) const { @@ -114,7 +114,7 @@ public: " Message: %s\n\n", (int)ep->ExceptionRecord->ExceptionCode, (size_t)ep->ExceptionRecord->ExceptionAddress, - message == NULL ? "<none>" : message + message == nullptr ? "<none>" : message ); } @@ -156,7 +156,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) HANDLE file; memset(dfi, 0, sizeof(*dfi)); - file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); + file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, 0); if (file != INVALID_HANDLE_VALUE) { byte buffer[1024]; DWORD numread; @@ -165,7 +165,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) uint32 crc = (uint32)-1; for (;;) { - if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || numread == 0) { + if (ReadFile(file, buffer, sizeof(buffer), &numread, nullptr) == 0 || numread == 0) { break; } filesize += numread; @@ -174,7 +174,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) dfi->size = filesize; dfi->crc32 = crc ^ (uint32)-1; - if (GetFileTime(file, NULL, NULL, &write_time)) { + if (GetFileTime(file, nullptr, nullptr, &write_time)) { FileTimeToSystemTime(&write_time, &dfi->file_time); } CloseHandle(file); @@ -217,7 +217,7 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod) BOOL res; HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); - if (proc != NULL) { + if (proc != nullptr) { res = EnumProcessModules(proc, modules, sizeof(modules), &needed); CloseHandle(proc); if (res) { @@ -228,7 +228,7 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod) } } } - output = PrintModuleInfo(output, last, NULL); + output = PrintModuleInfo(output, last, nullptr); return output + seprintf(output, last, "\n"); } @@ -362,7 +362,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c if (LoadLibraryList((Function*)&proc, dbg_import)) { /* Initialize symbol handler. */ HANDLE hCur = GetCurrentProcess(); - proc.pSymInitialize(hCur, NULL, TRUE); + proc.pSymInitialize(hCur, nullptr, TRUE); /* Load symbols only when needed, fail silently on errors, demangle symbol names. */ proc.pSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_UNDNAME); @@ -399,7 +399,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c #else IMAGE_FILE_MACHINE_I386, #endif - hCur, GetCurrentThread(), &frame, &ctx, NULL, proc.pSymFunctionTableAccess64, proc.pSymGetModuleBase64, NULL)) break; + hCur, GetCurrentThread(), &frame, &ctx, nullptr, proc.pSymFunctionTableAccess64, proc.pSymGetModuleBase64, nullptr)) break; if (frame.AddrPC.Offset == frame.AddrReturn.Offset) { buffer += seprintf(buffer, last, " <infinite loop>\n"); @@ -443,16 +443,16 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c { int ret = 0; HMODULE dbghelp = LoadLibrary(_T("dbghelp.dll")); - if (dbghelp != NULL) { + if (dbghelp != nullptr) { typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, CONST PMINIDUMP_EXCEPTION_INFORMATION, CONST PMINIDUMP_USER_STREAM_INFORMATION, CONST PMINIDUMP_CALLBACK_INFORMATION); MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump"); - if (funcMiniDumpWriteDump != NULL) { + if (funcMiniDumpWriteDump != nullptr) { seprintf(filename, filename_last, "%scrash.dmp", _personal_dir); - HANDLE file = CreateFile(OTTD2FS(filename), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + HANDLE file = CreateFile(OTTD2FS(filename), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0); HANDLE proc = GetCurrentProcess(); DWORD procid = GetCurrentProcessId(); MINIDUMP_EXCEPTION_INFORMATION mdei; @@ -470,7 +470,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c mdei.ExceptionPointers = ep; mdei.ClientPointers = false; - funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, NULL); + funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, nullptr); ret = 1; } else { ret = -1; @@ -488,11 +488,11 @@ static void ShowCrashlogWindow(); * Stack pointer for use when 'starting' the crash handler. * Not static as gcc's inline assembly needs it that way. */ -void *_safe_esp = NULL; +void *_safe_esp = nullptr; static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) { - if (CrashLogWindows::current != NULL) { + if (CrashLogWindows::current != nullptr) { CrashLog::AfterCrashLogCleanup(); ExitProcess(2); } @@ -501,7 +501,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) static const TCHAR _emergency_crash[] = _T("A serious fault condition occurred in the game. The game will shut down.\n") _T("As you loaded an emergency savegame no crash information will be generated.\n"); - MessageBox(NULL, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR); + MessageBox(nullptr, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR); ExitProcess(3); } @@ -510,7 +510,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) _T("A serious fault condition occurred in the game. The game will shut down.\n") _T("As you loaded an savegame for which you do not have the required NewGRFs\n") _T("no crash information will be generated.\n"); - MessageBox(NULL, _saveload_crash, _T("Fatal Application Failure"), MB_ICONERROR); + MessageBox(nullptr, _saveload_crash, _T("Fatal Application Failure"), MB_ICONERROR); ExitProcess(3); } @@ -525,7 +525,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) /* Close any possible log files */ CloseConsoleLogIfActive(); - if ((VideoDriver::GetInstance() == NULL || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != NULL) { + if ((VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != nullptr) { #ifdef _M_AMD64 ep->ContextRecord->Rip = (DWORD64)ShowCrashlogWindow; ep->ContextRecord->Rsp = (DWORD64)_safe_esp; @@ -542,7 +542,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) static void CDECL CustomAbort(int signal) { - RaiseException(0xE1212012, 0, 0, NULL); + RaiseException(0xE1212012, 0, 0, nullptr); } /* static */ void CrashLog::InitialiseCrashLog() @@ -693,5 +693,5 @@ static void ShowCrashlogWindow() { ShowCursor(TRUE); ShowWindow(GetActiveWindow(), FALSE); - DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc); + DialogBox(GetModuleHandle(nullptr), MAKEINTRESOURCE(100), nullptr, CrashDialogFunc); } diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 5abe848bd..8c4e11d3f 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -86,7 +86,7 @@ public: int num_glyphs; Font *font; - mutable int *glyph_to_char = NULL; + mutable int *glyph_to_char = nullptr; public: UniscribeVisualRun(const UniscribeRun &range, int x); @@ -139,9 +139,9 @@ public: void UniscribeResetScriptCache(FontSize size) { - if (_script_cache[size] != NULL) { + if (_script_cache[size] != nullptr) { ScriptFreeCache(&_script_cache[size]); - _script_cache[size] = NULL; + _script_cache[size] = nullptr; } } @@ -168,9 +168,9 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b /* The char-to-glyph array is the same size as the input. */ range.char_to_glyph.resize(range.len); - HDC temp_dc = NULL; - HFONT old_font = NULL; - HFONT cur_font = NULL; + HDC temp_dc = nullptr; + HFONT old_font = nullptr; + HFONT cur_font = nullptr; while (true) { /* Shape the text run by determining the glyphs needed for display. */ @@ -217,9 +217,9 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b } else if (hr == E_PENDING) { /* Glyph data is not in cache, load native font. */ cur_font = HFontFromFont(range.font); - if (cur_font == NULL) return false; // Sorry, no dice. + if (cur_font == nullptr) return false; // Sorry, no dice. - temp_dc = CreateCompatibleDC(NULL); + temp_dc = CreateCompatibleDC(nullptr); SetMapMode(temp_dc, MM_TEXT); old_font = (HFONT)SelectObject(temp_dc, cur_font); } else if (hr == USP_E_SCRIPT_NOT_IN_FONT && range.sa.eScript != SCRIPT_UNDEFINED) { @@ -227,19 +227,19 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b range.sa.eScript = SCRIPT_UNDEFINED; } else { /* Some unknown other error. */ - if (temp_dc != NULL) { + if (temp_dc != nullptr) { SelectObject(temp_dc, old_font); DeleteObject(cur_font); - ReleaseDC(NULL, temp_dc); + ReleaseDC(nullptr, temp_dc); } return false; } } - if (temp_dc != NULL) { + if (temp_dc != nullptr) { SelectObject(temp_dc, old_font); DeleteObject(cur_font); - ReleaseDC(NULL, temp_dc); + ReleaseDC(nullptr, temp_dc); } return true; @@ -280,16 +280,16 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF { int32 length = buff_end - buff; /* Can't layout an empty string. */ - if (length == 0) return NULL; + if (length == 0) return nullptr; /* Can't layout our in-built sprite fonts. */ for (auto const &pair : fontMapping) { - if (pair.second->fc->IsBuiltInFont()) return NULL; + if (pair.second->fc->IsBuiltInFont()) return nullptr; } /* Itemize text. */ std::vector<SCRIPT_ITEM> items = UniscribeItemizeString(buff, length); - if (items.size() == 0) return NULL; + if (items.size() == 0) return nullptr; /* Build ranges from the items and the font map. A range is a run of text * that is part of a single item and formatted using a single font style. */ @@ -306,7 +306,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF /* Shape the range. */ if (!UniscribeShapeRun(buff, ranges.back())) { - return NULL; + return nullptr; } /* If we are at the end of the current item, advance to the next item. */ @@ -323,7 +323,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF std::vector<UniscribeRun>::iterator start_run = this->cur_range; std::vector<UniscribeRun>::iterator last_run = this->cur_range; - if (start_run == this->ranges.end()) return NULL; + if (start_run == this->ranges.end()) return nullptr; /* Add remaining width of the first run if it is a broken run. */ int cur_width = 0; @@ -355,7 +355,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF int last_cluster = this->cur_range_offset + 1; for (std::vector<UniscribeRun>::iterator r = start_run; r != last_run; r++) { log_attribs.resize(r->pos - start_run->pos + r->len); - if (FAILED(ScriptBreak(this->text_buffer + r->pos + start_offs, r->len - start_offs, &r->sa, &log_attribs[r->pos - start_run->pos + start_offs]))) return NULL; + if (FAILED(ScriptBreak(this->text_buffer + r->pos + start_offs, r->len - start_offs, &r->sa, &log_attribs[r->pos - start_run->pos + start_offs]))) return nullptr; std::vector<int> dx(r->len); ScriptGetLogicalWidths(&r->sa, r->len, (int)r->glyphs.size(), &r->advances[0], &r->char_to_glyph[0], &r->vis_attribs[0], &dx[0]); @@ -401,7 +401,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF bidi_level.push_back(r->sa.s.uBidiLevel); } std::vector<INT> vis_to_log(bidi_level.size()); - if (FAILED(ScriptLayout((int)bidi_level.size(), &bidi_level[0], &vis_to_log[0], NULL))) return NULL; + if (FAILED(ScriptLayout((int)bidi_level.size(), &bidi_level[0], &vis_to_log[0], nullptr))) return nullptr; /* Create line. */ std::unique_ptr<UniscribeLine> line(new UniscribeLine()); @@ -415,14 +415,14 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF if (i_run == last_run - 1 && remaing_offset < (last_run - 1)->len) { run.len = remaing_offset - 1; - if (!UniscribeShapeRun(this->text_buffer, run)) return NULL; + if (!UniscribeShapeRun(this->text_buffer, run)) return nullptr; } if (i_run == start_run && this->cur_range_offset > 0) { assert(run.len - this->cur_range_offset > 0); run.pos += this->cur_range_offset; run.len -= this->cur_range_offset; - if (!UniscribeShapeRun(this->text_buffer, run)) return NULL; + if (!UniscribeShapeRun(this->text_buffer, run)) return nullptr; } line->emplace_back(run, cur_pos); @@ -490,12 +490,12 @@ UniscribeParagraphLayout::UniscribeVisualRun::UniscribeVisualRun(UniscribeVisual start_pos(other.start_pos), total_advance(other.total_advance), num_glyphs(other.num_glyphs), font(other.font) { this->glyph_to_char = other.glyph_to_char; - other.glyph_to_char = NULL; + other.glyph_to_char = nullptr; } const int *UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCharMap() const { - if (this->glyph_to_char == NULL) { + if (this->glyph_to_char == nullptr) { this->glyph_to_char = CallocT<int>(this->GetGlyphCount()); /* The char to glyph array contains the first glyph index of the cluster that is associated diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index ae78407ac..b0495d64d 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -61,14 +61,14 @@ bool LoadLibraryList(Function proc[], const char *dll) HMODULE lib; lib = LoadLibrary(MB_TO_WIDE(dll)); - if (lib == NULL) return false; + if (lib == nullptr) return false; for (;;) { FARPROC p; while (*dll++ != '\0') { /* Nothing */ } if (*dll == '\0') break; p = GetProcAddress(lib, dll); - if (p == NULL) return false; + if (p == nullptr) return false; *proc++ = (Function)p; } dll++; @@ -84,7 +84,7 @@ void ShowOSErrorBox(const char *buf, bool system) void OSOpenBrowser(const char *url) { - ShellExecute(GetActiveWindow(), _T("open"), OTTD2FS(url), NULL, NULL, SW_SHOWNORMAL); + ShellExecute(GetActiveWindow(), _T("open"), OTTD2FS(url), nullptr, nullptr, SW_SHOWNORMAL); } /* Code below for windows version of opendir/readdir/closedir copied and @@ -142,7 +142,7 @@ DIR *opendir(const TCHAR *path) if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) { d = dir_calloc(); - if (d != NULL) { + if (d != nullptr) { TCHAR search_path[MAX_PATH]; bool slash = path[_tcslen(path) - 1] == '\\'; @@ -158,14 +158,14 @@ DIR *opendir(const TCHAR *path) d->at_first_entry = true; } else { dir_free(d); - d = NULL; + d = nullptr; } } else { errno = ENOMEM; } } else { /* path not found or not a directory */ - d = NULL; + d = nullptr; errno = ENOENT; } @@ -179,11 +179,11 @@ struct dirent *readdir(DIR *d) if (d->at_first_entry) { /* the directory was empty when opened */ - if (d->hFind == INVALID_HANDLE_VALUE) return NULL; + if (d->hFind == INVALID_HANDLE_VALUE) return nullptr; d->at_first_entry = false; } else if (!FindNextFile(d->hFind, &d->fd)) { // determine cause and bail if (GetLastError() == ERROR_NO_MORE_FILES) SetLastError(prev_err); - return NULL; + return nullptr; } /* This entry has passed all checks; return information about it. @@ -251,7 +251,7 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot) DWORD spc, bps, nfc, tnc; _sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]); - if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { + if (tot != nullptr && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { *tot = ((spc * bps) * (uint64)nfc); retval = true; } @@ -339,9 +339,9 @@ void CreateConsole() *stderr = *fdopen(2, "w" ); #endif - setvbuf(stdin, NULL, _IONBF, 0); - setvbuf(stdout, NULL, _IONBF, 0); - setvbuf(stderr, NULL, _IONBF, 0); + setvbuf(stdin, nullptr, _IONBF, 0); + setvbuf(stdout, nullptr, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); } /** Temporary pointer to get the help message to the window */ @@ -398,7 +398,7 @@ void ShowInfo(const char *str) * ShowInfo are much shorter, or so long they need this way of displaying * them anyway. */ _help_msg = str; - DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(101), NULL, HelpDialogFunc); + DialogBox(GetModuleHandle(nullptr), MAKEINTRESOURCE(101), nullptr, HelpDialogFunc); } else { /* We need to put the text in a separate buffer because the default * buffer in OTTD2FS might not be large enough (512 chars). */ @@ -459,28 +459,28 @@ void DetermineBasePaths(const char *exe) char tmp[MAX_PATH]; TCHAR path[MAX_PATH]; #ifdef WITH_PERSONAL_DIR - if (SUCCEEDED(OTTDSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path))) { + if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) { strecpy(tmp, FS2OTTD(path), lastof(tmp)); AppendPathSeparator(tmp, lastof(tmp)); strecat(tmp, PERSONAL_DIR, lastof(tmp)); AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_PERSONAL_DIR] = stredup(tmp); } else { - _searchpaths[SP_PERSONAL_DIR] = NULL; + _searchpaths[SP_PERSONAL_DIR] = nullptr; } - if (SUCCEEDED(OTTDSHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, SHGFP_TYPE_CURRENT, path))) { + if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) { strecpy(tmp, FS2OTTD(path), lastof(tmp)); AppendPathSeparator(tmp, lastof(tmp)); strecat(tmp, PERSONAL_DIR, lastof(tmp)); AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_SHARED_DIR] = stredup(tmp); } else { - _searchpaths[SP_SHARED_DIR] = NULL; + _searchpaths[SP_SHARED_DIR] = nullptr; } #else - _searchpaths[SP_PERSONAL_DIR] = NULL; - _searchpaths[SP_SHARED_DIR] = NULL; + _searchpaths[SP_PERSONAL_DIR] = nullptr; + _searchpaths[SP_SHARED_DIR] = nullptr; #endif /* Get the path to working directory of OpenTTD */ @@ -488,15 +488,15 @@ void DetermineBasePaths(const char *exe) AppendPathSeparator(tmp, lastof(tmp)); _searchpaths[SP_WORKING_DIR] = stredup(tmp); - if (!GetModuleFileName(NULL, path, lengthof(path))) { + if (!GetModuleFileName(nullptr, path, lengthof(path))) { DEBUG(misc, 0, "GetModuleFileName failed (%lu)\n", GetLastError()); - _searchpaths[SP_BINARY_DIR] = NULL; + _searchpaths[SP_BINARY_DIR] = nullptr; } else { TCHAR exec_dir[MAX_PATH]; _tcsncpy(path, convert_to_fs(exe, path, lengthof(path)), lengthof(path)); - if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, NULL)) { + if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, nullptr)) { DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError()); - _searchpaths[SP_BINARY_DIR] = NULL; + _searchpaths[SP_BINARY_DIR] = nullptr; } else { strecpy(tmp, convert_from_fs(exec_dir, tmp, lengthof(tmp)), lastof(tmp)); char *s = strrchr(tmp, PATHSEPCHAR); @@ -505,8 +505,8 @@ void DetermineBasePaths(const char *exe) } } - _searchpaths[SP_INSTALLATION_DIR] = NULL; - _searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL; + _searchpaths[SP_INSTALLATION_DIR] = nullptr; + _searchpaths[SP_APPLICATION_BUNDLE_DIR] = nullptr; } @@ -516,18 +516,18 @@ bool GetClipboardContents(char *buffer, const char *last) const char *ptr; if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { - OpenClipboard(NULL); + OpenClipboard(nullptr); cbuf = GetClipboardData(CF_UNICODETEXT); ptr = (const char*)GlobalLock(cbuf); - int out_len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)ptr, -1, buffer, (last - buffer) + 1, NULL, NULL); + int out_len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)ptr, -1, buffer, (last - buffer) + 1, nullptr, nullptr); GlobalUnlock(cbuf); CloseClipboard(); if (out_len == 0) return false; #if !defined(UNICODE) } else if (IsClipboardFormatAvailable(CF_TEXT)) { - OpenClipboard(NULL); + OpenClipboard(nullptr); cbuf = GetClipboardData(CF_TEXT); ptr = (const char*)GlobalLock(cbuf); @@ -596,7 +596,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen) const WCHAR *wide_buf = name; #else /* Convert string from the local codepage to UTF-16. */ - int wide_len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0); + int wide_len = MultiByteToWideChar(CP_ACP, 0, name, -1, nullptr, 0); if (wide_len == 0) { utf8_buf[0] = '\0'; return utf8_buf; @@ -607,7 +607,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen) #endif /* Convert UTF-16 string to UTF-8. */ - int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, NULL, NULL); + int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, nullptr, nullptr); if (len == 0) utf8_buf[0] = '\0'; return utf8_buf; @@ -630,7 +630,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool co int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen); if (len == 0) system_buf[0] = '\0'; #else - int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0); + int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, nullptr, 0); if (len == 0) { system_buf[0] = '\0'; return system_buf; @@ -639,7 +639,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool co WCHAR *wide_buf = AllocaM(WCHAR, len); MultiByteToWideChar(CP_UTF8, 0, name, -1, wide_buf, len); - len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, NULL, NULL); + len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, nullptr, nullptr); if (len == 0) system_buf[0] = '\0'; #endif @@ -654,7 +654,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool co */ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) { - static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL; + static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = nullptr; static bool first_time = true; /* We only try to load the library one time; if it fails, it fails */ @@ -674,7 +674,7 @@ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, first_time = false; } - if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); + if (SHGetFolderPath != nullptr) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); /* SHGetFolderPath doesn't exist, try a more conservative approach, * eg environment variables. This is only included for legacy modes @@ -698,7 +698,7 @@ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, HKEY key; if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break; DWORD len = MAX_PATH; - ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), NULL, NULL, (LPBYTE)pszPath, &len); + ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), nullptr, nullptr, (LPBYTE)pszPath, &len); RegCloseKey(key); if (ret == ERROR_SUCCESS) return (HRESULT)0; break; @@ -718,7 +718,7 @@ const char *GetCurrentLocale(const char *) if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, lang, lengthof(lang)) == 0 || GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, country, lengthof(country)) == 0) { /* Unable to retrieve the locale. */ - return NULL; + return nullptr; } /* Format it as 'en_us'. */ static char retbuf[6] = {lang[0], lang[1], '_', country[0], country[1], 0}; @@ -750,7 +750,7 @@ void Win32SetCurrentLocaleName(const char *iso_code) int OTTDStringCompare(const char *s1, const char *s2) { typedef int (WINAPI *PFNCOMPARESTRINGEX)(LPCWSTR, DWORD, LPCWCH, int, LPCWCH, int, LPVOID, LPVOID, LPARAM); - static PFNCOMPARESTRINGEX _CompareStringEx = NULL; + static PFNCOMPARESTRINGEX _CompareStringEx = nullptr; static bool first_time = true; #ifndef SORT_DIGITSASNUMBERS @@ -765,10 +765,10 @@ int OTTDStringCompare(const char *s1, const char *s2) first_time = false; } - if (_CompareStringEx != NULL) { + if (_CompareStringEx != nullptr) { /* CompareStringEx takes UTF-16 strings, even in ANSI-builds. */ - int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1, -1, NULL, 0); - int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, NULL, 0); + int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1, -1, nullptr, 0); + int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, nullptr, 0); if (len_s1 != 0 && len_s2 != 0) { LPWSTR str_s1 = AllocaM(WCHAR, len_s1); @@ -777,7 +777,7 @@ int OTTDStringCompare(const char *s1, const char *s2) MultiByteToWideChar(CP_UTF8, 0, s1, -1, str_s1, len_s1); MultiByteToWideChar(CP_UTF8, 0, s2, -1, str_s2, len_s2); - int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1, -1, str_s2, -1, NULL, NULL, 0); + int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1, -1, str_s2, -1, nullptr, nullptr, 0); if (result != 0) return result; } } |