From a543da85ff2a39bfdc84b98ebd486b10a79ff9a7 Mon Sep 17 00:00:00 2001 From: jmdejong Date: Sun, 6 Jan 2019 20:41:40 +0100 Subject: [PATCH 01/25] Fix simple_exec's waitpid error When SIGCHLD is ignored (the default) then waitpid will always return error (-1) on linux. This caused the assertion to fail even when everything is working correctly. This change adds an empty SIGCHLD handler so waitpid will give a useful result. At the end the previous handler is restored. --- src/simple_exec.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/simple_exec.h b/src/simple_exec.h index b85327b..8d9ca0d 100644 --- a/src/simple_exec.h +++ b/src/simple_exec.h @@ -27,6 +27,7 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in #include #include #include +#include #define release_assert(x) do { int __release_assert_tmp__ = (x); assert(__release_assert_tmp__); } while(0) @@ -42,6 +43,8 @@ enum RUN_COMMAND_ERROR COMMAND_NOT_FOUND = 1 }; +void sigchldHandler(int p){} + int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* const* allArgs) { // adapted from: https://stackoverflow.com/a/479103 @@ -64,6 +67,9 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in int errPipe[2]; release_assert(pipe(errPipe) == 0); + void (*prev_handler)(int); + prevHandler = signal(SIGCHLD, sigchldHandler); + pid_t pid; switch( pid = fork() ) { @@ -174,6 +180,7 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in } } } + signal(SIGCHLD, prevHandler); } int runCommand(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* command, ...) From b58794ccdb0050f5e1dae7a5f08df7e0ee3b7978 Mon Sep 17 00:00:00 2001 From: Michael Labbe Date: Mon, 30 Sep 2019 12:51:21 -0700 Subject: [PATCH 02/25] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..f165585 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,32 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Compilation Environment** + + - OS (eg: OSX 10.14, Ubuntu 18.04): + - Compiler (eg: GCC, Clang): + - Compiler Version (eg: MSVC 2017): + - Build directory used (eg: `build/gmake_linux`: + - Have I attempted to reproduce the problem on the `devel` branch? + +**Describe the bug** + +_A clear and concise description of what the bug is._ + +**Compilation output** + +_If compiling with a makefile, paste the output of `make verbose=1` which includes Makefile steps._ + +**Additional context** + +_Add any other context about the problem here._ + +**User Description** + +_Are you using NFD as an individual, a small company (less than ten employees) or a larger organization? From ad0b798aed98db601a59133d0a1e6ab1963bbe82 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Sat, 28 Mar 2020 00:34:34 +0100 Subject: [PATCH 03/25] Fix CopyNFDCharToWChar() (called by SetDefaultPath()) asserting on Windows when given non ASCII path due to incorrect length computed by NFDi_UTF8_Strlen(). Caused by NFDi_UTF8_Strlen() relying on right shifting negative value, which is implementation defined behavior. The issue was fixed by casting to a unsigned value before shifting. --- src/nfd_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nfd_common.c b/src/nfd_common.c index 55517f5..a5c02b7 100644 --- a/src/nfd_common.c +++ b/src/nfd_common.c @@ -100,6 +100,7 @@ int32_t NFDi_UTF8_Strlen( const nfdchar_t *str ) int32_t character_count = 0; int32_t i = 0; /* Counter used to iterate over string. */ nfdchar_t maybe_bom[4]; + unsigned char c; /* If there is UTF-8 BOM ignore it. */ if (strlen(str) > 2) @@ -112,17 +113,18 @@ int32_t NFDi_UTF8_Strlen( const nfdchar_t *str ) while(str[i]) { - if (str[i] >> 7 == 0) + c = (unsigned char)str[i]; + if (c >> 7 == 0) { /* If bit pattern begins with 0 we have ascii character. */ ++character_count; } - else if (str[i] >> 6 == 3) + else if (c >> 6 == 3) { /* If bit pattern begins with 11 it is beginning of UTF-8 byte sequence. */ ++character_count; } - else if (str[i] >> 6 == 2) + else if (c >> 6 == 2) ; /* If bit pattern begins with 10 it is middle of utf-8 byte sequence. */ else { From 189710cdd9cc5eb6b31dbac97ca5748949662b58 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 10 Nov 2020 09:23:13 +0100 Subject: [PATCH 04/25] Source files using relative path allow compiling without extra include paths. --- src/nfd_cocoa.m | 2 +- src/nfd_common.h | 2 +- src/nfd_gtk.c | 2 +- src/nfd_zenity.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nfd_cocoa.m b/src/nfd_cocoa.m index 776152d..6ca20ec 100644 --- a/src/nfd_cocoa.m +++ b/src/nfd_cocoa.m @@ -5,7 +5,7 @@ */ #include -#include "nfd.h" +#include "include/nfd.h" #include "nfd_common.h" static NSArray *BuildAllowedFileTypes( const char *filterList ) diff --git a/src/nfd_common.h b/src/nfd_common.h index 1a9ab16..24aed68 100644 --- a/src/nfd_common.h +++ b/src/nfd_common.h @@ -10,7 +10,7 @@ #ifndef _NFD_COMMON_H #define _NFD_COMMON_H -#include "nfd.h" +#include "include/nfd.h" #include diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index 7a9958e..ea3c70d 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -8,7 +8,7 @@ #include #include #include -#include "nfd.h" +#include "include/nfd.h" #include "nfd_common.h" diff --git a/src/nfd_zenity.c b/src/nfd_zenity.c index 5f93133..f799816 100644 --- a/src/nfd_zenity.c +++ b/src/nfd_zenity.c @@ -7,7 +7,7 @@ #include #include #include -#include "nfd.h" +#include "include/nfd.h" #include "nfd_common.h" #define SIMPLE_EXEC_IMPLEMENTATION From 8b9b803250ac12d607076a6bcb92fef3c326de5e Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 10 Nov 2020 09:39:24 +0100 Subject: [PATCH 05/25] Disable warning using strncat() with vs2019 (somehow didn't get it with vs2015) --- src/nfd_common.c | 5 +++++ src/nfd_win.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/nfd_common.c b/src/nfd_common.c index 55517f5..d82d514 100644 --- a/src/nfd_common.c +++ b/src/nfd_common.c @@ -4,6 +4,11 @@ http://www.frogtoss.com/labs */ + // Disable warning using strncat() +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + #include #include #include diff --git a/src/nfd_win.cpp b/src/nfd_win.cpp index 949da2b..6b8417c 100644 --- a/src/nfd_win.cpp +++ b/src/nfd_win.cpp @@ -11,6 +11,10 @@ #define _WIN32_WINNT _WIN32_WINNT_VISTA #endif +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS +#endif + #define _CRTDBG_MAP_ALLOC #include #include From 7286ab25dde2176596f6b41d58670e2373a6d975 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Sun, 29 Nov 2020 11:27:34 +0100 Subject: [PATCH 06/25] GTK: Work around X11 focus issue (Fixes #79) Ported fix by Matt Borgerson (@mborgerson) from https://github.com/guillaumechereau/noc/pull/11 --- src/nfd_gtk.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index 7a9958e..df830d2 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -8,6 +8,9 @@ #include #include #include +#if defined(GDK_WINDOWING_X11) +#include +#endif /* defined(GDK_WINDOWING_X11) */ #include "nfd.h" #include "nfd_common.h" @@ -191,6 +194,16 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, /* Set the default path */ SetDefaultPath(dialog, defaultPath); +#if defined(GDK_WINDOWING_X11) + /* Work around focus issue on X11 (https://github.com/mlabbe/nativefiledialog/issues/79) */ + gtk_widget_show_all(dialog); + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + GdkWindow *window = gtk_widget_get_window(dialog); + gdk_window_set_events(window, gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK); + gtk_window_present_with_time(GTK_WINDOW(dialog), gdk_x11_get_server_time(window)); + } +#endif /* defined(GDK_WINDOWING_X11) */ + result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) { From a1bb9d1490f9f3d131983751151798d38d430b94 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Sun, 29 Nov 2020 18:55:25 +0100 Subject: [PATCH 07/25] Gtk: Apply focus fix to all dialog variants --- src/nfd_gtk.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index df830d2..48cb3dd 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -165,6 +165,19 @@ static void WaitForCleanup(void) while (gtk_events_pending()) gtk_main_iteration(); } + +static void ConfigureFocus(GtkWidget *dialog) +{ +#if defined(GDK_WINDOWING_X11) + /* Work around focus issue on X11 (https://github.com/mlabbe/nativefiledialog/issues/79) */ + gtk_widget_show_all(dialog); + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + GdkWindow *window = gtk_widget_get_window(dialog); + gdk_window_set_events(window, gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK); + gtk_window_present_with_time(GTK_WINDOW(dialog), gdk_x11_get_server_time(window)); + } +#endif /* defined(GDK_WINDOWING_X11) */ +} /* public */ @@ -194,15 +207,7 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, /* Set the default path */ SetDefaultPath(dialog, defaultPath); -#if defined(GDK_WINDOWING_X11) - /* Work around focus issue on X11 (https://github.com/mlabbe/nativefiledialog/issues/79) */ - gtk_widget_show_all(dialog); - if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { - GdkWindow *window = gtk_widget_get_window(dialog); - gdk_window_set_events(window, gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK); - gtk_window_present_with_time(GTK_WINDOW(dialog), gdk_x11_get_server_time(window)); - } -#endif /* defined(GDK_WINDOWING_X11) */ + ConfigureFocus(dialog); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) @@ -262,6 +267,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, /* Set the default path */ SetDefaultPath(dialog, defaultPath); + ConfigureFocus(dialog); + result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) { @@ -308,6 +315,8 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, /* Set the default path */ SetDefaultPath(dialog, defaultPath); + + ConfigureFocus(dialog); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) @@ -361,6 +370,8 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, /* Set the default path */ SetDefaultPath(dialog, defaultPath); + + ConfigureFocus(dialog); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) From d7ec5cdb1fa1700fc9921bf16eeff2c49358c3a8 Mon Sep 17 00:00:00 2001 From: Michael Labbe Date: Thu, 7 Jan 2021 12:13:43 -0800 Subject: [PATCH 08/25] win32 support for filenames in default paths --- src/ftg_core.h | 2960 ++++++++++++++++++++++++++++++++++++++++++++++ src/nfd_common.c | 21 + src/nfd_common.h | 2 +- src/nfd_win.cpp | 90 +- 4 files changed, 3043 insertions(+), 30 deletions(-) create mode 100644 src/ftg_core.h diff --git a/src/ftg_core.h b/src/ftg_core.h new file mode 100644 index 0000000..e1cceee --- /dev/null +++ b/src/ftg_core.h @@ -0,0 +1,2960 @@ +/* ftg_core.h - v0.5 - Frogtoss Toolbox. Public domain-like license below. + + ftg libraries are copyright (C) 2015 Frogtoss Games, Inc. + http://github.com/mlabbe/ftg_toolbox + + ftg header files are single file header files intended to be useful + in C/C++. ftg_core contains generally useful functions + + Special thanks to STB for the inspiration. + + + **** + You must + + #define FTG_IMPLEMENT_CORE + + in exactly one C or C++ file. + **** + + If _DEBUG is defined, assert behaviors change. + + OPTIONS + + 1. define FTG_ENABLE_ASSERT to enable FTG_ASSERT and related macros. + 2. define FTG_ENABLE_STOPWATCH to enable code timing stopwatch macros. + 3. See SELF-TESTING below to enable self testing. + 4. define FTG_BIG_ENDIAN if you are compiling for big + endian. Otherwise FTG_LITTLE_ENDIAN will be set. + + PURPOSE + + ftg_core.h contains common routines and aims to smooth over the + differences between compilers and their libraries. It is tested on + Visual C++ 98 (c89), Visual Studio 2015 (roughly c99), modern Clang + and modern GCC both in --std=gnu89 and --std=gnu99 dialects. + + It also contains a grab bag of commonly-useful routines and is + somewhat unfocused. + + + SELF-TESTING + + This file contains unit tests. In order to run them, add + ftg_core.h as follows: + + #define FTG_IMPLEMENT_TEST + #define FTG_IMPLEMENT_CORE + #define + #define + + { + ftg_decl_suite(); + int num_failures = ftgt_run_all_tests(NULL); + } + + + Version history + 0.6 windows console alloc/free + 0.5 file management + limited utf-8 support (u8 functions) + FTG_MALLOC/FREE/REALLOC macros + 0.4 stopwatch timers + 0.3 ftg_index_array, + 64-bit file management + 0.2 ftg_strncpy, ftg_tests, + ftg_va + 0.1 ftg_stristr, ftg_stricmp, + compiler macros + + + Future additions + delete file, dir + unit test 64-bit file functions + wrap allocations in ifdefs + standard utf-8 string ops + + + */ +#ifndef FTG__INCLUDE_CORE_H +#define FTG__INCLUDE_CORE_H + +#if defined(_WIN32) && !defined(__MINGW32__) +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +# endif +#endif + +#ifndef FTG_CORE_NO_STDIO +# include +#endif + +/* for off64_t */ +#if defined(__linux__) && _FILE_OFFSET_BITS == 64 +# include +#endif + +/* set FTG_DEBUG to either 0 or 1, and ensure both debug and !debug aren't + set across popular macros */ +#if defined(NDEBUG) +# define FTG_DEBUG 0 +#endif + +#if defined(_DEBUG) || defined(DEBUG) +# if defined(FTG_DEBUG) +# error "Both DEBUG and NDEBUG are set." +# endif +# define FTG_DEBUG 1 +#endif + + +/* broad test for OSes that are vaguely POSIX compliant */ +#if defined(__linux__) || defined(__APPLE__) || defined(ANDROID) || \ + defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \ + defined(__FreeBSD__) || defined(__OpenBSD__) +# define FTG_POSIX_LIKE +#endif + +/* detect target enviroment bits */ +#if _WIN64 +# define FTG_BITS 64 +#elif _WIN32 +# define FTG_BITS 32 +#endif +#if __GNUC__ +# if __x86_64__ || __ppc64__ || __aarch64__ +# define FTG_BITS 64 +# else +# define FTG_BITS 32 +# endif +#endif + +/* unicode strategy: UTF-8 everywhere, except when dealing with Windows functions. + On Windows, define UNICODE and directly call wide versions of functions. + + By defining UNICODE, TCHAR functions don't accept char* which is a safety mechanism. + + I agree with and attempt to comply with utf8everywhere.org. + + Define FTG_IGNORE_UNICODE at your own peril. + */ +#ifndef FTG_IGNORE_UNICODE +# ifdef _WIN32 +# if !defined(UNICODE) || !defined(_UNICODE) +# error _UNICODE and UNICODE not defined -- see header comment for justification +# endif +# endif +#endif + +#ifndef FTG_BITS +# error "ftg_core.h could not determine 32-bit or 64-bit" +#endif + +/* min/max */ +#define FTG_MAX(a,b) ((a) > (b) ? (a) : (b)) +#define FTG_MIN(a,b) ((a) < (b) ? (a) : (b)) +#define FTG_CLAMP(x,xmin,xmax) ((x) < (xmin) ? (xmin) : (x) > (xmax) ? (xmax) : (x)) + +/* portable specifiers -- used to portably printf these types, ex: + printf("size_t is %" FTG_SPEC_SIZE_T, (size_t)1); + + These are piecemeal, as encountered, and best-guess. + If using C99, just use inttypes.h. +*/ +#if defined(_MSC_VER) && _MSC_VER < 1310 +# define FTG_SPEC_SIZE_T "u" +# define FTG_SPEC_SSIZE_T "d" +# define FTG_SPEC_PTRDIFF_T "d" +#elif defined(_MSC_VER) || defined(__MINGW32__) +# define FTG_SPEC_SIZE_T "Iu" +# define FTG_SPEC_SSIZE_T "Id" +# define FTG_SPEC_PTRDIFF_T "Id" +#elif defined(__GNUC__) +# define FTG_SPEC_SIZE_T "zu" +# define FTG_SPEC_SSIZE_T "zd" +# define FTG_SPEC_PTRDIFF_T "zd" +#endif + +#if defined(_MSC_VER) +# define FTG_SPEC_INT64 "I64d" +# define FTG_SPEC_UINT64 "I64d" +#else +# if FTG_BITS == 64 && !defined(__APPLE__) && !defined(__OpenBSD__) +# define FTG_SPEC_INT64 "li" +# define FTG_SPEC_UINT64 "lu" +# elif FTG_BITS == 32 || defined(__APPLE__) || defined(__OpenBSD__) +# define FTG_SPEC_INT64 "lli" +# define FTG_SPEC_UINT64 "lld" +# endif +#endif + +/* ftg_off_t printing */ +#ifndef FTG_CORE_NO_STDIO +# define FTG_SPEC_OFF_T FTG_SPEC_INT64 +#endif + +/* octal directory creation mode for posix-like OSes; override if needed */ +#ifndef FTG_DIRECTORY_MODE +# define FTG_DIRECTORY_MODE 0750 +#endif + +#if defined(_MSC_VER) && (_MSC_VER >= 1800) +// VS doesn't define STDC_VERSION because it isn't fully compliant, but this +// actually lets us compile code that we couldn't without it. +# if !defined(__STDC_VERSION__) && !defined(__cplusplus) +# define __STDC_VERSION__ 199901L +# endif + +// Because VS doesn't support C99, it thinks non-constant aggregate initializers +// are non-standard per C89 3.5.7, but they are in C99. Disable warning +// in vs2013 and greater. +# ifndef __cplusplus +# pragma warning(disable : 4204) +# endif +#endif + +#if __STDC_VERSION__ < 199901L +#define FTG_FUNC "" +#else +#define FTG_FUNC __func__ +#endif + +/* break */ + +#ifdef FTGT_TESTS_ENABLED +# define FTG_BREAK() do{}while(0) +#endif + +#ifndef FTG_BREAK + #if defined(_WIN32) && _MSC_VER >= 1310 + #define FTG_BREAK() __debugbreak(); + #elif defined(_WIN32) + #define FTG_BREAK() __asm{ int 0x3 } + #elif defined(__linux__) + #ifdef __arm__ + #define FTG_BREAK() __asm__ volatile(".inst 0xde01"); + #else + #define FTG_BREAK() __asm__("int $0x3"); + #endif + #elif defined(TARGET_OS_MAC) && defined(__LITTLE_ENDIAN__) + #define FTG_BREAK() __builtin_trap(); + #elif defined(ANDROID) + #define FTG_BREAK() __android_log_assert("breakpoint()", "ftg", "breakpoint"); + #elif defined(TARGET_IPHONE_SIMULATOR) + #define FTG_BREAK() { __builtin_trap(); } + #elif defined(TARGET_OS_IPHONE) + #ifdef __ARM_ARCH_ISA_A64 + asm("svc 0"); + #else + asm("trap"); + #endif + #else + #include + #define FTG_BREAK() assert(0) + #endif +#endif + +/* Make true/false/bool universal macros */ +#ifndef __cplusplus + #if __STDC_VERSION__ < 199901L + #if !__bool_true_false_are_defined + #define true 1 + #define false 0 + #define bool int + #endif + #else + #include + #endif +#endif + +/* assert + +define FTG_ENABLE_ASSERT with FTG_DEBUG=1 to prevent asserts from being noops + +Further, define FTG_CUSTOM_ASSERT_REPORTER to provide alternative diagnostics for FTG_ASSERT calls. +Alternatively, undef it to use system assert. +*/ + +#if !defined(FTG_CUSTOM_ASSERT_REPORTER) && defined(FTGT_TESTS_ENABLED) +# define FTG_CUSTOM_ASSERT_REPORTER ftg__test_assert_reporter +#elif !defined(FTG_CUSTOM_ASSERT_REPORTER) +# define FTG_CUSTOM_ASSERT_REPORTER ftg__default_assert_reporter +#endif + +#if defined(FTG_ENABLE_ASSERT) || FTG_DEBUG==1 || defined(FTGT_TESTS_ENABLED) +# ifdef FTG_CUSTOM_ASSERT_REPORTER +# define FTG_ASSERT(exp) \ + { if (!(exp) && FTG_CUSTOM_ASSERT_REPORTER(#exp, __FILE__, FTG_FUNC, __LINE__)) FTG_BREAK() \ + ;} +# define FTG_ASSERT_FAIL(exp) \ + { FTG_CUSTOM_ASSERT_REPORTER(#exp, __FILE__, FTG_FUNC, __LINE__); FTG_BREAK() \ + ;((void)exp);} +# else +# include +# define FTG_ASSERT(exp) (void)((exp)||(assert(exp))) +# define FTG_ASSERT_FAIL(exp) (assert(0);) +# endif +#else +# define FTG_ASSERT(exp) ((void)0) +# define FTG_ASSERT_FAIL(exp) ((void)0) +#endif + +#define FTG_ASSERT_ALWAYS(exp) \ + { if (!(exp) && FTG_CUSTOM_ASSERT_REPORTER(#exp, __FILE__, FTG_FUNC, __LINE__)) FTG_BREAK(); } + +/* static assert */ + +#define FTG_STATIC_ASSERT_MSG(x, msg) typedef int FTG__StaticAssert_##msg[(x) ? 1 : -1] +#define FTG__STATIC_ASSERT_3(x,L) FTG_STATIC_ASSERT_MSG(x, assertion_at_line_##L) +#define FTG__STATIC_ASSERT_2(x,L) FTG__STATIC_ASSERT_3(x,L) +#define FTG_STATIC_ASSERT(x) FTG__STATIC_ASSERT_2(x,__LINE__) + +/* int types */ +#if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined (__GNUC__) || defined(__clang__) +# include +#else +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +typedef unsigned int uint32_t; +typedef signed int int32_t; + +# if defined(_MSC_VER) +typedef unsigned __int64 uint64_t; +typedef signed __int64 int64_t; + +# if FTG_BITS == 64 +# define SIZE_MAX (18446744073709551615UL) +# else +# define SIZE_MAX (4294967295U) +# endif + +# else +typedef unsigned long long uint64_t; +typedef signed long long int64_t; +# endif +#endif + + +/* portable 64-bit offset types + ftg_off_t is guaranteed to be 64-bit, even on 32-bit builds + on all OSes. + ftg_fopen, ftg_ftell, etc. all operate on 64-bit values. + */ +#ifndef FTG_CORE_NO_STDIO + +struct ftg_dirhandle_s; +typedef struct ftg_dirhandle_s ftg_dirhandle_t; + + +#if defined(__APPLE__) +# define FTG_IO64_EXPLICIT 0 +# if _FILE_OFFSET_BITS == 64 || defined(__LP64__) + typedef off_t ftg_off_t; +# else + typedef off64_t ftg_off_t +# endif +#elif defined(__linux__) + /* Linux is a fun one. It offers three separate ways to get a + 64-bit file descriptor. The first is through explicit 64-bit + calls and typedefs: defining _LARGEFILE64_SOURCE. The + alternative is specifying _FILE_OFFSET_BITS=64 and then using + transparently using the normal routines. Finally, if __LP64__ + is defined, off_t is 64-bit anyway. + + As a library trying to work in all cases, we use explicit calls + if they are available, or fall back on transparent calls if they + are not. To simplify preprocessor tests, we define + FTG__IO64_EXPLICIT. + + And we statically assert if neither of these are defined. */ +# if defined(_LARGEFILE64_SOURCE) +# define FTG__IO64_EXPLICIT 1 + typedef off64_t ftg_off_t; +# elif _FILE_OFFSET_BITS == 64 +# define FTG__IO64_EXPLICIT 0 + typedef off_t ftg_off_t; +# else +# define FTG__IO64_EXPLICIT 0 +# if defined(__LP64__) + typedef off_t ftg_off_t; +# else +/* if this is hit, define _FILE_OFFSET_BITS=64 across your compile, or + define FTG_CORE_NO_STDIO to disable all ftg_core I/O */ +# error "no 64-bit fopen support." +# endif +# endif +#elif defined(_WIN32) +typedef int64_t ftg_off_t; +typedef wchar_t ftg_wchar_t; +#elif defined(__FreeBSD__) || defined(__OpenBSD__) + typedef off_t ftg_off_t; +#endif + +FTG_STATIC_ASSERT(sizeof(ftg_off_t)==8); + +#endif /* FTG_CORE_NO_STDIO */ + +FTG_STATIC_ASSERT(sizeof(int8_t)==1); +FTG_STATIC_ASSERT(sizeof(int16_t)==2); +FTG_STATIC_ASSERT(sizeof(int32_t)==4); +FTG_STATIC_ASSERT(sizeof(int64_t)==8); + +#define FTG_ARRAY_ELEMENTS(n) (sizeof((n)) / sizeof((*n))) +/* + Compiler extensions made portable + + USAGE + + In MSVC, attributes must be on declarations in addition to prototypes. + Use FTG_ATTRIBUTES to declare them. + + Prototype + FTG_EXT_warn_unused_result FTG_EXT_force_inline int SomeFunc( void ); + + Declaration + FTG_ATTRIBUTES(FTG_EXT_warn_unused_result) int SomeFunc( void ); + + + Keyword extensions made portable + + Goal is to use language and compiler-native versions of keywords added + after the c89 standard. + + ftg_inline + ftg_restrict +*/ + +#if defined(__GNUC__) || defined(__clang__) + #define FTG_EXT_warn_unused_result __attribute__((warn_unused_result)) + #define FTG_EXT_force_inline __attribute__((always_inline)) + #define FTG_EXT_pure_function __attribute__((pure)) + #define FTG_EXT_const_function __attribute__((const)) + #define FTG_EXT_unused __attribute__((unused)) + #define FTG_EXT_no_vtable + #ifdef __cplusplus + #define ftg_restrict __restrict + #else + #if __STDC_VERSION__ >= 199901L + #define ftg_restrict restrict + #endif + #endif + #if __STDC_VERSION__ < 199901L + #define ftg_inline __inline + #else + #define ftg_inline inline + #endif + #define FTG_ATTRIBUTES(x) + +// todo: investigate https://twitter.com/deplinenoise/status/971873640609300480 +#elif defined(_MSC_VER) && (_MSC_VER >= 1700) /* vs2012 */ + #define ftg_restrict __restrict + #define ftg_inline __inline + #define FTG_EXT_warn_unused_result _Check_return_ + #define FTG_EXT_force_inline __forceinline + #define FTG_EXT_unused + #define FTG_ATTRIBUTES(x) x +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) /* vs2005 */ + #define FTG_EXT_no_vtable __declspec(novtable) + #define ftg_restrict __restrict + #define ftg_inline __inline + #define FTG_EXT_unused + #define FTG_ATTRIBUTES(x) x +#endif + +#ifndef FTG_EXT_warn_unused_result + #define FTG_EXT_warn_unused_result +#endif +#ifndef FTG_EXT_force_inline + #define FTG_EXT_force_inline +#endif +#ifndef FTG_EXT_pure_function + #define FTG_EXT_pure_function +#endif +#ifndef FTG_EXT_const_function + #define FTG_EXT_const_function +#endif +#ifndef ftg_restrict + #define ftg_restrict +#endif +#ifndef ftg_inline + #define ftg_inline +#endif +#ifndef FTG_ATTRIBUTES + #define FTG_ATTRIBUTES(x) +#endif + +#ifdef FTG_CORE_STATIC +# define FTGDEF static FTG_EXT_unused +#else +# define FTGDEF extern +#endif + +/* endianness + + use little endian unless FTG_BIG_ENDIAN is defined. + */ + +#ifndef FTG_BIG_ENDIAN +# define FTG_LITTLE_ENDIAN +#endif + +/* fourcc */ +#ifdef FTG_LITTLE_ENDIAN +# define FTG_FOURCC(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24)) +#elif FTG_BIG_ENDIAN +# define FTG_FOURCC(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24)) +#endif + +/* misc macros */ + +#define FTG_UNUSED(x) ((void)x) +#define FTG_STRLEN 255 +#define FTG_STRLEN_SHORT 16 +#define FTG_STRLEN_LONG 1024 + +#define FTG_UNDEFINED_HUE 360.f*2 + +#define FTG_IA_INIT_ZERO {NULL, 0, 0} +#define FTG_IA_INITIAL_RECORD_COUNT 8 + +/* usually better to use ftg_correct_dirslash than reference this directly */ +#ifdef _WIN32 +# define FTG_DIRSLASH '\\' +# define FTG_DIRSLASH_STR "\\" +#elif defined(FTG_POSIX_LIKE) +# define FTG_DIRSLASH '/' +# define FTG_DIRSLASH_STR "/" +#endif + +#if defined(__linux__) +# define FTG__HAVE_EXPLICIT_BZERO +#elif defined(__APPLE__) +# define FTG__HAVE_MEMSET_S +#endif + +/* + stopwatch -- portable, high precision start/next/stop timer + + #define FTG_ENABLE_STOPWATCH before calling this function, or every + call is a noop. + + + USAGE + 1. Declare a stopwatch variable mytimer: + FTG_STOPWATCH_DECL(mytimer); + + 2. Start the timer, storing time in the bucket named "0": + FTG_STOPWATCH_START(mytimer, 0) + + 3. (optional) Track additional times within the timer. + This buckets the remaining code into bucket "1": + FTG_STOPWATCH_NEXT(mytimer, 1) + + 4. Stop the timer + FTG_STOPWATCH_STOP(mytimer) + + + TIMING AFTER STOP + If FTG_STOPWATCH_NEXT() is encountered after a timer has stopped, + no additional time is counted. This is a key subtlety. + Time spent in subfunction c() of a() is accumulated, but when c() + is a subfunction of b(), it is not accumulated, providing the timer + was stopped before b() was called. + + + DESCRIBING THE STEPS (optional) + Instead of using numerical steps, you can use named steps like this: + #define A_STEP_NAME 1 + Then, + FTG_STOPWATCH_NEXT(mytimer, A_STEP_NAME) + This increases the readability of the reporting. + + + CUSTOM REPORTING (optional) + After a stopwatch ends, a function with the following prototype is called + to report the stopwatch: + + void ftg__default_stopwatch_reporter(const struct ftg_stopwatch_s *); + + #define FTG_STOPWATCH_REPORTER to your own function in the file that implements ftg_core + to call that instead. + */ + +#ifdef FTG_ENABLE_STOPWATCH + +# define FTG_STOPWATCH_DECL(sw) struct ftg_stopwatch_s sw = {"", {0}, {""}, 0, FTG__MAX_STOPWATCH_TIMES+100, false}; +# define FTG_STOPWATCH_START(sw, bucket) ftg__stopwatch_start(&sw, #sw, #bucket, bucket) +# define FTG_STOPWATCH_NEXT(sw, bucket) ftg__stopwatch_next_bucket(&sw, #bucket, bucket) +# define FTG_STOPWATCH_STOP(sw) ftg__stopwatch_stop(&sw) +# define FTG_STOPWATCH_EXPR(exp) exp + +#define FTG__MAX_STOPWATCH_TIMES 12 + +struct ftg_stopwatch_s { + char name[FTG_STRLEN_SHORT]; + + uint64_t times[FTG__MAX_STOPWATCH_TIMES]; + char time_names[FTG__MAX_STOPWATCH_TIMES][FTG_STRLEN_SHORT]; + + uint64_t start_time; + + size_t current_bucket; + bool currently_logging; +}; + +#else +# define FTG_STOPWATCH_DECL(sw) +# define FTG_STOPWATCH_START(sw, bucket) +# define FTG_STOPWATCH_NEXT(sw, bucket) +# define FTG_STOPWATCH_STOP(sw) +# define FTG_STOPWATCH_EXPR(exp) +struct ftg_stopwatch_s; +#endif + +/* Define a type by its language-native class type. Useful for + creating types as forward declarations which are ignored when + actually compiling in C. + +Usage: +#define TYPE_MACRO FTG_DECL_CLASS(some_type) +TYPE_MACRO; +void some_func(TYPE_MACRO *); + */ +#ifdef __cplusplus +#define FTG_DECL_CLASS(T) class T +#elif __OBJC__ +#define FTG_DECL_CLASS(T) @class T +#else +#define FTG_DECL_CLASS(T) struct T +#endif + +/* exported decls */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* MSVC earlier than 2005 does not include these in stdio.h. */ +#if defined(_MSC_VER) && _MSC_VER < 1400 +extern int __cdecl _fseeki64(FILE *, __int64, int); +extern __int64 __cdecl _ftelli64(FILE *); +#endif + + +#if defined(FTG_MALLOC) && defined(FTG_FREE) && defined(FTG_REALLOC) +// okay +#elif !defined(FTG_MALLOC) && !defined(FTG_FREE) && !defined(FTG_REALLOC) +// also okay +#else +#error "Must define all or none of FTG_MALLOC, FTG_FREE and FTG_REALLOC." +#endif + +/* default implementations just call system malloc with assert guards + for OOM and overflow. + + ftg_free zeroes pointer in calling code after free. + + num - number of elements, size - size of each element */ +#ifndef FTG_MALLOC +# define FTG_MALLOC(size, num) ftg_malloc(size, num); +# define FTG_FREE(ptr) ftg_free((void**)&ptr); +# define FTG_REALLOC(ptr, size, num) ftg_realloc(ptr, size, num) +#endif + +FTGDEF void * +ftg_malloc(size_t size, size_t num); + +FTGDEF void +ftg_free(void **heap); + +FTGDEF int +ftg_stricmp(const char *s1, const char *s2); + +FTGDEF void * +ftg_realloc(void *ptr, size_t size, size_t num); + +FTGDEF char * +ftg_stristr(const char *haystack, const char *needle); + +FTGDEF FTG_EXT_warn_unused_result int +ftg_strncpy(char *ftg_restrict dst, const char *ftg_restrict src, size_t max_copy); + +FTGDEF FTG_EXT_warn_unused_result char * +ftg_strcatall(size_t num, ...); + +FTGDEF const char* +ftg_strsplit(const char *str, char split_ch, size_t index, size_t *out_len); + +FTGDEF void +ftg_bzero(void *ptr, size_t num); + +FTGDEF char * +ftg_va(const char *fmt, ...); + +FTGDEF uint32_t +ftg_hash_fast(const void *p, uint32_t len); + +FTGDEF uint32_t +ftg_hash_number(uint32_t number); + +FTGDEF int +ftg__default_assert_reporter(const char *expr, const char *filename, const char *func, unsigned int lineno); + +#ifdef FTGT_TESTS_ENABLED +FTGDEF int +ftg__test_assert_reporter(const char *expr, const char *filename, const char *func, unsigned int lineno); +#endif + +#ifndef FTG_CORE_NO_STDIO +FTGDEF unsigned char * +ftg_file_read(const char *path, bool make_string, ftg_off_t *len); + +FTGDEF bool +ftg_file_write(const char *path, const uint8_t *buf, size_t buf_bytes); + +FTGDEF bool +ftg_file_write_string(const char *path, const char *str); +#endif + +FTGDEF void +ftg_gethsv(float r, float g, float b, float *ftg_restrict h, float *ftg_restrict s, float *ftg_restrict v); + +FTGDEF void +ftg_getrgb(float h, float s, float v, float *ftg_restrict r, float *ftg_restrict g, float *ftg_restrict b); + +FTGDEF float +ftg_aspect_correct_scale_for_rect(const float screen[2], const float rect[2]); + +FTGDEF size_t +ftg_u8_strlen(const char *s); + +struct ftg_index_array_s { + size_t *indices; + size_t count; /* num used */ + size_t records; /* alloced, always > count */ +}; + +/* warning: ftg_ia api will be deprecated and moved to a container-specific header file */ +FTGDEF bool +ftg_ia_is_init(struct ftg_index_array_s *i); + +FTGDEF bool +ftg_ia_append(struct ftg_index_array_s *i, size_t index); + +FTGDEF void +ftg_ia_prealloc(struct ftg_index_array_s *i, size_t initial_record_count); + +FTGDEF void +ftg_ia_free(struct ftg_index_array_s *i); + +FTGDEF const char * +ftg_correct_dirslash(char *path); + +FTGDEF char * +ftg_get_filename_ext(const char *path); + +FTGDEF char * +ftg_get_filename_from_path(const char *path); + +FTGDEF bool +ftg_is_dirslash(char c); + +FTGDEF bool +ftg_push_path(char *dst_path, const char *src_path, size_t max_path); + +FTGDEF void +ftg_pop_path(char *dst_path); + +#ifndef FTG_CORE_NO_STDIO +FTGDEF FILE * +ftg_fopen64(const char *filename, const char *type); + +FTGDEF ftg_off_t +ftg_ftell64(FILE *stream); + +FTGDEF int64_t +ftg_fseek64(FILE *stream, ftg_off_t offset, int origin); + +FTGDEF const char * +ftg_opendir(ftg_dirhandle_t *handle, const char *path, char *out, size_t out_len); + +FTGDEF const char * +ftg_readdir(ftg_dirhandle_t *handle, char *out, size_t out_len); + +FTGDEF void +ftg_closedir(ftg_dirhandle_t *handle); + +FTGDEF bool +ftg_is_dir(const char *path); + +FTGDEF bool +ftg_path_exists(const char *path); + +FTGDEF bool +ftg_mkdir(const char *path); + +FTGDEF void +ftg_mkalldirs(const char *path); + +FTGDEF void +ftg_rmalldirs(const char *path); + +FTGDEF bool +ftg_rmdir(const char *path); + +FTGDEF void +ftg_alloc_console(void); + +FTGDEF void +ftg_free_console(void); +#endif + +#ifdef FTG_ENABLE_STOPWATCH +FTGDEF void +ftg__stopwatch_start(struct ftg_stopwatch_s *stopwatch, + const char *name, const char *bucket_name, size_t bucket); + +FTGDEF void +ftg__stopwatch_stop(struct ftg_stopwatch_s *stopwatch); + +FTGDEF void +ftg__stopwatch_next_bucket(struct ftg_stopwatch_s *stopwatch, + const char *bucket_name, size_t bucket); + +FTGDEF void +ftg__default_stopwatch_reporter(struct ftg_stopwatch_s *sw); +#endif + +#ifdef __cplusplus +} +#endif + +/* implementation */ + +#ifdef FTG_IMPLEMENT_CORE + +#ifndef FTG_CORE_NO_STDIO +# include +# ifdef FTG_POSIX_LIKE +# include +# include +# include +# include +# include +# elif defined(_WIN32) +# define WIN32_LEAN_AND_MEAN +# include /* for HANDLE in ftg_opendir */ +# include +# ifndef INVALID_FILE_ATTRIBUTES +# define INVALID_FILE_ATTRIBUTES ((DWORD)-1) /* missing in older sdks */ +# endif +# undef WIN32_LEAN_AND_MEAN +# endif +#endif + +#include +#include +#include +#include +#include +#include + +/* SIZE_MAX may not be defined in C++ because C++ does not know about this C99 addition. */ +#ifndef SIZE_MAX +# if FTG_BITS == 64 +# define FTG__SIZE_MAX (18446744073709551615UL) +# else +# define FTG__SIZE_MAX (4294967295U) +# endif +#else +# define FTG__SIZE_MAX SIZE_MAX +#endif + +int +ftg__default_assert_reporter(const char *expr, const char *filename, const char *func, unsigned int lineno) +{ + ((void)filename); + fprintf(stderr, "assert %s(%d)%s: %s\n", filename, lineno, func, expr); + return 1; +} + +#ifdef FTGT_TESTS_ENABLED +int +ftg__test_assert_reporter(const char *expr, const char *filename, const char *func, unsigned int lineno) +{ + printf("\n[ftg_test intercepted assert] "); + ftg__default_assert_reporter(expr, filename, func, lineno); + + ftgt_notify_assert_hit(); + + return 1; +} +#endif + +/* memory */ + +void * +ftg_malloc(size_t size, size_t num) +{ + void *heap = NULL; + FTG_ASSERT(size != 0 && num != 0); + + if (size > 0 && num > 0 && FTG__SIZE_MAX/size >= num) + { + size_t alloc_size = size * num; + heap = malloc(alloc_size); + if (!heap) + { + FTG_ASSERT_FAIL("oom"); + } + } + else + { + FTG_ASSERT_FAIL("ftg_malloc overflow - no memory allocated"); + } + + return heap; +} + +void +ftg_free(void **heap) +{ + FTG_ASSERT(heap && *heap); + free(*heap); + *heap = NULL; +} + +/* strings */ + +/* ascii case folded string compare */ +int +ftg_stricmp(const char *s1, const char *s2) +{ + int result; + const char *p1; + const char *p2; + if ( s1==s2) + return 0; + + p1 = s1; + p2 = s2; + result = 0; + if ( p1 == p2 ) + return result; + + while (!result) + { + result = tolower(*p1) - tolower(*p2); + if ( *p1 == '\0' ) + break; + ++p1; + ++p2; + } + + return result; +} + + +/* Fill up to max_copy characters in dst, including null. Unlike strncpy(), a null + terminating character is guaranteed to be appended, EVEN if it overwrites + the last character in the string. + + Only appends a single NULL character instead of NULL filling the string. The + trailing bytes are left uninitialized. + + No bytes are written if max_copy is 0, and FTG_ASSERT is thrown. + + \return 1 on truncation or max_copy==0, zero otherwise. + */ +FTG_ATTRIBUTES(FTG_EXT_warn_unused_result) int +ftg_strncpy(char *ftg_restrict dst, const char *ftg_restrict src, size_t max_copy) +{ + size_t n; + char *d; + + FTG_ASSERT(dst); + FTG_ASSERT(src); + FTG_ASSERT(max_copy > 0); + + if (max_copy == 0) + return 1; + + n = max_copy; + d = dst; + while ( n > 0 && *src != '\0' ) + { + *d++ = *src++; + --n; + } + + /* Truncation case - + terminate string and return true */ + if ( n == 0 ) + { + dst[max_copy-1] = '\0'; + return 1; + } + + /* No truncation. Append a single NULL and return. */ + *d = '\0'; + return 0; +} + +/* case insensitive strstr */ +char * +ftg_stristr(const char *haystack, const char *needle) +{ + if ( !*needle ) + return (char*)(haystack+strlen(haystack)); + + for ( ; *haystack; ++haystack ) + { + if ( tolower( *haystack ) == tolower( *needle ) ) + { + const char *h,*n; + for ( h = haystack, n = needle; *h && *n; ++h, ++n ) + { + if ( tolower( *h ) != tolower( *n ) ) + break; + } + if ( !*n ) + return (char*)haystack; + } + } + + return NULL; +} + +/* append num strings, returning heap-allocated string. + caller must free() returned ptr. */ +FTG_ATTRIBUTES(FTG_EXT_warn_unused_result) char * +ftg_strcatall(size_t num, ...) +{ + size_t i, alloc_size = 0; + va_list va1, va2; + char *buf, *p_buf; + + va_start(va1, num); + for (i = 0; i < num; i++) + { + alloc_size += strlen(va_arg(va1, char*)); + } + va_end(va1); + alloc_size += 1; + + buf = p_buf = (char*)FTG_MALLOC(sizeof(char), alloc_size); + if (!buf) return NULL; + va_start(va2, num); + for (i = 0; i < num; i++) + { + char *s = va_arg(va2, char*); + while (*s) + { + *p_buf = *s; + p_buf++; s++; + } + } + va_end(va2); + + buf[alloc_size-1] = '\0'; + return buf; +} + + +/* split *str on split_chr, returing the split number 'index'. + index 0 = beginning of string, NULL when index exceeds number of splits + len is set to the length of the string or 0 if NULL is returned */ +FTGDEF const char* +ftg_strsplit(const char *str, char split_ch, size_t index, size_t *len) { + size_t encounters = 0; + const char *p = str; + const char *end; + + if (index == 0) { + goto find_next_split; + } + + for (p = str; *p; p++) { + if (*p == split_ch) + encounters++; + if (encounters == index) { + break; + } + + } + + // hit end of string; requested index does not exist + if (!*p) { + if (len) *len = 0; + return NULL; + } + + p++; + +find_next_split: + // skip search for next split char if not needed + if (!len) + return p; + + for (end = p; *end && *end != split_ch; end++) + ; + *len = end-p; + + return p; +} + + +/* avoids memset argument order confusion for most common use case, + guards against 0 num, works on platforms that don't have bzero, + can't be optimized away. */ +void +ftg_bzero(void *ptr, size_t num) +{ + FTG_ASSERT(num > 0); + FTG_ASSERT(ptr); + +#ifdef FTG__HAVE_MEMSET_S + errno_t err = memset_s(ptr, num, 0, num); + FTG_ASSERT(err == 0); + FTG_UNUSED(err); +#elif defined(FTG__HAVE_EXPLICIT_BZERO) + explicit_bzero(ptr, num); +#else + memset(ptr, 0, num); +#endif +} + +/* calls realloc with guards -- behaves the same way */ +void * +ftg_realloc(void *ptr, size_t size, size_t num) +{ + void *alloc_ptr = NULL; + FTG_ASSERT(size != 0 && num != 0); + if (size > 0 && num > 0 && FTG__SIZE_MAX/size >= num) + { + size_t alloc_size = size * num; + + alloc_ptr = realloc(ptr, alloc_size); + FTG_ASSERT(alloc_ptr); + } + else + { + FTG_ASSERT_FAIL("ftg_realloc overflow - no memory allocated"); + } + + /* return result from realloc even if null */ + return alloc_ptr; +} + +char * +ftg_va(const char *fmt, ...) +{ + static char buf[FTG_STRLEN_LONG]; + int len; + + va_list ap; + va_start(ap, fmt); +#ifdef _WIN32 + len = _vsnprintf(buf, FTG_STRLEN_LONG, fmt, ap); + FTG_ASSERT(len != -1); + FTG_UNUSED(len); +#else + len = vsnprintf(buf, FTG_STRLEN_LONG, fmt, ap); + FTG_ASSERT(len < FTG_STRLEN_LONG); + FTG_UNUSED(len); +#endif + va_end(ap); + buf[FTG_STRLEN_LONG-1] = 0; + + return buf; +} + +/* in-place swapping of slashes to match executing platform's + directory slash order. returns a pointer to *path + */ +const char *ftg_correct_dirslash(char *path) +{ +#ifdef _WIN32 + char bad_slash = '/'; + char good_slash = '\\'; +#elif defined(FTG_POSIX_LIKE) + char bad_slash = '\\'; + char good_slash = '/'; +#endif + + char *p = &path[0]; + while(*p) + { + if (*p == bad_slash) + *p = good_slash; + p++; + } + + return path; +} + +/* get extension of the filename, not including the '.' */ +FTGDEF char * +ftg_get_filename_ext(const char *path) +{ + size_t len = strlen(path); + const char *end = &path[len]; + + while(len > 0) + { + char c; + + len--; + c = path[len]; + + if (c == FTG_DIRSLASH) + break; + + if (c == '.') + return (char*)&path[len+1]; + } + + return (char*)end; /* return null terminator */ +} + +/* return the filename part of a path using the current OS's slash char */ +FTGDEF char * +ftg_get_filename_from_path(const char *path) +{ + const char *p = path + strlen(path)-1; + while (p != path) + { + if (*p == FTG_DIRSLASH) + return (char*)p+1; + p--; + } + + return (char*)path; +} + +/* cross-environment dir slash check */ +FTGDEF bool +ftg_is_dirslash(char c) +{ + return (c == '/' || c == '\\'); +} + +/* append a directory to a path, separated by a directory slash ('/' or '\') + return true if truncation occurs */ +FTGDEF bool +ftg_push_path(char *dst_path, const char *src_path, size_t max_path) +{ + char *dst = dst_path; + const char *src = dst_path; + bool slashing = false; + char c; + +#define FTG__CHECK_MAX_PATH \ + if ((ptrdiff_t)(dst - dst_path + 1) >= (ptrdiff_t)max_path) return true; + + FTG_ASSERT(src_path && dst_path); + + // start with a slash if src_path is absolute + if (ftg_is_dirslash(dst_path[0])) + { + FTG__CHECK_MAX_PATH; + dst++; + src++; + slashing = true; + } + + while ((c = *src) != '\0') + { + bool is_slash; + FTG__CHECK_MAX_PATH; + is_slash = ftg_is_dirslash(c); + if (!slashing || !is_slash) + *dst++ = c; + + slashing = is_slash; + src++; + } + + // begin reading from src_path + src = src_path; + + // insert a separating slash (or leading slash for an abs path) + if (((dst != dst_path) && !slashing) || + ((dst == dst_path) && (ftg_is_dirslash(src_path[0])))) + { + FTG__CHECK_MAX_PATH; + *dst++ = FTG_DIRSLASH; + slashing = true; + } + + while ((c = *src) != '\0') + { + bool is_slash; + FTG__CHECK_MAX_PATH; + is_slash = ftg_is_dirslash(c); + if (!slashing || !is_slash) + *dst++ = c; + + slashing = is_slash; + src++; + } + + *dst = '\0'; + + // strip any trailing slash + if (slashing && ((dst - dst_path) > 1)) + { + dst--; + *dst = '\0'; + } + + return false; +#undef FTG__CHECK_MAX_PATH +} + +/* in-place truncate dst_path to remove last path component: + filename or directory. */ +FTGDEF void +ftg_pop_path(char *dst_path) +{ + size_t length = strlen(dst_path); + + if (length == 0) + return; + + if ((length == 1) && (ftg_is_dirslash(dst_path[0]))) + return; + + if (ftg_is_dirslash(dst_path[length-1])) + length--; + + // don't strip the root / of an abs path + if (ftg_is_dirslash(dst_path[0])) + { + dst_path++; + length--; + } + + while(length > 0) + { + char c; + length--; + c = dst_path[length]; + if (ftg_is_dirslash(c)) + break; + } + + dst_path[length] = '\0'; +} + +/* read a file into a memory buffer. clear the memory with ftg_free. + if make_string is true, a null terminator is attached. + + len is the number of bytes returned, including the null terminator if + return is non-NULL, otherwise it is unchanged. + + Uses 64-bit file routines internally. +*/ +#ifndef FTG_CORE_NO_STDIO +FTGDEF uint8_t * +ftg_file_read(const char *path, bool make_string, ftg_off_t *len) +{ + int64_t file_len; + ftg_off_t out_size; + size_t size; + unsigned char *buf; + size_t num_elements; + FILE *fp = ftg_fopen64(path, "rb"); + if (!fp) + return NULL; + + ftg_fseek64(fp, 0L, SEEK_END); + file_len = ftg_ftell64(fp); + ftg_fseek64(fp, 0L, SEEK_SET); + + out_size = make_string ? file_len+1 : file_len; + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4127) +#endif + if (sizeof(int64_t) > sizeof(size_t) && (size_t)file_len > FTG__SIZE_MAX) + { + // fread will truncate if trying to read more than 2GB on a 32-bit OS in one call. + FTG_ASSERT_FAIL("File is larger than a single fread() call and will be truncated."); + file_len = FTG__SIZE_MAX; + } +#ifdef _MSC_VER +# pragma warning(pop) +#endif + + /* ftg_off_t is a signed value, size_t is an unsigned value. + rather than work with memory with a signed value, cast + to size_t. */ + FTG_ASSERT(out_size >= 0); + size = (size_t)out_size; + + buf = (unsigned char*)FTG_MALLOC(sizeof(unsigned char), size); + if (!buf) + return NULL; + + num_elements = fread(buf, (size_t)file_len, 1, fp); + if (num_elements != 1) + goto fail; + + fclose(fp); + + if (make_string) + buf[size-1] = '\0'; + + if (len) + *len = out_size; + + return buf; + + fail: + FTG_FREE(buf); + return NULL; +} + +/* write *buf bytes into a file. Returns whether all the bytes were written. + buf does not necessarily point to a string. */ +FTGDEF bool +ftg_file_write(const char *path, const uint8_t *buf, size_t buf_bytes) +{ + size_t write_bytes; + FILE *fp = ftg_fopen64(path, "wb"); + + if (!fp) + return false; + + write_bytes = fwrite(buf, sizeof(uint8_t), buf_bytes, fp); + fclose(fp); + + FTG_ASSERT(write_bytes == buf_bytes); + + return write_bytes == buf_bytes; +} + +/* writes a string to a file, not including the terminator */ +FTGDEF bool +ftg_file_write_string(const char *path, const char *str) +{ + size_t byte_count = strlen(str); + return ftg_file_write(path, (const uint8_t*)str, byte_count); +} +#endif /* !FTG_CORE_NO_STDIO */ + + +static ftg_inline +float ftg__get_min(float a, float b, float c) +{ + float r = a; + if (r > b) r = b; + if (r > c) r = c; + return r; +} + +static ftg_inline +float ftg__get_max(float a, float b, float c) +{ + float r = a; + if (r < b) r = b; + if (r < c) r = c; + return r; +} + + +void +ftg_gethsv(float r, float g, float b, float *ftg_restrict h, float *ftg_restrict s, float *ftg_restrict v) +{ + float max_chan = ftg__get_max(r,g,b); + float min_chan = ftg__get_min(r,g,b); + float delta; + + *v = max_chan; + + *s = (max_chan != 0.0f) ? (( max_chan - min_chan) / max_chan ): 0.0f; + + if ( *s == 0.0f ) + { + *h = FTG_UNDEFINED_HUE; /* undefined */ + } + else + { + delta = max_chan - min_chan; + + if (r == max_chan) + *h = (g - b) / delta; /* Color between yellow and magenta */ + else if ( g == max_chan ) + *h = 2.0f + (b-r) / delta; /* Color between cyan and yellow */ + else if ( b == max_chan ) + *h = 4.0f + (r-g) / delta; /* Color between magenta and cyan */ + + *h *= 60.0f; /* Convert hue to degrees */ + if ( *h < 0.0f ) + *h += 360.0f; + } +} + +void +ftg_getrgb(float h, float s, float v, float *ftg_restrict r, float *ftg_restrict g, float *ftg_restrict b) +{ + FTG_ASSERT( h==FTG_UNDEFINED_HUE || (h >= 0.0f && h <= 360.0f) ); + FTG_ASSERT( s >= 0.0f && s <= 1.0f ); + FTG_ASSERT( v >= 0.0f && v <= 1.0f ); + + if ( s == 0.0f ) + { + /* Achromatic color */ + if ( h == FTG_UNDEFINED_HUE ) + { + *r = *g = *b = v; + } + else + { + FTG_ASSERT_FAIL("If s == 0 and hue has value, this is an invalid HSV set"); + return; + } + } + else + { + // Chromatic case: s != 0 so there is a hue. + float f,p,q,t; + int i; + + if ( h == 360.0f ) + h = 0.0f; + h /= 60.0f; + + i = (int)h; + f = h - i; + + p = v * (1.0f - s); + q = v * (1.0f - (s * f )); + t = v * (1.0f - (s * (1.0f - f ))); + + switch(i) + { + case 0: *r = v; *g = t; *b = p; break; + case 1: *r = q; *g = v; *b = p; break; + case 2: *r = p; *g = v; *b = t; break; + case 3: *r = p; *g = q; *b = v; break; + case 4: *r = t; *g = p; *b = v; break; + case 5: *r = v; *g = p; *b = q; break; + } + } +} + + +/* For a rectangle inside a screen, get the scale factor that permits the rectangle + to be scaled without stretching or squashing. */ +float +ftg_aspect_correct_scale_for_rect(const float screen[2], const float rect[2]) +{ + float screenAspect = screen[0] / screen[1]; + float rectAspect = rect[0] / rect[1]; + + float scaleFactor; + if (screenAspect > rectAspect) + scaleFactor = screen[1] / rect[1]; + else + scaleFactor = screen[0] / rect[0]; + + return scaleFactor; +} + +FTGDEF size_t +ftg_u8_strlen(const char *s) +{ + const char *p = s; + size_t j = 0; + + while (*p) { + if ((*p & 0xc0) != 0x80) + j++; + p++; + } + + return j; +} + +bool +ftg_ia_is_init(struct ftg_index_array_s *i) +{ + return (i && i->indices && i->records > 0); +} + +void +ftg_ia_prealloc(struct ftg_index_array_s *i, size_t initial_record_count) +{ + FTG_ASSERT(initial_record_count > 0); + + if (i->records > initial_record_count || initial_record_count == 0) + return; + + i->indices = (size_t*)FTG_MALLOC(initial_record_count, sizeof(size_t)); + if (!i->indices) + return; + i->records = initial_record_count; + i->count = 0; +} + +bool +ftg_ia_append(struct ftg_index_array_s *i, size_t index_value) +{ + if (i->count+1 > i->records) + { + size_t new_record_count; + size_t *new_frame_indices; + + if (i->count == 0) + new_record_count = FTG_IA_INITIAL_RECORD_COUNT; + else + new_record_count = i->count*2; + + new_frame_indices = (size_t*)FTG_REALLOC(i->indices, + sizeof(size_t), new_record_count); + + if (!new_frame_indices) { + FTG_ASSERT_FAIL("Could not reallocate index array."); + return false; + } + + i->records = new_record_count; + i->indices = new_frame_indices; + } + + i->indices[i->count] = index_value; + i->count++; + + return true; +} + +void +ftg_ia_free(struct ftg_index_array_s *i) +{ + if (i->indices) + FTG_FREE(i->indices); + i->records = i->count = 0; +} + +/* portable 64-bit UTF-8 file routines */ +#ifndef FTG_CORE_NO_STDIO + +#ifdef _WIN32 +/* these utf8 conversion routines are taken from public domain stb.h + with minor tweaks */ +FTGDEF ftg_wchar_t * +ftg_wchar_from_u8(const char *in_str, ftg_wchar_t *out_str, size_t n) +{ + unsigned char *str = (unsigned char *)in_str; + uint32_t c; + unsigned int i = 0; + --n; + while (*str) { + if (i >= n) + return NULL; + if (!(*str & 0x80)) + out_str[i++] = *str++; + else if ((*str & 0xe0) == 0xc0) { + if (*str < 0xc2) return NULL; + c = (*str++ & 0x1f) << 6; + if ((*str & 0xc0) != 0x80) return NULL; + out_str[i++] = (ftg_wchar_t)(c + (*str++ & 0x3f)); + } else if ((*str & 0xf0) == 0xe0) { + if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return NULL; + if (*str == 0xed && str[1] > 0x9f) return NULL; // str[1] < 0x80 is checked below + c = (*str++ & 0x0f) << 12; + if ((*str & 0xc0) != 0x80) return NULL; + c += (*str++ & 0x3f) << 6; + if ((*str & 0xc0) != 0x80) return NULL; + out_str[i++] = (ftg_wchar_t)(c + (*str++ & 0x3f)); + } else if ((*str & 0xf8) == 0xf0) { + if (*str > 0xf4) return NULL; + if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return NULL; + if (*str == 0xf4 && str[1] > 0x8f) return NULL; // str[1] < 0x80 is checked below + c = (*str++ & 0x07) << 18; + if ((*str & 0xc0) != 0x80) return NULL; + c += (*str++ & 0x3f) << 12; + if ((*str & 0xc0) != 0x80) return NULL; + c += (*str++ & 0x3f) << 6; + if ((*str & 0xc0) != 0x80) return NULL; + c += (*str++ & 0x3f); + // utf-8 encodings of values used in surrogate pairs are invalid + if ((c & 0xFFFFF800) == 0xD800) return NULL; + if (c >= 0x10000) { + c -= 0x10000; + if ((size_t)i + 2 > n) return NULL; + out_str[i++] = 0xD800 | (0x3ff & (c >> 10)); + out_str[i++] = 0xDC00 | (0x3ff & (c )); + } + } else + return NULL; + } + out_str[i] = 0; + return out_str; +} + +FTGDEF char * +ftg_wchar_to_u8(const ftg_wchar_t *in_str, char *out_str, size_t n) +{ + unsigned int i = 0; + --n; + while (*in_str) { + if (*in_str < 0x80) { + if ((size_t)i+1 > n) return NULL; + out_str[i++] = (char) *in_str++; + } else if (*in_str < 0x800) { + if ((size_t)i+2 > n) return NULL; + out_str[i++] = (char)(0xc0 + (*in_str >> 6)); + out_str[i++] = 0x80 + (*in_str & 0x3f); + in_str += 1; + } else if (*in_str >= 0xd800 && *in_str < 0xdc00) { + uint32_t c; + if ((size_t)i+4 > n) return NULL; + c = ((in_str[0] - 0xd800) << 10) + ((in_str[1]) - 0xdc00) + 0x10000; + out_str[i++] = (char)(0xf0 + (c >> 18)); + out_str[i++] = 0x80 + ((c >> 12) & 0x3f); + out_str[i++] = 0x80 + ((c >> 6) & 0x3f); + out_str[i++] = 0x80 + ((c ) & 0x3f); + in_str += 2; + } else if (*in_str >= 0xdc00 && *in_str < 0xe000) { + return NULL; + } else { + if ((size_t)i+3 > n) return NULL; + out_str[i++] = 0xe0 + (*in_str >> 12); + out_str[i++] = 0x80 + ((*in_str >> 6) & 0x3f); + out_str[i++] = 0x80 + ((*in_str ) & 0x3f); + in_str += 1; + } + } + out_str[i] = 0; + return out_str; +} +#endif + +FILE * +ftg_fopen64(const char *filename, const char *type) +{ +#ifdef _WIN32 + /* win32 fopen is not utf-8, it's some stupid codepage */ + ftg_wchar_t wfilename[FTG_STRLEN_LONG]; + ftg_wchar_t wtype[4]; + + ftg_wchar_from_u8(filename, wfilename, FTG_STRLEN_LONG); + ftg_wchar_from_u8(type, wtype, 4); + return _wfopen(wfilename, wtype); +#else + +# if FTG__IO64_EXPLICIT + return fopen64(filename, type); +# else + return fopen(filename, type); +# endif + +#endif +} + +ftg_off_t +ftg_ftell64(FILE *stream) +{ +#ifdef _WIN32 + int64_t tell = _ftelli64(stream); + +#if FTG_DEBUG + if (tell == -1L) + { + const char *fail_reason = strerror(errno); + FTG_ASSERT_FAIL(fail_reason); + } +#endif + return tell; + +#else + +# if FTG__IO64_EXPLICIT + off64_t tell = ftello64(stream); +# else + off_t tell = ftello(stream); +# endif + + FTG_ASSERT(tell >= 0); + return tell; +#endif +} + +int64_t +ftg_fseek64(FILE *stream, ftg_off_t offset, int origin) +{ +#ifdef _WIN32 + int seek = _fseeki64(stream, offset, origin); + FTG_ASSERT(seek == 0); + return (int64_t)seek; +#else + +# if FTG__IO64_EXPLICIT + int seek = fseeko64(stream, offset, origin); +# else + int seek = fseeko(stream, offset, origin); +# endif + + FTG_ASSERT(seek != -1); + return (int64_t)seek; +#endif +} + +struct ftg_dirhandle_s { +#if defined(_WIN32) + HANDLE d; +# elif defined(FTG_POSIX_LIKE) + DIR *d; +#endif +}; + +/* see ftg__test_opendir for iteration example + returns *out, the first file in the directory. + */ +FTGDEF const char * +ftg_opendir(ftg_dirhandle_t *handle, const char *path, char *out, size_t out_len) +{ +#ifdef FTG_POSIX_LIKE + struct dirent *dirent; + bool trunc; + + handle->d = opendir(path); + if (handle->d == NULL) + { + FTG_ASSERT_FAIL("OpenDir failed."); + + *out = 0; + return out; + } + + dirent = readdir(handle->d); + trunc = ftg_strncpy(out, dirent->d_name, out_len); + if (trunc) + { + FTG_ASSERT_FAIL(ftg_va("Truncation on ftg_opendir for path %s.", path)); + /* never return truncated paths */ + *out = 0; + return out; + } + + return out; +#elif defined(_WIN32) + WIN32_FIND_DATAW fd; + ftg_wchar_t search_path[MAX_PATH+3]; + + if (ftg_u8_strlen(path) > MAX_PATH + 3) + { + FTG_ASSERT_FAIL("path is too long"); + *out = 0; + return out; + } + + ftg_wchar_from_u8(path, search_path, MAX_PATH+3); + wcsncat(search_path, L"\\*", 2); + + handle->d = FindFirstFileW(search_path, &fd); + if (handle->d == INVALID_HANDLE_VALUE) + { + FTG_ASSERT_FAIL("OpenDir failed."); + *out = 0; + return out; + } + + ftg_wchar_to_u8(fd.cFileName, out, out_len); + + return out; +#endif +} + +FTGDEF const char * +ftg_readdir(ftg_dirhandle_t *handle, char *out, size_t out_len) +{ +#ifdef FTG_POSIX_LIKE + struct dirent *dirent; + bool trunc; + + dirent = readdir(handle->d); + if (dirent==NULL) + { + *out = 0; + return out; + } + + trunc = ftg_strncpy(out, dirent->d_name, out_len); + if (trunc) + { + FTG_ASSERT_FAIL(ftg_va("Truncation on ftg_readdir for path %s.", + dirent->d_name)); + *out = 0; + return out; + } + + return out; + +#elif defined(_WIN32) + WIN32_FIND_DATAW fd; + + if (FindNextFileW(handle->d, &fd) != 0) + { + ftg_wchar_to_u8(fd.cFileName, out, out_len); + } + else + { + DWORD error = GetLastError(); + if (error == ERROR_NO_MORE_FILES) + { + *out = 0; + return out; + } + else + { + FTG_ASSERT_FAIL(ftg_va("ftg_readdir() error %d", error)); + *out = 0; + return out; + } + } + + return out; +#endif +} + +FTGDEF void +ftg_closedir(ftg_dirhandle_t *handle) +{ +#ifdef FTG_POSIX_LIKE + int ret = closedir(handle->d); + FTG_ASSERT(ret != -1); + FTG_UNUSED(ret); + + return; + +#elif defined(_WIN32) + if (!FindClose(handle->d)) + { + FTG_ASSERT_FAIL(ftg_va("ftg_closedir() error: %d", GetLastError())); + } +#endif +} + +/* returns true if path exists and is a directory */ +FTGDEF bool +ftg_is_dir(const char *path) +{ +#ifdef FTG_POSIX_LIKE + struct stat buf; + if (stat(path, &buf) == -1) + return false; /* does not exist */ + + return (S_ISDIR(buf.st_mode)); +#elif defined(_WIN32) + ftg_wchar_t wpath[FTG_STRLEN_LONG]; + + DWORD attr = GetFileAttributesW(ftg_wchar_from_u8(path, wpath, FTG_STRLEN_LONG)); + if (attr == INVALID_FILE_ATTRIBUTES) + return false; /* does not exist */ + + return ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY); +#endif +} + +/* returns true if the dir or file exists */ +FTGDEF bool +ftg_path_exists(const char *path) +{ +#ifdef FTG_POSIX_LIKE + return access(path, F_OK) != -1; +#elif defined(_WIN32) + ftg_wchar_t wide_path[MAX_PATH]; + DWORD attrib; + + ftg_wchar_from_u8(path, wide_path, MAX_PATH); + attrib = GetFileAttributesW(wide_path); + + return (attrib != INVALID_FILE_ATTRIBUTES); +#endif +} + +/* make a directory that must not already exist */ +FTGDEF bool +ftg_mkdir(const char *path) +{ +#ifdef FTG_POSIX_LIKE + int result = mkdir(path, FTG_DIRECTORY_MODE); + if (result != 0) + { + FTG_ASSERT_FAIL(strerror(errno)); + } + + return (result == 0); +#elif defined(_WIN32) + ftg_wchar_t wide_path[MAX_PATH]; + int result; + + ftg_wchar_from_u8(path, wide_path, MAX_PATH); + result = _wmkdir(wide_path); + if (result != 0) + { + FTG_ASSERT_FAIL(strerror(errno)); + } + + return (result == 0); +#endif +} + +/* recursively make all directories in *path that are not yet created */ +FTGDEF void +ftg_mkalldirs(const char *path) +{ + if (!ftg_is_dir(path)) + { + if(path[0] != '\0') + { + bool trunc; + char parent_path[FTG_STRLEN_LONG] = {'\0'}; + + trunc = ftg_push_path(parent_path, path, FTG_STRLEN_LONG); + FTG_ASSERT(!trunc); + FTG_UNUSED(trunc); + ftg_pop_path(parent_path); + + ftg_mkalldirs(parent_path); + ftg_mkdir(path); + } + } +} + +static void +ftg__remove_dir_contents(const char *path) +{ + ftg_dirhandle_t dir_handle; + char dir_path[FTG_STRLEN_LONG]; + const char *filename; + + int i = 5; + + filename = ftg_opendir(&dir_handle, path, dir_path, FTG_STRLEN_LONG); + while(*filename) + { + if (strcmp(filename, ".") && strcmp(filename, "..")) + { + char child_path[FTG_STRLEN_LONG] = {'\0'}; + ftg_push_path(child_path, path, FTG_STRLEN_LONG); + ftg_push_path(child_path, filename, FTG_STRLEN_LONG); + + i--; + if (i == 0) + exit(0); + ftg_rmalldirs(child_path); + } + + filename = ftg_readdir(&dir_handle, dir_path, FTG_STRLEN_LONG); + } + + ftg_closedir(&dir_handle); +} + +/* recursively remove all directories in *path, deleting contents */ +FTGDEF void +ftg_rmalldirs(const char *path) +{ + if (ftg_is_dir(path)) + { + ftg__remove_dir_contents(path); + ftg_rmdir(path); + } + else + { + int result = remove(path); + FTG_ASSERT(result == 0); + FTG_UNUSED(result); + } +} + +/* remove a directory that must already exist and be empty */ +FTGDEF bool +ftg_rmdir(const char *path) +{ +#ifdef FTG_POSIX_LIKE + int result = rmdir(path); + if (result != 0) + { + FTG_ASSERT_FAIL(strerror(errno)); + } + + return (result == 0); +#elif defined(_WIN32) + ftg_wchar_t wide_path[MAX_PATH]; + int result; + + ftg_wchar_from_u8(path, wide_path, MAX_PATH); + result = _wrmdir(wide_path); + if (result != 0) + { + FTG_ASSERT_FAIL(strerror(errno)); + } + + return (result == 0); +#endif +} + +/* add a console on windows -- exit silently on others. + note that only one console can exist per process */ +#ifdef _WIN32 +static FILE *ftg__io[3] = {0,0,0}; +#endif + +FTGDEF void +ftg_alloc_console(void) +{ +#if defined(_WIN32) + int i; + bool result = AllocConsole(); + FTG_ASSERT(result); FTG_UNUSED(result); + if (!result) + return; + +#if FTG_DEBUG + for (i = 0; i < 3; i++) + FTG_ASSERT(!ftg__io[i]); +#endif + FTG_UNUSED(i); + + ftg__io[0] = freopen("conin$","r",stdin); + ftg__io[1] = freopen("conout$","w",stdout); + ftg__io[2] = freopen("conout$","w",stderr); +#endif +} + +FTGDEF void +ftg_free_console(void) +{ +#if defined(_WIN32) + int i; + + FreeConsole(); + for (i = 0; i < 3; i++) + { + if (!ftg__io[i]) continue; + fclose(ftg__io[i]); + ftg__io[i] = NULL; + } +#endif +} + +#endif /* !FTG_CORE_NO_STDIO */ + + +// Paul Hsieh hash (borrowed from stb.h with type changes for +// portability) +#define ftg__get16_slow(p) ((p)[0] + ((p)[1] << 8)) +#if defined(_MSC_VER) +#define ftg__get16(p) (*((unsigned short *) (p))) +#else +#define ftg__get16(p) ftg__get16_slow(p) +#endif + +FTGDEF uint32_t +ftg_hash_fast(const void *p, uint32_t len) +{ + unsigned char *q = (unsigned char *) p; + uint32_t hash = len; + + if (len <= 0 || q == NULL) return 0; + + /* Main loop */ + if (((size_t) q & 1) == 0) { + for (;len > 3; len -= 4) { + uint32_t val; + hash += ftg__get16(q); + val = (ftg__get16(q+2) << 11); + hash = (hash << 16) ^ hash ^ val; + q += 4; + hash += hash >> 11; + } + } else { + for (;len > 3; len -= 4) { + uint32_t val; + hash += ftg__get16_slow(q); + val = (ftg__get16_slow(q+2) << 11); + hash = (hash << 16) ^ hash ^ val; + q += 4; + hash += hash >> 11; + } + } + + /* Handle end cases */ + switch (len) { + case 3: hash += ftg__get16_slow(q); + hash ^= hash << 16; + hash ^= q[2] << 18; + hash += hash >> 11; + break; + case 2: hash += ftg__get16_slow(q); + hash ^= hash << 11; + hash += hash >> 17; + break; + case 1: hash += q[0]; + hash ^= hash << 10; + hash += hash >> 1; + break; + case 0: break; + } + + /* Force "avalanching" of final 127 bits */ + hash ^= hash << 3; + hash += hash >> 5; + hash ^= hash << 4; + hash += hash >> 17; + hash ^= hash << 25; + hash += hash >> 6; + + return hash; +} + +FTGDEF uint32_t +ftg_hash_number(uint32_t hash) +{ + hash ^= hash << 3; + hash += hash >> 5; + hash ^= hash << 4; + hash += hash >> 17; + hash ^= hash << 25; + hash += hash >> 6; + + return hash; +} + + + + +/* stopwatch (code timing routines) */ + +#ifdef FTG_ENABLE_STOPWATCH + +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# undef WIN32_LEAN_AND_MEAN +#elif defined(__APPLE__) +# include +# define FTG__CLOCK_MACH +#else +# include +# define FTG__CLOCK_GETTIME +# ifdef CLOCK_MONOTONIC_RAW +# define FTG__CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW +# else +# define FTG__CLOCK_MONOTONIC CLOCK_MONOTONIC +# endif +#endif + +#ifndef FTG_STOPWATCH_REPORTER +# define FTG_STOPWATCH_REPORTER ftg__default_stopwatch_reporter +#endif + + +#ifdef FTG__CLOCK_GETTIME +static uint64_t ftg__stopwatch_get_usec_since_init(void) +{ + static struct timespec ftg__init_time = {0,0}; + struct timespec now, since_init; + uint64_t usec; + int ret; + + if (ftg__init_time.tv_sec == 0 && ftg__init_time.tv_nsec == 0) + { + ret = clock_gettime(FTG__CLOCK_MONOTONIC, &ftg__init_time); + FTG_ASSERT(ret==0); FTG_UNUSED(ret); + } + + ret = clock_gettime(FTG__CLOCK_MONOTONIC, &now); + FTG_ASSERT(ret==0); FTG_UNUSED(ret); + + since_init.tv_sec = now.tv_sec - ftg__init_time.tv_sec; + since_init.tv_nsec = now.tv_nsec - ftg__init_time.tv_nsec; + + usec = (since_init.tv_sec * 1000000) + (since_init.tv_nsec / 1000); + + return usec; +} +#endif + + +static uint64_t +ftg__stopwatch_elapsed_usec(struct ftg_stopwatch_s *sw) +{ +#ifdef _WIN32 + LARGE_INTEGER end_time, freq, elapsed; + + QueryPerformanceCounter(&end_time); + QueryPerformanceFrequency(&freq); + + // calculate elapsed time + elapsed.QuadPart = end_time.QuadPart - sw->start_time; + + // convert to microseconds + elapsed.QuadPart *= 1000000; + + // divide by ticks per second + elapsed.QuadPart /= freq.QuadPart; + + return (uint64_t)elapsed.QuadPart; +#elif defined(FTG__CLOCK_MACH) + static mach_timebase_info_data_t timebase = {0,0}; + + uint64_t end, elapsed; + + if (timebase.denom == 0) + mach_timebase_info(&timebase); + + end = mach_absolute_time(); + elapsed = end - sw->start_time; + + // convert to microseconds before applying timebase + elapsed /= 1000; + elapsed *= timebase.numer / timebase.denom; + + return elapsed; + +#elif defined(FTG__CLOCK_GETTIME) + return ftg__stopwatch_get_usec_since_init() - sw->start_time; +#endif +} + +static void +ftg__stopwatch_set_start_time(struct ftg_stopwatch_s *sw) +{ +#ifdef _WIN32 + LARGE_INTEGER start_time; + + QueryPerformanceCounter(&start_time); + sw->start_time = (int64_t)start_time.QuadPart; + +#elif defined(FTG__CLOCK_MACH) + sw->start_time = mach_absolute_time(); + +#elif defined(FTG__CLOCK_GETTIME) + sw->start_time = ftg__stopwatch_get_usec_since_init(); +#endif +} + +void +ftg__stopwatch_next_bucket(struct ftg_stopwatch_s *sw, const char *bucket_name, size_t bucket_idx) +{ + // if this is hit then FTG_STOPWATCH_START was not called after FTG_STOPWATCH_DECL. + FTG_ASSERT(sw->current_bucket != FTG__MAX_STOPWATCH_TIMES+100); + + // it is possible to end up entering a sub-function that is being logged without coming + // from the parent which is logging. This guards against incorrectly logging the time. + if (sw->currently_logging == false) + return; + + if (sw->times[bucket_idx] == 0) + { + bool truncate = ftg_strncpy(sw->time_names[bucket_idx], bucket_name, FTG_STRLEN_SHORT); + FTG_UNUSED(truncate); + } + + sw->times[sw->current_bucket] += ftg__stopwatch_elapsed_usec(sw); + ftg__stopwatch_set_start_time(sw); + + if (bucket_idx >= FTG__MAX_STOPWATCH_TIMES) + { + FTG_ASSERT_FAIL("stopwatch with bucket index > FTG__MAX_STOPWATCH_TIMES specified. not dumped."); + sw->currently_logging = false; + return; + } + + sw->current_bucket = bucket_idx; +} + +void +ftg__stopwatch_start(struct ftg_stopwatch_s *sw, const char *name, const char *bucket_name, size_t bucket_idx) +{ + bool truncate = ftg_strncpy(sw->name, name, FTG_STRLEN_SHORT); + FTG_UNUSED(truncate); + + sw->currently_logging = true; + ftg_bzero(sw->times, sizeof(sw->times)); + ftg_bzero(sw->time_names, sizeof(sw->time_names)); + + // todo: compress this + if (bucket_idx >= FTG__MAX_STOPWATCH_TIMES) + { + FTG_ASSERT_FAIL("stopwatch with bucket index > FTG__MAX_STOPWATCH_TIMES specified. not dumped."); + return; + } + + sw->current_bucket = bucket_idx; + truncate = ftg_strncpy(sw->time_names[bucket_idx], bucket_name, FTG_STRLEN_SHORT); + FTG_UNUSED(truncate); + + // start counter at the end of this function to avoid profiling setup work. + ftg__stopwatch_set_start_time(sw); +} + +void +ftg__stopwatch_stop(struct ftg_stopwatch_s *sw) +{ + // if this is hit then FTG_STOPWATCH_START was not called after FTG_STOPWATCH_DECL. + FTG_ASSERT(sw->current_bucket != FTG__MAX_STOPWATCH_TIMES+100); + + sw->times[sw->current_bucket] += ftg__stopwatch_elapsed_usec(sw); + + sw->currently_logging = false; + FTG_STOPWATCH_REPORTER(sw); +} + +void +ftg__default_stopwatch_reporter(struct ftg_stopwatch_s *sw) +{ + size_t i; + uint64_t accum_ms = 0; +#if FTG_DEBUG + const char debug_str[] = "FTG_DEBUG=1 "; +#else + const char debug_str[] = ""; +#endif + + printf("%sstopwatch %s completed:\n", debug_str, sw->name); + for (i = 0; i < FTG__MAX_STOPWATCH_TIMES; ++i) + { + if (sw->times[i] == 0 && sw->time_names[i][0] == '\0') + continue; + + accum_ms += sw->times[i] / 1000; + printf("\t%s[%" FTG_SPEC_SIZE_T "]: %" FTG_SPEC_UINT64 " usec\n", + sw->time_names[i], i, sw->times[i]); + } + + printf("total ms: %" FTG_SPEC_UINT64 "\n", accum_ms); +} + +#endif /* FTG_ENABLE_STOPWATCH */ + +/* test suite + + ftg_decl_suite() should be called somewhere in the declaring + C file. + */ +#ifdef FTGT_TESTS_ENABLED + +#include + +struct ftg_testvars_s { + char *s1, *s2, *s3; +}; + +static struct ftg_testvars_s tv; + +static int ftg__test_setup(void) { + tv.s1 = (char*)FTG_MALLOC(sizeof(char*), FTG_STRLEN); + tv.s2 = (char*)FTG_MALLOC(sizeof(char*), FTG_STRLEN); + tv.s3 = (char*)FTG_MALLOC(sizeof(char*), FTG_STRLEN); + + strcpy(tv.s1, "catdoghamster"); + strcpy(tv.s2, "CATDOGhamster"); + strcpy(tv.s3, "fooballs"); + + return (tv.s1&&tv.s2&&tv.s3)?0:1; +} + +static int ftg__test_teardown(void) { + FTG_FREE(tv.s1); + FTG_FREE(tv.s2); + FTG_FREE(tv.s3); + + return 0; +} + +static int ftg__test_stricmp(void) +{ + FTGT_ASSERT(ftg_stricmp(tv.s1,tv.s2)==0); + FTGT_ASSERT(ftg_stricmp(tv.s1,tv.s2)==0); + FTGT_ASSERT(ftg_stricmp(tv.s1,tv.s2)==0); + FTGT_ASSERT(ftg_stricmp(tv.s1,tv.s3)!=0); + FTGT_ASSERT(ftg_stricmp(tv.s1,tv.s1)==0); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_stristr(void) +{ + FTGT_ASSERT(ftg_stristr(tv.s1, "dog") == tv.s1+3); + FTGT_ASSERT(ftg_stristr(tv.s1, "DOG") == tv.s1+3); + FTGT_ASSERT(ftg_stristr(tv.s1, tv.s1) == tv.s1); + FTGT_ASSERT(ftg_stristr(tv.s1, "\0") == tv.s1+strlen(tv.s1)); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_strncpy(void) +{ + int trunc = 0; + char buf[FTG_STRLEN]; + trunc = ftg_strncpy(buf, tv.s1, FTG_STRLEN); + FTGT_ASSERT(strlen(buf)==strlen(tv.s1)); + FTGT_ASSERT(!trunc); + + trunc = ftg_strncpy(buf, tv.s1, 0); + FTGT_ASSERT(ftgt_test_errorlevel()); + + trunc = ftg_strncpy(buf, tv.s1, 7); + FTGT_ASSERT(strcmp(buf, "catdog")==0); + FTGT_ASSERT(trunc); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_strcatall(void) +{ + char *str = ftg_strcatall(3, "one", "two", "three"); + FTGT_ASSERT(strcmp(str, "onetwothree")==0); + FTG_FREE(str); + + str = ftg_strcatall(0); + FTGT_ASSERT(str[0] == '\0'); + FTG_FREE(str); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_va(void) +{ + char *buf = ftg_va("hello"); + FTGT_ASSERT(strcmp(buf, "hello")==0); + + buf = ftg_va("%d %d", 2, 3); + FTGT_ASSERT(strcmp(buf, "2 3")==0); + + buf = ftg_va("%d", (int)1048576); + FTGT_ASSERT(strcmp(buf, "1048576")==0); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_correct_dirslash(void) +{ + char dir[255]; + + strcpy(dir, "/dir/a"); + ftg_correct_dirslash(dir); + FTGT_ASSERT(dir[0] == FTG_DIRSLASH); + FTGT_ASSERT(dir[4] == FTG_DIRSLASH); + + strcpy(dir, "\\dir\\a"); + ftg_correct_dirslash(dir); + FTGT_ASSERT(dir[0] == FTG_DIRSLASH); + FTGT_ASSERT(dir[4] == FTG_DIRSLASH); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_opendir(void) +{ + ftg_dirhandle_t dir; + char path_str[FTG_STRLEN_LONG]; + int dot_count = 0; + + ftg_opendir(&dir, ".", path_str, FTG_STRLEN_LONG); + while (*path_str) + { + if (strcmp(path_str, ".")==0) + dot_count++; + + if (strcmp(path_str, "..")==0) + dot_count++; + + /* finished with path_str, get the next one */ + ftg_readdir(&dir, path_str, FTG_STRLEN_LONG); + } + ftg_closedir(&dir); + + FTGT_ASSERT(dot_count==2); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_is_dir(void) +{ +#ifdef FTG_POSIX_LIKE + FTGT_ASSERT(ftg_is_dir("/")); +#else + FTGT_ASSERT(ftg_is_dir("c:\\")); +#endif + + FTGT_ASSERT(!ftg_is_dir("this does not exist")); + + FTGT_ASSERT(ftg_is_dirslash('/')); + FTGT_ASSERT(ftg_is_dirslash('\\')); + FTGT_ASSERT(!ftg_is_dirslash(' ')); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_get_filename_ext(void) +{ + char *ext; + char str[1024]; + + /* regular */ + ext = ftg_get_filename_ext("hello.txt"); + FTGT_ASSERT(strcmp(ext, "txt") == 0); + + /* multiple extensions */ + ext = ftg_get_filename_ext("hello.wat.txt"); + FTGT_ASSERT(strcmp(ext, "txt") == 0); + + /* dot in directory part of path */ + strcpy(str, "/some.ext/hello.txt"); + ftg_correct_dirslash(str); + ext = ftg_get_filename_ext(str); + FTGT_ASSERT(strcmp(ext, "txt") == 0); + + strcpy(str, "/some.ext/hello"); + ftg_correct_dirslash(str); + ext = ftg_get_filename_ext(str); + FTGT_ASSERT(ext[0] == '\0'); + + strcpy(str, "/some.ext/"); + ftg_correct_dirslash(str); + ext = ftg_get_filename_ext(str); + FTGT_ASSERT(ext[0] == '\0'); + + /* no extension */ + ext = ftg_get_filename_ext("hello"); + FTGT_ASSERT(ext[0] == '\0'); + + /* empty */ + ext = ftg_get_filename_ext(""); + FTGT_ASSERT(ext[0] == '\0'); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_get_filename_from_path(void) +{ + int i; + const char *tests[][2] = + { + {"bar.txt", "bar.txt"}, + {"foo/bar.txt", "bar.txt"}, + {"/a/b/", ""}, + {NULL, NULL} + }; + + for (i = 0; tests[i][0] != NULL; i++) + { + const char *q = tests[i][0]; + const char *a = tests[i][1]; + char q_buf[FTG_STRLEN]; + bool trunc; + + trunc = ftg_strncpy(q_buf, q, FTG_STRLEN); + FTG_ASSERT(!trunc); + ftg_correct_dirslash(q_buf); + + FTGT_ASSERT(strcmp(ftg_get_filename_from_path(q_buf), a)==0); + } + + return ftgt_test_errorlevel(); +} + +static int ftg__test_file_rw(void) +{ + const char tmp_file[] = "ftg_core_tmp_file.txt"; + const char test_str[] = "hello\nworld!"; + unsigned char *read_str; + ftg_off_t read_len; + bool result; + + result = ftg_file_write(tmp_file, (uint8_t*)test_str, strlen(test_str)+1); + FTGT_ASSERT(result); + + read_str = ftg_file_read(tmp_file, true, &read_len); + FTGT_ASSERT(memcmp(read_str, test_str, strlen(test_str)+1)==0); + + FTG_FREE(read_str); + // todo: rm temp file + + return ftgt_test_errorlevel(); +} + +static int ftg__test_ia(void) +{ + struct ftg_index_array_s ia = FTG_IA_INIT_ZERO; + size_t i; + FTGT_ASSERT(!ftg_ia_is_init(&ia)); + + for (i = 0; i < FTG_IA_INITIAL_RECORD_COUNT * 2; ++i) + { + bool success = ftg_ia_append(&ia, i*2); + FTGT_ASSERT(success); + } + + FTGT_ASSERT(ia.records > FTG_IA_INITIAL_RECORD_COUNT); + + for (i = 0; i < ia.count; i++) + { + FTGT_ASSERT(ia.indices[i] == i*2); + } + + ftg_ia_free(&ia); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_dircreate(void) +{ + bool success; + if (ftg_is_dir("testdir")) + { + printf("removing testdir which shouldn't exist"); + success = ftg_rmdir("testdir"); + FTG_ASSERT(success); + } + + success = ftg_mkdir("testdir"); + FTGT_ASSERT(success); + FTGT_ASSERT(ftg_is_dir("testdir")); + + // this assumes FTG_DIRECTORY_MODE allows for the deletion + // of the created directory. + success = ftg_rmdir("testdir"); + FTGT_ASSERT(success); + FTGT_ASSERT(!ftg_is_dir("testdir")); + + ftg_mkalldirs("one/two/three"); + FTGT_ASSERT(ftg_is_dir("one/two/three")); + ftg_rmalldirs("one"); + FTGT_ASSERT(!ftg_is_dir("one")); + + return ftgt_test_errorlevel(); +} + +static int ftg__test_push_path(void) +{ + char buffer[64]; + bool trunc; + int i; + + // [0] + [1] must equal [2] to pass the test + const char * tests[][3] = + { + { "/a", "b", "/a/b" }, + { "/a", "/b", "/a/b" }, + { "/a", "b/", "/a/b" }, + { "/a", "/b/", "/a/b" }, + { "/a/", "b", "/a/b" }, + { "/a/", "/b", "/a/b" }, + { "/a/", "b/", "/a/b" }, + { "/a/", "/b/", "/a/b" }, + + { "a", "b", "a/b" }, + { "a", "/b", "a/b" }, + { "a", "b/", "a/b" }, + { "a", "/b/", "a/b" }, + { "a/", "b", "a/b" }, + { "a/", "/b", "a/b" }, + { "a/", "b/", "a/b" }, + { "a/", "/b/", "a/b" }, + + { "", "b", "b" }, + { "", "/b", "/b" }, + { "", "b/", "b" }, + { "", "/b/", "/b" }, + { "/", "b", "/b" }, + { "/", "/b", "/b" }, + { "/", "b/", "/b" }, + { "/", "/b/", "/b" }, + + { "a", "", "a" }, + { "a/", "", "a" }, + { "/a", "", "/a" }, + { "/a/", "", "/a" }, + { "a", "/", "a" }, + { "a/", "/", "a" }, + { "/a", "/", "/a" }, + { "/a/", "/", "/a" }, + + { "", "", "" }, + { "/", "", "/" }, + { "", "/", "/" }, + { "/", "/", "/" }, + + { "//a", "", "/a" }, + { "a//", "", "a" }, + { "", "//b", "/b" }, + { "", "b//", "b" }, + { "//a//", "//b//","/a/b" }, + + { NULL, NULL, NULL } + }; + + for(i = 0; tests[i][0] != NULL; i++) + { + const char *a = tests[i][0]; + const char *b = tests[i][1]; + const char *c = tests[i][2]; + char c_buf[64]; + + trunc = ftg_strncpy(buffer, a, 8); + FTG_ASSERT(!trunc); + ftg_push_path(buffer, b, 8); + ftg_correct_dirslash(buffer); + + trunc = ftg_strncpy(c_buf, c, 64); + FTG_ASSERT(!trunc); + ftg_correct_dirslash(c_buf); + + FTGT_ASSERT(strcmp(buffer, c_buf) == 0); + } + + // test truncation cases + trunc = ftg_strncpy(buffer, "aaaaaaa", 8); + FTG_ASSERT(!trunc); + trunc = ftg_push_path(buffer, "a", 8); + FTGT_ASSERT(trunc); + FTGT_ASSERT(strcmp(buffer, "aaaaaaa") == 0); + + trunc = ftg_strncpy(buffer, "aaaaaa", 8); + FTG_ASSERT(!trunc); + trunc = ftg_push_path(buffer, "a", 8); + ftg_correct_dirslash(buffer); + FTGT_ASSERT(trunc); + FTGT_ASSERT(strcmp(buffer, ftg_va("aaaaaa%c", FTG_DIRSLASH))==0); + + trunc = ftg_strncpy(buffer, "aaaaaa/", 8); + FTG_ASSERT(!trunc); + trunc = ftg_push_path(buffer, "a", 8); + ftg_correct_dirslash(buffer); + FTGT_ASSERT(trunc); + FTGT_ASSERT(strcmp(buffer, ftg_va("aaaaaa%c", FTG_DIRSLASH))==0); + + trunc = ftg_strncpy(buffer, "a/", 8); + FTG_ASSERT(!trunc); + trunc = ftg_push_path(buffer, "aaaaaa", 8); + ftg_correct_dirslash(buffer); + FTGT_ASSERT(trunc); + FTGT_ASSERT(strcmp(buffer, ftg_va("a%caaaaa", FTG_DIRSLASH))==0); + + return ftgt_test_errorlevel(); +} + + +static int ftg__test_pop_path(void) +{ + const char * paths[][2] = + { + { "/dir/file.ext", "/dir" }, + { "/dir/file", "/dir" }, + { "/dir/", "/" }, + { "/dir", "/" }, + { "/", "/" }, + { "dir", "" }, + { "", "" }, + { NULL, NULL } + }; + + int i; + for (i = 0; paths[i][0] != NULL; i++) + { + const char *a = paths[i][0]; + const char *b = paths[i][1]; + char path[FTG_STRLEN]; + bool trunc; + + trunc = ftg_strncpy(path, a, FTG_STRLEN); + FTG_ASSERT(!trunc); + ftg_pop_path(path); + FTGT_ASSERT(strcmp(path, b) == 0); + } + + return ftgt_test_errorlevel(); +} + +static int ftg__test_strsplit(void) +{ + const char *p; + size_t i; + size_t len; + + const char PATH[] = "ab:cd:ef"; + const char WILL_REACH_END[] = "abc"; + const char EMPTY[] = ""; + + FTGT_ASSERT(ftg_strsplit(PATH, ':', 0, &len) == &PATH[0] && len == 2); + FTGT_ASSERT(ftg_strsplit(PATH, ':', 1, &len) == &PATH[3] && len == 2); + FTGT_ASSERT(ftg_strsplit(PATH, ':', 2, &len) == &PATH[6] && len == 2); + FTGT_ASSERT(ftg_strsplit(PATH, ':', 3, &len) == NULL && len == 0); + + + FTGT_ASSERT(ftg_strsplit(WILL_REACH_END, ':', 1, &len) == NULL && len == 0); + + FTGT_ASSERT(ftg_strsplit(EMPTY, ':', 0, &len) == &EMPTY[0] && len == 0); + FTGT_ASSERT(ftg_strsplit(EMPTY, ':', 1, &len) == NULL && len == 0); + + // iteration usage example + for (p = PATH, i = 0; (p = ftg_strsplit(PATH, ':', i, &len)) != NULL; i++) { + + switch(i) { + case 0: + FTGT_ASSERT(p == &PATH[0] && len == 2); + break; + + case 1: + FTGT_ASSERT(p == &PATH[3] && len == 2); + break; + + case 2: + FTGT_ASSERT(p == &PATH[6] && len == 2); + break; + + default: + FTGT_ASSERT(0); + } + + } + + return ftgt_test_errorlevel(); +} + +FTGDEF +void ftg_decl_suite(void) +{ + ftgt_suite_s *suite = ftgt_create_suite(NULL, "ftg_core", ftg__test_setup, ftg__test_teardown); + FTGT_ADD_TEST(suite, ftg__test_stricmp); + FTGT_ADD_TEST(suite, ftg__test_stristr); + FTGT_ADD_TEST(suite, ftg__test_strncpy); + FTGT_ADD_TEST(suite, ftg__test_strcatall); + FTGT_ADD_TEST(suite, ftg__test_va); + FTGT_ADD_TEST(suite, ftg__test_correct_dirslash); + FTGT_ADD_TEST(suite, ftg__test_opendir); + FTGT_ADD_TEST(suite, ftg__test_is_dir); + FTGT_ADD_TEST(suite, ftg__test_get_filename_ext); + FTGT_ADD_TEST(suite, ftg__test_get_filename_from_path); + FTGT_ADD_TEST(suite, ftg__test_file_rw); + FTGT_ADD_TEST(suite, ftg__test_ia); + FTGT_ADD_TEST(suite, ftg__test_dircreate); + FTGT_ADD_TEST(suite, ftg__test_push_path); + FTGT_ADD_TEST(suite, ftg__test_pop_path); + FTGT_ADD_TEST(suite, ftg__test_strsplit); +} + + +#ifdef FTG_JUST_TEST +int main(void) +{ + ftg_decl_suite(); + return ftgt_run_all_tests(NULL); +} +#endif /* FTG_JUST_TEST */ +#endif /* FTGT_TESTS_ENABLED */ +#endif /* FTG_IMPLEMENT_CORE */ +#endif /* eof */ diff --git a/src/nfd_common.c b/src/nfd_common.c index 55517f5..f8a9421 100644 --- a/src/nfd_common.c +++ b/src/nfd_common.c @@ -9,6 +9,10 @@ #include #include "nfd_common.h" +#define FTG_IMPLEMENT_CORE +#include "ftg_core.h" + + static char g_errorstr[NFD_MAX_STRLEN] = {0}; /* public routines */ @@ -140,3 +144,20 @@ int NFDi_IsFilterSegmentChar( char ch ) return (ch==','||ch==';'||ch=='\0'); } +void NFDi_SplitPath(const char *path, const char **out_dir, const char **out_filename) { + + // test filesystem to early out test on 'c:\path', which can't be + // determined to not be a filename called `path` at `c:\` + // otherwise. + if (ftg_is_dir(path)) { + *out_dir = path; + *out_filename = NULL; + return; + } + + const char *filename = ftg_get_filename_from_path(path); + if (filename[0]) { + *out_filename = filename; + } + *out_dir = path; +} diff --git a/src/nfd_common.h b/src/nfd_common.h index 1a9ab16..bc0b0c7 100644 --- a/src/nfd_common.h +++ b/src/nfd_common.h @@ -30,7 +30,7 @@ void NFDi_SetError( const char *msg ); int NFDi_SafeStrncpy( char *dst, const char *src, size_t maxCopy ); int32_t NFDi_UTF8_Strlen( const nfdchar_t *str ); int NFDi_IsFilterSegmentChar( char ch ); - +void NFDi_SplitPath(const char *path, const char **out_dir, const char **out_filename); #ifdef __cplusplus } #endif diff --git a/src/nfd_win.cpp b/src/nfd_win.cpp index 949da2b..4757f23 100644 --- a/src/nfd_win.cpp +++ b/src/nfd_win.cpp @@ -27,7 +27,6 @@ #include #include "nfd_common.h" - #define COM_INITFLAGS ::COINIT_APARTMENTTHREADED | ::COINIT_DISABLE_OLE1DDE static BOOL COMIsInitialized(HRESULT coResult) @@ -104,11 +103,11 @@ static int CopyWCharToExistingNFDCharBuffer( const wchar_t *inStr, nfdchar_t *ou // allocs the space in outStr -- call free() -static void CopyNFDCharToWChar( const nfdchar_t *inStr, wchar_t **outStr ) +static void CopyNFDCharToWChar( const nfdchar_t *inStr, size_t inStrLen, wchar_t **outStr ) { - int inStrByteCount = static_cast(strlen(inStr)); + int inStrByteCount = (int)inStrLen; /* byte count does not include terminator */ int charsNeeded = MultiByteToWideChar(CP_UTF8, 0, - inStr, inStrByteCount, + inStr, (int)inStrByteCount, NULL, 0 ); assert( charsNeeded ); assert( !*outStr ); @@ -118,17 +117,10 @@ static void CopyNFDCharToWChar( const nfdchar_t *inStr, wchar_t **outStr ) if ( !*outStr ) return; - int ret = MultiByteToWideChar(CP_UTF8, 0, - inStr, inStrByteCount, - *outStr, charsNeeded); + MultiByteToWideChar(CP_UTF8, 0, + inStr, (int)inStrByteCount, + *outStr, charsNeeded); (*outStr)[charsNeeded-1] = '\0'; - -#ifdef _DEBUG - int inStrCharacterCount = static_cast(NFDi_UTF8_Strlen(inStr)); - assert( ret == inStrCharacterCount ); -#else - _NFD_UNUSED(ret); -#endif } @@ -211,8 +203,8 @@ static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char { /* end of filter -- add it to specList */ - CopyNFDCharToWChar( specbuf, (wchar_t**)&specList[specIdx].pszName ); - CopyNFDCharToWChar( specbuf, (wchar_t**)&specList[specIdx].pszSpec ); + CopyNFDCharToWChar( specbuf, strlen(specbuf), (wchar_t**)&specList[specIdx].pszName ); + CopyNFDCharToWChar( specbuf, strlen(specbuf), (wchar_t**)&specList[specIdx].pszSpec ); memset( specbuf, 0, sizeof(char)*NFD_MAX_STRLEN ); ++specIdx; @@ -347,13 +339,24 @@ static nfdresult_t AllocPathSet( IShellItemArray *shellItems, nfdpathset_t *path } -static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath ) +static nfdresult_t SetDefaultDir( IFileDialog *dialog, const char *defaultPath ) { - if ( !defaultPath || strlen(defaultPath) == 0 ) + if ( !defaultPath || defaultPath[0] == '\0' ) return NFD_OKAY; + const char *defaultDir, *defaultFilename; + NFDi_SplitPath(defaultPath, &defaultDir, &defaultFilename); + + size_t defaultDirLen; + if (defaultFilename) { + assert(defaultFilename > defaultDir); + defaultDirLen = defaultFilename - defaultDir; + } else { + defaultDirLen = strlen(defaultDir); + } + wchar_t *defaultPathW = {0}; - CopyNFDCharToWChar( defaultPath, &defaultPathW ); + CopyNFDCharToWChar( defaultPath, defaultDirLen, &defaultPathW ); IShellItem *folder; HRESULT result = SHCreateItemFromParsingName( defaultPathW, NULL, IID_PPV_ARGS(&folder) ); @@ -381,6 +384,26 @@ static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath return NFD_OKAY; } +static void SetDefaultFile( IFileDialog *dialog, const char *defaultPath) +{ + if ( !defaultPath || defaultPath[0] == '\0' ) + return; + + const char *defaultDir, *defaultFilename; + NFDi_SplitPath(defaultPath, &defaultDir, &defaultFilename); + + // no filename in to set -- nothing to do + if (!defaultFilename) + return; + + wchar_t *defaultFilenameW = {0}; + CopyNFDCharToWChar( defaultFilename, strlen(defaultFilename), &defaultFilenameW); + + dialog->SetFileName( defaultFilenameW ); + + NFDi_Free( defaultFilenameW ); +} + /* public */ @@ -416,11 +439,14 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, goto end; } - // Set the default path - if ( !SetDefaultPath( fileOpenDialog, defaultPath ) ) + // Set the default dir + if ( !SetDefaultDir( fileOpenDialog, defaultPath ) ) { goto end; - } + } + + // Set the default filename + SetDefaultFile( fileOpenDialog, defaultPath ); // Show the dialog. result = fileOpenDialog->Show(NULL); @@ -507,12 +533,15 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, goto end; } - // Set the default path - if ( !SetDefaultPath( fileOpenDialog, defaultPath ) ) + // Set the default dir + if ( !SetDefaultDir( fileOpenDialog, defaultPath ) ) { goto end; } + // Set the default filename + SetDefaultFile( fileOpenDialog, defaultPath ); + // Set a flag for multiple options DWORD dwFlags; result = fileOpenDialog->GetOptions(&dwFlags); @@ -600,12 +629,15 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, goto end; } - // Set the default path - if ( !SetDefaultPath( fileSaveDialog, defaultPath ) ) + // Set the default dir + if ( !SetDefaultDir( fileSaveDialog, defaultPath ) ) { goto end; } + // Set the default filename + SetDefaultFile( fileSaveDialog, defaultPath ); + // Show the dialog. result = fileSaveDialog->Show(NULL); if ( SUCCEEDED(result) ) @@ -685,10 +717,10 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, goto end; } - // Set the default path - if (SetDefaultPath(fileDialog, defaultPath) != NFD_OKAY) + // Set the default dir + if (SetDefaultDir(fileDialog, defaultPath) != NFD_OKAY) { - NFDi_SetError("SetDefaultPath failed."); + NFDi_SetError("SetDefaultDir failed."); goto end; } From 53a0348f894780ab5c318e826214b51fe588bb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Thu, 7 Jan 2021 13:19:31 -0800 Subject: [PATCH 09/25] Linux fix default path/filename not working at all when doesn't exist --- src/nfd_gtk.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index 7a9958e..120a9d1 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -11,6 +11,7 @@ #include "nfd.h" #include "nfd_common.h" +#include "ftg_core.h" const char INIT_FAIL_MSG[] = "gtk_init_check failed to initilaize GTK+"; @@ -46,12 +47,12 @@ static void AddFiltersToDialog( GtkWidget *dialog, const char *filterList ) if ( NFDi_IsFilterSegmentChar(*p_filterList) ) { - char typebufWildcard[NFD_MAX_STRLEN]; + char typebufWildcard[NFD_MAX_STRLEN+3]; /* add another type to the filter */ assert( strlen(typebuf) > 0 ); assert( strlen(typebuf) < NFD_MAX_STRLEN-1 ); - snprintf( typebufWildcard, NFD_MAX_STRLEN, "*.%s", typebuf ); + snprintf( typebufWildcard, NFD_MAX_STRLEN+3, "*.%s", typebuf ); AddTypeToFilterName( typebuf, filterName, NFD_MAX_STRLEN ); gtk_file_filter_add_pattern( filter, typebufWildcard ); @@ -92,17 +93,23 @@ static void AddFiltersToDialog( GtkWidget *dialog, const char *filterList ) gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter ); } -static void SetDefaultPath( GtkWidget *dialog, const char *defaultPath ) +static void SetDefaultDir( GtkWidget *dialog, const char *defaultPath ) { - if ( !defaultPath || strlen(defaultPath) == 0 ) + fflush(stdout); + if ( !defaultPath || defaultPath[0] == '\0' ) return; /* GTK+ manual recommends not specifically setting the default path. We do it anyway in order to be consistent across platforms. - If consistency with the native OS is preferred, this is the line + If consistency with the native OS is preferred, this is the section to comment out. -ml */ - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(dialog), defaultPath ); + + if (ftg_is_dir(defaultPath)) + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(dialog), defaultPath); + else + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(dialog), defaultPath); + } static nfdresult_t AllocPathSet( GSList *fileList, nfdpathset_t *pathSet ) @@ -188,8 +195,8 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, /* Build the filter list */ AddFiltersToDialog(dialog, filterList); - /* Set the default path */ - SetDefaultPath(dialog, defaultPath); + /* Set the default dir */ + SetDefaultDir(dialog, defaultPath); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) @@ -246,8 +253,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, /* Build the filter list */ AddFiltersToDialog(dialog, filterList); - /* Set the default path */ - SetDefaultPath(dialog, defaultPath); + /* Set the default dir */ + SetDefaultDir(dialog, defaultPath); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) @@ -293,8 +300,8 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, /* Build the filter list */ AddFiltersToDialog(dialog, filterList); - /* Set the default path */ - SetDefaultPath(dialog, defaultPath); + /* Set the default dir */ + SetDefaultDir(dialog, defaultPath); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) @@ -346,8 +353,8 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(dialog), TRUE ); - /* Set the default path */ - SetDefaultPath(dialog, defaultPath); + /* Set the default dir */ + SetDefaultDir(dialog, defaultPath); result = NFD_CANCEL; if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) From 3f3e7956915bbbc355e0a2f6daf0e6c2080be001 Mon Sep 17 00:00:00 2001 From: Michael Labbe Date: Thu, 7 Jan 2021 15:20:14 -0800 Subject: [PATCH 10/25] macos support filenames in default paths --- src/nfd_cocoa.m | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/nfd_cocoa.m b/src/nfd_cocoa.m index 776152d..5548515 100644 --- a/src/nfd_cocoa.m +++ b/src/nfd_cocoa.m @@ -8,6 +8,8 @@ #include "nfd.h" #include "nfd_common.h" +#include "ftg_core.h" + static NSArray *BuildAllowedFileTypes( const char *filterList ) { // Commas and semicolons are the same thing on this platform @@ -59,11 +61,37 @@ static void AddFilterListToDialog( NSSavePanel *dialog, const char *filterList ) static void SetDefaultPath( NSSavePanel *dialog, const nfdchar_t *defaultPath ) { - if ( !defaultPath || strlen(defaultPath) == 0 ) + if ( !defaultPath || defaultPath[0] == '\0' ) return; + + // If the file in defaultPath doesn't exist, fall back to just using the directory. + // Cocoa behaviour here ignores the entire defaultPath if the file at the end of + // the path doesn't exist, falling back to an internally computed path. + // + // We override this behaviour to be consistent on all platforms: + // just open the directory in question in the dialog and have no file selected. + const char *defaultDir, *defaultFilename; + NFDi_SplitPath(defaultPath, &defaultDir, &defaultFilename); + + bool onlyUseDirectory = true; + if (defaultFilename) { + if (ftg_path_exists(defaultPath)) { + onlyUseDirectory = false; + } + } + + NSString *defaultPathString; + if (defaultFilename && onlyUseDirectory) { + assert(defaultFilename > defaultDir); + defaultPathString = [NSString stringWithFormat:@"%.*s", + (int)(defaultFilename - defaultDir), + defaultDir]; + } else { + defaultPathString = [NSString stringWithUTF8String:defaultPath]; + } - NSString *defaultPathString = [NSString stringWithUTF8String: defaultPath]; - NSURL *url = [NSURL fileURLWithPath:defaultPathString isDirectory:YES]; + NSURL *url = [NSURL fileURLWithPath:defaultPathString + isDirectory:ftg_is_dir(defaultPath)]; [dialog setDirectoryURL:url]; } From be028fc616878cc0d2543ab98f8cbf3452bec69b Mon Sep 17 00:00:00 2001 From: Michael Labbe Date: Fri, 8 Jan 2021 08:47:26 -0800 Subject: [PATCH 11/25] win32 set default extension --- README.md | 14 +++++++++++++- src/nfd_win.cpp | 13 ++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e34afa9..946be16 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,18 @@ release | what's new | date | remove deprecated scons | aug 2019 | fix mingw compilation | aug 2019 | -Wextra warning cleanup | aug 2019 +1.2.0 | defaultPath can specify files now | jan 2021 + | extension automatically added when saving | jan 2021 + +### Breaking Changes ### + +There are no ABI breaking changes in NFD's history. + +#### 1.2.0 #### + + - If argument `filterList` is specified, a default extension is appended to the filename if the user does not take an action to specify one. Previously no extension was added on the GTK3 and Win32 implementations, but was added on MacOS. + + - Argument `defaultPath` sometimes failed to display the specified directory if a file was included in the `defaultPath` but the file did not exist. In 1.2.0, polyfill was added to display the directory even if the file doesn't exist. ## Building ## @@ -161,7 +173,7 @@ I accept quality code patches, or will resolve these and other matters through s # Copyright and Credit # -Copyright © 2014-2019 [Frogtoss Games](http://www.frogtoss.com), Inc. +Copyright © 2014-2021 [Frogtoss Games](http://www.frogtoss.com), Inc. File [LICENSE](LICENSE) covers all files in this repo. Native File Dialog by Michael Labbe diff --git a/src/nfd_win.cpp b/src/nfd_win.cpp index 4757f23..1843401 100644 --- a/src/nfd_win.cpp +++ b/src/nfd_win.cpp @@ -146,7 +146,7 @@ static int AppendExtensionToSpecBuf( const char *ext, char *specBuf, size_t spec return NFD_OKAY; } -static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char *filterList ) +static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileDialog, const char *filterList ) { const wchar_t WILDCARD[] = L"*.*"; @@ -192,8 +192,15 @@ static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char { if ( NFDi_IsFilterSegmentChar(*p_filterList) ) { + if (specbuf[0] == '\0') { + wchar_t *ext = NULL; + CopyNFDCharToWChar(typebuf, strlen(typebuf), &ext); + fileDialog->SetDefaultExtension(ext); + NFDi_Free(ext); + } + /* append a type to the specbuf (pending filter) */ - AppendExtensionToSpecBuf( typebuf, specbuf, NFD_MAX_STRLEN ); + AppendExtensionToSpecBuf( typebuf, specbuf, NFD_MAX_STRLEN ); p_typebuf = typebuf; memset( typebuf, 0, sizeof(char)*NFD_MAX_STRLEN ); @@ -225,7 +232,7 @@ static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char specList[specIdx].pszSpec = WILDCARD; specList[specIdx].pszName = WILDCARD; - fileOpenDialog->SetFileTypes( filterCount+1, specList ); + fileDialog->SetFileTypes( filterCount+1, specList ); /* free speclist */ for ( size_t i = 0; i < filterCount; ++i ) From c0e491055bba7b6e0326e2d94566b65e6aebc014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 10:04:15 -0800 Subject: [PATCH 12/25] gtk polyfill: add extension from selected filter --- src/nfd_gtk.c | 99 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index 120a9d1..c57c6bc 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "nfd.h" #include "nfd_common.h" @@ -51,7 +52,7 @@ static void AddFiltersToDialog( GtkWidget *dialog, const char *filterList ) /* add another type to the filter */ assert( strlen(typebuf) > 0 ); assert( strlen(typebuf) < NFD_MAX_STRLEN-1 ); - + snprintf( typebufWildcard, NFD_MAX_STRLEN+3, "*.%s", typebuf ); AddTypeToFilterName( typebuf, filterName, NFD_MAX_STRLEN ); @@ -93,6 +94,19 @@ static void AddFiltersToDialog( GtkWidget *dialog, const char *filterList ) gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter ); } +static void GetFirstFilterExtension(const char *filterList, char outExt[NFD_MAX_STRLEN]) { + const char *p = filterList; + + size_t len = 0; + while (len < NFD_MAX_STRLEN-1 && isalpha(*p)) { + len = p - filterList; + outExt[len] = *p; + p++; + + } + outExt[len+1] = '\0'; +} + static void SetDefaultDir( GtkWidget *dialog, const char *defaultPath ) { fflush(stdout); @@ -169,7 +183,31 @@ static void WaitForCleanup(void) while (gtk_events_pending()) gtk_main_iteration(); } - + +static char *AllocUserFilename(GtkWidget *dialog, char *gtk_filename) { + // polyfill: if no extension, add the first extension from the + // gtk file filter. + char filter_ext[NFD_MAX_STRLEN] = {0}; + + GtkFileFilter *ff = gtk_file_chooser_get_filter( GTK_FILE_CHOOSER(dialog)); + if (ff) + GetFirstFilterExtension(gtk_file_filter_get_name( GTK_FILE_FILTER(ff)), filter_ext); + + char *specified_ext = ftg_get_filename_ext(gtk_filename); + char *outPath; + + if (specified_ext[0] == '\0' && + filter_ext[0] != '\0' && + gtk_filename[strlen(gtk_filename)-1] != '.') { + + outPath = ftg_strcatall(3, gtk_filename, ".", filter_ext); + } else { + outPath = ftg_strcatall(1, gtk_filename); + } + + return outPath; +} + /* public */ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, @@ -202,22 +240,15 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) { char *filename; - filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) ); + *outPath = AllocUserFilename(dialog, filename); + g_free(filename); - { - size_t len = strlen(filename); - *outPath = NFDi_Malloc( len + 1 ); - memcpy( *outPath, filename, len + 1 ); - if ( !*outPath ) - { - g_free( filename ); - gtk_widget_destroy(dialog); - return NFD_ERROR; - } + if (!(*outPath)) { + gtk_widget_destroy(dialog); + NFDi_SetError("Error allocating bytes"); + return NFD_ERROR; } - g_free( filename ); - result = NFD_OKAY; } @@ -308,20 +339,15 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, { char *filename; filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) ); - - { - size_t len = strlen(filename); - *outPath = NFDi_Malloc( len + 1 ); - memcpy( *outPath, filename, len + 1 ); - if ( !*outPath ) - { - g_free( filename ); - gtk_widget_destroy(dialog); - return NFD_ERROR; - } - } + *outPath = AllocUserFilename(dialog, filename); g_free(filename); + if (!(*outPath)) { + gtk_widget_destroy(dialog); + NFDi_SetError("Error allocating bytes"); + return NFD_ERROR; + } + result = NFD_OKAY; } @@ -361,20 +387,15 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, { char *filename; filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) ); - - { - size_t len = strlen(filename); - *outPath = NFDi_Malloc( len + 1 ); - memcpy( *outPath, filename, len + 1 ); - if ( !*outPath ) - { - g_free( filename ); - gtk_widget_destroy(dialog); - return NFD_ERROR; - } - } + *outPath = AllocUserFilename(dialog, filename); g_free(filename); + if (!(*outPath)) { + gtk_widget_destroy(dialog); + NFDi_SetError("Error allocating bytes"); + return NFD_ERROR; + } + result = NFD_OKAY; } From 04362c72f92100c5b36a539cfba2ba979ba9a415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 11:16:42 -0800 Subject: [PATCH 13/25] remove benign warning --- src/nfd_gtk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index 5eabae9..321371c 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -19,6 +19,9 @@ const char INIT_FAIL_MSG[] = "gtk_init_check failed to initilaize GTK+"; +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif static void AddTypeToFilterName( const char *typebuf, char *filterName, size_t bufsize ) { From f04d99e4646fa5266ee9b6023bd9b936d577347a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 11:46:20 -0800 Subject: [PATCH 14/25] add nfd_free --- README.md | 7 +++++-- src/include/nfd.h | 2 ++ src/nfd_common.c | 4 ++++ test/test_opendialog.c | 3 ++- test/test_pickfolder.c | 2 +- test/test_savedialog.c | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b179731..3c48085 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ int main( void ) if ( result == NFD_OKAY ) { puts("Success!"); puts(outPath); - free(outPath); + NFD_Free(outPath); } else if ( result == NFD_CANCEL ) { puts("User pressed cancel."); @@ -80,8 +80,9 @@ release | what's new | date 1.2.0 | defaultPath can specify files now | jan 2021 | extension automatically added when saving | jan 2021 | GTK dialog focus bugfix | jan 2021 + | Added NFD_Free() | jan 2021 -### Breaking Changes ### +### Breaking and Notable Changes ### There are no ABI breaking changes in NFD's history. @@ -90,6 +91,8 @@ There are no ABI breaking changes in NFD's history. - If argument `filterList` is specified, a default extension is appended to the filename if the user does not take an action to specify one. Previously no extension was added on the GTK3 and Win32 implementations, but was added on MacOS. - Argument `defaultPath` sometimes failed to display the specified directory if a file was included in the `defaultPath` but the file did not exist. In 1.2.0, polyfill was added to display the directory even if the file doesn't exist. + + - `NFD_Free()` was added, and can be used in place of `free()`. This was done to facilitate usage of NFD in a DLL on Windows. Otherwise, there is no difference. ## Building ## diff --git a/src/include/nfd.h b/src/include/nfd.h index 74c9274..343d406 100644 --- a/src/include/nfd.h +++ b/src/include/nfd.h @@ -65,6 +65,8 @@ size_t NFD_PathSet_GetCount( const nfdpathset_t *pathSet ); nfdchar_t *NFD_PathSet_GetPath( const nfdpathset_t *pathSet, size_t index ); /* Free the pathSet */ void NFD_PathSet_Free( nfdpathset_t *pathSet ); +/* Free any other memory allocated by NFD */ +void NFD_Free(void *ptr); #ifdef __cplusplus diff --git a/src/nfd_common.c b/src/nfd_common.c index f8a9421..c52b725 100644 --- a/src/nfd_common.c +++ b/src/nfd_common.c @@ -43,6 +43,10 @@ void NFD_PathSet_Free( nfdpathset_t *pathset ) NFDi_Free( pathset->buf ); } +void NFD_Free(void *ptr) { + NFDi_Free(ptr); +} + /* internal routines */ void *NFDi_Malloc( size_t bytes ) diff --git a/test/test_opendialog.c b/test/test_opendialog.c index 54bf374..3a07065 100644 --- a/test/test_opendialog.c +++ b/test/test_opendialog.c @@ -9,12 +9,13 @@ int main( void ) { nfdchar_t *outPath = NULL; + nfdresult_t result = NFD_OpenDialog( "png,jpg;pdf", NULL, &outPath ); if ( result == NFD_OKAY ) { puts("Success!"); puts(outPath); - free(outPath); + NFD_Free(outPath); } else if ( result == NFD_CANCEL ) { diff --git a/test/test_pickfolder.c b/test/test_pickfolder.c index 708fee8..7c086e4 100644 --- a/test/test_pickfolder.c +++ b/test/test_pickfolder.c @@ -14,7 +14,7 @@ int main( void ) { puts("Success!"); puts(outPath); - free(outPath); + NFD_Free(outPath); } else if ( result == NFD_CANCEL ) { diff --git a/test/test_savedialog.c b/test/test_savedialog.c index 7ec37f0..15361ec 100644 --- a/test/test_savedialog.c +++ b/test/test_savedialog.c @@ -13,7 +13,7 @@ int main( void ) { puts("Success!"); puts(savePath); - free(savePath); + NFD_Free(savePath); } else if ( result == NFD_CANCEL ) { From a93a3c28c168380e4db925f5de19a3abb7de34ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 12:21:44 -0800 Subject: [PATCH 15/25] fix warnings, errors introduced in last pr --- README.md | 4 ++++ src/nfd_zenity.c | 4 ++-- src/simple_exec.h | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c48085..5025051 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ release | what's new | date | extension automatically added when saving | jan 2021 | GTK dialog focus bugfix | jan 2021 | Added NFD_Free() | jan 2021 + | Fix vs2019 debug assert | jan 2021 + | Fix zenity debug assert | jan 2021 ### Breaking and Notable Changes ### @@ -189,6 +191,8 @@ Tomasz Konojacki for [microutf8](http://puszcza.gnu.org.ua/software/microutf8/) [Tom Mason](https://github.com/wheybags) for Zenity support. +Various pull requests and bugfixes -- thanks to the original authors. + ## Support ## Directed support for this work is available from the original author under a paid agreement. diff --git a/src/nfd_zenity.c b/src/nfd_zenity.c index f799816..fa9f4ba 100644 --- a/src/nfd_zenity.c +++ b/src/nfd_zenity.c @@ -45,12 +45,12 @@ static void AddFiltersToCommandArgs(char** commandArgs, int commandArgsLen, cons if ( NFDi_IsFilterSegmentChar(*p_filterList) ) { - char typebufWildcard[NFD_MAX_STRLEN]; + char typebufWildcard[NFD_MAX_STRLEN+3]; /* add another type to the filter */ assert( strlen(typebuf) > 0 ); assert( strlen(typebuf) < NFD_MAX_STRLEN-1 ); - snprintf( typebufWildcard, NFD_MAX_STRLEN, "*.%s", typebuf ); + snprintf( typebufWildcard, NFD_MAX_STRLEN+3, "*.%s", typebuf ); AddTypeToFilterName( typebuf, filterName, NFD_MAX_STRLEN ); diff --git a/src/simple_exec.h b/src/simple_exec.h index c86e274..c192cf2 100644 --- a/src/simple_exec.h +++ b/src/simple_exec.h @@ -29,6 +29,8 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in #include #include +#include "ftg_core.h" + #define release_assert(exp) { if (!(exp)) { abort(); } } enum PIPE_FILE_DESCRIPTORS @@ -43,7 +45,7 @@ enum RUN_COMMAND_ERROR COMMAND_NOT_FOUND = 1 }; -void sigchldHandler(int p){} +void sigchldHandler(int p){FTG_UNUSED(p);} int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* const* allArgs) { @@ -67,7 +69,7 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in int errPipe[2]; release_assert(pipe(errPipe) == 0); - void (*prev_handler)(int); + void (*prevHandler)(int); prevHandler = signal(SIGCHLD, sigchldHandler); pid_t pid; From 8f15758447d412eab0bf7c059859a8a87bc33dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 12:28:47 -0800 Subject: [PATCH 16/25] clang-format pass --- .clang-format | 57 +++++ README.md | 1 + docs/contributing.md | 2 + src/common.h | 10 +- src/ftg_core.h | 1 + src/include/nfd.h | 55 +++-- src/nfd_cocoa.m | 220 ++++++++--------- src/nfd_common.c | 145 +++++------ src/nfd_common.h | 14 +- src/nfd_gtk.c | 337 +++++++++++++------------- src/nfd_win.cpp | 562 +++++++++++++++++++------------------------ src/nfd_zenity.c | 228 +++++++++--------- src/simple_exec.h | 276 ++++++++++----------- 13 files changed, 944 insertions(+), 964 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..89789a6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,57 @@ +# main +IndentWidth: 4 +BreakBeforeBraces: Linux +AlwaysBreakAfterDefinitionReturnType: true +UseTab: Never +AllowShortIfStatementsOnASingleLine: false +ColumnLimit: 80 +IndentCaseLabels: false + +# for macros +AlignEscapedNewlinesLeft: false +IndentPPDirectives: AfterHash + +# i love alignment +BinPackArguments: false +AllowAllParametersOfDeclarationOnNextLine: true +BinPackParameters: false +AlignTrailingComments: true +AlignConsecutiveDeclarations: true +AlignAfterOpenBracket: Align + +# most flow control must be indented for easy eye scanning +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortLoopsOnASingleLine: true + +# braces +BraceWrapping: + BeforeElse: false + AfterControlStatement: false + AfterFunction: false + AfterStruct: false + AfterUnion: false + IndentBraces: false + +# other +AlignOperands: true +MaxEmptyLinesToKeep: 3 +KeepEmptyLinesAtTheStartOfBlocks: false +PointerAlignment: Left +DerivePointerAlignment: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +IncludeBlocks: Preserve +SortIncludes: false +BreakBeforeBinaryOperators: None +ReflowComments: true + + +# penalties +PenaltyExcessCharacter: 2 \ No newline at end of file diff --git a/README.md b/README.md index 5025051..afcc33d 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ release | what's new | date | Added NFD_Free() | jan 2021 | Fix vs2019 debug assert | jan 2021 | Fix zenity debug assert | jan 2021 + | add clang-format | jan 2021 ### Breaking and Notable Changes ### diff --git a/docs/contributing.md b/docs/contributing.md index f6c3b54..8faded3 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -16,6 +16,8 @@ Here are the rules: - **Do not change the externally facing API**. NFD needs to maintain ABI compatibility. +- **Run clang-format before submitting.**. There is a `.clang-format` file in the root of the repo. This ensures your formatting matches the source project. + ## Submitting Cloud Autobuild systems ## I have received a few pull requests for Travis and AppVeyor-based autobuilding which I have not accepted. NativeFileDialog is officially covered by my private BuildBot network which supports all three target OSes, both CPU architectures and four compilers. I take the view that having a redundant, lesser autobuild system does not improve coverage: it gives a false positive when partial building succeeds. Please do not invest time into cloud-based building with the hope of a pull request being accepted. diff --git a/src/common.h b/src/common.h index 7745d32..6f4c6b0 100644 --- a/src/common.h +++ b/src/common.h @@ -11,11 +11,11 @@ #define _NFD_COMMON_H #define NFD_MAX_STRLEN 256 -#define _NFD_UNUSED(x) ((void)x) +#define _NFD_UNUSED(x) ((void)x) -void *NFDi_Malloc( size_t bytes ); -void NFDi_Free( void *ptr ); -void NFDi_SetError( const char *msg ); -void NFDi_SafeStrncpy( char *dst, const char *src, size_t maxCopy ); +void* NFDi_Malloc(size_t bytes); +void NFDi_Free(void* ptr); +void NFDi_SetError(const char* msg); +void NFDi_SafeStrncpy(char* dst, const char* src, size_t maxCopy); #endif diff --git a/src/ftg_core.h b/src/ftg_core.h index e1cceee..831ed73 100644 --- a/src/ftg_core.h +++ b/src/ftg_core.h @@ -1,3 +1,4 @@ +/* clang-format off */ /* ftg_core.h - v0.5 - Frogtoss Toolbox. Public domain-like license below. ftg libraries are copyright (C) 2015 Frogtoss Games, Inc. diff --git a/src/include/nfd.h b/src/include/nfd.h index 343d406..bdab5e8 100644 --- a/src/include/nfd.h +++ b/src/include/nfd.h @@ -21,52 +21,51 @@ typedef char nfdchar_t; /* opaque data structure -- see NFD_PathSet_* */ typedef struct { - nfdchar_t *buf; - size_t *indices; /* byte offsets into buf */ - size_t count; /* number of indices into buf */ -}nfdpathset_t; + nfdchar_t* buf; + size_t* indices; /* byte offsets into buf */ + size_t count; /* number of indices into buf */ +} nfdpathset_t; typedef enum { - NFD_ERROR, /* programmatic error */ - NFD_OKAY, /* user pressed okay, or successful return */ - NFD_CANCEL /* user pressed cancel */ -}nfdresult_t; - + NFD_ERROR, /* programmatic error */ + NFD_OKAY, /* user pressed okay, or successful return */ + NFD_CANCEL /* user pressed cancel */ +} nfdresult_t; + /* nfd_.c */ -/* single file open dialog */ -nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ); +/* single file open dialog */ +nfdresult_t NFD_OpenDialog(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdchar_t** outPath); -/* multiple file open dialog */ -nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdpathset_t *outPaths ); +/* multiple file open dialog */ +nfdresult_t NFD_OpenDialogMultiple(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdpathset_t* outPaths); /* save dialog */ -nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ); +nfdresult_t NFD_SaveDialog(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdchar_t** outPath); /* select folder dialog */ -nfdresult_t NFD_PickFolder( const nfdchar_t *defaultPath, - nfdchar_t **outPath); +nfdresult_t NFD_PickFolder(const nfdchar_t* defaultPath, nfdchar_t** outPath); /* nfd_common.c */ /* get last error -- set when nfdresult_t returns NFD_ERROR */ -const char *NFD_GetError( void ); +const char* NFD_GetError(void); /* get the number of entries stored in pathSet */ -size_t NFD_PathSet_GetCount( const nfdpathset_t *pathSet ); +size_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet); /* Get the UTF-8 path at offset index */ -nfdchar_t *NFD_PathSet_GetPath( const nfdpathset_t *pathSet, size_t index ); -/* Free the pathSet */ -void NFD_PathSet_Free( nfdpathset_t *pathSet ); +nfdchar_t* NFD_PathSet_GetPath(const nfdpathset_t* pathSet, size_t index); +/* Free the pathSet */ +void NFD_PathSet_Free(nfdpathset_t* pathSet); /* Free any other memory allocated by NFD */ -void NFD_Free(void *ptr); +void NFD_Free(void* ptr); #ifdef __cplusplus diff --git a/src/nfd_cocoa.m b/src/nfd_cocoa.m index e75890f..27c37a7 100644 --- a/src/nfd_cocoa.m +++ b/src/nfd_cocoa.m @@ -10,60 +10,57 @@ #include "ftg_core.h" -static NSArray *BuildAllowedFileTypes( const char *filterList ) +static NSArray* +BuildAllowedFileTypes(const char* filterList) { // Commas and semicolons are the same thing on this platform - NSMutableArray *buildFilterList = [[NSMutableArray alloc] init]; + NSMutableArray* buildFilterList = [[NSMutableArray alloc] init]; char typebuf[NFD_MAX_STRLEN] = {0}; - + size_t filterListLen = strlen(filterList); - char *p_typebuf = typebuf; - for ( size_t i = 0; i < filterListLen+1; ++i ) - { - if ( filterList[i] == ',' || filterList[i] == ';' || filterList[i] == '\0' ) - { + char* p_typebuf = typebuf; + for (size_t i = 0; i < filterListLen + 1; ++i) { + if (filterList[i] == ',' || filterList[i] == ';' || filterList[i] == '\0') { if (filterList[i] != '\0') ++p_typebuf; *p_typebuf = '\0'; - NSString *thisType = [NSString stringWithUTF8String: typebuf]; + NSString* thisType = [NSString stringWithUTF8String:typebuf]; [buildFilterList addObject:thisType]; p_typebuf = typebuf; *p_typebuf = '\0'; - } - else - { + } else { *p_typebuf = filterList[i]; ++p_typebuf; - } } - NSArray *returnArray = [NSArray arrayWithArray:buildFilterList]; + NSArray* returnArray = [NSArray arrayWithArray:buildFilterList]; [buildFilterList release]; return returnArray; } -static void AddFilterListToDialog( NSSavePanel *dialog, const char *filterList ) +static void +AddFilterListToDialog(NSSavePanel* dialog, const char* filterList) { - if ( !filterList || strlen(filterList) == 0 ) + if (!filterList || strlen(filterList) == 0) return; - NSArray *allowedFileTypes = BuildAllowedFileTypes( filterList ); - if ( [allowedFileTypes count] != 0 ) - { + NSArray* allowedFileTypes = BuildAllowedFileTypes(filterList); + if ([allowedFileTypes count] != 0) { [dialog setAllowedFileTypes:allowedFileTypes]; } } -static void SetDefaultPath( NSSavePanel *dialog, const nfdchar_t *defaultPath ) +static void +SetDefaultPath(NSSavePanel* dialog, const nfdchar_t* defaultPath) { - if ( !defaultPath || defaultPath[0] == '\0' ) + if (!defaultPath || defaultPath[0] == '\0') return; - + // If the file in defaultPath doesn't exist, fall back to just using the directory. // Cocoa behaviour here ignores the entire defaultPath if the file at the end of // the path doesn't exist, falling back to an internally computed path. @@ -72,69 +69,65 @@ static void SetDefaultPath( NSSavePanel *dialog, const nfdchar_t *defaultPath ) // just open the directory in question in the dialog and have no file selected. const char *defaultDir, *defaultFilename; NFDi_SplitPath(defaultPath, &defaultDir, &defaultFilename); - + bool onlyUseDirectory = true; if (defaultFilename) { if (ftg_path_exists(defaultPath)) { onlyUseDirectory = false; } } - - NSString *defaultPathString; + + NSString* defaultPathString; if (defaultFilename && onlyUseDirectory) { assert(defaultFilename > defaultDir); - defaultPathString = [NSString stringWithFormat:@"%.*s", - (int)(defaultFilename - defaultDir), - defaultDir]; + defaultPathString = [NSString + stringWithFormat:@"%.*s", (int)(defaultFilename - defaultDir), defaultDir]; } else { defaultPathString = [NSString stringWithUTF8String:defaultPath]; } - NSURL *url = [NSURL fileURLWithPath:defaultPathString - isDirectory:ftg_is_dir(defaultPath)]; - [dialog setDirectoryURL:url]; + NSURL* url = [NSURL fileURLWithPath:defaultPathString + isDirectory:ftg_is_dir(defaultPath)]; + [dialog setDirectoryURL:url]; } /* fixme: pathset should be pathSet */ -static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset ) +static nfdresult_t +AllocPathSet(NSArray* urls, nfdpathset_t* pathset) { assert(pathset); assert([urls count]); pathset->count = (size_t)[urls count]; - pathset->indices = NFDi_Malloc( sizeof(size_t)*pathset->count ); - if ( !pathset->indices ) - { + pathset->indices = NFDi_Malloc(sizeof(size_t) * pathset->count); + if (!pathset->indices) { return NFD_ERROR; } // count the total space needed for buf size_t bufsize = 0; - for ( NSURL *url in urls ) - { - NSString *path = [url path]; + for (NSURL* url in urls) { + NSString* path = [url path]; bufsize += [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1; } - pathset->buf = NFDi_Malloc( sizeof(nfdchar_t) * bufsize ); - if ( !pathset->buf ) - { + pathset->buf = NFDi_Malloc(sizeof(nfdchar_t) * bufsize); + if (!pathset->buf) { return NFD_ERROR; } // fill buf - nfdchar_t *p_buf = pathset->buf; - size_t count = 0; - for ( NSURL *url in urls ) - { - NSString *path = [url path]; - const nfdchar_t *utf8Path = [path UTF8String]; + nfdchar_t* p_buf = pathset->buf; + size_t count = 0; + for (NSURL* url in urls) { + NSString* path = [url path]; + const nfdchar_t* utf8Path = [path UTF8String]; size_t byteLen = [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1; - memcpy( p_buf, utf8Path, byteLen ); + memcpy(p_buf, utf8Path, byteLen); ptrdiff_t index = p_buf - pathset->buf; - assert( index >= 0 ); + assert(index >= 0); pathset->indices[count] = (size_t)index; p_buf += byteLen; @@ -147,14 +140,13 @@ static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset ) /* public */ -nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) +nfdresult_t +NFD_OpenDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; - NSOpenPanel *dialog = [NSOpenPanel openPanel]; + NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; + NSOpenPanel* dialog = [NSOpenPanel openPanel]; [dialog setAllowsMultipleSelection:NO]; // Build the filter list @@ -164,22 +156,20 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, SetDefaultPath(dialog, defaultPath); nfdresult_t nfdResult = NFD_CANCEL; - if ( [dialog runModal] == NSModalResponseOK ) - { - NSURL *url = [dialog URL]; - const char *utf8Path = [[url path] UTF8String]; + if ([dialog runModal] == NSModalResponseOK) { + NSURL* url = [dialog URL]; + const char* utf8Path = [[url path] UTF8String]; // byte count, not char count - size_t len = strlen(utf8Path);//NFDi_UTF8_Strlen(utf8Path); + size_t len = strlen(utf8Path); // NFDi_UTF8_Strlen(utf8Path); - *outPath = NFDi_Malloc( len+1 ); - if ( !*outPath ) - { + *outPath = NFDi_Malloc(len + 1); + if (!*outPath) { [pool release]; - [keyWindow makeKeyAndOrderFront:nil]; + [keyWindow makeKeyAndOrderFront:nil]; return NFD_ERROR; } - memcpy( *outPath, utf8Path, len+1 ); /* copy null term */ + memcpy(*outPath, utf8Path, len + 1); /* copy null term */ nfdResult = NFD_OKAY; } [pool release]; @@ -189,14 +179,15 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, } -nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdpathset_t *outPaths ) +nfdresult_t +NFD_OpenDialogMultiple(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdpathset_t* outPaths) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; - - NSOpenPanel *dialog = [NSOpenPanel openPanel]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; + + NSOpenPanel* dialog = [NSOpenPanel openPanel]; [dialog setAllowsMultipleSelection:YES]; // Build the fiter list. @@ -204,23 +195,20 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, // Set the starting directory SetDefaultPath(dialog, defaultPath); - + nfdresult_t nfdResult = NFD_CANCEL; - if ( [dialog runModal] == NSModalResponseOK ) - { - NSArray *urls = [dialog URLs]; + if ([dialog runModal] == NSModalResponseOK) { + NSArray* urls = [dialog URLs]; - if ( [urls count] == 0 ) - { + if ([urls count] == 0) { [pool release]; - [keyWindow makeKeyAndOrderFront:nil]; + [keyWindow makeKeyAndOrderFront:nil]; return NFD_CANCEL; } - if ( AllocPathSet( urls, outPaths ) == NFD_ERROR ) - { + if (AllocPathSet(urls, outPaths) == NFD_ERROR) { [pool release]; - [keyWindow makeKeyAndOrderFront:nil]; + [keyWindow makeKeyAndOrderFront:nil]; return NFD_ERROR; } @@ -228,21 +216,20 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, } [pool release]; - [keyWindow makeKeyAndOrderFront:nil]; + [keyWindow makeKeyAndOrderFront:nil]; return nfdResult; } -nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) +nfdresult_t +NFD_SaveDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; - - NSSavePanel *dialog = [NSSavePanel savePanel]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; + + NSSavePanel* dialog = [NSSavePanel savePanel]; [dialog setExtensionHidden:NO]; - + // Build the filter list. AddFilterListToDialog(dialog, filterList); @@ -250,21 +237,20 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, SetDefaultPath(dialog, defaultPath); nfdresult_t nfdResult = NFD_CANCEL; - if ( [dialog runModal] == NSModalResponseOK ) - { - NSURL *url = [dialog URL]; - const char *utf8Path = [[url path] UTF8String]; - - size_t byteLen = [url.path lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1; - - *outPath = NFDi_Malloc( byteLen ); - if ( !*outPath ) - { + if ([dialog runModal] == NSModalResponseOK) { + NSURL* url = [dialog URL]; + const char* utf8Path = [[url path] UTF8String]; + + size_t byteLen = + [url.path lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1; + + *outPath = NFDi_Malloc(byteLen); + if (!*outPath) { [pool release]; - [keyWindow makeKeyAndOrderFront:nil]; + [keyWindow makeKeyAndOrderFront:nil]; return NFD_ERROR; } - memcpy( *outPath, utf8Path, byteLen ); + memcpy(*outPath, utf8Path, byteLen); nfdResult = NFD_OKAY; } @@ -273,13 +259,13 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, return nfdResult; } -nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, - nfdchar_t **outPath) +nfdresult_t +NFD_PickFolder(const nfdchar_t* defaultPath, nfdchar_t** outPath) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; - NSOpenPanel *dialog = [NSOpenPanel openPanel]; + NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; + NSOpenPanel* dialog = [NSOpenPanel openPanel]; [dialog setAllowsMultipleSelection:NO]; [dialog setCanChooseDirectories:YES]; [dialog setCanCreateDirectories:YES]; @@ -289,22 +275,20 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, SetDefaultPath(dialog, defaultPath); nfdresult_t nfdResult = NFD_CANCEL; - if ( [dialog runModal] == NSModalResponseOK ) - { - NSURL *url = [dialog URL]; - const char *utf8Path = [[url path] UTF8String]; + if ([dialog runModal] == NSModalResponseOK) { + NSURL* url = [dialog URL]; + const char* utf8Path = [[url path] UTF8String]; // byte count, not char count - size_t len = strlen(utf8Path);//NFDi_UTF8_Strlen(utf8Path); + size_t len = strlen(utf8Path); // NFDi_UTF8_Strlen(utf8Path); - *outPath = NFDi_Malloc( len+1 ); - if ( !*outPath ) - { + *outPath = NFDi_Malloc(len + 1); + if (!*outPath) { [pool release]; - [keyWindow makeKeyAndOrderFront:nil]; + [keyWindow makeKeyAndOrderFront:nil]; return NFD_ERROR; } - memcpy( *outPath, utf8Path, len+1 ); /* copy null term */ + memcpy(*outPath, utf8Path, len + 1); /* copy null term */ nfdResult = NFD_OKAY; } [pool release]; diff --git a/src/nfd_common.c b/src/nfd_common.c index f9dcc01..cef0d37 100644 --- a/src/nfd_common.c +++ b/src/nfd_common.c @@ -4,9 +4,9 @@ http://www.frogtoss.com/labs */ - // Disable warning using strncat() +// Disable warning using strncat() #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) -#define _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS #endif #include @@ -22,79 +22,88 @@ static char g_errorstr[NFD_MAX_STRLEN] = {0}; /* public routines */ -const char *NFD_GetError( void ) +const char* +NFD_GetError(void) { return g_errorstr; } -size_t NFD_PathSet_GetCount( const nfdpathset_t *pathset ) +size_t +NFD_PathSet_GetCount(const nfdpathset_t* pathset) { assert(pathset); return pathset->count; } -nfdchar_t *NFD_PathSet_GetPath( const nfdpathset_t *pathset, size_t num ) +nfdchar_t* +NFD_PathSet_GetPath(const nfdpathset_t* pathset, size_t num) { assert(pathset); assert(num < pathset->count); - + return pathset->buf + pathset->indices[num]; } -void NFD_PathSet_Free( nfdpathset_t *pathset ) +void +NFD_PathSet_Free(nfdpathset_t* pathset) { assert(pathset); - NFDi_Free( pathset->indices ); - NFDi_Free( pathset->buf ); + NFDi_Free(pathset->indices); + NFDi_Free(pathset->buf); } -void NFD_Free(void *ptr) { +void +NFD_Free(void* ptr) +{ NFDi_Free(ptr); } /* internal routines */ -void *NFDi_Malloc( size_t bytes ) +void* +NFDi_Malloc(size_t bytes) { - void *ptr = malloc(bytes); - if ( !ptr ) + void* ptr = malloc(bytes); + if (!ptr) NFDi_SetError("NFDi_Malloc failed."); return ptr; } -void NFDi_Free( void *ptr ) +void +NFDi_Free(void* ptr) { assert(ptr); free(ptr); } -void NFDi_SetError( const char *msg ) +void +NFDi_SetError(const char* msg) { - int bTruncate = NFDi_SafeStrncpy( g_errorstr, msg, NFD_MAX_STRLEN ); - assert( !bTruncate ); _NFD_UNUSED(bTruncate); + int bTruncate = NFDi_SafeStrncpy(g_errorstr, msg, NFD_MAX_STRLEN); + assert(!bTruncate); + _NFD_UNUSED(bTruncate); } -int NFDi_SafeStrncpy( char *dst, const char *src, size_t maxCopy ) +int +NFDi_SafeStrncpy(char* dst, const char* src, size_t maxCopy) { size_t n = maxCopy; - char *d = dst; + char* d = dst; + + assert(src); + assert(dst); - assert( src ); - assert( dst ); - - while ( n > 0 && *src != '\0' ) - { + while (n > 0 && *src != '\0') { *d++ = *src++; --n; } /* Truncation case - terminate string and return true */ - if ( n == 0 ) - { - dst[maxCopy-1] = '\0'; + if (n == 0) { + dst[maxCopy - 1] = '\0'; return 1; } @@ -105,58 +114,54 @@ int NFDi_SafeStrncpy( char *dst, const char *src, size_t maxCopy ) /* adapted from microutf8 */ -int32_t NFDi_UTF8_Strlen( const nfdchar_t *str ) +int32_t +NFDi_UTF8_Strlen(const nfdchar_t* str) { - /* This function doesn't properly check validity of UTF-8 character - sequence, it is supposed to use only with valid UTF-8 strings. */ - - int32_t character_count = 0; - int32_t i = 0; /* Counter used to iterate over string. */ - nfdchar_t maybe_bom[4]; + /* This function doesn't properly check validity of UTF-8 character + sequence, it is supposed to use only with valid UTF-8 strings. */ + + int32_t character_count = 0; + int32_t i = 0; /* Counter used to iterate over string. */ + nfdchar_t maybe_bom[4]; unsigned char c; - - /* If there is UTF-8 BOM ignore it. */ - if (strlen(str) > 2) - { - strncpy(maybe_bom, str, 3); - maybe_bom[3] = 0; - if (strcmp(maybe_bom, (nfdchar_t*)NFD_UTF8_BOM) == 0) - i += 3; - } - - while(str[i]) - { - c = (unsigned char)str[i]; - if (c >> 7 == 0) - { - /* If bit pattern begins with 0 we have ascii character. */ - ++character_count; - } - else if (c >> 6 == 3) - { - /* If bit pattern begins with 11 it is beginning of UTF-8 byte sequence. */ - ++character_count; - } - else if (c >> 6 == 2) - ; /* If bit pattern begins with 10 it is middle of utf-8 byte sequence. */ - else - { + + /* If there is UTF-8 BOM ignore it. */ + if (strlen(str) > 2) { + strncpy(maybe_bom, str, 3); + maybe_bom[3] = 0; + if (strcmp(maybe_bom, (nfdchar_t*)NFD_UTF8_BOM) == 0) + i += 3; + } + + while (str[i]) { + c = (unsigned char)str[i]; + if (c >> 7 == 0) { + /* If bit pattern begins with 0 we have ascii character. */ + ++character_count; + } else if (c >> 6 == 3) { + /* If bit pattern begins with 11 it is beginning of UTF-8 byte sequence. */ + ++character_count; + } else if (c >> 6 == 2) + ; /* If bit pattern begins with 10 it is middle of utf-8 byte sequence. */ + else { /* In any other case this is not valid UTF-8. */ - return -1; + return -1; } - ++i; - } + ++i; + } - return character_count; + return character_count; } -int NFDi_IsFilterSegmentChar( char ch ) +int +NFDi_IsFilterSegmentChar(char ch) { - return (ch==','||ch==';'||ch=='\0'); + return (ch == ',' || ch == ';' || ch == '\0'); } -void NFDi_SplitPath(const char *path, const char **out_dir, const char **out_filename) { - +void +NFDi_SplitPath(const char* path, const char** out_dir, const char** out_filename) +{ // test filesystem to early out test on 'c:\path', which can't be // determined to not be a filename called `path` at `c:\` // otherwise. @@ -166,7 +171,7 @@ void NFDi_SplitPath(const char *path, const char **out_dir, const char **out_fil return; } - const char *filename = ftg_get_filename_from_path(path); + const char* filename = ftg_get_filename_from_path(path); if (filename[0]) { *out_filename = filename; } diff --git a/src/nfd_common.h b/src/nfd_common.h index f22a218..7b9f93e 100644 --- a/src/nfd_common.h +++ b/src/nfd_common.h @@ -24,13 +24,13 @@ extern "C" { #define NFD_UTF8_BOM "\xEF\xBB\xBF" -void *NFDi_Malloc( size_t bytes ); -void NFDi_Free( void *ptr ); -void NFDi_SetError( const char *msg ); -int NFDi_SafeStrncpy( char *dst, const char *src, size_t maxCopy ); -int32_t NFDi_UTF8_Strlen( const nfdchar_t *str ); -int NFDi_IsFilterSegmentChar( char ch ); -void NFDi_SplitPath(const char *path, const char **out_dir, const char **out_filename); +void* NFDi_Malloc(size_t bytes); +void NFDi_Free(void* ptr); +void NFDi_SetError(const char* msg); +int NFDi_SafeStrncpy(char* dst, const char* src, size_t maxCopy); +int32_t NFDi_UTF8_Strlen(const nfdchar_t* str); +int NFDi_IsFilterSegmentChar(char ch); +void NFDi_SplitPath(const char* path, const char** out_dir, const char** out_filename); #ifdef __cplusplus } #endif diff --git a/src/nfd_gtk.c b/src/nfd_gtk.c index 321371c..cdb1305 100644 --- a/src/nfd_gtk.c +++ b/src/nfd_gtk.c @@ -10,7 +10,7 @@ #include #include #if defined(GDK_WINDOWING_X11) -#include +# include #endif /* defined(GDK_WINDOWING_X11) */ #include "nfd.h" #include "nfd_common.h" @@ -20,103 +20,101 @@ const char INIT_FAIL_MSG[] = "gtk_init_check failed to initilaize GTK+"; #ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wstringop-truncation" +# pragma GCC diagnostic ignored "-Wstringop-truncation" #endif -static void AddTypeToFilterName( const char *typebuf, char *filterName, size_t bufsize ) +static void +AddTypeToFilterName(const char* typebuf, char* filterName, size_t bufsize) { const char SEP[] = ", "; size_t len = strlen(filterName); - if ( len != 0 ) - { - strncat( filterName, SEP, bufsize - len - 1 ); + if (len != 0) { + strncat(filterName, SEP, bufsize - len - 1); len += strlen(SEP); } - - strncat( filterName, typebuf, bufsize - len - 1 ); + + strncat(filterName, typebuf, bufsize - len - 1); } -static void AddFiltersToDialog( GtkWidget *dialog, const char *filterList ) +static void +AddFiltersToDialog(GtkWidget* dialog, const char* filterList) { - GtkFileFilter *filter; - char typebuf[NFD_MAX_STRLEN] = {0}; - const char *p_filterList = filterList; - char *p_typebuf = typebuf; - char filterName[NFD_MAX_STRLEN] = {0}; - - if ( !filterList || strlen(filterList) == 0 ) + GtkFileFilter* filter; + char typebuf[NFD_MAX_STRLEN] = {0}; + const char* p_filterList = filterList; + char* p_typebuf = typebuf; + char filterName[NFD_MAX_STRLEN] = {0}; + + if (!filterList || strlen(filterList) == 0) return; filter = gtk_file_filter_new(); - while ( 1 ) - { - - if ( NFDi_IsFilterSegmentChar(*p_filterList) ) - { - char typebufWildcard[NFD_MAX_STRLEN+3]; + while (1) { + if (NFDi_IsFilterSegmentChar(*p_filterList)) { + char typebufWildcard[NFD_MAX_STRLEN + 3]; /* add another type to the filter */ - assert( strlen(typebuf) > 0 ); - assert( strlen(typebuf) < NFD_MAX_STRLEN-1 ); - - snprintf( typebufWildcard, NFD_MAX_STRLEN+3, "*.%s", typebuf ); - AddTypeToFilterName( typebuf, filterName, NFD_MAX_STRLEN ); - - gtk_file_filter_add_pattern( filter, typebufWildcard ); - + assert(strlen(typebuf) > 0); + assert(strlen(typebuf) < NFD_MAX_STRLEN - 1); + + snprintf(typebufWildcard, NFD_MAX_STRLEN + 3, "*.%s", typebuf); + AddTypeToFilterName(typebuf, filterName, NFD_MAX_STRLEN); + + gtk_file_filter_add_pattern(filter, typebufWildcard); + p_typebuf = typebuf; - memset( typebuf, 0, sizeof(char) * NFD_MAX_STRLEN ); + memset(typebuf, 0, sizeof(char) * NFD_MAX_STRLEN); } - - if ( *p_filterList == ';' || *p_filterList == '\0' ) - { + + if (*p_filterList == ';' || *p_filterList == '\0') { /* end of filter -- add it to the dialog */ - - gtk_file_filter_set_name( filter, filterName ); - gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter ); + + gtk_file_filter_set_name(filter, filterName); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); filterName[0] = '\0'; - if ( *p_filterList == '\0' ) + if (*p_filterList == '\0') break; - filter = gtk_file_filter_new(); + filter = gtk_file_filter_new(); } - if ( !NFDi_IsFilterSegmentChar( *p_filterList ) ) - { + if (!NFDi_IsFilterSegmentChar(*p_filterList)) { *p_typebuf = *p_filterList; p_typebuf++; } p_filterList++; } - + /* always append a wildcard option to the end*/ filter = gtk_file_filter_new(); - gtk_file_filter_set_name( filter, "*.*" ); - gtk_file_filter_add_pattern( filter, "*" ); - gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(dialog), filter ); + gtk_file_filter_set_name(filter, "*.*"); + gtk_file_filter_add_pattern(filter, "*"); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } -static void GetFirstFilterExtension(const char *filterList, char outExt[NFD_MAX_STRLEN]) { - const char *p = filterList; +static void +GetFirstFilterExtension(const char* filterList, char outExt[NFD_MAX_STRLEN]) +{ + const char* p = filterList; size_t len = 0; - while (len < NFD_MAX_STRLEN-1 && isalpha(*p)) { + while (len < NFD_MAX_STRLEN - 1 && isalpha(*p)) { len = p - filterList; outExt[len] = *p; p++; - } - outExt[len+1] = '\0'; + outExt[len + 1] = '\0'; } -static void SetDefaultDir( GtkWidget *dialog, const char *defaultPath ) +static void +SetDefaultDir(GtkWidget* dialog, const char* defaultPath) { fflush(stdout); - if ( !defaultPath || defaultPath[0] == '\0' ) + if (!defaultPath || defaultPath[0] == '\0') return; /* GTK+ manual recommends not specifically setting the default path. @@ -126,87 +124,85 @@ static void SetDefaultDir( GtkWidget *dialog, const char *defaultPath ) to comment out. -ml */ if (ftg_is_dir(defaultPath)) - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(dialog), defaultPath); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), defaultPath); else - gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(dialog), defaultPath); - + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), defaultPath); } -static nfdresult_t AllocPathSet( GSList *fileList, nfdpathset_t *pathSet ) +static nfdresult_t +AllocPathSet(GSList* fileList, nfdpathset_t* pathSet) { - size_t bufSize = 0; - GSList *node; - nfdchar_t *p_buf; - size_t count = 0; - + size_t bufSize = 0; + GSList* node; + nfdchar_t* p_buf; + size_t count = 0; + assert(fileList); assert(pathSet); - pathSet->count = (size_t)g_slist_length( fileList ); - assert( pathSet->count > 0 ); + pathSet->count = (size_t)g_slist_length(fileList); + assert(pathSet->count > 0); - pathSet->indices = NFDi_Malloc( sizeof(size_t)*pathSet->count ); - if ( !pathSet->indices ) - { + pathSet->indices = NFDi_Malloc(sizeof(size_t) * pathSet->count); + if (!pathSet->indices) { return NFD_ERROR; } /* count the total space needed for buf */ - for ( node = fileList; node; node = node->next ) - { + for (node = fileList; node; node = node->next) { assert(node->data); - bufSize += strlen( (const gchar*)node->data ) + 1; + bufSize += strlen((const gchar*)node->data) + 1; } - pathSet->buf = NFDi_Malloc( sizeof(nfdchar_t) * bufSize ); + pathSet->buf = NFDi_Malloc(sizeof(nfdchar_t) * bufSize); /* fill buf */ p_buf = pathSet->buf; - for ( node = fileList; node; node = node->next ) - { - nfdchar_t *path = (nfdchar_t*)(node->data); - size_t byteLen = strlen(path)+1; - ptrdiff_t index; - - memcpy( p_buf, path, byteLen ); + for (node = fileList; node; node = node->next) { + nfdchar_t* path = (nfdchar_t*)(node->data); + size_t byteLen = strlen(path) + 1; + ptrdiff_t index; + + memcpy(p_buf, path, byteLen); g_free(node->data); index = p_buf - pathSet->buf; - assert( index >= 0 ); + assert(index >= 0); pathSet->indices[count] = (size_t)index; p_buf += byteLen; ++count; } - g_slist_free( fileList ); - + g_slist_free(fileList); + return NFD_OKAY; } -static void WaitForCleanup(void) +static void +WaitForCleanup(void) { - while (gtk_events_pending()) - gtk_main_iteration(); + while (gtk_events_pending()) gtk_main_iteration(); } -static char *AllocUserFilename(GtkWidget *dialog, char *gtk_filename) { +static char* +AllocUserFilename(GtkWidget* dialog, char* gtk_filename) +{ // polyfill: if no extension, add the first extension from the // gtk file filter. char filter_ext[NFD_MAX_STRLEN] = {0}; - GtkFileFilter *ff = gtk_file_chooser_get_filter( GTK_FILE_CHOOSER(dialog)); + GtkFileFilter* ff = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog)); if (ff) - GetFirstFilterExtension(gtk_file_filter_get_name( GTK_FILE_FILTER(ff)), filter_ext); + GetFirstFilterExtension(gtk_file_filter_get_name(GTK_FILE_FILTER(ff)), + filter_ext); - char *specified_ext = ftg_get_filename_ext(gtk_filename); - char *outPath; - - if (specified_ext[0] == '\0' && - filter_ext[0] != '\0' && - gtk_filename[strlen(gtk_filename)-1] != '.') { + char* specified_ext = ftg_get_filename_ext(gtk_filename); + char* outPath; + if (specified_ext[0] == '\0' && filter_ext[0] != '\0' && + gtk_filename[strlen(gtk_filename) - 1] != '.') { outPath = ftg_strcatall(3, gtk_filename, ".", filter_ext); } else { outPath = ftg_strcatall(1, gtk_filename); @@ -216,40 +212,43 @@ static char *AllocUserFilename(GtkWidget *dialog, char *gtk_filename) { } -static void ConfigureFocus(GtkWidget *dialog) +static void +ConfigureFocus(GtkWidget* dialog) { #if defined(GDK_WINDOWING_X11) /* Work around focus issue on X11 (https://github.com/mlabbe/nativefiledialog/issues/79) */ gtk_widget_show_all(dialog); if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { - GdkWindow *window = gtk_widget_get_window(dialog); - gdk_window_set_events(window, gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK); - gtk_window_present_with_time(GTK_WINDOW(dialog), gdk_x11_get_server_time(window)); + GdkWindow* window = gtk_widget_get_window(dialog); + gdk_window_set_events( + window, gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK); + gtk_window_present_with_time(GTK_WINDOW(dialog), + gdk_x11_get_server_time(window)); } #endif /* defined(GDK_WINDOWING_X11) */ } /* public */ -nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) -{ - GtkWidget *dialog; +nfdresult_t +NFD_OpenDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) +{ + GtkWidget* dialog; nfdresult_t result; - if ( !gtk_init_check( NULL, NULL ) ) - { + if (!gtk_init_check(NULL, NULL)) { NFDi_SetError(INIT_FAIL_MSG); return NFD_ERROR; } - dialog = gtk_file_chooser_dialog_new( "Open File", - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - "_Cancel", GTK_RESPONSE_CANCEL, - "_Open", GTK_RESPONSE_ACCEPT, - NULL ); + dialog = gtk_file_chooser_dialog_new("Open File", + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Open", + GTK_RESPONSE_ACCEPT, + NULL); /* Build the filter list */ AddFiltersToDialog(dialog, filterList); @@ -260,10 +259,9 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, ConfigureFocus(dialog); result = NFD_CANCEL; - if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) - { - char *filename; - filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) ); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + char* filename; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); *outPath = AllocUserFilename(dialog, filename); g_free(filename); @@ -283,26 +281,28 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, } -nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdpathset_t *outPaths ) +nfdresult_t +NFD_OpenDialogMultiple(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdpathset_t* outPaths) { - GtkWidget *dialog; + GtkWidget* dialog; nfdresult_t result; - if ( !gtk_init_check( NULL, NULL ) ) - { + if (!gtk_init_check(NULL, NULL)) { NFDi_SetError(INIT_FAIL_MSG); return NFD_ERROR; } - dialog = gtk_file_chooser_dialog_new( "Open Files", - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - "_Cancel", GTK_RESPONSE_CANCEL, - "_Open", GTK_RESPONSE_ACCEPT, - NULL ); - gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER(dialog), TRUE ); + dialog = gtk_file_chooser_dialog_new("Open Files", + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Open", + GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); /* Build the filter list */ AddFiltersToDialog(dialog, filterList); @@ -313,15 +313,13 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, ConfigureFocus(dialog); result = NFD_CANCEL; - if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) - { - GSList *fileList = gtk_file_chooser_get_filenames( GTK_FILE_CHOOSER(dialog) ); - if ( AllocPathSet( fileList, outPaths ) == NFD_ERROR ) - { + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + GSList* fileList = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); + if (AllocPathSet(fileList, outPaths) == NFD_ERROR) { gtk_widget_destroy(dialog); return NFD_ERROR; } - + result = NFD_OKAY; } @@ -332,39 +330,38 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, return result; } -nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) +nfdresult_t +NFD_SaveDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) { - GtkWidget *dialog; + GtkWidget* dialog; nfdresult_t result; - if ( !gtk_init_check( NULL, NULL ) ) - { + if (!gtk_init_check(NULL, NULL)) { NFDi_SetError(INIT_FAIL_MSG); return NFD_ERROR; } - dialog = gtk_file_chooser_dialog_new( "Save File", - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - "_Cancel", GTK_RESPONSE_CANCEL, - "_Save", GTK_RESPONSE_ACCEPT, - NULL ); - gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(dialog), TRUE ); + dialog = gtk_file_chooser_dialog_new("Save File", + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Save", + GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); - /* Build the filter list */ + /* Build the filter list */ AddFiltersToDialog(dialog, filterList); /* Set the default dir */ SetDefaultDir(dialog, defaultPath); ConfigureFocus(dialog); - result = NFD_CANCEL; - if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) - { - char *filename; - filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) ); + result = NFD_CANCEL; + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + char* filename; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); *outPath = AllocUserFilename(dialog, filename); g_free(filename); @@ -380,29 +377,30 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, WaitForCleanup(); gtk_widget_destroy(dialog); WaitForCleanup(); - + return result; } -nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, - nfdchar_t **outPath) +nfdresult_t +NFD_PickFolder(const nfdchar_t* defaultPath, nfdchar_t** outPath) { - GtkWidget *dialog; + GtkWidget* dialog; nfdresult_t result; - if (!gtk_init_check(NULL, NULL)) - { + if (!gtk_init_check(NULL, NULL)) { NFDi_SetError(INIT_FAIL_MSG); return NFD_ERROR; } - dialog = gtk_file_chooser_dialog_new( "Select folder", - NULL, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - "_Cancel", GTK_RESPONSE_CANCEL, - "_Select", GTK_RESPONSE_ACCEPT, - NULL ); - gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(dialog), TRUE ); + dialog = gtk_file_chooser_dialog_new("Select folder", + NULL, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Select", + GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); /* Set the default dir */ @@ -410,11 +408,10 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, ConfigureFocus(dialog); - result = NFD_CANCEL; - if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) - { - char *filename; - filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) ); + result = NFD_CANCEL; + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + char* filename; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); *outPath = AllocUserFilename(dialog, filename); g_free(filename); @@ -430,6 +427,6 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, WaitForCleanup(); gtk_widget_destroy(dialog); WaitForCleanup(); - + return result; } diff --git a/src/nfd_win.cpp b/src/nfd_win.cpp index 49b9bbf..1a4ad2a 100644 --- a/src/nfd_win.cpp +++ b/src/nfd_win.cpp @@ -7,12 +7,12 @@ #ifdef __MINGW32__ // Explicitly setting NTDDI version, this is necessary for the MinGW compiler -#define NTDDI_VERSION NTDDI_VISTA -#define _WIN32_WINNT _WIN32_WINNT_VISTA +# define NTDDI_VERSION NTDDI_VISTA +# define _WIN32_WINNT _WIN32_WINNT_VISTA #endif #ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS #endif #define _CRTDBG_MAP_ALLOC @@ -21,7 +21,7 @@ /* only locally define UNICODE in this compilation unit */ #ifndef UNICODE -#define UNICODE +# define UNICODE #endif #include @@ -33,10 +33,10 @@ #define COM_INITFLAGS ::COINIT_APARTMENTTHREADED | ::COINIT_DISABLE_OLE1DDE -static BOOL COMIsInitialized(HRESULT coResult) +static BOOL +COMIsInitialized(HRESULT coResult) { - if (coResult == RPC_E_CHANGED_MODE) - { + if (coResult == RPC_E_CHANGED_MODE) { // If COM was previously initialized with different init flags, // NFD still needs to operate. Eat this warning. return TRUE; @@ -45,12 +45,14 @@ static BOOL COMIsInitialized(HRESULT coResult) return SUCCEEDED(coResult); } -static HRESULT COMInit(void) +static HRESULT +COMInit(void) { return ::CoInitializeEx(NULL, COM_INITFLAGS); } -static void COMUninit(HRESULT coResult) +static void +COMUninit(HRESULT coResult) { // do not uninitialize if RPC_E_CHANGED_MODE occurred -- this // case does not refcount COM. @@ -59,172 +61,163 @@ static void COMUninit(HRESULT coResult) } // allocs the space in outPath -- call free() -static void CopyWCharToNFDChar( const wchar_t *inStr, nfdchar_t **outStr ) +static void +CopyWCharToNFDChar(const wchar_t* inStr, nfdchar_t** outStr) { - int inStrCharacterCount = static_cast(wcslen(inStr)); - int bytesNeeded = WideCharToMultiByte( CP_UTF8, 0, - inStr, inStrCharacterCount, - NULL, 0, NULL, NULL ); - assert( bytesNeeded ); + int inStrCharacterCount = static_cast(wcslen(inStr)); + int bytesNeeded = WideCharToMultiByte( + CP_UTF8, 0, inStr, inStrCharacterCount, NULL, 0, NULL, NULL); + assert(bytesNeeded); bytesNeeded += 1; - *outStr = (nfdchar_t*)NFDi_Malloc( bytesNeeded ); - if ( !*outStr ) + *outStr = (nfdchar_t*)NFDi_Malloc(bytesNeeded); + if (!*outStr) return; - int bytesWritten = WideCharToMultiByte( CP_UTF8, 0, - inStr, -1, - *outStr, bytesNeeded, - NULL, NULL ); - assert( bytesWritten ); _NFD_UNUSED( bytesWritten ); + int bytesWritten = + WideCharToMultiByte(CP_UTF8, 0, inStr, -1, *outStr, bytesNeeded, NULL, NULL); + assert(bytesWritten); + _NFD_UNUSED(bytesWritten); } /* includes NULL terminator byte in return */ -static size_t GetUTF8ByteCountForWChar( const wchar_t *str ) +static size_t +GetUTF8ByteCountForWChar(const wchar_t* str) { - size_t bytesNeeded = WideCharToMultiByte( CP_UTF8, 0, - str, -1, - NULL, 0, NULL, NULL ); - assert( bytesNeeded ); - return bytesNeeded+1; + size_t bytesNeeded = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); + assert(bytesNeeded); + return bytesNeeded + 1; } // write to outPtr -- no free() necessary. -static int CopyWCharToExistingNFDCharBuffer( const wchar_t *inStr, nfdchar_t *outPtr ) +static int +CopyWCharToExistingNFDCharBuffer(const wchar_t* inStr, nfdchar_t* outPtr) { - int bytesNeeded = static_cast(GetUTF8ByteCountForWChar( inStr )); + int bytesNeeded = static_cast(GetUTF8ByteCountForWChar(inStr)); /* invocation copies null term */ - int bytesWritten = WideCharToMultiByte( CP_UTF8, 0, - inStr, -1, - outPtr, bytesNeeded, - NULL, 0 ); - assert( bytesWritten ); + int bytesWritten = + WideCharToMultiByte(CP_UTF8, 0, inStr, -1, outPtr, bytesNeeded, NULL, 0); + assert(bytesWritten); return bytesWritten; - } // allocs the space in outStr -- call free() -static void CopyNFDCharToWChar( const nfdchar_t *inStr, size_t inStrLen, wchar_t **outStr ) +static void +CopyNFDCharToWChar(const nfdchar_t* inStr, size_t inStrLen, wchar_t** outStr) { int inStrByteCount = (int)inStrLen; /* byte count does not include terminator */ - int charsNeeded = MultiByteToWideChar(CP_UTF8, 0, - inStr, (int)inStrByteCount, - NULL, 0 ); - assert( charsNeeded ); - assert( !*outStr ); - charsNeeded += 1; // terminator - - *outStr = (wchar_t*)NFDi_Malloc( charsNeeded * sizeof(wchar_t) ); - if ( !*outStr ) - return; - - MultiByteToWideChar(CP_UTF8, 0, - inStr, (int)inStrByteCount, - *outStr, charsNeeded); - (*outStr)[charsNeeded-1] = '\0'; + int charsNeeded = + MultiByteToWideChar(CP_UTF8, 0, inStr, (int)inStrByteCount, NULL, 0); + assert(charsNeeded); + assert(!*outStr); + charsNeeded += 1; // terminator + + *outStr = (wchar_t*)NFDi_Malloc(charsNeeded * sizeof(wchar_t)); + if (!*outStr) + return; + + MultiByteToWideChar(CP_UTF8, 0, inStr, (int)inStrByteCount, *outStr, charsNeeded); + (*outStr)[charsNeeded - 1] = '\0'; } /* ext is in format "jpg", no wildcards or separators */ -static int AppendExtensionToSpecBuf( const char *ext, char *specBuf, size_t specBufLen ) +static int +AppendExtensionToSpecBuf(const char* ext, char* specBuf, size_t specBufLen) { const char SEP[] = ";"; - assert( specBufLen > strlen(ext)+3 ); - - if ( strlen(specBuf) > 0 ) - { - strncat( specBuf, SEP, specBufLen - strlen(specBuf) - 1 ); + assert(specBufLen > strlen(ext) + 3); + + if (strlen(specBuf) > 0) { + strncat(specBuf, SEP, specBufLen - strlen(specBuf) - 1); specBufLen += strlen(SEP); } char extWildcard[NFD_MAX_STRLEN]; - int bytesWritten = sprintf_s( extWildcard, NFD_MAX_STRLEN, "*.%s", ext ); - assert( bytesWritten == (int)(strlen(ext)+2) ); + int bytesWritten = sprintf_s(extWildcard, NFD_MAX_STRLEN, "*.%s", ext); + assert(bytesWritten == (int)(strlen(ext) + 2)); _NFD_UNUSED(bytesWritten); - - strncat( specBuf, extWildcard, specBufLen - strlen(specBuf) - 1 ); + + strncat(specBuf, extWildcard, specBufLen - strlen(specBuf) - 1); return NFD_OKAY; } -static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileDialog, const char *filterList ) +static nfdresult_t +AddFiltersToDialog(::IFileDialog* fileDialog, const char* filterList) { const wchar_t WILDCARD[] = L"*.*"; - if ( !filterList || strlen(filterList) == 0 ) + if (!filterList || strlen(filterList) == 0) return NFD_OKAY; // Count rows to alloc - UINT filterCount = 1; /* guaranteed to have one filter on a correct, non-empty parse */ - const char *p_filterList; - for ( p_filterList = filterList; *p_filterList; ++p_filterList ) - { - if ( *p_filterList == ';' ) + UINT filterCount = + 1; /* guaranteed to have one filter on a correct, non-empty parse */ + const char* p_filterList; + for (p_filterList = filterList; *p_filterList; ++p_filterList) { + if (*p_filterList == ';') ++filterCount; - } + } assert(filterCount); - if ( !filterCount ) - { + if (!filterCount) { NFDi_SetError("Error parsing filters."); return NFD_ERROR; } /* filterCount plus 1 because we hardcode the *.* wildcard after the while loop */ - COMDLG_FILTERSPEC *specList = (COMDLG_FILTERSPEC*)NFDi_Malloc( sizeof(COMDLG_FILTERSPEC) * ((size_t)filterCount + 1) ); - if ( !specList ) - { + COMDLG_FILTERSPEC* specList = (COMDLG_FILTERSPEC*)NFDi_Malloc( + sizeof(COMDLG_FILTERSPEC) * ((size_t)filterCount + 1)); + if (!specList) { return NFD_ERROR; } - for (UINT i = 0; i < filterCount+1; ++i ) - { + for (UINT i = 0; i < filterCount + 1; ++i) { specList[i].pszName = NULL; specList[i].pszSpec = NULL; } size_t specIdx = 0; p_filterList = filterList; - char typebuf[NFD_MAX_STRLEN] = {0}; /* one per comma or semicolon */ - char *p_typebuf = typebuf; + char typebuf[NFD_MAX_STRLEN] = {0}; /* one per comma or semicolon */ + char* p_typebuf = typebuf; char specbuf[NFD_MAX_STRLEN] = {0}; /* one per semicolon */ - while ( 1 ) - { - if ( NFDi_IsFilterSegmentChar(*p_filterList) ) - { + while (1) { + if (NFDi_IsFilterSegmentChar(*p_filterList)) { if (specbuf[0] == '\0') { - wchar_t *ext = NULL; + wchar_t* ext = NULL; CopyNFDCharToWChar(typebuf, strlen(typebuf), &ext); fileDialog->SetDefaultExtension(ext); NFDi_Free(ext); } /* append a type to the specbuf (pending filter) */ - AppendExtensionToSpecBuf( typebuf, specbuf, NFD_MAX_STRLEN ); + AppendExtensionToSpecBuf(typebuf, specbuf, NFD_MAX_STRLEN); p_typebuf = typebuf; - memset( typebuf, 0, sizeof(char)*NFD_MAX_STRLEN ); + memset(typebuf, 0, sizeof(char) * NFD_MAX_STRLEN); } - if ( *p_filterList == ';' || *p_filterList == '\0' ) - { + if (*p_filterList == ';' || *p_filterList == '\0') { /* end of filter -- add it to specList */ - - CopyNFDCharToWChar( specbuf, strlen(specbuf), (wchar_t**)&specList[specIdx].pszName ); - CopyNFDCharToWChar( specbuf, strlen(specbuf), (wchar_t**)&specList[specIdx].pszSpec ); - - memset( specbuf, 0, sizeof(char)*NFD_MAX_STRLEN ); + + CopyNFDCharToWChar( + specbuf, strlen(specbuf), (wchar_t**)&specList[specIdx].pszName); + CopyNFDCharToWChar( + specbuf, strlen(specbuf), (wchar_t**)&specList[specIdx].pszSpec); + + memset(specbuf, 0, sizeof(char) * NFD_MAX_STRLEN); ++specIdx; - if ( specIdx == filterCount ) + if (specIdx == filterCount) break; } - if ( !NFDi_IsFilterSegmentChar( *p_filterList )) - { + if (!NFDi_IsFilterSegmentChar(*p_filterList)) { *p_typebuf = *p_filterList; ++p_typebuf; } @@ -235,102 +228,94 @@ static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileDialog, const char *fi /* Add wildcard */ specList[specIdx].pszSpec = WILDCARD; specList[specIdx].pszName = WILDCARD; - - fileDialog->SetFileTypes( filterCount+1, specList ); + + fileDialog->SetFileTypes(filterCount + 1, specList); /* free speclist */ - for ( size_t i = 0; i < filterCount; ++i ) - { - NFDi_Free( (void*)specList[i].pszSpec ); + for (size_t i = 0; i < filterCount; ++i) { + NFDi_Free((void*)specList[i].pszSpec); } - NFDi_Free( specList ); + NFDi_Free(specList); return NFD_OKAY; } -static nfdresult_t AllocPathSet( IShellItemArray *shellItems, nfdpathset_t *pathSet ) +static nfdresult_t +AllocPathSet(IShellItemArray* shellItems, nfdpathset_t* pathSet) { const char ERRORMSG[] = "Error allocating pathset."; assert(shellItems); assert(pathSet); - + // How many items in shellItems? - DWORD numShellItems; + DWORD numShellItems; HRESULT result = shellItems->GetCount(&numShellItems); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError(ERRORMSG); return NFD_ERROR; } pathSet->count = static_cast(numShellItems); - assert( pathSet->count > 0 ); + assert(pathSet->count > 0); - pathSet->indices = (size_t*)NFDi_Malloc( sizeof(size_t)*pathSet->count ); - if ( !pathSet->indices ) - { + pathSet->indices = (size_t*)NFDi_Malloc(sizeof(size_t) * pathSet->count); + if (!pathSet->indices) { return NFD_ERROR; } /* count the total bytes needed for buf */ size_t bufSize = 0; - for ( DWORD i = 0; i < numShellItems; ++i ) - { - ::IShellItem *shellItem; + for (DWORD i = 0; i < numShellItems; ++i) { + ::IShellItem* shellItem; result = shellItems->GetItemAt(i, &shellItem); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError(ERRORMSG); return NFD_ERROR; } // Confirm SFGAO_FILESYSTEM is true for this shellitem, or ignore it. SFGAOF attribs; - result = shellItem->GetAttributes( SFGAO_FILESYSTEM, &attribs ); - if ( !SUCCEEDED(result) ) - { + result = shellItem->GetAttributes(SFGAO_FILESYSTEM, &attribs); + if (!SUCCEEDED(result)) { NFDi_SetError(ERRORMSG); return NFD_ERROR; } - if ( !(attribs & SFGAO_FILESYSTEM) ) + if (!(attribs & SFGAO_FILESYSTEM)) continue; LPWSTR name; shellItem->GetDisplayName(SIGDN_FILESYSPATH, &name); // Calculate length of name with UTF-8 encoding - bufSize += GetUTF8ByteCountForWChar( name ); - + bufSize += GetUTF8ByteCountForWChar(name); + CoTaskMemFree(name); } assert(bufSize); - pathSet->buf = (nfdchar_t*)NFDi_Malloc( sizeof(nfdchar_t) * bufSize ); - memset( pathSet->buf, 0, sizeof(nfdchar_t) * bufSize ); + pathSet->buf = (nfdchar_t*)NFDi_Malloc(sizeof(nfdchar_t) * bufSize); + memset(pathSet->buf, 0, sizeof(nfdchar_t) * bufSize); /* fill buf */ - nfdchar_t *p_buf = pathSet->buf; - for (DWORD i = 0; i < numShellItems; ++i ) - { - ::IShellItem *shellItem; + nfdchar_t* p_buf = pathSet->buf; + for (DWORD i = 0; i < numShellItems; ++i) { + ::IShellItem* shellItem; result = shellItems->GetItemAt(i, &shellItem); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError(ERRORMSG); return NFD_ERROR; } // Confirm SFGAO_FILESYSTEM is true for this shellitem, or ignore it. SFGAOF attribs; - result = shellItem->GetAttributes( SFGAO_FILESYSTEM, &attribs ); - if ( !SUCCEEDED(result) ) - { + result = shellItem->GetAttributes(SFGAO_FILESYSTEM, &attribs); + if (!SUCCEEDED(result)) { NFDi_SetError(ERRORMSG); return NFD_ERROR; } - if ( !(attribs & SFGAO_FILESYSTEM) ) + if (!(attribs & SFGAO_FILESYSTEM)) continue; LPWSTR name; @@ -340,19 +325,20 @@ static nfdresult_t AllocPathSet( IShellItemArray *shellItems, nfdpathset_t *path CoTaskMemFree(name); ptrdiff_t index = p_buf - pathSet->buf; - assert( index >= 0 ); + assert(index >= 0); pathSet->indices[i] = static_cast(index); - - p_buf += bytesWritten; + + p_buf += bytesWritten; } - + return NFD_OKAY; } -static nfdresult_t SetDefaultDir( IFileDialog *dialog, const char *defaultPath ) +static nfdresult_t +SetDefaultDir(IFileDialog* dialog, const char* defaultPath) { - if ( !defaultPath || defaultPath[0] == '\0' ) + if (!defaultPath || defaultPath[0] == '\0') return NFD_OKAY; const char *defaultDir, *defaultFilename; @@ -366,38 +352,39 @@ static nfdresult_t SetDefaultDir( IFileDialog *dialog, const char *defaultPath ) defaultDirLen = strlen(defaultDir); } - wchar_t *defaultPathW = {0}; - CopyNFDCharToWChar( defaultPath, defaultDirLen, &defaultPathW ); + wchar_t* defaultPathW = {0}; + CopyNFDCharToWChar(defaultPath, defaultDirLen, &defaultPathW); - IShellItem *folder; - HRESULT result = SHCreateItemFromParsingName( defaultPathW, NULL, IID_PPV_ARGS(&folder) ); + IShellItem* folder; + HRESULT result = + SHCreateItemFromParsingName(defaultPathW, NULL, IID_PPV_ARGS(&folder)); // Valid non results. - if ( result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE) ) - { - NFDi_Free( defaultPathW ); + if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || + result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE)) { + NFDi_Free(defaultPathW); return NFD_OKAY; } - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Error creating ShellItem"); - NFDi_Free( defaultPathW ); + NFDi_Free(defaultPathW); return NFD_ERROR; } - + // Could also call SetDefaultFolder(), but this guarantees defaultPath -- more consistency across API. - dialog->SetFolder( folder ); + dialog->SetFolder(folder); - NFDi_Free( defaultPathW ); + NFDi_Free(defaultPathW); folder->Release(); - + return NFD_OKAY; } -static void SetDefaultFile( IFileDialog *dialog, const char *defaultPath) +static void +SetDefaultFile(IFileDialog* dialog, const char* defaultPath) { - if ( !defaultPath || defaultPath[0] == '\0' ) + if (!defaultPath || defaultPath[0] == '\0') return; const char *defaultDir, *defaultFilename; @@ -407,83 +394,76 @@ static void SetDefaultFile( IFileDialog *dialog, const char *defaultPath) if (!defaultFilename) return; - wchar_t *defaultFilenameW = {0}; - CopyNFDCharToWChar( defaultFilename, strlen(defaultFilename), &defaultFilenameW); + wchar_t* defaultFilenameW = {0}; + CopyNFDCharToWChar(defaultFilename, strlen(defaultFilename), &defaultFilenameW); - dialog->SetFileName( defaultFilenameW ); + dialog->SetFileName(defaultFilenameW); - NFDi_Free( defaultFilenameW ); + NFDi_Free(defaultFilenameW); } /* public */ -nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) +nfdresult_t +NFD_OpenDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) { nfdresult_t nfdResult = NFD_ERROR; - + HRESULT coResult = COMInit(); - if (!COMIsInitialized(coResult)) - { + if (!COMIsInitialized(coResult)) { NFDi_SetError("Could not initialize COM."); return nfdResult; } // Create dialog - ::IFileOpenDialog *fileOpenDialog(NULL); - HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, NULL, - CLSCTX_ALL, ::IID_IFileOpenDialog, - reinterpret_cast(&fileOpenDialog) ); - - if ( !SUCCEEDED(result) ) - { + ::IFileOpenDialog* fileOpenDialog(NULL); + HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, + NULL, + CLSCTX_ALL, + ::IID_IFileOpenDialog, + reinterpret_cast(&fileOpenDialog)); + + if (!SUCCEEDED(result)) { NFDi_SetError("Could not create dialog."); goto end; } // Build the filter list - if ( !AddFiltersToDialog( fileOpenDialog, filterList ) ) - { + if (!AddFiltersToDialog(fileOpenDialog, filterList)) { goto end; } // Set the default dir - if ( !SetDefaultDir( fileOpenDialog, defaultPath ) ) - { + if (!SetDefaultDir(fileOpenDialog, defaultPath)) { goto end; } // Set the default filename - SetDefaultFile( fileOpenDialog, defaultPath ); + SetDefaultFile(fileOpenDialog, defaultPath); // Show the dialog. result = fileOpenDialog->Show(NULL); - if ( SUCCEEDED(result) ) - { + if (SUCCEEDED(result)) { // Get the file name - ::IShellItem *shellItem(NULL); + ::IShellItem* shellItem(NULL); result = fileOpenDialog->GetResult(&shellItem); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Could not get shell item from dialog."); goto end; } - wchar_t *filePath(NULL); + wchar_t* filePath(NULL); result = shellItem->GetDisplayName(::SIGDN_FILESYSPATH, &filePath); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Could not get file path for selected."); shellItem->Release(); goto end; } - CopyWCharToNFDChar( filePath, outPath ); + CopyWCharToNFDChar(filePath, outPath); CoTaskMemFree(filePath); - if ( !*outPath ) - { + if (!*outPath) { /* error is malloc-based, error message would be redundant */ shellItem->Release(); goto end; @@ -491,13 +471,9 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, nfdResult = NFD_OKAY; shellItem->Release(); - } - else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED) ) - { + } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { nfdResult = NFD_CANCEL; - } - else - { + } else { NFDi_SetError("File dialog box show failed."); nfdResult = NFD_ERROR; } @@ -507,173 +483,156 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList, fileOpenDialog->Release(); COMUninit(coResult); - + return nfdResult; } -nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdpathset_t *outPaths ) +nfdresult_t +NFD_OpenDialogMultiple(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdpathset_t* outPaths) { nfdresult_t nfdResult = NFD_ERROR; HRESULT coResult = COMInit(); - if (!COMIsInitialized(coResult)) - { - NFDi_SetError("Could not initialize COM."); + if (!COMIsInitialized(coResult)) { + NFDi_SetError("Could not initialize COM."); return nfdResult; } // Create dialog - ::IFileOpenDialog *fileOpenDialog(NULL); - HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, NULL, - CLSCTX_ALL, ::IID_IFileOpenDialog, - reinterpret_cast(&fileOpenDialog) ); - - if ( !SUCCEEDED(result) ) - { + ::IFileOpenDialog* fileOpenDialog(NULL); + HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, + NULL, + CLSCTX_ALL, + ::IID_IFileOpenDialog, + reinterpret_cast(&fileOpenDialog)); + + if (!SUCCEEDED(result)) { fileOpenDialog = NULL; NFDi_SetError("Could not create dialog."); goto end; } // Build the filter list - if ( !AddFiltersToDialog( fileOpenDialog, filterList ) ) - { + if (!AddFiltersToDialog(fileOpenDialog, filterList)) { goto end; } // Set the default dir - if ( !SetDefaultDir( fileOpenDialog, defaultPath ) ) - { + if (!SetDefaultDir(fileOpenDialog, defaultPath)) { goto end; } // Set the default filename - SetDefaultFile( fileOpenDialog, defaultPath ); + SetDefaultFile(fileOpenDialog, defaultPath); // Set a flag for multiple options DWORD dwFlags; result = fileOpenDialog->GetOptions(&dwFlags); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Could not get options."); goto end; } result = fileOpenDialog->SetOptions(dwFlags | FOS_ALLOWMULTISELECT); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Could not set options."); goto end; } - + // Show the dialog. result = fileOpenDialog->Show(NULL); - if ( SUCCEEDED(result) ) - { - IShellItemArray *shellItems; - result = fileOpenDialog->GetResults( &shellItems ); - if ( !SUCCEEDED(result) ) - { + if (SUCCEEDED(result)) { + IShellItemArray* shellItems; + result = fileOpenDialog->GetResults(&shellItems); + if (!SUCCEEDED(result)) { NFDi_SetError("Could not get shell items."); goto end; } - - if ( AllocPathSet( shellItems, outPaths ) == NFD_ERROR ) - { + + if (AllocPathSet(shellItems, outPaths) == NFD_ERROR) { shellItems->Release(); goto end; } shellItems->Release(); nfdResult = NFD_OKAY; - } - else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED) ) - { + } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { nfdResult = NFD_CANCEL; - } - else - { + } else { NFDi_SetError("File dialog box show failed."); nfdResult = NFD_ERROR; } end: - if ( fileOpenDialog ) + if (fileOpenDialog) fileOpenDialog->Release(); COMUninit(coResult); - + return nfdResult; } -nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) +nfdresult_t +NFD_SaveDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) { nfdresult_t nfdResult = NFD_ERROR; HRESULT coResult = COMInit(); - if (!COMIsInitialized(coResult)) - { + if (!COMIsInitialized(coResult)) { NFDi_SetError("Could not initialize COM."); - return nfdResult; + return nfdResult; } - - // Create dialog - ::IFileSaveDialog *fileSaveDialog(NULL); - HRESULT result = ::CoCreateInstance(::CLSID_FileSaveDialog, NULL, - CLSCTX_ALL, ::IID_IFileSaveDialog, - reinterpret_cast(&fileSaveDialog) ); - if ( !SUCCEEDED(result) ) - { + // Create dialog + ::IFileSaveDialog* fileSaveDialog(NULL); + HRESULT result = ::CoCreateInstance(::CLSID_FileSaveDialog, + NULL, + CLSCTX_ALL, + ::IID_IFileSaveDialog, + reinterpret_cast(&fileSaveDialog)); + + if (!SUCCEEDED(result)) { fileSaveDialog = NULL; NFDi_SetError("Could not create dialog."); goto end; } // Build the filter list - if ( !AddFiltersToDialog( fileSaveDialog, filterList ) ) - { + if (!AddFiltersToDialog(fileSaveDialog, filterList)) { goto end; } // Set the default dir - if ( !SetDefaultDir( fileSaveDialog, defaultPath ) ) - { + if (!SetDefaultDir(fileSaveDialog, defaultPath)) { goto end; } // Set the default filename - SetDefaultFile( fileSaveDialog, defaultPath ); + SetDefaultFile(fileSaveDialog, defaultPath); // Show the dialog. result = fileSaveDialog->Show(NULL); - if ( SUCCEEDED(result) ) - { + if (SUCCEEDED(result)) { // Get the file name - ::IShellItem *shellItem; + ::IShellItem* shellItem; result = fileSaveDialog->GetResult(&shellItem); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Could not get shell item from dialog."); goto end; } - wchar_t *filePath(NULL); + wchar_t* filePath(NULL); result = shellItem->GetDisplayName(::SIGDN_FILESYSPATH, &filePath); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { shellItem->Release(); NFDi_SetError("Could not get file path for selected."); goto end; } - CopyWCharToNFDChar( filePath, outPath ); + CopyWCharToNFDChar(filePath, outPath); CoTaskMemFree(filePath); - if ( !*outPath ) - { + if (!*outPath) { /* error is malloc-based, error message would be redundant */ shellItem->Release(); goto end; @@ -681,120 +640,101 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, nfdResult = NFD_OKAY; shellItem->Release(); - } - else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED) ) - { + } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { nfdResult = NFD_CANCEL; - } - else - { + } else { NFDi_SetError("File dialog box show failed."); nfdResult = NFD_ERROR; } - + end: - if ( fileSaveDialog ) + if (fileSaveDialog) fileSaveDialog->Release(); COMUninit(coResult); - + return nfdResult; } -nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, - nfdchar_t **outPath) +nfdresult_t +NFD_PickFolder(const nfdchar_t* defaultPath, nfdchar_t** outPath) { nfdresult_t nfdResult = NFD_ERROR; - DWORD dwOptions = 0; + DWORD dwOptions = 0; HRESULT coResult = COMInit(); - if (!COMIsInitialized(coResult)) - { + if (!COMIsInitialized(coResult)) { NFDi_SetError("CoInitializeEx failed."); return nfdResult; } // Create dialog - ::IFileOpenDialog *fileDialog(NULL); - HRESULT result = CoCreateInstance(CLSID_FileOpenDialog, - NULL, - CLSCTX_ALL, - IID_PPV_ARGS(&fileDialog)); - if ( !SUCCEEDED(result) ) - { + ::IFileOpenDialog* fileDialog(NULL); + HRESULT result = CoCreateInstance( + CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_PPV_ARGS(&fileDialog)); + if (!SUCCEEDED(result)) { NFDi_SetError("CoCreateInstance for CLSID_FileOpenDialog failed."); goto end; } // Set the default dir - if (SetDefaultDir(fileDialog, defaultPath) != NFD_OKAY) - { + if (SetDefaultDir(fileDialog, defaultPath) != NFD_OKAY) { NFDi_SetError("SetDefaultDir failed."); goto end; } // Get the dialogs options - if (!SUCCEEDED(fileDialog->GetOptions(&dwOptions))) - { + if (!SUCCEEDED(fileDialog->GetOptions(&dwOptions))) { NFDi_SetError("GetOptions for IFileDialog failed."); goto end; } // Add in FOS_PICKFOLDERS which hides files and only allows selection of folders - if (!SUCCEEDED(fileDialog->SetOptions(dwOptions | FOS_PICKFOLDERS))) - { + if (!SUCCEEDED(fileDialog->SetOptions(dwOptions | FOS_PICKFOLDERS))) { NFDi_SetError("SetOptions for IFileDialog failed."); goto end; } // Show the dialog to the user result = fileDialog->Show(NULL); - if ( SUCCEEDED(result) ) - { + if (SUCCEEDED(result)) { // Get the folder name - ::IShellItem *shellItem(NULL); + ::IShellItem* shellItem(NULL); result = fileDialog->GetResult(&shellItem); - if ( !SUCCEEDED(result) ) - { + if (!SUCCEEDED(result)) { NFDi_SetError("Could not get file path for selected."); shellItem->Release(); goto end; } - wchar_t *path = NULL; + wchar_t* path = NULL; result = shellItem->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &path); - if ( !SUCCEEDED(result) ) - { - NFDi_SetError("GetDisplayName for IShellItem failed."); + if (!SUCCEEDED(result)) { + NFDi_SetError("GetDisplayName for IShellItem failed."); shellItem->Release(); goto end; } CopyWCharToNFDChar(path, outPath); CoTaskMemFree(path); - if ( !*outPath ) - { + if (!*outPath) { shellItem->Release(); goto end; } nfdResult = NFD_OKAY; shellItem->Release(); - } - else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED) ) - { + } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { nfdResult = NFD_CANCEL; - } - else - { + } else { NFDi_SetError("Show for IFileDialog failed."); nfdResult = NFD_ERROR; } - end: +end: if (fileDialog) fileDialog->Release(); diff --git a/src/nfd_zenity.c b/src/nfd_zenity.c index fa9f4ba..43ccc6d 100644 --- a/src/nfd_zenity.c +++ b/src/nfd_zenity.c @@ -17,90 +17,94 @@ const char NO_ZENITY_MSG[] = "zenity not installed"; -static void AddTypeToFilterName( const char *typebuf, char *filterName, size_t bufsize ) +static void +AddTypeToFilterName(const char* typebuf, char* filterName, size_t bufsize) { size_t len = strlen(filterName); - if( len > 0 ) - strncat( filterName, " *.", bufsize - len - 1 ); + if (len > 0) + strncat(filterName, " *.", bufsize - len - 1); else - strncat( filterName, "--file-filter=*.", bufsize - len - 1 ); - + strncat(filterName, "--file-filter=*.", bufsize - len - 1); + len = strlen(filterName); - strncat( filterName, typebuf, bufsize - len - 1 ); + strncat(filterName, typebuf, bufsize - len - 1); } -static void AddFiltersToCommandArgs(char** commandArgs, int commandArgsLen, const char *filterList ) +static void +AddFiltersToCommandArgs(char** commandArgs, int commandArgsLen, const char* filterList) { - char typebuf[NFD_MAX_STRLEN] = {0}; - const char *p_filterList = filterList; - char *p_typebuf = typebuf; - char filterName[NFD_MAX_STRLEN] = {0}; - int i; - - if ( !filterList || strlen(filterList) == 0 ) + char typebuf[NFD_MAX_STRLEN] = {0}; + const char* p_filterList = filterList; + char* p_typebuf = typebuf; + char filterName[NFD_MAX_STRLEN] = {0}; + int i; + + if (!filterList || strlen(filterList) == 0) return; - while ( 1 ) - { - - if ( NFDi_IsFilterSegmentChar(*p_filterList) ) - { - char typebufWildcard[NFD_MAX_STRLEN+3]; + while (1) { + if (NFDi_IsFilterSegmentChar(*p_filterList)) { + char typebufWildcard[NFD_MAX_STRLEN + 3]; /* add another type to the filter */ - assert( strlen(typebuf) > 0 ); - assert( strlen(typebuf) < NFD_MAX_STRLEN-1 ); - - snprintf( typebufWildcard, NFD_MAX_STRLEN+3, "*.%s", typebuf ); + assert(strlen(typebuf) > 0); + assert(strlen(typebuf) < NFD_MAX_STRLEN - 1); + + snprintf(typebufWildcard, NFD_MAX_STRLEN + 3, "*.%s", typebuf); + + AddTypeToFilterName(typebuf, filterName, NFD_MAX_STRLEN); - AddTypeToFilterName( typebuf, filterName, NFD_MAX_STRLEN ); - p_typebuf = typebuf; - memset( typebuf, 0, sizeof(char) * NFD_MAX_STRLEN ); + memset(typebuf, 0, sizeof(char) * NFD_MAX_STRLEN); } - - if ( *p_filterList == ';' || *p_filterList == '\0' ) - { + + if (*p_filterList == ';' || *p_filterList == '\0') { /* end of filter -- add it to the dialog */ - for(i = 0; commandArgs[i] != NULL && i < commandArgsLen; i++); + for (i = 0; commandArgs[i] != NULL && i < commandArgsLen; i++) + ; commandArgs[i] = strdup(filterName); - + filterName[0] = '\0'; - if ( *p_filterList == '\0' ) + if (*p_filterList == '\0') break; } - if ( !NFDi_IsFilterSegmentChar( *p_filterList ) ) - { + if (!NFDi_IsFilterSegmentChar(*p_filterList)) { *p_typebuf = *p_filterList; p_typebuf++; } p_filterList++; } - + /* always append a wildcard option to the end*/ - - for(i = 0; commandArgs[i] != NULL && i < commandArgsLen; i++); + + for (i = 0; commandArgs[i] != NULL && i < commandArgsLen; i++) + ; commandArgs[i] = strdup("--file-filter=*.*"); } -static nfdresult_t ZenityCommon(char** command, int commandLen, const char* defaultPath, const char* filterList, char** stdOut) +static nfdresult_t +ZenityCommon(char** command, + int commandLen, + const char* defaultPath, + const char* filterList, + char** stdOut) { - if(defaultPath != NULL) - { + if (defaultPath != NULL) { char* prefix = "--filename="; - int len = strlen(prefix) + strlen(defaultPath) + 1; + int len = strlen(prefix) + strlen(defaultPath) + 1; - char* tmp = (char*) calloc(len, 1); + char* tmp = (char*)calloc(len, 1); strcat(tmp, prefix); strcat(tmp, defaultPath); int i; - for(i = 0; command[i] != NULL && i < commandLen; i++); + for (i = 0; command[i] != NULL && i < commandLen; i++) + ; command[i] = tmp; } @@ -109,44 +113,40 @@ static nfdresult_t ZenityCommon(char** command, int commandLen, const char* defa int byteCount = 0; int exitCode = 0; - int processInvokeError = runCommandArray(stdOut, &byteCount, &exitCode, 0, command); + int processInvokeError = + runCommandArray(stdOut, &byteCount, &exitCode, 0, command); - for(int i = 0; command[i] != NULL && i < commandLen; i++) - free(command[i]); + for (int i = 0; command[i] != NULL && i < commandLen; i++) free(command[i]); nfdresult_t result = NFD_OKAY; - if(processInvokeError == COMMAND_NOT_FOUND) - { + if (processInvokeError == COMMAND_NOT_FOUND) { NFDi_SetError(NO_ZENITY_MSG); result = NFD_ERROR; - } - else - { - if(exitCode == 1) + } else { + if (exitCode == 1) result = NFD_CANCEL; } return result; } - -static nfdresult_t AllocPathSet(char* zenityList, nfdpathset_t *pathSet ) + +static nfdresult_t +AllocPathSet(char* zenityList, nfdpathset_t* pathSet) { assert(zenityList); assert(pathSet); - + size_t len = strlen(zenityList) + 1; pathSet->buf = NFDi_Malloc(len); int numEntries = 1; - for(size_t i = 0; i < len; i++) - { + for (size_t i = 0; i < len; i++) { char ch = zenityList[i]; - if(ch == '|') - { + if (ch == '|') { numEntries++; ch = '\0'; } @@ -155,33 +155,30 @@ static nfdresult_t AllocPathSet(char* zenityList, nfdpathset_t *pathSet ) } pathSet->count = numEntries; - assert( pathSet->count > 0 ); + assert(pathSet->count > 0); - pathSet->indices = NFDi_Malloc( sizeof(size_t)*pathSet->count ); + pathSet->indices = NFDi_Malloc(sizeof(size_t) * pathSet->count); int entry = 0; pathSet->indices[0] = 0; - for(size_t i = 0; i < len; i++) - { + for (size_t i = 0; i < len; i++) { char ch = zenityList[i]; - if(ch == '|') - { + if (ch == '|') { entry++; pathSet->indices[entry] = i + 1; } } - + return NFD_OKAY; } - + /* public */ -nfdresult_t NFD_OpenDialog( const char *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) -{ - int commandLen = 100; +nfdresult_t +NFD_OpenDialog(const char* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) +{ + int commandLen = 100; char* command[commandLen]; memset(command, 0, commandLen * sizeof(char*)); @@ -189,19 +186,17 @@ nfdresult_t NFD_OpenDialog( const char *filterList, command[1] = strdup("--file-selection"); command[2] = strdup("--title=Open File"); - char* stdOut = NULL; - nfdresult_t result = ZenityCommon(command, commandLen, defaultPath, filterList, &stdOut); - - if(stdOut != NULL) - { + char* stdOut = NULL; + nfdresult_t result = + ZenityCommon(command, commandLen, defaultPath, filterList, &stdOut); + + if (stdOut != NULL) { size_t len = strlen(stdOut); *outPath = NFDi_Malloc(len); memcpy(*outPath, stdOut, len); - (*outPath)[len-1] = '\0'; // trim out the final \n with a null terminator + (*outPath)[len - 1] = '\0'; // trim out the final \n with a null terminator free(stdOut); - } - else - { + } else { *outPath = NULL; } @@ -209,11 +204,12 @@ nfdresult_t NFD_OpenDialog( const char *filterList, } -nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdpathset_t *outPaths ) +nfdresult_t +NFD_OpenDialogMultiple(const nfdchar_t* filterList, + const nfdchar_t* defaultPath, + nfdpathset_t* outPaths) { - int commandLen = 100; + int commandLen = 100; char* command[commandLen]; memset(command, 0, commandLen * sizeof(char*)); @@ -222,32 +218,29 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList, command[2] = strdup("--title=Open Files"); command[3] = strdup("--multiple"); - char* stdOut = NULL; - nfdresult_t result = ZenityCommon(command, commandLen, defaultPath, filterList, &stdOut); - - if(stdOut != NULL) - { + char* stdOut = NULL; + nfdresult_t result = + ZenityCommon(command, commandLen, defaultPath, filterList, &stdOut); + + if (stdOut != NULL) { size_t len = strlen(stdOut); - stdOut[len-1] = '\0'; // remove trailing newline + stdOut[len - 1] = '\0'; // remove trailing newline - if ( AllocPathSet( stdOut, outPaths ) == NFD_ERROR ) + if (AllocPathSet(stdOut, outPaths) == NFD_ERROR) result = NFD_ERROR; free(stdOut); - } - else - { + } else { result = NFD_ERROR; } return result; } -nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, - const nfdchar_t *defaultPath, - nfdchar_t **outPath ) +nfdresult_t +NFD_SaveDialog(const nfdchar_t* filterList, const nfdchar_t* defaultPath, nfdchar_t** outPath) { - int commandLen = 100; + int commandLen = 100; char* command[commandLen]; memset(command, 0, commandLen * sizeof(char*)); @@ -256,29 +249,27 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList, command[2] = strdup("--title=Save File"); command[3] = strdup("--save"); - char* stdOut = NULL; - nfdresult_t result = ZenityCommon(command, commandLen, defaultPath, filterList, &stdOut); - - if(stdOut != NULL) - { + char* stdOut = NULL; + nfdresult_t result = + ZenityCommon(command, commandLen, defaultPath, filterList, &stdOut); + + if (stdOut != NULL) { size_t len = strlen(stdOut); *outPath = NFDi_Malloc(len); memcpy(*outPath, stdOut, len); - (*outPath)[len-1] = '\0'; // trim out the final \n with a null terminator + (*outPath)[len - 1] = '\0'; // trim out the final \n with a null terminator free(stdOut); - } - else - { + } else { *outPath = NULL; } return result; } -nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, - nfdchar_t **outPath) +nfdresult_t +NFD_PickFolder(const nfdchar_t* defaultPath, nfdchar_t** outPath) { - int commandLen = 100; + int commandLen = 100; char* command[commandLen]; memset(command, 0, commandLen * sizeof(char*)); @@ -287,19 +278,16 @@ nfdresult_t NFD_PickFolder(const nfdchar_t *defaultPath, command[2] = strdup("--directory"); command[3] = strdup("--title=Select folder"); - char* stdOut = NULL; + char* stdOut = NULL; nfdresult_t result = ZenityCommon(command, commandLen, defaultPath, "", &stdOut); - - if(stdOut != NULL) - { + + if (stdOut != NULL) { size_t len = strlen(stdOut); *outPath = NFDi_Malloc(len); memcpy(*outPath, stdOut, len); - (*outPath)[len-1] = '\0'; // trim out the final \n with a null terminator + (*outPath)[len - 1] = '\0'; // trim out the final \n with a null terminator free(stdOut); - } - else - { + } else { *outPath = NULL; } diff --git a/src/simple_exec.h b/src/simple_exec.h index c192cf2..bdc8b03 100644 --- a/src/simple_exec.h +++ b/src/simple_exec.h @@ -12,10 +12,19 @@ #ifndef SIMPLE_EXEC_H #define SIMPLE_EXEC_H -int runCommand(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* command, ...); -int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* const* allArgs); - -#endif // SIMPLE_EXEC_H +int runCommand(char** stdOut, + int* stdOutByteCount, + int* returnCode, + int includeStdErr, + char* command, + ...); +int runCommandArray(char** stdOut, + int* stdOutByteCount, + int* returnCode, + int includeStdErr, + char* const* allArgs); + +#endif // SIMPLE_EXEC_H #ifdef SIMPLE_EXEC_IMPLEMENTATION @@ -31,32 +40,38 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in #include "ftg_core.h" -#define release_assert(exp) { if (!(exp)) { abort(); } } +#define release_assert(exp) \ + { \ + if (!(exp)) { \ + abort(); \ + } \ + } -enum PIPE_FILE_DESCRIPTORS -{ - READ_FD = 0, - WRITE_FD = 1 -}; +enum PIPE_FILE_DESCRIPTORS { READ_FD = 0, WRITE_FD = 1 }; -enum RUN_COMMAND_ERROR -{ - COMMAND_RAN_OK = 0, - COMMAND_NOT_FOUND = 1 -}; +enum RUN_COMMAND_ERROR { COMMAND_RAN_OK = 0, COMMAND_NOT_FOUND = 1 }; -void sigchldHandler(int p){FTG_UNUSED(p);} +void +sigchldHandler(int p) +{ + FTG_UNUSED(p); +} -int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* const* allArgs) +int +runCommandArray(char** stdOut, + int* stdOutByteCount, + int* returnCode, + int includeStdErr, + char* const* allArgs) { // adapted from: https://stackoverflow.com/a/479103 - int bufferSize = 256; + int bufferSize = 256; char buffer[bufferSize + 1]; - int dataReadFromChildDefaultSize = bufferSize * 5; - int dataReadFromChildSize = dataReadFromChildDefaultSize; - int dataReadFromChildUsed = 0; + int dataReadFromChildDefaultSize = bufferSize * 5; + int dataReadFromChildSize = dataReadFromChildDefaultSize; + int dataReadFromChildUsed = 0; char* dataReadFromChild = (char*)malloc(dataReadFromChildSize); @@ -73,155 +88,146 @@ int runCommandArray(char** stdOut, int* stdOutByteCount, int* returnCode, int in prevHandler = signal(SIGCHLD, sigchldHandler); pid_t pid; - switch( pid = fork() ) + switch (pid = fork()) { + case -1: { + release_assert(0 && "Fork failed"); + break; + } + + case 0: // child { - case -1: - { - release_assert(0 && "Fork failed"); - break; + release_assert(dup2(parentToChild[READ_FD], STDIN_FILENO) != -1); + release_assert(dup2(childToParent[WRITE_FD], STDOUT_FILENO) != -1); + + if (includeStdErr) { + release_assert(dup2(childToParent[WRITE_FD], STDERR_FILENO) != -1); + } else { + int devNull = open("/dev/null", O_WRONLY); + release_assert(dup2(devNull, STDERR_FILENO) != -1); } - case 0: // child - { - release_assert(dup2(parentToChild[READ_FD ], STDIN_FILENO ) != -1); - release_assert(dup2(childToParent[WRITE_FD], STDOUT_FILENO) != -1); - - if(includeStdErr) - { - release_assert(dup2(childToParent[WRITE_FD], STDERR_FILENO) != -1); - } - else - { - int devNull = open("/dev/null", O_WRONLY); - release_assert(dup2(devNull, STDERR_FILENO) != -1); - } + // unused + release_assert(close(parentToChild[WRITE_FD]) == 0); + release_assert(close(childToParent[READ_FD]) == 0); + release_assert(close(errPipe[READ_FD]) == 0); - // unused - release_assert(close(parentToChild[WRITE_FD]) == 0); - release_assert(close(childToParent[READ_FD ]) == 0); - release_assert(close(errPipe[READ_FD]) == 0); - - const char* command = allArgs[0]; - execvp(command, allArgs); - - char err = 1; - ssize_t result = write(errPipe[WRITE_FD], &err, 1); - release_assert(result != -1); - - close(errPipe[WRITE_FD]); - close(parentToChild[READ_FD]); - close(childToParent[WRITE_FD]); - - exit(0); - } + const char* command = allArgs[0]; + execvp(command, allArgs); + char err = 1; + ssize_t result = write(errPipe[WRITE_FD], &err, 1); + release_assert(result != -1); - default: // parent - { - // unused - release_assert(close(parentToChild[READ_FD]) == 0); - release_assert(close(childToParent[WRITE_FD]) == 0); - release_assert(close(errPipe[WRITE_FD]) == 0); + close(errPipe[WRITE_FD]); + close(parentToChild[READ_FD]); + close(childToParent[WRITE_FD]); - while(1) + exit(0); + } + + + default: // parent + { + // unused + release_assert(close(parentToChild[READ_FD]) == 0); + release_assert(close(childToParent[WRITE_FD]) == 0); + release_assert(close(errPipe[WRITE_FD]) == 0); + + while (1) { + ssize_t bytesRead = 0; + switch (bytesRead = read(childToParent[READ_FD], buffer, bufferSize)) { + case 0: // End-of-File, or non-blocking read. { - ssize_t bytesRead = 0; - switch(bytesRead = read(childToParent[READ_FD], buffer, bufferSize)) - { - case 0: // End-of-File, or non-blocking read. - { - int status = 0; - release_assert(waitpid(pid, &status, 0) == pid); - - // done with these now - release_assert(close(parentToChild[WRITE_FD]) == 0); - release_assert(close(childToParent[READ_FD]) == 0); - - char errChar = 0; - ssize_t result = read(errPipe[READ_FD], &errChar, 1); - release_assert(result != -1); - close(errPipe[READ_FD]); - - if(errChar) - { - free(dataReadFromChild); - return COMMAND_NOT_FOUND; - } - - // free any un-needed memory with realloc + add a null terminator for convenience - dataReadFromChild = (char*)realloc(dataReadFromChild, dataReadFromChildUsed + 1); - dataReadFromChild[dataReadFromChildUsed] = '\0'; - - if(stdOut != NULL) - *stdOut = dataReadFromChild; - else - free(dataReadFromChild); - - if(stdOutByteCount != NULL) - *stdOutByteCount = dataReadFromChildUsed; - if(returnCode != NULL) - *returnCode = WEXITSTATUS(status); - - return COMMAND_RAN_OK; - } - case -1: - { - release_assert(0 && "read() failed"); - break; - } - - default: - { - if(dataReadFromChildUsed + bytesRead + 1 >= dataReadFromChildSize) - { - dataReadFromChildSize += dataReadFromChildDefaultSize; - dataReadFromChild = (char*)realloc(dataReadFromChild, dataReadFromChildSize); - } - - memcpy(dataReadFromChild + dataReadFromChildUsed, buffer, bytesRead); - dataReadFromChildUsed += bytesRead; - break; - } + int status = 0; + release_assert(waitpid(pid, &status, 0) == pid); + + // done with these now + release_assert(close(parentToChild[WRITE_FD]) == 0); + release_assert(close(childToParent[READ_FD]) == 0); + + char errChar = 0; + ssize_t result = read(errPipe[READ_FD], &errChar, 1); + release_assert(result != -1); + close(errPipe[READ_FD]); + + if (errChar) { + free(dataReadFromChild); + return COMMAND_NOT_FOUND; } + + // free any un-needed memory with realloc + add a null terminator for convenience + dataReadFromChild = + (char*)realloc(dataReadFromChild, dataReadFromChildUsed + 1); + dataReadFromChild[dataReadFromChildUsed] = '\0'; + + if (stdOut != NULL) + *stdOut = dataReadFromChild; + else + free(dataReadFromChild); + + if (stdOutByteCount != NULL) + *stdOutByteCount = dataReadFromChildUsed; + if (returnCode != NULL) + *returnCode = WEXITSTATUS(status); + + return COMMAND_RAN_OK; + } + case -1: { + release_assert(0 && "read() failed"); + break; + } + + default: { + if (dataReadFromChildUsed + bytesRead + 1 >= dataReadFromChildSize) { + dataReadFromChildSize += dataReadFromChildDefaultSize; + dataReadFromChild = + (char*)realloc(dataReadFromChild, dataReadFromChildSize); + } + + memcpy(dataReadFromChild + dataReadFromChildUsed, buffer, bytesRead); + dataReadFromChildUsed += bytesRead; + break; + } } } } + } signal(SIGCHLD, prevHandler); } -int runCommand(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* command, ...) +int +runCommand(char** stdOut, int* stdOutByteCount, int* returnCode, int includeStdErr, char* command, ...) { va_list vl; va_start(vl, command); - + char* currArg = NULL; - - int allArgsInitialSize = 16; - int allArgsSize = allArgsInitialSize; + + int allArgsInitialSize = 16; + int allArgsSize = allArgsInitialSize; char** allArgs = (char**)malloc(sizeof(char*) * allArgsSize); allArgs[0] = command; - + int i = 1; - do - { + do { currArg = va_arg(vl, char*); allArgs[i] = currArg; i++; - if(i >= allArgsSize) - { + if (i >= allArgsSize) { allArgsSize += allArgsInitialSize; allArgs = (char**)realloc(allArgs, sizeof(char*) * allArgsSize); } - } while(currArg != NULL); + } while (currArg != NULL); va_end(vl); - int retval = runCommandArray(stdOut, stdOutByteCount, returnCode, includeStdErr, allArgs); + int retval = + runCommandArray(stdOut, stdOutByteCount, returnCode, includeStdErr, allArgs); free(allArgs); return retval; } -#endif //SIMPLE_EXEC_IMPLEMENTATION +#endif // SIMPLE_EXEC_IMPLEMENTATION From 7605edfe3f2271e58969abe0405ca775140f54d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 14:59:58 -0800 Subject: [PATCH 17/25] support arm64 linux --- README.md | 7 +++++-- build/premake5.lua | 13 ++++++++++++- docs/build.md | 9 +++++++++ src/ftg_core.h | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index afcc33d..672021d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Features: - Simple universal file filter syntax. - Paid support available. - Multiple file selection support. - - 64-bit and 32-bit friendly. + - x64, x86 and arm64 (Linux) support - GCC, Clang, Xcode, Mingw and Visual Studio supported. - No third party dependencies for building or linking. - Support for Vista's modern `IFileDialog` on Windows. @@ -84,6 +84,7 @@ release | what's new | date | Fix vs2019 debug assert | jan 2021 | Fix zenity debug assert | jan 2021 | add clang-format | jan 2021 + | Linux arm64 support | jan 2021 ### Breaking and Notable Changes ### @@ -109,12 +110,14 @@ Previously, NFD used SCons to build. As of 1.1.6, SCons support has been remove ### Makefiles ### -The makefile offers up to four options, with `release_x64` as the default. +The makefile offers up to six options, with `release_x64` as the default. make config=release_x86 make config=release_x64 + make config=release_arm64 make config=debug_x86 make config=debug_x64 + make config=debug_arm64 ### Compiling Your Programs ### diff --git a/build/premake5.lua b/build/premake5.lua index e95e1b3..8f87d2d 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -36,7 +36,7 @@ workspace "NativeFileDialog" filter "system:macosx" platforms {"x64"} filter "system:windows or system:linux" - platforms {"x64", "x86"} + platforms {"x64", "x86", "arm64"} objdir(path.join(build_dir, "obj/")) @@ -48,6 +48,9 @@ workspace "NativeFileDialog" filter "configurations:x64" architecture "x86_64" + filter "configurations:arm64" + architecture "arm64" + -- debug/release filters filter "configurations:Debug" defines {"DEBUG"} @@ -117,6 +120,10 @@ local make_test = function(name) links {"nfd_d"} libdirs {build_dir.."/lib/Debug/x86"} + filter {"configurations:Debug", "architecture:arm64"} + links {"nfd_d"} + libdirs {build_dir.."/lib/Debug/arm64"} + filter {"configurations:Release", "architecture:x86_64"} links {"nfd"} libdirs {build_dir.."/lib/Release/x64"} @@ -125,6 +132,10 @@ local make_test = function(name) links {"nfd"} libdirs {build_dir.."/lib/Release/x86"} + filter {"configurations:Release", "architecture:arm64"} + links {"nfd"} + libdirs {build_dir.."/lib/Release/arm64"} + filter {"configurations:Debug"} targetsuffix "_d" diff --git a/docs/build.md b/docs/build.md index a1f7327..a76965e 100644 --- a/docs/build.md +++ b/docs/build.md @@ -37,3 +37,12 @@ If you report an issue, be sure to run make with `verbose=1` so commands are vis ## Adding NFD source directly to your project ## Lots of developers add NFD source directly to their projects instead of using the included build scripts. As of 1.1.6, this is an acknowledged approach to building. Of course, everyone has a slightly different toolchain with various warnings and linters enabled. If you run a linter or catch a warning, please consider submitting a pull request to help NFD build cleanly for everyone. + +## Building for arm64 Linux ## + +Building for arm64 Linux simply requires a `config=debug_arm64` option is passed in to the Makefile in `gmake_linux`. + +Use `make help` to see all available options. + +32-bit ARM is not currently supported. + diff --git a/src/ftg_core.h b/src/ftg_core.h index 831ed73..dd3190b 100644 --- a/src/ftg_core.h +++ b/src/ftg_core.h @@ -234,6 +234,8 @@ #elif defined(__linux__) #ifdef __arm__ #define FTG_BREAK() __asm__ volatile(".inst 0xde01"); + #elif defined(__aarch64__) + #define FTG_BREAK() __builtin_trap(); #else #define FTG_BREAK() __asm__("int $0x3"); #endif From 4b2d762f83b2d811226a26e67e75807427255e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 15:05:47 -0800 Subject: [PATCH 18/25] fix arm build config leaking to windows --- build/premake5.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build/premake5.lua b/build/premake5.lua index 8f87d2d..2a03b89 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -36,8 +36,9 @@ workspace "NativeFileDialog" filter "system:macosx" platforms {"x64"} filter "system:windows or system:linux" - platforms {"x64", "x86", "arm64"} - + platforms {"x64", "x86"} + filter "system:linux" + platforms {"arm64"} objdir(path.join(build_dir, "obj/")) @@ -120,7 +121,7 @@ local make_test = function(name) links {"nfd_d"} libdirs {build_dir.."/lib/Debug/x86"} - filter {"configurations:Debug", "architecture:arm64"} + filter {"configurations:Debug", "architecture:arm64", "system:linux"} links {"nfd_d"} libdirs {build_dir.."/lib/Debug/arm64"} @@ -132,7 +133,7 @@ local make_test = function(name) links {"nfd"} libdirs {build_dir.."/lib/Release/x86"} - filter {"configurations:Release", "architecture:arm64"} + filter {"configurations:Release", "architecture:arm64", "system:linux"} links {"nfd"} libdirs {build_dir.."/lib/Release/arm64"} From 47c3d7dbdd13ad895add486b8f426e4e091e8d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 8 Jan 2021 15:06:26 -0800 Subject: [PATCH 19/25] premake5 dist run --- build/gmake_linux/Makefile | 16 ++++++ build/gmake_linux/nfd.make | 54 +++++++++++++++++++ build/gmake_linux/test_opendialog.make | 54 +++++++++++++++++++ .../gmake_linux/test_opendialogmultiple.make | 54 +++++++++++++++++++ build/gmake_linux/test_pickfolder.make | 54 +++++++++++++++++++ build/gmake_linux/test_savedialog.make | 54 +++++++++++++++++++ build/gmake_linux_zenity/Makefile | 16 ++++++ build/gmake_linux_zenity/nfd.make | 54 +++++++++++++++++++ build/gmake_linux_zenity/test_opendialog.make | 54 +++++++++++++++++++ .../test_opendialogmultiple.make | 54 +++++++++++++++++++ build/gmake_linux_zenity/test_pickfolder.make | 54 +++++++++++++++++++ build/gmake_linux_zenity/test_savedialog.make | 54 +++++++++++++++++++ build/gmake_windows/nfd.make | 8 +-- build/gmake_windows/test_opendialog.make | 8 +-- .../test_opendialogmultiple.make | 8 +-- build/gmake_windows/test_pickfolder.make | 8 +-- build/gmake_windows/test_savedialog.make | 8 +-- build/vs2010/nfd.vcxproj | 9 ++-- build/vs2010/nfd.vcxproj.filters | 1 + build/vs2010/test_opendialog.vcxproj | 8 +-- build/vs2010/test_opendialogmultiple.vcxproj | 8 +-- build/vs2010/test_pickfolder.vcxproj | 8 +-- build/vs2010/test_savedialog.vcxproj | 8 +-- build/xcode4/nfd.xcodeproj/project.pbxproj | 2 + 24 files changed, 616 insertions(+), 40 deletions(-) diff --git a/build/gmake_linux/Makefile b/build/gmake_linux/Makefile index fb00580..826ad0a 100644 --- a/build/gmake_linux/Makefile +++ b/build/gmake_linux/Makefile @@ -22,6 +22,13 @@ ifeq ($(config),release_x86) test_opendialogmultiple_config = release_x86 test_savedialog_config = release_x86 endif +ifeq ($(config),release_arm64) + nfd_config = release_arm64 + test_pickfolder_config = release_arm64 + test_opendialog_config = release_arm64 + test_opendialogmultiple_config = release_arm64 + test_savedialog_config = release_arm64 +endif ifeq ($(config),debug_x64) nfd_config = debug_x64 test_pickfolder_config = debug_x64 @@ -36,6 +43,13 @@ ifeq ($(config),debug_x86) test_opendialogmultiple_config = debug_x86 test_savedialog_config = debug_x86 endif +ifeq ($(config),debug_arm64) + nfd_config = debug_arm64 + test_pickfolder_config = debug_arm64 + test_opendialog_config = debug_arm64 + test_opendialogmultiple_config = debug_arm64 + test_savedialog_config = debug_arm64 +endif PROJECTS := nfd test_pickfolder test_opendialog test_opendialogmultiple test_savedialog @@ -86,8 +100,10 @@ help: @echo "CONFIGURATIONS:" @echo " release_x64" @echo " release_x86" + @echo " release_arm64" @echo " debug_x64" @echo " debug_x86" + @echo " debug_arm64" @echo "" @echo "TARGETS:" @echo " all (default)" diff --git a/build/gmake_linux/nfd.make b/build/gmake_linux/nfd.make index 379ae12..b572406 100644 --- a/build/gmake_linux/nfd.make +++ b/build/gmake_linux/nfd.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../lib/Release/arm64 + TARGET = $(TARGETDIR)/libnfd.a + OBJDIR = ../obj/arm64/Release/nfd + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -Wall -Wextra -fno-exceptions `pkg-config --cflags gtk+-3.0` + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -Wall -Wextra -fno-exceptions `pkg-config --cflags gtk+-3.0` + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -s + LINKCMD = $(AR) -rcs "$@" $(OBJECTS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../lib/Debug/x64 @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../lib/Debug/arm64 + TARGET = $(TARGETDIR)/libnfd_d.a + OBJDIR = ../obj/arm64/Debug/nfd + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra -fno-exceptions `pkg-config --cflags gtk+-3.0` + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra -fno-exceptions `pkg-config --cflags gtk+-3.0` + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) + LINKCMD = $(AR) -rcs "$@" $(OBJECTS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/nfd_common.o \ $(OBJDIR)/nfd_gtk.o \ diff --git a/build/gmake_linux/test_opendialog.make b/build/gmake_linux/test_opendialog.make index 223b1bb..c77c21b 100644 --- a/build/gmake_linux/test_opendialog.make +++ b/build/gmake_linux/test_opendialog.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialog + OBJDIR = ../obj/arm64/Release/test_opendialog + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialog_d + OBJDIR = ../obj/arm64/Debug/test_opendialog + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_opendialog.o \ diff --git a/build/gmake_linux/test_opendialogmultiple.make b/build/gmake_linux/test_opendialogmultiple.make index 8b0e224..687c28b 100644 --- a/build/gmake_linux/test_opendialogmultiple.make +++ b/build/gmake_linux/test_opendialogmultiple.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialogmultiple + OBJDIR = ../obj/arm64/Release/test_opendialogmultiple + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialogmultiple_d + OBJDIR = ../obj/arm64/Debug/test_opendialogmultiple + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_opendialogmultiple.o \ diff --git a/build/gmake_linux/test_pickfolder.make b/build/gmake_linux/test_pickfolder.make index 28760ef..cd5fd1a 100644 --- a/build/gmake_linux/test_pickfolder.make +++ b/build/gmake_linux/test_pickfolder.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_pickfolder + OBJDIR = ../obj/arm64/Release/test_pickfolder + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_pickfolder_d + OBJDIR = ../obj/arm64/Debug/test_pickfolder + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_pickfolder.o \ diff --git a/build/gmake_linux/test_savedialog.make b/build/gmake_linux/test_savedialog.make index 5cfd1b8..cb594bb 100644 --- a/build/gmake_linux/test_savedialog.make +++ b/build/gmake_linux/test_savedialog.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_savedialog + OBJDIR = ../obj/arm64/Release/test_savedialog + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_savedialog_d + OBJDIR = ../obj/arm64/Debug/test_savedialog + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d `pkg-config --libs gtk+-3.0` + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_savedialog.o \ diff --git a/build/gmake_linux_zenity/Makefile b/build/gmake_linux_zenity/Makefile index fb00580..826ad0a 100644 --- a/build/gmake_linux_zenity/Makefile +++ b/build/gmake_linux_zenity/Makefile @@ -22,6 +22,13 @@ ifeq ($(config),release_x86) test_opendialogmultiple_config = release_x86 test_savedialog_config = release_x86 endif +ifeq ($(config),release_arm64) + nfd_config = release_arm64 + test_pickfolder_config = release_arm64 + test_opendialog_config = release_arm64 + test_opendialogmultiple_config = release_arm64 + test_savedialog_config = release_arm64 +endif ifeq ($(config),debug_x64) nfd_config = debug_x64 test_pickfolder_config = debug_x64 @@ -36,6 +43,13 @@ ifeq ($(config),debug_x86) test_opendialogmultiple_config = debug_x86 test_savedialog_config = debug_x86 endif +ifeq ($(config),debug_arm64) + nfd_config = debug_arm64 + test_pickfolder_config = debug_arm64 + test_opendialog_config = debug_arm64 + test_opendialogmultiple_config = debug_arm64 + test_savedialog_config = debug_arm64 +endif PROJECTS := nfd test_pickfolder test_opendialog test_opendialogmultiple test_savedialog @@ -86,8 +100,10 @@ help: @echo "CONFIGURATIONS:" @echo " release_x64" @echo " release_x86" + @echo " release_arm64" @echo " debug_x64" @echo " debug_x86" + @echo " debug_arm64" @echo "" @echo "TARGETS:" @echo " all (default)" diff --git a/build/gmake_linux_zenity/nfd.make b/build/gmake_linux_zenity/nfd.make index 21870bd..d689dad 100644 --- a/build/gmake_linux_zenity/nfd.make +++ b/build/gmake_linux_zenity/nfd.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../lib/Release/arm64 + TARGET = $(TARGETDIR)/libnfd.a + OBJDIR = ../obj/arm64/Release/nfd + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -Wall -Wextra -fno-exceptions + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -Wall -Wextra -fno-exceptions + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -s + LINKCMD = $(AR) -rcs "$@" $(OBJECTS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../lib/Debug/x64 @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../lib/Debug/arm64 + TARGET = $(TARGETDIR)/libnfd_d.a + OBJDIR = ../obj/arm64/Debug/nfd + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra -fno-exceptions + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra -fno-exceptions + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) + LINKCMD = $(AR) -rcs "$@" $(OBJECTS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/nfd_common.o \ $(OBJDIR)/nfd_zenity.o \ diff --git a/build/gmake_linux_zenity/test_opendialog.make b/build/gmake_linux_zenity/test_opendialog.make index 7f1a1cb..084cdbe 100644 --- a/build/gmake_linux_zenity/test_opendialog.make +++ b/build/gmake_linux_zenity/test_opendialog.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialog + OBJDIR = ../obj/arm64/Release/test_opendialog + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialog_d + OBJDIR = ../obj/arm64/Debug/test_opendialog + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_opendialog.o \ diff --git a/build/gmake_linux_zenity/test_opendialogmultiple.make b/build/gmake_linux_zenity/test_opendialogmultiple.make index dd2dab1..f241c4d 100644 --- a/build/gmake_linux_zenity/test_opendialogmultiple.make +++ b/build/gmake_linux_zenity/test_opendialogmultiple.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialogmultiple + OBJDIR = ../obj/arm64/Release/test_opendialogmultiple + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialogmultiple_d + OBJDIR = ../obj/arm64/Debug/test_opendialogmultiple + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_opendialogmultiple.o \ diff --git a/build/gmake_linux_zenity/test_pickfolder.make b/build/gmake_linux_zenity/test_pickfolder.make index 61c103b..484c6d8 100644 --- a/build/gmake_linux_zenity/test_pickfolder.make +++ b/build/gmake_linux_zenity/test_pickfolder.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_pickfolder + OBJDIR = ../obj/arm64/Release/test_pickfolder + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_pickfolder_d + OBJDIR = ../obj/arm64/Debug/test_pickfolder + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_pickfolder.o \ diff --git a/build/gmake_linux_zenity/test_savedialog.make b/build/gmake_linux_zenity/test_savedialog.make index 505ed88..64a5f22 100644 --- a/build/gmake_linux_zenity/test_savedialog.make +++ b/build/gmake_linux_zenity/test_savedialog.make @@ -64,6 +64,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),release_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_savedialog + OBJDIR = ../obj/arm64/Release/test_savedialog + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -s -lnfd + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin @@ -118,6 +145,33 @@ all: prebuild prelink $(TARGET) endif +ifeq ($(config),debug_arm64) + RESCOMP = windres + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_savedialog_d + OBJDIR = ../obj/arm64/Debug/test_savedialog + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -lnfd_d + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + OBJECTS := \ $(OBJDIR)/test_savedialog.o \ diff --git a/build/gmake_windows/nfd.make b/build/gmake_windows/nfd.make index ebcb5e9..fc12db2 100644 --- a/build/gmake_windows/nfd.make +++ b/build/gmake_windows/nfd.make @@ -14,7 +14,7 @@ ifeq ($(config),release_x64) RESCOMP = windres TARGETDIR = ../lib/Release/x64 TARGET = $(TARGETDIR)/nfd.lib - OBJDIR = ../obj/x64/Release/nfd + OBJDIR = obj/x64/Release/nfd DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -41,7 +41,7 @@ ifeq ($(config),release_x86) RESCOMP = windres TARGETDIR = ../lib/Release/x86 TARGET = $(TARGETDIR)/nfd.lib - OBJDIR = ../obj/x86/Release/nfd + OBJDIR = obj/x86/Release/nfd DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -68,7 +68,7 @@ ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../lib/Debug/x64 TARGET = $(TARGETDIR)/nfd_d.lib - OBJDIR = ../obj/x64/Debug/nfd + OBJDIR = obj/x64/Debug/nfd DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -95,7 +95,7 @@ ifeq ($(config),debug_x86) RESCOMP = windres TARGETDIR = ../lib/Debug/x86 TARGET = $(TARGETDIR)/nfd_d.lib - OBJDIR = ../obj/x86/Debug/nfd + OBJDIR = obj/x86/Debug/nfd DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += diff --git a/build/gmake_windows/test_opendialog.make b/build/gmake_windows/test_opendialog.make index ad77941..a10a3f3 100644 --- a/build/gmake_windows/test_opendialog.make +++ b/build/gmake_windows/test_opendialog.make @@ -14,7 +14,7 @@ ifeq ($(config),release_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialog.exe - OBJDIR = ../obj/x64/Release/test_opendialog + OBJDIR = obj/x64/Release/test_opendialog DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -41,7 +41,7 @@ ifeq ($(config),release_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialog.exe - OBJDIR = ../obj/x86/Release/test_opendialog + OBJDIR = obj/x86/Release/test_opendialog DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -68,7 +68,7 @@ ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialog_d.exe - OBJDIR = ../obj/x64/Debug/test_opendialog + OBJDIR = obj/x64/Debug/test_opendialog DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -95,7 +95,7 @@ ifeq ($(config),debug_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialog_d.exe - OBJDIR = ../obj/x86/Debug/test_opendialog + OBJDIR = obj/x86/Debug/test_opendialog DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += diff --git a/build/gmake_windows/test_opendialogmultiple.make b/build/gmake_windows/test_opendialogmultiple.make index d09cb6d..ca886e8 100644 --- a/build/gmake_windows/test_opendialogmultiple.make +++ b/build/gmake_windows/test_opendialogmultiple.make @@ -14,7 +14,7 @@ ifeq ($(config),release_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialogmultiple.exe - OBJDIR = ../obj/x64/Release/test_opendialogmultiple + OBJDIR = obj/x64/Release/test_opendialogmultiple DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -41,7 +41,7 @@ ifeq ($(config),release_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialogmultiple.exe - OBJDIR = ../obj/x86/Release/test_opendialogmultiple + OBJDIR = obj/x86/Release/test_opendialogmultiple DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -68,7 +68,7 @@ ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialogmultiple_d.exe - OBJDIR = ../obj/x64/Debug/test_opendialogmultiple + OBJDIR = obj/x64/Debug/test_opendialogmultiple DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -95,7 +95,7 @@ ifeq ($(config),debug_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialogmultiple_d.exe - OBJDIR = ../obj/x86/Debug/test_opendialogmultiple + OBJDIR = obj/x86/Debug/test_opendialogmultiple DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += diff --git a/build/gmake_windows/test_pickfolder.make b/build/gmake_windows/test_pickfolder.make index f440fa2..f31fff6 100644 --- a/build/gmake_windows/test_pickfolder.make +++ b/build/gmake_windows/test_pickfolder.make @@ -14,7 +14,7 @@ ifeq ($(config),release_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_pickfolder.exe - OBJDIR = ../obj/x64/Release/test_pickfolder + OBJDIR = obj/x64/Release/test_pickfolder DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -41,7 +41,7 @@ ifeq ($(config),release_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_pickfolder.exe - OBJDIR = ../obj/x86/Release/test_pickfolder + OBJDIR = obj/x86/Release/test_pickfolder DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -68,7 +68,7 @@ ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_pickfolder_d.exe - OBJDIR = ../obj/x64/Debug/test_pickfolder + OBJDIR = obj/x64/Debug/test_pickfolder DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -95,7 +95,7 @@ ifeq ($(config),debug_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_pickfolder_d.exe - OBJDIR = ../obj/x86/Debug/test_pickfolder + OBJDIR = obj/x86/Debug/test_pickfolder DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += diff --git a/build/gmake_windows/test_savedialog.make b/build/gmake_windows/test_savedialog.make index 1325a5a..f86e851 100644 --- a/build/gmake_windows/test_savedialog.make +++ b/build/gmake_windows/test_savedialog.make @@ -14,7 +14,7 @@ ifeq ($(config),release_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_savedialog.exe - OBJDIR = ../obj/x64/Release/test_savedialog + OBJDIR = obj/x64/Release/test_savedialog DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -41,7 +41,7 @@ ifeq ($(config),release_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_savedialog.exe - OBJDIR = ../obj/x86/Release/test_savedialog + OBJDIR = obj/x86/Release/test_savedialog DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -68,7 +68,7 @@ ifeq ($(config),debug_x64) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_savedialog_d.exe - OBJDIR = ../obj/x64/Debug/test_savedialog + OBJDIR = obj/x64/Debug/test_savedialog DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += @@ -95,7 +95,7 @@ ifeq ($(config),debug_x86) RESCOMP = windres TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_savedialog_d.exe - OBJDIR = ../obj/x86/Debug/test_savedialog + OBJDIR = obj/x86/Debug/test_savedialog DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += diff --git a/build/vs2010/nfd.vcxproj b/build/vs2010/nfd.vcxproj index 52e1248..93386e0 100644 --- a/build/vs2010/nfd.vcxproj +++ b/build/vs2010/nfd.vcxproj @@ -66,25 +66,25 @@ ..\lib\Release\x64\ - ..\obj\x64\Release\nfd\ + obj\x64\Release\nfd\ nfd .lib ..\lib\Release\x86\ - ..\obj\x86\Release\nfd\ + obj\x86\Release\nfd\ nfd .lib ..\lib\Debug\x64\ - ..\obj\x64\Debug\nfd\ + obj\x64\Debug\nfd\ nfd_d .lib ..\lib\Debug\x86\ - ..\obj\x86\Debug\nfd\ + obj\x86\Debug\nfd\ nfd_d .lib @@ -154,6 +154,7 @@ + diff --git a/build/vs2010/nfd.vcxproj.filters b/build/vs2010/nfd.vcxproj.filters index df4729b..94c8d29 100644 --- a/build/vs2010/nfd.vcxproj.filters +++ b/build/vs2010/nfd.vcxproj.filters @@ -7,6 +7,7 @@ + include diff --git a/build/vs2010/test_opendialog.vcxproj b/build/vs2010/test_opendialog.vcxproj index 8cd19f5..61fb080 100644 --- a/build/vs2010/test_opendialog.vcxproj +++ b/build/vs2010/test_opendialog.vcxproj @@ -67,28 +67,28 @@ false ..\bin\ - ..\obj\x64\Release\test_opendialog\ + obj\x64\Release\test_opendialog\ test_opendialog .exe false ..\bin\ - ..\obj\x86\Release\test_opendialog\ + obj\x86\Release\test_opendialog\ test_opendialog .exe true ..\bin\ - ..\obj\x64\Debug\test_opendialog\ + obj\x64\Debug\test_opendialog\ test_opendialog_d .exe true ..\bin\ - ..\obj\x86\Debug\test_opendialog\ + obj\x86\Debug\test_opendialog\ test_opendialog_d .exe diff --git a/build/vs2010/test_opendialogmultiple.vcxproj b/build/vs2010/test_opendialogmultiple.vcxproj index b5a8cfd..1a1f671 100644 --- a/build/vs2010/test_opendialogmultiple.vcxproj +++ b/build/vs2010/test_opendialogmultiple.vcxproj @@ -67,28 +67,28 @@ false ..\bin\ - ..\obj\x64\Release\test_opendialogmultiple\ + obj\x64\Release\test_opendialogmultiple\ test_opendialogmultiple .exe false ..\bin\ - ..\obj\x86\Release\test_opendialogmultiple\ + obj\x86\Release\test_opendialogmultiple\ test_opendialogmultiple .exe true ..\bin\ - ..\obj\x64\Debug\test_opendialogmultiple\ + obj\x64\Debug\test_opendialogmultiple\ test_opendialogmultiple_d .exe true ..\bin\ - ..\obj\x86\Debug\test_opendialogmultiple\ + obj\x86\Debug\test_opendialogmultiple\ test_opendialogmultiple_d .exe diff --git a/build/vs2010/test_pickfolder.vcxproj b/build/vs2010/test_pickfolder.vcxproj index 856365e..e598172 100644 --- a/build/vs2010/test_pickfolder.vcxproj +++ b/build/vs2010/test_pickfolder.vcxproj @@ -67,28 +67,28 @@ false ..\bin\ - ..\obj\x64\Release\test_pickfolder\ + obj\x64\Release\test_pickfolder\ test_pickfolder .exe false ..\bin\ - ..\obj\x86\Release\test_pickfolder\ + obj\x86\Release\test_pickfolder\ test_pickfolder .exe true ..\bin\ - ..\obj\x64\Debug\test_pickfolder\ + obj\x64\Debug\test_pickfolder\ test_pickfolder_d .exe true ..\bin\ - ..\obj\x86\Debug\test_pickfolder\ + obj\x86\Debug\test_pickfolder\ test_pickfolder_d .exe diff --git a/build/vs2010/test_savedialog.vcxproj b/build/vs2010/test_savedialog.vcxproj index c0df626..1a7ef98 100644 --- a/build/vs2010/test_savedialog.vcxproj +++ b/build/vs2010/test_savedialog.vcxproj @@ -67,28 +67,28 @@ false ..\bin\ - ..\obj\x64\Release\test_savedialog\ + obj\x64\Release\test_savedialog\ test_savedialog .exe false ..\bin\ - ..\obj\x86\Release\test_savedialog\ + obj\x86\Release\test_savedialog\ test_savedialog .exe true ..\bin\ - ..\obj\x64\Debug\test_savedialog\ + obj\x64\Debug\test_savedialog\ test_savedialog_d .exe true ..\bin\ - ..\obj\x86\Debug\test_savedialog\ + obj\x86\Debug\test_savedialog\ test_savedialog_d .exe diff --git a/build/xcode4/nfd.xcodeproj/project.pbxproj b/build/xcode4/nfd.xcodeproj/project.pbxproj index 0b3f6a8..81f6d11 100644 --- a/build/xcode4/nfd.xcodeproj/project.pbxproj +++ b/build/xcode4/nfd.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 073D89061E5024380E6C1F46 /* ftg_core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ftg_core.h; path = ../../src/ftg_core.h; sourceTree = ""; }; 42F539D06B2FF28252CB8010 /* simple_exec.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = simple_exec.h; path = ../../src/simple_exec.h; sourceTree = ""; }; 4E280AA77CCE5E99D60FB8E7 /* libnfd.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libnfd.a; path = libnfd.a; sourceTree = BUILT_PRODUCTS_DIR; }; 5A7B972AA2EC7B5CE78B4D6A /* nfd_common.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = nfd_common.c; path = ../../src/nfd_common.c; sourceTree = ""; }; @@ -36,6 +37,7 @@ isa = PBXGroup; children = ( 5E955E0662063038E372D446 /* common.h */, + 073D89061E5024380E6C1F46 /* ftg_core.h */, 5E8C725002DF100215175890 /* include */, 906CCB56B692FB081D99F196 /* nfd_cocoa.m */, 5A7B972AA2EC7B5CE78B4D6A /* nfd_common.c */, From 01de5ac3cc9e449e011daacb0994eecfd4761f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Sat, 9 Jan 2021 10:37:44 -0800 Subject: [PATCH 20/25] known issues readme update --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 672021d..2a750cd 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ On Linux, you have the option of compiling and linking against GTK. If you use #### Linux Zenity #### -Alternatively, you can use the Zenity backend by running the Makefile in `build/gmake_linux_zenity`. Zenity runs the dialog in its own address space, but requires the user to have Zenity correctly installed and configured on their system. +Alternatively, you can use the Zenity backend by running the Makefile in `build/gmake_linux_zenity`. Zenity runs the dialog in its own address space, but requires the user to have Zenity correctly installed and configured on their system. For a full list of Zenity limitations, see "Known Limitations" below. #### MacOS #### @@ -178,8 +178,11 @@ I accept quality code patches, or will resolve these and other matters through s - No support for Windows XP's legacy dialogs such as `GetOpenFileName`. - No support for file filter names -- ex: "Image Files" (*.png, *.jpg). Nameless filters are supported, however. - - GTK Zenity implementation's process exec error handling does not gracefully handle numerous error cases, choosing to abort rather than cleanup and return. - - GTK 3 spams one warning per dialog created. + - GTK 3 sometimes spams one warning per dialog created, depending on how GTK3 was built. + - The GTK Zenity backend (non-default) is a lightweight alternative intended only for small programs: + - It errors out if Zenity is not installed on the user's system + - This backend's process exec error handling does not gracefully handle numerous error cases, choosing to abort rather than cleanup and return. + - Unlike the other backends, the Zenity backend does not return implied extensions from filterlists. [#95](https://github.com/mlabbe/nativefiledialog/issues/95 "Issue 95") # Copyright and Credit # From eb29acc563cbb26390653bf3dc57a08d8f09074d Mon Sep 17 00:00:00 2001 From: Michael Labbe Date: Sat, 9 Jan 2021 11:10:35 -0800 Subject: [PATCH 21/25] macos focus bugfix --- README.md | 2 ++ src/nfd_cocoa.m | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 2a750cd..1a844b2 100644 --- a/README.md +++ b/README.md @@ -80,12 +80,14 @@ release | what's new | date 1.2.0 | defaultPath can specify files now | jan 2021 | extension automatically added when saving | jan 2021 | GTK dialog focus bugfix | jan 2021 + | Macos dialog focus bugfix | jan 2021 | Added NFD_Free() | jan 2021 | Fix vs2019 debug assert | jan 2021 | Fix zenity debug assert | jan 2021 | add clang-format | jan 2021 | Linux arm64 support | jan 2021 + ### Breaking and Notable Changes ### There are no ABI breaking changes in NFD's history. diff --git a/src/nfd_cocoa.m b/src/nfd_cocoa.m index 27c37a7..a0c44ec 100644 --- a/src/nfd_cocoa.m +++ b/src/nfd_cocoa.m @@ -137,6 +137,17 @@ return NFD_OKAY; } +void +SetAppPolicy(void) +{ + NSApplication* app = [NSApplication sharedApplication]; + + NSApplicationActivationPolicy initial_policy = [app activationPolicy]; + if (initial_policy == NSApplicationActivationPolicyProhibited) { + [app setActivationPolicy:NSApplicationActivationPolicyAccessory]; + } +} + /* public */ @@ -145,6 +156,8 @@ { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + SetAppPolicy(); + NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; NSOpenPanel* dialog = [NSOpenPanel openPanel]; [dialog setAllowsMultipleSelection:NO]; @@ -187,6 +200,8 @@ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; + SetAppPolicy(); + NSOpenPanel* dialog = [NSOpenPanel openPanel]; [dialog setAllowsMultipleSelection:YES]; @@ -227,6 +242,8 @@ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; + SetAppPolicy(); + NSSavePanel* dialog = [NSSavePanel savePanel]; [dialog setExtensionHidden:NO]; @@ -264,6 +281,8 @@ { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + SetAppPolicy(); + NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow]; NSOpenPanel* dialog = [NSOpenPanel openPanel]; [dialog setAllowsMultipleSelection:NO]; From 0647a4ebbf7ccb16a896726c181bade9fcd7be61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 15 Jan 2021 11:40:49 -0800 Subject: [PATCH 22/25] macos arm64 and fat binary support --- README.md | 2 + build/gmake_macosx/Makefile | 16 ++++ build/gmake_macosx/fat_bin.pl | 49 +++++++++++ build/gmake_macosx/nfd.make | 86 +++++++++++++++++-- build/gmake_macosx/test_opendialog.make | 86 +++++++++++++++++-- .../gmake_macosx/test_opendialogmultiple.make | 86 +++++++++++++++++-- build/gmake_macosx/test_pickfolder.make | 86 +++++++++++++++++-- build/gmake_macosx/test_savedialog.make | 86 +++++++++++++++++-- build/premake5.lua | 28 ++++-- build/xcode4/nfd.xcodeproj/project.pbxproj | 24 ++++-- .../test_opendialog.xcodeproj/project.pbxproj | 22 ++++- .../project.pbxproj | 22 ++++- .../test_pickfolder.xcodeproj/project.pbxproj | 22 ++++- .../test_savedialog.xcodeproj/project.pbxproj | 22 ++++- docs/build.md | 15 ++++ 15 files changed, 584 insertions(+), 68 deletions(-) create mode 100755 build/gmake_macosx/fat_bin.pl diff --git a/README.md b/README.md index 1a844b2..a8d32eb 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ release | what's new | date | Fix zenity debug assert | jan 2021 | add clang-format | jan 2021 | Linux arm64 support | jan 2021 + | Apple Silicon support | jan 2021 + | Macos fat binary builds | jan 2021 ### Breaking and Notable Changes ### diff --git a/build/gmake_macosx/Makefile b/build/gmake_macosx/Makefile index f431868..f1b2e7c 100644 --- a/build/gmake_macosx/Makefile +++ b/build/gmake_macosx/Makefile @@ -15,6 +15,13 @@ ifeq ($(config),release_x64) test_opendialogmultiple_config = release_x64 test_savedialog_config = release_x64 endif +ifeq ($(config),release_arm64) + nfd_config = release_arm64 + test_pickfolder_config = release_arm64 + test_opendialog_config = release_arm64 + test_opendialogmultiple_config = release_arm64 + test_savedialog_config = release_arm64 +endif ifeq ($(config),debug_x64) nfd_config = debug_x64 test_pickfolder_config = debug_x64 @@ -22,6 +29,13 @@ ifeq ($(config),debug_x64) test_opendialogmultiple_config = debug_x64 test_savedialog_config = debug_x64 endif +ifeq ($(config),debug_arm64) + nfd_config = debug_arm64 + test_pickfolder_config = debug_arm64 + test_opendialog_config = debug_arm64 + test_opendialogmultiple_config = debug_arm64 + test_savedialog_config = debug_arm64 +endif PROJECTS := nfd test_pickfolder test_opendialog test_opendialogmultiple test_savedialog @@ -71,7 +85,9 @@ help: @echo "" @echo "CONFIGURATIONS:" @echo " release_x64" + @echo " release_arm64" @echo " debug_x64" + @echo " debug_arm64" @echo "" @echo "TARGETS:" @echo " all (default)" diff --git a/build/gmake_macosx/fat_bin.pl b/build/gmake_macosx/fat_bin.pl new file mode 100755 index 0000000..5c78fe7 --- /dev/null +++ b/build/gmake_macosx/fat_bin.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w + +use strict; +use Cwd; + +# run this script to compile native file dialog for both arm64 and +# x64 architectures, and to combine them into one static, fat +# binary. + +sub run { + my $cmd = shift; + + print("> $cmd\n"); + system($cmd); + + if ($? == -1) { + die "Shell command failed"; + } +} + + +if ($#ARGV == -1) { + print "Usage: $0 \n"; + exit 1; +} + +my $cfg = $ARGV[0]; +my $ext = ''; +if ($cfg eq 'debug') { + $ext = '_d'; +} + + +run("make config=${cfg}_x64 nfd clean"); +run("make config=${cfg}_arm64 nfd clean"); + +run("make config=${cfg}_x64 target=all verbose=1 nfd"); +run("make config=${cfg}_arm64 target=all verbose=1 nfd"); + +my $outfile = "../lib/$cfg/libnfd$ext.a"; +run("lipo " . + "../lib/$cfg/arm64/libnfd$ext.a " . + "../lib/$cfg/x64/libnfd$ext.a " . + "-create " . + "-output $outfile"); + +my $abs_outfile = Cwd::abs_path($outfile); +print("multi-arch binary $abs_outfile successfully created.\n"); + diff --git a/build/gmake_macosx/nfd.make b/build/gmake_macosx/nfd.make index 390dcee..98e711b 100644 --- a/build/gmake_macosx/nfd.make +++ b/build/gmake_macosx/nfd.make @@ -22,17 +22,52 @@ ifeq ($(config),release_x64) endif TARGETDIR = ../lib/Release/x64 TARGET = $(TARGETDIR)/libnfd.a - OBJDIR = obj/x64/Release/nfd + OBJDIR = ../obj/x64/Release/nfd DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -Wall -Wextra -fno-exceptions - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -Wall -Wextra -fno-exceptions + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -Wall -Wextra -target x86_64-apple-macos10.12 -fno-exceptions + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -Wall -Wextra -target x86_64-apple-macos10.12 -fno-exceptions ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += LDDEPS += - ALL_LDFLAGS += $(LDFLAGS) -m64 + ALL_LDFLAGS += $(LDFLAGS) -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(AR) -rcs "$@" $(OBJECTS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),release_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../lib/Release/arm64 + TARGET = $(TARGETDIR)/libnfd.a + OBJDIR = ../obj/arm64/Release/nfd + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -Wall -Wextra -target arm64-apple-macos11 -fno-exceptions + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -Wall -Wextra -target arm64-apple-macos11 -fno-exceptions + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -target arm64-apple-macos11 LINKCMD = $(AR) -rcs "$@" $(OBJECTS) define PREBUILDCMDS endef @@ -57,17 +92,52 @@ ifeq ($(config),debug_x64) endif TARGETDIR = ../lib/Debug/x64 TARGET = $(TARGETDIR)/libnfd_d.a - OBJDIR = obj/x64/Debug/nfd + OBJDIR = ../obj/x64/Debug/nfd + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wall -Wextra -target x86_64-apple-macos10.12 -fno-exceptions + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wall -Wextra -target x86_64-apple-macos10.12 -fno-exceptions + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(AR) -rcs "$@" $(OBJECTS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),debug_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../lib/Debug/arm64 + TARGET = $(TARGETDIR)/libnfd_d.a + OBJDIR = ../obj/arm64/Debug/nfd DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wall -Wextra -fno-exceptions - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wall -Wextra -fno-exceptions + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra -target arm64-apple-macos11 -fno-exceptions + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra -target arm64-apple-macos11 -fno-exceptions ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += LDDEPS += - ALL_LDFLAGS += $(LDFLAGS) -m64 + ALL_LDFLAGS += $(LDFLAGS) -target arm64-apple-macos11 LINKCMD = $(AR) -rcs "$@" $(OBJECTS) define PREBUILDCMDS endef diff --git a/build/gmake_macosx/test_opendialog.make b/build/gmake_macosx/test_opendialog.make index d4c861c..5375c35 100644 --- a/build/gmake_macosx/test_opendialog.make +++ b/build/gmake_macosx/test_opendialog.make @@ -22,17 +22,52 @@ ifeq ($(config),release_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialog - OBJDIR = obj/x64/Release/test_opendialog + OBJDIR = ../obj/x64/Release/test_opendialog DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += ../lib/Release/x64/libnfd.a -framework Foundation -framework AppKit LDDEPS += ../lib/Release/x64/libnfd.a - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),release_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialog + OBJDIR = ../obj/arm64/Release/test_opendialog + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a -framework Foundation -framework AppKit + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef @@ -57,17 +92,52 @@ ifeq ($(config),debug_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialog_d - OBJDIR = obj/x64/Debug/test_opendialog + OBJDIR = ../obj/x64/Debug/test_opendialog + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -framework Foundation -framework AppKit -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),debug_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialog_d + OBJDIR = ../obj/arm64/Debug/test_opendialog DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += -framework Foundation -framework AppKit -lnfd_d LDDEPS += - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef diff --git a/build/gmake_macosx/test_opendialogmultiple.make b/build/gmake_macosx/test_opendialogmultiple.make index ef6c746..2e64d44 100644 --- a/build/gmake_macosx/test_opendialogmultiple.make +++ b/build/gmake_macosx/test_opendialogmultiple.make @@ -22,17 +22,52 @@ ifeq ($(config),release_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialogmultiple - OBJDIR = obj/x64/Release/test_opendialogmultiple + OBJDIR = ../obj/x64/Release/test_opendialogmultiple DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += ../lib/Release/x64/libnfd.a -framework Foundation -framework AppKit LDDEPS += ../lib/Release/x64/libnfd.a - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),release_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialogmultiple + OBJDIR = ../obj/arm64/Release/test_opendialogmultiple + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a -framework Foundation -framework AppKit + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef @@ -57,17 +92,52 @@ ifeq ($(config),debug_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_opendialogmultiple_d - OBJDIR = obj/x64/Debug/test_opendialogmultiple + OBJDIR = ../obj/x64/Debug/test_opendialogmultiple + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -framework Foundation -framework AppKit -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),debug_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_opendialogmultiple_d + OBJDIR = ../obj/arm64/Debug/test_opendialogmultiple DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += -framework Foundation -framework AppKit -lnfd_d LDDEPS += - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef diff --git a/build/gmake_macosx/test_pickfolder.make b/build/gmake_macosx/test_pickfolder.make index 85469da..e3fe7b9 100644 --- a/build/gmake_macosx/test_pickfolder.make +++ b/build/gmake_macosx/test_pickfolder.make @@ -22,17 +22,52 @@ ifeq ($(config),release_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_pickfolder - OBJDIR = obj/x64/Release/test_pickfolder + OBJDIR = ../obj/x64/Release/test_pickfolder DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += ../lib/Release/x64/libnfd.a -framework Foundation -framework AppKit LDDEPS += ../lib/Release/x64/libnfd.a - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),release_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_pickfolder + OBJDIR = ../obj/arm64/Release/test_pickfolder + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a -framework Foundation -framework AppKit + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef @@ -57,17 +92,52 @@ ifeq ($(config),debug_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_pickfolder_d - OBJDIR = obj/x64/Debug/test_pickfolder + OBJDIR = ../obj/x64/Debug/test_pickfolder + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -framework Foundation -framework AppKit -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),debug_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_pickfolder_d + OBJDIR = ../obj/arm64/Debug/test_pickfolder DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += -framework Foundation -framework AppKit -lnfd_d LDDEPS += - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef diff --git a/build/gmake_macosx/test_savedialog.make b/build/gmake_macosx/test_savedialog.make index 401e992..9ec6def 100644 --- a/build/gmake_macosx/test_savedialog.make +++ b/build/gmake_macosx/test_savedialog.make @@ -22,17 +22,52 @@ ifeq ($(config),release_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_savedialog - OBJDIR = obj/x64/Release/test_savedialog + OBJDIR = ../obj/x64/Release/test_savedialog DEFINES += -DNDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -target x86_64-apple-macos10.12 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += ../lib/Release/x64/libnfd.a -framework Foundation -framework AppKit LDDEPS += ../lib/Release/x64/libnfd.a - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),release_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_savedialog + OBJDIR = ../obj/arm64/Release/test_savedialog + DEFINES += -DNDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -target arm64-apple-macos11 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += ../lib/Release/arm64/libnfd.a -framework Foundation -framework AppKit + LDDEPS += ../lib/Release/arm64/libnfd.a + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Release/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef @@ -57,17 +92,52 @@ ifeq ($(config),debug_x64) endif TARGETDIR = ../bin TARGET = $(TARGETDIR)/test_savedialog_d - OBJDIR = obj/x64/Debug/test_savedialog + OBJDIR = ../obj/x64/Debug/test_savedialog + DEFINES += -DDEBUG + INCLUDES += -I../../src/include + FORCE_INCLUDE += + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -target x86_64-apple-macos10.12 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + LIBS += -framework Foundation -framework AppKit -lnfd_d + LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 -target x86_64-apple-macos10.12 + LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +all: prebuild prelink $(TARGET) + @: + +endif + +ifeq ($(config),debug_arm64) + ifeq ($(origin CC), default) + CC = clang + endif + ifeq ($(origin CXX), default) + CXX = clang++ + endif + ifeq ($(origin AR), default) + AR = ar + endif + TARGETDIR = ../bin + TARGET = $(TARGETDIR)/test_savedialog_d + OBJDIR = ../obj/arm64/Debug/test_savedialog DEFINES += -DDEBUG INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) - ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g - ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 + ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -target arm64-apple-macos11 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) LIBS += -framework Foundation -framework AppKit -lnfd_d LDDEPS += - ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/x64 -m64 + ALL_LDFLAGS += $(LDFLAGS) -L../lib/Debug/arm64 -target arm64-apple-macos11 LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) define PREBUILDCMDS endef diff --git a/build/premake5.lua b/build/premake5.lua index 2a03b89..f7cdca7 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -4,8 +4,22 @@ -- by package maintainers. -- -- IMPORTANT NOTE: premake5 alpha 9 does not handle this script --- properly. Build premake5 from Github master, or, presumably, --- use alpha 10 in the future. +-- properly. Use a later premake5 alpha. Do not use premake4. + +function add_macos_arm_target_flags() + arm_triple = 'arm64-apple-macos11' + x64_triple = 'x86_64-apple-macos10.12' + + filter {"system:macosx", "architecture:arm64"} + buildoptions {"-target " .. arm_triple} + linkoptions {"-target " .. arm_triple} + + filter {"system:macosx", "architecture:x86_64"} + buildoptions {"-target " .. x64_triple} + linkoptions {"-target " .. x64_triple} + + filter{} +end newoption { @@ -37,7 +51,7 @@ workspace "NativeFileDialog" platforms {"x64"} filter "system:windows or system:linux" platforms {"x64", "x86"} - filter "system:linux" + filter "system:linux or system:macosx" platforms {"arm64"} objdir(path.join(build_dir, "obj/")) @@ -62,6 +76,8 @@ workspace "NativeFileDialog" defines {"NDEBUG"} optimize "On" + add_macos_arm_target_flags() + project "nfd" kind "StaticLib" @@ -121,7 +137,7 @@ local make_test = function(name) links {"nfd_d"} libdirs {build_dir.."/lib/Debug/x86"} - filter {"configurations:Debug", "architecture:arm64", "system:linux"} + filter {"configurations:Debug", "architecture:arm64"} links {"nfd_d"} libdirs {build_dir.."/lib/Debug/arm64"} @@ -133,7 +149,7 @@ local make_test = function(name) links {"nfd"} libdirs {build_dir.."/lib/Release/x86"} - filter {"configurations:Release", "architecture:arm64", "system:linux"} + filter {"configurations:Release", "architecture:arm64"} links {"nfd"} libdirs {build_dir.."/lib/Release/arm64"} @@ -153,7 +169,7 @@ local make_test = function(name) filter {"configurations:Debug", "system:linux", "options:linux_backend=zenity"} linkoptions {"-lnfd_d"} - + add_macos_arm_target_flags() filter {"action:gmake", "system:windows"} links {"ole32", "uuid"} diff --git a/build/xcode4/nfd.xcodeproj/project.pbxproj b/build/xcode4/nfd.xcodeproj/project.pbxproj index 81f6d11..1828b22 100644 --- a/build/xcode4/nfd.xcodeproj/project.pbxproj +++ b/build/xcode4/nfd.xcodeproj/project.pbxproj @@ -141,12 +141,16 @@ GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = obj/x64/Debug/nfd; + OBJROOT = ../obj/arm64/Debug/nfd; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = ( + "-target arm64-apple-macos11", "-fno-exceptions", ); - SYMROOT = ../lib/Debug/x64; + OTHER_LDFLAGS = ( + "-target arm64-apple-macos11", + ); + SYMROOT = ../lib/Debug/arm64; USER_HEADER_SEARCH_PATHS = ( ../../src/include, ); @@ -158,7 +162,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CONFIGURATION_BUILD_DIR = ../lib/Release/x64; + CONFIGURATION_BUILD_DIR = ../lib/Release/arm64; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_DYNAMIC_NO_PIC = NO; INSTALL_PATH = /usr/local/lib; @@ -178,12 +182,16 @@ GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = obj/x64/Release/nfd; + OBJROOT = ../obj/arm64/Release/nfd; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( + "-target arm64-apple-macos11", "-fno-exceptions", ); - SYMROOT = ../lib/Release/x64; + OTHER_LDFLAGS = ( + "-target arm64-apple-macos11", + ); + SYMROOT = ../lib/Release/arm64; USER_HEADER_SEARCH_PATHS = ( ../../src/include, ); @@ -195,7 +203,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CONFIGURATION_BUILD_DIR = ../lib/Debug/x64; + CONFIGURATION_BUILD_DIR = ../lib/Debug/arm64; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_DYNAMIC_NO_PIC = NO; INSTALL_PATH = /usr/local/lib; @@ -209,8 +217,10 @@ 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "nfd" */ = { isa = XCConfigurationList; buildConfigurations = ( + E9E0596139F3EE13BC721FA1 /* Release */, E9E0596139F3EE13BC721FA1 /* Release */, 6730896713934999D21BBFA7 /* Debug */, + 6730896713934999D21BBFA7 /* Debug */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; @@ -219,6 +229,8 @@ isa = XCConfigurationList; buildConfigurations = ( 8FABFCB6E6396728BEB27AF6 /* Release */, + 8FABFCB6E6396728BEB27AF6 /* Release */, + F08D42BCDB7968AE235F30FC /* Debug */, F08D42BCDB7968AE235F30FC /* Debug */, ); defaultConfigurationIsVisible = 0; diff --git a/build/xcode4/test_opendialog.xcodeproj/project.pbxproj b/build/xcode4/test_opendialog.xcodeproj/project.pbxproj index 60616c6..0e47dad 100644 --- a/build/xcode4/test_opendialog.xcodeproj/project.pbxproj +++ b/build/xcode4/test_opendialog.xcodeproj/project.pbxproj @@ -205,12 +205,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Debug/x64, + ../lib/Debug/arm64, ); - OBJROOT = obj/x64/Debug/test_opendialog; + OBJROOT = ../obj/arm64/Debug/test_opendialog; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); OTHER_LDFLAGS = ( "-lnfd_d", + "-target arm64-apple-macos11", ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( @@ -244,10 +248,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Release/x64, + ../lib/Release/arm64, ); - OBJROOT = obj/x64/Release/test_opendialog; + OBJROOT = ../obj/arm64/Release/test_opendialog; ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); + OTHER_LDFLAGS = ( + "-target arm64-apple-macos11", + ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( ../../src/include, @@ -274,6 +284,8 @@ isa = XCConfigurationList; buildConfigurations = ( 3AC688EA60ECB89CC7F3AF2A /* Release */, + 3AC688EA60ECB89CC7F3AF2A /* Release */, + 188342B02F95DDE21FB1D8F0 /* Debug */, 188342B02F95DDE21FB1D8F0 /* Debug */, ); defaultConfigurationIsVisible = 0; @@ -283,6 +295,8 @@ isa = XCConfigurationList; buildConfigurations = ( 2B21E9B97884DFEBEEA3DFF9 /* Release */, + 2B21E9B97884DFEBEEA3DFF9 /* Release */, + 888E12FF4BF9D4B18A9D793F /* Debug */, 888E12FF4BF9D4B18A9D793F /* Debug */, ); defaultConfigurationIsVisible = 0; diff --git a/build/xcode4/test_opendialogmultiple.xcodeproj/project.pbxproj b/build/xcode4/test_opendialogmultiple.xcodeproj/project.pbxproj index 057fd75..a8e48d2 100644 --- a/build/xcode4/test_opendialogmultiple.xcodeproj/project.pbxproj +++ b/build/xcode4/test_opendialogmultiple.xcodeproj/project.pbxproj @@ -215,10 +215,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Release/x64, + ../lib/Release/arm64, ); - OBJROOT = obj/x64/Release/test_opendialogmultiple; + OBJROOT = ../obj/arm64/Release/test_opendialogmultiple; ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); + OTHER_LDFLAGS = ( + "-target arm64-apple-macos11", + ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( ../../src/include, @@ -241,12 +247,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Debug/x64, + ../lib/Debug/arm64, ); - OBJROOT = obj/x64/Debug/test_opendialogmultiple; + OBJROOT = ../obj/arm64/Debug/test_opendialogmultiple; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); OTHER_LDFLAGS = ( "-lnfd_d", + "-target arm64-apple-macos11", ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( @@ -274,6 +284,8 @@ isa = XCConfigurationList; buildConfigurations = ( 39064156FC7203083B15A796 /* Release */, + 39064156FC7203083B15A796 /* Release */, + A461F01CC62D9D4E02E2C65C /* Debug */, A461F01CC62D9D4E02E2C65C /* Debug */, ); defaultConfigurationIsVisible = 0; @@ -283,6 +295,8 @@ isa = XCConfigurationList; buildConfigurations = ( 298419250DCB215791B84F65 /* Release */, + 298419250DCB215791B84F65 /* Release */, + EB85776BB9A8CB1D40B71DAB /* Debug */, EB85776BB9A8CB1D40B71DAB /* Debug */, ); defaultConfigurationIsVisible = 0; diff --git a/build/xcode4/test_pickfolder.xcodeproj/project.pbxproj b/build/xcode4/test_pickfolder.xcodeproj/project.pbxproj index d02dc65..dcbf531 100644 --- a/build/xcode4/test_pickfolder.xcodeproj/project.pbxproj +++ b/build/xcode4/test_pickfolder.xcodeproj/project.pbxproj @@ -227,10 +227,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Release/x64, + ../lib/Release/arm64, ); - OBJROOT = obj/x64/Release/test_pickfolder; + OBJROOT = ../obj/arm64/Release/test_pickfolder; ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); + OTHER_LDFLAGS = ( + "-target arm64-apple-macos11", + ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( ../../src/include, @@ -253,12 +259,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Debug/x64, + ../lib/Debug/arm64, ); - OBJROOT = obj/x64/Debug/test_pickfolder; + OBJROOT = ../obj/arm64/Debug/test_pickfolder; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); OTHER_LDFLAGS = ( "-lnfd_d", + "-target arm64-apple-macos11", ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( @@ -274,6 +284,8 @@ isa = XCConfigurationList; buildConfigurations = ( B388AA0BD9AED9BD40B5D04B /* Release */, + B388AA0BD9AED9BD40B5D04B /* Release */, + C658A791DD6B42C3CD873DD1 /* Debug */, C658A791DD6B42C3CD873DD1 /* Debug */, ); defaultConfigurationIsVisible = 0; @@ -283,6 +295,8 @@ isa = XCConfigurationList; buildConfigurations = ( 22B4A81A70179E4CE6369E5A /* Release */, + 22B4A81A70179E4CE6369E5A /* Release */, + B1EBC520755786D2B3FB2B60 /* Debug */, B1EBC520755786D2B3FB2B60 /* Debug */, ); defaultConfigurationIsVisible = 0; diff --git a/build/xcode4/test_savedialog.xcodeproj/project.pbxproj b/build/xcode4/test_savedialog.xcodeproj/project.pbxproj index 6c7d1f0..cc509a7 100644 --- a/build/xcode4/test_savedialog.xcodeproj/project.pbxproj +++ b/build/xcode4/test_savedialog.xcodeproj/project.pbxproj @@ -203,10 +203,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Release/x64, + ../lib/Release/arm64, ); - OBJROOT = obj/x64/Release/test_savedialog; + OBJROOT = ../obj/arm64/Release/test_savedialog; ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); + OTHER_LDFLAGS = ( + "-target arm64-apple-macos11", + ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( ../../src/include, @@ -253,12 +259,16 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; LIBRARY_SEARCH_PATHS = ( - ../lib/Debug/x64, + ../lib/Debug/arm64, ); - OBJROOT = obj/x64/Debug/test_savedialog; + OBJROOT = ../obj/arm64/Debug/test_savedialog; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = ( + "-target arm64-apple-macos11", + ); OTHER_LDFLAGS = ( "-lnfd_d", + "-target arm64-apple-macos11", ); SYMROOT = ../bin; USER_HEADER_SEARCH_PATHS = ( @@ -274,6 +284,8 @@ isa = XCConfigurationList; buildConfigurations = ( 0EFAC8E73520F8999C27EF27 /* Release */, + 0EFAC8E73520F8999C27EF27 /* Release */, + B5BD5F6DCCCFFA9FBCEBF5AD /* Debug */, B5BD5F6DCCCFFA9FBCEBF5AD /* Debug */, ); defaultConfigurationIsVisible = 0; @@ -283,6 +295,8 @@ isa = XCConfigurationList; buildConfigurations = ( 6D9009F6BAF3002831120036 /* Release */, + 6D9009F6BAF3002831120036 /* Release */, + 0F8CFFFCD2F8C1AE119C663C /* Debug */, 0F8CFFFCD2F8C1AE119C663C /* Debug */, ); defaultConfigurationIsVisible = 0; diff --git a/docs/build.md b/docs/build.md index a76965e..0f92d94 100644 --- a/docs/build.md +++ b/docs/build.md @@ -46,3 +46,18 @@ Use `make help` to see all available options. 32-bit ARM is not currently supported. +## Building Apple Silicon ## + +In 2020, Apple announced Apple Silicon. This is fully supported by Native File Dialog. This can be targeted by passing `config=debug_arm64` to the Makefile in `gmake_macosx`. + +Further, a fat binary static library can be produced: + +```bash +cd build/gmake_macosx +./fat_bin.pl debug +./fat_bin.pl release + +# (optional) see it for yourself +lipo -archs ../lib/Debug/libnfd_d.a +lipo -archs ../lib/Release/libnfd.a +``` From 29bd31d60d14967886b998b5650a66561f4700e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Fri, 15 Jan 2021 16:22:22 -0800 Subject: [PATCH 23/25] suggest survey to user --- README.md | 8 ++++++++ build/gmake_linux/nfd.make | 12 ++++++++++++ build/gmake_linux_zenity/nfd.make | 12 ++++++++++++ build/gmake_macosx/nfd.make | 8 ++++++++ build/gmake_windows/nfd.make | 8 ++++++++ build/premake5.lua | 9 +++++++++ build/vs2010/nfd.vcxproj | 12 ++++++++++++ build/xcode4/nfd.xcodeproj/project.pbxproj | 18 ++++++++++++++++++ 8 files changed, 87 insertions(+) diff --git a/README.md b/README.md index a8d32eb..5464514 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,14 @@ release | what's new | date | Apple Silicon support | jan 2021 | Macos fat binary builds | jan 2021 +## Usage Survey ## + +Do you use Native File Dialog? It helps me to understand how. + +There is a totally optional usage survey. Share how you use Native File Dialog. Big and small projects, public and private may share. + +[Click here to answer up to seven questions](https://forms.gle/ApWCFsXeCVxpg4XLA "Usage survey"). + ### Breaking and Notable Changes ### diff --git a/build/gmake_linux/nfd.make b/build/gmake_linux/nfd.make index b572406..081c2f2 100644 --- a/build/gmake_linux/nfd.make +++ b/build/gmake_linux/nfd.make @@ -31,6 +31,8 @@ ifeq ($(config),release_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -58,6 +60,8 @@ ifeq ($(config),release_x86) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -85,6 +89,8 @@ ifeq ($(config),release_arm64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -112,6 +118,8 @@ ifeq ($(config),debug_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -139,6 +147,8 @@ ifeq ($(config),debug_x86) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -166,6 +176,8 @@ ifeq ($(config),debug_arm64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/gmake_linux_zenity/nfd.make b/build/gmake_linux_zenity/nfd.make index d689dad..1ee8fb4 100644 --- a/build/gmake_linux_zenity/nfd.make +++ b/build/gmake_linux_zenity/nfd.make @@ -31,6 +31,8 @@ ifeq ($(config),release_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -58,6 +60,8 @@ ifeq ($(config),release_x86) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -85,6 +89,8 @@ ifeq ($(config),release_arm64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -112,6 +118,8 @@ ifeq ($(config),debug_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -139,6 +147,8 @@ ifeq ($(config),debug_x86) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -166,6 +176,8 @@ ifeq ($(config),debug_arm64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/gmake_macosx/nfd.make b/build/gmake_macosx/nfd.make index 98e711b..2d47862 100644 --- a/build/gmake_macosx/nfd.make +++ b/build/gmake_macosx/nfd.make @@ -39,6 +39,8 @@ ifeq ($(config),release_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -74,6 +76,8 @@ ifeq ($(config),release_arm64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -109,6 +113,8 @@ ifeq ($(config),debug_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -144,6 +150,8 @@ ifeq ($(config),debug_arm64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/gmake_windows/nfd.make b/build/gmake_windows/nfd.make index fc12db2..8b8e7a9 100644 --- a/build/gmake_windows/nfd.make +++ b/build/gmake_windows/nfd.make @@ -31,6 +31,8 @@ ifeq ($(config),release_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" endef all: prebuild prelink $(TARGET) @: @@ -58,6 +60,8 @@ ifeq ($(config),release_x86) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" endef all: prebuild prelink $(TARGET) @: @@ -85,6 +89,8 @@ ifeq ($(config),debug_x64) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" endef all: prebuild prelink $(TARGET) @: @@ -112,6 +118,8 @@ ifeq ($(config),debug_x86) define PRELINKCMDS endef define POSTBUILDCMDS + @echo Running postbuild commands + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" endef all: prebuild prelink $(TARGET) @: diff --git a/build/premake5.lua b/build/premake5.lua index f7cdca7..4174cb0 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -119,6 +119,15 @@ workspace "NativeFileDialog" filter "action:vs*" defines { "_CRT_SECURE_NO_WARNINGS" } + + -- ask the user nicely + msg = "Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\"" + filter {"system:not windows"} + postbuildcommands {"@echo \"\\n\27[33m ***\27[0m ".. msg .."\27[33m ***\27[0m"} + + filter {"system:windows"} + postbuildcommands {"@echo ".. msg} + local make_test = function(name) project(name) kind "ConsoleApp" diff --git a/build/vs2010/nfd.vcxproj b/build/vs2010/nfd.vcxproj index 93386e0..25b9982 100644 --- a/build/vs2010/nfd.vcxproj +++ b/build/vs2010/nfd.vcxproj @@ -105,6 +105,9 @@ true true + + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @@ -123,6 +126,9 @@ true true + + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @@ -137,6 +143,9 @@ Windows true + + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @@ -151,6 +160,9 @@ Windows true + + @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + diff --git a/build/xcode4/nfd.xcodeproj/project.pbxproj b/build/xcode4/nfd.xcodeproj/project.pbxproj index 1828b22..b95dd66 100644 --- a/build/xcode4/nfd.xcodeproj/project.pbxproj +++ b/build/xcode4/nfd.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ CAB045371D367029EF7AD377 /* Resources */, 345D5E8E86E389805927ECCE /* Sources */, 5AC8C497AD4EEF897F9352D7 /* Frameworks */, + 9607AE3710C85E8F00CD1376 /* Postbuild */, ); buildRules = ( ); @@ -111,6 +112,23 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 9607AE3710C85E8F00CD1376 /* Postbuild */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = Postbuild; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "set -e\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 345D5E8E86E389805927ECCE /* Sources */ = { isa = PBXSourcesBuildPhase; From 4835a5d5fe3fdb65d8539d8d1af5fee920a543c1 Mon Sep 17 00:00:00 2001 From: Michael Labbe Date: Sat, 16 Jan 2021 09:05:24 -0800 Subject: [PATCH 24/25] fix mingw, update ftg_core, change build msg --- build/gmake_linux/nfd.make | 12 +++---- build/gmake_linux_zenity/nfd.make | 12 +++---- build/gmake_macosx/nfd.make | 8 ++--- build/gmake_windows/nfd.make | 16 ++++----- build/premake5.lua | 9 ++--- build/vs2010/nfd.vcxproj | 16 ++++----- build/xcode4/nfd.xcodeproj/project.pbxproj | 2 +- src/ftg_core.h | 38 ++++++++++++++++------ 8 files changed, 66 insertions(+), 47 deletions(-) diff --git a/build/gmake_linux/nfd.make b/build/gmake_linux/nfd.make index 081c2f2..84eadac 100644 --- a/build/gmake_linux/nfd.make +++ b/build/gmake_linux/nfd.make @@ -32,7 +32,7 @@ ifeq ($(config),release_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -61,7 +61,7 @@ ifeq ($(config),release_x86) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -90,7 +90,7 @@ ifeq ($(config),release_arm64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -119,7 +119,7 @@ ifeq ($(config),debug_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -148,7 +148,7 @@ ifeq ($(config),debug_x86) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -177,7 +177,7 @@ ifeq ($(config),debug_arm64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/gmake_linux_zenity/nfd.make b/build/gmake_linux_zenity/nfd.make index 1ee8fb4..ad6832f 100644 --- a/build/gmake_linux_zenity/nfd.make +++ b/build/gmake_linux_zenity/nfd.make @@ -32,7 +32,7 @@ ifeq ($(config),release_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -61,7 +61,7 @@ ifeq ($(config),release_x86) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -90,7 +90,7 @@ ifeq ($(config),release_arm64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -119,7 +119,7 @@ ifeq ($(config),debug_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -148,7 +148,7 @@ ifeq ($(config),debug_x86) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -177,7 +177,7 @@ ifeq ($(config),debug_arm64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/gmake_macosx/nfd.make b/build/gmake_macosx/nfd.make index 2d47862..ebc42b8 100644 --- a/build/gmake_macosx/nfd.make +++ b/build/gmake_macosx/nfd.make @@ -40,7 +40,7 @@ ifeq ($(config),release_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -77,7 +77,7 @@ ifeq ($(config),release_arm64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -114,7 +114,7 @@ ifeq ($(config),debug_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -151,7 +151,7 @@ ifeq ($(config),debug_arm64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo "\n *** Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" *** + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/gmake_windows/nfd.make b/build/gmake_windows/nfd.make index 8b8e7a9..7ce9c53 100644 --- a/build/gmake_windows/nfd.make +++ b/build/gmake_windows/nfd.make @@ -15,7 +15,7 @@ ifeq ($(config),release_x64) TARGETDIR = ../lib/Release/x64 TARGET = $(TARGETDIR)/nfd.lib OBJDIR = obj/x64/Release/nfd - DEFINES += -DNDEBUG + DEFINES += -DNDEBUG -DUNICODE -D_UNICODE INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) @@ -32,7 +32,7 @@ ifeq ($(config),release_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -44,7 +44,7 @@ ifeq ($(config),release_x86) TARGETDIR = ../lib/Release/x86 TARGET = $(TARGETDIR)/nfd.lib OBJDIR = obj/x86/Release/nfd - DEFINES += -DNDEBUG + DEFINES += -DNDEBUG -DUNICODE -D_UNICODE INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) @@ -61,7 +61,7 @@ ifeq ($(config),release_x86) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -73,7 +73,7 @@ ifeq ($(config),debug_x64) TARGETDIR = ../lib/Debug/x64 TARGET = $(TARGETDIR)/nfd_d.lib OBJDIR = obj/x64/Debug/nfd - DEFINES += -DDEBUG + DEFINES += -DDEBUG -DUNICODE -D_UNICODE INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) @@ -90,7 +90,7 @@ ifeq ($(config),debug_x64) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: @@ -102,7 +102,7 @@ ifeq ($(config),debug_x86) TARGETDIR = ../lib/Debug/x86 TARGET = $(TARGETDIR)/nfd_d.lib OBJDIR = obj/x86/Debug/nfd - DEFINES += -DDEBUG + DEFINES += -DDEBUG -DUNICODE -D_UNICODE INCLUDES += -I../../src/include FORCE_INCLUDE += ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) @@ -119,7 +119,7 @@ ifeq ($(config),debug_x86) endef define POSTBUILDCMDS @echo Running postbuild commands - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo "\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA" *** endef all: prebuild prelink $(TARGET) @: diff --git a/build/premake5.lua b/build/premake5.lua index 4174cb0..7241fc9 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -96,6 +96,7 @@ workspace "NativeFileDialog" filter "system:windows" language "C++" files {root_dir.."src/nfd_win.cpp"} + defines {"UNICODE", "_UNICODE"} filter {"action:gmake or action:xcode4"} buildoptions {"-fno-exceptions"} @@ -121,12 +122,12 @@ workspace "NativeFileDialog" -- ask the user nicely - msg = "Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\"" - filter {"system:not windows"} + msg = "Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA\"" + filter {"action:not vs*"} postbuildcommands {"@echo \"\\n\27[33m ***\27[0m ".. msg .."\27[33m ***\27[0m"} - filter {"system:windows"} - postbuildcommands {"@echo ".. msg} + filter {"action:vs*"} + postbuildcommands {"@echo Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA"} local make_test = function(name) project(name) diff --git a/build/vs2010/nfd.vcxproj b/build/vs2010/nfd.vcxproj index 25b9982..30e19df 100644 --- a/build/vs2010/nfd.vcxproj +++ b/build/vs2010/nfd.vcxproj @@ -92,7 +92,7 @@ NotUsing Level4 - NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + NDEBUG;UNICODE;_UNICODE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\src\include;%(AdditionalIncludeDirectories) Full true @@ -106,14 +106,14 @@ true - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA NotUsing Level4 - NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + NDEBUG;UNICODE;_UNICODE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\src\include;%(AdditionalIncludeDirectories) Full true @@ -127,14 +127,14 @@ true - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA NotUsing Level4 - DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + DEBUG;UNICODE;_UNICODE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\src\include;%(AdditionalIncludeDirectories) ProgramDatabase Disabled @@ -144,14 +144,14 @@ true - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA NotUsing Level4 - DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + DEBUG;UNICODE;_UNICODE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ..\..\src\include;%(AdditionalIncludeDirectories) EditAndContinue Disabled @@ -161,7 +161,7 @@ true - @echo Do you use Native File Dialog? There is a totally optional user survey. \nI would appreciate hearing how you use it!\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA" + @echo Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA diff --git a/build/xcode4/nfd.xcodeproj/project.pbxproj b/build/xcode4/nfd.xcodeproj/project.pbxproj index b95dd66..c80fe2c 100644 --- a/build/xcode4/nfd.xcodeproj/project.pbxproj +++ b/build/xcode4/nfd.xcodeproj/project.pbxproj @@ -125,7 +125,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "set -e\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n@echo \"\\n *** Do you use Native File Dialog? There is a totally optional user survey. \\nI would appreciate hearing how you use it!\\nSurvey: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***\nfi"; + shellScript = "set -e\n@echo \"\\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/src/ftg_core.h b/src/ftg_core.h index dd3190b..857f03a 100644 --- a/src/ftg_core.h +++ b/src/ftg_core.h @@ -88,6 +88,8 @@ #ifndef FTG_CORE_NO_STDIO # include +#else +# include // for size_t #endif /* for off64_t */ @@ -112,8 +114,12 @@ /* broad test for OSes that are vaguely POSIX compliant */ #if defined(__linux__) || defined(__APPLE__) || defined(ANDROID) || \ defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \ - defined(__FreeBSD__) || defined(__OpenBSD__) -# define FTG_POSIX_LIKE + defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__) +# define FTG_POSIX_LIKE 1 +#endif + +#if defined(__EMSCRIPTEN__) +# define FTG_WASM 1 #endif /* detect target enviroment bits */ @@ -126,7 +132,7 @@ # if __x86_64__ || __ppc64__ || __aarch64__ # define FTG_BITS 64 # else -# define FTG_BITS 32 +# define FTG_BITS 32 // todo: confirm emscripten sets this # endif #endif @@ -229,8 +235,10 @@ #ifndef FTG_BREAK #if defined(_WIN32) && _MSC_VER >= 1310 #define FTG_BREAK() __debugbreak(); - #elif defined(_WIN32) + #elif defined(_WIN32) && defined(_MSC_VER) #define FTG_BREAK() __asm{ int 0x3 } + #elif defined(__MINGW32__) + #define FTG_BREAK() __asm__ volatile("int $0x03"); #elif defined(__linux__) #ifdef __arm__ #define FTG_BREAK() __asm__ volatile(".inst 0xde01"); @@ -392,12 +400,14 @@ typedef struct ftg_dirhandle_s ftg_dirhandle_t; typedef int64_t ftg_off_t; typedef wchar_t ftg_wchar_t; #elif defined(__FreeBSD__) || defined(__OpenBSD__) - typedef off_t ftg_off_t; +typedef off_t ftg_off_t; +#elif defined(FTG_WASM) +typedef off_t ftg_off_t; #endif FTG_STATIC_ASSERT(sizeof(ftg_off_t)==8); -#endif /* FTG_CORE_NO_STDIO */ +#endif /* !FTG_CORE_NO_STDIO */ FTG_STATIC_ASSERT(sizeof(int8_t)==1); FTG_STATIC_ASSERT(sizeof(int16_t)==2); @@ -2561,6 +2571,7 @@ static int ftg__test_correct_dirslash(void) static int ftg__test_opendir(void) { +#ifndef FTG_CORE_NO_STDIO ftg_dirhandle_t dir; char path_str[FTG_STRLEN_LONG]; int dot_count = 0; @@ -2580,15 +2591,17 @@ static int ftg__test_opendir(void) ftg_closedir(&dir); FTGT_ASSERT(dot_count==2); - +#endif return ftgt_test_errorlevel(); } static int ftg__test_is_dir(void) { +#ifndef FTG_CORE_NO_STDIO + #ifdef FTG_POSIX_LIKE FTGT_ASSERT(ftg_is_dir("/")); -#else +#elif _WIN32 FTGT_ASSERT(ftg_is_dir("c:\\")); #endif @@ -2597,7 +2610,8 @@ static int ftg__test_is_dir(void) FTGT_ASSERT(ftg_is_dirslash('/')); FTGT_ASSERT(ftg_is_dirslash('\\')); FTGT_ASSERT(!ftg_is_dirslash(' ')); - +#endif + return ftgt_test_errorlevel(); } @@ -2671,6 +2685,7 @@ static int ftg__test_get_filename_from_path(void) static int ftg__test_file_rw(void) { +#ifndef FTG_CORE_NO_STDIO const char tmp_file[] = "ftg_core_tmp_file.txt"; const char test_str[] = "hello\nworld!"; unsigned char *read_str; @@ -2685,7 +2700,8 @@ static int ftg__test_file_rw(void) FTG_FREE(read_str); // todo: rm temp file - +#endif + return ftgt_test_errorlevel(); } @@ -2715,6 +2731,7 @@ static int ftg__test_ia(void) static int ftg__test_dircreate(void) { +#ifndef FTG_CORE_NO_STDIO bool success; if (ftg_is_dir("testdir")) { @@ -2737,6 +2754,7 @@ static int ftg__test_dircreate(void) FTGT_ASSERT(ftg_is_dir("one/two/three")); ftg_rmalldirs("one"); FTGT_ASSERT(!ftg_is_dir("one")); +#endif return ftgt_test_errorlevel(); } From 2850c97af02e6b4cce6ffb91a0445acb5eb9b241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Labb=C3=A9?= Date: Sat, 16 Jan 2021 09:29:20 -0800 Subject: [PATCH 25/25] fix recently introduced xcode error --- README.md | 2 +- build/premake5.lua | 2 +- build/xcode4/nfd.xcodeproj/project.pbxproj | 18 ------------------ 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5464514..9ad6039 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Do you use Native File Dialog? It helps me to understand how. There is a totally optional usage survey. Share how you use Native File Dialog. Big and small projects, public and private may share. -[Click here to answer up to seven questions](https://forms.gle/ApWCFsXeCVxpg4XLA "Usage survey"). +[Click here to fill out the usage survey.](https://forms.gle/ApWCFsXeCVxpg4XLA "Usage survey"). ### Breaking and Notable Changes ### diff --git a/build/premake5.lua b/build/premake5.lua index 7241fc9..fb525ab 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -123,7 +123,7 @@ workspace "NativeFileDialog" -- ask the user nicely msg = "Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA\"" - filter {"action:not vs*"} + filter {"action:not vs*", "action:not xcode*"} postbuildcommands {"@echo \"\\n\27[33m ***\27[0m ".. msg .."\27[33m ***\27[0m"} filter {"action:vs*"} diff --git a/build/xcode4/nfd.xcodeproj/project.pbxproj b/build/xcode4/nfd.xcodeproj/project.pbxproj index c80fe2c..1828b22 100644 --- a/build/xcode4/nfd.xcodeproj/project.pbxproj +++ b/build/xcode4/nfd.xcodeproj/project.pbxproj @@ -74,7 +74,6 @@ CAB045371D367029EF7AD377 /* Resources */, 345D5E8E86E389805927ECCE /* Sources */, 5AC8C497AD4EEF897F9352D7 /* Frameworks */, - 9607AE3710C85E8F00CD1376 /* Postbuild */, ); buildRules = ( ); @@ -112,23 +111,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 9607AE3710C85E8F00CD1376 /* Postbuild */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = Postbuild; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "set -e\n@echo \"\\n *** Do you use Native File Dialog? Please take the user survey to help development: https://forms.gle/ApWCFsXeCVxpg4XLA\" ***"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ 345D5E8E86E389805927ECCE /* Sources */ = { isa = PBXSourcesBuildPhase;