diff options
-rw-r--r-- | .github/workflows/cmake.yml | 13 | ||||
-rw-r--r-- | include/cleanpath.h | 3 | ||||
-rw-r--r-- | lib/cleanpath.c | 14 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | tests/test_modes_filter_all.c | 12 | ||||
-rw-r--r-- | tests/test_modes_filter_general.c | 12 |
6 files changed, 51 insertions, 5 deletions
diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index bc094b7..abb6236 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -20,11 +20,15 @@ jobs: include: - name: Debug (Linux) os: ubuntu-latest - build_type: Release + build_type: Debug - name: Debug (MacOS) os: macos-latest - build_type: Release + build_type: Debug + + - name: Debug (Windows) + os: windows-latest + build_type: Debug - name: Release (Linux) os: ubuntu-latest @@ -34,6 +38,11 @@ jobs: os: macos-latest build_type: Release + - name: Release (Windows) + os: windows-latest + build_type: Release + + steps: - uses: actions/checkout@v2 diff --git a/include/cleanpath.h b/include/cleanpath.h index 6d50db4..b2d21f4 100644 --- a/include/cleanpath.h +++ b/include/cleanpath.h @@ -35,10 +35,13 @@ #define CLEANPATH_PART_MAX 1024 #define CLEANPATH_VAR "PATH" #define CLEANPATH_SEP ":" +#define CLEANPATH_MSG_NOAVAIL "" #if OS_WINDOWS #undef CLEANPATH_SEP #define CLEANPATH_SEP ";" +#undef CLEANPATH_MSG_NOAVAIL +#define CLEANPATH_MSG_NOAVAIL " [not implemented] " #endif struct CleanPath { diff --git a/lib/cleanpath.c b/lib/cleanpath.c index 9c46c38..2337869 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -1,9 +1,13 @@ +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <regex.h> #include "config.h" #include "cleanpath.h" +#if !OS_WINDOWS +#include <regex.h> +#endif + /** * Split path into parts by sep * @param path a string (e.g. "/path1:/path2:/pathN") @@ -58,8 +62,10 @@ struct CleanPath *cleanpath_init(const char *path, const char *sep) { * @note CLEANPATH_FILTER_EXACT is the default mode */ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern) { - int match; +#if !OS_WINDOWS regex_t regex; +#endif + int match; for (size_t i = 0; path->part[i]; i++) { match = 0; @@ -68,11 +74,15 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern match = strstr(path->part[i], pattern) != NULL ? 1 : 0; break; case CLEANPATH_FILTER_REGEX: +#if !OS_WINDOWS if (regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB) != 0) { return; } match = regexec(®ex, path->part[i], 0, NULL, 0) == 0 ? 1 : 0; regfree(®ex); +#else + fprintf(stderr, "WARNING: --regex|-r is not implemented on Windows. Using default filter mode.\n"); +#endif break; case CLEANPATH_FILTER_EXACT: default: @@ -52,7 +52,7 @@ static void show_usage() { printf(" --version -V Displays the program's version\n"); printf(" --exact -e Filter when pattern is an exact match (default)\n"); printf(" --loose -l Filter when any part of the pattern matches\n"); - printf(" --regex -r Filter matches with (Extended) Regular Expressions\n"); + printf(" --regex -r Filter matches with (Extended) Regular Expressions " CLEANPATH_MSG_NOAVAIL "\n"); printf(" --sep [str] -s Use custom path separator (default: ':')\n"); printf(" --env [str] -E Use custom environment variable (default: PATH)\n"); } diff --git a/tests/test_modes_filter_all.c b/tests/test_modes_filter_all.c index 4f41dce..7e19242 100644 --- a/tests/test_modes_filter_all.c +++ b/tests/test_modes_filter_all.c @@ -6,16 +6,26 @@ #define MAX_PART CLEANPATH_PART_MAX #define MAX_RECORD 255 +#if OS_WINDOWS +// Disable regex filter test +#undef MAX_MODE +#define MAX_MODE 2 +#endif + unsigned modes[MAX_MODE] = { CLEANPATH_FILTER_EXACT, CLEANPATH_FILTER_LOOSE, +#if !OS_WINDOWS CLEANPATH_FILTER_REGEX, +#endif }; char *modes_str[MAX_MODE] = { "exact", "loose", +#if !OS_WINDOWS "regex", +#endif }; const char *inputs[MAX_MODE][MAX_PART][MAX_RECORD] = { @@ -35,10 +45,12 @@ const char *inputs[MAX_MODE][MAX_PART][MAX_RECORD] = { "bin", NULL }, +#if !OS_WINDOWS { // Filter regex ".*", NULL }, +#endif }; struct TestResult { diff --git a/tests/test_modes_filter_general.c b/tests/test_modes_filter_general.c index e3a9cda..50dec68 100644 --- a/tests/test_modes_filter_general.c +++ b/tests/test_modes_filter_general.c @@ -5,16 +5,26 @@ #define MAX_PART CLEANPATH_PART_MAX #define MAX_RECORD 255 +#if OS_WINDOWS +// Disable regex filter test +#undef MAX_MODE +#define MAX_MODE 2 +#endif + unsigned modes[MAX_MODE] = { CLEANPATH_FILTER_EXACT, CLEANPATH_FILTER_LOOSE, +#if !OS_WINDOWS CLEANPATH_FILTER_REGEX, +#endif }; char *modes_str[MAX_MODE] = { "exact", "loose", +#if !OS_WINDOWS "regex", +#endif }; const char *inputs[MAX_MODE][MAX_PART][MAX_RECORD] = { @@ -29,12 +39,14 @@ const char *inputs[MAX_MODE][MAX_PART][MAX_RECORD] = { "intentionally bad", // test non-existent pattern in string NULL }, +#if !OS_WINDOWS { // Filter regex "^/opt/local/.*", "intentionally bad", // test non-existent pattern in string "intentionally worse (", // cause total regex failure with unmatched parenthesis NULL }, +#endif }; const char *expected = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin"; |