summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt10
-rw-r--r--src/common/assert.h36
-rw-r--r--src/common/break_points.cpp1
-rw-r--r--src/common/chunk_file.h11
-rw-r--r--src/common/common.h76
-rw-r--r--src/common/common_funcs.h66
-rw-r--r--src/common/common_types.h6
-rw-r--r--src/common/concurrent_ring_buffer.h5
-rw-r--r--src/common/emu_window.cpp8
-rw-r--r--src/common/extended_trace.cpp428
-rw-r--r--src/common/extended_trace.h50
-rw-r--r--src/common/file_search.cpp103
-rw-r--r--src/common/file_search.h23
-rw-r--r--src/common/file_util.cpp14
-rw-r--r--src/common/hash.cpp13
-rw-r--r--src/common/key_map.cpp6
-rw-r--r--src/common/key_map.h6
-rw-r--r--src/common/log.h56
-rw-r--r--src/common/logging/backend.cpp5
-rw-r--r--src/common/logging/log.h3
-rw-r--r--src/common/mem_arena.cpp9
-rw-r--r--src/common/memory_util.cpp14
-rw-r--r--src/common/msg_handler.cpp107
-rw-r--r--src/common/msg_handler.h70
-rw-r--r--src/common/scope_exit.h5
-rw-r--r--src/common/string_util.cpp6
-rw-r--r--src/common/symbols.cpp2
-rw-r--r--src/common/utf8.cpp459
-rw-r--r--src/common/utf8.h67
29 files changed, 147 insertions, 1518 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 3c3419bbc..b05c35546 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -4,8 +4,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
set(SRCS
break_points.cpp
emu_window.cpp
- extended_trace.cpp
- file_search.cpp
file_util.cpp
hash.cpp
key_map.cpp
@@ -16,16 +14,15 @@ set(SRCS
mem_arena.cpp
memory_util.cpp
misc.cpp
- msg_handler.cpp
scm_rev.cpp
string_util.cpp
symbols.cpp
thread.cpp
timer.cpp
- utf8.cpp
)
set(HEADERS
+ assert.h
bit_field.h
break_points.h
chunk_file.h
@@ -37,14 +34,11 @@ set(HEADERS
cpu_detect.h
debug_interface.h
emu_window.h
- extended_trace.h
fifo_queue.h
- file_search.h
file_util.h
hash.h
key_map.h
linear_disk_cache.h
- log.h
logging/text_formatter.h
logging/filter.h
logging/log.h
@@ -53,7 +47,6 @@ set(HEADERS
math_util.h
mem_arena.h
memory_util.h
- msg_handler.h
platform.h
scm_rev.h
scope_exit.h
@@ -64,7 +57,6 @@ set(HEADERS
thread_queue_list.h
thunk.h
timer.h
- utf8.h
)
create_directory_groups(${SRCS} ${HEADERS})
diff --git a/src/common/assert.h b/src/common/assert.h
new file mode 100644
index 000000000..3b2232a7e
--- /dev/null
+++ b/src/common/assert.h
@@ -0,0 +1,36 @@
+// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/common_funcs.h"
+
+// TODO (yuriks) allow synchronous logging so we don't need printf
+#define ASSERT(_a_) \
+ do if (!(_a_)) {\
+ fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
+ __LINE__, __FILE__, __TIME__); \
+ Crash(); \
+ } while (0)
+
+#define ASSERT_MSG(_a_, ...) \
+ do if (!(_a_)) {\
+ fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
+ __LINE__, __FILE__, __TIME__); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, "\n"); \
+ Crash(); \
+ } while (0)
+
+#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
+
+#ifdef _DEBUG
+#define DEBUG_ASSERT(_a_) ASSERT(_a_)
+#define DEBUG_ASSERT_MSG(_a_, ...) ASSERT_MSG(_a_, __VA_ARGS__)
+#else // not debug
+#define DEBUG_ASSERT(_a_)
+#define DEBUG_ASSERT_MSG(_a_, _desc_, ...)
+#endif
+
+#define UNIMPLEMENTED() DEBUG_ASSERT_MSG(false, "Unimplemented code!")
diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp
index 6696935fa..2655d3ce9 100644
--- a/src/common/break_points.cpp
+++ b/src/common/break_points.cpp
@@ -5,6 +5,7 @@
#include "common/common.h"
#include "common/debug_interface.h"
#include "common/break_points.h"
+#include "common/logging/log.h"
#include <sstream>
#include <algorithm>
diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h
index 39a14dc81..3f97d56bf 100644
--- a/src/common/chunk_file.h
+++ b/src/common/chunk_file.h
@@ -180,7 +180,7 @@ public:
case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything
case MODE_VERIFY:
for (int i = 0; i < size; i++) {
- _dbg_assert_msg_(Common, ((u8*)data)[i] == (*ptr)[i],
+ DEBUG_ASSERT_MSG(((u8*)data)[i] == (*ptr)[i],
"Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i],
(*ptr)[i], (*ptr)[i], &(*ptr)[i]);
@@ -200,7 +200,7 @@ public:
case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything
case MODE_VERIFY:
for (int i = 0; i < size; i++) {
- _dbg_assert_msg_(Common, ((u8*)data)[i] == (*ptr)[i],
+ DEBUG_ASSERT_MSG(((u8*)data)[i] == (*ptr)[i],
"Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i],
(*ptr)[i], (*ptr)[i], &(*ptr)[i]);
@@ -505,8 +505,7 @@ public:
case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
case MODE_MEASURE: break;
case MODE_VERIFY:
- _dbg_assert_msg_(Common,
- !strcmp(x.c_str(), (char*)*ptr),
+ DEBUG_ASSERT_MSG((x == (char*)*ptr),
"Savestate verification failure: \"%s\" != \"%s\" (at %p).\n",
x.c_str(), (char*)*ptr, ptr);
break;
@@ -524,7 +523,7 @@ public:
case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
case MODE_MEASURE: break;
case MODE_VERIFY:
- _dbg_assert_msg_(Common, x == (wchar_t*)*ptr,
+ DEBUG_ASSERT_MSG((x == (wchar_t*)*ptr),
"Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n",
x.c_str(), (wchar_t*)*ptr, ptr);
break;
@@ -638,7 +637,7 @@ public:
Do(cookie);
if(mode == PointerWrap::MODE_READ && cookie != arbitraryNumber)
{
- PanicAlertT("Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber);
+ LOG_ERROR(Common, "After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber);
SetError(ERROR_FAILURE);
}
}
diff --git a/src/common/common.h b/src/common/common.h
index 3246c7797..948dc536a 100644
--- a/src/common/common.h
+++ b/src/common/common.h
@@ -25,9 +25,9 @@ private:
NonCopyable& operator=(NonCopyable& other);
};
-#include "common/log.h"
+#include "common/assert.h"
+#include "common/logging/log.h"
#include "common/common_types.h"
-#include "common/msg_handler.h"
#include "common/common_funcs.h"
#include "common/common_paths.h"
#include "common/platform.h"
@@ -35,13 +35,11 @@ private:
#ifdef __APPLE__
// The Darwin ABI requires that stack frames be aligned to 16-byte boundaries.
// This is only needed on i386 gcc - x86_64 already aligns to 16 bytes.
-#if defined __i386__ && defined __GNUC__
-#undef STACKALIGN
-#define STACKALIGN __attribute__((__force_align_arg_pointer__))
-#endif
-
+ #if defined __i386__ && defined __GNUC__
+ #undef STACKALIGN
+ #define STACKALIGN __attribute__((__force_align_arg_pointer__))
+ #endif
#elif defined _WIN32
-
// Check MSC ver
#if defined _MSC_VER && _MSC_VER <= 1000
#error needs at least version 1000 of MSC
@@ -51,9 +49,6 @@ private:
#define NOMINMAX
#endif
-// Memory leak checks
- #define CHECK_HEAP_INTEGRITY()
-
// Alignment
#define MEMORY_ALIGNED16(x) __declspec(align(16)) x
#define MEMORY_ALIGNED32(x) __declspec(align(32)) x
@@ -61,57 +56,34 @@ private:
#define MEMORY_ALIGNED128(x) __declspec(align(128)) x
#define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x
#define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x
-
-// Since they are always around on windows
- #define HAVE_WX 1
- #define HAVE_OPENAL 1
-
- #define HAVE_PORTAUDIO 1
-
-// Debug definitions
- #if defined(_DEBUG)
- #include <crtdbg.h>
- #undef CHECK_HEAP_INTEGRITY
- #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");}
- // If you want to see how much a pain in the ass singletons are, for example:
- // {614} normal block at 0x030C5310, 188 bytes long.
- // Data: <Master Log > 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00
- struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } };
- //CrtDebugBreak breakAt(614);
- #endif // end DEBUG/FAST
-
#endif
// Windows compatibility
#ifndef _WIN32
-#ifdef _LP64
-#define _M_X64 1
-#else
-#define _M_IX86 1
-#endif
-#define __forceinline inline __attribute__((always_inline))
-#define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
-#define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
-#define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
-#define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
-#define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
-#define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
+ #ifdef _LP64
+ #define _M_X64 1
+ #else
+ #define _M_IX86 1
+ #endif
+ #define __forceinline inline __attribute__((always_inline))
+ #define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
+ #define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
+ #define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
+ #define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
+ #define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
+ #define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
#endif
#ifdef _MSC_VER
-#define __strdup _strdup
-#define __getcwd _getcwd
-#define __chdir _chdir
+ #define __strdup _strdup
+ #define __getcwd _getcwd
+ #define __chdir _chdir
#else
-#define __strdup strdup
-#define __getcwd getcwd
-#define __chdir chdir
+ #define __strdup strdup
+ #define __getcwd getcwd
+ #define __chdir chdir
#endif
-// Dummy macro for marking translatable strings that can not be immediately translated.
-// wxWidgets does not have a true dummy macro for this.
-#define _trans(a) a
-
#if defined _M_GENERIC
# define _M_SSE 0x0
#elif defined __GNUC__
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index c2750a63c..bc296ed3e 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -24,12 +24,17 @@ template<> struct CompileTimeAssert<true> {};
#define b32(x) (b16(x) | (b16(x) >>16) )
#define ROUND_UP_POW2(x) (b32(x - 1) + 1)
-#define MIN(a, b) ((a)<(b)?(a):(b))
-#define MAX(a, b) ((a)>(b)?(a):(b))
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-#define CLAMP(x, min, max) (((x) > max) ? max : (((x) < min) ? min : (x)))
+/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
+#define CONCAT2(x, y) DO_CONCAT2(x, y)
+#define DO_CONCAT2(x, y) x ## y
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+// helper macro to properly align structure members.
+// Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121",
+// depending on the current source line to make sure variable names are unique.
+#define INSERT_PADDING_BYTES(num_bytes) u8 CONCAT2(pad, __LINE__)[(num_bytes)]
+#define INSERT_PADDING_WORDS(num_words) u32 CONCAT2(pad, __LINE__)[(num_words)]
#ifndef _MSC_VER
@@ -40,15 +45,14 @@ template<> struct CompileTimeAssert<true> {};
#include <sys/endian.h>
#endif
-// go to debugger mode
- #ifdef GEKKO
- #define Crash()
- #elif defined _M_GENERIC
- #define Crash() { exit(1); }
- #else
- #define Crash() {asm ("int $3");}
- #endif
- #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
+#if defined(__x86_64__) || defined(_M_X64)
+#define Crash() __asm__ __volatile__("int $3")
+#elif defined(_M_ARM)
+#define Crash() __asm__ __volatile__("trap")
+#else
+#define Crash() exit(1)
+#endif
+
// GCC 4.8 defines all the rotate functions now
// Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit
#ifndef _rotl
@@ -93,10 +97,10 @@ inline u64 _rotr64(u64 x, unsigned int shift){
#define LC_GLOBAL_LOCALE ((locale_t)-1)
#define LC_ALL_MASK LC_ALL
#define LC_COLLATE_MASK LC_COLLATE
- #define LC_CTYPE_MASK LC_CTYPE
- #define LC_MONETARY_MASK LC_MONETARY
+ #define LC_CTYPE_MASK LC_CTYPE
+ #define LC_MONETARY_MASK LC_MONETARY
#define LC_NUMERIC_MASK LC_NUMERIC
- #define LC_TIME_MASK LC_TIME
+ #define LC_TIME_MASK LC_TIME
inline locale_t uselocale(locale_t new_locale)
{
@@ -132,25 +136,12 @@ inline u64 _rotr64(u64 x, unsigned int shift){
#define fstat64 _fstat64
#define fileno _fileno
- #if _M_IX86
- #define Crash() {__asm int 3}
- #else
-extern "C" {
- __declspec(dllimport) void __stdcall DebugBreak(void);
-}
- #define Crash() {DebugBreak();}
- #endif // M_IX86
+ extern "C" {
+ __declspec(dllimport) void __stdcall DebugBreak(void);
+ }
+ #define Crash() {DebugBreak();}
#endif // _MSC_VER ndef
-// Dolphin's min and max functions
-#undef min
-#undef max
-
-template<class T>
-inline T min(const T& a, const T& b) {return a > b ? b : a;}
-template<class T>
-inline T max(const T& a, const T& b) {return a > b ? a : b;}
-
// Generic function to get last error message.
// Call directly after the command or use the error num.
// This function might change the error code.
@@ -227,13 +218,4 @@ inline void swap<8>(u8* data)
*reinterpret_cast<u64*>(data) = swap64(data);
}
-template <typename T>
-inline T FromBigEndian(T data)
-{
- //static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");
-
- swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
- return data;
-}
-
} // Namespace Common
diff --git a/src/common/common_types.h b/src/common/common_types.h
index 94e1406b1..1b453e7f5 100644
--- a/src/common/common_types.h
+++ b/src/common/common_types.h
@@ -28,6 +28,12 @@
#include <cstdint>
#include <cstdlib>
+#ifdef _MSC_VER
+#ifndef __func__
+#define __func__ __FUNCTION__
+#endif
+#endif
+
typedef std::uint8_t u8; ///< 8-bit unsigned byte
typedef std::uint16_t u16; ///< 16-bit unsigned short
typedef std::uint32_t u32; ///< 32-bit unsigned word
diff --git a/src/common/concurrent_ring_buffer.h b/src/common/concurrent_ring_buffer.h
index 311bb01f4..fc18e6c86 100644
--- a/src/common/concurrent_ring_buffer.h
+++ b/src/common/concurrent_ring_buffer.h
@@ -11,7 +11,6 @@
#include <thread>
#include "common/common.h" // for NonCopyable
-#include "common/log.h" // for _dbg_assert_
namespace Common {
@@ -93,7 +92,7 @@ public:
return QUEUE_CLOSED;
}
}
- _dbg_assert_(Common, CanRead());
+ DEBUG_ASSERT(CanRead());
return PopInternal(dest, dest_len);
}
@@ -119,7 +118,7 @@ private:
size_t PopInternal(T* dest, size_t dest_len) {
size_t output_count = 0;
while (output_count < dest_len && CanRead()) {
- _dbg_assert_(Common, CanRead());
+ DEBUG_ASSERT(CanRead());
T* item = &Data()[reader_index];
T out_val = std::move(*item);
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 4ec7b263a..48bb35db5 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -5,13 +5,13 @@
#include "emu_window.h"
void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
- HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
+ Service::HID::PadState mapped_key = KeyMap::GetPadKey(key);
- HID_User::PadButtonPress(mapped_key);
+ Service::HID::PadButtonPress(mapped_key);
}
void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
- HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
+ Service::HID::PadState mapped_key = KeyMap::GetPadKey(key);
- HID_User::PadButtonRelease(mapped_key);
+ Service::HID::PadButtonRelease(mapped_key);
}
diff --git a/src/common/extended_trace.cpp b/src/common/extended_trace.cpp
deleted file mode 100644
index cf7c346d4..000000000
--- a/src/common/extended_trace.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
-// --------------------------------------------------------------------------------------
-//
-// Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
-// For companies(Austin,TX): If you would like to get my resume, send an email.
-//
-// The source is free, but if you want to use it, mention my name and e-mail address
-//
-// History:
-// 1.0 Initial version Zoltan Csizmadia
-// 1.1 WhineCube version Masken
-// 1.2 Dolphin version Masken
-//
-// --------------------------------------------------------------------------------------
-
-#if defined(WIN32)
-#include <cstdio>
-#include <windows.h>
-#include "common/extended_trace.h"
-#include "common/string_util.h"
-using namespace std;
-
-#include <tchar.h>
-#include <ImageHlp.h>
-
-#define BUFFERSIZE 0x200
-#pragma warning(disable:4996)
-
-// Unicode safe char* -> TCHAR* conversion
-void PCSTR2LPTSTR( PCSTR lpszIn, LPTSTR lpszOut )
-{
-#if defined(UNICODE)||defined(_UNICODE)
- ULONG index = 0;
- PCSTR lpAct = lpszIn;
-
- for( ; ; lpAct++ )
- {
- lpszOut[index++] = (TCHAR)(*lpAct);
- if ( *lpAct == 0 )
- break;
- }
-#else
- // This is trivial :)
- strcpy( lpszOut, lpszIn );
-#endif
-}
-
-// Let's figure out the path for the symbol files
-// Search path= ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;" + lpszIniPath
-// Note: There is no size check for lpszSymbolPath!
-static void InitSymbolPath( PSTR lpszSymbolPath, PCSTR lpszIniPath )
-{
- CHAR lpszPath[BUFFERSIZE];
-
- // Creating the default path
- // ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;"
- strcpy( lpszSymbolPath, "." );
-
- // environment variable _NT_SYMBOL_PATH
- if ( GetEnvironmentVariableA( "_NT_SYMBOL_PATH", lpszPath, BUFFERSIZE ) )
- {
- strcat( lpszSymbolPath, ";" );
- strcat( lpszSymbolPath, lpszPath );
- }
-
- // environment variable _NT_ALTERNATE_SYMBOL_PATH
- if ( GetEnvironmentVariableA( "_NT_ALTERNATE_SYMBOL_PATH", lpszPath, BUFFERSIZE ) )
- {
- strcat( lpszSymbolPath, ";" );
- strcat( lpszSymbolPath, lpszPath );
- }
-
- // environment variable SYSTEMROOT
- if ( GetEnvironmentVariableA( "SYSTEMROOT", lpszPath, BUFFERSIZE ) )
- {
- strcat( lpszSymbolPath, ";" );
- strcat( lpszSymbolPath, lpszPath );
- strcat( lpszSymbolPath, ";" );
-
- // SYSTEMROOT\System32
- strcat( lpszSymbolPath, lpszPath );
- strcat( lpszSymbolPath, "\\System32" );
- }
-
- // Add user defined path
- if ( lpszIniPath != nullptr )
- if ( lpszIniPath[0] != '\0' )
- {
- strcat( lpszSymbolPath, ";" );
- strcat( lpszSymbolPath, lpszIniPath );
- }
-}
-
-// Uninitialize the loaded symbol files
-BOOL UninitSymInfo() {
- return SymCleanup( GetCurrentProcess() );
-}
-
-// Initializes the symbol files
-BOOL InitSymInfo( PCSTR lpszInitialSymbolPath )
-{
- CHAR lpszSymbolPath[BUFFERSIZE];
- DWORD symOptions = SymGetOptions();
-
- symOptions |= SYMOPT_LOAD_LINES;
- symOptions &= ~SYMOPT_UNDNAME;
- SymSetOptions( symOptions );
- InitSymbolPath( lpszSymbolPath, lpszInitialSymbolPath );
-
- return SymInitialize( GetCurrentProcess(), lpszSymbolPath, TRUE);
-}
-
-// Get the module name from a given address
-static BOOL GetModuleNameFromAddress( UINT address, LPTSTR lpszModule )
-{
- BOOL ret = FALSE;
- IMAGEHLP_MODULE moduleInfo;
-
- ::ZeroMemory( &moduleInfo, sizeof(moduleInfo) );
- moduleInfo.SizeOfStruct = sizeof(moduleInfo);
-
- if ( SymGetModuleInfo( GetCurrentProcess(), (DWORD)address, &moduleInfo ) )
- {
- // Got it!
- PCSTR2LPTSTR( moduleInfo.ModuleName, lpszModule );
- ret = TRUE;
- }
- else
- // Not found :(
- _tcscpy( lpszModule, _T("?") );
-
- return ret;
-}
-
-// Get function prototype and parameter info from ip address and stack address
-static BOOL GetFunctionInfoFromAddresses( ULONG fnAddress, ULONG stackAddress, LPTSTR lpszSymbol )
-{
- BOOL ret = FALSE;
- DWORD dwSymSize = 10000;
- TCHAR lpszUnDSymbol[BUFFERSIZE]=_T("?");
- CHAR lpszNonUnicodeUnDSymbol[BUFFERSIZE]="?";
- LPTSTR lpszParamSep = nullptr;
- LPTSTR lpszParsed = lpszUnDSymbol;
- PIMAGEHLP_SYMBOL pSym = (PIMAGEHLP_SYMBOL)GlobalAlloc( GMEM_FIXED, dwSymSize );
-
- ::ZeroMemory( pSym, dwSymSize );
- pSym->SizeOfStruct = dwSymSize;
- pSym->MaxNameLength = dwSymSize - sizeof(IMAGEHLP_SYMBOL);
-
- // Set the default to unknown
- _tcscpy( lpszSymbol, _T("?") );
-
- // Get symbol info for IP
-#ifndef _M_X64
- DWORD dwDisp = 0;
- if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, &dwDisp, pSym ) )
-#else
- //makes it compile but hell im not sure if this works...
- DWORD64 dwDisp = 0;
- if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, (PDWORD64)&dwDisp, pSym ) )
-#endif
- {
- // Make the symbol readable for humans
- UnDecorateSymbolName( pSym->Name, lpszNonUnicodeUnDSymbol, BUFFERSIZE,
- UNDNAME_COMPLETE |
- UNDNAME_NO_THISTYPE |
- UNDNAME_NO_SPECIAL_SYMS |
- UNDNAME_NO_MEMBER_TYPE |
- UNDNAME_NO_MS_KEYWORDS |
- UNDNAME_NO_ACCESS_SPECIFIERS );
-
- // Symbol information is ANSI string
- PCSTR2LPTSTR( lpszNonUnicodeUnDSymbol, lpszUnDSymbol );
-
- // I am just smarter than the symbol file :)
- if (_tcscmp(lpszUnDSymbol, _T("_WinMain@16")) == 0)
- _tcscpy(lpszUnDSymbol, _T("WinMain(HINSTANCE,HINSTANCE,LPCTSTR,int)"));
- else if (_tcscmp(lpszUnDSymbol, _T("_main")) == 0)
- _tcscpy(lpszUnDSymbol, _T("main(int,TCHAR * *)"));
- else if (_tcscmp(lpszUnDSymbol, _T("_mainCRTStartup")) == 0)
- _tcscpy(lpszUnDSymbol, _T("mainCRTStartup()"));
- else if (_tcscmp(lpszUnDSymbol, _T("_wmain")) == 0)
- _tcscpy(lpszUnDSymbol, _T("wmain(int,TCHAR * *,TCHAR * *)"));
- else if (_tcscmp(lpszUnDSymbol, _T("_wmainCRTStartup")) == 0)
- _tcscpy(lpszUnDSymbol, _T("wmainCRTStartup()"));
-
- lpszSymbol[0] = _T('\0');
-
- // Let's go through the stack, and modify the function prototype, and insert the actual
- // parameter values from the stack
- if ( _tcsstr( lpszUnDSymbol, _T("(void)") ) == nullptr && _tcsstr( lpszUnDSymbol, _T("()") ) == nullptr)
- {
- ULONG index = 0;
- for( ; ; index++ )
- {
- lpszParamSep = _tcschr( lpszParsed, _T(',') );
- if ( lpszParamSep == nullptr )
- break;
-
- *lpszParamSep = _T('\0');
-
- _tcscat( lpszSymbol, lpszParsed );
- _stprintf( lpszSymbol + _tcslen(lpszSymbol), _T("=0x%08X,"), *((ULONG*)(stackAddress) + 2 + index) );
-
- lpszParsed = lpszParamSep + 1;
- }
-
- lpszParamSep = _tcschr( lpszParsed, _T(')') );
- if ( lpszParamSep != nullptr )
- {
- *lpszParamSep = _T('\0');
-
- _tcscat( lpszSymbol, lpszParsed );
- _stprintf( lpszSymbol + _tcslen(lpszSymbol), _T("=0x%08X)"), *((ULONG*)(stackAddress) + 2 + index) );
-
- lpszParsed = lpszParamSep + 1;
- }
- }
-
- _tcscat( lpszSymbol, lpszParsed );
-
- ret = TRUE;
- }
- GlobalFree( pSym );
-
- return ret;
-}
-
-// Get source file name and line number from IP address
-// The output format is: "sourcefile(linenumber)" or
-// "modulename!address" or
-// "address"
-static BOOL GetSourceInfoFromAddress( UINT address, LPTSTR lpszSourceInfo )
-{
- BOOL ret = FALSE;
- IMAGEHLP_LINE lineInfo;
- DWORD dwDisp;
- TCHAR lpszFileName[BUFFERSIZE] = _T("");
- TCHAR lpModuleInfo[BUFFERSIZE] = _T("");
-
- _tcscpy( lpszSourceInfo, _T("?(?)") );
-
- ::ZeroMemory( &lineInfo, sizeof( lineInfo ) );
- lineInfo.SizeOfStruct = sizeof( lineInfo );
-
- if ( SymGetLineFromAddr( GetCurrentProcess(), address, &dwDisp, &lineInfo ) )
- {
- // Got it. Let's use "sourcefile(linenumber)" format
- PCSTR2LPTSTR( lineInfo.FileName, lpszFileName );
- TCHAR fname[_MAX_FNAME];
- TCHAR ext[_MAX_EXT];
- _tsplitpath(lpszFileName, nullptr, nullptr, fname, ext);
- _stprintf( lpszSourceInfo, _T("%s%s(%d)"), fname, ext, lineInfo.LineNumber );
- ret = TRUE;
- }
- else
- {
- // There is no source file information. :(
- // Let's use the "modulename!address" format
- GetModuleNameFromAddress( address, lpModuleInfo );
-
- if ( lpModuleInfo[0] == _T('?') || lpModuleInfo[0] == _T('\0'))
- // There is no modulename information. :((
- // Let's use the "address" format
- _stprintf( lpszSourceInfo, _T("0x%08X"), address );
- else
- _stprintf( lpszSourceInfo, _T("%s!0x%08X"), lpModuleInfo, address );
-
- ret = FALSE;
- }
-
- return ret;
-}
-
-void PrintFunctionAndSourceInfo(FILE* file, const STACKFRAME& callstack)
-{
- TCHAR symInfo[BUFFERSIZE] = _T("?");
- TCHAR srcInfo[BUFFERSIZE] = _T("?");
-
- GetFunctionInfoFromAddresses((ULONG)callstack.AddrPC.Offset, (ULONG)callstack.AddrFrame.Offset, symInfo);
- GetSourceInfoFromAddress((ULONG)callstack.AddrPC.Offset, srcInfo);
- etfprint(file, " " + Common::TStrToUTF8(srcInfo) + " : " + Common::TStrToUTF8(symInfo) + "\n");
-}
-
-void StackTrace( HANDLE hThread, const char* lpszMessage, FILE *file )
-{
- STACKFRAME callStack;
- BOOL bResult;
- CONTEXT context;
- HANDLE hProcess = GetCurrentProcess();
-
- // If it's not this thread, let's suspend it, and resume it at the end
- if ( hThread != GetCurrentThread() )
- if ( SuspendThread( hThread ) == -1 )
- {
- // whaaat ?!
- etfprint(file, "Call stack info failed\n");
- return;
- }
-
- ::ZeroMemory( &context, sizeof(context) );
- context.ContextFlags = CONTEXT_FULL;
-
- if ( !GetThreadContext( hThread, &context ) )
- {
- etfprint(file, "Call stack info failed\n");
- return;
- }
-
- ::ZeroMemory( &callStack, sizeof(callStack) );
-#ifndef _M_X64
- callStack.AddrPC.Offset = context.Eip;
- callStack.AddrStack.Offset = context.Esp;
- callStack.AddrFrame.Offset = context.Ebp;
-#else
- callStack.AddrPC.Offset = context.Rip;
- callStack.AddrStack.Offset = context.Rsp;
- callStack.AddrFrame.Offset = context.Rbp;
-#endif
- callStack.AddrPC.Mode = AddrModeFlat;
- callStack.AddrStack.Mode = AddrModeFlat;
- callStack.AddrFrame.Mode = AddrModeFlat;
-
- etfprint(file, "Call stack info: \n");
- etfprint(file, lpszMessage);
-
- PrintFunctionAndSourceInfo(file, callStack);
-
- for( ULONG index = 0; ; index++ )
- {
- bResult = StackWalk(
- IMAGE_FILE_MACHINE_I386,
- hProcess,
- hThread,
- &callStack,
- nullptr,
- nullptr,
- SymFunctionTableAccess,
- SymGetModuleBase,
- nullptr);
-
- if ( index == 0 )
- continue;
-
- if( !bResult || callStack.AddrFrame.Offset == 0 )
- break;
-
- PrintFunctionAndSourceInfo(file, callStack);
-
- }
-
- if ( hThread != GetCurrentThread() )
- ResumeThread( hThread );
-}
-
-void StackTrace(HANDLE hThread, const char* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp )
-{
- STACKFRAME callStack;
- BOOL bResult;
- TCHAR symInfo[BUFFERSIZE] = _T("?");
- TCHAR srcInfo[BUFFERSIZE] = _T("?");
- HANDLE hProcess = GetCurrentProcess();
-
- // If it's not this thread, let's suspend it, and resume it at the end
- if ( hThread != GetCurrentThread() )
- if ( SuspendThread( hThread ) == -1 )
- {
- // whaaat ?!
- etfprint(file, "Call stack info failed\n");
- return;
- }
-
- ::ZeroMemory( &callStack, sizeof(callStack) );
- callStack.AddrPC.Offset = eip;
- callStack.AddrStack.Offset = esp;
- callStack.AddrFrame.Offset = ebp;
- callStack.AddrPC.Mode = AddrModeFlat;
- callStack.AddrStack.Mode = AddrModeFlat;
- callStack.AddrFrame.Mode = AddrModeFlat;
-
- etfprint(file, "Call stack info: \n");
- etfprint(file, lpszMessage);
-
- PrintFunctionAndSourceInfo(file, callStack);
-
- for( ULONG index = 0; ; index++ )
- {
- bResult = StackWalk(
- IMAGE_FILE_MACHINE_I386,
- hProcess,
- hThread,
- &callStack,
- nullptr,
- nullptr,
- SymFunctionTableAccess,
- SymGetModuleBase,
- nullptr);
-
- if ( index == 0 )
- continue;
-
- if( !bResult || callStack.AddrFrame.Offset == 0 )
- break;
-
- PrintFunctionAndSourceInfo(file, callStack);
- }
-
- if ( hThread != GetCurrentThread() )
- ResumeThread( hThread );
-}
-
-char g_uefbuf[2048];
-
-void etfprintf(FILE *file, const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- int len = vsprintf(g_uefbuf, format, ap);
- fwrite(g_uefbuf, 1, len, file);
- va_end(ap);
-}
-
-void etfprint(FILE *file, const std::string &text)
-{
- size_t len = text.length();
- fwrite(text.data(), 1, len, file);
-}
-
-#endif //WIN32
diff --git a/src/common/extended_trace.h b/src/common/extended_trace.h
deleted file mode 100644
index ed3113a24..000000000
--- a/src/common/extended_trace.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// -----------------------------------------------------------------------------------------
-//
-// Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
-// For companies(Austin,TX): If you would like to get my resume, send an email.
-//
-// The source is free, but if you want to use it, mention my name and e-mail address
-//
-// History:
-// 1.0 Initial version Zoltan Csizmadia
-// 1.1 WhineCube version Masken
-// 1.2 Dolphin version Masken
-//
-// ----------------------------------------------------------------------------------------
-
-#pragma once
-
-#if defined(WIN32)
-
-#include <windows.h>
-#include <tchar.h>
-
-#include <string>
-
-#pragma comment( lib, "imagehlp.lib" )
-
-#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) InitSymInfo( IniSymbolPath )
-#define EXTENDEDTRACEUNINITIALIZE() UninitSymInfo()
-#define STACKTRACE(file) StackTrace( GetCurrentThread(), "", file)
-#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), "", file, eip, esp, ebp)
-// class File;
-
-BOOL InitSymInfo( PCSTR );
-BOOL UninitSymInfo();
-void StackTrace(HANDLE, char const* msg, FILE *file);
-void StackTrace(HANDLE, char const* msg, FILE *file, DWORD eip, DWORD esp, DWORD ebp);
-
-// functions by Masken
-void etfprintf(FILE *file, const char *format, ...);
-void etfprint(FILE *file, const std::string &text);
-#define UEFBUFSIZE 2048
-extern char g_uefbuf[UEFBUFSIZE];
-
-#else // not WIN32
-
-#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) ((void)0)
-#define EXTENDEDTRACEUNINITIALIZE() ((void)0)
-#define STACKTRACE(file) ((void)0)
-#define STACKTRACE2(file, eip, esp, ebp) ((void)0)
-
-#endif // WIN32
diff --git a/src/common/file_search.cpp b/src/common/file_search.cpp
deleted file mode 100644
index b3a0a84fb..000000000
--- a/src/common/file_search.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-
-#include "common/common.h"
-
-#ifndef _WIN32
-#include <dirent.h>
-#else
-#include <windows.h>
-#endif
-
-#include <algorithm>
-
-#include "common/file_search.h"
-#include "common/string_util.h"
-
-
-CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories)
-{
- // Reverse the loop order for speed?
- for (size_t j = 0; j < _rSearchStrings.size(); j++)
- {
- for (size_t i = 0; i < _rDirectories.size(); i++)
- {
- FindFiles(_rSearchStrings[j], _rDirectories[i]);
- }
- }
-}
-
-
-void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath)
-{
- std::string GCMSearchPath;
- Common::BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
-#ifdef _WIN32
- WIN32_FIND_DATA findData;
- HANDLE FindFirst = FindFirstFile(Common::UTF8ToTStr(GCMSearchPath).c_str(), &findData);
-
- if (FindFirst != INVALID_HANDLE_VALUE)
- {
- bool bkeepLooping = true;
-
- while (bkeepLooping)
- {
- if (findData.cFileName[0] != '.')
- {
- std::string strFilename;
- Common::BuildCompleteFilename(strFilename, _strPath, Common::TStrToUTF8(findData.cFileName));
- m_FileNames.push_back(strFilename);
- }
-
- bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
- }
- }
- FindClose(FindFirst);
-
-
-#else
- // TODO: super lame/broken
-
- auto end_match(_searchString);
-
- // assuming we have a "*.blah"-like pattern
- if (!end_match.empty() && end_match[0] == '*')
- end_match.erase(0, 1);
-
- // ugly
- if (end_match == ".*")
- end_match.clear();
-
- DIR* dir = opendir(_strPath.c_str());
-
- if (!dir)
- return;
-
- while (auto const dp = readdir(dir))
- {
- std::string found(dp->d_name);
-
- if ((found != ".") && (found != "..")
- && (found.size() >= end_match.size())
- && std::equal(end_match.rbegin(), end_match.rend(), found.rbegin()))
- {
- std::string full_name;
- if (_strPath.c_str()[_strPath.size()-1] == DIR_SEP_CHR)
- full_name = _strPath + found;
- else
- full_name = _strPath + DIR_SEP + found;
-
- m_FileNames.push_back(full_name);
- }
- }
-
- closedir(dir);
-#endif
-}
-
-const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
-{
- return m_FileNames;
-}
diff --git a/src/common/file_search.h b/src/common/file_search.h
deleted file mode 100644
index 55ca02638..000000000
--- a/src/common/file_search.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <string>
-#include <vector>
-
-class CFileSearch
-{
-public:
- typedef std::vector<std::string>XStringVector;
-
- CFileSearch(const XStringVector& _rSearchStrings, const XStringVector& _rDirectories);
- const XStringVector& GetFileNames() const;
-
-private:
-
- void FindFiles(const std::string& _searchString, const std::string& _strPath);
-
- XStringVector m_FileNames;
-};
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 706e7c842..457376bf4 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -622,15 +622,15 @@ std::string GetBundleDirectory()
#ifdef _WIN32
std::string& GetExeDirectory()
{
- static std::string DolphinPath;
- if (DolphinPath.empty())
+ static std::string exe_path;
+ if (exe_path.empty())
{
- TCHAR Dolphin_exe_Path[2048];
- GetModuleFileName(nullptr, Dolphin_exe_Path, 2048);
- DolphinPath = Common::TStrToUTF8(Dolphin_exe_Path);
- DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\'));
+ TCHAR tchar_exe_path[2048];
+ GetModuleFileName(nullptr, tchar_exe_path, 2048);
+ exe_path = Common::TStrToUTF8(tchar_exe_path);
+ exe_path = exe_path.substr(0, exe_path.find_last_of('\\'));
}
- return DolphinPath;
+ return exe_path;
}
#endif
diff --git a/src/common/hash.cpp b/src/common/hash.cpp
index fe2c9e636..0624dab8d 100644
--- a/src/common/hash.cpp
+++ b/src/common/hash.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include "common/hash.h"
#if _M_SSE >= 0x402
@@ -155,7 +156,7 @@ u64 GetMurmurHash3(const u8 *src, int len, u32 samples)
const u8 * data = (const u8*)src;
const int nblocks = len / 16;
u32 Step = (len / 8);
- if(samples == 0) samples = max(Step, 1u);
+ if(samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if(Step < 1) Step = 1;
@@ -233,7 +234,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
- if(samples == 0) samples = max(Step, 1u);
+ if(samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
@@ -265,7 +266,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
- if(samples == 0) samples = max(Step, 1u);
+ if(samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
@@ -308,7 +309,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
u32 Step = (len/4);
const u32 *data = (const u32 *)src;
const u32 *end = data + Step;
- if(samples == 0) samples = max(Step, 1u);
+ if(samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
@@ -380,7 +381,7 @@ u64 GetMurmurHash3(const u8* src, int len, u32 samples)
u32 out[2];
const int nblocks = len / 8;
u32 Step = (len / 4);
- if(samples == 0) samples = max(Step, 1u);
+ if(samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if(Step < 1) Step = 1;
@@ -456,7 +457,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
- if(samples == 0) samples = max(Step, 1u);
+ if(samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp
index d8945bb13..844d5df68 100644
--- a/src/common/key_map.cpp
+++ b/src/common/key_map.cpp
@@ -7,18 +7,18 @@
namespace KeyMap {
-static std::map<HostDeviceKey, HID_User::PadState> key_map;
+static std::map<HostDeviceKey, Service::HID::PadState> key_map;
static int next_device_id = 0;
int NewDeviceId() {
return next_device_id++;
}
-void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState) {
+void SetKeyMapping(HostDeviceKey key, Service::HID::PadState padState) {
key_map[key].hex = padState.hex;
}
-HID_User::PadState GetPadKey(HostDeviceKey key) {
+Service::HID::PadState GetPadKey(HostDeviceKey key) {
return key_map[key];
}
diff --git a/src/common/key_map.h b/src/common/key_map.h
index 8d949b852..0ecec714f 100644
--- a/src/common/key_map.h
+++ b/src/common/key_map.h
@@ -4,7 +4,7 @@
#pragma once
-#include "core/hle/service/hid_user.h"
+#include "core/hle/service/hid/hid.h"
namespace KeyMap {
@@ -35,11 +35,11 @@ int NewDeviceId();
/**
* Maps a device-specific key to a PadState.
*/
-void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState);
+void SetKeyMapping(HostDeviceKey key, Service::HID::PadState padState);
/**
* Gets the PadState that's mapped to the provided device-specific key.
*/
-HID_User::PadState GetPadKey(HostDeviceKey key);
+Service::HID::PadState GetPadKey(HostDeviceKey key);
}
diff --git a/src/common/log.h b/src/common/log.h
deleted file mode 100644
index b397cf14d..000000000
--- a/src/common/log.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "common/common_funcs.h"
-#include "common/msg_handler.h"
-#include "common/logging/log.h"
-
-#ifdef _MSC_VER
-#ifndef __func__
-#define __func__ __FUNCTION__
-#endif
-#endif
-
-#ifdef _DEBUG
-#define _dbg_assert_(_t_, _a_) \
- if (!(_a_)) {\
- LOG_CRITICAL(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
- __LINE__, __FILE__, __TIME__); \
- if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \
- }
-#define _dbg_assert_msg_(_t_, _a_, ...)\
- if (!(_a_)) {\
- LOG_CRITICAL(_t_, __VA_ARGS__); \
- if (!PanicYesNo(__VA_ARGS__)) {Crash();} \
- }
-#define _dbg_update_() Host_UpdateLogDisplay();
-
-#else // not debug
-#define _dbg_update_() ;
-
-#ifndef _dbg_assert_
-#define _dbg_assert_(_t_, _a_) {}
-#define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
-#endif // dbg_assert
-#endif
-
-#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
-
-#ifndef GEKKO
-#ifdef _MSC_VER
-#define _assert_msg_(_t_, _a_, _fmt_, ...) \
- if (!(_a_)) {\
- if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \
- }
-#else // not msvc
-#define _assert_msg_(_t_, _a_, _fmt_, ...) \
- if (!(_a_)) {\
- if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
- }
-#endif // _WIN32
-#else // GEKKO
-#define _assert_msg_(_t_, _a_, _fmt_, ...)
-#endif \ No newline at end of file
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 83ebb42d9..8fee20a83 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -4,7 +4,7 @@
#include <algorithm>
-#include "common/log.h" // For _dbg_assert_
+#include "common/assert.h"
#include "common/logging/backend.h"
#include "common/logging/log.h"
@@ -37,6 +37,7 @@ static std::shared_ptr<Logger> global_logger;
SUB(Service, GSP) \
SUB(Service, AC) \
SUB(Service, PTM) \
+ SUB(Service, LDR) \
SUB(Service, CFG) \
SUB(Service, DSP) \
SUB(Service, HID) \
@@ -67,7 +68,7 @@ Logger::Logger() {
#undef SUB
// Ensures that ALL_LOG_CLASSES isn't missing any entries.
- _dbg_assert_(Log, all_classes.size() == (size_t)Class::Count);
+ DEBUG_ASSERT(all_classes.size() == (size_t)Class::Count);
}
// GetClassName is a macro defined by Windows.h, grrr...
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 3d94bf0d9..6c5ca3968 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -32,7 +32,7 @@ typedef u8 ClassType;
/**
* Specifies the sub-system that generated the log message.
*
- * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in log.cpp.
+ * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in backend.cpp.
*/
enum class Class : ClassType {
Log, ///< Messages about the log system itself
@@ -57,6 +57,7 @@ enum class Class : ClassType {
Service_GSP, ///< The GSP (GPU control) service
Service_AC, ///< The AC (WiFi status) service
Service_PTM, ///< The PTM (Power status & misc.) service
+ Service_LDR, ///< The LDR (3ds dll loader) service
Service_CFG, ///< The CFG (Configuration) service
Service_DSP, ///< The DSP (DSP control) service
Service_HID, ///< The HID (User input) service
diff --git a/src/common/mem_arena.cpp b/src/common/mem_arena.cpp
index a20361d6f..76c70701d 100644
--- a/src/common/mem_arena.cpp
+++ b/src/common/mem_arena.cpp
@@ -116,7 +116,7 @@ void MemArena::GrabLowMemSpace(size_t size)
GetSystemInfo(&sysInfo);
#elif defined(ANDROID)
// Use ashmem so we don't have to allocate a file on disk!
- fd = ashmem_create_region("PPSSPP_RAM", size);
+ fd = ashmem_create_region("Citra_RAM", size);
// Note that it appears that ashmem is pinned by default, so no need to pin.
if (fd < 0)
{
@@ -218,7 +218,7 @@ u8* MemArena::Find4GBBase()
void* base = mmap(0, 0x10000000, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_SHARED, -1, 0);
if (base == MAP_FAILED) {
- PanicAlert("Failed to map 256 MB of memory space: %s", strerror(errno));
+ LOG_ERROR(Common_Memory, "Failed to map 256 MB of memory space: %s", strerror(errno));
return 0;
}
munmap(base, 0x10000000);
@@ -338,7 +338,7 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
// address space.
if (!Memory_TryBase(base, views, num_views, flags, arena))
{
- PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
+ LOG_ERROR(Common_Memory, "MemoryMap_Setup: Failed finding a memory base.");
return 0;
}
#elif defined(_WIN32)
@@ -363,12 +363,11 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
if (!Memory_TryBase(base, views, num_views, flags, arena))
{
LOG_ERROR(Common_Memory, "MemoryMap_Setup: Failed finding a memory base.");
- PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
return 0;
}
#endif
if (base_attempts)
- PanicAlert("No possible memory base pointer found!");
+ LOG_ERROR(Common_Memory, "No possible memory base pointer found!");
return base;
}
diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp
index 8f982da89..7e69d31cb 100644
--- a/src/common/memory_util.cpp
+++ b/src/common/memory_util.cpp
@@ -56,7 +56,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
{
ptr = nullptr;
#endif
- PanicAlert("Failed to allocate executable memory");
+ LOG_ERROR(Common_Memory, "Failed to allocate executable memory");
}
#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
else
@@ -72,7 +72,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
#if defined(_M_X64)
if ((u64)ptr >= 0x80000000 && low == true)
- PanicAlert("Executable memory ended up above 2GB!");
+ LOG_ERROR(Common_Memory, "Executable memory ended up above 2GB!");
#endif
return ptr;
@@ -94,7 +94,7 @@ void* AllocateMemoryPages(size_t size)
// (unsigned long)size);
if (ptr == nullptr)
- PanicAlert("Failed to allocate raw memory");
+ LOG_ERROR(Common_Memory, "Failed to allocate raw memory");
return ptr;
}
@@ -117,7 +117,7 @@ void* AllocateAlignedMemory(size_t size,size_t alignment)
// (unsigned long)size);
if (ptr == nullptr)
- PanicAlert("Failed to allocate aligned memory");
+ LOG_ERROR(Common_Memory, "Failed to allocate aligned memory");
return ptr;
}
@@ -129,7 +129,7 @@ void FreeMemoryPages(void* ptr, size_t size)
#ifdef _WIN32
if (!VirtualFree(ptr, 0, MEM_RELEASE))
- PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
+ LOG_ERROR(Common_Memory, "FreeMemoryPages failed!\n%s", GetLastErrorMsg());
ptr = nullptr; // Is this our responsibility?
#else
@@ -155,7 +155,7 @@ void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
#ifdef _WIN32
DWORD oldValue;
if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
- PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
+ LOG_ERROR(Common_Memory, "WriteProtectMemory failed!\n%s", GetLastErrorMsg());
#else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
#endif
@@ -166,7 +166,7 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
#ifdef _WIN32
DWORD oldValue;
if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue))
- PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
+ LOG_ERROR(Common_Memory, "UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
#else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
#endif
diff --git a/src/common/msg_handler.cpp b/src/common/msg_handler.cpp
deleted file mode 100644
index 4a47b518e..000000000
--- a/src/common/msg_handler.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <cstdio>
-
-#include "common/common.h" // Local
-#include "common/string_util.h"
-
-bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style);
-static MsgAlertHandler msg_handler = DefaultMsgHandler;
-static bool AlertEnabled = true;
-
-std::string DefaultStringTranslator(const char* text);
-static StringTranslator str_translator = DefaultStringTranslator;
-
-// Select which of these functions that are used for message boxes. If
-// wxWidgets is enabled we will use wxMsgAlert() that is defined in Main.cpp
-void RegisterMsgAlertHandler(MsgAlertHandler handler)
-{
- msg_handler = handler;
-}
-
-// Select translation function. For wxWidgets use wxStringTranslator in Main.cpp
-void RegisterStringTranslator(StringTranslator translator)
-{
- str_translator = translator;
-}
-
-// enable/disable the alert handler
-void SetEnableAlert(bool enable)
-{
- AlertEnabled = enable;
-}
-
-// This is the first stop for gui alerts where the log is updated and the
-// correct window is shown
-bool MsgAlert(bool yes_no, int Style, const char* format, ...)
-{
- // Read message and write it to the log
- std::string caption;
- char buffer[2048];
-
- static std::string info_caption;
- static std::string warn_caption;
- static std::string ques_caption;
- static std::string crit_caption;
-
- if (!info_caption.length())
- {
- info_caption = str_translator(_trans("Information"));
- ques_caption = str_translator(_trans("Question"));
- warn_caption = str_translator(_trans("Warning"));
- crit_caption = str_translator(_trans("Critical"));
- }
-
- switch(Style)
- {
- case INFORMATION:
- caption = info_caption;
- break;
- case QUESTION:
- caption = ques_caption;
- break;
- case WARNING:
- caption = warn_caption;
- break;
- case CRITICAL:
- caption = crit_caption;
- break;
- }
-
- va_list args;
- va_start(args, format);
- Common::CharArrayFromFormatV(buffer, sizeof(buffer)-1, str_translator(format).c_str(), args);
- va_end(args);
-
- LOG_INFO(Common, "%s: %s", caption.c_str(), buffer);
-
- // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
- if (msg_handler && (AlertEnabled || Style == QUESTION || Style == CRITICAL))
- return msg_handler(caption.c_str(), buffer, yes_no, Style);
-
- return true;
-}
-
-// Default non library dependent panic alert
-bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style)
-{
-//#ifdef _WIN32
-// int STYLE = MB_ICONINFORMATION;
-// if (Style == QUESTION) STYLE = MB_ICONQUESTION;
-// if (Style == WARNING) STYLE = MB_ICONWARNING;
-//
-// return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));
-//#else
- printf("%s\n", text);
- return true;
-//#endif
-}
-
-// Default (non) translator
-std::string DefaultStringTranslator(const char* text)
-{
- return text;
-}
-
diff --git a/src/common/msg_handler.h b/src/common/msg_handler.h
deleted file mode 100644
index 5a483ddb4..000000000
--- a/src/common/msg_handler.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <string>
-
-// Message alerts
-enum MSG_TYPE
-{
- INFORMATION,
- QUESTION,
- WARNING,
- CRITICAL
-};
-
-typedef bool (*MsgAlertHandler)(const char* caption, const char* text,
- bool yes_no, int Style);
-typedef std::string (*StringTranslator)(const char* text);
-
-void RegisterMsgAlertHandler(MsgAlertHandler handler);
-void RegisterStringTranslator(StringTranslator translator);
-
-extern bool MsgAlert(bool yes_no, int Style, const char* format, ...)
-#ifdef __GNUC__
- __attribute__((format(printf, 3, 4)))
-#endif
- ;
-void SetEnableAlert(bool enable);
-
-#ifndef GEKKO
-#ifdef _MSC_VER
- #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__)
- #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__)
- #define PanicYesNo(format, ...) MsgAlert(true, WARNING, format, __VA_ARGS__)
- #define AskYesNo(format, ...) MsgAlert(true, QUESTION, format, __VA_ARGS__)
- #define CriticalAlert(format, ...) MsgAlert(false, CRITICAL, format, __VA_ARGS__)
- // Use these macros (that do the same thing) if the message should be translated.
- #define SuccessAlertT(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__)
- #define PanicAlertT(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__)
- #define PanicYesNoT(format, ...) MsgAlert(true, WARNING, format, __VA_ARGS__)
- #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, __VA_ARGS__)
- #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, __VA_ARGS__)
-#else
- #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, ##__VA_ARGS__)
- #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, ##__VA_ARGS__)
- #define PanicYesNo(format, ...) MsgAlert(true, WARNING, format, ##__VA_ARGS__)
- #define AskYesNo(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__)
- #define CriticalAlert(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__)
- // Use these macros (that do the same thing) if the message should be translated.
- #define SuccessAlertT(format, ...) MsgAlert(false, INFORMATION, format, ##__VA_ARGS__)
- #define PanicAlertT(format, ...) MsgAlert(false, WARNING, format, ##__VA_ARGS__)
- #define PanicYesNoT(format, ...) MsgAlert(true, WARNING, format, ##__VA_ARGS__)
- #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__)
- #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__)
-#endif
-#else
-// GEKKO
- #define SuccessAlert(format, ...) ;
- #define PanicAlert(format, ...) ;
- #define PanicYesNo(format, ...) ;
- #define AskYesNo(format, ...) ;
- #define CriticalAlert(format, ...) ;
- #define SuccessAlertT(format, ...) ;
- #define PanicAlertT(format, ...) ;
- #define PanicYesNoT(format, ...) ;
- #define AskYesNoT(format, ...) ;
- #define CriticalAlertT(format, ...) ;
-#endif
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h
index 263beaf0e..08f09a8c8 100644
--- a/src/common/scope_exit.h
+++ b/src/common/scope_exit.h
@@ -4,6 +4,9 @@
#pragma once
+#include "common/common_funcs.h"
+#include <utility>
+
namespace detail {
template <typename Func>
struct ScopeExitHelper {
@@ -34,4 +37,4 @@ namespace detail {
* }
* \endcode
*/
-#define SCOPE_EXIT(body) auto scope_exit_helper_##__LINE__ = detail::ScopeExit([&]() body)
+#define SCOPE_EXIT(body) auto CONCAT2(scope_exit_helper_, __LINE__) = detail::ScopeExit([&]() body)
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index b3b772bd9..3264dd51a 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -426,7 +426,7 @@ std::u16string UTF8ToUTF16(const std::string& input)
static std::string UTF16ToUTF8(const std::wstring& input)
{
- auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), nullptr, 0, nullptr, nullptr);
+ auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr);
std::string output;
output.resize(size);
@@ -439,12 +439,12 @@ static std::string UTF16ToUTF8(const std::wstring& input)
static std::wstring CPToUTF16(u32 code_page, const std::string& input)
{
- auto const size = MultiByteToWideChar(code_page, 0, input.data(), input.size(), nullptr, 0);
+ auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
std::wstring output;
output.resize(size);
- if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), input.size(), &output[0], output.size()))
+ if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size())))
output.clear();
return output;
diff --git a/src/common/symbols.cpp b/src/common/symbols.cpp
index 9e4dccfb3..f23e51c9d 100644
--- a/src/common/symbols.cpp
+++ b/src/common/symbols.cpp
@@ -54,4 +54,4 @@ namespace Symbols
{
g_symbols.clear();
}
-} \ No newline at end of file
+}
diff --git a/src/common/utf8.cpp b/src/common/utf8.cpp
deleted file mode 100644
index 66a2f6339..000000000
--- a/src/common/utf8.cpp
+++ /dev/null
@@ -1,459 +0,0 @@
-/*
- Basic UTF-8 manipulation routines
- by Jeff Bezanson
- placed in the public domain Fall 2005
-
- This code is designed to provide the utilities you need to manipulate
- UTF-8 as an internal string encoding. These functions do not perform the
- error checking normally needed when handling UTF-8 data, so if you happen
- to be from the Unicode Consortium you will want to flay me alive.
- I do this because error checking can be performed at the boundaries (I/O),
- with these routines reserved for higher performance on data known to be
- valid.
-*/
-
-#ifdef _WIN32
-#include <windows.h>
-#undef min
-#undef max
-#endif
-
-#include <cstdlib>
-#include <cstring>
-#include <algorithm>
-
-#include "common/common_types.h"
-#include "common/utf8.h"
-
-// is start of UTF sequence
-inline bool isutf(char c) {
- return (c & 0xC0) != 0x80;
-}
-
-static const u32 offsetsFromUTF8[6] = {
- 0x00000000UL, 0x00003080UL, 0x000E2080UL,
- 0x03C82080UL, 0xFA082080UL, 0x82082080UL
-};
-
-static const u8 trailingBytesForUTF8[256] = {
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,
-};
-
-/* returns length of next utf-8 sequence */
-int u8_seqlen(const char *s)
-{
- return trailingBytesForUTF8[(unsigned int)(unsigned char)s[0]] + 1;
-}
-
-/* conversions without error checking
- only works for valid UTF-8, i.e. no 5- or 6-byte sequences
- srcsz = source size in bytes, or -1 if 0-terminated
- sz = dest size in # of wide characters
-
- returns # characters converted
- dest will always be L'\0'-terminated, even if there isn't enough room
- for all the characters.
- if sz = srcsz+1 (i.e. 4*srcsz+4 bytes), there will always be enough space.
-*/
-int u8_toucs(u32 *dest, int sz, const char *src, int srcsz)
-{
- u32 ch;
- const char *src_end = src + srcsz;
- int nb;
- int i=0;
-
- while (i < sz-1) {
- nb = trailingBytesForUTF8[(unsigned char)*src];
- if (srcsz == -1) {
- if (*src == 0)
- goto done_toucs;
- }
- else {
- if (src + nb >= src_end)
- goto done_toucs;
- }
- ch = 0;
- switch (nb) {
- /* these fall through deliberately */
- case 3: ch += (unsigned char)*src++; ch <<= 6;
- case 2: ch += (unsigned char)*src++; ch <<= 6;
- case 1: ch += (unsigned char)*src++; ch <<= 6;
- case 0: ch += (unsigned char)*src++;
- }
- ch -= offsetsFromUTF8[nb];
- dest[i++] = ch;
- }
- done_toucs:
- dest[i] = 0;
- return i;
-}
-
-/* srcsz = number of source characters, or -1 if 0-terminated
- sz = size of dest buffer in bytes
-
- returns # characters converted
- dest will only be '\0'-terminated if there is enough space. this is
- for consistency; imagine there are 2 bytes of space left, but the next
- character requires 3 bytes. in this case we could NUL-terminate, but in
- general we can't when there's insufficient space. therefore this function
- only NUL-terminates if all the characters fit, and there's space for
- the NUL as well.
- the destination string will never be bigger than the source string.
-*/
-int u8_toutf8(char *dest, int sz, u32 *src, int srcsz)
-{
- u32 ch;
- int i = 0;
- char *dest_end = dest + sz;
-
- while (srcsz<0 ? src[i]!=0 : i < srcsz) {
- ch = src[i];
- if (ch < 0x80) {
- if (dest >= dest_end)
- return i;
- *dest++ = (char)ch;
- }
- else if (ch < 0x800) {
- if (dest >= dest_end-1)
- return i;
- *dest++ = (ch>>6) | 0xC0;
- *dest++ = (ch & 0x3F) | 0x80;
- }
- else if (ch < 0x10000) {
- if (dest >= dest_end-2)
- return i;
- *dest++ = (ch>>12) | 0xE0;
- *dest++ = ((ch>>6) & 0x3F) | 0x80;
- *dest++ = (ch & 0x3F) | 0x80;
- }
- else if (ch < 0x110000) {
- if (dest >= dest_end-3)
- return i;
- *dest++ = (ch>>18) | 0xF0;
- *dest++ = ((ch>>12) & 0x3F) | 0x80;
- *dest++ = ((ch>>6) & 0x3F) | 0x80;
- *dest++ = (ch & 0x3F) | 0x80;
- }
- i++;
- }
- if (dest < dest_end)
- *dest = '\0';
- return i;
-}
-
-int u8_wc_toutf8(char *dest, u32 ch)
-{
- if (ch < 0x80) {
- dest[0] = (char)ch;
- return 1;
- }
- if (ch < 0x800) {
- dest[0] = (ch>>6) | 0xC0;
- dest[1] = (ch & 0x3F) | 0x80;
- return 2;
- }
- if (ch < 0x10000) {
- dest[0] = (ch>>12) | 0xE0;
- dest[1] = ((ch>>6) & 0x3F) | 0x80;
- dest[2] = (ch & 0x3F) | 0x80;
- return 3;
- }
- if (ch < 0x110000) {
- dest[0] = (ch>>18) | 0xF0;
- dest[1] = ((ch>>12) & 0x3F) | 0x80;
- dest[2] = ((ch>>6) & 0x3F) | 0x80;
- dest[3] = (ch & 0x3F) | 0x80;
- return 4;
- }
- return 0;
-}
-
-/* charnum => byte offset */
-int u8_offset(const char *str, int charnum)
-{
- int offs=0;
-
- while (charnum > 0 && str[offs]) {
- (void)(isutf(str[++offs]) || isutf(str[++offs]) ||
- isutf(str[++offs]) || ++offs);
- charnum--;
- }
- return offs;
-}
-
-/* byte offset => charnum */
-int u8_charnum(const char *s, int offset)
-{
- int charnum = 0, offs=0;
-
- while (offs < offset && s[offs]) {
- (void)(isutf(s[++offs]) || isutf(s[++offs]) ||
- isutf(s[++offs]) || ++offs);
- charnum++;
- }
- return charnum;
-}
-
-/* number of characters */
-int u8_strlen(const char *s)
-{
- int count = 0;
- int i = 0;
-
- while (u8_nextchar(s, &i) != 0)
- count++;
-
- return count;
-}
-
-/* reads the next utf-8 sequence out of a string, updating an index */
-u32 u8_nextchar(const char *s, int *i)
-{
- u32 ch = 0;
- int sz = 0;
-
- do {
- ch <<= 6;
- ch += (unsigned char)s[(*i)++];
- sz++;
- } while (s[*i] && !isutf(s[*i]));
- ch -= offsetsFromUTF8[sz-1];
-
- return ch;
-}
-
-void u8_inc(const char *s, int *i)
-{
- (void)(isutf(s[++(*i)]) || isutf(s[++(*i)]) ||
- isutf(s[++(*i)]) || ++(*i));
-}
-
-void u8_dec(const char *s, int *i)
-{
- (void)(isutf(s[--(*i)]) || isutf(s[--(*i)]) ||
- isutf(s[--(*i)]) || --(*i));
-}
-
-int octal_digit(char c)
-{
- return (c >= '0' && c <= '7');
-}
-
-int hex_digit(char c)
-{
- return ((c >= '0' && c <= '9') ||
- (c >= 'A' && c <= 'F') ||
- (c >= 'a' && c <= 'f'));
-}
-
-/* assumes that src points to the character after a backslash
- returns number of input characters processed */
-int u8_read_escape_sequence(const char *str, u32 *dest)
-{
- u32 ch;
- char digs[9]="\0\0\0\0\0\0\0\0";
- int dno=0, i=1;
-
- ch = (u32)str[0]; /* take literal character */
- if (str[0] == 'n')
- ch = L'\n';
- else if (str[0] == 't')
- ch = L'\t';
- else if (str[0] == 'r')
- ch = L'\r';
- else if (str[0] == 'b')
- ch = L'\b';
- else if (str[0] == 'f')
- ch = L'\f';
- else if (str[0] == 'v')
- ch = L'\v';
- else if (str[0] == 'a')
- ch = L'\a';
- else if (octal_digit(str[0])) {
- i = 0;
- do {
- digs[dno++] = str[i++];
- } while (octal_digit(str[i]) && dno < 3);
- ch = strtol(digs, nullptr, 8);
- }
- else if (str[0] == 'x') {
- while (hex_digit(str[i]) && dno < 2) {
- digs[dno++] = str[i++];
- }
- if (dno > 0)
- ch = strtol(digs, nullptr, 16);
- }
- else if (str[0] == 'u') {
- while (hex_digit(str[i]) && dno < 4) {
- digs[dno++] = str[i++];
- }
- if (dno > 0)
- ch = strtol(digs, nullptr, 16);
- }
- else if (str[0] == 'U') {
- while (hex_digit(str[i]) && dno < 8) {
- digs[dno++] = str[i++];
- }
- if (dno > 0)
- ch = strtol(digs, nullptr, 16);
- }
- *dest = ch;
-
- return i;
-}
-
-/* convert a string with literal \uxxxx or \Uxxxxxxxx characters to UTF-8
- example: u8_unescape(mybuf, 256, "hello\\u220e")
- note the double backslash is needed if called on a C string literal */
-int u8_unescape(char *buf, int sz, char *src)
-{
- int c=0, amt;
- u32 ch;
- char temp[4];
-
- while (*src && c < sz) {
- if (*src == '\\') {
- src++;
- amt = u8_read_escape_sequence(src, &ch);
- }
- else {
- ch = (u32)*src;
- amt = 1;
- }
- src += amt;
- amt = u8_wc_toutf8(temp, ch);
- if (amt > sz-c)
- break;
- memcpy(&buf[c], temp, amt);
- c += amt;
- }
- if (c < sz)
- buf[c] = '\0';
- return c;
-}
-
-const char *u8_strchr(const char *s, u32 ch, int *charn)
-{
- int i = 0, lasti=0;
- u32 c;
-
- *charn = 0;
- while (s[i]) {
- c = u8_nextchar(s, &i);
- if (c == ch) {
- return &s[lasti];
- }
- lasti = i;
- (*charn)++;
- }
- return nullptr;
-}
-
-const char *u8_memchr(const char *s, u32 ch, size_t sz, int *charn)
-{
- u32 i = 0, lasti=0;
- u32 c;
- int csz;
-
- *charn = 0;
- while (i < sz) {
- c = csz = 0;
- do {
- c <<= 6;
- c += (unsigned char)s[i++];
- csz++;
- } while (i < sz && !isutf(s[i]));
- c -= offsetsFromUTF8[csz-1];
-
- if (c == ch) {
- return &s[lasti];
- }
- lasti = i;
- (*charn)++;
- }
- return nullptr;
-}
-
-int u8_is_locale_utf8(const char *locale)
-{
- /* this code based on libutf8 */
- const char* cp = locale;
-
- for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++) {
- if (*cp == '.') {
- const char* encoding = ++cp;
- for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++)
- ;
- if ((cp-encoding == 5 && !strncmp(encoding, "UTF-8", 5))
- || (cp-encoding == 4 && !strncmp(encoding, "utf8", 4)))
- return 1; /* it's UTF-8 */
- break;
- }
- }
- return 0;
-}
-
-int UTF8StringNonASCIICount(const char *utf8string) {
- UTF8 utf(utf8string);
- int count = 0;
- while (!utf.end()) {
- int c = utf.next();
- if (c > 127)
- ++count;
- }
- return count;
-}
-
-bool UTF8StringHasNonASCII(const char *utf8string) {
- return UTF8StringNonASCIICount(utf8string) > 0;
-}
-
-#ifdef _WIN32
-
-std::string ConvertWStringToUTF8(const wchar_t *wstr) {
- int len = (int)wcslen(wstr);
- int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr, len, 0, 0, nullptr, nullptr);
- std::string s;
- s.resize(size);
- if (size > 0) {
- WideCharToMultiByte(CP_UTF8, 0, wstr, len, &s[0], size, nullptr, nullptr);
- }
- return s;
-}
-
-std::string ConvertWStringToUTF8(const std::wstring &wstr) {
- int len = (int)wstr.size();
- int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, 0, 0, nullptr, nullptr);
- std::string s;
- s.resize(size);
- if (size > 0) {
- WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, &s[0], size, nullptr, nullptr);
- }
- return s;
-}
-
-void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source) {
- int len = (int)source.size();
- int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, nullptr, 0);
- MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, dest, std::min((int)destSize, size));
-}
-
-std::wstring ConvertUTF8ToWString(const std::string &source) {
- int len = (int)source.size();
- int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, nullptr, 0);
- std::wstring str;
- str.resize(size);
- if (size > 0) {
- MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, &str[0], size);
- }
- return str;
-}
-
-#endif \ No newline at end of file
diff --git a/src/common/utf8.h b/src/common/utf8.h
deleted file mode 100644
index 6479ec5ad..000000000
--- a/src/common/utf8.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- Basic UTF-8 manipulation routines
- by Jeff Bezanson
- placed in the public domain Fall 2005
-
- This code is designed to provide the utilities you need to manipulate
- UTF-8 as an internal string encoding. These functions do not perform the
- error checking normally needed when handling UTF-8 data, so if you happen
- to be from the Unicode Consortium you will want to flay me alive.
- I do this because error checking can be performed at the boundaries (I/O),
- with these routines reserved for higher performance on data known to be
- valid.
-*/
-
-// Further modified, and C++ stuff added, by hrydgard@gmail.com.
-
-#pragma once
-
-#include "common/common_types.h"
-#include <string>
-
-u32 u8_nextchar(const char *s, int *i);
-int u8_wc_toutf8(char *dest, u32 ch);
-int u8_strlen(const char *s);
-
-class UTF8 {
-public:
- static const u32 INVALID = (u32)-1;
- UTF8(const char *c) : c_(c), index_(0) {}
- bool end() const { return c_[index_] == 0; }
- u32 next() {
- return u8_nextchar(c_, &index_);
- }
- u32 peek() {
- int tempIndex = index_;
- return u8_nextchar(c_, &tempIndex);
- }
- int length() const {
- return u8_strlen(c_);
- }
- int byteIndex() const {
- return index_;
- }
- static int encode(char *dest, u32 ch) {
- return u8_wc_toutf8(dest, ch);
- }
-
-private:
- const char *c_;
- int index_;
-};
-
-int UTF8StringNonASCIICount(const char *utf8string);
-
-bool UTF8StringHasNonASCII(const char *utf8string);
-
-
-// UTF8 to Win32 UTF-16
-// Should be used when calling Win32 api calls
-#ifdef _WIN32
-
-std::string ConvertWStringToUTF8(const std::wstring &wstr);
-std::string ConvertWStringToUTF8(const wchar_t *wstr);
-void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source);
-std::wstring ConvertUTF8ToWString(const std::string &source);
-
-#endif \ No newline at end of file