From 89511934b805999e0c12071750c52c1c45d35536 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 12 May 2021 23:46:22 -0400 Subject: Proper namespace for the header file. Bump version. --- CMakeLists.txt | 10 +++--- include/cleanpath.h | 64 --------------------------------------- include/cleanpath/cleanpath.h | 64 +++++++++++++++++++++++++++++++++++++++ lib/cleanpath.c | 2 +- src/main.c | 2 +- tests/test_errors.c | 4 +-- tests/test_modes_filter_all.c | 4 +-- tests/test_modes_filter_general.c | 4 +-- tests/test_no_sep_ending.c | 4 +-- 9 files changed, 79 insertions(+), 79 deletions(-) delete mode 100644 include/cleanpath.h create mode 100644 include/cleanpath/cleanpath.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cbeba46..562064d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ include(CTest) set(CMAKE_C_STANDARD 99) set(LIB_SOURCES lib/cleanpath.c) set(MAIN_SOURCES src/main.c) -set(INCLUDES include/cleanpath.h) +set(LIB_INCLUDES include/cleanpath/cleanpath.h) configure_file ("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/include/config.h") @@ -19,22 +19,22 @@ enable_testing() add_subdirectory(tests) add_library(cleanpath_static STATIC ${LIB_SOURCES}) -set_target_properties(cleanpath_static PROPERTIES PUBLIC_HEADER ${INCLUDES}) +set_target_properties(cleanpath_static PROPERTIES PUBLIC_HEADER ${LIB_INCLUDES}) set_target_properties(cleanpath_static PROPERTIES OUTPUT_NAME cleanpath) add_library(cleanpath_shared SHARED ${LIB_SOURCES}) -set_target_properties(cleanpath_shared PROPERTIES PUBLIC_HEADER ${INCLUDES}) +set_target_properties(cleanpath_shared PROPERTIES PUBLIC_HEADER ${LIB_INCLUDES}) set_target_properties(cleanpath_shared PROPERTIES OUTPUT_NAME cleanpath) add_executable(cleanpath ${MAIN_SOURCES}) target_link_libraries(cleanpath cleanpath_static) install(TARGETS cleanpath_static - PUBLIC_HEADER DESTINATION include + PUBLIC_HEADER DESTINATION include/cleanpath LIBRARY DESTINATION lib) install(TARGETS cleanpath_shared - PUBLIC_HEADER DESTINATION include + PUBLIC_HEADER DESTINATION include/cleanpath LIBRARY DESTINATION lib) install(TARGETS cleanpath diff --git a/include/cleanpath.h b/include/cleanpath.h deleted file mode 100644 index 9f38188..0000000 --- a/include/cleanpath.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef CLEANPATH_CLEANPATH_H -#define CLEANPATH_CLEANPATH_H - -// Define some platform detection shortcuts -#define OS_DARWIN 0 -#define OS_WINDOWS 0 -#define OS_LINUX 0 -#define OS_SUPPORTED 0 - -#if defined(__APPLE__) && defined(__MACH__) -# undef OS_DARWIN -# define OS_DARWIN 1 -# undef OS_SUPPORTED -# define OS_SUPPORTED 1 - -#elif defined(_WIN32) -# undef OS_WINDOWS -# define OS_WINDOWS 1 -# undef OS_SUPPORTED -# define OS_SUPPORTED 1 - -#elif defined(__linux) || defined(__linux__) -# undef OS_LINUX -# define OS_LINUX 1 -# undef OS_SUPPORTED -# define OS_SUPPORTED 1 -#endif - -#include -#include -#include - -#define CLEANPATH_VERSION "0.1.0" -#define CLEANPATH_FILTER_NONE -1 -#define CLEANPATH_FILTER_EXACT 0 -#define CLEANPATH_FILTER_LOOSE 1 -#define CLEANPATH_FILTER_REGEX 2 -#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 { - char *data; // Pointer to the path string - size_t data_len; // Length of the path string - char *sep; // Pointer to the separator used to split the data string - char *part[CLEANPATH_PART_MAX]; // Array of pointers to path elements - size_t part_nelem; // Total number of elements in part array -}; - -// Prototypes -struct CleanPath *cleanpath_init(const char *path, const char *sep); -void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern); -char *cleanpath_read(struct CleanPath *path); -void cleanpath_free(struct CleanPath *path); - -#endif //CLEANPATH_CLEANPATH_H \ No newline at end of file diff --git a/include/cleanpath/cleanpath.h b/include/cleanpath/cleanpath.h new file mode 100644 index 0000000..afee624 --- /dev/null +++ b/include/cleanpath/cleanpath.h @@ -0,0 +1,64 @@ +#ifndef CLEANPATH_CLEANPATH_H +#define CLEANPATH_CLEANPATH_H + +// Define some platform detection shortcuts +#define OS_DARWIN 0 +#define OS_WINDOWS 0 +#define OS_LINUX 0 +#define OS_SUPPORTED 0 + +#if defined(__APPLE__) && defined(__MACH__) +# undef OS_DARWIN +# define OS_DARWIN 1 +# undef OS_SUPPORTED +# define OS_SUPPORTED 1 + +#elif defined(_WIN32) +# undef OS_WINDOWS +# define OS_WINDOWS 1 +# undef OS_SUPPORTED +# define OS_SUPPORTED 1 + +#elif defined(__linux) || defined(__linux__) +# undef OS_LINUX +# define OS_LINUX 1 +# undef OS_SUPPORTED +# define OS_SUPPORTED 1 +#endif + +#include +#include +#include + +#define CLEANPATH_VERSION "1.0.0" +#define CLEANPATH_FILTER_NONE -1 +#define CLEANPATH_FILTER_EXACT 0 +#define CLEANPATH_FILTER_LOOSE 1 +#define CLEANPATH_FILTER_REGEX 2 +#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 { + char *data; // Pointer to the path string + size_t data_len; // Length of the path string + char *sep; // Pointer to the separator used to split the data string + char *part[CLEANPATH_PART_MAX]; // Array of pointers to path elements + size_t part_nelem; // Total number of elements in part array +}; + +// Prototypes +struct CleanPath *cleanpath_init(const char *path, const char *sep); +void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern); +char *cleanpath_read(struct CleanPath *path); +void cleanpath_free(struct CleanPath *path); + +#endif //CLEANPATH_CLEANPATH_H diff --git a/lib/cleanpath.c b/lib/cleanpath.c index fde9e6d..91b399d 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -2,7 +2,7 @@ #include #include #include "config.h" -#include "cleanpath.h" +#include "cleanpath/cleanpath.h" #if !OS_WINDOWS #include diff --git a/src/main.c b/src/main.c index 216b875..7b60bbe 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include #include #include -#include "cleanpath.h" +#include "cleanpath/cleanpath.h" // Make argument parsing less wordy #define ARGM(X) strcmp(argv[i], X) == 0 diff --git a/tests/test_errors.c b/tests/test_errors.c index f9d641f..82241ed 100644 --- a/tests/test_errors.c +++ b/tests/test_errors.c @@ -1,4 +1,4 @@ -#include "cleanpath.h" +#include "cleanpath/cleanpath.h" #include "framework.h" int main() { @@ -8,4 +8,4 @@ int main() { //intentionally bad myassert(cleanpath_init("good", NULL) == NULL, "cleanpath_init() returned non-NULL on NULL sep\n"); myassert(cleanpath_init(NULL, "good") == NULL, "cleanpath_init() returned non-NULL on NULL path\n"); -} \ No newline at end of file +} diff --git a/tests/test_modes_filter_all.c b/tests/test_modes_filter_all.c index 7e19242..d57b418 100644 --- a/tests/test_modes_filter_all.c +++ b/tests/test_modes_filter_all.c @@ -1,5 +1,5 @@ #include -#include "cleanpath.h" +#include "cleanpath/cleanpath.h" #include "framework.h" #define MAX_MODE 3 @@ -98,4 +98,4 @@ int main() { myassert(status == 0, "%d mode(s) failed", status); return 0; -} \ No newline at end of file +} diff --git a/tests/test_modes_filter_general.c b/tests/test_modes_filter_general.c index 50dec68..45206a4 100644 --- a/tests/test_modes_filter_general.c +++ b/tests/test_modes_filter_general.c @@ -1,4 +1,4 @@ -#include "cleanpath.h" +#include "cleanpath/cleanpath.h" #include "framework.h" #define MAX_MODE 3 @@ -95,4 +95,4 @@ int main() { myassert(status == 0, "%d mode(s) failed", status); return 0; -} \ No newline at end of file +} diff --git a/tests/test_no_sep_ending.c b/tests/test_no_sep_ending.c index 6b89c2b..2f86270 100644 --- a/tests/test_no_sep_ending.c +++ b/tests/test_no_sep_ending.c @@ -1,4 +1,4 @@ -#include "cleanpath.h" +#include "cleanpath/cleanpath.h" #include "framework.h" int main() { @@ -16,4 +16,4 @@ int main() { len = strlen(result); puts(result); myassert(len && *(result + (len - 1)) != TEST_SEP[0], "Result ends with a separator:\n'%s'", result); -} \ No newline at end of file +} -- cgit