diff --git a/core/src/include/omega_edit/config.h b/core/src/include/omega_edit/config.h index a3dc0656..9f8bdea2 100644 --- a/core/src/include/omega_edit/config.h +++ b/core/src/include/omega_edit/config.h @@ -20,8 +20,8 @@ #ifndef OMEGA_EDIT_CONFIG_H #define OMEGA_EDIT_CONFIG_H -#include // this header is generated at build time #include +#include // this header is generated at build time #ifdef __cplusplus @@ -57,7 +57,7 @@ #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 @@ -79,17 +79,19 @@ #ifdef _MSC_VER #include // For MSVC, use _sopen_s -static inline int safe_open_(const char* filename, int oflag, int pmode) { +static inline int safe_open_(const char *filename, int oflag, int pmode) { int fd; _sopen_s(&fd, filename, oflag | _O_BINARY, _SH_DENYWR, pmode); return fd; } #else + // For other compilers/platforms, fall back to open -static inline int safe_open_(const char* filename, int oflag, int pmode) { +static inline int safe_open_(const char *filename, int oflag, int pmode) { // Note: The mode only applies if O_CREAT is part of oflag return open(filename, oflag, pmode); } + #endif /** @@ -105,8 +107,8 @@ static inline int safe_open_(const char* filename, int oflag, int pmode) { * @param mode mode to open the file in * @return opened file pointer */ -static inline FILE* safe_fopen_(const char* filename, const char* mode) { - FILE* file; +static inline FILE *safe_fopen_(const char *filename, const char *mode) { + FILE *file; #ifdef HAVE_FOPEN_S // Use fopen_s where supported fopen_s(&file, filename, mode); diff --git a/core/src/include/omega_edit/features.h b/core/src/include/omega_edit/features.h index 28c72050..a189b147 100644 --- a/core/src/include/omega_edit/features.h +++ b/core/src/include/omega_edit/features.h @@ -16,6 +16,7 @@ * @file features.h * @brief Features that are available on the current platform. * @warning Dummy file to satisfy IDEs. A real version is generated at build time. +* @info To ignore changes to this file, use: git update-index --assume-unchanged core/src/include/omega_edit/features.h */ #ifndef OMEGA_EDIT_FEATURES_H diff --git a/core/src/include/omega_edit/filesystem.h b/core/src/include/omega_edit/filesystem.h index ebed4d61..b185d360 100644 --- a/core/src/include/omega_edit/filesystem.h +++ b/core/src/include/omega_edit/filesystem.h @@ -110,7 +110,7 @@ int omega_util_paths_equivalent(char const *path1, char const *path2); * @param path2 second path * @return 0 if the contents are equal, 1 if the contents are not equal, or -1 if an error occurred opening the file at path1 or -2 if an error occurred opening the file at path2 */ -int omega_util_compare_files(const char* path1, const char* path2); +int omega_util_compare_files(const char *path1, const char *path2); /** * Compare the modification times of two files @@ -149,7 +149,7 @@ 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 * @param path path to get the absolute path of * @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 + * @return absolute path that has no symbolic link, dot, or dot-dot path elements */ char *omega_util_normalize_path(char const *path, char *buffer); diff --git a/core/src/include/omega_edit/fwd_defs.h b/core/src/include/omega_edit/fwd_defs.h index 5a211e8e..07e8ceb6 100644 --- a/core/src/include/omega_edit/fwd_defs.h +++ b/core/src/include/omega_edit/fwd_defs.h @@ -71,10 +71,14 @@ typedef enum { #define ORIGINAL_MODIFIED (-100) /** Mask types */ -typedef enum { MASK_AND, MASK_OR, MASK_XOR } omega_mask_kind_t; +typedef enum { + MASK_AND, MASK_OR, MASK_XOR +} omega_mask_kind_t; /** Byte order mark (BOM) types */ -typedef enum { BOM_UNKNOWN = 0, BOM_NONE, BOM_UTF8, BOM_UTF16LE, BOM_UTF16BE, BOM_UTF32LE, BOM_UTF32BE } omega_bom_t; +typedef enum { + BOM_UNKNOWN = 0, BOM_NONE, 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; diff --git a/core/src/include/omega_edit/stl_string_adaptor.hpp b/core/src/include/omega_edit/stl_string_adaptor.hpp index fad70ece..21d88026 100644 --- a/core/src/include/omega_edit/stl_string_adaptor.hpp +++ b/core/src/include/omega_edit/stl_string_adaptor.hpp @@ -71,6 +71,7 @@ int64_t omega_edit_overwrite_string(omega_session_t *session_ptr, int64_t offset */ 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 diff --git a/core/src/lib/change.cpp b/core/src/lib/change.cpp index f7a29b6c..8961bf87 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 fce791c4..d6bcd312 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 bff5f3fa..7cb4930a 100644 --- a/core/src/lib/edit.cpp +++ b/core/src/lib/edit.cpp @@ -30,9 +30,10 @@ #include #ifdef OMEGA_BUILD_WINDOWS + #include + #define close _close -#define fdopen _fdopen #define min std::min #define max std::max #else @@ -41,159 +42,162 @@ #define max std::max #endif -static void initialize_model_segments_(omega_model_segments_t &model_segments, int64_t length) { - model_segments.clear(); - if (0 < length) { - // Model begins with a single READ segment spanning the original file - const auto change_ptr = std::make_shared(); - change_ptr->serial = 0; - change_ptr->kind = (uint8_t) (change_kind_t::CHANGE_INSERT); - change_ptr->offset = 0; - change_ptr->length = length; - auto read_segment_ptr = std::make_unique(); - read_segment_ptr->change_ptr = change_ptr; - read_segment_ptr->computed_offset = 0; - read_segment_ptr->change_offset = read_segment_ptr->change_ptr->offset; - read_segment_ptr->computed_length = read_segment_ptr->change_ptr->length; - model_segments.push_back(std::move(read_segment_ptr)); +namespace { + void initialize_model_segments_(omega_model_segments_t &model_segments, int64_t length) { + model_segments.clear(); + if (0 < length) { + // Model begins with a single READ segment spanning the original file + const auto change_ptr = std::make_shared(); + change_ptr->serial = 0; + change_ptr->kind = (uint8_t) (change_kind_t::CHANGE_INSERT); + change_ptr->offset = 0; + change_ptr->length = length; + auto read_segment_ptr = std::make_unique(); + read_segment_ptr->change_ptr = change_ptr; + read_segment_ptr->computed_offset = 0; + read_segment_ptr->change_offset = read_segment_ptr->change_ptr->offset; + read_segment_ptr->computed_length = read_segment_ptr->change_ptr->length; + model_segments.push_back(std::move(read_segment_ptr)); + } } -} - -static inline const_omega_change_ptr_t del_(int64_t serial, int64_t offset, int64_t length, bool transaction_bit) { - const auto change_ptr = std::make_shared(); - change_ptr->serial = serial; - change_ptr->kind = (transaction_bit ? OMEGA_CHANGE_TRANSACTION_BIT : 0x00) | (uint8_t) change_kind_t::CHANGE_DELETE; - change_ptr->offset = offset; - change_ptr->length = length; - change_ptr->data.bytes_ptr = nullptr; - return change_ptr; -} -static inline const_omega_change_ptr_t ins_(int64_t serial, int64_t offset, const omega_byte_t *bytes, int64_t length, - bool transaction_bit) { - auto change_ptr = std::make_shared(); - change_ptr->serial = serial; - change_ptr->kind = (transaction_bit ? OMEGA_CHANGE_TRANSACTION_BIT : 0x00) | (uint8_t) change_kind_t::CHANGE_INSERT; - change_ptr->offset = offset; - change_ptr->length = length ? length : static_cast(strlen((const char *) bytes)); - if (change_ptr->length < 8) { - // small bytes optimization - memcpy(change_ptr->data.sm_bytes, bytes, change_ptr->length); - change_ptr->data.sm_bytes[change_ptr->length] = '\0'; - } else { - // allocate its capacity plus one, so we can null-terminate it - change_ptr->data.bytes_ptr = new omega_byte_t[change_ptr->length + 1]; - memcpy(change_ptr->data.bytes_ptr, bytes, change_ptr->length); - change_ptr->data.bytes_ptr[change_ptr->length] = '\0'; - } - return std::move(change_ptr); -} - -static inline const_omega_change_ptr_t ovr_(int64_t serial, int64_t offset, const omega_byte_t *bytes, int64_t length, - bool transaction_bit) { - auto change_ptr = std::make_shared(); - change_ptr->serial = serial; - change_ptr->kind = - (transaction_bit ? OMEGA_CHANGE_TRANSACTION_BIT : 0x00) | (uint8_t) change_kind_t::CHANGE_OVERWRITE; - change_ptr->offset = offset; - change_ptr->length = length ? length : static_cast(strlen((const char *) bytes)); - if (change_ptr->length < 8) { - // small bytes optimization - memcpy(change_ptr->data.sm_bytes, bytes, change_ptr->length); - change_ptr->data.sm_bytes[change_ptr->length] = '\0'; - } else { - // allocate its capacity plus one, so we can null-terminate it - change_ptr->data.bytes_ptr = new omega_byte_t[change_ptr->length + 1]; - memcpy(change_ptr->data.bytes_ptr, bytes, change_ptr->length); - change_ptr->data.bytes_ptr[change_ptr->length] = '\0'; - } - return std::move(change_ptr); -} - -static inline void update_viewport_offset_adjustment_(omega_viewport_t *viewport_ptr, - const omega_change_t *change_ptr) { - assert(0 < change_ptr->length); - const auto offset = omega_viewport_get_offset(viewport_ptr); - // If the viewport is floating and a change happens before or at the start of the given viewport... - if (omega_viewport_is_floating(viewport_ptr) && change_ptr->offset <= offset) { - // ...and the change is a delete, or insert, update the offset adjustment accordingly - if (change_kind_t::CHANGE_DELETE == omega_change_get_kind(change_ptr)) { - viewport_ptr->data_segment.offset_adjustment -= change_ptr->length; - // If the offset adjustment is now negative, adjust it to zero - if (offset < -viewport_ptr->data_segment.offset_adjustment) { - viewport_ptr->data_segment.offset_adjustment = -offset; + inline auto del_(int64_t serial, int64_t offset, int64_t length, bool transaction_bit) -> const_omega_change_ptr_t { + const auto change_ptr = std::make_shared(); + change_ptr->serial = serial; + change_ptr->kind = + (transaction_bit ? OMEGA_CHANGE_TRANSACTION_BIT : 0x00) | (uint8_t) change_kind_t::CHANGE_DELETE; + change_ptr->offset = offset; + change_ptr->length = length; + change_ptr->data.bytes_ptr = nullptr; + return change_ptr; + } + + inline auto ins_(int64_t serial, int64_t offset, const omega_byte_t *bytes, int64_t length, + bool transaction_bit) -> const_omega_change_ptr_t { + auto change_ptr = std::make_shared(); + change_ptr->serial = serial; + change_ptr->kind = + (transaction_bit ? OMEGA_CHANGE_TRANSACTION_BIT : 0x00) | (uint8_t) change_kind_t::CHANGE_INSERT; + change_ptr->offset = offset; + change_ptr->length = length ? length : static_cast(strlen((const char *) bytes)); + if (change_ptr->length < 8) { + // small bytes optimization + memcpy(change_ptr->data.sm_bytes, bytes, change_ptr->length); + change_ptr->data.sm_bytes[change_ptr->length] = '\0'; + } else { + // allocate its capacity plus one, so we can null-terminate it + change_ptr->data.bytes_ptr = new omega_byte_t[change_ptr->length + 1]; + memcpy(change_ptr->data.bytes_ptr, bytes, change_ptr->length); + change_ptr->data.bytes_ptr[change_ptr->length] = '\0'; + } + return std::move(change_ptr); + } + + inline auto ovr_(int64_t serial, int64_t offset, const omega_byte_t *bytes, int64_t length, + bool transaction_bit) -> const_omega_change_ptr_t { + auto change_ptr = std::make_shared(); + change_ptr->serial = serial; + change_ptr->kind = + (transaction_bit ? OMEGA_CHANGE_TRANSACTION_BIT : 0x00) | (uint8_t) change_kind_t::CHANGE_OVERWRITE; + change_ptr->offset = offset; + change_ptr->length = length ? length : static_cast(strlen((const char *) bytes)); + if (change_ptr->length < 8) { + // small bytes optimization + memcpy(change_ptr->data.sm_bytes, bytes, change_ptr->length); + change_ptr->data.sm_bytes[change_ptr->length] = '\0'; + } else { + // allocate its capacity plus one, so we can null-terminate it + change_ptr->data.bytes_ptr = new omega_byte_t[change_ptr->length + 1]; + memcpy(change_ptr->data.bytes_ptr, bytes, change_ptr->length); + change_ptr->data.bytes_ptr[change_ptr->length] = '\0'; + } + return std::move(change_ptr); + } + + inline void update_viewport_offset_adjustment_(omega_viewport_t *viewport_ptr, + const omega_change_t *change_ptr) { + assert(0 < change_ptr->length); + const auto offset = omega_viewport_get_offset(viewport_ptr); + // If the viewport is floating and a change happens before or at the start of the given viewport... + if ((omega_viewport_is_floating(viewport_ptr) != 0) && change_ptr->offset <= offset) { + // ...and the change is a delete, or insert, update the offset adjustment accordingly + if (change_kind_t::CHANGE_DELETE == omega_change_get_kind(change_ptr)) { + viewport_ptr->data_segment.offset_adjustment -= change_ptr->length; + // If the offset adjustment is now negative, adjust it to zero + if (offset < -viewport_ptr->data_segment.offset_adjustment) { + viewport_ptr->data_segment.offset_adjustment = -offset; + } + } else if (change_kind_t::CHANGE_INSERT == omega_change_get_kind(change_ptr)) { + viewport_ptr->data_segment.offset_adjustment += change_ptr->length; } - } else if (change_kind_t::CHANGE_INSERT == omega_change_get_kind(change_ptr)) { - viewport_ptr->data_segment.offset_adjustment += change_ptr->length; } } -} -static inline bool change_affects_viewport_(const omega_viewport_t *viewport_ptr, const omega_change_t *change_ptr) { - assert(0 < change_ptr->length); - switch (omega_change_get_kind(change_ptr)) { - case change_kind_t::CHANGE_DELETE:// deliberate fall-through - case change_kind_t::CHANGE_INSERT: - // INSERT and DELETE changes that happen before the viewport end offset affect the viewport - return (change_ptr->offset <= - (omega_viewport_get_offset(viewport_ptr) + omega_viewport_get_capacity(viewport_ptr))); - case change_kind_t::CHANGE_OVERWRITE: - // OVERWRITE changes that happen inside the viewport affect the viewport - return omega_viewport_in_segment(viewport_ptr, change_ptr->offset, change_ptr->length); - default: - ABORT(LOG_ERROR("Unhandled change kind");); + inline bool change_affects_viewport_(const omega_viewport_t *viewport_ptr, const omega_change_t *change_ptr) { + assert(0 < change_ptr->length); + switch (omega_change_get_kind(change_ptr)) { + case change_kind_t::CHANGE_DELETE:// deliberate fall-through + case change_kind_t::CHANGE_INSERT: + // INSERT and DELETE changes that happen before the viewport end offset affect the viewport + return (change_ptr->offset <= + (omega_viewport_get_offset(viewport_ptr) + omega_viewport_get_capacity(viewport_ptr))); + case change_kind_t::CHANGE_OVERWRITE: + // OVERWRITE changes that happen inside the viewport affect the viewport + return omega_viewport_in_segment(viewport_ptr, change_ptr->offset, change_ptr->length) != 0; + default: + ABORT(LOG_ERROR("Unhandled change kind");); + } } -} -static int update_viewports_(const omega_session_t *session_ptr, const omega_change_t *change_ptr) { - 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)) { - viewport_ptr->data_segment.capacity = - -1 * std::abs(viewport_ptr->data_segment.capacity);// indicate dirty read - omega_viewport_notify(viewport_ptr.get(), - (0 < omega_change_get_serial(change_ptr)) ? VIEWPORT_EVT_EDIT : VIEWPORT_EVT_UNDO, - change_ptr); + auto update_viewports_(const omega_session_t *session_ptr, const omega_change_t *change_ptr) -> int { + 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)) { + viewport_ptr->data_segment.capacity = + -1 * std::abs(viewport_ptr->data_segment.capacity);// indicate dirty read + omega_viewport_notify(viewport_ptr.get(), + (0 < omega_change_get_serial(change_ptr)) ? VIEWPORT_EVT_EDIT : VIEWPORT_EVT_UNDO, + change_ptr); + } } + return 0; } - return 0; -} -static inline omega_model_segment_ptr_t clone_model_segment_(const omega_model_segment_ptr_t &segment_ptr) { - auto result = std::make_unique(); - result->computed_offset = segment_ptr->computed_offset; - result->computed_length = segment_ptr->computed_length; - result->change_offset = segment_ptr->change_offset; - result->change_ptr = segment_ptr->change_ptr; - return result; -} + inline auto clone_model_segment_(const omega_model_segment_ptr_t &segment_ptr) -> omega_model_segment_ptr_t { + auto result = std::make_unique(); + result->computed_offset = segment_ptr->computed_offset; + result->computed_length = segment_ptr->computed_length; + result->change_offset = segment_ptr->change_offset; + result->change_ptr = segment_ptr->change_ptr; + return result; + } -static inline void free_model_changes_(omega_model_struct *model_ptr) { - 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); + inline void free_model_changes_(omega_model_struct *model_ptr) { + 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); + } } + model_ptr->changes.clear(); } - model_ptr->changes.clear(); -} -static inline void free_model_changes_undone_(omega_model_struct *model_ptr) { - 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); + inline void free_model_changes_undone_(omega_model_struct *model_ptr) { + 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); + } } + model_ptr->changes_undone.clear(); } - model_ptr->changes_undone.clear(); -} -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()); } -} + inline void free_session_changes_(const omega_session_t *session_ptr) { + 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()); } -} + 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()); } + } /* -------------------------------------------------------------------------------------------------------------------- The objective here is to model the edits using segments. Essentially creating a contiguous model of the file by @@ -201,138 +205,160 @@ static inline void free_session_changes_undone_(const omega_session_t *session_p that is covered by adjusting, or removing, the READ, INSERT, and OVERWRITE segments accordingly. The model expects to take in changes with original offsets and lengths and the model will calculate computed offsets and lengths. -------------------------------------------------------------------------------------------------------------------- */ -static int update_model_helper_(omega_model_t *model_ptr, const const_omega_change_ptr_t &change_ptr) { - assert(change_ptr->length > 0); - int64_t read_offset = 0; - - if (model_ptr->model_segments.empty()) { - if (omega_change_get_kind(change_ptr.get()) != change_kind_t::CHANGE_DELETE) { - // The model is empty, and we have a change with content - auto insert_segment_ptr = std::make_unique(); - insert_segment_ptr->computed_offset = change_ptr->offset; - insert_segment_ptr->computed_length = change_ptr->length; - insert_segment_ptr->change_offset = 0; - insert_segment_ptr->change_ptr = change_ptr; - model_ptr->model_segments.push_back(std::move(insert_segment_ptr)); - } - return 0; - } - 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);); + auto update_model_helper_(omega_model_t *model_ptr, const const_omega_change_ptr_t &change_ptr) -> int { + assert(change_ptr->length > 0); + int64_t read_offset = 0; + + if (model_ptr->model_segments.empty()) { + if (omega_change_get_kind(change_ptr.get()) != change_kind_t::CHANGE_DELETE) { + // The model is empty, and we have a change with content + auto insert_segment_ptr = std::make_unique(); + insert_segment_ptr->computed_offset = change_ptr->offset; + insert_segment_ptr->computed_length = change_ptr->length; + insert_segment_ptr->change_offset = 0; + insert_segment_ptr->change_ptr = change_ptr; + model_ptr->model_segments.push_back(std::move(insert_segment_ptr)); + } + return 0; } - if (change_ptr->offset >= read_offset && change_ptr->offset <= read_offset + (*iter)->computed_length) { - if (change_ptr->offset != read_offset) { - const auto delta = change_ptr->offset - (*iter)->computed_offset; - if (delta == (*iter)->computed_length) { - // The update happens right at the end of the existing segment - ++iter; - } else { - // The update site falls in the middle of an existing segment, so we need to split the segment at - // the update site. iter points to the segment on the left of the split and split_segment_ptr - // points to a new duplicate segment on the right of the split. - auto split_segment_ptr = clone_model_segment_(*iter); - split_segment_ptr->computed_offset += delta; - split_segment_ptr->computed_length -= delta; - split_segment_ptr->change_offset += delta; - (*iter)->computed_length = delta; - // iter will now point to the new split segment inserted into the model and who's offset falls on - // the update site - iter = model_ptr->model_segments.insert(iter + 1, std::move(split_segment_ptr)); - } + 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);); } - switch (omega_change_get_kind(change_ptr.get())) { - case change_kind_t::CHANGE_DELETE: { - auto delete_length = change_ptr->length; - while (delete_length && iter != model_ptr->model_segments.end()) { - if ((*iter)->computed_length <= delete_length) { - // DELETE change spans the entire segment - delete_length -= (*iter)->computed_length; - iter = model_ptr->model_segments.erase(iter); - } else { - // DELETE removes a portion of the beginning of the segment - (*iter)->computed_length -= delete_length; - (*iter)->computed_offset += delete_length - change_ptr->length; - (*iter)->change_offset += delete_length; - assert((*iter)->change_offset < (*iter)->change_ptr->length); - delete_length = 0; - ++iter;// move to the next segment for adjusting - } - } - // adjust the computed offsets for segments beyond the DELETE site - for (; iter != model_ptr->model_segments.end(); ++iter) { - (*iter)->computed_offset -= change_ptr->length; + if (change_ptr->offset >= read_offset && change_ptr->offset <= read_offset + (*iter)->computed_length) { + if (change_ptr->offset != read_offset) { + const auto delta = change_ptr->offset - (*iter)->computed_offset; + if (delta == (*iter)->computed_length) { + // The update happens right at the end of the existing segment + ++iter; + } else { + // The update site falls in the middle of an existing segment, so we need to split the segment at + // the update site. iter points to the segment on the left of the split and split_segment_ptr + // points to a new duplicate segment on the right of the split. + auto split_segment_ptr = clone_model_segment_(*iter); + split_segment_ptr->computed_offset += delta; + split_segment_ptr->computed_length -= delta; + split_segment_ptr->change_offset += delta; + (*iter)->computed_length = delta; + // iter will now point to the new split segment inserted into the model and who's offset falls on + // the update site + iter = model_ptr->model_segments.insert(iter + 1, std::move(split_segment_ptr)); } - break; } - case change_kind_t::CHANGE_OVERWRITE:// deliberate fall-through - case change_kind_t::CHANGE_INSERT: { - auto insert_segment_ptr = std::make_unique(); - insert_segment_ptr->computed_offset = change_ptr->offset; - insert_segment_ptr->computed_length = change_ptr->length; - insert_segment_ptr->change_offset = 0; - insert_segment_ptr->change_ptr = change_ptr; - iter = model_ptr->model_segments.insert(iter, std::move(insert_segment_ptr)); - for (++iter; iter != model_ptr->model_segments.end(); ++iter) { - (*iter)->computed_offset += change_ptr->length; + switch (omega_change_get_kind(change_ptr.get())) { + case change_kind_t::CHANGE_DELETE: { + auto delete_length = change_ptr->length; + while (delete_length && iter != model_ptr->model_segments.end()) { + if ((*iter)->computed_length <= delete_length) { + // DELETE change spans the entire segment + delete_length -= (*iter)->computed_length; + iter = model_ptr->model_segments.erase(iter); + } else { + // DELETE removes a portion of the beginning of the segment + (*iter)->computed_length -= delete_length; + (*iter)->computed_offset += delete_length - change_ptr->length; + (*iter)->change_offset += delete_length; + assert((*iter)->change_offset < (*iter)->change_ptr->length); + delete_length = 0; + ++iter;// move to the next segment for adjusting + } + } + // adjust the computed offsets for segments beyond the DELETE site + for (; iter != model_ptr->model_segments.end(); ++iter) { + (*iter)->computed_offset -= change_ptr->length; + } + break; } - break; + case change_kind_t::CHANGE_OVERWRITE:// deliberate fall-through + case change_kind_t::CHANGE_INSERT: { + auto insert_segment_ptr = std::make_unique(); + insert_segment_ptr->computed_offset = change_ptr->offset; + insert_segment_ptr->computed_length = change_ptr->length; + insert_segment_ptr->change_offset = 0; + insert_segment_ptr->change_ptr = change_ptr; + iter = model_ptr->model_segments.insert(iter, std::move(insert_segment_ptr)); + for (++iter; iter != model_ptr->model_segments.end(); ++iter) { + (*iter)->computed_offset += change_ptr->length; + } + break; + } + default: + ABORT(LOG_ERROR("Unhandled change kind");); } - default: - ABORT(LOG_ERROR("Unhandled change kind");); + return 0; } - return 0; + read_offset += (*iter)->computed_length; } - read_offset += (*iter)->computed_length; + return -1; } - return -1; -} -static int update_model_(omega_session_t *session_ptr, const const_omega_change_ptr_t &change_ptr) { - const auto model_ptr = session_ptr->models_.back().get(); - if (omega_change_get_kind(change_ptr.get()) == change_kind_t::CHANGE_OVERWRITE) { - // Overwrite will model just like a DELETE, followed by an INSERT - const_omega_change_ptr_t const_change_ptr = - del_(0, change_ptr->offset, change_ptr->length, !omega_session_get_transaction_bit_(session_ptr)); - const auto rc = update_model_helper_(model_ptr, const_change_ptr); - if (0 != rc) { return rc; } + auto update_model_(omega_session_t *session_ptr, const const_omega_change_ptr_t &change_ptr) -> int { + const auto model_ptr = session_ptr->models_.back().get(); + if (omega_change_get_kind(change_ptr.get()) == change_kind_t::CHANGE_OVERWRITE) { + // Overwrite will model just like a DELETE, followed by an INSERT + const_omega_change_ptr_t const_change_ptr = + del_(0, change_ptr->offset, change_ptr->length, !omega_session_get_transaction_bit_(session_ptr)); + const auto rc = update_model_helper_(model_ptr, const_change_ptr); + if (0 != rc) { return rc; } + } + return update_model_helper_(model_ptr, change_ptr); } - return update_model_helper_(model_ptr, change_ptr); -} -static int64_t update_(omega_session_t *session_ptr, const const_omega_change_ptr_t &change_ptr) { - if (change_ptr->offset <= omega_session_get_computed_file_size(session_ptr)) { - if (omega_change_get_serial(change_ptr.get()) < 0) { - // This is a previously undone change that is being redone, so flip the serial number back to positive - const_cast(change_ptr.get())->serial *= -1; - } else if (!session_ptr->models_.back()->changes_undone.empty()) { - // This is not a redo change, so any changes undone are now invalid and must be cleared - free_session_changes_undone_(session_ptr); + auto update_(omega_session_t *session_ptr, const const_omega_change_ptr_t &change_ptr) -> int64_t { + if (change_ptr->offset <= omega_session_get_computed_file_size(session_ptr)) { + if (omega_change_get_serial(change_ptr.get()) < 0) { + // This is a previously undone change that is being redone, so flip the serial number back to positive + const_cast(change_ptr.get())->serial *= -1; + } else if (!session_ptr->models_.back()->changes_undone.empty()) { + // This is not a redo change, so any changes undone are now invalid and must be cleared + free_session_changes_undone_(session_ptr); + } + session_ptr->models_.back()->changes.push_back(change_ptr); + if (0 != update_model_(session_ptr, change_ptr)) { return -1; } + update_viewports_(session_ptr, change_ptr.get()); + omega_session_notify(session_ptr, SESSION_EVT_EDIT, change_ptr.get()); + return omega_change_get_serial(change_ptr.get()); + } + return -1; + } + + inline auto determine_change_transaction_bit_(omega_session_t *session_ptr) -> bool { + switch (omega_session_get_transaction_state(session_ptr)) { + case 0: + // No transaction in progress, use the flipped previous change transaction bit + return !omega_session_get_transaction_bit_(session_ptr); + case 1: + // This is the first change in a transaction, use the flipped previous change transaction bit and set the + // transaction in progress flag + session_ptr->session_flags_ |= SESSION_FLAGS_SESSION_TRANSACTION_IN_PROGRESS; + return !omega_session_get_transaction_bit_(session_ptr); + case 2: + // This is the second or later change in a transaction, use the previous change transaction bit + return omega_session_get_transaction_bit_(session_ptr); + default: + // This should never happen + ABORT(LOG_ERROR("Invalid transaction state");); + return false; } - session_ptr->models_.back()->changes.push_back(change_ptr); - if (0 != update_model_(session_ptr, change_ptr)) { return -1; } - update_viewports_(session_ptr, change_ptr.get()); - omega_session_notify(session_ptr, SESSION_EVT_EDIT, change_ptr.get()); - return omega_change_get_serial(change_ptr.get()); } - return -1; } 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) { std::string checkpoint_directory_str; // If no checkpoint directory is specified, then try to figure out a good default - if (!checkpoint_directory) { + if (checkpoint_directory == nullptr) { // First try to use the directory of the file being edited - if (file_path && file_path[0] != '\0') { + if ((file_path != nullptr) && file_path[0] != '\0') { checkpoint_directory = checkpoint_directory_str.assign(omega_util_dirname(file_path, nullptr)).c_str(); } // If that doesn't work, then try to use the system temp directory - if (!checkpoint_directory) { - const auto temp_dir = omega_util_get_temp_directory(); - if (temp_dir) { + if (checkpoint_directory == nullptr) { + auto *const temp_dir = omega_util_get_temp_directory(); + if (temp_dir != nullptr) { checkpoint_directory = checkpoint_directory_str.assign(temp_dir).c_str(); free(temp_dir); } else { @@ -341,52 +367,55 @@ omega_session_t *omega_edit_create_session(const char *file_path, omega_session_ } } } - if (!omega_util_directory_exists(checkpoint_directory) && 0 != omega_util_create_directory(checkpoint_directory)) { + if ((omega_util_directory_exists(checkpoint_directory) == 0) && + 0 != omega_util_create_directory(checkpoint_directory)) { LOG_ERROR("failed to create checkpoint directory '" << checkpoint_directory << "'"); return nullptr; } - auto resolved_path = omega_util_normalize_path(checkpoint_directory, nullptr); - if (!resolved_path) { + auto *const resolved_path = omega_util_normalize_path(checkpoint_directory, nullptr); + if (resolved_path == nullptr) { LOG_ERROR("failed to resolve checkpoint_directory path '" << checkpoint_directory << "' to absolute path"); return nullptr; } checkpoint_directory_str.assign(resolved_path); FILE *file_ptr = nullptr; - char checkpoint_filename[FILENAME_MAX]; - if (file_path && file_path[0] != '\0') { + char checkpoint_filename[FILENAME_MAX + 1]; // +1 for null terminator + if ((file_path != nullptr) && file_path[0] != '\0') { // Copy the original file to a checkpoint file to handle out of band changes to the original file - if (FILENAME_MAX <= snprintf(checkpoint_filename, FILENAME_MAX, "%s%c.OmegaEdit-orig.XXXXXX", - checkpoint_directory_str.c_str(), omega_util_directory_separator())) { + if (FILENAME_MAX <= + snprintf(static_cast(checkpoint_filename), FILENAME_MAX, "%s%c.OmegaEdit-orig.XXXXXX", + checkpoint_directory_str.c_str(), omega_util_directory_separator())) { LOG_ERROR("failed to create original checkpoint filename template"); return nullptr; } const auto mode = 0600;// S_IRUSR | S_IWUSR - const auto checkpoint_fd = omega_util_mkstemp(checkpoint_filename, mode); + const auto checkpoint_fd = omega_util_mkstemp(static_cast(checkpoint_filename), mode); close(checkpoint_fd); - if (0 != omega_util_file_copy(file_path, checkpoint_filename, mode)) { - LOG_ERROR("failed to copy original file '" << file_path << "' to checkpoint file '" << checkpoint_filename + if (0 != omega_util_file_copy(file_path, static_cast(checkpoint_filename), mode)) { + LOG_ERROR("failed to copy original file '" << file_path << "' to checkpoint file '" + << static_cast(checkpoint_filename) << "'"); return nullptr; } file_ptr = FOPEN(checkpoint_filename, "rb"); - if (!file_ptr) { return nullptr; } + if (file_ptr == nullptr) { return nullptr; } } off_t file_size = 0; - if (file_ptr) { + if (file_ptr != nullptr) { if (0 != FSEEK(file_ptr, 0L, SEEK_END)) { FCLOSE(file_ptr); return nullptr; } file_size = FTELL(file_ptr); } - const auto session_ptr = new omega_session_t; + auto *const session_ptr = new omega_session_t; session_ptr->checkpoint_directory_ = checkpoint_directory_str; session_ptr->event_handler = cbk; session_ptr->user_data_ptr = user_data_ptr; session_ptr->event_interest_ = event_interest; session_ptr->num_changes_adjustment_ = 0; session_ptr->models_.push_back(std::make_unique()); - if (file_ptr) { + if (file_ptr != nullptr) { session_ptr->models_.back()->file_ptr = file_ptr; session_ptr->models_.back()->file_path.assign(file_path); session_ptr->checkpoint_file_name_.assign(checkpoint_filename); @@ -399,7 +428,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 @@ -413,7 +442,7 @@ void omega_edit_destroy_session(omega_session_t *session_ptr) { // Destroy all undone changes free_session_changes_undone_(session_ptr); // Remove all checkpoint files - while (omega_session_get_num_checkpoints(session_ptr)) { + while (omega_session_get_num_checkpoints(session_ptr) != 0) { if (0 != omega_util_remove_file(session_ptr->models_.back()->file_path.c_str())) { LOG_ERRNO(); } session_ptr->models_.pop_back(); } @@ -454,7 +483,7 @@ void omega_edit_destroy_viewport(omega_viewport_t *viewport_ptr) { for (auto iter = viewport_ptr->session_ptr->viewports_.rbegin(); iter != viewport_ptr->session_ptr->viewports_.rend(); ++iter) { if (viewport_ptr == iter->get()) { - const auto session_ptr = viewport_ptr->session_ptr; + auto *const session_ptr = viewport_ptr->session_ptr; omega_data_destroy(&(*iter)->data_segment.data, omega_viewport_get_capacity(iter->get())); session_ptr->viewports_.erase(std::next(iter).base()); omega_session_notify(session_ptr, SESSION_EVT_DESTROY_VIEWPORT, viewport_ptr); @@ -463,42 +492,22 @@ void omega_edit_destroy_viewport(omega_viewport_t *viewport_ptr) { } } -inline bool determine_change_transaction_bit_(omega_session_t *session_ptr) { - switch (omega_session_get_transaction_state(session_ptr)) { - case 0: - // No transaction in progress, use the flipped previous change transaction bit - return !omega_session_get_transaction_bit_(session_ptr); - case 1: - // This is the first change in a transaction, use the flipped previous change transaction bit and set the - // transaction in progress flag - session_ptr->session_flags_ |= SESSION_FLAGS_SESSION_TRANSACTION_IN_PROGRESS; - return !omega_session_get_transaction_bit_(session_ptr); - case 2: - // This is the second or later change in a transaction, use the previous change transaction bit - return omega_session_get_transaction_bit_(session_ptr); - default: - // This should never happen - ABORT(LOG_ERROR("Invalid transaction state");); - return false; - } -} - 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, - min(length, static_cast(computed_file_size) - offset), - determine_change_transaction_bit_(session_ptr))) - : 0; + return (omega_session_changes_paused(session_ptr) == 0) && 0 < length && offset < computed_file_size + ? update_(session_ptr, del_(1 + omega_session_get_num_changes(session_ptr), offset, + min(length, static_cast(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; + return (omega_session_changes_paused(session_ptr) == 0) && 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; } int64_t omega_edit_insert(omega_session_t *session_ptr, int64_t offset, const char *cstr, int64_t length) { @@ -507,11 +516,11 @@ 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; + return (omega_session_changes_paused(session_ptr) == 0) && 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; } int64_t omega_edit_overwrite(omega_session_t *session_ptr, int64_t offset, const char *cstr, int64_t length) { @@ -520,7 +529,7 @@ int64_t omega_edit_overwrite(omega_session_t *session_ptr, int64_t offset, const 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) { - if (!omega_session_changes_paused(session_ptr) && 0 == omega_edit_create_checkpoint(session_ptr)) { + if ((omega_session_changes_paused(session_ptr) == 0) && 0 == omega_edit_create_checkpoint(session_ptr)) { const auto in_file = session_ptr->models_.back()->file_path; const auto out_file = in_file + "_"; if (0 == omega_util_apply_byte_transform_to_file(in_file.c_str(), out_file.c_str(), transform, user_data_ptr, @@ -528,8 +537,8 @@ int omega_edit_apply_transform(omega_session_t *session_ptr, omega_util_byte_tra errno = 0;// reset errno 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_) { + ((session_ptr->models_.back()->file_ptr = FOPEN(in_file.c_str(), "rb")) != nullptr)) { + 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); @@ -542,7 +551,7 @@ int omega_edit_apply_transform(omega_session_t *session_ptr, omega_util_byte_tra ABORT(LOG_ERRNO();); } // The transform failed, but we can recover from this - if (omega_util_file_exists(out_file.c_str())) { omega_util_remove_file(out_file.c_str()); } + if (omega_util_file_exists(out_file.c_str()) != 0) { omega_util_remove_file(out_file.c_str()); } } return -1; } @@ -553,8 +562,7 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, assert(file_path); assert(0 <= offset); const auto computed_file_size = omega_session_get_computed_file_size(session_ptr); - const auto adjusted_length = - length <= 0 ? computed_file_size - offset : min(length, computed_file_size - offset); + const auto adjusted_length = length <= 0 ? computed_file_size - offset : 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); @@ -563,18 +571,19 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, char temp_filename[FILENAME_MAX]; const auto force_overwrite = io_flags & omega_io_flags_t::IO_FLG_FORCE_OVERWRITE; const auto overwrite = force_overwrite || io_flags & omega_io_flags_t::IO_FLG_OVERWRITE; - const auto session_file_path = omega_session_get_file_path(session_ptr); - const auto checkpoint_file = session_ptr->checkpoint_file_name_.c_str(); - if (saved_file_path) { saved_file_path[0] = '\0'; } + const auto *const session_file_path = omega_session_get_file_path(session_ptr); + const auto *const checkpoint_file = session_ptr->checkpoint_file_name_.c_str(); + if (saved_file_path != nullptr) { saved_file_path[0] = '\0'; } // If overwrite is requested and the file path is the same as the original session file, then overwrite_original // will be true - const auto overwrite_original = (overwrite && session_file_path && omega_util_file_exists(file_path) && - omega_util_paths_equivalent(file_path, session_file_path)); + const auto overwrite_original = (overwrite && (session_file_path != nullptr) && + (omega_util_file_exists(file_path) != 0) && + (omega_util_paths_equivalent(file_path, session_file_path) != 0)); // If the original file is going to be overwritten, and the file has been modified since the session was opened, and // the IO_FLG_FORCE_OVERWRITE flag is not set, then return an error - if (overwrite_original && !force_overwrite && + if (overwrite_original && (force_overwrite == 0) && 1 == omega_util_compare_modification_times(session_file_path, checkpoint_file)) { LOG_ERROR("original file '" << session_file_path << "' has been modified since the session was created, save failed (use " @@ -584,16 +593,16 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, omega_util_dirname(file_path, temp_filename); if (!temp_filename[0]) { omega_util_get_current_dir(temp_filename); } - if (!omega_util_directory_exists(temp_filename) && 0 != omega_util_create_directory(temp_filename)) { + if ((omega_util_directory_exists(temp_filename) == 0) && 0 != omega_util_create_directory(temp_filename)) { LOG_ERROR("failed to create directory: " << omega_util_normalize_path(temp_filename, nullptr)); return -2; } 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; @@ -615,7 +624,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);); @@ -635,7 +644,7 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, switch (omega_model_segment_get_kind(segment.get())) { case model_segment_kind_t::SEGMENT_READ: { - if (!session_ptr->models_.back()->file_ptr) { + if (session_ptr->models_.back()->file_ptr == nullptr) { ABORT(LOG_ERROR("attempt to read segment from null file pointer");); } if (omega_util_write_segment_to_file(session_ptr->models_.back()->file_ptr, @@ -650,7 +659,7 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, } case model_segment_kind_t::SEGMENT_INSERT: { if (static_cast(fwrite(omega_change_get_bytes(segment->change_ptr.get()) + - segment->change_offset + segment_start, + segment->change_offset + segment_start, 1, segment_length, temp_fptr)) != segment_length) { FCLOSE(temp_fptr); omega_util_remove_file(temp_filename); @@ -672,7 +681,8 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, return -8; } if (bytes_written != omega_util_file_size(temp_filename)) { - LOG_ERROR("failed to write all requested bytes to '" << temp_filename << "', expected: " << bytes_written << ", got: " << omega_util_file_size(temp_filename)); + LOG_ERROR("failed to write all requested bytes to '" << temp_filename << "', expected: " << bytes_written + << ", got: " << omega_util_file_size(temp_filename)); //omega_util_remove_file(temp_filename); return -9; } @@ -682,12 +692,12 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, LOG_ERRNO(); return -10; } - } else if (!(file_path = omega_util_available_filename(file_path, nullptr))) { + } else if ((file_path = omega_util_available_filename(file_path, nullptr)) == nullptr) { LOG_ERROR("cannot find an available filename"); return -11; } } - if (rename(temp_filename, file_path)) { + if (rename(temp_filename, file_path) != 0) { LOG_ERRNO(); return -12; } @@ -697,14 +707,14 @@ int omega_edit_save_segment(omega_session_t *session_ptr, const char *file_path, if (overwrite_original) { if (0 != omega_util_touch(checkpoint_file, 0)) { LOG_ERROR("failed to touch checkpoint file: " << checkpoint_file); -#ifndef OMEGA_BUILD_WINDOWS // Windows files may not have their modified times updated without elevated privileges +#ifndef OMEGA_BUILD_WINDOWS// Windows files may not have their modified times updated without elevated privileges return -13; #endif } assert(0 <= omega_util_compare_modification_times(checkpoint_file, file_path)); } - if (saved_file_path) { omega_util_normalize_path(file_path, saved_file_path); } + if (saved_file_path != nullptr) { omega_util_normalize_path(file_path, saved_file_path); } omega_session_notify(session_ptr, SESSION_EVT_SAVE, saved_file_path); return 0; } @@ -715,14 +725,14 @@ int omega_edit_save(omega_session_t *session_ptr, const char *file_path, int io_ int omega_edit_clear_changes(omega_session_t *session_ptr) { int64_t length = 0; - if (session_ptr->models_.front()->file_ptr) { + if (session_ptr->models_.front()->file_ptr != nullptr) { if (0 != FSEEK(session_ptr->models_.front()->file_ptr, 0L, SEEK_END)) { return -1; } length = FTELL(session_ptr->models_.front()->file_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); } @@ -731,21 +741,21 @@ int omega_edit_clear_changes(omega_session_t *session_ptr) { } int64_t omega_edit_undo_last_change(omega_session_t *session_ptr) { - if (!omega_session_changes_paused(session_ptr) && !session_ptr->models_.back()->changes.empty()) { + if ((omega_session_changes_paused(session_ptr) == 0) && !session_ptr->models_.back()->changes.empty()) { const auto change_ptr = session_ptr->models_.back()->changes.back(); session_ptr->models_.back()->changes.pop_back(); int64_t length = 0; - if (session_ptr->models_.back()->file_ptr) { + if (session_ptr->models_.back()->file_ptr != nullptr) { if (0 != FSEEK(session_ptr->models_.back()->file_ptr, 0L, SEEK_END)) { return -1; } 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; } } // Negate the undone change's serial number to indicate that the change has been undone - const auto undone_change_ptr = const_cast(change_ptr.get()); + auto *const undone_change_ptr = const_cast(change_ptr.get()); undone_change_ptr->serial *= -1; session_ptr->models_.back()->changes_undone.push_back(change_ptr); @@ -755,7 +765,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); } @@ -766,14 +776,14 @@ int64_t omega_edit_undo_last_change(omega_session_t *session_ptr) { int64_t omega_edit_redo_last_undo(omega_session_t *session_ptr) { int64_t rc = 0; - if (!omega_session_changes_paused(session_ptr) && !session_ptr->models_.back()->changes_undone.empty()) { + if ((omega_session_changes_paused(session_ptr) == 0) && !session_ptr->models_.back()->changes_undone.empty()) { const auto change_ptr = session_ptr->models_.back()->changes_undone.back(); rc = update_(session_ptr, change_ptr); session_ptr->models_.back()->changes_undone.pop_back(); // 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); } } @@ -781,9 +791,9 @@ int64_t omega_edit_redo_last_undo(omega_session_t *session_ptr) { } int omega_edit_create_checkpoint(omega_session_t *session_ptr) { - const auto checkpoint_directory = omega_session_get_checkpoint_directory(session_ptr); + const auto *const checkpoint_directory = omega_session_get_checkpoint_directory(session_ptr); // make sure the checkpoint directory exists - if (!omega_util_directory_exists(checkpoint_directory)) { + if (omega_util_directory_exists(checkpoint_directory) == 0) { LOG_ERROR("checkpoint directory '" << checkpoint_directory << "' does not exist"); } char checkpoint_filename[FILENAME_MAX]; @@ -809,8 +819,8 @@ int omega_edit_create_checkpoint(omega_session_t *session_ptr) { } int omega_edit_destroy_last_checkpoint(omega_session_t *session_ptr) { - if (omega_session_get_num_checkpoints(session_ptr)) { - const auto last_checkpoint_ptr = session_ptr->models_.back().get(); + if (omega_session_get_num_checkpoints(session_ptr) > 0) { + auto *const last_checkpoint_ptr = session_ptr->models_.back().get(); FCLOSE(last_checkpoint_ptr->file_ptr); if (0 != omega_util_remove_file(last_checkpoint_ptr->file_path.c_str())) { LOG_ERRNO(); } free_model_changes_(last_checkpoint_ptr); diff --git a/core/src/lib/filesystem.cpp b/core/src/lib/filesystem.cpp index 804172c2..c32d883e 100644 --- a/core/src/lib/filesystem.cpp +++ b/core/src/lib/filesystem.cpp @@ -53,12 +53,12 @@ int omega_util_mkstemp(char *tmpl, int mode) { if (fd != -1) { return fd; } else if (errno != EEXIST) { - return -1; // If the error is not "File exists", give up. + return -1;// If the error is not "File exists", give up. } } errno = EEXIST; - return -2; // Exhausted all attempts + return -2;// Exhausted all attempts } int omega_util_file_exists(const char *path) { @@ -102,26 +102,26 @@ int omega_util_paths_equivalent(char const *path1, char const *path2) { return fs::equivalent(path1, path2) ? 1 : 0; } -int omega_util_compare_files(const char* path1, const char* path2) { +int omega_util_compare_files(const char *path1, const char *path2) { // Open the first file std::ifstream file1(path1, std::ios::binary); if (!file1) { LOG_ERROR("Error opening file: '" << path1 << "'"); - return -1; // Error opening the first file + return -1;// Error opening the first file } // Open the second file std::ifstream file2(path2, std::ios::binary); if (!file2) { LOG_ERROR("Error opening file: '" << path2 << "'"); - return -2; // Error opening the second file + return -2;// Error opening the second file } // Compare the files std::istreambuf_iterator end, iter1(file1), iter2(file2); while (iter1 != end && iter2 != end) { if (*iter1 != *iter2) { - return 1; // Files are not equal + return 1;// Files are not equal } ++iter1; ++iter2; @@ -154,8 +154,11 @@ int omega_util_compare_modification_times(const char *path1, const char *path2) const char *omega_util_get_current_dir(char *buffer) { static char buff[FILENAME_MAX];//create string buffer to hold path if (!buffer) { buffer = buff; } - auto const path = fs::current_path(); - auto const len = path.string().copy(buffer, FILENAME_MAX); + auto const path_str = fs::current_path().string(); + assert(0 < path_str.length()); + assert(FILENAME_MAX > path_str.length()); + auto const len = path_str.copy(buffer, path_str.length()); + assert(len == path_str.length()); buffer[len] = '\0'; return buffer; } @@ -164,17 +167,24 @@ char *omega_util_dirname(char const *path, char *buffer) { assert(path); static char buff[FILENAME_MAX];//create string buffer to hold path if (!buffer) { buffer = buff; } - auto const len = fs::path(path).parent_path().string().copy(buffer, FILENAME_MAX); + auto const dirname_str = fs::path(path).parent_path().string(); + assert(0 <= dirname_str.length()); + assert(FILENAME_MAX > dirname_str.length()); + auto const len = dirname_str.copy(buffer, dirname_str.length()); + assert(len == dirname_str.length()); buffer[len] = '\0'; return buffer; } char *omega_util_basename(char const *path, char *buffer, int drop_suffix) { assert(path); + assert(0 < strlen(path)); + assert(FILENAME_MAX > strlen(path)); static char buff[FILENAME_MAX];//create string buffer to hold path if (!buffer) { buffer = buff; } - auto const len = drop_suffix ? fs::path(path).stem().string().copy(buffer, FILENAME_MAX) - : fs::path(path).filename().string().copy(buffer, FILENAME_MAX); + auto const basename_str = (drop_suffix == 0) ? fs::path(path).filename().string() : fs::path(path).stem().string(); + auto const len = basename_str.copy(buffer, basename_str.length()); + assert(len == basename_str.length()); buffer[len] = '\0'; return buffer; } @@ -183,16 +193,24 @@ char *omega_util_file_extension(char const *path, char *buffer) { assert(path); static char buff[FILENAME_MAX];//create string buffer to hold path if (!buffer) { buffer = buff; } - auto const len = fs::path(path).extension().string().copy(buffer, FILENAME_MAX); + auto const path_str = fs::path(path).extension().string(); + assert(0 <= path_str.length()); + assert(FILENAME_MAX > path_str.length()); + auto const len = path_str.copy(buffer, path_str.length()); + assert(len == path_str.length()); buffer[len] = '\0'; return buffer; } char *omega_util_normalize_path(char const *path, char *buffer) { assert(path); - static char buff[FILENAME_MAX];//create string buffer to hold path + static char buff[FILENAME_MAX]{};//create string buffer to hold path if (!buffer) { buffer = buff; } - auto const len = fs::absolute(fs::canonical(path)).string().copy(buffer, FILENAME_MAX); + auto const absolute_path_str = fs::absolute(fs::canonical(path)).string(); + assert(0 < absolute_path_str.length()); + assert(FILENAME_MAX > absolute_path_str.length()); + auto const len = absolute_path_str.copy(buffer, absolute_path_str.length()); + assert(len == absolute_path_str.length()); buffer[len] = '\0'; return buffer; } @@ -214,10 +232,11 @@ char *omega_util_available_filename(char const *path, char *buffer) { // stop after 999 filenames exist return nullptr; } - auto const len = fs::path(dirname) - .append(basename + "-" + std::to_string(i) + extension) - .string() - .copy(buffer, FILENAME_MAX); + auto const filename_str = fs::path(dirname) + .append(basename + "-" + std::to_string(i) + extension) + .string(); + auto const len = filename_str.copy(buffer, filename_str.length()); + assert(len == filename_str.length()); buffer[len] = '\0'; } while (omega_util_file_exists(buffer)); return buffer; @@ -245,9 +264,7 @@ int omega_util_file_copy(const char *src_path, const char *dst_path, int mode) { } // Remove the destination file if it already exists - if (fs::exists(dst_fs_path)) { - fs::remove(dst_fs_path); - } + if (fs::exists(dst_fs_path)) { fs::remove(dst_fs_path); } // Copy the file to the destination path, overwriting if it already exists if (!fs::copy_file(src_fs_path, dst_fs_path, fs::copy_options::overwrite_existing)) { diff --git a/core/src/lib/impl_/change_def.hpp b/core/src/lib/impl_/change_def.hpp index 5a7eda90..587a14b3 100644 --- a/core/src/lib/impl_/change_def.hpp +++ b/core/src/lib/impl_/change_def.hpp @@ -19,7 +19,9 @@ #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_/find.cpp b/core/src/lib/impl_/find.cpp index 67763fd8..03df09cf 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) { @@ -87,8 +87,8 @@ 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); + ? (const unsigned char *) omega_util_memrchr(haystack, *needle, haystack_length) + : (const unsigned char *) std::memchr(haystack, *needle, haystack_length); } assert(skip_table_ptr); @@ -103,7 +103,7 @@ const unsigned char *omega_find(const unsigned char *haystack, size_t haystack_l 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) { + last_needle_char == skip && std::memcmp(needle, probe, needle_length) == 0) { return probe; } diff --git a/core/src/lib/impl_/internal_fun.cpp b/core/src/lib/impl_/internal_fun.cpp index 317db3d0..727957cb 100644 --- a/core/src/lib/impl_/internal_fun.cpp +++ b/core/src/lib/impl_/internal_fun.cpp @@ -62,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 @@ -140,5 +140,5 @@ static inline void print_model_segment_(const omega_model_segment_ptr_t &segment 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 56d371c2..ee5345e1 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_/macros.h b/core/src/lib/impl_/macros.h index 5dd56a0b..f7c64ee4 100644 --- a/core/src/lib/impl_/macros.h +++ b/core/src/lib/impl_/macros.h @@ -53,7 +53,9 @@ #define LOG_ERROR(x) \ do { CLOG << LOCATION << x << std::endl; } while (0) #ifdef _WIN32 + #include + #define LOG_ERRNO() \ do { \ DWORD errCode = GetLastError(); \ diff --git a/core/src/lib/impl_/model_segment_def.hpp b/core/src/lib/impl_/model_segment_def.hpp index fbfc4e10..512e3c2a 100644 --- a/core/src/lib/impl_/model_segment_def.hpp +++ b/core/src/lib/impl_/model_segment_def.hpp @@ -18,7 +18,9 @@ #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 7bcab7ac..410399f9 100644 --- a/core/src/lib/search.cpp +++ b/core/src/lib/search.cpp @@ -141,7 +141,7 @@ int omega_search_next_match(omega_search_context_t *search_context_ptr, int64_t } 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_context_ptr->match_offset - search_context_ptr->session_offset); } // Only start searching if the pattern length is less than the search length. diff --git a/core/src/lib/session.cpp b/core/src/lib/session.cpp index 8598b33c..d2ec9fcd 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())) { diff --git a/core/src/lib/utility.c b/core/src/lib/utility.c index e96034ed..71f55472 100644 --- a/core/src/lib/utility.c +++ b/core/src/lib/utility.c @@ -15,8 +15,10 @@ #include "../include/omega_edit/config.h" #ifdef OMEGA_BUILD_WINDOWS + #include #include + #ifdef OPEN #undef OPEN #endif @@ -55,8 +57,8 @@ int omega_util_compute_mode(int mode) { #ifdef OMEGA_BUILD_WINDOWS // Convert Unix-style mode bits to the equivalent Windows style int winMode = 0; - if (mode & 0400) winMode |= _S_IREAD; // Owner read - if (mode & 0200) winMode |= _S_IWRITE; // Owner write + if (mode & 0400) winMode |= _S_IREAD; // Owner read + if (mode & 0200) winMode |= _S_IWRITE;// Owner write return winMode; #else const mode_t umask_value = umask(0); @@ -278,7 +280,7 @@ char const *omega_util_BOM_to_string(omega_bom_t bom) { return "UTF-32LE"; case BOM_UTF32BE: return "UTF-32BE"; - case BOM_UNKNOWN: // fall through + case BOM_UNKNOWN:// fall through default: // Should never happen return "unknown"; @@ -362,7 +364,7 @@ void omega_util_count_characters(const unsigned char *data, size_t length, omega size_t i = 0; switch (counts_ptr->bom) { case BOM_UNKNOWN:// fall through, assume UTF-8 if the BOM is unknown - case BOM_NONE:// fall through, assume UTF-8 if the BOM is none + case BOM_NONE: // fall through, assume UTF-8 if the BOM is none case BOM_UTF8: while (i < length) { if ((data[i] & 0x80) == 0) { @@ -470,13 +472,13 @@ size_t omega_util_BOM_size(omega_bom_t bom) { switch (bom) { case BOM_UTF8: return 3; - case BOM_UTF16LE: // fall through + case BOM_UTF16LE:// fall through case BOM_UTF16BE: return 2; - case BOM_UTF32LE: // fall through + case BOM_UTF32LE:// fall through case BOM_UTF32BE: return 4; - case BOM_NONE: // fall through + case BOM_NONE:// fall through default: return 0; } @@ -500,8 +502,8 @@ const omega_byte_buffer_t *omega_util_BOM_to_buffer(omega_bom_t bom) { return &utf32le_bom; case BOM_UTF32BE: return &utf32be_bom; - case BOM_NONE: // fall through - case BOM_UNKNOWN: // fall through + case BOM_NONE: // fall through + case BOM_UNKNOWN:// fall through default: return NULL; } diff --git a/core/src/lib/viewport.cpp b/core/src/lib/viewport.cpp index 3f699763..ab14e41b 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 278c7220..520c3e79 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 56d564d1..3eb3fc08 100644 --- a/core/src/tests/omega_test.cpp +++ b/core/src/tests/omega_test.cpp @@ -45,9 +45,7 @@ const auto DATA_DIR = std::filesystem::current_path() / "data"; * Sleep for the given number of seconds. * @param seconds Number of seconds to sleep. */ -static inline void omega_util_sleep_(int seconds) { - std::this_thread::sleep_for(std::chrono::seconds(seconds)); -} +static inline void omega_util_sleep_(int seconds) { std::this_thread::sleep_for(std::chrono::seconds(seconds)); } TEST_CASE("Size Tests", "[SizeTests]") { REQUIRE(1 == sizeof(omega_byte_t));//must always be 1-byte @@ -118,16 +116,15 @@ TEST_CASE("File Compare", "[UtilTests]") { SECTION("Identity") { // Same file ought to yield identical contents REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.dat"), MAKE_PATH("test1.dat"))); - } - SECTION("Difference") { + }SECTION("Difference") { // Different files with different contents REQUIRE(0 != omega_util_compare_files(MAKE_PATH("test1.dat"), MAKE_PATH("test2.dat"))); } } TEST_CASE("File Copy", "[UtilTests]") { - struct stat src_stat {}; - struct stat dst_stat {}; + struct stat src_stat{}; + struct stat dst_stat{}; omega_util_remove_file(MAKE_PATH("test1.copy.dat")); #ifdef OMEGA_BUILD_WINDOWS // sleep for 1 second to ensure the file modification time is different, @@ -159,7 +156,7 @@ TEST_CASE("File Copy", "[UtilTests]") { // On Windows, the mode is not preserved as expected on non-Windows platforms REQUIRE(dst_mode == dst_stat.st_mode); #endif - + REQUIRE(omega_util_directory_exists(DATA_DIR.string().c_str())); REQUIRE(!omega_util_file_exists(DATA_DIR.string().c_str())); REQUIRE(!omega_util_directory_exists((DATA_DIR / "test1.copy.dat").string().c_str())); @@ -205,7 +202,8 @@ TEST_CASE("File Touch", "[UtilTests]") { REQUIRE_THAT(omega_util_available_filename(exists.c_str(), nullptr), Equals(expected)); expected = dont_exist; REQUIRE_THAT(omega_util_available_filename(dont_exist.c_str(), nullptr), Equals(expected)); - omega_util_touch(dont_exist.c_str(), 0); // logs an error as expected because create is false and the file does not exist + omega_util_touch(dont_exist.c_str(), + 0);// logs an error as expected because create is false and the file does not exist REQUIRE(!omega_util_file_exists(dont_exist.c_str())); #ifdef OMEGA_BUILD_WINDOWS // sleep for 1 second to ensure the file modification time is different, @@ -332,14 +330,18 @@ TEST_CASE("Transformer", "[TransformerTest]") { } TEST_CASE("File Transformer", "[TransformerTest]") { - REQUIRE(0 == omega_util_apply_byte_transform_to_file(MAKE_PATH("test1.dat"), MAKE_PATH("test1.actual.transformed.1.dat"), - to_upper, nullptr, 0, 0)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.transformed.1.dat"), MAKE_PATH("test1.actual.transformed.1.dat"))); - REQUIRE(0 == omega_util_apply_byte_transform_to_file(MAKE_PATH("test1.dat"), MAKE_PATH("test1.actual.transformed.2.dat"), - to_lower, nullptr, 37, 10)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.transformed.2.dat"), MAKE_PATH("test1.actual.transformed.2.dat"))); - REQUIRE(0 != omega_util_apply_byte_transform_to_file(MAKE_PATH("test1.dat"), MAKE_PATH("test1.actual.transformed.3.dat"), - to_lower, nullptr, 37, 100)); + REQUIRE(0 == omega_util_apply_byte_transform_to_file( + MAKE_PATH("test1.dat"), MAKE_PATH("test1.actual.transformed.1.dat"), to_upper, nullptr, 0, 0)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.transformed.1.dat"), + MAKE_PATH("test1.actual.transformed.1.dat"))); + REQUIRE(0 == omega_util_apply_byte_transform_to_file(MAKE_PATH("test1.dat"), + MAKE_PATH("test1.actual.transformed.2.dat"), to_lower, nullptr, + 37, 10)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.transformed.2.dat"), + MAKE_PATH("test1.actual.transformed.2.dat"))); + REQUIRE(0 != omega_util_apply_byte_transform_to_file(MAKE_PATH("test1.dat"), + MAKE_PATH("test1.actual.transformed.3.dat"), to_lower, nullptr, + 37, 100)); REQUIRE(0 == omega_util_file_exists(MAKE_PATH("test1.actual.transformed.3.dat"))); } @@ -467,34 +469,38 @@ TEST_CASE("Checkpoint Tests", "[CheckpointTests]") { REQUIRE(2 == omega_edit_overwrite_string(session_ptr, 37, "BCDEFGHIJKLMNOPQRSTUVWXY")); REQUIRE(2 == omega_session_get_num_changes(session_ptr)); REQUIRE(2 == omega_session_get_num_change_transactions(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.1.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), MAKE_PATH("test1.actual.checkpoint.1.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.1.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), + MAKE_PATH("test1.actual.checkpoint.1.dat"))); mask_info_t mask_info; mask_info.mask_kind = MASK_XOR; mask_info.mask = 0xFF; REQUIRE(0 == omega_edit_apply_transform(session_ptr, byte_mask_transform, &mask_info, 10, 26)); REQUIRE(2 == omega_session_get_num_checkpoints(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.2.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.2.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); REQUIRE(0 == omega_edit_apply_transform(session_ptr, byte_mask_transform, &mask_info, 10, 26)); REQUIRE(3 == omega_session_get_num_checkpoints(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.3.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), MAKE_PATH("test1.actual.checkpoint.3.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.3.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), + MAKE_PATH("test1.actual.checkpoint.3.dat"))); mask_info.mask_kind = MASK_AND; REQUIRE(0 == omega_edit_apply_transform(session_ptr, byte_mask_transform, &mask_info, 10, 0)); REQUIRE(4 == omega_session_get_num_checkpoints(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.4.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), MAKE_PATH("test1.actual.checkpoint.4.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.4.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), + MAKE_PATH("test1.actual.checkpoint.4.dat"))); mask_info.mask_kind = MASK_OR; mask_info.mask = 0x00; REQUIRE(0 == omega_edit_apply_transform(session_ptr, byte_mask_transform, &mask_info, 10, 0)); REQUIRE(5 == omega_session_get_num_checkpoints(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.5.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), MAKE_PATH("test1.actual.checkpoint.5.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.5.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), + MAKE_PATH("test1.actual.checkpoint.5.dat"))); mask_info.mask_kind = MASK_AND; REQUIRE(0 == omega_edit_apply_transform(session_ptr, byte_mask_transform, &mask_info, 10, 0)); REQUIRE(6 == omega_session_get_num_checkpoints(session_ptr)); @@ -502,9 +508,10 @@ TEST_CASE("Checkpoint Tests", "[CheckpointTests]") { "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); REQUIRE(3 == omega_session_get_num_changes(session_ptr)); REQUIRE(3 == omega_session_get_num_change_transactions(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.6.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.6.dat"), MAKE_PATH("test1.actual.checkpoint.6.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.6.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.6.dat"), + MAKE_PATH("test1.actual.checkpoint.6.dat"))); auto change_ptr = omega_session_get_last_change(session_ptr); REQUIRE(change_ptr); REQUIRE(3 == omega_change_get_serial(change_ptr)); @@ -519,9 +526,10 @@ TEST_CASE("Checkpoint Tests", "[CheckpointTests]") { REQUIRE(2 == omega_session_get_num_changes(session_ptr)); REQUIRE(2 == omega_session_get_num_change_transactions(session_ptr)); REQUIRE(nullptr == omega_session_get_last_change(session_ptr)); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.7.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), MAKE_PATH("test1.actual.checkpoint.7.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.actual.checkpoint.7.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.expected.checkpoint.1.dat"), + MAKE_PATH("test1.actual.checkpoint.7.dat"))); omega_edit_destroy_session(session_ptr); } @@ -543,26 +551,30 @@ TEST_CASE("Model Tests", "[ModelTests]") { char saved_filename[FILENAME_MAX]; omega_util_remove_file(MAKE_PATH("test_dir/model-test.actual.1.dat")); omega_util_remove_directory(MAKE_PATH("test_dir")); - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test_dir/model-test.actual.1.dat"), omega_io_flags_t::IO_FLG_NONE, - saved_filename)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.1.dat"), MAKE_PATH("test_dir/model-test.actual.1.dat"))); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test_dir/model-test.actual.1.dat"), + omega_io_flags_t::IO_FLG_NONE, saved_filename)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.1.dat"), + MAKE_PATH("test_dir/model-test.actual.1.dat"))); omega_util_remove_file(MAKE_PATH("model-test.actual.1.dat")); REQUIRE(0 == omega_util_remove_file(MAKE_PATH("test_dir/model-test.actual.1.dat"))); REQUIRE(0 == omega_util_remove_directory(MAKE_PATH("test_dir"))); REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.1.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); REQUIRE(0 != omega_util_compare_files(MAKE_PATH("model-test.dat"), MAKE_PATH("model-test.actual.1.dat"))); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.1.dat"), MAKE_PATH("model-test.actual.1.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.expected.1.dat"), MAKE_PATH("model-test.actual.1.dat"))); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("model-test.actual.1.dat"), saved_filename)); omega_util_remove_file(MAKE_PATH("model-test.actual.1-1.dat")); REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.1.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.actual.1.dat"), MAKE_PATH("model-test.actual.1-1.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.actual.1.dat"), MAKE_PATH("model-test.actual.1-1.dat"))); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("model-test.actual.1-1.dat"), saved_filename)); omega_util_remove_file(MAKE_PATH("model-test.actual.1-2.dat")); REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.1.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.actual.1.dat"), MAKE_PATH("model-test.actual.1-2.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.actual.1.dat"), MAKE_PATH("model-test.actual.1-2.dat"))); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("model-test.actual.1-2.dat"), saved_filename)); REQUIRE(0 < omega_edit_insert_bytes(session_ptr, 10, reinterpret_cast("0"), 1)); file_size += 1; @@ -570,7 +582,8 @@ TEST_CASE("Model Tests", "[ModelTests]") { omega_util_remove_file(MAKE_PATH("model-test.actual.2.dat")); REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.2.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.2.dat"), MAKE_PATH("model-test.actual.2.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.expected.2.dat"), MAKE_PATH("model-test.actual.2.dat"))); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("model-test.actual.2.dat"), saved_filename)); REQUIRE(0 < omega_edit_insert_bytes(session_ptr, 5, reinterpret_cast("xxx"), 0)); file_size += 3; @@ -578,7 +591,8 @@ TEST_CASE("Model Tests", "[ModelTests]") { REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.3.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename)); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("model-test.actual.3.dat"), saved_filename)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.3.dat"), MAKE_PATH("model-test.actual.3.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.expected.3.dat"), MAKE_PATH("model-test.actual.3.dat"))); auto num_changes = file_info.num_changes; REQUIRE(num_changes * -1 == omega_edit_undo_last_change(session_ptr)); REQUIRE(1 == omega_session_get_num_undone_changes(session_ptr)); @@ -592,7 +606,8 @@ TEST_CASE("Model Tests", "[ModelTests]") { REQUIRE(omega_session_get_computed_file_size(session_ptr) == file_size); REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.4.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.4.dat"), MAKE_PATH("model-test.actual.4.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.expected.4.dat"), MAKE_PATH("model-test.actual.4.dat"))); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("model-test.actual.4.dat"), saved_filename)); REQUIRE(1 == omega_session_get_num_undone_changes(session_ptr)); REQUIRE(0 < omega_edit_overwrite_string(session_ptr, 0, "-")); @@ -610,14 +625,15 @@ TEST_CASE("Model Tests", "[ModelTests]") { REQUIRE((last_change = omega_session_get_last_change(session_ptr))); REQUIRE('O' == omega_change_get_kind_as_char(last_change)); REQUIRE(1 == omega_change_get_length(last_change)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.5.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, + nullptr)); REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.5.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.5.dat"), MAKE_PATH("model-test.actual.5.dat"))); + omega_util_compare_files(MAKE_PATH("model-test.expected.5.dat"), MAKE_PATH("model-test.actual.5.dat"))); REQUIRE(0 < omega_edit_delete(session_ptr, 0, omega_session_get_computed_file_size(session_ptr))); REQUIRE(0 == omega_session_get_computed_file_size(session_ptr)); while (file_info.num_changes) { omega_edit_undo_last_change(session_ptr); } - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.6.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.6.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, + nullptr)); REQUIRE(file_info.num_changes == omega_session_get_num_changes(session_ptr)); REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.dat"), MAKE_PATH("model-test.actual.6.dat"))); omega_edit_destroy_session(session_ptr); @@ -700,7 +716,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { auto session_ptr = omega_edit_create_session(MAKE_PATH("utf-8_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_NONE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(0 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(5 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -712,7 +729,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("utf-8bom_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_UTF8 == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(3 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(5 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -724,7 +742,8 @@ 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, omega_session_detect_BOM(session_ptr, 0))); + omega_session_get_computed_file_size(session_ptr) - 2, + omega_session_detect_BOM(session_ptr, 0))); 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 @@ -736,7 +755,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("utf-16le_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_UTF16LE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(2 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(5 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -748,7 +768,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("utf-16be_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_UTF16BE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(2 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(5 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -760,7 +781,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("utf-32le_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_UTF32LE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(4 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(5 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -772,7 +794,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("utf-32be_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_UTF32BE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(4 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(5 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -784,7 +807,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("ascii_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_NONE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(0 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(14 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -796,7 +820,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(MAKE_PATH("ascii-dos_1.dat"), nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_NONE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(0 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(15 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -808,7 +833,8 @@ TEST_CASE("Character Counts", "[CharCounts]") { session_ptr = omega_edit_create_session(nullptr, nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); - REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, omega_session_detect_BOM(session_ptr, 0))); + REQUIRE(0 == omega_session_character_counts(session_ptr, char_counts_ptr, 0, 0, + omega_session_detect_BOM(session_ptr, 0))); REQUIRE(BOM_NONE == omega_character_counts_get_BOM(char_counts_ptr)); REQUIRE(0 == omega_character_counts_bom_bytes(char_counts_ptr)); REQUIRE(0 == omega_character_counts_single_byte_chars(char_counts_ptr)); @@ -897,10 +923,11 @@ TEST_CASE("Hanoi insert", "[ModelTests]") { REQUIRE(!omega_change_is_undone(omega_session_get_change(session_ptr, rc))); REQUIRE(0 == omega_session_get_num_undone_changes(session_ptr)); REQUIRE(0 == omega_check_model(session_ptr)); - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.7.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("model-test.actual.7.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, + nullptr)); REQUIRE(file_info.num_changes == omega_session_get_num_changes(session_ptr)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("model-test.expected.7.dat"), MAKE_PATH("model-test.actual.7.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("model-test.expected.7.dat"), MAKE_PATH("model-test.actual.7.dat"))); omega_edit_clear_changes(session_ptr); REQUIRE(0 == omega_session_get_num_changes(session_ptr)); omega_edit_insert_string(session_ptr, 0, "\rUnix EOL\n Mac EOL\n DOS EOL\r\n \r"); @@ -1005,8 +1032,8 @@ TEST_CASE("Check initialization", "[InitTests]") { REQUIRE(1 == omega_session_get_num_undone_changes(session_ptr)); REQUIRE(omega_session_get_num_changes(session_ptr) == num_changes_before_undo - 1); REQUIRE(71 == omega_session_get_computed_file_size(session_ptr)); - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("test1.dat.out"), omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.dat.out"), omega_io_flags_t::IO_FLG_OVERWRITE, + nullptr)); REQUIRE(6 == omega_session_get_num_changes(session_ptr)); REQUIRE(-6 == omega_edit_undo_last_change(session_ptr)); REQUIRE(5 == omega_session_get_num_changes(session_ptr)); @@ -1014,15 +1041,17 @@ TEST_CASE("Check initialization", "[InitTests]") { REQUIRE(0 == omega_edit_clear_changes(session_ptr)); REQUIRE(0 == omega_session_get_num_changes(session_ptr)); REQUIRE(0 == omega_session_get_num_undone_changes(session_ptr)); - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("test1.reset.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("test1.reset.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, + nullptr)); REQUIRE(0 == omega_util_compare_files(MAKE_PATH("test1.dat"), MAKE_PATH("test1.reset.dat"))); omega_edit_destroy_session(session_ptr); } } } -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; }; @@ -1130,24 +1159,24 @@ 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)))) + 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)); @@ -1235,10 +1264,11 @@ TEST_CASE("Search-Forward", "[SearchTests]") { while (omega_search_next_match(match_context, 1)) { ++needles_found; } REQUIRE(12 == needles_found); omega_search_destroy_context(match_context); - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("search-test.actual.1.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, nullptr)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("search-test.actual.1.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, + nullptr)); omega_edit_destroy_session(session_ptr); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("search-test.expected.1.dat"), MAKE_PATH("search-test.actual.1.dat"))); + REQUIRE(0 == + omega_util_compare_files(MAKE_PATH("search-test.expected.1.dat"), MAKE_PATH("search-test.actual.1.dat"))); session_ptr = omega_edit_create_session(nullptr, nullptr, nullptr, NO_EVENTS, nullptr); REQUIRE(session_ptr); std::string as = "bbbbabbbbaabbbba"; @@ -1473,17 +1503,20 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename)); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("session_save.1.dat"), saved_filename)); - REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.1.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - saved_filename, 1, 0)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.1.dat"), MAKE_PATH("session_save_seg.1.dat"))); + REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.1.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename, 1, 0)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.1.dat"), + MAKE_PATH("session_save_seg.1.dat"))); omega_util_remove_file(MAKE_PATH("session_save_seg.1.dat")); - REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.2.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - saved_filename, 0, 4)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.2.dat"), MAKE_PATH("session_save_seg.2.dat"))); + REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.2.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename, 0, 4)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.2.dat"), + MAKE_PATH("session_save_seg.2.dat"))); omega_util_remove_file(MAKE_PATH("session_save_seg.2.dat")); - REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.3.dat"), omega_io_flags_t::IO_FLG_OVERWRITE, - saved_filename, 2, 6)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.3.dat"), MAKE_PATH("session_save_seg.3.dat"))); + REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.3.dat"), + omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename, 2, 6)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.3.dat"), + MAKE_PATH("session_save_seg.3.dat"))); omega_util_remove_file(MAKE_PATH("session_save_seg.3.dat")); REQUIRE(7 == session_events_count); // SESSION_EVT_SAVE REQUIRE(2 == viewport_events_count);// no additional viewport events @@ -1516,32 +1549,34 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { omega_util_remove_file(MAKE_PATH("session_save.1-1.dat")); REQUIRE(5 == session_events_count); // SESSION_EVT_SAVE REQUIRE(3 == viewport_events_count);// VIEWPORT_EVT_EDIT - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_NONE, + saved_filename)); REQUIRE(6 == session_events_count);// SESSION_EVT_SAVE REQUIRE(omega_util_paths_equivalent(MAKE_PATH("session_save.1-1.dat"), saved_filename)); REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save.expected.2.dat"), MAKE_PATH("session_save.1-1.dat"))); omega_util_remove_file(MAKE_PATH("session_save.1-2.dat")); - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_NONE, + saved_filename)); REQUIRE(7 == session_events_count);// SESSION_EVT_SAVE REQUIRE(omega_util_paths_equivalent(MAKE_PATH("session_save.1-2.dat"), saved_filename)); REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save.expected.2.dat"), MAKE_PATH("session_save.1-2.dat"))); omega_util_remove_file(MAKE_PATH("session_save.1-3.dat")); - REQUIRE(0 == - omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_NONE, saved_filename)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("session_save.1.dat"), omega_io_flags_t::IO_FLG_NONE, + saved_filename)); REQUIRE(8 == session_events_count);// SESSION_EVT_SAVE REQUIRE(omega_util_paths_equivalent(MAKE_PATH("session_save.1-3.dat"), saved_filename)); REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save.expected.2.dat"), MAKE_PATH("session_save.1-3.dat"))); omega_util_remove_file(MAKE_PATH("session_save_seg.2.dat")); - REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.2.dat"), omega_io_flags_t::IO_FLG_NONE, - saved_filename, 0, 4)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.2.dat"), MAKE_PATH("session_save_seg.2.dat"))); + REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.2.dat"), + omega_io_flags_t::IO_FLG_NONE, saved_filename, 0, 4)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.2.dat"), + MAKE_PATH("session_save_seg.2.dat"))); omega_util_remove_file(MAKE_PATH("session_save_seg.2.dat")); omega_util_remove_file(MAKE_PATH("session_save_seg.3.dat")); - REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.3.dat"), omega_io_flags_t::IO_FLG_NONE, - saved_filename, 2, 6)); - REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.3.dat"), MAKE_PATH("session_save_seg.3.dat"))); + REQUIRE(0 == omega_edit_save_segment(session_ptr, MAKE_PATH("session_save_seg.3.dat"), + omega_io_flags_t::IO_FLG_NONE, saved_filename, 2, 6)); + REQUIRE(0 == omega_util_compare_files(MAKE_PATH("session_save_seg.expected.3.dat"), + MAKE_PATH("session_save_seg.3.dat"))); omega_util_remove_file(MAKE_PATH("session_save_seg.3.dat")); omega_edit_destroy_session(session_ptr); @@ -1559,8 +1594,8 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { REQUIRE(0 == omega_util_touch(MAKE_PATH("session_save.1-3.dat"), 0)); // overwrite should fail because the original file has been modified elsewhere const auto save_rc = omega_edit_save(session_ptr, MAKE_PATH("session_save.1-3.dat"), - omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename); -#ifdef OMEGA_BUILD_WINDOWS // Windows doesn't always support this + omega_io_flags_t::IO_FLG_OVERWRITE, saved_filename); +#ifdef OMEGA_BUILD_WINDOWS// Windows doesn't always support this REQUIRE((ORIGINAL_MODIFIED == save_rc || 0 == save_rc)); REQUIRE((saved_filename[0] == '\0' || 0 == save_rc)); #else @@ -1568,8 +1603,8 @@ TEST_CASE("Session Save", "[SessionSaveTests]") { REQUIRE(saved_filename[0] == '\0'); #endif // force overwrite should succeed - REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("session_save.1-3.dat"), omega_io_flags_t::IO_FLG_FORCE_OVERWRITE, - saved_filename)); + REQUIRE(0 == omega_edit_save(session_ptr, MAKE_PATH("session_save.1-3.dat"), + omega_io_flags_t::IO_FLG_FORCE_OVERWRITE, saved_filename)); REQUIRE(omega_util_paths_equivalent(MAKE_PATH("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); diff --git a/packages/client/webpack.config.js b/packages/client/webpack.config.js index 671748df..046c7126 100644 --- a/packages/client/webpack.config.js +++ b/packages/client/webpack.config.js @@ -49,7 +49,13 @@ module.exports = { }, plugins: [ new CopyPlugin({ - patterns: ['package.json', 'README.md'], + patterns: [ + 'package.json', + 'README.md', + '../../LICENSE.txt', + 'src/omega_edit_grpc_pb.d.ts', + 'src/omega_edit_pb.d.ts', + ], }), { // generate a file with the client version before compiling