diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a44c7c8f4..de3d7466a 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -30,222 +30,99 @@ endif () message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION} (shared libs: ${BUILD_SHARED_LIBS})") -# Make sure windows shared library exports symbols for Scala FFI bindings +# Common configurations set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - -# Get verbose output from the makefile (useful for debugging the build) set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON") - -# Use C++17 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) -list(APPEND CMAKE_MODULE_PATH "cmake") -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -# GCC needs to pass the -lstdc++fs flag to link C++17 filesystem implementation. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT MINGW) set(FILESYSTEM_LIB stdc++fs) endif () -####################################################################################################################### -# DEPENDENCIES -####################################################################################################################### -if(BUILD_TESTS) +# Dependencies +if (BUILD_TESTS) include(FetchContent) - # Fetch the Catch2 unit testing framework, build it, and make it available to the project FetchContent_Declare( Catch2 - GIT_SHALLOW TRUE + GIT_SHALLOW TRUE GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0) - message(STATUS "Fetching, building, and making Catch2 available to the project") + GIT_TAG v3.4.0) FetchContent_MakeAvailable(Catch2) list(APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/extras") -endif() - -####################################################################################################################### -# CORE LIBRARY -####################################################################################################################### -# Define the library source files -set(OMEGA_EDIT_SOURCE_FILES - "src/include/omega_edit.h" - "src/include/omega_edit/config.h" - "src/include/omega_edit/export.h" - "src/include/omega_edit/fwd_defs.h" - "src/include/omega_edit/byte.h" - "src/include/omega_edit/scoped_ptr.hpp" - "src/include/omega_edit/stl_string_adaptor.hpp" "src/lib/stl_string_adapter.cpp" - "src/include/omega_edit/change.h" "src/lib/change.cpp" "src/lib/impl_/change_def.hpp" - "src/include/omega_edit/character_counts.h" "src/lib/character_counts.c" "src/lib/impl_/character_counts_def.h" - "src/include/omega_edit/check.h" "src/lib/check.cpp" - "src/include/omega_edit/edit.h" "src/lib/edit.cpp" - "src/include/omega_edit/search.h" "src/lib/search.cpp" "src/lib/impl_/search_context_def.h" - "src/include/omega_edit/segment.h" "src/lib/segment.cpp" "src/lib/impl_/segment_def.hpp" - "src/include/omega_edit/version.h" "src/lib/version.c" - "src/include/omega_edit/visit.h" "src/lib/visit.cpp" - "src/include/omega_edit/session.h" "src/lib/session.cpp" "src/lib/impl_/session_def.hpp" - "src/include/omega_edit/viewport.h" "src/lib/viewport.cpp" "src/lib/impl_/viewport_def.hpp" - "src/include/omega_edit/license.h" "src/lib/license.c" - "src/include/omega_edit/utility.h" "src/lib/utility.c" - "src/include/omega_edit/encode.h" "src/lib/encode.c" - "src/include/omega_edit/filesystem.h" "src/lib/filesystem.cpp" - "src/lib/impl_/macros.h" "src/lib/impl_/internal_fwd_defs.hpp" - "src/lib/impl_/internal_fun.hpp" "src/lib/impl_/internal_fun.cpp" - "src/lib/impl_/find.h" "src/lib/impl_/find.cpp" - "src/lib/impl_/data_def.hpp" "src/lib/impl_/model_def.hpp" "src/lib/impl_/model_segment_def.hpp") - -# Don't add RPATH so we can manipulate the library search path using the environment at runtime -set(CMAKE_MACOSX_RPATH OFF) +endif () -# Create the library +# Core library configuration +file(GLOB_RECURSE OMEGA_EDIT_SOURCE_FILES "src/include/*.h" "src/include/*.hpp" "src/lib/*.c" "src/lib/*.cpp") add_library(omega_edit ${OMEGA_EDIT_SOURCE_FILES}) add_library(omega_edit::omega_edit ALIAS omega_edit) -set_target_properties(omega_edit PROPERTIES VERSION ${omega_edit_VERSION} SOVERSION ${omega_edit_VERSION_MAJOR}) +set_target_properties(omega_edit PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) target_include_directories(omega_edit PUBLIC "$") target_compile_definitions(omega_edit PUBLIC "$<$>:OMEGA_EDIT_STATIC_DEFINE>") target_link_libraries(omega_edit PRIVATE ${FILESYSTEM_LIB}) -## Include the install rules if the user wants them (included by default when top-level) +# Packaging rules string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level) option(omega_edit_INCLUDE_PACKAGING "Include packaging rules for OmegaEdit" "${is_top_level}") if (omega_edit_INCLUDE_PACKAGING) - message(STATUS "Including packaging") add_subdirectory(packaging) endif () -# Parse version information +# Version definitions string(TOUPPER "${PROJECT_NAME}" PREFIX) - -# Send version information into libomega_edit through macro definitions foreach (level MAJOR MINOR PATCH) target_compile_definitions(omega_edit PRIVATE "${PREFIX}_VERSION_${level}=${${PROJECT_NAME}_VERSION_${level}}") endforeach () -####################################################################################################################### -# EXAMPLES -####################################################################################################################### +# Examples if (BUILD_EXAMPLES) - add_executable(add_bom "src/examples/add_bom.cpp") - target_link_libraries(add_bom PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(count_characters "src/examples/count_characters.c") - target_link_libraries(count_characters PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(detect_bom "src/examples/detect_bom.c") - target_link_libraries(detect_bom PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(replace "src/examples/replace.cpp") - target_link_libraries(replace PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(rotate "src/examples/rotate.cpp") - target_link_libraries(rotate PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(slice "src/examples/slice.cpp") - target_link_libraries(slice PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(peek "src/examples/peek.cpp") - target_link_libraries(peek PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(search "src/examples/search.cpp") - target_link_libraries(search PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(simple "src/examples/simple.cpp") - target_link_libraries(simple PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(simple_c "src/examples/simple_c.c") - target_link_libraries(simple_c PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(replay "src/examples/replay.cpp") - target_link_libraries(replay PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(transform "src/examples/transform.c") - target_link_libraries(transform PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(profile "src/examples/profile.c") - target_link_libraries(profile PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - - add_executable(play "src/examples/play.cpp") - target_link_libraries(play PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - add_custom_command(TARGET play POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/examples/data" "$/data/examples" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + file(GLOB_RECURSE EXAMPLES_SRC "src/examples/*.c" "src/examples/*.cpp") + foreach (example_src ${EXAMPLES_SRC}) + get_filename_component(example_name ${example_src} NAME_WE) + add_executable(${example_name} ${example_src}) + target_link_libraries(${example_name} PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) + endforeach () endif () -####################################################################################################################### -# TESTING -####################################################################################################################### +# Tests if (BUILD_TESTS) enable_testing() - - if (MSVC) - set(CTEST_CONFIGURATION_TYPE "${JOB_BUILD_CONFIGURATION}") - endif () - add_executable(omega_test "src/tests/omega_test.cpp" "src/tests/test_util.h") target_link_libraries(omega_test PRIVATE omega_edit::omega_edit Catch2::Catch2WithMain ${FILESYSTEM_LIB}) - add_custom_command(TARGET omega_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/data" "$/data" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") - - add_executable(generate_file "src/tests/generate_file.cpp" "src/tests/test_util.h") - target_link_libraries(generate_file PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB}) - + add_custom_command(TARGET omega_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/data" "$/data") include(CTest) include(Catch) catch_discover_tests(omega_test WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") - find_program(VALGRIND "valgrind") if (VALGRIND) - add_custom_target(valgrind - COMMAND ${VALGRIND} --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt $ - COMMENT "Running tests under valgrind" - DEPENDS omega_test) - endif() + add_custom_target(valgrind COMMAND ${VALGRIND} --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt $ COMMENT "Running tests under valgrind" DEPENDS omega_test) + endif () endif () -####################################################################################################################### -# DOCUMENTATION -####################################################################################################################### +# Documentation if (BUILD_DOCS) - # Generate API documentation using Doxygen - find_package(Doxygen COMPONENTS dot) + find_package(Doxygen) if (DOXYGEN_FOUND) - message(STATUS "API documentation generation enabled") - set(DOXYGEN_GENERATE_HTML YES) - set(DOXYGEN_GENERATE_MAN YES) set(DOXYGEN_GENERATE_XML YES) - set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES) - set(DOXYGEN_EXTRACT_ALL YES) - set(DOXYGEN_INDEX_DIR "${CMAKE_CURRENT_BINARY_DIR}/docs/xml") - set(DOXYGEN_INDEX_FILE "${DOXYGEN_INDEX_DIR}/index.xml") set(DOXYGEN_OUTPUT_DIRECTORY docs) - doxygen_add_docs(docs "src/include" ALL COMMENT "Generate doxygen docs") - # Add the cmake folder so the FindSphinx module is found - set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}") - find_package(Sphinx REQUIRED) + set(DOXYGEN_INDEX_DIR "${CMAKE_CURRENT_BINARY_DIR}/docs/xml") + doxygen_add_docs(docs "src/include" ALL) + find_package(Sphinx) if (SPHINX_FOUND) - # Generate user documentation using Sphinx - message(STATUS "User documentation generation enabled") set(SPHINX_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/sphinx") set(SPHINX_BUILD "${CMAKE_CURRENT_BINARY_DIR}/docs/sphinx") - set(SPHINX_INDEX_FILE "${SPHINX_BUILD}/index.html") - add_custom_command(OUTPUT "${SPHINX_INDEX_FILE}" - COMMAND "${SPHINX_EXECUTABLE}" - ARGS -b html - # Tell Breathe where to find the Doxygen output + add_custom_target( + sphinx ALL + COMMAND "${SPHINX_EXECUTABLE}" -b html -Dbreathe_projects.omega_edit="${DOXYGEN_INDEX_DIR}" "${SPHINX_SOURCE}" "${SPHINX_BUILD}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - DEPENDS - # Other docs files you want to track should go here (or in some variable) - "${SPHINX_SOURCE}/index.rst" - MAIN_DEPENDENCY "${SPHINX_SOURCE}/conf.py" - COMMENT "Generating documentation with Sphinx") - # Nice named target so we can run the job easily - add_custom_target(sphinx ALL DEPENDS "${SPHINX_INDEX_FILE}") + COMMENT "Generating documentation with Sphinx" + ) add_dependencies(sphinx docs) include(GNUInstallDirs) install(DIRECTORY "${SPHINX_BUILD}" DESTINATION "${CMAKE_INSTALL_DOCDIR}") - else (SPHINX_FOUND) - message(STATUS "Sphinx need to be installed to generate user documentation") - endif (SPHINX_FOUND) - else (DOXYGEN_FOUND) - message(STATUS "Doxygen need to be installed to generate API documentation") - endif (DOXYGEN_FOUND) -endif (BUILD_DOCS) + endif () + endif () +endif () diff --git a/core/packaging/CMakeLists.txt b/core/packaging/CMakeLists.txt index 98ded40d1..92205f13b 100644 --- a/core/packaging/CMakeLists.txt +++ b/core/packaging/CMakeLists.txt @@ -8,49 +8,50 @@ # Unless required by applicable law or agreed to in writing, software is distributed under the License is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing permissions and limitations under the License. -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) + +include("GNUInstallDirs") +include("CMakePackageConfigHelpers") if (NOT DEFINED omega_edit_INSTALL_CMAKEDIR) - set(omega_edit_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/omega_edit" CACHE STRING "Path to omega_edit CMake files") -endif () + set(omega_edit_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/omega_edit" CACHE STRING "Path to omega_edit CMake files") +endif() install(TARGETS omega_edit EXPORT omega_edit_Targets RUNTIME COMPONENT omega_edit_Runtime LIBRARY COMPONENT omega_edit_Runtime NAMELINK_COMPONENT omega_edit_Development ARCHIVE COMPONENT omega_edit_Development INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(DIRECTORY "${omega_edit_SOURCE_DIR}/src/include/" TYPE INCLUDE COMPONENT omega_edit_Development) if (BUILD_SHARED_LIBS) - set(type shared) -else () - set(type static) -endif () + set(type "shared") +else() + set(type "static") +endif() -install(EXPORT omega_edit_Targets DESTINATION "${omega_edit_INSTALL_CMAKEDIR}" NAMESPACE omega_edit:: FILE "omega_edit-${type}-targets.cmake" COMPONENT omega_edit_Development) -write_basic_package_version_file(omega_editConfigVersion.cmake COMPATIBILITY SameMajorVersion) +install(EXPORT omega_edit_Targets DESTINATION "${omega_edit_INSTALL_CMAKEDIR}" NAMESPACE "omega_edit::" FILE "omega_edit-${type}-targets.cmake" COMPONENT omega_edit_Development) +write_basic_package_version_file("omega_editConfigVersion.cmake" COMPATIBILITY SameMajorVersion) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/omega_editConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/omega_editConfigVersion.cmake" DESTINATION "${omega_edit_INSTALL_CMAKEDIR}" COMPONENT omega_edit_Development) # see: https://www.scivision.dev/cmake-cpack-basic/ -set(_fmt TGZ) -if(WIN32) - set(_fmt ZIP) +set(_fmt "TGZ") +if (WIN32) + set(_fmt "ZIP") endif() -set(CPACK_GENERATOR ${_fmt}) -set(CPACK_SOURCE_GENERATOR ${_fmt}) +set(CPACK_GENERATOR "${_fmt}") +set(CPACK_SOURCE_GENERATOR "${_fmt}") set(CPACK_PACKAGE_VENDOR "Concurrent Technologies Corporation") set(CPACK_PACKAGE_CONTACT "omega.edit@ctc.com") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../LICENSE.txt") set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/../README.md") set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/package") -set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}) -string(TOLOWER ${CMAKE_SYSTEM_NAME} _sys) -string(TOLOWER ${PROJECT_NAME} _project_lower) +set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}") +string(TOLOWER "${CMAKE_SYSTEM_NAME}" _sys) +string(TOLOWER "${PROJECT_NAME}" _project_lower) set(CPACK_PACKAGE_FILE_NAME "${_project_lower}-${_sys}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${_project_lower}-${PROJECT_VERSION}") # not .gitignore as its regex syntax is distinct -file(READ ${CMAKE_CURRENT_LIST_DIR}/.cpack_ignore _cpack_ignore) -string(REGEX REPLACE "\n" ";" _cpack_ignore ${_cpack_ignore}) +file(READ "${CMAKE_CURRENT_LIST_DIR}/.cpack_ignore" _cpack_ignore) +string(REGEX REPLACE "\n" ";" _cpack_ignore "${_cpack_ignore}") set(CPACK_SOURCE_IGNORE_FILES "${_cpack_ignore}") -install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION "${CMAKE_INSTALL_DOCDIR}") +install(FILES "${CPACK_RESOURCE_FILE_README}" "${CPACK_RESOURCE_FILE_LICENSE}" DESTINATION "${CMAKE_INSTALL_DOCDIR}") -include(CPack) +include("CPack") diff --git a/core/packaging/omega_editConfig.cmake b/core/packaging/omega_editConfig.cmake index 47b8a8200..db9b4b597 100644 --- a/core/packaging/omega_editConfig.cmake +++ b/core/packaging/omega_editConfig.cmake @@ -8,6 +8,7 @@ # Unless required by applicable law or agreed to in writing, software is distributed under the License is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing permissions and limitations under the License. + cmake_minimum_required(VERSION 3.13) set(omega_edit_known_comps static shared) @@ -18,7 +19,7 @@ foreach (omega_edit_comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) set(omega_edit_comp_${omega_edit_comp} YES) else () set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE - "omega_edit does not recognize component `${omega_edit_comp}`.") + "omega_edit does not recognize component `${omega_edit_comp}`.") set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) return() endif () @@ -26,7 +27,7 @@ endforeach () if (omega_edit_comp_static AND omega_edit_comp_shared) set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE - "omega_edit `static` and `shared` components are mutually exclusive.") + "omega_edit `static` and `shared` components are mutually exclusive.") set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) return() endif () @@ -37,7 +38,7 @@ set(omega_edit_shared_targets "${CMAKE_CURRENT_LIST_DIR}/omega_edit-shared-targe macro(omega_edit_load_targets type) if (NOT EXISTS "${omega_edit_${type}_targets}") set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE - "omega_edit `${type}` libraries were requested but not found.") + "omega_edit `${type}` libraries were requested but not found.") set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) return() endif () diff --git a/core/sphinx/_static/OmegaEditLogo.png b/core/sphinx/_static/OmegaEditLogo.png new file mode 100644 index 000000000..1d1ba7790 Binary files /dev/null and b/core/sphinx/_static/OmegaEditLogo.png differ diff --git a/core/sphinx/conf.py b/core/sphinx/conf.py index e9a11c6f8..7db7b5834 100644 --- a/core/sphinx/conf.py +++ b/core/sphinx/conf.py @@ -38,7 +38,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -#... +# ... extensions = [ 'sphinx.ext.autodoc', @@ -55,7 +55,7 @@ 'breathe' ] -#... +# ... # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -75,7 +75,7 @@ html_theme = 'sphinx_rtd_theme' html_theme_options = { 'canonical_url': '', - 'analytics_id': '', # Provided by Google in your dashboard + 'analytics_id': '', # Provided by Google in your dashboard 'display_version': True, 'prev_next_buttons_location': 'bottom', 'style_external_links': False, @@ -95,5 +95,8 @@ # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] +# RTD Theme Options +html_logo="_static/OmegaEditLogo.png" + # Breathe Configuration -breathe_default_project = "omega_edit" \ No newline at end of file +breathe_default_project = "omega_edit" diff --git a/core/sphinx/index.rst b/core/sphinx/index.rst index c6002e218..6d367415a 100644 --- a/core/sphinx/index.rst +++ b/core/sphinx/index.rst @@ -10,10 +10,12 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing permissions and limitations under the License. -.. ΩEdit documentation master file +.. Ωedit™ documentation master file -Welcome to ΩEdit's documentation! -================================= +Welcome to Ωedit™'s API documentation! +====================================== + +For more information, please visit the `Ωedit™ Wiki `_. .. toctree:: :maxdepth: 2 @@ -46,17 +48,12 @@ edit.h .. doxygenfile:: edit.h encode.h ------------ +-------- .. doxygenfile:: encode.h -export.h ------------ - -.. doxygenfile:: export.h - filesystem.h ----------- +------------ .. doxygenfile:: filesystem.h diff --git a/core/src/examples/add_bom.cpp b/core/src/examples/add_bom.cpp index 027031161..9b65f8a93 100644 --- a/core/src/examples/add_bom.cpp +++ b/core/src/examples/add_bom.cpp @@ -12,8 +12,8 @@ * * **********************************************************************************************************************/ -#include #include +#include omega_bom_t string_to_BOM(const std::string_view &bom_str) { if (bom_str == "utf8") { @@ -57,9 +57,7 @@ int main(int argc, char **argv) { // Copy from stdin to stdout char buffer[4096]; - while (std::cin.read(buffer, sizeof(buffer))) { - std::cout.write(buffer, sizeof(buffer)); - } + while (std::cin.read(buffer, sizeof(buffer))) { std::cout.write(buffer, sizeof(buffer)); } std::cout.write(buffer, std::cin.gcount()); return 0; diff --git a/core/src/examples/count_characters.c b/core/src/examples/count_characters.c index 33d74f24b..cedafe990 100644 --- a/core/src/examples/count_characters.c +++ b/core/src/examples/count_characters.c @@ -14,10 +14,10 @@ #define __STDC_FORMAT_MACROS -#include +#include #include #include -#include +#include int main(int argc, char *argv[]) { if (argc < 2) { @@ -26,9 +26,11 @@ int main(int argc, char *argv[]) { } omega_session_t *session_ptr = omega_edit_create_session(argv[1], NULL, NULL, NO_EVENTS, NULL); omega_character_counts_t *character_counts_ptr = omega_character_counts_create(); - omega_session_character_counts(session_ptr, character_counts_ptr, 0, omega_session_get_computed_file_size(session_ptr)); + omega_session_character_counts(session_ptr, character_counts_ptr, 0, + omega_session_get_computed_file_size(session_ptr)); - printf("File: %s, BOM: %s\n", argv[1], omega_util_BOM_to_string(omega_character_counts_get_BOM(character_counts_ptr))); + printf("File: %s, BOM: %s\n", argv[1], + omega_util_BOM_to_string(omega_character_counts_get_BOM(character_counts_ptr))); printf(" Single-byte characters: %" PRId64 "\n", omega_character_counts_single_byte_chars(character_counts_ptr)); printf(" Double-byte characters: %" PRId64 "\n", omega_character_counts_double_byte_chars(character_counts_ptr)); printf(" Triple-byte characters: %" PRId64 "\n", omega_character_counts_triple_byte_chars(character_counts_ptr)); diff --git a/core/src/examples/detect_bom.c b/core/src/examples/detect_bom.c index 5ae06eefc..5b07e843f 100644 --- a/core/src/examples/detect_bom.c +++ b/core/src/examples/detect_bom.c @@ -12,8 +12,8 @@ * * **********************************************************************************************************************/ -#include #include +#include int main(int argc, char *argv[]) { if (argc < 2) { diff --git a/core/src/examples/peek.cpp b/core/src/examples/peek.cpp index 399e54da0..3ae5309d0 100644 --- a/core/src/examples/peek.cpp +++ b/core/src/examples/peek.cpp @@ -20,9 +20,7 @@ using namespace std; -enum class display_mode_t { - BIT_MODE, BYTE_MODE, CHAR_MODE -}; +enum class display_mode_t { BIT_MODE, BYTE_MODE, CHAR_MODE }; struct view_mode_t { display_mode_t display_mode = display_mode_t::BYTE_MODE; }; diff --git a/core/src/examples/play.cpp b/core/src/examples/play.cpp index 425f36540..eeaa62867 100644 --- a/core/src/examples/play.cpp +++ b/core/src/examples/play.cpp @@ -96,9 +96,7 @@ void session_change_cbk(const omega_session_t *session_ptr, omega_session_event_ } } -enum class display_mode_t { - BIT_MODE, BYTE_MODE, CHAR_MODE -}; +enum class display_mode_t { BIT_MODE, BYTE_MODE, CHAR_MODE }; struct view_mode_t { display_mode_t display_mode = display_mode_t::CHAR_MODE; }; @@ -146,7 +144,7 @@ void vpt_change_cbk(const omega_viewport_t *viewport_ptr, << " offset: " << omega_viewport_get_offset(viewport_ptr) << endl; if (omega_viewport_get_user_data_ptr(viewport_ptr)) { switch (reinterpret_cast(omega_viewport_get_user_data_ptr(viewport_ptr)) - ->display_mode) { + ->display_mode) { case display_mode_t::BIT_MODE: clog << " BIT MODE ["; write_pretty_bits(omega_viewport_get_data(viewport_ptr), diff --git a/core/src/examples/search.cpp b/core/src/examples/search.cpp index 41bfb9d30..fb8b8b03f 100644 --- a/core/src/examples/search.cpp +++ b/core/src/examples/search.cpp @@ -31,9 +31,8 @@ int main(int argc, char **argv) { const auto reverse_search = stoi(argv[6]); if (auto session_ptr = omega_edit_create_session(in_filename, nullptr, nullptr, NO_EVENTS, nullptr)) { int num_matches = 0; - auto search_context = - omega_search_create_context(session_ptr, pattern, 0, start_offset, length, case_insensitive, - reverse_search); + auto search_context = omega_search_create_context(session_ptr, pattern, 0, start_offset, length, + case_insensitive, reverse_search); while (omega_search_next_match(search_context, 1)) { const auto match_offset = omega_search_context_get_match_offset(search_context); const auto match_length = omega_search_context_get_pattern_length(search_context); diff --git a/core/src/examples/simple.cpp b/core/src/examples/simple.cpp index aa35ebc8e..4df75ea21 100644 --- a/core/src/examples/simple.cpp +++ b/core/src/examples/simple.cpp @@ -23,9 +23,9 @@ inline void vpt_change_cbk(const omega_viewport_t *viewport_ptr, omega_viewport_ case VIEWPORT_EVT_CREATE: case VIEWPORT_EVT_EDIT: { char change_kind = (viewport_event_ptr) - ? omega_change_get_kind_as_char( - reinterpret_cast(viewport_event_ptr)) - : 'R'; + ? omega_change_get_kind_as_char( + reinterpret_cast(viewport_event_ptr)) + : 'R'; clog << change_kind << ": [" << omega_viewport_get_string(viewport_ptr) << "]" << endl; break; } diff --git a/core/src/examples/simple_c.c b/core/src/examples/simple_c.c index 4b28989d4..2a285c1dd 100644 --- a/core/src/examples/simple_c.c +++ b/core/src/examples/simple_c.c @@ -22,8 +22,8 @@ void vpt_change_cbk(const omega_viewport_t *viewport_ptr, omega_viewport_event_t case VIEWPORT_EVT_CREATE: case VIEWPORT_EVT_EDIT: { char change_kind = viewport_event_ptr - ? omega_change_get_kind_as_char((const omega_change_t *) (viewport_event_ptr)) - : 'R'; + ? omega_change_get_kind_as_char((const omega_change_t *) (viewport_event_ptr)) + : 'R'; fprintf(stdout, "%c: [%s]\n", change_kind, omega_viewport_get_data(viewport_ptr)); break; } diff --git a/core/src/include/omega_edit/byte.h b/core/src/include/omega_edit/byte.h index e02256d0e..f3fa89577 100644 --- a/core/src/include/omega_edit/byte.h +++ b/core/src/include/omega_edit/byte.h @@ -26,11 +26,15 @@ extern "C" { #endif +/** omega_byte_t is configured (via OMEGA_BYTE_T in config.h) as a single byte */ typedef OMEGA_BYTE_T omega_byte_t; #ifdef __cplusplus } + +// static assert that omega_byte_t is indeed 1 byte static_assert(1 == sizeof(omega_byte_t), "size of omega_byte_t is expected to be 1 byte"); + #endif #endif//OMEGA_EDIT_BYTE_H diff --git a/core/src/include/omega_edit/change.h b/core/src/include/omega_edit/change.h index ba2bbb3be..f28283955 100644 --- a/core/src/include/omega_edit/change.h +++ b/core/src/include/omega_edit/change.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_CHANGE_H #include "byte.h" -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -40,49 +39,49 @@ extern "C" { * @param change_ptr change to get the original change offset from * @return original change offset */ -OMEGA_EDIT_EXPORT int64_t omega_change_get_offset(const omega_change_t *change_ptr); +int64_t omega_change_get_offset(const omega_change_t *change_ptr); /** * Given a change, return the original number of bytes deleted, inserted, or overwritten * @param change_ptr change to get the original number of bytes from * @return original number of bytes deleted, inserted, or overwritten */ -OMEGA_EDIT_EXPORT int64_t omega_change_get_length(const omega_change_t *change_ptr); +int64_t omega_change_get_length(const omega_change_t *change_ptr); /** * Given a change, return the change serial number. A negative serial number is an undone change. * @param change_ptr change to get the serial number from * @return change serial number */ -OMEGA_EDIT_EXPORT int64_t omega_change_get_serial(const omega_change_t *change_ptr); +int64_t omega_change_get_serial(const omega_change_t *change_ptr); /** * Given a change, return a character representing the kind of change ('D', 'I', and 'O') * @param change_ptr change to get the kind from * @return 'D' if the change is a delete, 'I' if the change is an insert and 'O' if the change is an overwrite */ -OMEGA_EDIT_EXPORT char omega_change_get_kind_as_char(const omega_change_t *change_ptr); +char omega_change_get_kind_as_char(const omega_change_t *change_ptr); /** * Given a change, return the transaction bit (0 or 1) * @param change_ptr change to get the transaction bit from * @return transaction bit (0 or 1) */ -OMEGA_EDIT_EXPORT int omega_change_get_transaction_bit(const omega_change_t *change_ptr); +int omega_change_get_transaction_bit(const omega_change_t *change_ptr); /** * Given a change, return a pointer to the byte data * @param change_ptr change to get the bytes data from * @return pointer to the byte data */ -OMEGA_EDIT_EXPORT const omega_byte_t *omega_change_get_bytes(const omega_change_t *change_ptr); +const omega_byte_t *omega_change_get_bytes(const omega_change_t *change_ptr); /** * Given a change, determine if this change is undone * @param change_ptr change to determine if it has been undone or not * @return non-zero if the change is undone, and zero otherwise */ -OMEGA_EDIT_EXPORT int omega_change_is_undone(const omega_change_t *change_ptr); +int omega_change_is_undone(const omega_change_t *change_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/character_counts.h b/core/src/include/omega_edit/character_counts.h index 33066e620..1c8250a8d 100644 --- a/core/src/include/omega_edit/character_counts.h +++ b/core/src/include/omega_edit/character_counts.h @@ -20,7 +20,6 @@ #ifndef OMEGA_EDIT_CHARACTER_COUNTS_H #define OMEGA_EDIT_CHARACTER_COUNTS_H -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -38,78 +37,78 @@ extern "C" { * Create a new omega_character_counts_t object * @return new omega_character_counts_t object */ -OMEGA_EDIT_EXPORT omega_character_counts_t *omega_character_counts_create(); +omega_character_counts_t *omega_character_counts_create(); /** * Destroy an omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to destroy */ -OMEGA_EDIT_EXPORT void omega_character_counts_destroy(omega_character_counts_t *counts_ptr); +void omega_character_counts_destroy(omega_character_counts_t *counts_ptr); /** * Reset an omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to reset */ -OMEGA_EDIT_EXPORT void omega_character_counts_reset(omega_character_counts_t *counts_ptr); +void omega_character_counts_reset(omega_character_counts_t *counts_ptr); /** * Get the byte order mark (BOM) for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the BOM from * @return BOM for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT omega_bom_t omega_character_counts_get_BOM(const omega_character_counts_t *counts_ptr); +omega_bom_t omega_character_counts_get_BOM(const omega_character_counts_t *counts_ptr); /** * Set the byte order mark (BOM) for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to set the BOM for * @param bom BOM to set for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT void omega_character_counts_set_BOM(omega_character_counts_t *counts_ptr, omega_bom_t bom); +void omega_character_counts_set_BOM(omega_character_counts_t *counts_ptr, omega_bom_t bom); /** * Get the number of BOM bytes found for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the number of BOM bytes from * @return number of BOM bytes found for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT int64_t omega_character_counts_bom_bytes(const omega_character_counts_t *counts_ptr); +int64_t omega_character_counts_bom_bytes(const omega_character_counts_t *counts_ptr); /** * Get the number of single byte characters for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the number of single byte characters from * @return number of single byte characters for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT int64_t omega_character_counts_single_byte_chars(const omega_character_counts_t *counts_ptr); +int64_t omega_character_counts_single_byte_chars(const omega_character_counts_t *counts_ptr); /** * Get the number of double byte characters for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the number of double byte characters from * @return number of double byte characters for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT int64_t omega_character_counts_double_byte_chars(const omega_character_counts_t *counts_ptr); +int64_t omega_character_counts_double_byte_chars(const omega_character_counts_t *counts_ptr); /** * Get the number of triple byte characters for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the number of triple byte characters from * @return number of triple byte characters for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT int64_t omega_character_counts_triple_byte_chars(const omega_character_counts_t *counts_ptr); +int64_t omega_character_counts_triple_byte_chars(const omega_character_counts_t *counts_ptr); /** * Get the number of quad byte characters for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the number of quad byte characters from * @return number of quad byte characters for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT int64_t omega_character_counts_quad_byte_chars(const omega_character_counts_t *counts_ptr); +int64_t omega_character_counts_quad_byte_chars(const omega_character_counts_t *counts_ptr); /** * Get the number of invalid sequences for the given omega_character_counts_t object * @param counts_ptr omega_character_counts_t object to get the number of invalid sequences from * @return number of invalid sequences for the given omega_character_counts_t object */ -OMEGA_EDIT_EXPORT int64_t omega_character_counts_invalid_bytes(const omega_character_counts_t *counts_ptr); +int64_t omega_character_counts_invalid_bytes(const omega_character_counts_t *counts_ptr); #ifdef __cplusplus } #endif -#endif //OMEGA_EDIT_CHARACTER_COUNTS_H +#endif//OMEGA_EDIT_CHARACTER_COUNTS_H diff --git a/core/src/include/omega_edit/check.h b/core/src/include/omega_edit/check.h index 3dcc8e9bf..77305b316 100644 --- a/core/src/include/omega_edit/check.h +++ b/core/src/include/omega_edit/check.h @@ -20,7 +20,6 @@ #ifndef OMEGA_EDIT_CHECK_H #define OMEGA_EDIT_CHECK_H -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -32,7 +31,7 @@ extern "C" { * @param session_ptr session whose model to check for errors * @return 0 if the model is error free and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_check_model(const omega_session_t *session_ptr); +int omega_check_model(const omega_session_t *session_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/config.h b/core/src/include/omega_edit/config.h index a51f4f131..7db04dcc0 100644 --- a/core/src/include/omega_edit/config.h +++ b/core/src/include/omega_edit/config.h @@ -34,39 +34,46 @@ * CONFIGURATION **********************************************************************************************************************/ -// Define to enable debugging +/** Define to enable debugging */ #define DEBUG -// Default maximum viewport capacity #ifndef OMEGA_VIEWPORT_CAPACITY_LIMIT +/** Default maximum viewport capacity */ #define OMEGA_VIEWPORT_CAPACITY_LIMIT (1024 * 1024) #endif//OMEGA_VIEWPORT_CAPACITY_LIMIT -// Define the maximum length of a pattern for searching #ifndef OMEGA_SEARCH_PATTERN_LENGTH_LIMIT +/** Define the maximum length of a pattern for searching */ #define OMEGA_SEARCH_PATTERN_LENGTH_LIMIT (OMEGA_VIEWPORT_CAPACITY_LIMIT / 2) #endif//OMEGA_SEARCH_PATTERN_LENGTH_LIMIT -// Define the byte type to be used across the project #ifndef OMEGA_BYTE_T +/** Define the byte type to be used across the project */ #define OMEGA_BYTE_T unsigned char #endif//OMEGA_BYTE_T -#if !defined(__CYGWIN__) && \ +#if !defined(__CYGWIN__) && \ (defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(_WIN64) || defined(_MSC_BUILD)) +/** Define if building for Windows */ #define OMEGA_BUILD_WINDOWS #else +/** Define if building for Unix-like operating systems */ #define OMEGA_BUILD_UNIX #endif #if INTPTR_MAX == INT64_MAX +/** Define if building for 64-bit */ #define OMEGA_BUILD_64_BIT #elif INTPTR_MAX == INT32_MAX +/** Define if building for 32-bit */ #define OMEGA_BUILD_32_BIT #else #error Unknown pointer size or missing size macros! #endif +/** + * @brief Alias for the open function, accommodating large files if _LARGEFILE_SOURCE is defined. + */ #ifndef OPEN #ifdef _LARGEFILE_SOURCE #define OPEN open @@ -75,10 +82,16 @@ #endif #endif +/** + * Alias for the close function used to close a file descriptor. + */ #ifndef CLOSE #define CLOSE close #endif +/** + * Alias for the fseek/fseeko function, using fseeko if _LARGEFILE_SOURCE is defined to accommodate large files. + */ #ifndef FSEEK #ifdef _LARGEFILE_SOURCE #define FSEEK fseeko @@ -87,6 +100,9 @@ #endif #endif +/** + * Alias for the ftell/ftello function, using ftello if _LARGEFILE_SOURCE is defined to accommodate large files. + */ #ifndef FTELL #ifdef _LARGEFILE_SOURCE #define FTELL ftello @@ -95,4 +111,5 @@ #endif #endif + #endif//OMEGA_EDIT_CONFIG_H diff --git a/core/src/include/omega_edit/edit.h b/core/src/include/omega_edit/edit.h index c4da7d305..eadf25938 100644 --- a/core/src/include/omega_edit/edit.h +++ b/core/src/include/omega_edit/edit.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_EDIT_H #include "byte.h" -#include "export.h" #include "fwd_defs.h" #include "utility.h" @@ -50,15 +49,14 @@ extern "C" { * current working directory * @return pointer to the created session, or NULL on failure */ -OMEGA_EDIT_EXPORT omega_session_t *omega_edit_create_session(const char *file_path, omega_session_event_cbk_t cbk, - void *user_data_ptr, int32_t event_interest, - const char *checkpoint_directory); +omega_session_t *omega_edit_create_session(const char *file_path, omega_session_event_cbk_t cbk, void *user_data_ptr, + int32_t event_interest, const char *checkpoint_directory); /** * Destroy the given session and all associated objects (changes, and viewports) * @param session_ptr session to destroy */ -OMEGA_EDIT_EXPORT void omega_edit_destroy_session(omega_session_t *session_ptr); +void omega_edit_destroy_session(omega_session_t *session_ptr); /** * Create a new viewport, returns a pointer to the new viewport @@ -72,38 +70,36 @@ OMEGA_EDIT_EXPORT void omega_edit_destroy_session(omega_session_t *session_ptr); * @param event_interest oring together the viewport events of interest, or zero if all viewport events are desired * @return pointer to the new viewport, or NULL on failure */ -OMEGA_EDIT_EXPORT omega_viewport_t *omega_edit_create_viewport(omega_session_t *session_ptr, int64_t offset, - int64_t capacity, int is_floating, - omega_viewport_event_cbk_t cbk, void *user_data_ptr, - int32_t event_interest); +omega_viewport_t *omega_edit_create_viewport(omega_session_t *session_ptr, int64_t offset, int64_t capacity, + int is_floating, omega_viewport_event_cbk_t cbk, void *user_data_ptr, + int32_t event_interest); /** * Destroy a given viewport * @param viewport_ptr viewport to destroy - * @return 0 of the viewport was successfully destroyed, and non-zero otherwise */ -OMEGA_EDIT_EXPORT void omega_edit_destroy_viewport(omega_viewport_t *viewport_ptr); +void omega_edit_destroy_viewport(omega_viewport_t *viewport_ptr); /** * Given a session, clear all active changes * @param session_ptr session to clear all changes for * @return zero on success and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_edit_clear_changes(omega_session_t *session_ptr); +int omega_edit_clear_changes(omega_session_t *session_ptr); /** * Given a session, undo the last change * @param session_ptr session to undo the last change for * @return negative serial number of the undone change if successful, zero otherwise */ -OMEGA_EDIT_EXPORT int64_t omega_edit_undo_last_change(omega_session_t *session_ptr); +int64_t omega_edit_undo_last_change(omega_session_t *session_ptr); /** * Redoes the last undo (if available) * @param session_ptr session to redo the last undo for * @return positive serial number of the redone change if successful, zero otherwise */ -OMEGA_EDIT_EXPORT int64_t omega_edit_redo_last_undo(omega_session_t *session_ptr); +int64_t omega_edit_redo_last_undo(omega_session_t *session_ptr); /** * Save a segment of the the given session (the edited file) to the given file path. If the save file already exists, @@ -119,8 +115,8 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_redo_last_undo(omega_session_t *session_ptr * @param length save this many bytes from the given start offset * @return 0 on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, int io_flags, - char *saved_file_path, int64_t offset, int64_t length); +int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, int io_flags, char *saved_file_path, + int64_t offset, int64_t length); /** * Save the given session (the edited file) to the given file path. If the save file already exists, it can be overwritten @@ -133,8 +129,7 @@ OMEGA_EDIT_EXPORT int omega_edit_save_segment(omega_session_t *session_ptr, cons * this parameter is non-null, the saved file path will be copied here (must be able to accommodate FILENAME_MAX bytes) * @return 0 on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_edit_save(omega_session_t *session_ptr, const char *file_path, int io_flags, - char *saved_file_path); +int omega_edit_save(omega_session_t *session_ptr, const char *file_path, int io_flags, char *saved_file_path); /** * Delete a number of bytes at the given offset @@ -143,7 +138,7 @@ OMEGA_EDIT_EXPORT int omega_edit_save(omega_session_t *session_ptr, const char * * @param length number of bytes to delete * @return positive change serial number on success, zero otherwise */ -OMEGA_EDIT_EXPORT int64_t omega_edit_delete(omega_session_t *session_ptr, int64_t offset, int64_t length); +int64_t omega_edit_delete(omega_session_t *session_ptr, int64_t offset, int64_t length); /** * Insert a number of bytes at the given offset @@ -156,8 +151,8 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_delete(omega_session_t *session_ptr, int64_ * function compute the length using strlen, because it will be wrong. Passing length 0 is a convenience for testing * and should not be used in production code. In production code, explicitly pass in the length. */ -OMEGA_EDIT_EXPORT int64_t omega_edit_insert_bytes(omega_session_t *session_ptr, int64_t offset, - const omega_byte_t *bytes, int64_t length); +int64_t omega_edit_insert_bytes(omega_session_t *session_ptr, int64_t offset, const omega_byte_t *bytes, + int64_t length); /** * Insert a C string at the given offset @@ -171,8 +166,7 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_insert_bytes(omega_session_t *session_ptr, * function compute the length using strlen, because it will be wrong. Passing length 0 is a convenience for testing * and should not be used in production code. In production code, explicitly pass in the length. */ -OMEGA_EDIT_EXPORT int64_t omega_edit_insert(omega_session_t *session_ptr, int64_t offset, const char *cstr, - int64_t length); +int64_t omega_edit_insert(omega_session_t *session_ptr, int64_t offset, const char *cstr, int64_t length); /** * Overwrite bytes at the given offset with the given new bytes @@ -185,8 +179,8 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_insert(omega_session_t *session_ptr, int64_ * function compute the length using strlen, because it will be wrong. Passing length 0 is a convenience for testing * and should not be used in production code. In production code, explicitly pass in the length. */ -OMEGA_EDIT_EXPORT int64_t omega_edit_overwrite_bytes(omega_session_t *session_ptr, int64_t offset, - const omega_byte_t *bytes, int64_t length); +int64_t omega_edit_overwrite_bytes(omega_session_t *session_ptr, int64_t offset, const omega_byte_t *bytes, + int64_t length); /** * Overwrite bytes at the given offset with the given new C string @@ -199,8 +193,7 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_overwrite_bytes(omega_session_t *session_pt * function compute the length using strlen, because it will be wrong. Passing length 0 is a convenience for testing * and should not be used in production code. In production code, explicitly pass in the length. */ -OMEGA_EDIT_EXPORT int64_t omega_edit_overwrite(omega_session_t *session_ptr, int64_t offset, const char *cstr, - int64_t length); +int64_t omega_edit_overwrite(omega_session_t *session_ptr, int64_t offset, const char *cstr, int64_t length); /** * Checkpoint and apply the given mask of the given mask type to the bytes starting at the given offset up to the given @@ -212,22 +205,22 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_overwrite(omega_session_t *session_ptr, int * @param length the number of bytes from the given offset to apply the mask to * @return zero on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_edit_apply_transform(omega_session_t *session_ptr, omega_util_byte_transform_t transform, - void *user_data_ptr, int64_t offset, int64_t length); +int omega_edit_apply_transform(omega_session_t *session_ptr, omega_util_byte_transform_t transform, void *user_data_ptr, + int64_t offset, int64_t length); /** * Creates a session checkpoint. * @param session_ptr session to checkpoint * @return zero on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_edit_create_checkpoint(omega_session_t *session_ptr); +int omega_edit_create_checkpoint(omega_session_t *session_ptr); /** * Destroys the last checkpoint created on the given session * @param session_ptr session to remove the checkpoint * @return zero on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_edit_destroy_last_checkpoint(omega_session_t *session_ptr); +int omega_edit_destroy_last_checkpoint(omega_session_t *session_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/encode.h b/core/src/include/omega_edit/encode.h index 947f191c3..ecc0918c7 100644 --- a/core/src/include/omega_edit/encode.h +++ b/core/src/include/omega_edit/encode.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_ENCODE_H #include "byte.h" -#include "export.h" #ifdef __cplusplus #include @@ -39,7 +38,7 @@ extern "C" { * @param src_length src_length of the bytes * @return number of characters written to the destination, or 0 if unsuccessful */ -OMEGA_EDIT_EXPORT size_t omega_encode_bin2hex(const omega_byte_t *src, char *dst, size_t src_length); +size_t omega_encode_bin2hex(const omega_byte_t *src, char *dst, size_t src_length); /** * Given a pointer to hex characters, write the binary representation to dst @@ -48,7 +47,7 @@ OMEGA_EDIT_EXPORT size_t omega_encode_bin2hex(const omega_byte_t *src, char *dst * @param src_length src_length of the hex characters * @return number of bytes written to the destination, or 0 if unsuccessful */ -OMEGA_EDIT_EXPORT size_t omega_encode_hex2bin(const char *src, omega_byte_t *dst, size_t src_length); +size_t omega_encode_hex2bin(const char *src, omega_byte_t *dst, size_t src_length); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/export.h b/core/src/include/omega_edit/export.h deleted file mode 100755 index 0854177f4..000000000 --- a/core/src/include/omega_edit/export.h +++ /dev/null @@ -1,60 +0,0 @@ -/********************************************************************************************************************** -* Copyright (c) 2021 Concurrent Technologies Corporation. * -* * -* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -* with the License. You may obtain a copy of the License at * -* * -* http://www.apache.org/licenses/LICENSE-2.0 * -* * -* Unless required by applicable law or agreed to in writing, software is distributed under the License is * -* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * -* implied. See the License for the specific language governing permissions and limitations under the License. * -* * -**********************************************************************************************************************/ - -/** - * @file export.h - * @brief Export macros. - */ - -#ifndef OMEGA_EDIT_EXPORT_H -#define OMEGA_EDIT_EXPORT_H - -#ifdef OMEGA_EDIT_STATIC_DEFINE -#define OMEGA_EDIT_EXPORT -#define OMEGA_EDIT_NO_EXPORT -#else -#ifndef OMEGA_EDIT_EXPORT -#ifdef omega_edit_EXPORTS -/* We are building this library */ -#define OMEGA_EDIT_EXPORT -#else -/* We are using this library */ -#define OMEGA_EDIT_EXPORT -#endif -#endif - -#ifndef OMEGA_EDIT_NO_EXPORT -#define OMEGA_EDIT_NO_EXPORT -#endif -#endif - -#ifndef OMEGA_EDIT_DEPRECATED -#define OMEGA_EDIT_DEPRECATED __attribute__((__deprecated__)) -#endif - -#ifndef OMEGA_EDIT_DEPRECATED_EXPORT -#define OMEGA_EDIT_DEPRECATED_EXPORT OMEGA_EDIT_EXPORT OMEGA_EDIT_DEPRECATED -#endif - -#ifndef OMEGA_EDIT_DEPRECATED_NO_EXPORT -#define OMEGA_EDIT_DEPRECATED_NO_EXPORT OMEGA_EDIT_NO_EXPORT OMEGA_EDIT_DEPRECATED -#endif - -#if 0 /* DEFINE_NO_DEPRECATED */ -#ifndef OMEGA_EDIT_NO_DEPRECATED -#define OMEGA_EDIT_NO_DEPRECATED -#endif -#endif - -#endif /* OMEGA_EDIT_EXPORT_H */ diff --git a/core/src/include/omega_edit/filesystem.h b/core/src/include/omega_edit/filesystem.h index 08aa6b526..100a829eb 100644 --- a/core/src/include/omega_edit/filesystem.h +++ b/core/src/include/omega_edit/filesystem.h @@ -20,8 +20,6 @@ #ifndef OMEGA_EDIT_FILESYSTEM_H #define OMEGA_EDIT_FILESYSTEM_H -#include "export.h" - #ifdef __cplusplus #include @@ -38,56 +36,56 @@ extern "C" { * @param buffer pointer to memory to hold the current working directory (allocated to at least FILENAME_MAX) or could be NULL, in which case an internal static buffer will be used * @return current working directory or NULL on error */ -OMEGA_EDIT_EXPORT const char *omega_util_get_current_dir(char *buffer); +const char *omega_util_get_current_dir(char *buffer); /** * Check if the given file name exists * @param file_name file name to check existence of * @return non-zero if the file exists, and zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_file_exists(const char *file_name); +int omega_util_file_exists(const char *file_name); /** * Check if the given directory exists * @param path directory to check for the existence of * @return non-zero if the directory exists and zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_directory_exists(const char *path); +int omega_util_directory_exists(const char *path); /** * Create the given directory * @param path directory to create * @return zero if the path was created successfully and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_create_directory(char const *path); +int omega_util_create_directory(char const *path); /** * Remove the given file * @param path path to the fle to remove * @return zero if the file was removed successfully and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_remove_file(char const *path); +int omega_util_remove_file(char const *path); /** * Remove the given directory * @param path directory to remove * @return zero if the path was removed successfully and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_remove_directory(char const *path); +int omega_util_remove_directory(char const *path); /** * Remove the given path, whether it is a file or directory * @param path directory or file to remove * @return number of files removed */ -OMEGA_EDIT_EXPORT uint64_t omega_util_remove_all(char const *path); +uint64_t omega_util_remove_all(char const *path); /** * Given a file path, return the file size * @param path path to get the file size of * @return file size */ -OMEGA_EDIT_EXPORT int64_t omega_util_file_size(char const *path); +int64_t omega_util_file_size(char const *path); /** * Given two file paths, determine if they are equivalent @@ -95,7 +93,7 @@ OMEGA_EDIT_EXPORT int64_t omega_util_file_size(char const *path); * @param path2 second path * @return non-zero if the paths are equivalent and zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_paths_equivalent(char const *path1, char const *path2); +int omega_util_paths_equivalent(char const *path1, char const *path2); /** * Compare the modification times of two files @@ -103,7 +101,7 @@ OMEGA_EDIT_EXPORT int omega_util_paths_equivalent(char const *path1, char const * @param path2 second path * @return 0 if the modification times are equal, -1 if the modification time of path1 is less than path2, 1 if the modification time of path1 is greater than path2, or -2 if an error occurred */ -OMEGA_EDIT_EXPORT int omega_util_compare_modification_times(const char *path1, const char *path2); +int omega_util_compare_modification_times(const char *path1, const char *path2); /** * Given a file name, return the associated basename (filename without the directory) and if a matching suffix is given, the returned basename will have the suffix removed @@ -112,7 +110,7 @@ OMEGA_EDIT_EXPORT int omega_util_compare_modification_times(const char *path1, c * @param drop_suffix if non-zero, remove the suffix (file extension) from the path basename * @return associated basename, possibly without the suffix */ -OMEGA_EDIT_EXPORT char *omega_util_basename(char const *path, char *buffer, int drop_suffix); +char *omega_util_basename(char const *path, char *buffer, int drop_suffix); /** * Given a file name, return the associated file extension, with or without the dot prefix @@ -120,7 +118,7 @@ OMEGA_EDIT_EXPORT char *omega_util_basename(char const *path, char *buffer, int * @param buffer pointer to memory to hold the file extension (allocated to at least FILENAME_MAX) or could be NULL, in which case an internal static buffer will be used * @return associated file extension or NULL if no extension exists */ -OMEGA_EDIT_EXPORT char *omega_util_file_extension(char const *path, char *buffer); +char *omega_util_file_extension(char const *path, char *buffer); /** * Creates a available filename from the given path @@ -128,7 +126,7 @@ OMEGA_EDIT_EXPORT char *omega_util_file_extension(char const *path, char *buffer * @param buffer pointer to a buffer that can hold up to FILENAME_MAX bytes, or NULL to use an internal static buffer * @return a path that is currently available (insecure as the file may exist later at the time of attempted creation) */ -OMEGA_EDIT_EXPORT char *omega_util_available_filename(char const *path, char *buffer); +char *omega_util_available_filename(char const *path, char *buffer); /** * Given a path, which must exist, returns an absolute path that has no symbolic link, dot, or dot-dot elements @@ -136,7 +134,7 @@ OMEGA_EDIT_EXPORT char *omega_util_available_filename(char const *path, char *bu * @param buffer pointer to memory to hold the file extension (allocated to at least FILENAME_MAX) or could be NULL, in which case an internal static buffer will be used * @return absolute path that has no symbolic link, dot, or dot-dot elements */ -OMEGA_EDIT_EXPORT char *omega_util_normalize_path(char const *path, char *buffer); +char *omega_util_normalize_path(char const *path, char *buffer); /** * Given a file name, return the associated directory @@ -144,7 +142,7 @@ OMEGA_EDIT_EXPORT char *omega_util_normalize_path(char const *path, char *buffer * @param buffer pointer to memory to hold the directory name (allocated to at least FILENAME_MAX) or could be NULL, in which case an internal static buffer will be used * @return associated directory */ -OMEGA_EDIT_EXPORT char *omega_util_dirname(char const *path, char *buffer); +char *omega_util_dirname(char const *path, char *buffer); /** * Copy the file at the given source path to the given destination path @@ -153,13 +151,13 @@ OMEGA_EDIT_EXPORT char *omega_util_dirname(char const *path, char *buffer); * @param mode mode to set the destination file to, if zero then the mode of the source file is used * @return zero on success, non-zero on failure */ -OMEGA_EDIT_EXPORT int omega_util_file_copy(const char *src_path, const char *dst_path, int mode); +int omega_util_file_copy(const char *src_path, const char *dst_path, int mode); /** * Try to get the temporary directory for the host system * @return temporary directory for the host system allocated by malloc (must be free'd by the caller), or NULL on error */ -OMEGA_EDIT_EXPORT char *omega_util_get_temp_directory(); +char *omega_util_get_temp_directory(); /** * Touch the given file, optionally creating it if it does not exist @@ -167,13 +165,13 @@ OMEGA_EDIT_EXPORT char *omega_util_get_temp_directory(); * @param create if non-zero, create the file name if it does not exist * @return zero on success, non-zero on failure */ -OMEGA_EDIT_EXPORT int omega_util_touch(const char *file_name, int create); +int omega_util_touch(const char *file_name, int create); /** * Returns the directory separator character used on the host system * @return directory separator character used on the host system */ -OMEGA_EDIT_EXPORT char omega_util_directory_separator(); +char omega_util_directory_separator(); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/fwd_defs.h b/core/src/include/omega_edit/fwd_defs.h index a8052bc0c..f25d6ba55 100644 --- a/core/src/include/omega_edit/fwd_defs.h +++ b/core/src/include/omega_edit/fwd_defs.h @@ -25,9 +25,7 @@ extern "C" { #endif -/** - * Enumeration of session events - */ +/** Enumeration of session events */ typedef enum { SESSION_EVT_UNDEFINED = 0, //< No session event interest is defined SESSION_EVT_CREATE = 1, //< Occurs when the session has been successfully created @@ -44,9 +42,7 @@ typedef enum { SESSION_EVT_DESTROY_VIEWPORT = 1 << 11 //< Occurs when the session has successfully destroyed a viewport } omega_session_event_t; -/** - * Enumeration of viewport events - */ +/** Enumeration of viewport events */ typedef enum { VIEWPORT_EVT_UNDEFINED = 0, //< No viewport event interest is defined VIEWPORT_EVT_CREATE = 1, //< Occurs when the viewport has been successfully created @@ -58,44 +54,44 @@ typedef enum { VIEWPORT_EVT_CHANGES = 1 << 6 //< Occurs when the viewport has changes to its data from some other activity } omega_viewport_event_t; +/** Subscribe to all events */ #define ALL_EVENTS (~0) + +/** Subscribe to no events */ #define NO_EVENTS (0) -/** - * Enumeration of IO flags - */ +/** Enumeration of IO flags */ typedef enum { IO_FLG_NONE = 0, //< No IO flags are defined IO_FLG_OVERWRITE = 1, //< Overwrite original file, unless modified outside the session IO_FLG_FORCE_OVERWRITE = 1 << 1//< Force overwrite of original file, even if modified outside the session } omega_io_flags_t; -#define ORIGINAL_MODIFIED (-100)// original session file has been modified since the session was created +/** Error code to indicate that the original session file has been modified since the session was created */ +#define ORIGINAL_MODIFIED (-100) -/** - * Mask types - */ -typedef enum { - MASK_AND, MASK_OR, MASK_XOR -} omega_mask_kind_t; +/** Mask types */ +typedef enum { MASK_AND, MASK_OR, MASK_XOR } omega_mask_kind_t; -/** - * Byte order mark (BOM) types - */ -typedef enum { - BOM_NONE = 0, - BOM_UTF8, - BOM_UTF16LE, - BOM_UTF16BE, - BOM_UTF32LE, - BOM_UTF32BE -} omega_bom_t; +/** Byte order mark (BOM) types */ +typedef enum { BOM_NONE = 0, BOM_UTF8, BOM_UTF16LE, BOM_UTF16BE, BOM_UTF32LE, BOM_UTF32BE } omega_bom_t; +/** Opaque character counts */ typedef struct omega_character_counts_struct omega_character_counts_t; + +/** Opaque change */ typedef struct omega_change_struct omega_change_t; + +/** Opaque search context */ typedef struct omega_search_context_struct omega_search_context_t; + +/** Opaque segment */ typedef struct omega_segment_struct omega_segment_t; + +/** Opaque session */ typedef struct omega_session_struct omega_session_t; + +/** Opaque viewport */ typedef struct omega_viewport_struct omega_viewport_t; /** On session change callback. This under-defined function will be called when a session event occurs. */ diff --git a/core/src/include/omega_edit/license.h b/core/src/include/omega_edit/license.h index 54f20c092..bd9ff2ebf 100644 --- a/core/src/include/omega_edit/license.h +++ b/core/src/include/omega_edit/license.h @@ -20,8 +20,6 @@ #ifndef OMEGA_EDIT_LICENSE_H #define OMEGA_EDIT_LICENSE_H -#include "export.h" - #ifdef __cplusplus extern "C" { #endif @@ -30,7 +28,7 @@ extern "C" { * Gets the license text * @return null-terminated license text */ -OMEGA_EDIT_EXPORT const char *omega_license_get(); +const char *omega_license_get(); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/search.h b/core/src/include/omega_edit/search.h index 7054ee86a..e30418cfa 100644 --- a/core/src/include/omega_edit/search.h +++ b/core/src/include/omega_edit/search.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_SEARCH_H #include "byte.h" -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -54,10 +53,10 @@ extern "C" { * @warning Ensure that the pattern_length does not exceed the session_length - session_offset. This is considered an * error and a null pointer will be returned. */ -OMEGA_EDIT_EXPORT omega_search_context_t * -omega_search_create_context_bytes(omega_session_t *session_ptr, const omega_byte_t *pattern, int64_t pattern_length, - int64_t session_offset, int64_t session_length, int case_insensitive, - int is_reverse_search); +omega_search_context_t *omega_search_create_context_bytes(omega_session_t *session_ptr, const omega_byte_t *pattern, + int64_t pattern_length, int64_t session_offset, + int64_t session_length, int case_insensitive, + int is_reverse_search); /** * Create a search context @@ -77,45 +76,45 @@ omega_search_create_context_bytes(omega_session_t *session_ptr, const omega_byte * @warning Ensure that the pattern_length does not exceed the session_length - session_offset. This is considered an * error and a null pointer will be returned. */ -OMEGA_EDIT_EXPORT omega_search_context_t * -omega_search_create_context(omega_session_t *session_ptr, const char *pattern, int64_t pattern_length, - int64_t session_offset, int64_t session_length, int case_insensitive, - int is_reverse_search); +omega_search_context_t *omega_search_create_context(omega_session_t *session_ptr, const char *pattern, + int64_t pattern_length, int64_t session_offset, + int64_t session_length, int case_insensitive, + int is_reverse_search); /** * Given a search context, determine if the search is being done forwards or backwards * @param search_context_ptr search context to determine if the search is forwards or backwards * @return zero for forwards search and non-zero for backwards search */ -OMEGA_EDIT_EXPORT int omega_search_context_is_reverse_search(const omega_search_context_t *search_context_ptr); +int omega_search_context_is_reverse_search(const omega_search_context_t *search_context_ptr); /** * Given a search context, return the session length * @param search_context_ptr search context to get the session length from * @return session length */ -OMEGA_EDIT_EXPORT int64_t omega_search_context_get_session_length(const omega_search_context_t *search_context_ptr); +int64_t omega_search_context_get_session_length(const omega_search_context_t *search_context_ptr); /** * Given a search context, return the session offset * @param search_context_ptr search context to get the session offset from * @return session offset */ -OMEGA_EDIT_EXPORT int64_t omega_search_context_get_session_offset(const omega_search_context_t *search_context_ptr); +int64_t omega_search_context_get_session_offset(const omega_search_context_t *search_context_ptr); /** * Given a search context, get the most recent search offset * @param search_context_ptr search context to get the most recent search offset from * @return most recent search offset, if the search offset is equal to the session length, then no match was found */ -OMEGA_EDIT_EXPORT int64_t omega_search_context_get_match_offset(const omega_search_context_t *search_context_ptr); +int64_t omega_search_context_get_match_offset(const omega_search_context_t *search_context_ptr); /** * Given a search context, get the pattern length * @param search_context_ptr search context to get the pattern length from * @return pattern length offset */ -OMEGA_EDIT_EXPORT int64_t omega_search_context_get_pattern_length(const omega_search_context_t *search_context_ptr); +int64_t omega_search_context_get_pattern_length(const omega_search_context_t *search_context_ptr); /** * Given a search context, find the next match @@ -123,13 +122,13 @@ OMEGA_EDIT_EXPORT int64_t omega_search_context_get_pattern_length(const omega_se * @param advance_context advance the internal search context offset by this many bytes * @return non-zero if a match is found, zero otherwise */ -OMEGA_EDIT_EXPORT int omega_search_next_match(omega_search_context_t *search_context_ptr, int64_t advance_context); +int omega_search_next_match(omega_search_context_t *search_context_ptr, int64_t advance_context); /** * Destroy the given search context * @param search_context_ptr search context to destroy */ -OMEGA_EDIT_EXPORT void omega_search_destroy_context(omega_search_context_t *search_context_ptr); +void omega_search_destroy_context(omega_search_context_t *search_context_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/segment.h b/core/src/include/omega_edit/segment.h index c9e79be70..84900fc38 100644 --- a/core/src/include/omega_edit/segment.h +++ b/core/src/include/omega_edit/segment.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_SEGMENT_H #include "byte.h" -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -42,48 +41,48 @@ extern "C" { * @param capacity desired capacity of the segment, must be greater then zero * @return segment of the desired capacity */ -OMEGA_EDIT_EXPORT omega_segment_t *omega_segment_create(int64_t capacity); +omega_segment_t *omega_segment_create(int64_t capacity); /** * Gets the capacity of the segment * @param segment_ptr segment to get the capacity from * @return given segment's capacity */ -OMEGA_EDIT_EXPORT int64_t omega_segment_get_capacity(const omega_segment_t *segment_ptr); +int64_t omega_segment_get_capacity(const omega_segment_t *segment_ptr); /** * Gets the length of a populated segment * @param segment_ptr populated segment to get the length from * @return given segment's length */ -OMEGA_EDIT_EXPORT int64_t omega_segment_get_length(const omega_segment_t *segment_ptr); +int64_t omega_segment_get_length(const omega_segment_t *segment_ptr); /** * Gets the offset of a populated segment * @param segment_ptr populated segment to get the offset from * @return given segment's offset, or a negative number if the segment is not populated */ -OMEGA_EDIT_EXPORT int64_t omega_segment_get_offset(const omega_segment_t *segment_ptr); +int64_t omega_segment_get_offset(const omega_segment_t *segment_ptr); /** * Gets the offset adjustment of a populated segment * @param segment_ptr populated segment to get the offset adjustment from * @return given segment's offset adjustment */ -OMEGA_EDIT_EXPORT int64_t omega_segment_get_offset_adjustment(const omega_segment_t *segment_ptr); +int64_t omega_segment_get_offset_adjustment(const omega_segment_t *segment_ptr); /** * Gets the data in a populated segment (data in the segment is a copy, not a reference) * @param segment_ptr populated segment to get the offset from * @return given segment's data, or null if the segment is not populated */ -OMEGA_EDIT_EXPORT omega_byte_t *omega_segment_get_data(omega_segment_t *segment_ptr); +omega_byte_t *omega_segment_get_data(omega_segment_t *segment_ptr); /** * Destroy the given segment * @param segment_ptr segment to destroy */ -OMEGA_EDIT_EXPORT void omega_segment_destroy(omega_segment_t *segment_ptr); +void omega_segment_destroy(omega_segment_t *segment_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/session.h b/core/src/include/omega_edit/session.h index d95049393..abb83e770 100644 --- a/core/src/include/omega_edit/session.h +++ b/core/src/include/omega_edit/session.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_SESSION_H #include "byte.h" -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -37,9 +36,10 @@ extern "C" { #endif -// index of the DOS end of line (EOL) byte pairs '\r\n' in the byte frequency profile +/** Index for the DOS end-of-line byte pair (CR LF) in the byte frequency profile. */ const size_t PROFILE_DOS_EOL = 256; +/** Byte frequency profile */ typedef int64_t omega_byte_frequency_profile_t[257]; /** @@ -47,21 +47,21 @@ typedef int64_t omega_byte_frequency_profile_t[257]; * @param session_ptr session to return the file path from * @return file path, or null if not known */ -OMEGA_EDIT_EXPORT const char *omega_session_get_file_path(const omega_session_t *session_ptr); +const char *omega_session_get_file_path(const omega_session_t *session_ptr); /** * Given a session, return the session event callback * @param session_ptr session to return the event callback from * @return session event callback */ -OMEGA_EDIT_EXPORT omega_session_event_cbk_t omega_session_get_event_cbk(const omega_session_t *session_ptr); +omega_session_event_cbk_t omega_session_get_event_cbk(const omega_session_t *session_ptr); /** * Given a session, return the session event interest * @param session_ptr session to return the session event interest from * @return session event interest */ -OMEGA_EDIT_EXPORT int32_t omega_session_get_event_interest(const omega_session_t *session_ptr); +int32_t omega_session_get_event_interest(const omega_session_t *session_ptr); /** * Set the session event interest to the given session event interest for the the given session @@ -69,13 +69,13 @@ OMEGA_EDIT_EXPORT int32_t omega_session_get_event_interest(const omega_session_t * @param event_interest desired session event interest * @return session event interest */ -OMEGA_EDIT_EXPORT int32_t omega_session_set_event_interest(omega_session_t *session_ptr, int32_t event_interest); +int32_t omega_session_set_event_interest(omega_session_t *session_ptr, int32_t event_interest); /** * Given a session, return the associated user data * @param session_ptr session to get the associated user data from * @return associated user data for the given session */ -OMEGA_EDIT_EXPORT void *omega_session_get_user_data_ptr(const omega_session_t *session_ptr); +void *omega_session_get_user_data_ptr(const omega_session_t *session_ptr); /** * Given a session and offset, populate a data segment @@ -84,57 +84,56 @@ OMEGA_EDIT_EXPORT void *omega_session_get_user_data_ptr(const omega_session_t *s * @param offset session offset to begin getting data from * @return zero on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_session_get_segment(const omega_session_t *session_ptr, omega_segment_t *data_segment_ptr, - int64_t offset); +int omega_session_get_segment(const omega_session_t *session_ptr, omega_segment_t *data_segment_ptr, int64_t offset); /** * Given a session, return the number of active viewports * @param session_ptr session to get the number of active viewports for * @return number of active viewports */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_viewports(const omega_session_t *session_ptr); +int64_t omega_session_get_num_viewports(const omega_session_t *session_ptr); /** * Given a session, return the number of active search contexts * @param session_ptr session to get the number of active search contexts for * @return number of active search contexts */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_search_contexts(const omega_session_t *session_ptr); +int64_t omega_session_get_num_search_contexts(const omega_session_t *session_ptr); /** * Given a session, return the current number of active changes * @param session_ptr session to get number of active changes from * @return number of active changes */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_changes(const omega_session_t *session_ptr); +int64_t omega_session_get_num_changes(const omega_session_t *session_ptr); /** * Given a session, return the current number of undone changes eligible for being redone * @param session_ptr session to get the number of undone changes for * @return number of undone changes eligible for being redone */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_undone_changes(const omega_session_t *session_ptr); +int64_t omega_session_get_num_undone_changes(const omega_session_t *session_ptr); /** * Given a session, return the computed file size in bytes * @param session_ptr session to get the computed file size from * @return computed file size in bytes, or -1 on failure */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_computed_file_size(const omega_session_t *session_ptr); +int64_t omega_session_get_computed_file_size(const omega_session_t *session_ptr); /** * Given a session, get the last change (if any) * @param session_ptr session to get the last change from * @return last change, or nullptr if there are no changes */ -OMEGA_EDIT_EXPORT const omega_change_t *omega_session_get_last_change(const omega_session_t *session_ptr); +const omega_change_t *omega_session_get_last_change(const omega_session_t *session_ptr); /** * Given a session, get the last undone change eligible for redo (if any) * @param session_ptr session to get the last undone change eligible for redo from * @return last undone change eligible for redo, or nullptr if there are no eligible changes for redo */ -OMEGA_EDIT_EXPORT const omega_change_t *omega_session_get_last_undo(const omega_session_t *session_ptr); +const omega_change_t *omega_session_get_last_undo(const omega_session_t *session_ptr); /** * Given a change serial, get the change @@ -142,95 +141,94 @@ OMEGA_EDIT_EXPORT const omega_change_t *omega_session_get_last_undo(const omega_ * @param change_serial change serial of the change to get * @return change with the matching serial, or nullptr on failure */ -OMEGA_EDIT_EXPORT const omega_change_t *omega_session_get_change(const omega_session_t *session_ptr, - int64_t change_serial); +const omega_change_t *omega_session_get_change(const omega_session_t *session_ptr, int64_t change_serial); /** * Determine if the viewport on-change callbacks have been paused or not * @param session_ptr session to determine if viewport on-change callbacks are paused on * @return non-zero if viewport on-change callbacks are paused and zero if they are not */ -OMEGA_EDIT_EXPORT int omega_session_viewport_event_callbacks_paused(const omega_session_t *session_ptr); +int omega_session_viewport_event_callbacks_paused(const omega_session_t *session_ptr); /** * Pause viewport on-change callbacks for the given session * @param session_ptr session to pause viewport on-change callbacks on */ -OMEGA_EDIT_EXPORT void omega_session_pause_viewport_event_callbacks(omega_session_t *session_ptr); +void omega_session_pause_viewport_event_callbacks(omega_session_t *session_ptr); /** * Resume viewport on-change callbacks for the given session * @param session_ptr session to resume viewport on-change callbacks on */ -OMEGA_EDIT_EXPORT void omega_session_resume_viewport_event_callbacks(omega_session_t *session_ptr); +void omega_session_resume_viewport_event_callbacks(omega_session_t *session_ptr); /** * Notify changed viewports in the given session with a VIEWPORT_EVT_CHANGES event * @param session_ptr session to notify viewports with changes * @return number of viewports that were notified, or -1 on failure */ -OMEGA_EDIT_EXPORT int omega_session_notify_changed_viewports(const omega_session_t *session_ptr); +int omega_session_notify_changed_viewports(const omega_session_t *session_ptr); /** * Determine if the session is accepting changes or not * @param session_ptr session to determine if changes are accepted or not * @return non-zero if the session is accepting changes and zero if it is not */ -OMEGA_EDIT_EXPORT int omega_session_changes_paused(const omega_session_t *session_ptr); +int omega_session_changes_paused(const omega_session_t *session_ptr); /** * Pause data changes to the session * @param session_ptr session to pause changes to */ -OMEGA_EDIT_EXPORT void omega_session_pause_changes(omega_session_t *session_ptr); +void omega_session_pause_changes(omega_session_t *session_ptr); /** * Resume data changes to the session * @param session_ptr session to resume changes to */ -OMEGA_EDIT_EXPORT void omega_session_resume_changes(omega_session_t *session_ptr); +void omega_session_resume_changes(omega_session_t *session_ptr); /** * Given a session, begin a transaction * @param session_ptr session to begin a transaction on * @return 0 on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_session_begin_transaction(omega_session_t *session_ptr); +int omega_session_begin_transaction(omega_session_t *session_ptr); /** * Given a session, end a transaction * @param session_ptr session to end a transaction on * @return 0 on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_session_end_transaction(omega_session_t *session_ptr); +int omega_session_end_transaction(omega_session_t *session_ptr); /** * Given a session, return the current transaction state * @param session_ptr session to get the transaction state for * @return 0 for no transaction, 1 for transaction is opened, and 2 for transaction in progress, and -1 on failure */ -OMEGA_EDIT_EXPORT int omega_session_get_transaction_state(const omega_session_t *session_ptr); +int omega_session_get_transaction_state(const omega_session_t *session_ptr); /** * Given a session, return the current number of session change transactions * @param session_ptr session to get the number of session change transactions for * @return number of session change transactions */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_change_transactions(const omega_session_t *session_ptr); +int64_t omega_session_get_num_change_transactions(const omega_session_t *session_ptr); /** * Given a session, return the current number of session undone change transactions * @param session_ptr session to get the number of session undone change transactions for * @return number of session undone change transactions */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_undone_change_transactions(const omega_session_t *session_ptr); +int64_t omega_session_get_num_undone_change_transactions(const omega_session_t *session_ptr); /** * Given a session, return the current number of session checkpoints * @param session_ptr session to get the number of session checkpoints for * @return number of session checkpoints */ -OMEGA_EDIT_EXPORT int64_t omega_session_get_num_checkpoints(const omega_session_t *session_ptr); +int64_t omega_session_get_num_checkpoints(const omega_session_t *session_ptr); /** * Call the registered session event handler @@ -238,15 +236,15 @@ OMEGA_EDIT_EXPORT int64_t omega_session_get_num_checkpoints(const omega_session_ * @param session_event session event * @param event_ptr pointer to the change */ -OMEGA_EDIT_EXPORT void omega_session_notify(const omega_session_t *session_ptr, omega_session_event_t session_event, - const void *event_ptr); +void omega_session_notify(const omega_session_t *session_ptr, omega_session_event_t session_event, + const void *event_ptr); /** * Given a session, return the detected byte order marker (BOM) * @param session_ptr session to get the BOM from * @return detected byte order marker (BOM) */ -OMEGA_EDIT_EXPORT omega_bom_t omega_session_detect_BOM(const omega_session_t *session_ptr); +omega_bom_t omega_session_detect_BOM(const omega_session_t *session_ptr); /** * Given a session, offset and length, populate a byte frequency profile @@ -256,9 +254,8 @@ OMEGA_EDIT_EXPORT omega_bom_t omega_session_detect_BOM(const omega_session_t *se * @param length number of bytes from the offset to stop profiling (if 0, it will profile to the end of the session) * @return zero on success and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_session_byte_frequency_profile(const omega_session_t *session_ptr, - omega_byte_frequency_profile_t *profile_ptr, int64_t offset, - int64_t length); +int omega_session_byte_frequency_profile(const omega_session_t *session_ptr, + omega_byte_frequency_profile_t *profile_ptr, int64_t offset, int64_t length); /** * Given a session, offset and length, populate character counts @@ -268,16 +265,15 @@ OMEGA_EDIT_EXPORT int omega_session_byte_frequency_profile(const omega_session_t * @param length number of bytes from the offset to stop counting characters (if 0, it will count to the end of the session) * @return zero on success and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_session_character_counts(const omega_session_t *session_ptr, - omega_character_counts_t *counts_ptr, int64_t offset, - int64_t length); +int omega_session_character_counts(const omega_session_t *session_ptr, omega_character_counts_t *counts_ptr, + int64_t offset, int64_t length); /** * Given a session, return the checkpoint directory * @param session_ptr session to get the checkpoint directory for * @return checkpoint directory */ -OMEGA_EDIT_EXPORT const char *omega_session_get_checkpoint_directory(const omega_session_t *session_ptr); +const char *omega_session_get_checkpoint_directory(const omega_session_t *session_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/stl_string_adaptor.hpp b/core/src/include/omega_edit/stl_string_adaptor.hpp index 93853b43a..fad70ece9 100644 --- a/core/src/include/omega_edit/stl_string_adaptor.hpp +++ b/core/src/include/omega_edit/stl_string_adaptor.hpp @@ -20,8 +20,6 @@ #ifndef OMEGA_EDIT_STL_STRING_ADAPTOR_HPP #define OMEGA_EDIT_STL_STRING_ADAPTOR_HPP -#include "export.h" - #ifdef __cplusplus #include "change.h" @@ -37,14 +35,14 @@ * @param change_ptr change to get the data from * @return change data as a string */ -OMEGA_EDIT_EXPORT std::string omega_change_get_string(const omega_change_t *change_ptr) noexcept; +std::string omega_change_get_string(const omega_change_t *change_ptr) noexcept; /** * Given a viewport, return the viewport data as a string * @param viewport_ptr viewport to get the viewport data from * @return viewport data as a string */ -OMEGA_EDIT_EXPORT std::string omega_viewport_get_string(const omega_viewport_t *viewport_ptr) noexcept; +std::string omega_viewport_get_string(const omega_viewport_t *viewport_ptr) noexcept; /** * Insert a string at the given offset @@ -53,8 +51,7 @@ OMEGA_EDIT_EXPORT std::string omega_viewport_get_string(const omega_viewport_t * * @param str string to insert at the given offset * @return positive change serial number on success, zero otherwise */ -OMEGA_EDIT_EXPORT int64_t omega_edit_insert_string(omega_session_t *session_ptr, int64_t offset, - const std::string_view &str) noexcept; +int64_t omega_edit_insert_string(omega_session_t *session_ptr, int64_t offset, const std::string_view &str) noexcept; /** * Overwrite bytes at the given offset with the given new string @@ -63,8 +60,7 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_insert_string(omega_session_t *session_ptr, * @param str new string to overwrite the old bytes with * @return positive change serial number on success, zero otherwise */ -OMEGA_EDIT_EXPORT int64_t omega_edit_overwrite_string(omega_session_t *session_ptr, int64_t offset, - const std::string_view &str) noexcept; +int64_t omega_edit_overwrite_string(omega_session_t *session_ptr, int64_t offset, const std::string_view &str) noexcept; /** * Gets a segment of data from the given session @@ -73,8 +69,8 @@ OMEGA_EDIT_EXPORT int64_t omega_edit_overwrite_string(omega_session_t *session_p * @param length length of the desired segment from the given offset * @return string containing the desired segment of data */ -OMEGA_EDIT_EXPORT std::string omega_session_get_segment_string(const omega_session_t *session_ptr, int64_t offset, - int64_t length) noexcept; +std::string omega_session_get_segment_string(const omega_session_t *session_ptr, int64_t offset, + int64_t length) noexcept; /** * Create a search context * @param session_ptr session to find patterns in @@ -88,12 +84,10 @@ OMEGA_EDIT_EXPORT std::string omega_session_get_segment_string(const omega_sessi * @warning Ensure that the pattern length does not exceed the session_length - session_offset. This is considered an * error and a null pointer will be returned. */ -OMEGA_EDIT_EXPORT omega_search_context_t *omega_search_create_context_string(omega_session_t *session_ptr, - const std::string_view &pattern, - int64_t session_offset = 0, - int64_t session_length = 0, - bool case_insensitive = false, - bool reverse_search = false) noexcept; +omega_search_context_t *omega_search_create_context_string(omega_session_t *session_ptr, + const std::string_view &pattern, int64_t session_offset = 0, + int64_t session_length = 0, bool case_insensitive = false, + bool reverse_search = false) noexcept; #endif//__cplusplus diff --git a/core/src/include/omega_edit/utility.h b/core/src/include/omega_edit/utility.h index dc6f9f962..d47e762c3 100644 --- a/core/src/include/omega_edit/utility.h +++ b/core/src/include/omega_edit/utility.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_UTILITY_H #include "byte.h" -#include "export.h" #include "filesystem.h" #include "fwd_defs.h" @@ -43,7 +42,7 @@ extern "C" { * @param mode file mode * @return file mode modulo umask */ -OMEGA_EDIT_EXPORT int omega_util_compute_mode(int mode); +int omega_util_compute_mode(int mode); /** * Generate a temporary file name based on tmpl. The name constructed does not exist at the time of the call. @@ -52,7 +51,7 @@ OMEGA_EDIT_EXPORT int omega_util_compute_mode(int mode); * @param mode mode to set the file to, if zero then the mode is set to 0600 modulo umask * @return read-write file descriptor opened with mode 0600 modulo umask or -1 with errno set on error */ -OMEGA_EDIT_EXPORT int omega_util_mkstemp(char *tmpl, int mode); +int omega_util_mkstemp(char *tmpl, int mode); /** * Write a segment from one file into another file @@ -62,8 +61,7 @@ OMEGA_EDIT_EXPORT int omega_util_mkstemp(char *tmpl, int mode); * @param to_file_ptr to file pointer, opened for writing and positioned to where to write the segment to * @return number of bytes that where successfully written */ -OMEGA_EDIT_EXPORT int64_t omega_util_write_segment_to_file(FILE *from_file_ptr, int64_t offset, int64_t byte_count, - FILE *to_file_ptr); +int64_t omega_util_write_segment_to_file(FILE *from_file_ptr, int64_t offset, int64_t byte_count, FILE *to_file_ptr); /** * Shift the bits of the given buffer by a given number of bits to the left @@ -72,7 +70,7 @@ OMEGA_EDIT_EXPORT int64_t omega_util_write_segment_to_file(FILE *from_file_ptr, * @param shift_left number of bits (greater than 0 and less than 8) to shift to the left * @return zero on success, non-zero on failure */ -OMEGA_EDIT_EXPORT int omega_util_left_shift_buffer(omega_byte_t *buffer, int64_t len, omega_byte_t shift_left); +int omega_util_left_shift_buffer(omega_byte_t *buffer, int64_t len, omega_byte_t shift_left); /** * Shift the bits of the given buffer by a given number of bits to the right @@ -81,7 +79,7 @@ OMEGA_EDIT_EXPORT int omega_util_left_shift_buffer(omega_byte_t *buffer, int64_t * @param shift_right number of bits (greater than 0 and less than 8) to shift to the right * @return zero on success, non-zero on failure */ -OMEGA_EDIT_EXPORT int omega_util_right_shift_buffer(omega_byte_t *buffer, int64_t len, omega_byte_t shift_right); +int omega_util_right_shift_buffer(omega_byte_t *buffer, int64_t len, omega_byte_t shift_right); /** * Byte transform function pointer @@ -95,8 +93,8 @@ typedef omega_byte_t (*omega_util_byte_transform_t)(omega_byte_t, void *user_dat * @param transform transform function to apply to the bytes in the buffer * @param user_data_ptr pointer to user-defined data to associate with the transformer */ -OMEGA_EDIT_EXPORT void omega_util_apply_byte_transform(omega_byte_t *buffer, int64_t len, - omega_util_byte_transform_t transform, void *user_data_ptr); +void omega_util_apply_byte_transform(omega_byte_t *buffer, int64_t len, omega_util_byte_transform_t transform, + void *user_data_ptr); /** * Apply the given transform to the input file and write the transformed data to the output file @@ -108,9 +106,9 @@ OMEGA_EDIT_EXPORT void omega_util_apply_byte_transform(omega_byte_t *buffer, int * @param length number of bytes to transform from the given offset * @return zero on success, non-zero on failure */ -OMEGA_EDIT_EXPORT int omega_util_apply_byte_transform_to_file(char const *in_path, char const *out_path, - omega_util_byte_transform_t transform, - void *user_data_ptr, int64_t offset, int64_t length); +int omega_util_apply_byte_transform_to_file(char const *in_path, char const *out_path, + omega_util_byte_transform_t transform, void *user_data_ptr, int64_t offset, + int64_t length); /** * Apply the given mask of the given mask kind to the given byte @@ -119,7 +117,7 @@ OMEGA_EDIT_EXPORT int omega_util_apply_byte_transform_to_file(char const *in_pat * @param mask_kind mask kind (e.g., MASK_AND, MASK_OR, MASK_XOR) * @return masked byte */ -OMEGA_EDIT_EXPORT omega_byte_t omega_util_mask_byte(omega_byte_t byte, omega_byte_t mask, omega_mask_kind_t mask_kind); +omega_byte_t omega_util_mask_byte(omega_byte_t byte, omega_byte_t mask, omega_mask_kind_t mask_kind); /** * Compares sz bytes of two character strings @@ -128,7 +126,7 @@ OMEGA_EDIT_EXPORT omega_byte_t omega_util_mask_byte(omega_byte_t byte, omega_byt * @param sz number of bytes to compare * @return zero if sz bytes of the two character strings match, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_strncmp(const char *s1, const char *s2, uint64_t sz); +int omega_util_strncmp(const char *s1, const char *s2, uint64_t sz); /** * Compares sz bytes of two character strings, without regard to case (case insensitive) @@ -137,7 +135,7 @@ OMEGA_EDIT_EXPORT int omega_util_strncmp(const char *s1, const char *s2, uint64_ * @param sz number of bytes to compare * @return zero if sz bytes of the two character strings match, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_util_strnicmp(const char *s1, const char *s2, uint64_t sz); +int omega_util_strnicmp(const char *s1, const char *s2, uint64_t sz); /** * Cross-platform strndup work-alike @@ -145,7 +143,7 @@ OMEGA_EDIT_EXPORT int omega_util_strnicmp(const char *s1, const char *s2, uint64 * @param n length of the string to duplicate * @return duplicated , null terminated string, allocated with malloc, or NULL on failure */ -OMEGA_EDIT_EXPORT char *omega_util_strndup(const char *s, size_t n); +char *omega_util_strndup(const char *s, size_t n); /** * Cross-platform memrchr work-alike @@ -153,7 +151,7 @@ OMEGA_EDIT_EXPORT char *omega_util_strndup(const char *s, size_t n); * @param c byte to search for * @param n number of bytes to search */ -OMEGA_EDIT_EXPORT const void *omega_util_memrchr(const void *s, int c, size_t n); +const void *omega_util_memrchr(const void *s, int c, size_t n); /** * Detect the byte order mark (BOM) of the given memory @@ -161,21 +159,21 @@ OMEGA_EDIT_EXPORT const void *omega_util_memrchr(const void *s, int c, size_t n) * @param length length of the memory to detect the BOM of * @return BOM_NONE if no BOM is detected, otherwise the detected BOM */ -OMEGA_EDIT_EXPORT omega_bom_t omega_util_detect_BOM_from_memory(const unsigned char *data, size_t length); +omega_bom_t omega_util_detect_BOM_from_memory(const unsigned char *data, size_t length); /** * Detect the byte order mark (BOM) of the given file * @param filename path of the file to detect the BOM of * @return BOM_NONE if no BOM is detected, otherwise the detected BOM */ -OMEGA_EDIT_EXPORT omega_bom_t omega_util_detect_BOM_from_file(const char *filename); +omega_bom_t omega_util_detect_BOM_from_file(const char *filename); /** * Convert the given byte order mark (BOM) to a string * @param bom byte order mark (BOM) to convert * @return string representation of the given BOM */ -OMEGA_EDIT_EXPORT char const *omega_util_BOM_to_string(omega_bom_t bom); +char const *omega_util_BOM_to_string(omega_bom_t bom); /** * Count the number of single byte, and multi-byte characters in the given data @@ -184,13 +182,16 @@ OMEGA_EDIT_EXPORT char const *omega_util_BOM_to_string(omega_bom_t bom); * @param counts_ptr pointer to the character counts to populate * @note make sure the BOM is set in the given character counts before calling this function */ -OMEGA_EDIT_EXPORT void omega_util_count_characters(const unsigned char* data, size_t length, omega_character_counts_t* counts_ptr); +void omega_util_count_characters(const unsigned char *data, size_t length, omega_character_counts_t *counts_ptr); /** * Byte buffer */ typedef struct { + /** The data in the buffer */ const omega_byte_t *data; + + /** The length of the buffer */ size_t length; } omega_byte_buffer_t; @@ -199,7 +200,7 @@ typedef struct { * @param bom byte order mark (BOM) to get * @return byte buffer containing the given BOM, or NULL if the given BOM is BOM_NONE */ -OMEGA_EDIT_EXPORT const omega_byte_buffer_t* omega_util_BOM_to_buffer(omega_bom_t bom); +const omega_byte_buffer_t *omega_util_BOM_to_buffer(omega_bom_t bom); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/version.h b/core/src/include/omega_edit/version.h index ed4c63400..013fdfeaa 100644 --- a/core/src/include/omega_edit/version.h +++ b/core/src/include/omega_edit/version.h @@ -22,8 +22,6 @@ #ifndef OMEGA_EDIT_VERSION_H #define OMEGA_EDIT_VERSION_H -#include "export.h" - #ifdef __cplusplus extern "C" { #endif @@ -32,19 +30,19 @@ extern "C" { * Get the major version of the library * @return the major version of the library */ -OMEGA_EDIT_EXPORT int omega_version_major(); +int omega_version_major(); /** * Get the minor version of the library * @return the minor version of the library */ -OMEGA_EDIT_EXPORT int omega_version_minor(); +int omega_version_minor(); /** * Get the patch-level of the library * @return the patch-level of the library */ -OMEGA_EDIT_EXPORT int omega_version_patch(); +int omega_version_patch(); /** * Get the integer representation of the version of the library @@ -56,7 +54,7 @@ OMEGA_EDIT_EXPORT int omega_version_patch(); * auto patch = version & 0xFF; * @endcode */ -OMEGA_EDIT_EXPORT int omega_version(); +int omega_version(); /** * Returns "shared" if the library has been built as a shared library, or "static" if the library is built as a static @@ -64,7 +62,7 @@ OMEGA_EDIT_EXPORT int omega_version(); * @return "shared" if the library has been built as a shared library, or "static" if the library is built as a static * library */ -OMEGA_EDIT_EXPORT char const *omega_libtype(); +char const *omega_libtype(); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/viewport.h b/core/src/include/omega_edit/viewport.h index 94c878aa3..981c7e7fc 100644 --- a/core/src/include/omega_edit/viewport.h +++ b/core/src/include/omega_edit/viewport.h @@ -21,7 +21,6 @@ #define OMEGA_EDIT_VIEWPORT_H #include "byte.h" -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -40,77 +39,77 @@ extern "C" { * @param viewport_ptr viewport to get the session pointer from * @return viewport session pointer */ -OMEGA_EDIT_EXPORT const omega_session_t *omega_viewport_get_session(const omega_viewport_t *viewport_ptr); +const omega_session_t *omega_viewport_get_session(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the viewport capacity * @param viewport_ptr viewport to get the capacity from * @return viewport capacity */ -OMEGA_EDIT_EXPORT int64_t omega_viewport_get_capacity(const omega_viewport_t *viewport_ptr); +int64_t omega_viewport_get_capacity(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the viewport data length * @param viewport_ptr viewport to get the viewport data length from * @return viewport data length */ -OMEGA_EDIT_EXPORT int64_t omega_viewport_get_length(const omega_viewport_t *viewport_ptr); +int64_t omega_viewport_get_length(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the viewport data * @param viewport_ptr viewport to get the viewport data from * @return viewport data */ -OMEGA_EDIT_EXPORT const omega_byte_t *omega_viewport_get_data(const omega_viewport_t *viewport_ptr); +const omega_byte_t *omega_viewport_get_data(const omega_viewport_t *viewport_ptr); /** * Given a viewport, determine if it contains changes since the last omega_viewport_get_data call * @param viewport_ptr viewport to determine if changes are present * @return 0 if there are no changes present, and non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_viewport_has_changes(const omega_viewport_t *viewport_ptr); +int omega_viewport_has_changes(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the viewport offset * @param viewport_ptr viewport to get the viewport offset from * @return viewport offset */ -OMEGA_EDIT_EXPORT int64_t omega_viewport_get_offset(const omega_viewport_t *viewport_ptr); +int64_t omega_viewport_get_offset(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return non-zero if the viewport is floating and zero if the viewport is fixed * @param viewport_ptr viewport to determine if its floating or not * @return non-zero if the viewport is floating and zero if the viewport is fixed */ -OMEGA_EDIT_EXPORT int omega_viewport_is_floating(const omega_viewport_t *viewport_ptr); +int omega_viewport_is_floating(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the number of bytes that exist after the viewport * @param viewport_ptr viewport to get the number of bytes that exist after the viewport from * @return number of bytes that exist after the viewport */ -OMEGA_EDIT_EXPORT int64_t omega_viewport_get_following_byte_count(const omega_viewport_t *viewport_ptr); +int64_t omega_viewport_get_following_byte_count(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the viewport user data * @param viewport_ptr viewport to get the user data from * @return viewport user data */ -OMEGA_EDIT_EXPORT void *omega_viewport_get_user_data_ptr(const omega_viewport_t *viewport_ptr); +void *omega_viewport_get_user_data_ptr(const omega_viewport_t *viewport_ptr); /** * Given a session, return the viewport event callback * @param viewport_ptr viewport to return the event callback from * @return viewport event callback */ -OMEGA_EDIT_EXPORT omega_viewport_event_cbk_t omega_viewport_get_event_cbk(const omega_viewport_t *viewport_ptr); +omega_viewport_event_cbk_t omega_viewport_get_event_cbk(const omega_viewport_t *viewport_ptr); /** * Given a viewport, return the viewport event interest * @param viewport_ptr viewport to return the viewport event interest from * @return viewport event interest */ -OMEGA_EDIT_EXPORT int32_t omega_viewport_get_event_interest(const omega_viewport_t *viewport_ptr); +int32_t omega_viewport_get_event_interest(const omega_viewport_t *viewport_ptr); /** * Set the viewport event interest to the given viewport event interest for the the given viewport @@ -118,7 +117,7 @@ OMEGA_EDIT_EXPORT int32_t omega_viewport_get_event_interest(const omega_viewport * @param event_interest desired viewport event interest * @return viewport event interest */ -OMEGA_EDIT_EXPORT int32_t omega_viewport_set_event_interest(omega_viewport_t *viewport_ptr, int32_t event_interest); +int32_t omega_viewport_set_event_interest(omega_viewport_t *viewport_ptr, int32_t event_interest); /** * Change viewport settings @@ -129,8 +128,7 @@ OMEGA_EDIT_EXPORT int32_t omega_viewport_set_event_interest(omega_viewport_t *vi * "float" as bytes are inserted or deleted before the start of this viewport * @return 0 on success, non-zero otherwise */ -OMEGA_EDIT_EXPORT int omega_viewport_modify(omega_viewport_t *viewport_ptr, int64_t offset, int64_t capacity, - int is_floating); +int omega_viewport_modify(omega_viewport_t *viewport_ptr, int64_t offset, int64_t capacity, int is_floating); /** * Determine if the given viewport is in the given segment @@ -139,7 +137,7 @@ OMEGA_EDIT_EXPORT int omega_viewport_modify(omega_viewport_t *viewport_ptr, int6 * @param length length of the segment * @return non-zero if the viewport is in the given segment and zero otherwise */ -OMEGA_EDIT_EXPORT int omega_viewport_in_segment(const omega_viewport_t *viewport_ptr, int64_t offset, int64_t length); +int omega_viewport_in_segment(const omega_viewport_t *viewport_ptr, int64_t offset, int64_t length); /** * Execute the viewport on-change callback with the given change if a viewport on-change callback is defined and if the @@ -149,8 +147,8 @@ OMEGA_EDIT_EXPORT int omega_viewport_in_segment(const omega_viewport_t *viewport * @param event_ptr change responsible for the viewport change (if any) * @return 1 if the viewport on-change callback was executed, 0 if the viewport on-change callback was not executed */ -OMEGA_EDIT_EXPORT int omega_viewport_notify(const omega_viewport_t *viewport_ptr, omega_viewport_event_t viewport_event, - const void *event_ptr); +int omega_viewport_notify(const omega_viewport_t *viewport_ptr, omega_viewport_event_t viewport_event, + const void *event_ptr); #ifdef __cplusplus } diff --git a/core/src/include/omega_edit/visit.h b/core/src/include/omega_edit/visit.h index 8ea8751de..57225db27 100644 --- a/core/src/include/omega_edit/visit.h +++ b/core/src/include/omega_edit/visit.h @@ -20,7 +20,6 @@ #ifndef OMEGA_EDIT_VISIT_H #define OMEGA_EDIT_VISIT_H -#include "export.h" #include "fwd_defs.h" #ifdef __cplusplus @@ -43,8 +42,7 @@ typedef int (*omega_session_change_visitor_cbk_t)(const omega_change_t *, void * * @param user_data user-provided data to provide back to the callback * @return 0 if all changes were visited or the non-zero return value of the callback if visitation was stopped early */ -OMEGA_EDIT_EXPORT int omega_visit_changes(const omega_session_t *session_ptr, omega_session_change_visitor_cbk_t cbk, - void *user_data); +int omega_visit_changes(const omega_session_t *session_ptr, omega_session_change_visitor_cbk_t cbk, void *user_data); /** * Visit changes in the given session in reverse chronological order (newest first), if the callback returns an integer @@ -54,8 +52,8 @@ OMEGA_EDIT_EXPORT int omega_visit_changes(const omega_session_t *session_ptr, om * @param user_data user-provided data to provide back to the callback * @return 0 if all changes were visited or the non-zero return value of the callback if visitation was stopped early */ -OMEGA_EDIT_EXPORT int omega_visit_changes_reverse(const omega_session_t *session_ptr, - omega_session_change_visitor_cbk_t cbk, void *user_data); +int omega_visit_changes_reverse(const omega_session_t *session_ptr, omega_session_change_visitor_cbk_t cbk, + void *user_data); /** * Opaque visit change context @@ -68,43 +66,41 @@ typedef struct omega_visit_change_context_struct omega_visit_change_context_t; * @param reverse non-zero to reverse the visitation chronology (newest change to oldest change) * @return change visitor context */ -OMEGA_EDIT_EXPORT omega_visit_change_context_t *omega_visit_change_create_context(const omega_session_t *session_ptr, - int reverse); +omega_visit_change_context_t *omega_visit_change_create_context(const omega_session_t *session_ptr, int reverse); /** * Return non-zero if we are at the end of the change visitations * @param change_context_ptr change visitor context to see if we're at the end of * @return non-zero if we are at the end of the change visitations and zero if there are changes remaining to visit */ -OMEGA_EDIT_EXPORT int omega_visit_change_at_end(const omega_visit_change_context_t *change_context_ptr); +int omega_visit_change_at_end(const omega_visit_change_context_t *change_context_ptr); /** * Set the change visitor context to the beginning of the changes * @param change_context_ptr change visitor context to set to the beginning * @return non-zero if there are no changes to visit and zero otherwise */ -OMEGA_EDIT_EXPORT int omega_visit_change_begin(omega_visit_change_context_t *change_context_ptr); +int omega_visit_change_begin(omega_visit_change_context_t *change_context_ptr); /** * Given a change visitor context, find the next change * @param change_context_ptr change visitor context to find the next change in * @return non-zero if a change is found, zero otherwise */ -OMEGA_EDIT_EXPORT int omega_visit_change_next(omega_visit_change_context_t *change_context_ptr); +int omega_visit_change_next(omega_visit_change_context_t *change_context_ptr); /** * Given a change visitor context, get a pointer to the change * @param change_context_ptr change visitor context to get the change from * @return pointer to the change, or nullptr if no change is found */ -OMEGA_EDIT_EXPORT const omega_change_t * -omega_visit_change_context_get_change(const omega_visit_change_context_t *change_context_ptr); +const omega_change_t *omega_visit_change_context_get_change(const omega_visit_change_context_t *change_context_ptr); /** * Destroy the given change visitor context * @param change_context_ptr change visitor context to destroy */ -OMEGA_EDIT_EXPORT void omega_visit_change_destroy_context(omega_visit_change_context_t *change_context_ptr); +void omega_visit_change_destroy_context(omega_visit_change_context_t *change_context_ptr); #ifdef __cplusplus } diff --git a/core/src/lib/change.cpp b/core/src/lib/change.cpp index 8961bf87b..f7a29b6c2 100644 --- a/core/src/lib/change.cpp +++ b/core/src/lib/change.cpp @@ -38,8 +38,8 @@ int64_t omega_change_get_serial(const omega_change_t *change_ptr) { static inline const omega_byte_t *change_bytes_(const omega_change_t *change_ptr) { assert(change_ptr); return (omega_change_get_kind(change_ptr) != change_kind_t::CHANGE_DELETE) - ? omega_data_get_data_const(&change_ptr->data, change_ptr->length) - : nullptr; + ? omega_data_get_data_const(&change_ptr->data, change_ptr->length) + : nullptr; } const omega_byte_t *omega_change_get_bytes(const omega_change_t *change_ptr) { diff --git a/core/src/lib/check.cpp b/core/src/lib/check.cpp index d6bcd3124..fce791c46 100644 --- a/core/src/lib/check.cpp +++ b/core/src/lib/check.cpp @@ -23,9 +23,9 @@ int omega_check_model(const omega_session_t *session_ptr) { assert(session_ptr); int64_t expected_offset = 0; if (!session_ptr->models_.empty()) { - for (auto &&model_ptr: session_ptr->models_) { + for (auto &&model_ptr : session_ptr->models_) { assert(model_ptr); - for (const auto &segment: model_ptr->model_segments) { + for (const auto &segment : model_ptr->model_segments) { assert(segment->change_ptr); if (expected_offset != segment->computed_offset || (segment->change_offset + segment->computed_length) > segment->change_ptr->length) { diff --git a/core/src/lib/edit.cpp b/core/src/lib/edit.cpp index 48cdece28..6c6cc536e 100644 --- a/core/src/lib/edit.cpp +++ b/core/src/lib/edit.cpp @@ -143,7 +143,7 @@ static inline bool change_affects_viewport_(const omega_viewport_t *viewport_ptr } static int update_viewports_(const omega_session_t *session_ptr, const omega_change_t *change_ptr) { - for (auto &&viewport_ptr: session_ptr->viewports_) { + for (auto &&viewport_ptr : session_ptr->viewports_) { // possibly adjust the viewport offset if it's floating and other criteria are met update_viewport_offset_adjustment_(viewport_ptr.get(), change_ptr); if (change_affects_viewport_(viewport_ptr.get(), change_ptr)) { @@ -167,7 +167,7 @@ static inline omega_model_segment_ptr_t clone_model_segment_(const omega_model_s } static inline void free_model_changes_(omega_model_struct *model_ptr) { - for (const auto &change_ptr: model_ptr->changes) { + for (const auto &change_ptr : model_ptr->changes) { if (omega_change_get_kind(change_ptr.get()) != change_kind_t::CHANGE_DELETE) { omega_data_destroy(&const_cast(change_ptr.get())->data, change_ptr->length); } @@ -176,7 +176,7 @@ static inline void free_model_changes_(omega_model_struct *model_ptr) { } static inline void free_model_changes_undone_(omega_model_struct *model_ptr) { - for (const auto &change_ptr: model_ptr->changes_undone) { + for (const auto &change_ptr : model_ptr->changes_undone) { if (omega_change_get_kind(change_ptr.get()) != change_kind_t::CHANGE_DELETE) { omega_data_destroy(&const_cast(change_ptr.get())->data, change_ptr->length); } @@ -185,11 +185,11 @@ static inline void free_model_changes_undone_(omega_model_struct *model_ptr) { } static inline void free_session_changes_(const omega_session_t *session_ptr) { - for (auto &&model_ptr: session_ptr->models_) { free_model_changes_(model_ptr.get()); } + for (auto &&model_ptr : session_ptr->models_) { free_model_changes_(model_ptr.get()); } } static inline void free_session_changes_undone_(const omega_session_t *session_ptr) { - for (auto &&model_ptr: session_ptr->models_) { free_model_changes_undone_(model_ptr.get()); } + for (auto &&model_ptr : session_ptr->models_) { free_model_changes_undone_(model_ptr.get()); } } /* -------------------------------------------------------------------------------------------------------------------- @@ -216,8 +216,8 @@ static int update_model_helper_(omega_model_t *model_ptr, const const_omega_chan for (auto iter = model_ptr->model_segments.begin(); iter != model_ptr->model_segments.end(); ++iter) { if (read_offset != (*iter)->computed_offset) { ABORT(print_model_segments_(model_ptr, CLOG); - LOG_ERROR("break in model continuity, expected: " << read_offset - << ", got: " << (*iter)->computed_offset);); + LOG_ERROR("break in model continuity, expected: " << read_offset + << ", got: " << (*iter)->computed_offset);); } if (change_ptr->offset >= read_offset && change_ptr->offset <= read_offset + (*iter)->computed_length) { if (change_ptr->offset != read_offset) { @@ -395,7 +395,7 @@ omega_session_t *omega_edit_create_session(const char *file_path, omega_session_ void omega_edit_destroy_session(omega_session_t *session_ptr) { assert(session_ptr); // Close all open files in the models - for (const auto &model_ptr: session_ptr->models_) { + for (const auto &model_ptr : session_ptr->models_) { if (model_ptr->file_ptr) { fclose(model_ptr->file_ptr); } } // Destroy all search contexts @@ -482,19 +482,19 @@ inline bool determine_change_transaction_bit_(omega_session_t *session_ptr) { int64_t omega_edit_delete(omega_session_t *session_ptr, int64_t offset, int64_t length) { const auto computed_file_size = omega_session_get_computed_file_size(session_ptr); return !omega_session_changes_paused(session_ptr) && 0 < length && offset < computed_file_size - ? update_(session_ptr, del_(1 + omega_session_get_num_changes(session_ptr), offset, - std::min(length, computed_file_size - offset), - determine_change_transaction_bit_(session_ptr))) - : 0; + ? update_(session_ptr, del_(1 + omega_session_get_num_changes(session_ptr), offset, + std::min(length, computed_file_size - offset), + determine_change_transaction_bit_(session_ptr))) + : 0; } int64_t omega_edit_insert_bytes(omega_session_t *session_ptr, int64_t offset, const omega_byte_t *bytes, int64_t length) { return !omega_session_changes_paused(session_ptr) && 0 <= length && - offset <= omega_session_get_computed_file_size(session_ptr) - ? update_(session_ptr, ins_(1 + omega_session_get_num_changes(session_ptr), offset, bytes, length, - determine_change_transaction_bit_(session_ptr))) - : 0; + offset <= omega_session_get_computed_file_size(session_ptr) + ? update_(session_ptr, ins_(1 + omega_session_get_num_changes(session_ptr), offset, bytes, length, + determine_change_transaction_bit_(session_ptr))) + : 0; } int64_t omega_edit_insert(omega_session_t *session_ptr, int64_t offset, const char *cstr, int64_t length) { @@ -504,10 +504,10 @@ int64_t omega_edit_insert(omega_session_t *session_ptr, int64_t offset, const ch int64_t omega_edit_overwrite_bytes(omega_session_t *session_ptr, int64_t offset, const omega_byte_t *bytes, int64_t length) { return !omega_session_changes_paused(session_ptr) && 0 <= length && - offset <= omega_session_get_computed_file_size(session_ptr) - ? update_(session_ptr, ovr_(1 + omega_session_get_num_changes(session_ptr), offset, bytes, length, - determine_change_transaction_bit_(session_ptr))) - : 0; + offset <= omega_session_get_computed_file_size(session_ptr) + ? update_(session_ptr, ovr_(1 + omega_session_get_num_changes(session_ptr), offset, bytes, length, + determine_change_transaction_bit_(session_ptr))) + : 0; } int64_t omega_edit_overwrite(omega_session_t *session_ptr, int64_t offset, const char *cstr, int64_t length) { @@ -525,7 +525,7 @@ int omega_edit_apply_transform(omega_session_t *session_ptr, omega_util_byte_tra if (0 == fclose(session_ptr->models_.back()->file_ptr) && 0 == omega_util_remove_file(in_file.c_str()) && 0 == rename(out_file.c_str(), in_file.c_str()) && (session_ptr->models_.back()->file_ptr = fopen(in_file.c_str(), "rb"))) { - for (const auto &viewport_ptr: session_ptr->viewports_) { + for (const auto &viewport_ptr : session_ptr->viewports_) { viewport_ptr->data_segment.capacity = -1 * std::abs(viewport_ptr->data_segment.capacity);// indicate dirty read omega_viewport_notify(viewport_ptr.get(), VIEWPORT_EVT_TRANSFORM, nullptr); @@ -552,8 +552,8 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, const auto adjusted_length = length <= 0 ? computed_file_size - offset : std::min(length, computed_file_size - offset); if (adjusted_length < 0) { - LOG_ERROR("invalid offset: " << offset << ", length: " << length << ", adjusted_length: " - << adjusted_length << ", computed_file_size: " << computed_file_size); + LOG_ERROR("invalid offset: " << offset << ", length: " << length << ", adjusted_length: " << adjusted_length + << ", computed_file_size: " << computed_file_size); return -1; } char temp_filename[FILENAME_MAX]; @@ -587,9 +587,9 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, errno = 0;// reset errno const auto temp_filename_str = std::string(temp_filename); const auto count = temp_filename_str.empty() - ? snprintf(temp_filename, FILENAME_MAX, ".OmegaEdit_XXXXXX") - : snprintf(temp_filename, FILENAME_MAX, "%s%c.OmegaEdit_XXXXXX", - temp_filename_str.c_str(), omega_util_directory_separator()); + ? snprintf(temp_filename, FILENAME_MAX, ".OmegaEdit_XXXXXX") + : snprintf(temp_filename, FILENAME_MAX, "%s%c.OmegaEdit_XXXXXX", + temp_filename_str.c_str(), omega_util_directory_separator()); if (count < 0 || FILENAME_MAX <= count) { LOG_ERRNO(); return -3; @@ -610,7 +610,7 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, } int64_t write_offset = 0; int64_t bytes_written = 0; - for (const auto &segment: session_ptr->models_.back()->model_segments) { + for (const auto &segment : session_ptr->models_.back()->model_segments) { if (write_offset != segment->computed_offset) { ABORT(LOG_ERROR("break in model continuity, expected: " << write_offset << ", got: " << segment->computed_offset);); @@ -622,9 +622,7 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, } // Break the loop if we've written all the data that needs to be written - if (bytes_written >= adjusted_length) { - break; - } + if (bytes_written >= adjusted_length) { break; } // Calculate how much to write from this segment int64_t segment_start = std::max(offset - write_offset, int64_t(0)); @@ -636,8 +634,8 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, ABORT(LOG_ERROR("attempt to read segment from null file pointer");); } if (omega_util_write_segment_to_file(session_ptr->models_.back()->file_ptr, - segment->change_offset + segment_start, - segment_length, temp_fptr) != segment_length) { + segment->change_offset + segment_start, segment_length, + temp_fptr) != segment_length) { fclose(temp_fptr); omega_util_remove_file(temp_filename); LOG_ERROR("omega_util_write_segment_to_file failed"); @@ -646,10 +644,9 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, break; } case model_segment_kind_t::SEGMENT_INSERT: { - if (static_cast( - fwrite(omega_change_get_bytes(segment->change_ptr.get()) + segment->change_offset + - segment_start, 1, - segment_length, temp_fptr)) != segment_length) { + if (static_cast(fwrite(omega_change_get_bytes(segment->change_ptr.get()) + + segment->change_offset + segment_start, + 1, segment_length, temp_fptr)) != segment_length) { fclose(temp_fptr); omega_util_remove_file(temp_filename); LOG_ERROR("fwrite failed"); @@ -718,7 +715,7 @@ int omega_edit_clear_changes(omega_session_t *session_ptr) { initialize_model_segments_(session_ptr->models_.front()->model_segments, length); free_session_changes_(session_ptr); free_session_changes_undone_(session_ptr); - for (const auto &viewport_ptr: session_ptr->viewports_) { + for (const auto &viewport_ptr : session_ptr->viewports_) { viewport_ptr->data_segment.capacity = -1 * std::abs(viewport_ptr->data_segment.capacity);// indicate dirty read omega_viewport_notify(viewport_ptr.get(), VIEWPORT_EVT_CLEAR, nullptr); } @@ -736,7 +733,7 @@ int64_t omega_edit_undo_last_change(omega_session_t *session_ptr) { length = FTELL(session_ptr->models_.back()->file_ptr); } initialize_model_segments_(session_ptr->models_.back()->model_segments, length); - for (const auto &change: session_ptr->models_.back()->changes) { + for (const auto &change : session_ptr->models_.back()->changes) { if (0 > update_model_(session_ptr, change)) { return -1; } } @@ -751,7 +748,7 @@ int64_t omega_edit_undo_last_change(omega_session_t *session_ptr) { // If the undone change is part of a transaction, then undo the entire transaction if (!session_ptr->models_.back()->changes.empty() && omega_change_get_transaction_bit_(undone_change_ptr) == - omega_change_get_transaction_bit_(session_ptr->models_.back()->changes.back().get())) { + omega_change_get_transaction_bit_(session_ptr->models_.back()->changes.back().get())) { return omega_edit_undo_last_change(session_ptr); } @@ -769,7 +766,7 @@ int64_t omega_edit_redo_last_undo(omega_session_t *session_ptr) { // If the redone change is part of a transaction, then redo the entire transaction if (!session_ptr->models_.back()->changes_undone.empty() && omega_change_get_transaction_bit_(change_ptr.get()) == - omega_change_get_transaction_bit_(session_ptr->models_.back()->changes_undone.back().get())) { + omega_change_get_transaction_bit_(session_ptr->models_.back()->changes_undone.back().get())) { rc = omega_edit_redo_last_undo(session_ptr); } } diff --git a/core/src/lib/filesystem.cpp b/core/src/lib/filesystem.cpp index 5df830b0d..5490c8008 100644 --- a/core/src/lib/filesystem.cpp +++ b/core/src/lib/filesystem.cpp @@ -75,7 +75,8 @@ int omega_util_compare_modification_times(const char *path1, const char *path2) const auto file2_time = fs::last_write_time(file2_path); if (file1_time > file2_time) return 1; - else if (file1_time < file2_time) return -1; + else if (file1_time < file2_time) + return -1; } catch (const fs::filesystem_error &ex) { LOG_ERROR("Error comparing modification times: " << ex.what()); return -2; @@ -147,9 +148,9 @@ char *omega_util_available_filename(char const *path, char *buffer) { return nullptr; } auto const len = fs::path(dirname) - .append(basename + "-" + std::to_string(i) + extension) - .string() - .copy(buffer, FILENAME_MAX); + .append(basename + "-" + std::to_string(i) + extension) + .string() + .copy(buffer, FILENAME_MAX); buffer[len] = '\0'; } while (omega_util_file_exists(buffer)); return buffer; diff --git a/core/src/lib/impl_/change_def.hpp b/core/src/lib/impl_/change_def.hpp index 587a14b35..5a7eda90e 100644 --- a/core/src/lib/impl_/change_def.hpp +++ b/core/src/lib/impl_/change_def.hpp @@ -19,9 +19,7 @@ #include "data_def.hpp" #include -enum class change_kind_t { - CHANGE_DELETE = 0, CHANGE_INSERT = 1, CHANGE_OVERWRITE = 2 -}; +enum class change_kind_t { CHANGE_DELETE = 0, CHANGE_INSERT = 1, CHANGE_OVERWRITE = 2 }; #define OMEGA_CHANGE_KIND_MASK 0x03 #define OMEGA_CHANGE_TRANSACTION_BIT 0x04 diff --git a/core/src/lib/impl_/character_counts_def.h b/core/src/lib/impl_/character_counts_def.h index d922f5d30..232aeb8cb 100644 --- a/core/src/lib/impl_/character_counts_def.h +++ b/core/src/lib/impl_/character_counts_def.h @@ -31,4 +31,4 @@ struct omega_character_counts_struct { int64_t invalidBytes; }; -#endif //OMEGA_EDIT_CHARACTER_COUNTS_DEF_H +#endif//OMEGA_EDIT_CHARACTER_COUNTS_DEF_H diff --git a/core/src/lib/impl_/find.cpp b/core/src/lib/impl_/find.cpp index e41f63513..67763fd8e 100644 --- a/core/src/lib/impl_/find.cpp +++ b/core/src/lib/impl_/find.cpp @@ -23,7 +23,7 @@ struct omega_find_skip_table_t : public std::vector { int is_reverse_search; omega_find_skip_table_t(std::ptrdiff_t vec_size, std::ptrdiff_t fill, int isReverse) - : std::vector(vec_size, fill), is_reverse_search(isReverse) {} + : std::vector(vec_size, fill), is_reverse_search(isReverse) {} }; int omega_find_is_reversed(const omega_find_skip_table_t *skip_table_ptr) { @@ -35,8 +35,8 @@ int omega_find_is_reversed(const omega_find_skip_table_t *skip_table_ptr) { * Function to create the skip table for Boyer-Moore searching algorithm. Depending on the direction of the search, * it creates a forward skip table or a reverse skip table. */ -const omega_find_skip_table_t * -omega_find_create_skip_table(const unsigned char *needle, size_t needle_length, int is_reverse_search) { +const omega_find_skip_table_t *omega_find_create_skip_table(const unsigned char *needle, size_t needle_length, + int is_reverse_search) { assert(needle); assert(needle_length > 0); @@ -86,25 +86,24 @@ const unsigned char *omega_find(const unsigned char *haystack, size_t haystack_l // If the needle is a single character, use memchr/memrchr instead of the skip table. if (needle_length == 1) { - return skip_table_ptr->is_reverse_search ? - (const unsigned char *) omega_util_memrchr(haystack, *needle, haystack_length) : - (const unsigned char *) std::memchr(haystack, *needle, haystack_length); + return skip_table_ptr->is_reverse_search + ? (const unsigned char *) omega_util_memrchr(haystack, *needle, haystack_length) + : (const unsigned char *) std::memchr(haystack, *needle, haystack_length); } assert(skip_table_ptr); const auto needle_length_minus_1 = needle_length - 1; const auto last_needle_char = skip_table_ptr->is_reverse_search ? needle[0] : needle[needle_length_minus_1]; - std::ptrdiff_t haystack_position = skip_table_ptr->is_reverse_search ? static_cast(haystack_length - - needle_length) - : 0; + std::ptrdiff_t haystack_position = + skip_table_ptr->is_reverse_search ? static_cast(haystack_length - needle_length) : 0; - while (skip_table_ptr->is_reverse_search ? haystack_position >= 0 : haystack_position <= - haystack_length - needle_length) { + while (skip_table_ptr->is_reverse_search ? haystack_position >= 0 + : haystack_position <= haystack_length - needle_length) { const auto skip = haystack[haystack_position + (skip_table_ptr->is_reverse_search ? 0 : needle_length_minus_1)]; - if (const auto probe = haystack + haystack_position; last_needle_char == skip && - std::memcmp(needle, probe, needle_length) == 0) { + if (const auto probe = haystack + haystack_position; + last_needle_char == skip && std::memcmp(needle, probe, needle_length) == 0) { return probe; } diff --git a/core/src/lib/impl_/find.h b/core/src/lib/impl_/find.h index e93dbffc0..7c419e978 100644 --- a/core/src/lib/impl_/find.h +++ b/core/src/lib/impl_/find.h @@ -35,8 +35,8 @@ struct omega_find_skip_table_t; * @param is_reverse_search non-zero if the search is to be done in reverse, zero otherwise * @return skip table for use in the omega_find function */ -const omega_find_skip_table_t * -omega_find_create_skip_table(const unsigned char *needle, size_t needle_length, int is_reverse_search); +const omega_find_skip_table_t *omega_find_create_skip_table(const unsigned char *needle, size_t needle_length, + int is_reverse_search); /** * Determines if the skip table is for a reverse search diff --git a/core/src/lib/impl_/internal_fun.cpp b/core/src/lib/impl_/internal_fun.cpp index 60e17fb55..317db3d02 100644 --- a/core/src/lib/impl_/internal_fun.cpp +++ b/core/src/lib/impl_/internal_fun.cpp @@ -53,9 +53,7 @@ int populate_data_segment_(const omega_session_t *session_ptr, omega_segment_t * assert(data_segment_ptr); const auto &model_ptr = session_ptr->models_.back(); data_segment_ptr->length = 0; - if (model_ptr->model_segments.empty()) { - return 0; - } + if (model_ptr->model_segments.empty()) { return 0; } assert(0 <= data_segment_ptr->capacity); const auto data_segment_capacity = data_segment_ptr->capacity; const auto data_segment_offset = data_segment_ptr->offset + data_segment_ptr->offset_adjustment; @@ -64,8 +62,8 @@ int populate_data_segment_(const omega_session_t *session_ptr, omega_segment_t * for (auto iter = model_ptr->model_segments.cbegin(); iter != model_ptr->model_segments.cend(); ++iter) { if (read_offset != (*iter)->computed_offset) { ABORT(print_model_segments_(session_ptr->models_.back().get(), CLOG); - LOG_ERROR("break in model continuity, expected: " << read_offset - << ", got: " << (*iter)->computed_offset);); + LOG_ERROR("break in model continuity, expected: " << read_offset + << ", got: " << (*iter)->computed_offset);); } if (read_offset <= data_segment_offset && data_segment_offset <= read_offset + (*iter)->computed_length) { // We're at the first model segment that intersects with the data segment, but the model segment and the @@ -130,8 +128,8 @@ static inline void print_change_(const omega_change_t *change_ptr, std::ostream out_stream << "}"; } -static inline void -print_model_segment_(const omega_model_segment_ptr_t &segment_ptr, std::ostream &out_stream) noexcept { +static inline void print_model_segment_(const omega_model_segment_ptr_t &segment_ptr, + std::ostream &out_stream) noexcept { out_stream << R"({"kind": ")" << omega_model_segment_kind_as_char(omega_model_segment_get_kind(segment_ptr.get())) << R"(", "computed_offset": )" << segment_ptr->computed_offset << R"(, "computed_length": )" << segment_ptr->computed_length << R"(, "change_offset": )" << segment_ptr->change_offset @@ -142,5 +140,5 @@ print_model_segment_(const omega_model_segment_ptr_t &segment_ptr, std::ostream void print_model_segments_(const omega_model_t *model_ptr, std::ostream &out_stream) noexcept { assert(model_ptr); - for (const auto &segment: model_ptr->model_segments) { print_model_segment_(segment, out_stream); } + for (const auto &segment : model_ptr->model_segments) { print_model_segment_(segment, out_stream); } } diff --git a/core/src/lib/impl_/internal_fun.hpp b/core/src/lib/impl_/internal_fun.hpp index ee5345e12..56d371c22 100644 --- a/core/src/lib/impl_/internal_fun.hpp +++ b/core/src/lib/impl_/internal_fun.hpp @@ -23,11 +23,11 @@ // Data segment functions int populate_data_segment_(const omega_session_t *session_ptr, omega_segment_t *data_segment_ptr) -noexcept; + noexcept; // Model segment functions void print_model_segments_(const omega_model_t *model_ptr, std::ostream &out_stream) -noexcept; + noexcept; #endif//OMEGA_EDIT_INTERNAL_FUN_HPP diff --git a/core/src/lib/impl_/model_segment_def.hpp b/core/src/lib/impl_/model_segment_def.hpp index 512e3c2a4..fbfc4e10f 100644 --- a/core/src/lib/impl_/model_segment_def.hpp +++ b/core/src/lib/impl_/model_segment_def.hpp @@ -18,9 +18,7 @@ #include "../../include/omega_edit/change.h" #include "internal_fwd_defs.hpp" -enum class model_segment_kind_t { - SEGMENT_READ, SEGMENT_INSERT -}; +enum class model_segment_kind_t { SEGMENT_READ, SEGMENT_INSERT }; struct omega_model_segment_struct { int64_t computed_offset{}; ///< Computed offset can differ from the change as segments move and split diff --git a/core/src/lib/search.cpp b/core/src/lib/search.cpp index f590e5bca..5166df935 100644 --- a/core/src/lib/search.cpp +++ b/core/src/lib/search.cpp @@ -33,15 +33,15 @@ static inline omega_byte_t to_lower_(omega_byte_t byte, void *) { return static_cast(std::tolower(byte)); } -omega_search_context_t * -omega_search_create_context_bytes(omega_session_t *session_ptr, const omega_byte_t *pattern, int64_t pattern_length, - int64_t session_offset, int64_t session_length, int case_insensitive, - int is_reverse_search) { +omega_search_context_t *omega_search_create_context_bytes(omega_session_t *session_ptr, const omega_byte_t *pattern, + int64_t pattern_length, int64_t session_offset, + int64_t session_length, int case_insensitive, + int is_reverse_search) { assert(session_ptr); assert(pattern); assert(0 <= session_offset); - pattern_length = pattern_length ? pattern_length : static_cast(strlen( - reinterpret_cast(pattern))); + pattern_length = + pattern_length ? pattern_length : static_cast(strlen(reinterpret_cast(pattern))); assert(0 < pattern_length); const auto computed_file_size = omega_session_get_computed_file_size(session_ptr); const auto session_length_computed = session_length ? session_length : computed_file_size - session_offset; @@ -65,18 +65,18 @@ omega_search_create_context_bytes(omega_session_t *session_ptr, const omega_byte } pattern_data_ptr[pattern_length] = '\0'; // create a skip table for patterns with lengths greater than 1 byte - match_context_ptr->skip_table_ptr = omega_find_create_skip_table(pattern_data_ptr, pattern_length, - is_reverse_search); + match_context_ptr->skip_table_ptr = + omega_find_create_skip_table(pattern_data_ptr, pattern_length, is_reverse_search); session_ptr->search_contexts_.push_back(match_context_ptr); return match_context_ptr.get(); } return nullptr; } -omega_search_context_t * -omega_search_create_context(omega_session_t *session_ptr, const char *pattern, int64_t pattern_length, - int64_t session_offset, int64_t session_length, int case_insensitive, - int is_reverse_search) { +omega_search_context_t *omega_search_create_context(omega_session_t *session_ptr, const char *pattern, + int64_t pattern_length, int64_t session_offset, + int64_t session_length, int case_insensitive, + int is_reverse_search) { return omega_search_create_context_bytes(session_ptr, (const omega_byte_t *) pattern, pattern_length, session_offset, session_length, case_insensitive, is_reverse_search); } @@ -133,14 +133,15 @@ int omega_search_next_match(omega_search_context_t *search_context_ptr, int64_t // Calculate the search length. This depends on the direction of the search and the current match offset. int64_t search_length; if (is_reverse) { - search_length = is_begin ? search_context_ptr->session_length : - std::max(static_cast(search_context_ptr->match_offset - - search_context_ptr->session_offset - advance_context + 1), - static_cast(0)); + search_length = is_begin ? search_context_ptr->session_length + : std::max(static_cast(search_context_ptr->match_offset - + search_context_ptr->session_offset - + advance_context + 1), + static_cast(0)); } else { - search_length = is_begin ? search_context_ptr->session_length : - search_context_ptr->session_length - - (search_context_ptr->match_offset - search_context_ptr->session_offset); + search_length = is_begin ? search_context_ptr->session_length + : search_context_ptr->session_length - + (search_context_ptr->match_offset - search_context_ptr->session_offset); } // Only start searching if the pattern length is less than the search length. @@ -164,12 +165,13 @@ int omega_search_next_match(omega_search_context_t *search_context_ptr, int64_t // Determine the offset to start the search from. It depends on the direction of the search and // whether we are beginning a new search or continuing an old one. if (is_reverse) { - data_segment.offset = is_begin ? (search_context_ptr->session_offset + search_context_ptr->session_length - - data_segment.capacity) : - search_context_ptr->match_offset - data_segment.capacity - advance_context + 1; + data_segment.offset = + is_begin ? (search_context_ptr->session_offset + search_context_ptr->session_length - + data_segment.capacity) + : search_context_ptr->match_offset - data_segment.capacity - advance_context + 1; } else { - data_segment.offset = is_begin ? search_context_ptr->session_offset : - search_context_ptr->match_offset + advance_context; + data_segment.offset = + is_begin ? search_context_ptr->session_offset : search_context_ptr->match_offset + advance_context; } // Loop until a match is found or we have searched the entire segment. @@ -187,8 +189,7 @@ int omega_search_next_match(omega_search_context_t *search_context_ptr, int64_t } // Try to find the pattern in the current segment. - if (auto *found = omega_find(segment_data_ptr, data_segment.length, - search_context_ptr->skip_table_ptr, + if (auto *found = omega_find(segment_data_ptr, data_segment.length, search_context_ptr->skip_table_ptr, pattern, search_context_ptr->pattern_length)) { // If a match is found, destroy the data segment and update the match offset in the search context. omega_data_destroy(&data_segment.data, data_segment.capacity); diff --git a/core/src/lib/session.cpp b/core/src/lib/session.cpp index 821d23b87..e4922cd1a 100644 --- a/core/src/lib/session.cpp +++ b/core/src/lib/session.cpp @@ -54,9 +54,9 @@ int64_t omega_session_get_computed_file_size(const omega_session_t *session_ptr) assert(session_ptr->models_.back()); const auto computed_file_size = session_ptr->models_.back()->model_segments.empty() - ? 0 - : session_ptr->models_.back()->model_segments.back()->computed_offset + - session_ptr->models_.back()->model_segments.back()->computed_length; + ? 0 + : session_ptr->models_.back()->model_segments.back()->computed_offset + + session_ptr->models_.back()->model_segments.back()->computed_length; assert(0 <= computed_file_size); return computed_file_size; } @@ -83,8 +83,8 @@ const omega_change_t *omega_session_get_last_undo(const omega_session_t *session assert(session_ptr); assert(session_ptr->models_.back()); return session_ptr->models_.back()->changes_undone.empty() - ? nullptr - : session_ptr->models_.back()->changes_undone.back().get(); + ? nullptr + : session_ptr->models_.back()->changes_undone.back().get(); } const char *omega_session_get_file_path(const omega_session_t *session_ptr) { @@ -142,7 +142,7 @@ void omega_session_resume_viewport_event_callbacks(omega_session_t *session_ptr) int omega_session_notify_changed_viewports(const omega_session_t *session_ptr) { assert(session_ptr); int result = 0; - for (const auto &viewport: session_ptr->viewports_) { + for (const auto &viewport : session_ptr->viewports_) { if (omega_viewport_has_changes(viewport.get()) && 1 == omega_viewport_notify(viewport.get(), VIEWPORT_EVT_CHANGES, nullptr)) ++result; @@ -206,11 +206,11 @@ int64_t omega_session_get_num_change_transactions(const omega_session_t *session assert(session_ptr); int64_t result = 0; // Count the number of transactions in each model - for (const auto &model: session_ptr->models_) { + for (const auto &model : session_ptr->models_) { int64_t transactions_in_model = 0; bool transaction_bit = false; // Count the number of transactions in this model - for (const auto &change: model->changes) { + for (const auto &change : model->changes) { // If the transaction bit is different from the current transaction bit, then we have a new transaction if (transactions_in_model) { if (transaction_bit != omega_change_get_transaction_bit_(change.get())) { @@ -231,11 +231,11 @@ int64_t omega_session_get_num_undone_change_transactions(const omega_session_t * assert(session_ptr); int64_t result = 0; // Count the number of transactions in each model - for (const auto &model: session_ptr->models_) { + for (const auto &model : session_ptr->models_) { int64_t transactions_in_model = 0; bool transaction_bit = false; // Count the number of transactions in this model - for (const auto &change: model->changes_undone) { + for (const auto &change : model->changes_undone) { // If the transaction bit is different from the current transaction bit, then we have a new transaction if (transactions_in_model) { if (transaction_bit != omega_change_get_transaction_bit_(change.get())) { @@ -275,9 +275,8 @@ omega_bom_t omega_session_detect_BOM(const omega_session_t *session_ptr) { return bom; } -int -omega_session_byte_frequency_profile(const omega_session_t *session_ptr, omega_byte_frequency_profile_t *profile_ptr, - int64_t offset, int64_t length) { +int omega_session_byte_frequency_profile(const omega_session_t *session_ptr, + omega_byte_frequency_profile_t *profile_ptr, int64_t offset, int64_t length) { assert(session_ptr); assert(profile_ptr); assert(0 <= offset); diff --git a/core/src/lib/stl_string_adapter.cpp b/core/src/lib/stl_string_adapter.cpp index a6fba43d3..eeaec7938 100644 --- a/core/src/lib/stl_string_adapter.cpp +++ b/core/src/lib/stl_string_adapter.cpp @@ -31,13 +31,13 @@ int64_t omega_edit_insert_string(omega_session_t *session_ptr, int64_t offset, c return omega_edit_insert(session_ptr, offset, str.data(), static_cast(str.length())); } -int64_t -omega_edit_overwrite_string(omega_session_t *session_ptr, int64_t offset, const std::string_view &str) noexcept { +int64_t omega_edit_overwrite_string(omega_session_t *session_ptr, int64_t offset, + const std::string_view &str) noexcept { return omega_edit_overwrite(session_ptr, offset, str.data(), static_cast(str.length())); } -std::string -omega_session_get_segment_string(const omega_session_t *session_ptr, int64_t offset, int64_t length) noexcept { +std::string omega_session_get_segment_string(const omega_session_t *session_ptr, int64_t offset, + int64_t length) noexcept { const auto segment_ptr = omega_segment_create(length); const auto rc = omega_session_get_segment(session_ptr, segment_ptr, offset); assert(0 == rc); @@ -47,10 +47,10 @@ omega_session_get_segment_string(const omega_session_t *session_ptr, int64_t off return result; } -omega_search_context_t * -omega_search_create_context_string(omega_session_t *session_ptr, const std::string_view &pattern, - int64_t session_offset, int64_t session_length, bool case_insensitive, - bool reverse_search) noexcept { +omega_search_context_t *omega_search_create_context_string(omega_session_t *session_ptr, + const std::string_view &pattern, int64_t session_offset, + int64_t session_length, bool case_insensitive, + bool reverse_search) noexcept { return omega_search_create_context(session_ptr, pattern.data(), static_cast(pattern.length()), session_offset, session_length, case_insensitive ? 1 : 0, reverse_search ? 1 : 0); diff --git a/core/src/lib/utility.c b/core/src/lib/utility.c index 6425ca2ae..a3b5ca9aa 100644 --- a/core/src/lib/utility.c +++ b/core/src/lib/utility.c @@ -283,9 +283,7 @@ const void *omega_util_memrchr(const void *s, int c, size_t n) { if (n >= 1) { const unsigned char *cp = (const unsigned char *) s; for (const unsigned char *p = cp + n; p-- > cp;) { - if (*p == c) { - return p; - } + if (*p == c) { return p; } } } return NULL; @@ -348,8 +346,7 @@ static inline int is_low_surrogate_UTF16_(uint16_t word) { } -void omega_util_count_characters(const unsigned char *data, size_t length, - omega_character_counts_t *counts_ptr) { +void omega_util_count_characters(const unsigned char *data, size_t length, omega_character_counts_t *counts_ptr) { assert(data); assert(counts_ptr); @@ -396,97 +393,98 @@ void omega_util_count_characters(const unsigned char *data, size_t length, } size_t i = 0; switch (counts_ptr->bom) { - case BOM_NONE: // fall through, assume UTF-8 if the BOM is not specified + case BOM_NONE:// fall through, assume UTF-8 if the BOM is not specified case BOM_UTF8: while (i < length) { if ((data[i] & 0x80) == 0) { - ++counts_ptr->singleByteChars; // ASCII character + ++counts_ptr->singleByteChars;// ASCII character ++i; } else if ((data[i] & 0xE0) == 0xC0) { // check for 2-byte UTF-8 character if (i + 1 < length && (data[i + 1] & 0xC0) == 0x80) { - ++counts_ptr->doubleByteChars; // 2-byte UTF-8 character (e.g. é) + ++counts_ptr->doubleByteChars;// 2-byte UTF-8 character (e.g. é) i += 2; } else { - ++counts_ptr->invalidBytes; // invalid UTF-8 sequence + ++counts_ptr->invalidBytes;// invalid UTF-8 sequence ++i; } } else if ((data[i] & 0xF0) == 0xE0) { // check for 3-byte UTF-8 character if (i + 2 < length && (data[i + 1] & 0xC0) == 0x80 && (data[i + 2] & 0xC0) == 0x80) { - ++counts_ptr->tripleByteChars; // 3-byte UTF-8 character (e.g. €) + ++counts_ptr->tripleByteChars;// 3-byte UTF-8 character (e.g. €) i += 3; } else { - ++counts_ptr->invalidBytes; // invalid UTF-8 sequence + ++counts_ptr->invalidBytes;// invalid UTF-8 sequence ++i; } } else { // check for 4-byte UTF-8 character if (i + 3 < length && (data[i + 1] & 0xC0) == 0x80 && (data[i + 2] & 0xC0) == 0x80 && (data[i + 3] & 0xC0) == 0x80) { - ++counts_ptr->quadByteChars; // 4-byte UTF-8 character (e.g. 🌍) + ++counts_ptr->quadByteChars;// 4-byte UTF-8 character (e.g. 🌍) i += 4; } else { - ++counts_ptr->invalidBytes; // invalid UTF-8 sequence + ++counts_ptr->invalidBytes;// invalid UTF-8 sequence ++i; } } } break; - case BOM_UTF16LE: // fall through + case BOM_UTF16LE:// fall through case BOM_UTF16BE: while (i + 1 < length) { // Swap the bytes if the BOM is little endian - const uint16_t char16 = counts_ptr->bom == BOM_UTF16LE ? - (uint16_t) (data[i]) | (uint16_t) (data[i + 1]) << 8 : - (uint16_t) (data[i]) << 8 | (uint16_t) (data[i + 1]); + const uint16_t char16 = counts_ptr->bom == BOM_UTF16LE + ? (uint16_t) (data[i]) | (uint16_t) (data[i + 1]) << 8 + : (uint16_t) (data[i]) << 8 | (uint16_t) (data[i + 1]); if (is_lead_surrogate_UTF16_(char16)) { if (i + 3 < length) { - const uint16_t next_char16 = counts_ptr->bom == BOM_UTF16LE ? - (uint16_t) (data[i + 2]) | (uint16_t) (data[i + 3]) << 8 : - (uint16_t) (data[i + 2]) << 8 | (uint16_t) (data[i + 3]); + const uint16_t next_char16 = counts_ptr->bom == BOM_UTF16LE + ? (uint16_t) (data[i + 2]) | (uint16_t) (data[i + 3]) << 8 + : (uint16_t) (data[i + 2]) << 8 | (uint16_t) (data[i + 3]); if (is_low_surrogate_UTF16_(next_char16)) { ++counts_ptr->doubleByteChars; - i += 4; // skip the low surrogate as well + i += 4;// skip the low surrogate as well } else { - ++counts_ptr->invalidBytes; // incomplete surrogate pair + ++counts_ptr->invalidBytes;// incomplete surrogate pair ++i; } } else { - ++counts_ptr->invalidBytes; // incomplete surrogate pair at end of data - break; // exit loop + ++counts_ptr->invalidBytes;// incomplete surrogate pair at end of data + break; // exit loop } } else if (is_low_surrogate_UTF16_(char16)) { - ++counts_ptr->invalidBytes; // low surrogate without preceding high surrogate + ++counts_ptr->invalidBytes;// low surrogate without preceding high surrogate ++i; } else if (char16 <= 0x7F) { - ++counts_ptr->singleByteChars; // ASCII characters + ++counts_ptr->singleByteChars;// ASCII characters i += 2; } else { - ++counts_ptr->doubleByteChars; // all other characters + ++counts_ptr->doubleByteChars;// all other characters i += 2; } } break; - case BOM_UTF32LE: // fall through + case BOM_UTF32LE:// fall through case BOM_UTF32BE: while (i + 3 < length) { // Swap the bytes if the BOM is little endian - const uint32_t char32 = counts_ptr->bom == BOM_UTF32LE ? - (data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) | (data[i + 3] << 24)) : - ((data[i] << 24) | (data[i + 1] << 16) | (data[i + 2] << 8) | data[i + 3]); + const uint32_t char32 = + counts_ptr->bom == BOM_UTF32LE + ? (data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) | (data[i + 3] << 24)) + : ((data[i] << 24) | (data[i + 1] << 16) | (data[i + 2] << 8) | data[i + 3]); if ((char32 >= 0xD800 && char32 <= 0xDFFF) || char32 > 0x10FFFF) { - ++counts_ptr->invalidBytes; // surrogate pairs and characters above 0x10FFFF are invalid in UTF-32 + ++counts_ptr->invalidBytes;// surrogate pairs and characters above 0x10FFFF are invalid in UTF-32 ++i; } else if (char32 <= 0x7F) { - ++counts_ptr->singleByteChars; // ASCII characters + ++counts_ptr->singleByteChars;// ASCII characters i += 4; } else { - ++counts_ptr->quadByteChars; // all other characters + ++counts_ptr->quadByteChars;// all other characters i += 4; } } diff --git a/core/src/lib/viewport.cpp b/core/src/lib/viewport.cpp index ab14e41b9..3f6997634 100644 --- a/core/src/lib/viewport.cpp +++ b/core/src/lib/viewport.cpp @@ -39,7 +39,7 @@ int64_t omega_viewport_get_length(const omega_viewport_t *viewport_ptr) { auto const capacity = omega_viewport_get_capacity(viewport_ptr); auto const remaining_file_size = std::max(omega_session_get_computed_file_size(omega_viewport_get_session(viewport_ptr)) - - omega_viewport_get_offset(viewport_ptr), + omega_viewport_get_offset(viewport_ptr), static_cast(0)); return capacity < remaining_file_size ? capacity : remaining_file_size; } @@ -121,9 +121,9 @@ int omega_viewport_has_changes(const omega_viewport_t *viewport_ptr) { int omega_viewport_in_segment(const omega_viewport_t *viewport_ptr, int64_t offset, int64_t length) { return (offset + length) >= omega_viewport_get_offset(viewport_ptr) && - offset <= omega_viewport_get_offset(viewport_ptr) + omega_viewport_get_capacity(viewport_ptr) - ? 1 - : 0; + offset <= omega_viewport_get_offset(viewport_ptr) + omega_viewport_get_capacity(viewport_ptr) + ? 1 + : 0; } int omega_viewport_notify(const omega_viewport_t *viewport_ptr, omega_viewport_event_t viewport_event, diff --git a/core/src/lib/visit.cpp b/core/src/lib/visit.cpp index 520c3e79d..278c7220e 100644 --- a/core/src/lib/visit.cpp +++ b/core/src/lib/visit.cpp @@ -20,7 +20,7 @@ int omega_visit_changes(const omega_session_t *session_ptr, omega_session_change_visitor_cbk_t cbk, void *user_data) { assert(session_ptr); int rc = 0; - for (const auto &iter: session_ptr->models_.back()->changes) { + for (const auto &iter : session_ptr->models_.back()->changes) { if ((rc = cbk(iter.get(), user_data)) != 0) { break; } } return rc; @@ -118,15 +118,15 @@ const omega_change_t *omega_visit_change_context_get_change(const omega_visit_ch if (change_context_ptr->reverse) { return (!change_context_ptr->change_iter.riter_ptr || *change_context_ptr->change_iter.riter_ptr == - change_context_ptr->session_ptr->models_.back()->changes.rend()) - ? nullptr - : (*change_context_ptr->change_iter.riter_ptr)->get(); + change_context_ptr->session_ptr->models_.back()->changes.rend()) + ? nullptr + : (*change_context_ptr->change_iter.riter_ptr)->get(); } return (!change_context_ptr->change_iter.iter_ptr || *change_context_ptr->change_iter.iter_ptr == - change_context_ptr->session_ptr->models_.back()->changes.cend()) - ? nullptr - : (*change_context_ptr->change_iter.iter_ptr)->get(); + change_context_ptr->session_ptr->models_.back()->changes.cend()) + ? nullptr + : (*change_context_ptr->change_iter.iter_ptr)->get(); } void omega_visit_change_destroy_context(omega_visit_change_context_t *change_context_ptr) { diff --git a/core/src/tests/omega_test.cpp b/core/src/tests/omega_test.cpp index 4484edf16..97539ad58 100644 --- a/core/src/tests/omega_test.cpp +++ b/core/src/tests/omega_test.cpp @@ -104,15 +104,16 @@ TEST_CASE("File Compare", "[UtilTests]") { SECTION("Identity") { // Same file ought to yield identical contents REQUIRE(0 == compare_files("data/test1.dat", "data/test1.dat")); - }SECTION("Difference") { + } + SECTION("Difference") { // Different files with different contents REQUIRE(0 != compare_files("data/test1.dat", "data/test2.dat")); } } TEST_CASE("File Copy", "[UtilTests]") { - struct stat src_stat{}; - struct stat dst_stat{}; + struct stat src_stat {}; + struct stat dst_stat {}; REQUIRE(0 == omega_util_file_copy("data/test1.dat", "data/test1.copy.dat", 0)); REQUIRE(0 == compare_files("data/test1.dat", "data/test1.copy.dat")); @@ -670,14 +671,15 @@ TEST_CASE("Character Counts", "[CharCounts]") { // Force invalid bytes by not including the full sequence of a triple-byte character (e.g., ™). // Removing the last 2 bytes removes the trailing newline and the last byte of the 3-byte ™ character. - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, omega_session_get_computed_file_size(session_ptr) - 2)); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, + omega_session_get_computed_file_size(session_ptr) - 2)); REQUIRE(BOM_UTF8 == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(3 == omega_character_counts_bom_bytes(char_counts_ptr)); - REQUIRE(4 == omega_character_counts_single_byte_chars(char_counts_ptr)); // minus the newline + REQUIRE(4 == omega_character_counts_single_byte_chars(char_counts_ptr));// minus the newline REQUIRE(1 == omega_character_counts_double_byte_chars(char_counts_ptr)); REQUIRE(0 == omega_character_counts_triple_byte_chars(char_counts_ptr)); REQUIRE(0 == omega_character_counts_quad_byte_chars(char_counts_ptr)); - REQUIRE(2 == omega_character_counts_invalid_bytes(char_counts_ptr)); // first 2 bytes of the 3-byte ™ character + REQUIRE(2 == omega_character_counts_invalid_bytes(char_counts_ptr));// first 2 bytes of the 3-byte ™ character omega_edit_destroy_session(session_ptr); session_ptr = omega_edit_create_session("data/utf-16le_1.txt", nullptr, nullptr, NO_EVENTS, nullptr); @@ -917,7 +919,7 @@ TEST_CASE("Check initialization", "[InitTests]") { visit_change_context = omega_visit_change_create_context(session_ptr, 1); REQUIRE(visit_change_context); auto reverse_change_sequence = forward_change_sequence; - std::reverse(reverse_change_sequence.begin(),reverse_change_sequence.end()); + std::reverse(reverse_change_sequence.begin(), reverse_change_sequence.end()); string change_sequence; for (omega_visit_change_begin(visit_change_context); !omega_visit_change_at_end(visit_change_context); omega_visit_change_next(visit_change_context)) { @@ -955,9 +957,7 @@ TEST_CASE("Check initialization", "[InitTests]") { } } -enum class display_mode_t { - BIT_MODE, BYTE_MODE, CHAR_MODE -}; +enum class display_mode_t { BIT_MODE, BYTE_MODE, CHAR_MODE }; struct view_mode_t { display_mode_t display_mode = display_mode_t::CHAR_MODE; }; @@ -1054,9 +1054,7 @@ TEST_CASE("Search-Forward", "[SearchTests]") { REQUIRE(omega_session_get_computed_file_size(session_ptr) == omega_search_context_get_session_length(match_context)); REQUIRE(1 == omega_session_get_num_search_contexts(session_ptr)); - while (omega_search_next_match(match_context, 1)) { - ++needles_found; - } + while (omega_search_next_match(match_context, 1)) { ++needles_found; } REQUIRE(5 == needles_found); omega_search_destroy_context(match_context); REQUIRE(0 == omega_session_get_num_search_contexts(session_ptr)); @@ -1066,25 +1064,25 @@ TEST_CASE("Search-Forward", "[SearchTests]") { REQUIRE(-3 == omega_edit_undo_last_change(session_ptr)); REQUIRE(-3 == omega_change_get_serial(omega_session_get_last_undo(session_ptr))); REQUIRE('I' == omega_change_get_kind_as_char(omega_session_get_change( - session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); + session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); REQUIRE(nullptr != omega_change_get_bytes(omega_session_get_change( - session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); + session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); REQUIRE(!omega_change_get_string( - omega_session_get_change(session_ptr, - omega_change_get_serial(omega_session_get_last_undo(session_ptr)))).empty() - ); + omega_session_get_change(session_ptr, + omega_change_get_serial(omega_session_get_last_undo(session_ptr)))) + .empty()); REQUIRE(omega_session_get_num_undone_changes(session_ptr) == 1); REQUIRE(-2 == omega_edit_undo_last_change(session_ptr)); REQUIRE(omega_change_is_undone(omega_session_get_last_undo(session_ptr))); REQUIRE(-2 == omega_change_get_serial(omega_session_get_last_undo(session_ptr))); REQUIRE('D' == omega_change_get_kind_as_char(omega_session_get_change( - session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); + session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); REQUIRE(nullptr == omega_change_get_bytes(omega_session_get_change( - session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); + session_ptr, omega_change_get_serial(omega_session_get_last_undo(session_ptr))))); REQUIRE(omega_change_get_string( - omega_session_get_change(session_ptr, - omega_change_get_serial(omega_session_get_last_undo(session_ptr)))).empty() - ); + omega_session_get_change(session_ptr, + omega_change_get_serial(omega_session_get_last_undo(session_ptr)))) + .empty()); REQUIRE(omega_session_get_num_undone_changes(session_ptr) == 2); REQUIRE(0 < omega_edit_overwrite_string(session_ptr, 16, needle)); REQUIRE(omega_session_get_num_undone_changes(session_ptr) == 0); @@ -1223,7 +1221,8 @@ TEST_CASE("Search-Reverse", "[SearchTests]") { const auto session_ptr = omega_edit_create_session(nullptr, nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); omega_edit_insert_string(session_ptr, 0, - "The pursuit of happiness is a fundamental human goal. The pursuit of knowledge is equally important. It is through the pursuit of our passions that we truly live."); + "The pursuit of happiness is a fundamental human goal. The pursuit of knowledge is " + "equally important. It is through the pursuit of our passions that we truly live."); auto search_context_ptr = omega_search_create_context_string(session_ptr, "Pursuit", 0, 0, true, true); REQUIRE(search_context_ptr); auto matches = std::vector(); @@ -1404,15 +1403,19 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { REQUIRE(3 == session_events_count); // SESSION_EVT_EDIT REQUIRE(2 == viewport_events_count);// VIEWPORT_EVT_EDIT omega_util_remove_file("data/session_save.1.dat"); - REQUIRE(0 == omega_edit_save(session_ptr, "data/session_save.1.dat", omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename)); + REQUIRE(0 == omega_edit_save(session_ptr, "data/session_save.1.dat", omega_io_flags_t::IO_FLG_OVERWRITE, + saved_filename)); REQUIRE(omega_util_paths_equivalent("data/session_save.1.dat", saved_filename)); - REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.1.dat", omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename, 1, 0)); + REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.1.dat", omega_io_flags_t::IO_FLG_OVERWRITE, + saved_filename, 1, 0)); REQUIRE(0 == compare_files("data/session_save_seg.expected.1.dat", "data/session_save_seg.1.dat")); omega_util_remove_file("data/session_save_seg.1.dat"); - REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.2.dat", omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename, 0, 4)); + REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.2.dat", omega_io_flags_t::IO_FLG_OVERWRITE, + saved_filename, 0, 4)); REQUIRE(0 == compare_files("data/session_save_seg.expected.2.dat", "data/session_save_seg.2.dat")); omega_util_remove_file("data/session_save_seg.2.dat"); - REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.3.dat", omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename, 2, 6)); + REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.3.dat", omega_io_flags_t::IO_FLG_OVERWRITE, + saved_filename, 2, 6)); REQUIRE(0 == compare_files("data/session_save_seg.expected.3.dat", "data/session_save_seg.3.dat")); omega_util_remove_file("data/session_save_seg.3.dat"); REQUIRE(7 == session_events_count); // SESSION_EVT_SAVE @@ -1464,11 +1467,13 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { REQUIRE(omega_util_paths_equivalent("data/session_save.1-3.dat", saved_filename)); REQUIRE(0 == compare_files("data/session_save.expected.2.dat", "data/session_save.1-3.dat")); omega_util_remove_file("data/session_save_seg.2.dat"); - REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.2.dat", omega_io_flags_t::IO_FLG_NONE, saved_filename, 0, 4)); + REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.2.dat", omega_io_flags_t::IO_FLG_NONE, + saved_filename, 0, 4)); REQUIRE(0 == compare_files("data/session_save_seg.expected.2.dat", "data/session_save_seg.2.dat")); omega_util_remove_file("data/session_save_seg.2.dat"); omega_util_remove_file("data/session_save_seg.3.dat"); - REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.3.dat", omega_io_flags_t::IO_FLG_NONE, saved_filename, 2, 6)); + REQUIRE(0 == omega_edit_save_segment(session_ptr, "data/session_save_seg.3.dat", omega_io_flags_t::IO_FLG_NONE, + saved_filename, 2, 6)); REQUIRE(0 == compare_files("data/session_save_seg.expected.3.dat", "data/session_save_seg.3.dat")); omega_util_remove_file("data/session_save_seg.3.dat"); omega_edit_destroy_session(session_ptr); @@ -1494,7 +1499,7 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { saved_filename)); REQUIRE(omega_util_paths_equivalent("data/session_save.1-3.dat", saved_filename)); omega_edit_destroy_session(session_ptr); - session_ptr = omega_edit_create_session(nullptr, nullptr, nullptr,NO_EVENTS, nullptr); + session_ptr = omega_edit_create_session(nullptr, nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(0 == omega_edit_save(session_ptr, "data/session_save.empty.dat", omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename)); REQUIRE(omega_util_paths_equivalent("data/session_save.empty.dat", saved_filename)); diff --git a/yarn.lock b/yarn.lock index 146e20173..542a3903f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -51,10 +51,10 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.50.0.tgz#9e93b850f0f3fa35f5fa59adfd03adae8488e484" integrity sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ== -"@grpc/grpc-js@1.9.3": - version "1.9.3" - resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.9.3.tgz#811cc49966ab7ed96efa31d213e80d671fd13839" - integrity sha512-b8iWtdrYIeT5fdZdS4Br/6h/kuk0PW5EVBUGk1amSbrpL8DlktJD43CdcCWwRdd6+jgwHhADSbL9CsNnm6EUPA== +"@grpc/grpc-js@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.9.4.tgz#6cf152869910c2ac3429eee08c1dbdc84e7bafea" + integrity sha512-oEnzYiDuEsBydZBtP84BkpduLsE1nSAO4KrhTLHRzNrIQE647fhchmosTQsJdCo8X9zBBt+l5+fNk+m/yCFJ/Q== dependencies: "@grpc/proto-loader" "^0.7.8" "@types/node" ">=12.12.47"