added conditional tests, shared library exports and cmake install instructions

This commit is contained in:
Leonard Iklé committed 2020-10-11 16:21:52 +02:00
1 parent 41c48b931b
commit fb0f22423d
4 files changed
+357 -310

No files matched your search

+2 -2
View File
@@ -19,11 +19,11 @@ init:
- cmd: echo %GENERATOR%
before_build:
- cmd: mkdir build.win && cd build.win && cmake --version && cmake .. -G %GENERATOR%
- cmd: mkdir build.win && cd build.win && cmake --version && cmake .. -DENABLE_TESTS=1 -G %GENERATOR%
build:
project: c:\projects\cwalk\build.win\cwalk.sln
verbosity: minimal
test_script:
- cmd: c:\projects\cwalk\build.win\Release\cwalktest.exe
- cmd: c:\projects\cwalk\build.win\Release\cwalktest.exe
+1 -1
View File
@@ -21,7 +21,7 @@ compiler:
before_script:
- mkdir build
- cd build
- cmake -DENABLE_COVERAGE=1 ..
- cmake -DENABLE_COVERAGE=1 -DENABLE_TESTS=1 ..
script:
- make
+215 -199
View File
@@ -39,203 +39,219 @@ endif()
add_library(${LIBRARY_TARGET}
"${INCLUDE_DIRECTORY}/cwalk.h"
"${SOURCE_DIRECTORY}/cwalk.c")
target_include_directories(${LIBRARY_TARGET} PUBLIC "${INCLUDE_DIRECTORY}")
# add tests
enable_testing()
create_test(DEFAULT absolute simple)
create_test(DEFAULT absolute absolute_path)
create_test(DEFAULT absolute unix_relative_base)
create_test(DEFAULT absolute windows_relative_base)
create_test(DEFAULT absolute mixed)
create_test(DEFAULT absolute normalization)
create_test(DEFAULT absolute too_far)
create_test(DEFAULT absolute check)
create_test(DEFAULT absolute buffer_reuse)
create_test(DEFAULT basename simple)
create_test(DEFAULT basename empty)
create_test(DEFAULT basename trailing_separator)
create_test(DEFAULT basename trailing_separators)
create_test(DEFAULT basename no_separators)
create_test(DEFAULT basename special_directories)
create_test(DEFAULT basename root)
create_test(DEFAULT basename windows)
create_test(DEFAULT basename change_simple)
create_test(DEFAULT basename change_empty_path)
create_test(DEFAULT basename change_only_root)
create_test(DEFAULT basename change_empty_basename)
create_test(DEFAULT basename change_relative)
create_test(DEFAULT basename change_trim)
create_test(DEFAULT basename change_trim_only_root)
create_test(DEFAULT dirname simple)
create_test(DEFAULT dirname empty)
create_test(DEFAULT dirname trailing_separator)
create_test(DEFAULT dirname trailing_separators)
create_test(DEFAULT dirname no_separators)
create_test(DEFAULT dirname special_directories)
create_test(DEFAULT dirname root)
create_test(DEFAULT dirname three_segments)
create_test(DEFAULT dirname relative)
create_test(DEFAULT extension get_simple)
create_test(DEFAULT extension get_without)
create_test(DEFAULT extension get_first)
create_test(DEFAULT extension get_last)
create_test(DEFAULT extension get_multiple)
create_test(DEFAULT extension check_simple)
create_test(DEFAULT extension check_empty)
create_test(DEFAULT extension check_without)
create_test(DEFAULT extension change_simple)
create_test(DEFAULT extension change_no_basename)
create_test(DEFAULT extension change_no_extension)
create_test(DEFAULT extension change_with_dot)
create_test(DEFAULT extension change_overlap)
create_test(DEFAULT extension change_overlap_long)
create_test(DEFAULT extension change_hidden_file)
create_test(DEFAULT extension change_with_trailing_slash)
create_test(DEFAULT guess empty_string)
create_test(DEFAULT guess windows_root)
create_test(DEFAULT guess unix_root)
create_test(DEFAULT guess windows_separator)
create_test(DEFAULT guess unix_separator)
create_test(DEFAULT guess hidden_file)
create_test(DEFAULT guess extension)
create_test(DEFAULT guess unguessable)
create_test(DEFAULT intersection simple)
create_test(DEFAULT intersection trailing_separator)
create_test(DEFAULT intersection double_separator)
create_test(DEFAULT intersection empty)
create_test(DEFAULT intersection unequal_roots)
create_test(DEFAULT intersection relative_absolute_mix)
create_test(DEFAULT intersection same_roots)
create_test(DEFAULT intersection one_root_only)
create_test(DEFAULT intersection relative_base)
create_test(DEFAULT intersection relative_other)
create_test(DEFAULT intersection skipped_end)
create_test(DEFAULT is_absolute absolute)
create_test(DEFAULT is_absolute unc)
create_test(DEFAULT is_absolute device_unc)
create_test(DEFAULT is_absolute device_dot)
create_test(DEFAULT is_absolute device_question_mark)
create_test(DEFAULT is_absolute relative)
create_test(DEFAULT is_absolute windows_backslash)
create_test(DEFAULT is_absolute windows_slash)
create_test(DEFAULT is_absolute unix_backslash)
create_test(DEFAULT is_absolute unix_drive)
create_test(DEFAULT is_absolute absolute_drive)
create_test(DEFAULT is_absolute relative_drive)
create_test(DEFAULT is_absolute relative_windows)
create_test(DEFAULT is_relative absolute)
create_test(DEFAULT is_relative unc)
create_test(DEFAULT is_relative device_unc)
create_test(DEFAULT is_relative device_dot)
create_test(DEFAULT is_relative device_question_mark)
create_test(DEFAULT is_relative relative)
create_test(DEFAULT is_relative windows_backslash)
create_test(DEFAULT is_relative windows_slash)
create_test(DEFAULT is_relative unix_backslash)
create_test(DEFAULT is_relative unix_drive)
create_test(DEFAULT is_relative absolute_drive)
create_test(DEFAULT is_relative relative_drive)
create_test(DEFAULT is_relative relative_windows)
create_test(DEFAULT join simple)
create_test(DEFAULT join navigate_back)
create_test(DEFAULT join empty)
create_test(DEFAULT join two_absolute)
create_test(DEFAULT join two_unc)
create_test(DEFAULT join with_two_roots)
create_test(DEFAULT join back_after_root)
create_test(DEFAULT join relative_back_after_root)
create_test(DEFAULT join multiple)
create_test(DEFAULT normalize do_nothing)
create_test(DEFAULT normalize navigate_back)
create_test(DEFAULT normalize relative_too_far)
create_test(DEFAULT normalize absolute_too_far)
create_test(DEFAULT normalize terminated)
create_test(DEFAULT normalize double_separator)
create_test(DEFAULT normalize remove_current)
create_test(DEFAULT normalize mixed)
create_test(DEFAULT normalize overlap)
create_test(DEFAULT normalize empty)
create_test(DEFAULT normalize only_separators)
create_test(DEFAULT normalize back_after_root)
create_test(DEFAULT relative simple)
create_test(DEFAULT relative relative)
create_test(DEFAULT relative long_base)
create_test(DEFAULT relative long_target)
create_test(DEFAULT relative equal)
create_test(DEFAULT relative base_skipped_end)
create_test(DEFAULT relative target_skipped_end)
create_test(DEFAULT relative base_div_skipped_end)
create_test(DEFAULT relative target_div_skipped_end)
create_test(DEFAULT relative skip_all)
create_test(DEFAULT relative different_roots)
create_test(DEFAULT relative check)
create_test(DEFAULT root absolute)
create_test(DEFAULT root unc)
create_test(DEFAULT root device_unc)
create_test(DEFAULT root device_dot)
create_test(DEFAULT root device_question_mark)
create_test(DEFAULT root relative)
create_test(DEFAULT root windows_backslash)
create_test(DEFAULT root windows_slash)
create_test(DEFAULT root unix_backslash)
create_test(DEFAULT root unix_drive)
create_test(DEFAULT root absolute_drive)
create_test(DEFAULT root relative_drive)
create_test(DEFAULT root relative_windows)
create_test(DEFAULT root change_simple)
create_test(DEFAULT root change_empty)
create_test(DEFAULT root change_separators)
create_test(DEFAULT root change_overlapping)
create_test(DEFAULT root change_without_root)
create_test(DEFAULT segment first)
create_test(DEFAULT segment last)
create_test(DEFAULT segment next)
create_test(DEFAULT segment next_too_far)
create_test(DEFAULT segment previous_absolute)
create_test(DEFAULT segment previous_relative)
create_test(DEFAULT segment previous_absolute_one_char_first)
create_test(DEFAULT segment previous_relative_one_char_first)
create_test(DEFAULT segment previous_too_far)
create_test(DEFAULT segment previous_too_far_root)
create_test(DEFAULT segment type)
create_test(DEFAULT segment back_with_root)
create_test(DEFAULT segment change_simple)
create_test(DEFAULT segment change_first)
create_test(DEFAULT segment change_last)
create_test(DEFAULT segment change_trim)
create_test(DEFAULT segment change_empty)
create_test(DEFAULT segment change_with_separator)
create_test(DEFAULT segment change_overlap)
create_test(DEFAULT windows change_style)
create_test(DEFAULT windows get_root)
create_test(DEFAULT windows get_unc_root)
create_test(DEFAULT windows get_root_separator)
create_test(DEFAULT windows get_root_relative)
create_test(DEFAULT windows intersection_case)
create_test(DEFAULT windows root_backslash)
create_test(DEFAULT windows root_empty)
create_test_list(DEFAULT "${TEST_DIRECTORY}/tests.h")
add_executable(${TEST_TARGET}
"${TEST_DIRECTORY}/main.c"
"${TEST_DIRECTORY}/absolute_test.c"
"${TEST_DIRECTORY}/basename_test.c"
"${TEST_DIRECTORY}/dirname_test.c"
"${TEST_DIRECTORY}/extension_test.c"
"${TEST_DIRECTORY}/guess_test.c"
"${TEST_DIRECTORY}/intersection_test.c"
"${TEST_DIRECTORY}/is_absolute_test.c"
"${TEST_DIRECTORY}/is_relative_test.c"
"${TEST_DIRECTORY}/join_test.c"
"${TEST_DIRECTORY}/normalize_test.c"
"${TEST_DIRECTORY}/relative_test.c"
"${TEST_DIRECTORY}/root_test.c"
"${TEST_DIRECTORY}/segment_test.c"
"${TEST_DIRECTORY}/windows_test.c")
target_link_libraries(${TEST_TARGET} PUBLIC ${LIBRARY_TARGET})
target_include_directories(${TEST_TARGET} PUBLIC "${INCLUDE_DIRECTORY}")
# enable warnings
enable_warnings(${TEST_TARGET})
enable_warnings(${LIBRARY_TARGET})
target_include_directories(${LIBRARY_TARGET} PUBLIC "${INCLUDE_DIRECTORY}")
set_target_properties(${LIBRARY_TARGET} PROPERTIES PUBLIC_HEADER "${INCLUDE_DIRECTORY}/cwalk.h")
set_target_properties(${LIBRARY_TARGET} PROPERTIES DEFINE_SYMBOL CWK_EXPORTS)
# add shared library macro
if(BUILD_SHARED_LIBS)
target_compile_definitions(${LIBRARY_TARGET} PUBLIC CWK_SHARED)
endif()
# enable tests
if(ENABLE_TESTS)
message("-- Tests enabled")
enable_testing()
create_test(DEFAULT absolute simple)
create_test(DEFAULT absolute absolute_path)
create_test(DEFAULT absolute unix_relative_base)
create_test(DEFAULT absolute windows_relative_base)
create_test(DEFAULT absolute mixed)
create_test(DEFAULT absolute normalization)
create_test(DEFAULT absolute too_far)
create_test(DEFAULT absolute check)
create_test(DEFAULT absolute buffer_reuse)
create_test(DEFAULT basename simple)
create_test(DEFAULT basename empty)
create_test(DEFAULT basename trailing_separator)
create_test(DEFAULT basename trailing_separators)
create_test(DEFAULT basename no_separators)
create_test(DEFAULT basename special_directories)
create_test(DEFAULT basename root)
create_test(DEFAULT basename windows)
create_test(DEFAULT basename change_simple)
create_test(DEFAULT basename change_empty_path)
create_test(DEFAULT basename change_only_root)
create_test(DEFAULT basename change_empty_basename)
create_test(DEFAULT basename change_relative)
create_test(DEFAULT basename change_trim)
create_test(DEFAULT basename change_trim_only_root)
create_test(DEFAULT dirname simple)
create_test(DEFAULT dirname empty)
create_test(DEFAULT dirname trailing_separator)
create_test(DEFAULT dirname trailing_separators)
create_test(DEFAULT dirname no_separators)
create_test(DEFAULT dirname special_directories)
create_test(DEFAULT dirname root)
create_test(DEFAULT dirname three_segments)
create_test(DEFAULT dirname relative)
create_test(DEFAULT extension get_simple)
create_test(DEFAULT extension get_without)
create_test(DEFAULT extension get_first)
create_test(DEFAULT extension get_last)
create_test(DEFAULT extension get_multiple)
create_test(DEFAULT extension check_simple)
create_test(DEFAULT extension check_empty)
create_test(DEFAULT extension check_without)
create_test(DEFAULT extension change_simple)
create_test(DEFAULT extension change_no_basename)
create_test(DEFAULT extension change_no_extension)
create_test(DEFAULT extension change_with_dot)
create_test(DEFAULT extension change_overlap)
create_test(DEFAULT extension change_overlap_long)
create_test(DEFAULT extension change_hidden_file)
create_test(DEFAULT extension change_with_trailing_slash)
create_test(DEFAULT guess empty_string)
create_test(DEFAULT guess windows_root)
create_test(DEFAULT guess unix_root)
create_test(DEFAULT guess windows_separator)
create_test(DEFAULT guess unix_separator)
create_test(DEFAULT guess hidden_file)
create_test(DEFAULT guess extension)
create_test(DEFAULT guess unguessable)
create_test(DEFAULT intersection simple)
create_test(DEFAULT intersection trailing_separator)
create_test(DEFAULT intersection double_separator)
create_test(DEFAULT intersection empty)
create_test(DEFAULT intersection unequal_roots)
create_test(DEFAULT intersection relative_absolute_mix)
create_test(DEFAULT intersection same_roots)
create_test(DEFAULT intersection one_root_only)
create_test(DEFAULT intersection relative_base)
create_test(DEFAULT intersection relative_other)
create_test(DEFAULT intersection skipped_end)
create_test(DEFAULT is_absolute absolute)
create_test(DEFAULT is_absolute unc)
create_test(DEFAULT is_absolute device_unc)
create_test(DEFAULT is_absolute device_dot)
create_test(DEFAULT is_absolute device_question_mark)
create_test(DEFAULT is_absolute relative)
create_test(DEFAULT is_absolute windows_backslash)
create_test(DEFAULT is_absolute windows_slash)
create_test(DEFAULT is_absolute unix_backslash)
create_test(DEFAULT is_absolute unix_drive)
create_test(DEFAULT is_absolute absolute_drive)
create_test(DEFAULT is_absolute relative_drive)
create_test(DEFAULT is_absolute relative_windows)
create_test(DEFAULT is_relative absolute)
create_test(DEFAULT is_relative unc)
create_test(DEFAULT is_relative device_unc)
create_test(DEFAULT is_relative device_dot)
create_test(DEFAULT is_relative device_question_mark)
create_test(DEFAULT is_relative relative)
create_test(DEFAULT is_relative windows_backslash)
create_test(DEFAULT is_relative windows_slash)
create_test(DEFAULT is_relative unix_backslash)
create_test(DEFAULT is_relative unix_drive)
create_test(DEFAULT is_relative absolute_drive)
create_test(DEFAULT is_relative relative_drive)
create_test(DEFAULT is_relative relative_windows)
create_test(DEFAULT join simple)
create_test(DEFAULT join navigate_back)
create_test(DEFAULT join empty)
create_test(DEFAULT join two_absolute)
create_test(DEFAULT join two_unc)
create_test(DEFAULT join with_two_roots)
create_test(DEFAULT join back_after_root)
create_test(DEFAULT join relative_back_after_root)
create_test(DEFAULT join multiple)
create_test(DEFAULT normalize do_nothing)
create_test(DEFAULT normalize navigate_back)
create_test(DEFAULT normalize relative_too_far)
create_test(DEFAULT normalize absolute_too_far)
create_test(DEFAULT normalize terminated)
create_test(DEFAULT normalize double_separator)
create_test(DEFAULT normalize remove_current)
create_test(DEFAULT normalize mixed)
create_test(DEFAULT normalize overlap)
create_test(DEFAULT normalize empty)
create_test(DEFAULT normalize only_separators)
create_test(DEFAULT normalize back_after_root)
create_test(DEFAULT relative simple)
create_test(DEFAULT relative relative)
create_test(DEFAULT relative long_base)
create_test(DEFAULT relative long_target)
create_test(DEFAULT relative equal)
create_test(DEFAULT relative base_skipped_end)
create_test(DEFAULT relative target_skipped_end)
create_test(DEFAULT relative base_div_skipped_end)
create_test(DEFAULT relative target_div_skipped_end)
create_test(DEFAULT relative skip_all)
create_test(DEFAULT relative different_roots)
create_test(DEFAULT relative check)
create_test(DEFAULT root absolute)
create_test(DEFAULT root unc)
create_test(DEFAULT root device_unc)
create_test(DEFAULT root device_dot)
create_test(DEFAULT root device_question_mark)
create_test(DEFAULT root relative)
create_test(DEFAULT root windows_backslash)
create_test(DEFAULT root windows_slash)
create_test(DEFAULT root unix_backslash)
create_test(DEFAULT root unix_drive)
create_test(DEFAULT root absolute_drive)
create_test(DEFAULT root relative_drive)
create_test(DEFAULT root relative_windows)
create_test(DEFAULT root change_simple)
create_test(DEFAULT root change_empty)
create_test(DEFAULT root change_separators)
create_test(DEFAULT root change_overlapping)
create_test(DEFAULT root change_without_root)
create_test(DEFAULT segment first)
create_test(DEFAULT segment last)
create_test(DEFAULT segment next)
create_test(DEFAULT segment next_too_far)
create_test(DEFAULT segment previous_absolute)
create_test(DEFAULT segment previous_relative)
create_test(DEFAULT segment previous_absolute_one_char_first)
create_test(DEFAULT segment previous_relative_one_char_first)
create_test(DEFAULT segment previous_too_far)
create_test(DEFAULT segment previous_too_far_root)
create_test(DEFAULT segment type)
create_test(DEFAULT segment back_with_root)
create_test(DEFAULT segment change_simple)
create_test(DEFAULT segment change_first)
create_test(DEFAULT segment change_last)
create_test(DEFAULT segment change_trim)
create_test(DEFAULT segment change_empty)
create_test(DEFAULT segment change_with_separator)
create_test(DEFAULT segment change_overlap)
create_test(DEFAULT windows change_style)
create_test(DEFAULT windows get_root)
create_test(DEFAULT windows get_unc_root)
create_test(DEFAULT windows get_root_separator)
create_test(DEFAULT windows get_root_relative)
create_test(DEFAULT windows intersection_case)
create_test(DEFAULT windows root_backslash)
create_test(DEFAULT windows root_empty)
create_test_list(DEFAULT "${TEST_DIRECTORY}/tests.h")
add_executable(${TEST_TARGET}
"${TEST_DIRECTORY}/main.c"
"${TEST_DIRECTORY}/absolute_test.c"
"${TEST_DIRECTORY}/basename_test.c"
"${TEST_DIRECTORY}/dirname_test.c"
"${TEST_DIRECTORY}/extension_test.c"
"${TEST_DIRECTORY}/guess_test.c"
"${TEST_DIRECTORY}/intersection_test.c"
"${TEST_DIRECTORY}/is_absolute_test.c"
"${TEST_DIRECTORY}/is_relative_test.c"
"${TEST_DIRECTORY}/join_test.c"
"${TEST_DIRECTORY}/normalize_test.c"
"${TEST_DIRECTORY}/relative_test.c"
"${TEST_DIRECTORY}/root_test.c"
"${TEST_DIRECTORY}/segment_test.c"
"${TEST_DIRECTORY}/windows_test.c")
enable_warnings(${TEST_TARGET})
target_link_libraries(${TEST_TARGET} PUBLIC ${LIBRARY_TARGET})
target_include_directories(${TEST_TARGET} PUBLIC "${INCLUDE_DIRECTORY}")
endif()
install(TARGETS ${LIBRARY_TARGET}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include)
+139 -108
View File
@@ -6,8 +6,29 @@
#include <stdbool.h>
#include <stddef.h>
#if defined(_WIN32) || defined(__CYGWIN__)
#define CWK_EXPORT __declspec(dllexport)
#define CWK_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
#define CWK_EXPORT __attribute__((visibility("default")))
#define CWK_IMPORT __attribute__((visibility("default")))
#else
#define CWK_EXPORT
#define CWK_IMPORT
#endif
#if defined(CWK_SHARED)
#if defined(CWK_EXPORTS)
#define CWK_PUBLIC CWK_EXPORT
#else
#define CWK_PUBLIC CWK_IMPORT
#endif
#else
#define CWK_PUBLIC
#endif
#ifdef __cplusplus
extern "C"
extern "C"
{
#endif
@@ -55,41 +76,43 @@ enum cwk_path_style
*
* This function generates an absolute path based on a base path and another
* path. It is guaranteed to return an absolute path. If the second submitted
* path is absolute, it will override the base path. The result will be written
* to a buffer, which might be truncated if the buffer is not large enough to
* hold the full path. However, the truncated result will always be
* path is absolute, it will override the base path. The result will be
* written to a buffer, which might be truncated if the buffer is not large
* enough to hold the full path. However, the truncated result will always be
* null-terminated. The returned value is the amount of characters which the
* resulting path would take if it was not truncated (excluding the
* null-terminating character).
*
* @param base The absolute base path on which the relative path will be applied.
* @param base The absolute base path on which the relative path will be
* applied.
* @param path The relative path which will be applied on the base path.
* @param buffer The buffer where the result will be written to.
* @param buffer_size The size of the result buffer.
* @return Returns the total amount of characters of the new absolute path.
*/
size_t cwk_path_get_absolute(const char *base, const char *path, char *buffer,
size_t buffer_size);
CWK_PUBLIC size_t cwk_path_get_absolute(const char *base, const char *path,
char *buffer, size_t buffer_size);
/**
* @brief Generates a relative path based on a base.
*
* This function generates a relative path based on a base path and another
* path. It determines how to get to the submitted path, starting from the base
* directory. The result will be written to a buffer, which might be truncated
* if the buffer is not large enough to hold the full path. However, the
* truncated result will always be null-terminated. The returned value is the
* amount of characters which the resulting path would take if it was not
* path. It determines how to get to the submitted path, starting from the
* base directory. The result will be written to a buffer, which might be
* truncated if the buffer is not large enough to hold the full path. However,
* the truncated result will always be null-terminated. The returned value is
* the amount of characters which the resulting path would take if it was not
* truncated (excluding the null-terminating character).
*
* @param base_directory The base path from which the relative path will start.
* @param base_directory The base path from which the relative path will
* start.
* @param path The target path where the relative path will point to.
* @param buffer The buffer where the result will be written to.
* @param buffer_size The size of the result buffer.
* @return Returns the total amount of characters of the full path.
*/
size_t cwk_path_get_relative(const char *base_directory, const char *path,
char *buffer, size_t buffer_size);
CWK_PUBLIC size_t cwk_path_get_relative(const char *base_directory,
const char *path, char *buffer, size_t buffer_size);
/**
* @brief Joins two paths together.
@@ -98,9 +121,10 @@ size_t cwk_path_get_relative(const char *base_directory, const char *path,
* will remove double separators, and unlike cwk_path_get_absolute it permits
* the use of two relative paths to combine. The result will be written to a
* buffer, which might be truncated if the buffer is not large enough to hold
* the full path. However, the truncated result will always be null-terminated.
* The returned value is the amount of characters which the resulting path would
* take if it was not truncated (excluding the null-terminating character).
* the full path. However, the truncated result will always be
* null-terminated. The returned value is the amount of characters which the
* resulting path would take if it was not truncated (excluding the
* null-terminating character).
*
* @param path_a The first path which comes first.
* @param path_b The second path which comes after the first.
@@ -108,40 +132,41 @@ size_t cwk_path_get_relative(const char *base_directory, const char *path,
* @param buffer_size The size of the result buffer.
* @return Returns the total amount of characters of the full, combined path.
*/
size_t cwk_path_join(const char *path_a, const char *path_b, char *buffer,
size_t buffer_size);
CWK_PUBLIC size_t cwk_path_join(const char *path_a, const char *path_b,
char *buffer, size_t buffer_size);
/**
* @brief Joins multiple paths together.
*
* This function generates a new path by joining multiple paths together. It
* will remove double separators, and unlike cwk_path_get_absolute it permits
* the use of multiple relative paths to combine. The last path of the submitted
* string array must be set to NULL. The result will be written to a buffer,
* which might be truncated if the buffer is not large enough to hold the full
* path. However, the truncated result will always be null-terminated. The
* returned value is the amount of characters which the resulting path would
* take if it was not truncated (excluding the null-terminating character).
* the use of multiple relative paths to combine. The last path of the
* submitted string array must be set to NULL. The result will be written to a
* buffer, which might be truncated if the buffer is not large enough to hold
* the full path. However, the truncated result will always be
* null-terminated. The returned value is the amount of characters which the
* resulting path would take if it was not truncated (excluding the
* null-terminating character).
*
* @param paths An array of paths which will be joined.
* @param buffer The buffer where the result will be written to.
* @param buffer_size The size of the result buffer.
* @return Returns the total amount of characters of the full, combined path.
*/
size_t cwk_path_join_multiple(const char **paths, char *buffer,
CWK_PUBLIC size_t cwk_path_join_multiple(const char **paths, char *buffer,
size_t buffer_size);
/**
* @brief Determines the root of a path.
*
* This function determines the root of a path by finding it's length. The root
* always starts at the submitted path. If the path has no root, the length will
* be set to zero.
* This function determines the root of a path by finding it's length. The
* root always starts at the submitted path. If the path has no root, the
* length will be set to zero.
*
* @param path The path which will be inspected.
* @param length The output of the root length.
*/
void cwk_path_get_root(const char *path, size_t *length);
CWK_PUBLIC void cwk_path_get_root(const char *path, size_t *length);
/**
* @brief Changes the root of a path.
@@ -156,11 +181,11 @@ void cwk_path_get_root(const char *path, size_t *length);
* @param path The original path which will get a new root.
* @param new_root The new root which will be placed in the path.
* @param buffer The output buffer where the result is written to.
* @param buffer_size The size of the output buffer where the result is written
* to.
* @param buffer_size The size of the output buffer where the result is
* written to.
* @return Returns the total amount of characters of the new path.
*/
size_t cwk_path_change_root(const char *path, const char *new_root,
CWK_PUBLIC size_t cwk_path_change_root(const char *path, const char *new_root,
char *buffer, size_t buffer_size);
/**
@@ -172,7 +197,7 @@ size_t cwk_path_change_root(const char *path, const char *new_root,
* @param path The path which will be checked.
* @return Returns true if the path is absolute or false otherwise.
*/
bool cwk_path_is_absolute(const char *path);
CWK_PUBLIC bool cwk_path_is_absolute(const char *path);
/**
* @brief Determine whether the path is relative or not.
@@ -183,74 +208,75 @@ bool cwk_path_is_absolute(const char *path);
* @param path The path which will be checked.
* @return Returns true if the path is relative or false otherwise.
*/
bool cwk_path_is_relative(const char *path);
CWK_PUBLIC bool cwk_path_is_relative(const char *path);
/**
* @brief Gets the basename of a file path.
*
* This function gets the basename of a file path. A pointer to the beginning of
* the basename will be returned through the basename parameter. This pointer
* will be positioned on the first letter after the separator. The length of the
* file path will be returned through the length parameter. The length will be
* set to zero and the basename to NULL if there is no basename available.
* This function gets the basename of a file path. A pointer to the beginning
* of the basename will be returned through the basename parameter. This
* pointer will be positioned on the first letter after the separator. The
* length of the file path will be returned through the length parameter. The
* length will be set to zero and the basename to NULL if there is no basename
* available.
*
* @param path The path which will be inspected.
* @param basename The output of the basename pointer.
* @param length The output of the length of the basename.
*/
void cwk_path_get_basename(const char *path, const char **basename,
CWK_PUBLIC void cwk_path_get_basename(const char *path, const char **basename,
size_t *length);
/**
* @brief Changes the basename of a file path.
*
* This function changes the basename of a file path. This function will not
* write out more than the specified buffer can contain. However, the generated
* string is always null-terminated - even if not the whole path is written out.
* The function returns the total number of characters the complete buffer would
* have, even if it was not written out completely. The path may be the same
* memory address as the buffer.
* write out more than the specified buffer can contain. However, the
* generated string is always null-terminated - even if not the whole path is
* written out. The function returns the total number of characters the
* complete buffer would have, even if it was not written out completely. The
* path may be the same memory address as the buffer.
*
* @param path The original path which will be used for the modified path.
* @param new_basename The new basename which will replace the old one.
* @param buffer The buffer where the changed path will be written to.
* @param buffer_size The size of the result buffer where the changed path is
* written to.
* @return Returns the size which the complete new path would have if it was not
* truncated.
* @return Returns the size which the complete new path would have if it was
* not truncated.
*/
size_t cwk_path_change_basename(const char *path, const char *new_basename,
char *buffer, size_t buffer_size);
CWK_PUBLIC size_t cwk_path_change_basename(const char *path,
const char *new_basename, char *buffer, size_t buffer_size);
/**
* @brief Gets the dirname of a file path.
*
* This function determines the dirname of a file path and returns the length up
* to which character is considered to be part of it. If no dirname is found,
* the length will be set to zero. The beginning of the dirname is always equal
* to the submitted path pointer.
* This function determines the dirname of a file path and returns the length
* up to which character is considered to be part of it. If no dirname is
* found, the length will be set to zero. The beginning of the dirname is
* always equal to the submitted path pointer.
*
* @param path The path which will be inspected.
* @param length The length of the dirname.
*/
void cwk_path_get_dirname(const char *path, size_t *length);
CWK_PUBLIC void cwk_path_get_dirname(const char *path, size_t *length);
/**
* @brief Gets the extension of a file path.
*
* This function extracts the extension portion of a file path. A pointer to
* the beginning of the extension will be returned through the extension
* parameter if an extension is found and true is returned. This pointer will be
* positioned on the dot. The length of the extension name will be returned
* through the length parameter. If no extension is found both parameters won't
* be touched and false will be returned.
* parameter if an extension is found and true is returned. This pointer will
* be positioned on the dot. The length of the extension name will be returned
* through the length parameter. If no extension is found both parameters
* won't be touched and false will be returned.
*
* @param path The path which will be inspected.
* @param extension The output of the extension pointer.
* @param length The output of the length of the extension.
* @return Returns true if an extension is found or false otherwise.
*/
bool cwk_path_get_extension(const char *path, const char **extension,
CWK_PUBLIC bool cwk_path_get_extension(const char *path, const char **extension,
size_t *length);
/**
@@ -262,30 +288,31 @@ bool cwk_path_get_extension(const char *path, const char **extension,
* @param path The path which will be inspected.
* @return Returns true if the path has an extension or false otherwise.
*/
bool cwk_path_has_extension(const char *path);
CWK_PUBLIC bool cwk_path_has_extension(const char *path);
/**
* @brief Changes the extension of a file path.
*
* This function changes the extension of a file name. The function will append
* an extension if the basename does not have an extension, or use the extension
* as a basename if the path does not have a basename. This function will not
* write out more than the specified buffer can contain. However, the generated
* string is always null-terminated - even if not the whole path is written out.
* The function returns the total number of characters the complete buffer would
* have, even if it was not written out completely. The path may be the same
* memory address as the buffer.
* This function changes the extension of a file name. The function will
* append an extension if the basename does not have an extension, or use the
* extension as a basename if the path does not have a basename. This function
* will not write out more than the specified buffer can contain. However, the
* generated string is always null-terminated - even if not the whole path is
* written out. The function returns the total number of characters the
* complete buffer would have, even if it was not written out completely. The
* path may be the same memory address as the buffer.
*
* @param path The path which will be used to make the change.
* @param new_extension The extension which will be placed within the new path.
* @param new_extension The extension which will be placed within the new
* path.
* @param buffer The output buffer where the result will be written to.
* @param buffer_size The size of the output buffer where the result will be
* written to.
* @return Returns the total size which the output would have if it was not
* truncated.
*/
size_t cwk_path_change_extension(const char *path, const char *new_extension,
char *buffer, size_t buffer_size);
CWK_PUBLIC size_t cwk_path_change_extension(const char *path,
const char *new_extension, char *buffer, size_t buffer_size);
/**
* @brief Creates a normalized version of the path.
@@ -309,7 +336,8 @@ size_t cwk_path_change_extension(const char *path, const char *new_extension,
* @return The size which the complete normalized path has if it was not
* truncated.
*/
size_t cwk_path_normalize(const char *path, char *buffer, size_t buffer_size);
CWK_PUBLIC size_t cwk_path_normalize(const char *path, char *buffer,
size_t buffer_size);
/**
* @brief Finds common portions in two paths.
@@ -322,47 +350,50 @@ size_t cwk_path_normalize(const char *path, char *buffer, size_t buffer_size);
* @param path_other The other path which will compared with the base path.
* @return Returns the number of characters which are common in the base path.
*/
size_t cwk_path_get_intersection(const char *path_base, const char *path_other);
CWK_PUBLIC size_t cwk_path_get_intersection(const char *path_base,
const char *path_other);
/**
* @brief Gets the first segment of a path.
*
* This function finds the first segment of a path. The position of the segment
* is set to the first character after the separator, and the length counts all
* characters until the next separator (excluding the separator).
* This function finds the first segment of a path. The position of the
* segment is set to the first character after the separator, and the length
* counts all characters until the next separator (excluding the separator).
*
* @param path The path which will be inspected.
* @param segment The segment which will be extracted.
* @return Returns true if there is a segment or false if there is none.
*/
bool cwk_path_get_first_segment(const char *path, struct cwk_segment *segment);
CWK_PUBLIC bool cwk_path_get_first_segment(const char *path,
struct cwk_segment *segment);
/**
* @brief Gets the last segment of the path.
*
* This function gets the last segment of a path. This function may return false
* if the path doesn't contain any segments, in which case the submitted segment
* parameter is not modified. The position of the segment is set to the first
* character after the separator, and the length counts all characters until the
* end of the path (excluding the separator).
* This function gets the last segment of a path. This function may return
* false if the path doesn't contain any segments, in which case the submitted
* segment parameter is not modified. The position of the segment is set to
* the first character after the separator, and the length counts all
* characters until the end of the path (excluding the separator).
*
* @param path The path which will be inspected.
* @param segment The segment which will be extracted.
* @return Returns true if there is a segment or false if there is none.
*/
bool cwk_path_get_last_segment(const char *path, struct cwk_segment *segment);
CWK_PUBLIC bool cwk_path_get_last_segment(const char *path,
struct cwk_segment *segment);
/**
* @brief Advances to the next segment.
*
* This function advances the current segment to the next segment. If there are
* no more segments left, the submitted segment structure will stay unchanged
* and false is returned.
* This function advances the current segment to the next segment. If there
* are no more segments left, the submitted segment structure will stay
* unchanged and false is returned.
*
* @param segment The current segment which will be advanced to the next one.
* @return Returns true if another segment was found or false otherwise.
*/
bool cwk_path_get_next_segment(struct cwk_segment *segment);
CWK_PUBLIC bool cwk_path_get_next_segment(struct cwk_segment *segment);
/**
* @brief Moves to the previous segment.
@@ -375,31 +406,31 @@ bool cwk_path_get_next_segment(struct cwk_segment *segment);
* @return Returns true if there is a segment before this one or false
* otherwise.
*/
bool cwk_path_get_previous_segment(struct cwk_segment *segment);
CWK_PUBLIC bool cwk_path_get_previous_segment(struct cwk_segment *segment);
/**
* @brief Gets the type of the submitted path segment.
*
* This function inspects the contents of the segment and determines the type of
* it. Currently, there are three types CWK_NORMAL, CWK_CURRENT and CWK_BACK. A
* CWK_NORMAL segment is a normal folder or file entry. A CWK_CURRENT is a "./"
* and a CWK_BACK a "../" segment.
* This function inspects the contents of the segment and determines the type
* of it. Currently, there are three types CWK_NORMAL, CWK_CURRENT and
* CWK_BACK. A CWK_NORMAL segment is a normal folder or file entry. A
* CWK_CURRENT is a "./" and a CWK_BACK a "../" segment.
*
* @param segment The segment which will be inspected.
* @return Returns the type of the segment.
*/
enum cwk_segment_type cwk_path_get_segment_type(
CWK_PUBLIC enum cwk_segment_type cwk_path_get_segment_type(
const struct cwk_segment *segment);
/**
* @brief Changes the content of a segment.
*
* This function overrides the content of a segment to the submitted value and
* outputs the whole new path to the submitted buffer. The result might require
* less or more space than before if the new value length differs from the
* original length. The output is truncated if the new path is larger than the
* submitted buffer size, but it is always null-terminated. The source of the
* segment and the submitted buffer may be the same.
* outputs the whole new path to the submitted buffer. The result might
* require less or more space than before if the new value length differs from
* the original length. The output is truncated if the new path is larger than
* the submitted buffer size, but it is always null-terminated. The source of
* the segment and the submitted buffer may be the same.
*
* @param segment The segment which will be modifier.
* @param value The new content of the segment.
@@ -408,8 +439,8 @@ enum cwk_segment_type cwk_path_get_segment_type(
* @return Returns the total size which would have been written if the output
* was not truncated.
*/
size_t cwk_path_change_segment(struct cwk_segment *segment, const char *value,
char *buffer, size_t buffer_size);
CWK_PUBLIC size_t cwk_path_change_segment(struct cwk_segment *segment,
const char *value, char *buffer, size_t buffer_size);
/**
* @brief Checks whether the submitted pointer points to a separator.
@@ -422,19 +453,19 @@ size_t cwk_path_change_segment(struct cwk_segment *segment, const char *value,
* @param symbol A pointer to a string.
* @return Returns true if it is a separator, or false otherwise.
*/
bool cwk_path_is_separator(const char *str);
CWK_PUBLIC bool cwk_path_is_separator(const char *str);
/**
* @brief Guesses the path style.
*
* This function guesses the path style based on a submitted path-string. The
* guessing will look at the root and the type of slashes contained in the path
* and return the style which is more likely used in the path.
* guessing will look at the root and the type of slashes contained in the
* path and return the style which is more likely used in the path.
*
* @param path The path which will be inspected.
* @return Returns the style which is most likely used for the path.
*/
enum cwk_path_style cwk_path_guess_style(const char *path);
CWK_PUBLIC enum cwk_path_style cwk_path_guess_style(const char *path);
/**
* @brief Configures which path style is used.
@@ -447,7 +478,7 @@ enum cwk_path_style cwk_path_guess_style(const char *path);
*
* @param style The style which will be used from now on.
*/
void cwk_path_set_style(enum cwk_path_style style);
CWK_PUBLIC void cwk_path_set_style(enum cwk_path_style style);
/**
* @brief Gets the path style configuration.
@@ -457,7 +488,7 @@ void cwk_path_set_style(enum cwk_path_style style);
*
* @return Returns the current path style configuration.
*/
enum cwk_path_style cwk_path_get_style(void);
CWK_PUBLIC enum cwk_path_style cwk_path_get_style(void);
#ifdef __cplusplus
} // extern "C"