Cleanup: Convert winfunc and utfconv to C++
Basically, the intern/utfconv directory, as well as users of these headers. Pull Request: https://projects.blender.org/blender/blender/pulls/113901
This commit is contained in:
parent
85c557ffa2
commit
21c8af467d
8
extern/wcwidth/wcwidth.h
vendored
8
extern/wcwidth/wcwidth.h
vendored
@ -30,9 +30,17 @@ typedef unsigned int char32_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int mk_wcwidth(char32_t ucs);
|
||||
int mk_wcswidth(const char32_t *pwcs, size_t n);
|
||||
int mk_wcwidth_cjk(char32_t ucs);
|
||||
int mk_wcswidth_cjk(const char32_t *pwcs, size_t n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -10,8 +10,8 @@
|
||||
#include "GHOST_Debug.hh"
|
||||
#include <shellapi.h>
|
||||
|
||||
#include "utf_winfunc.h"
|
||||
#include "utfconv.h"
|
||||
#include "utf_winfunc.hh"
|
||||
#include "utfconv.hh"
|
||||
|
||||
#ifdef WITH_GHOST_DEBUG
|
||||
/* utility */
|
||||
|
@ -11,7 +11,7 @@
|
||||
# include "GHOST_ImeWin32.hh"
|
||||
# include "GHOST_C-api.h"
|
||||
# include "GHOST_WindowWin32.hh"
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
|
||||
/* ISO_639-1 2-Letter Abbreviations. */
|
||||
# define IMELANG_ENGLISH "en"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#ifndef _WIN32_IE
|
||||
# define _WIN32_IE 0x0501
|
||||
#endif
|
||||
#include "utfconv.h"
|
||||
#include "utfconv.hh"
|
||||
#include <shlobj.h>
|
||||
|
||||
GHOST_SystemPathsWin32::GHOST_SystemPathsWin32() {}
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include <tlhelp32.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include "utf_winfunc.h"
|
||||
#include "utfconv.h"
|
||||
#include "utf_winfunc.hh"
|
||||
#include "utfconv.hh"
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include "GHOST_DropTargetWin32.hh"
|
||||
#include "GHOST_SystemWin32.hh"
|
||||
#include "GHOST_WindowManager.hh"
|
||||
#include "utf_winfunc.h"
|
||||
#include "utfconv.h"
|
||||
#include "utf_winfunc.hh"
|
||||
#include "utfconv.hh"
|
||||
|
||||
#ifdef WITH_OPENGL_BACKEND
|
||||
# include "GHOST_ContextWGL.hh"
|
||||
|
@ -11,9 +11,9 @@ set(INC_SYS
|
||||
)
|
||||
|
||||
set(SRC
|
||||
utfconv.c
|
||||
utfconv.cc
|
||||
|
||||
utfconv.h
|
||||
utfconv.hh
|
||||
)
|
||||
|
||||
set(LIB
|
||||
@ -24,8 +24,8 @@ set(LIB
|
||||
# ... because one day we might want to use it on other platforms.
|
||||
if(WIN32)
|
||||
list(APPEND SRC
|
||||
utf_winfunc.c
|
||||
utf_winfunc.h
|
||||
utf_winfunc.cc
|
||||
utf_winfunc.hh
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -10,8 +10,8 @@
|
||||
# define _WIN32_IE 0x0501
|
||||
#endif
|
||||
|
||||
#include "utf_winfunc.h"
|
||||
#include "utfconv.h"
|
||||
#include "utf_winfunc.hh"
|
||||
#include "utfconv.hh"
|
||||
#include <io.h>
|
||||
#include <wchar.h>
|
||||
#include <windows.h>
|
@ -6,7 +6,7 @@
|
||||
* \ingroup intern_utf_conv
|
||||
*/
|
||||
|
||||
#include "utfconv.h"
|
||||
#include "utfconv.hh"
|
||||
|
||||
size_t count_utf_8_from_16(const wchar_t *string16)
|
||||
{
|
@ -13,10 +13,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Counts how many bytes is required for future utf-8 string using utf-16
|
||||
* \param string16: pointer to working utf-16 string
|
||||
@ -90,8 +86,4 @@ wchar_t *alloc_utf16_from_8(const char *in8, size_t add);
|
||||
} \
|
||||
(void)0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __UTFCONV_H__ */
|
@ -34,8 +34,8 @@
|
||||
#include "CLG_log.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utf_winfunc.h"
|
||||
# include "utfconv.h"
|
||||
# include "utf_winfunc.hh"
|
||||
# include "utfconv.hh"
|
||||
# include <io.h>
|
||||
# ifdef _WIN32_IE
|
||||
# undef _WIN32_IE
|
||||
|
@ -61,7 +61,7 @@ set(SRC
|
||||
intern/cpp_types.cc
|
||||
intern/delaunay_2d.cc
|
||||
intern/dot_export.cc
|
||||
intern/dynlib.c
|
||||
intern/dynlib.cc
|
||||
intern/easing.c
|
||||
intern/endian_switch.c
|
||||
intern/expr_pylike_eval.c
|
||||
@ -136,12 +136,12 @@ set(SRC
|
||||
intern/sort.c
|
||||
intern/sort_utils.c
|
||||
intern/stack.c
|
||||
intern/storage.c
|
||||
intern/storage.cc
|
||||
intern/string.c
|
||||
intern/string_cursor_utf8.c
|
||||
intern/string_ref.cc
|
||||
intern/string_search.cc
|
||||
intern/string_utf8.c
|
||||
intern/string_utf8.cc
|
||||
intern/string_utils.cc
|
||||
intern/system.c
|
||||
intern/task_graph.cc
|
||||
@ -160,8 +160,8 @@ set(SRC
|
||||
intern/virtual_array.cc
|
||||
intern/voronoi_2d.c
|
||||
intern/voxel.c
|
||||
intern/winstuff.c
|
||||
intern/winstuff_dir.c
|
||||
intern/winstuff.cc
|
||||
intern/winstuff_dir.cc
|
||||
|
||||
# Private headers.
|
||||
intern/BLI_mempool_private.h
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#ifdef WIN32
|
||||
# include "BLI_winstuff.h"
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
|
@ -20,8 +20,8 @@ struct DynamicLibrary {
|
||||
|
||||
#ifdef WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include "utf_winfunc.h"
|
||||
# include "utfconv.h"
|
||||
# include "utf_winfunc.hh"
|
||||
# include "utfconv.hh"
|
||||
# include <windows.h>
|
||||
|
||||
DynamicLibrary *BLI_dynlib_open(const char *name)
|
||||
@ -37,7 +37,7 @@ DynamicLibrary *BLI_dynlib_open(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lib = MEM_callocN(sizeof(*lib), "Dynamic Library");
|
||||
lib = MEM_cnew<DynamicLibrary>("Dynamic Library");
|
||||
lib->handle = handle;
|
||||
|
||||
return lib;
|
||||
@ -45,7 +45,7 @@ DynamicLibrary *BLI_dynlib_open(const char *name)
|
||||
|
||||
void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
|
||||
{
|
||||
return GetProcAddress(lib->handle, symname);
|
||||
return GetProcAddress(HMODULE(lib->handle), symname);
|
||||
}
|
||||
|
||||
char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
|
||||
@ -78,7 +78,7 @@ char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
|
||||
|
||||
void BLI_dynlib_close(DynamicLibrary *lib)
|
||||
{
|
||||
FreeLibrary(lib->handle);
|
||||
FreeLibrary(HMODULE(lib->handle));
|
||||
MEM_freeN(lib);
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ DynamicLibrary *BLI_dynlib_open(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lib = MEM_callocN(sizeof(*lib), "Dynamic Library");
|
||||
lib = MEM_cnew<DynamicLibrary>("Dynamic Library");
|
||||
lib->handle = handle;
|
||||
|
||||
return lib;
|
@ -9,7 +9,7 @@
|
||||
#include "BLI_fileops.hh"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
#endif
|
||||
|
||||
namespace blender {
|
||||
|
@ -21,8 +21,8 @@
|
||||
#ifdef WIN32
|
||||
# include "BLI_fileops_types.h"
|
||||
# include "BLI_winstuff.h"
|
||||
# include "utf_winfunc.h"
|
||||
# include "utfconv.h"
|
||||
# include "utf_winfunc.hh"
|
||||
# include "utfconv.hh"
|
||||
# include <io.h>
|
||||
# include <shellapi.h>
|
||||
# include <shobjidl.h>
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utf_winfunc.h"
|
||||
# include "utfconv.h"
|
||||
# include "utf_winfunc.hh"
|
||||
# include "utfconv.hh"
|
||||
# include <io.h>
|
||||
# ifdef _WIN32_IE
|
||||
# undef _WIN32_IE
|
||||
|
@ -37,7 +37,7 @@
|
||||
#ifdef WIN32
|
||||
# include "BLI_string_utf8.h"
|
||||
# include "BLI_winstuff.h"
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
# include <ShObjIdl.h>
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
@ -235,14 +235,14 @@ eFileAttributes BLI_file_attributes(const char *path)
|
||||
|
||||
WCHAR wline[FILE_MAXDIR];
|
||||
if (conv_utf_8_to_16(path, wline, ARRAY_SIZE(wline)) != 0) {
|
||||
return ret;
|
||||
return eFileAttributes(ret);
|
||||
}
|
||||
|
||||
DWORD attr = GetFileAttributesW(wline);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES) {
|
||||
BLI_assert_msg(GetLastError() != ERROR_FILE_NOT_FOUND,
|
||||
"BLI_file_attributes should only be called on existing files.");
|
||||
return ret;
|
||||
return eFileAttributes(ret);
|
||||
}
|
||||
|
||||
if (attr & FILE_ATTRIBUTE_READONLY) {
|
||||
@ -287,7 +287,7 @@ eFileAttributes BLI_file_attributes(const char *path)
|
||||
* If Archived set FILE_ATTR_ARCHIVE
|
||||
*/
|
||||
# endif
|
||||
return ret;
|
||||
return eFileAttributes(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -311,30 +311,30 @@ bool BLI_file_alias_target(const char *filepath,
|
||||
|
||||
IShellLinkW *Shortcut = NULL;
|
||||
hr = CoCreateInstance(
|
||||
&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID *)&Shortcut);
|
||||
CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID *)&Shortcut);
|
||||
|
||||
bool success = false;
|
||||
if (SUCCEEDED(hr)) {
|
||||
IPersistFile *PersistFile;
|
||||
hr = Shortcut->lpVtbl->QueryInterface(Shortcut, &IID_IPersistFile, (LPVOID *)&PersistFile);
|
||||
hr = Shortcut->QueryInterface(IID_IPersistFile, (LPVOID *)&PersistFile);
|
||||
if (SUCCEEDED(hr)) {
|
||||
WCHAR path_utf16[FILE_MAXDIR] = {0};
|
||||
if (conv_utf_8_to_16(filepath, path_utf16, ARRAY_SIZE(path_utf16)) == 0) {
|
||||
hr = PersistFile->lpVtbl->Load(PersistFile, path_utf16, STGM_READ);
|
||||
hr = PersistFile->Load(path_utf16, STGM_READ);
|
||||
if (SUCCEEDED(hr)) {
|
||||
hr = Shortcut->lpVtbl->Resolve(Shortcut, 0, SLR_NO_UI | SLR_UPDATE);
|
||||
hr = Shortcut->Resolve(0, SLR_NO_UI | SLR_UPDATE);
|
||||
if (SUCCEEDED(hr)) {
|
||||
wchar_t target_utf16[FILE_MAXDIR] = {0};
|
||||
hr = Shortcut->lpVtbl->GetPath(Shortcut, target_utf16, FILE_MAXDIR, NULL, 0);
|
||||
hr = Shortcut->GetPath(target_utf16, FILE_MAXDIR, NULL, 0);
|
||||
if (SUCCEEDED(hr)) {
|
||||
success = (conv_utf_16_to_8(target_utf16, r_targetpath, FILE_MAXDIR) == 0);
|
||||
}
|
||||
}
|
||||
PersistFile->lpVtbl->Release(PersistFile);
|
||||
PersistFile->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Shortcut->lpVtbl->Release(Shortcut);
|
||||
Shortcut->Release();
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
@ -526,14 +526,14 @@ void *BLI_file_read_text_as_mem_with_newline_as_nil(const char *filepath,
|
||||
size_t pad_bytes,
|
||||
size_t *r_size)
|
||||
{
|
||||
char *mem = BLI_file_read_text_as_mem(filepath, pad_bytes, r_size);
|
||||
char *mem = static_cast<char *>(BLI_file_read_text_as_mem(filepath, pad_bytes, r_size));
|
||||
if (mem != NULL) {
|
||||
char *mem_end = mem + *r_size;
|
||||
if (pad_bytes != 0) {
|
||||
*mem_end = '\0';
|
||||
}
|
||||
for (char *p = mem, *p_next; p != mem_end; p = p_next) {
|
||||
p_next = memchr(p, '\n', mem_end - p);
|
||||
p_next = static_cast<char *>(memchr(p, '\n', mem_end - p));
|
||||
if (p_next != NULL) {
|
||||
if (trim_trailing_space) {
|
||||
for (char *p_trim = p_next - 1; p_trim > p && ELEM(*p_trim, ' ', '\t'); p_trim--) {
|
||||
@ -571,7 +571,7 @@ LinkNode *BLI_file_read_as_lines(const char *filepath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = MEM_mallocN(size, "file_as_lines");
|
||||
buf = MEM_cnew_array<char>(size, "file_as_lines");
|
||||
if (buf) {
|
||||
size_t i, last = 0;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "BLI_string.h" /* #BLI_string_debug_size. */
|
||||
#include "BLI_string_utf8.h" /* own include */
|
||||
#ifdef WIN32
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic error "-Wsign-conversion"
|
||||
@ -598,10 +598,10 @@ char32_t BLI_str_utf32_char_to_upper(const char32_t wc)
|
||||
|
||||
if (wc >= from[0] && wc <= from[ARRAY_SIZE(from) - 2]) {
|
||||
/* Binary search since these are sorted. */
|
||||
int min = 0;
|
||||
int max = ARRAY_SIZE(from) - 2;
|
||||
size_t min = 0;
|
||||
size_t max = ARRAY_SIZE(from) - 2;
|
||||
while (max >= min) {
|
||||
const int mid = (min + max) / 2;
|
||||
const size_t mid = (min + max) / 2;
|
||||
if (wc > from[mid]) {
|
||||
min = mid + 1;
|
||||
}
|
||||
@ -704,10 +704,10 @@ char32_t BLI_str_utf32_char_to_lower(const char32_t wc)
|
||||
|
||||
if (wc >= from[0] && wc <= from[ARRAY_SIZE(from) - 2]) {
|
||||
/* Binary search since these are sorted. */
|
||||
int min = 0;
|
||||
int max = ARRAY_SIZE(from) - 2;
|
||||
size_t min = 0;
|
||||
size_t max = ARRAY_SIZE(from) - 2;
|
||||
while (max >= min) {
|
||||
const int mid = (min + max) / 2;
|
||||
const size_t mid = (min + max) / 2;
|
||||
if (wc > from[mid]) {
|
||||
min = mid + 1;
|
||||
}
|
@ -23,8 +23,8 @@
|
||||
# include "BLI_utildefines.h"
|
||||
# include "BLI_winstuff.h"
|
||||
|
||||
# include "utf_winfunc.h"
|
||||
# include "utfconv.h"
|
||||
# include "utf_winfunc.hh"
|
||||
# include "utfconv.hh"
|
||||
|
||||
/* FILE_MAXDIR + FILE_MAXFILE */
|
||||
|
@ -23,7 +23,7 @@
|
||||
# define WIN32_SKIP_HKEY_PROTECTION /* Need to use `HKEY`. */
|
||||
# include "BLI_utildefines.h"
|
||||
# include "BLI_winstuff.h"
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
|
||||
# define PATH_SUFFIX "\\*"
|
||||
# define PATH_SUFFIX_LEN 2
|
||||
@ -58,7 +58,7 @@ DIR *opendir(const char *path)
|
||||
if ((GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||
((path_len = strlen(path)) < (sizeof(newd->path) - PATH_SUFFIX_LEN)))
|
||||
{
|
||||
newd = MEM_mallocN(sizeof(DIR), "opendir");
|
||||
newd = static_cast<DIR *>(MEM_mallocN(sizeof(DIR), "opendir"));
|
||||
newd->handle = INVALID_HANDLE_VALUE;
|
||||
memcpy(newd->path, path, path_len);
|
||||
memcpy(newd->path + path_len, PATH_SUFFIX, PATH_SUFFIX_LEN + 1);
|
@ -28,12 +28,12 @@ if(NOT WITH_HEADLESS)
|
||||
../../../intern/utfconv
|
||||
)
|
||||
|
||||
# for winstuff_dir.c
|
||||
# for winstuff_dir.cc
|
||||
add_definitions(-DUSE_STANDALONE)
|
||||
|
||||
list(APPEND SRC
|
||||
../blenlib/intern/winstuff_dir.c
|
||||
../../../intern/utfconv/utfconv.c
|
||||
../blenlib/intern/winstuff_dir.cc
|
||||
../../../intern/utfconv/utfconv.cc
|
||||
)
|
||||
|
||||
endif()
|
||||
|
@ -66,7 +66,7 @@
|
||||
#include <openexr_api.h>
|
||||
|
||||
#if defined(WIN32)
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
|
@ -47,7 +47,7 @@
|
||||
/* For SHGetSpecialFolderPath, has to be done before BLI_winstuff
|
||||
* because 'near' is disabled through BLI_windstuff */
|
||||
# include "BLI_winstuff.h"
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
# include <direct.h> /* #chdir */
|
||||
# include <shlobj.h>
|
||||
#endif
|
||||
|
@ -19,7 +19,7 @@
|
||||
# include "BLI_path_util.h"
|
||||
# include "BLI_string.h"
|
||||
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
#endif
|
||||
|
||||
namespace blender::io::alembic {
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "BLI_string.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "ED_view3d.hh"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
#endif
|
||||
|
||||
#include "UI_view2d.hh"
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "ED_view3d.hh"
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
#endif
|
||||
|
||||
#include "UI_view2d.hh"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
# include "utfconv.h"
|
||||
# include "utfconv.hh"
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user