From 6d3ee3ac6d35be713f9f76722afd9f82b6d7bb9c Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 10:29:31 +0200 Subject: [PATCH 01/11] Update README.md with GitHub Actions badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 946f005..fcd648a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # M's ropes library -![Travis (.com) branch](https://img.shields.io/travis/com/ruimaciel/mropes/develop.svg) +![GitHub actions: master branch](https://github.com/ruimaciel/mropes/actions/workflows/ccpp.yml/badge.svg?branch=master) ![License](https://img.shields.io/github/license/ruimaciel/mropes.svg) ![Language](https://img.shields.io/github/languages/top/ruimaciel/mropes.svg) ![Code size](https://img.shields.io/github/languages/code-size/ruimaciel/mropes.svg) From 81636ed8d3ba182b27946edb13d09ba294b68cbd Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 10:39:44 +0200 Subject: [PATCH 02/11] Cleanup: reformat CMakeLists.txt --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6e217c..d0f81d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,10 +35,10 @@ target_include_directories(${PROJECT_NAME} $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src -) + ) -set_target_properties( - ${PROJECT_NAME} PROPERTIES +set_target_properties(${PROJECT_NAME} + PROPERTIES C_STANDARD 90 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF @@ -53,9 +53,9 @@ install(TARGETS ${PROJECT_NAME} ) install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/include/mropes/version.h - DESTINATION include/${PROJECT_NAME} - ) + ${CMAKE_CURRENT_BINARY_DIR}/include/mropes/version.h + DESTINATION include/${PROJECT_NAME} + ) install( EXPORT ${PROJECT_NAME} From 8062aff5502229101f53619ee900c53a561ab890 Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 10:57:08 +0200 Subject: [PATCH 03/11] Bump version number post-release --- CMakeLists.txt | 2 +- Changelog.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0f81d3..6701b50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(mropes - VERSION 1.0.0.0 + VERSION 1.0.0.1 LANGUAGES C ) diff --git a/Changelog.md b/Changelog.md index 85ad407..c64341b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + ## [1.0.0] 2023-06-05 ### Changed - Stable release From caca11f35b00d0c450a93413a8236e21094f3961 Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 11:13:49 +0200 Subject: [PATCH 04/11] Set _GNU_SOURCE in unit tests to use strdup without warnings --- tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3648a21..9b33cc0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,8 @@ find_package(subunit REQUIRED) include_directories(${PROJECT_SOURCE_DIR}) +add_definitions(-D_GNU_SOURCE) # allow access to strdup in tests + set(mropes_tests_prefix "check_mropes_") file(GLOB mropes_test_files From 05e512f5dd29b32255826eb6d386901fdd91a37c Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 11:23:30 +0200 Subject: [PATCH 05/11] Adopt .clang-format spec --- .clang-format | 226 +++++++++++++ Changelog.md | 2 + include/mropes/rope.h | 45 +-- src/rope.c | 732 ++++++++++++++++++++---------------------- src/rope_ops.c | 538 +++++++++++++++---------------- src/rope_ops.h | 49 +-- src/rope_stack.c | 100 +++--- src/rope_stack.h | 13 +- 8 files changed, 946 insertions(+), 759 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b1392af --- /dev/null +++ b/.clang-format @@ -0,0 +1,226 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: NextLine +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: true +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb + BasedOnStyle: google +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/Changelog.md b/Changelog.md index c64341b..b183c97 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Adopt .clang-format spec ## [1.0.0] 2023-06-05 ### Changed diff --git a/include/mropes/rope.h b/include/mropes/rope.h index 4a6fe39..679f650 100644 --- a/include/mropes/rope.h +++ b/include/mropes/rope.h @@ -4,39 +4,38 @@ #include enum mrope_node_type { - MROPE_NODE_UNKNOWN = 0, - MROPE_NODE_LEAF, - MROPE_NODE_BRANCH + MROPE_NODE_UNKNOWN = 0, + MROPE_NODE_LEAF, + MROPE_NODE_BRANCH }; struct mrope_node { - enum mrope_node_type type; - size_t weight; + enum mrope_node_type type; + size_t weight; }; struct mrope_branch_node { - struct mrope_node node; + struct mrope_node node; - struct mrope_node * left; - struct mrope_node * right; + struct mrope_node *left; + struct mrope_node *right; }; struct mrope_leaf_node { - struct mrope_node node; + struct mrope_node node; - char * text; + char *text; }; struct mrope { - struct mrope_node * root_node; + struct mrope_node *root_node; }; -enum mrope_error_code -{ - MROPE_OK = 0, - MROPE_MALLOC_FAILED, - MROPE_UNKNOWN_NODE_TYPE, - MROPE_OUT_OF_RANGE +enum mrope_error_code { + MROPE_OK = 0, + MROPE_MALLOC_FAILED, + MROPE_UNKNOWN_NODE_TYPE, + MROPE_OUT_OF_RANGE }; typedef enum mrope_error_code mreturn_t; @@ -49,10 +48,14 @@ mreturn_t mrope_prepend_rope(mrope_t *rope_inout, mrope_t *rope_inout_lhs); mreturn_t mrope_append_text(mrope_t *rope_inout, char *text_rhs); mreturn_t mrope_append_rope(mrope_t *rope_inout, mrope_t *rope_inout_rhs); mreturn_t mrope_clone(const mrope_t *rope_in, mrope_t *rope_out); -mreturn_t mrope_concat( const mrope_t *rope_in_lhs, const mrope_t *rope_in_rhs, mrope_t *rope_out); -mreturn_t mrope_split(const mrope_t *rope_in, const size_t index, mrope_t *rope_out_lhs, mrope_t *rope_out_rhs); -mreturn_t mrope_insert(mrope_t *rope_inout, const size_t index, mrope_t *rope_in); -mreturn_t mrope_delete(mrope_t *rope_inout, const size_t index, const size_t length); +mreturn_t mrope_concat(const mrope_t *rope_in_lhs, const mrope_t *rope_in_rhs, + mrope_t *rope_out); +mreturn_t mrope_split(const mrope_t *rope_in, const size_t index, + mrope_t *rope_out_lhs, mrope_t *rope_out_rhs); +mreturn_t mrope_insert(mrope_t *rope_inout, const size_t index, + mrope_t *rope_in); +mreturn_t mrope_delete(mrope_t *rope_inout, const size_t index, + const size_t length); size_t mrope_length(const mrope_t *rope_in); char mrope_index(const mrope_t *rope_in, const size_t index); diff --git a/src/rope.c b/src/rope.c index c9bd62b..59ab4ed 100644 --- a/src/rope.c +++ b/src/rope.c @@ -1,463 +1,435 @@ -#include - #include +#include #include #include #include "rope_ops.h" #include "rope_stack.h" +mreturn_t mrope_init(mrope_t *rope_out) { + assert(rope_out != NULL); -mreturn_t mrope_init(mrope_t *rope_out) -{ - assert(rope_out != NULL); - - rope_out->root_node = NULL; + rope_out->root_node = NULL; - return MROPE_OK; + return MROPE_OK; } +mreturn_t mrope_free(mrope_t *rope_inout) { + mreturn_t error = MROPE_OK; -mreturn_t mrope_free(mrope_t *rope_inout) -{ - mreturn_t error = MROPE_OK; + assert(rope_inout != NULL); - assert(rope_inout != NULL); + if (rope_inout->root_node == NULL) { + return MROPE_OK; + } - if(rope_inout->root_node == NULL) { - return MROPE_OK; - } + /*TODO replace with breadth-first search */ + if ((error = mrope_free_node(rope_inout->root_node)) != MROPE_OK) { + return error; + } - /*TODO replace with breadth-first search */ - if( (error = mrope_free_node(rope_inout->root_node)) != MROPE_OK) { - return error; - } + rope_inout->root_node = NULL; - rope_inout->root_node = NULL; - - return MROPE_OK; + return MROPE_OK; } +mreturn_t mrope_prepend_rope(mrope_t *rope_inout, mrope_t *rope_inout_lhs) { + struct mrope_branch_node *new_root = NULL; -mreturn_t mrope_prepend_rope(mrope_t * rope_inout, mrope_t * rope_inout_lhs) -{ - struct mrope_branch_node * new_root = NULL; - - assert(rope_inout != NULL); + assert(rope_inout != NULL); - if(rope_inout_lhs == NULL) { - /* nothing to concatenate */ - return MROPE_OK; - } - if(rope_inout_lhs->root_node == NULL) { - /* nothing to concatenate */ - return MROPE_OK; - } + if (rope_inout_lhs == NULL) { + /* nothing to concatenate */ + return MROPE_OK; + } + if (rope_inout_lhs->root_node == NULL) { + /* nothing to concatenate */ + return MROPE_OK; + } - new_root = mrope_make_branch_node(rope_inout_lhs->root_node, rope_inout->root_node); - if(new_root == NULL) { - return MROPE_MALLOC_FAILED; - } + new_root = + mrope_make_branch_node(rope_inout_lhs->root_node, rope_inout->root_node); + if (new_root == NULL) { + return MROPE_MALLOC_FAILED; + } - rope_inout->root_node = (struct mrope_node *)new_root; + rope_inout->root_node = (struct mrope_node *)new_root; - rope_inout_lhs->root_node = NULL; + rope_inout_lhs->root_node = NULL; - return MROPE_OK; + return MROPE_OK; } - -mreturn_t mrope_append_text(mrope_t *rope_inout, char *text_rhs) -{ - mreturn_t error = MROPE_OK; - struct mrope_leaf_node * leaf_node = NULL; - - assert(rope_inout != NULL); - assert(text_rhs != NULL); - - /* convert text into a leaf node */ - - if( (error = mrope_make_leaf_node_from_text(&leaf_node, text_rhs)) != MROPE_OK) { - return error; - } - - if(rope_inout->root_node == NULL) { - rope_inout->root_node = (struct mrope_node *)leaf_node; - return MROPE_OK; - } - - switch(rope_inout->root_node->type) - { - - case MROPE_NODE_LEAF: - { - struct mrope_branch_node * branch_node = NULL; - if( (branch_node = mrope_make_branch_node(rope_inout->root_node, (struct mrope_node *)leaf_node)) == NULL) { - /* FIXIT free leaf node */ - mrope_free_leaf_node(leaf_node); - return MROPE_MALLOC_FAILED; - } - - rope_inout->root_node = (struct mrope_node *)branch_node; - - return MROPE_OK; - } - break; - - case MROPE_NODE_BRANCH: - { - struct mrope_branch_node * branch_root_node = (struct mrope_branch_node *) rope_inout->root_node; - if(branch_root_node->left == NULL) { - if(branch_root_node->right != NULL) { - branch_root_node->left = branch_root_node->right; - branch_root_node->right = (struct mrope_node *)leaf_node; - } - else { - branch_root_node->left = (struct mrope_node *)leaf_node; - branch_root_node->right = NULL; - } - branch_root_node->node.weight = branch_root_node->left->weight; - return MROPE_OK; - } - - if(branch_root_node->right == NULL) { - branch_root_node->right = (struct mrope_node *)leaf_node; - branch_root_node->node.weight = branch_root_node->left->weight + branch_root_node->right->weight; - return MROPE_OK; - } - - struct mrope_branch_node * branch = NULL; - if( (branch = mrope_make_branch_node((struct mrope_node *)rope_inout->root_node, (struct mrope_node *)leaf_node)) == NULL) { - mrope_free_leaf_node(leaf_node); - return MROPE_MALLOC_FAILED; - } - - /* update the rope to append the newly created leaf node */ - rope_inout->root_node = (struct mrope_node *)branch; - - return MROPE_OK; - } - break; - - default: - return MROPE_UNKNOWN_NODE_TYPE; - } +mreturn_t mrope_append_text(mrope_t *rope_inout, char *text_rhs) { + mreturn_t error = MROPE_OK; + struct mrope_leaf_node *leaf_node = NULL; + + assert(rope_inout != NULL); + assert(text_rhs != NULL); + + /* convert text into a leaf node */ + + if ((error = mrope_make_leaf_node_from_text(&leaf_node, text_rhs)) != + MROPE_OK) { + return error; + } + + if (rope_inout->root_node == NULL) { + rope_inout->root_node = (struct mrope_node *)leaf_node; + return MROPE_OK; + } + + switch (rope_inout->root_node->type) { + case MROPE_NODE_LEAF: { + struct mrope_branch_node *branch_node = NULL; + if ((branch_node = mrope_make_branch_node( + rope_inout->root_node, (struct mrope_node *)leaf_node)) == + NULL) { + /* FIXIT free leaf node */ + mrope_free_leaf_node(leaf_node); + return MROPE_MALLOC_FAILED; + } + + rope_inout->root_node = (struct mrope_node *)branch_node; + + return MROPE_OK; + } break; + + case MROPE_NODE_BRANCH: { + struct mrope_branch_node *branch_root_node = + (struct mrope_branch_node *)rope_inout->root_node; + if (branch_root_node->left == NULL) { + if (branch_root_node->right != NULL) { + branch_root_node->left = branch_root_node->right; + branch_root_node->right = (struct mrope_node *)leaf_node; + } else { + branch_root_node->left = (struct mrope_node *)leaf_node; + branch_root_node->right = NULL; + } + branch_root_node->node.weight = branch_root_node->left->weight; + return MROPE_OK; + } + + if (branch_root_node->right == NULL) { + branch_root_node->right = (struct mrope_node *)leaf_node; + branch_root_node->node.weight = + branch_root_node->left->weight + branch_root_node->right->weight; + return MROPE_OK; + } + + struct mrope_branch_node *branch = NULL; + if ((branch = mrope_make_branch_node( + (struct mrope_node *)rope_inout->root_node, + (struct mrope_node *)leaf_node)) == NULL) { + mrope_free_leaf_node(leaf_node); + return MROPE_MALLOC_FAILED; + } + + /* update the rope to append the newly created leaf node */ + rope_inout->root_node = (struct mrope_node *)branch; + + return MROPE_OK; + } break; + + default: + return MROPE_UNKNOWN_NODE_TYPE; + } } +mreturn_t mrope_append_rope(mrope_t *rope_inout, mrope_t *rope_inout_rhs) { + struct mrope_branch_node *new_root = NULL; -mreturn_t mrope_append_rope(mrope_t *rope_inout, mrope_t *rope_inout_rhs) -{ - struct mrope_branch_node * new_root = NULL; + assert(rope_inout != NULL); - assert(rope_inout != NULL); + if (rope_inout_rhs == NULL) { + /* nothing to concatenate */ + return MROPE_OK; + } + if (rope_inout_rhs->root_node == NULL) { + /* nothing to concatenate */ + return MROPE_OK; + } - if(rope_inout_rhs == NULL) { - /* nothing to concatenate */ - return MROPE_OK; - } - if(rope_inout_rhs->root_node == NULL) { - /* nothing to concatenate */ - return MROPE_OK; - } + new_root = + mrope_make_branch_node(rope_inout->root_node, rope_inout_rhs->root_node); + if (new_root == NULL) { + return MROPE_MALLOC_FAILED; + } - new_root = mrope_make_branch_node(rope_inout->root_node, rope_inout_rhs->root_node); - if(new_root == NULL) { - return MROPE_MALLOC_FAILED; - } + rope_inout->root_node = (struct mrope_node *)new_root; - rope_inout->root_node = (struct mrope_node *)new_root; + rope_inout_rhs->root_node = NULL; - rope_inout_rhs->root_node = NULL; - - - return MROPE_OK; + return MROPE_OK; } +mreturn_t mrope_concat(const mrope_t *rope_in_lhs, const mrope_t *rope_in_rhs, + mrope_t *rope_out) { + mrope_t cloned_lhs; + mrope_t cloned_rhs; + struct mrope_branch_node *branch_node = NULL; -mreturn_t mrope_concat(const mrope_t *rope_in_lhs, const mrope_t *rope_in_rhs, mrope_t *rope_out) -{ - mrope_t cloned_lhs; - mrope_t cloned_rhs; - struct mrope_branch_node *branch_node = NULL; + assert(rope_out != NULL); + assert(rope_in_lhs != NULL); + assert(rope_in_rhs != NULL); - assert(rope_out != NULL); - assert(rope_in_lhs != NULL); - assert(rope_in_rhs != NULL); + mrope_init(&cloned_lhs); + mrope_init(&cloned_rhs); - mrope_init(&cloned_lhs); - mrope_init(&cloned_rhs); + mrope_clone(rope_in_lhs, &cloned_lhs); + mrope_clone(rope_in_rhs, &cloned_rhs); - mrope_clone(rope_in_lhs, &cloned_lhs); - mrope_clone(rope_in_rhs, &cloned_rhs); + branch_node = + mrope_make_branch_node(cloned_lhs.root_node, cloned_rhs.root_node); - branch_node = mrope_make_branch_node(cloned_lhs.root_node, cloned_rhs.root_node); + rope_out->root_node = (struct mrope_node *)branch_node; - rope_out->root_node = (struct mrope_node *)branch_node; - - return MROPE_OK; + return MROPE_OK; } +mreturn_t mrope_split(const mrope_t *rope_in, const size_t index, + mrope_t *rope_out_lhs, mrope_t *rope_out_rhs) { + mreturn_t error = MROPE_OK; + mrope_stack_t node_stack; + mrope_t out_lhs, out_rhs; + size_t current_index = 0; + + assert(rope_in != NULL); + assert(rope_out_lhs != NULL); + assert(rope_out_rhs != NULL); + + if (index > mrope_length(rope_in)) { + return MROPE_OUT_OF_RANGE; + } + + /* Let's run a stack-based depth-first search through the mrope data structure + */ + if ((error = mrope_stack_init(&node_stack)) != MROPE_OK) { + return error; + } + + mrope_stack_push(&node_stack, rope_in->root_node); + + error = mrope_init(&out_lhs); + if (error != MROPE_OK) { + return error; + } + + error = mrope_init(&out_rhs); + if (error != MROPE_OK) { + return error; + } + + /* the depth-first search will finish once the stack is empty */ + while (mrope_stack_top(&node_stack) != NULL) { + struct mrope_node *node = NULL; + + error = mrope_stack_pop(&node_stack, &node); + if (error != MROPE_OK) { + goto error_cleanup; + } -mreturn_t mrope_split(const mrope_t *rope_in, const size_t index, mrope_t *rope_out_lhs, mrope_t *rope_out_rhs) -{ - mreturn_t error = MROPE_OK; - mrope_stack_t node_stack; - mrope_t out_lhs, out_rhs; - size_t current_index = 0; - - assert(rope_in != NULL); - assert(rope_out_lhs != NULL); - assert(rope_out_rhs != NULL); - - if(index > mrope_length(rope_in)) { - return MROPE_OUT_OF_RANGE; - } - - /* Let's run a stack-based depth-first search through the mrope data structure */ - if( (error = mrope_stack_init(&node_stack)) != MROPE_OK) { - return error; - } - - mrope_stack_push(&node_stack, rope_in->root_node); - - error = mrope_init(&out_lhs); - if(error != MROPE_OK) { - return error; - } - - error = mrope_init(&out_rhs); - if(error != MROPE_OK) { - return error; - } - - /* the depth-first search will finish once the stack is empty */ - while(mrope_stack_top(&node_stack) != NULL) { - - struct mrope_node *node = NULL; - - error = mrope_stack_pop(&node_stack, &node); - if(error != MROPE_OK) { - goto error_cleanup; - } - - switch(node->type) - { - case MROPE_NODE_BRANCH: - { - struct mrope_branch_node *branch_node = (struct mrope_branch_node *)(node); - if(branch_node->left != NULL) { - error = mrope_stack_push(&node_stack,branch_node->left); - if(error != MROPE_OK) { - goto error_cleanup; - } - } - if(branch_node->right != NULL) { - error = mrope_stack_push(&node_stack,branch_node->right); - if(error != MROPE_OK) { - goto error_cleanup; - } - } - continue; - } - break; - - case MROPE_NODE_LEAF: - { - struct mrope_leaf_node *leaf_node = (struct mrope_leaf_node *)(node); - - /* Duplicates string */ - const size_t sz = leaf_node->node.weight+1; - char * duplicate_string = NULL; - if( ( duplicate_string = malloc(sz)) == NULL) { - error = MROPE_MALLOC_FAILED; - goto error_cleanup; - } - strncpy(duplicate_string, leaf_node->text, sz); - - if(index > current_index + leaf_node->node.weight) { - error = mrope_append_text(&out_lhs, duplicate_string); - if(error != MROPE_OK) { - goto error_cleanup; - } - } - else if(index <= current_index) { - error = mrope_append_text(&out_rhs, duplicate_string); - if(error != MROPE_OK) { - mrope_free(&out_lhs); - mrope_free(&out_rhs); - return error; - } - } - else { - const size_t offset = index-current_index; - char * lhs_string = NULL; - char * rhs_string = NULL; - - duplicate_string[offset] = '\0'; - if((lhs_string = realloc(duplicate_string, offset*sizeof(char))) == NULL) { - free(duplicate_string); - error = MROPE_MALLOC_FAILED; - goto error_cleanup; - } - - if( (error = mrope_append_text(&out_lhs, lhs_string)) != MROPE_OK) { - goto error_cleanup; - } - - if( ( rhs_string = malloc(sz-offset)) == NULL) { - error = MROPE_MALLOC_FAILED; - goto error_cleanup; - } - strncpy(rhs_string, &leaf_node->text[offset], sz-offset); - - if( (error = mrope_append_text(&out_rhs, rhs_string)) != MROPE_OK) { - goto error_cleanup; - } - } - - current_index += leaf_node->node.weight; - } - break; - - default: - { - error = MROPE_UNKNOWN_NODE_TYPE; - goto error_cleanup; - } - break; - } - } - - rope_out_lhs->root_node = out_lhs.root_node; - rope_out_rhs->root_node = out_rhs.root_node; - - return MROPE_OK; + switch (node->type) { + case MROPE_NODE_BRANCH: { + struct mrope_branch_node *branch_node = + (struct mrope_branch_node *)(node); + if (branch_node->left != NULL) { + error = mrope_stack_push(&node_stack, branch_node->left); + if (error != MROPE_OK) { + goto error_cleanup; + } + } + if (branch_node->right != NULL) { + error = mrope_stack_push(&node_stack, branch_node->right); + if (error != MROPE_OK) { + goto error_cleanup; + } + } + continue; + } break; + + case MROPE_NODE_LEAF: { + struct mrope_leaf_node *leaf_node = (struct mrope_leaf_node *)(node); + + /* Duplicates string */ + const size_t sz = leaf_node->node.weight + 1; + char *duplicate_string = NULL; + if ((duplicate_string = malloc(sz)) == NULL) { + error = MROPE_MALLOC_FAILED; + goto error_cleanup; + } + strncpy(duplicate_string, leaf_node->text, sz); + + if (index > current_index + leaf_node->node.weight) { + error = mrope_append_text(&out_lhs, duplicate_string); + if (error != MROPE_OK) { + goto error_cleanup; + } + } else if (index <= current_index) { + error = mrope_append_text(&out_rhs, duplicate_string); + if (error != MROPE_OK) { + mrope_free(&out_lhs); + mrope_free(&out_rhs); + return error; + } + } else { + const size_t offset = index - current_index; + char *lhs_string = NULL; + char *rhs_string = NULL; + + duplicate_string[offset] = '\0'; + if ((lhs_string = realloc(duplicate_string, offset * sizeof(char))) == + NULL) { + free(duplicate_string); + error = MROPE_MALLOC_FAILED; + goto error_cleanup; + } + + if ((error = mrope_append_text(&out_lhs, lhs_string)) != MROPE_OK) { + goto error_cleanup; + } + + if ((rhs_string = malloc(sz - offset)) == NULL) { + error = MROPE_MALLOC_FAILED; + goto error_cleanup; + } + strncpy(rhs_string, &leaf_node->text[offset], sz - offset); + + if ((error = mrope_append_text(&out_rhs, rhs_string)) != MROPE_OK) { + goto error_cleanup; + } + } -error_cleanup: - mrope_free(&out_lhs); - mrope_free(&out_rhs); - return error; + current_index += leaf_node->node.weight; + } break; -} + default: { + error = MROPE_UNKNOWN_NODE_TYPE; + goto error_cleanup; + } break; + } + } + rope_out_lhs->root_node = out_lhs.root_node; + rope_out_rhs->root_node = out_rhs.root_node; -mreturn_t mrope_insert(mrope_t *rope_inout, const size_t index, mrope_t *rope_in) -{ - mreturn_t error = MROPE_OK; - mrope_t temp_lhs, temp_rhs; + return MROPE_OK; - assert(rope_inout != NULL); - assert(rope_in != NULL); +error_cleanup: + mrope_free(&out_lhs); + mrope_free(&out_rhs); + return error; +} - mrope_init(&temp_lhs); - mrope_init(&temp_rhs); +mreturn_t mrope_insert(mrope_t *rope_inout, const size_t index, + mrope_t *rope_in) { + mreturn_t error = MROPE_OK; + mrope_t temp_lhs, temp_rhs; + assert(rope_inout != NULL); + assert(rope_in != NULL); - error = mrope_split(rope_inout, index, &temp_lhs, &temp_rhs); - if(error != MROPE_OK) { - return error; - } + mrope_init(&temp_lhs); + mrope_init(&temp_rhs); - error = mrope_append_rope(&temp_lhs, rope_in); - if(error != MROPE_OK) { - return error; - } + error = mrope_split(rope_inout, index, &temp_lhs, &temp_rhs); + if (error != MROPE_OK) { + return error; + } - error = mrope_append_rope(&temp_lhs, &temp_rhs); - if(error != MROPE_OK) { - return error; - } + error = mrope_append_rope(&temp_lhs, rope_in); + if (error != MROPE_OK) { + return error; + } - rope_inout->root_node = temp_lhs.root_node; - temp_lhs.root_node = NULL; - mrope_free(&temp_lhs); - mrope_free(&temp_rhs); + error = mrope_append_rope(&temp_lhs, &temp_rhs); + if (error != MROPE_OK) { + return error; + } - return MROPE_OK; -} + rope_inout->root_node = temp_lhs.root_node; + temp_lhs.root_node = NULL; + mrope_free(&temp_lhs); + mrope_free(&temp_rhs); + return MROPE_OK; +} -size_t mrope_length(const mrope_t *rope_in) -{ - assert(rope_in != NULL); +size_t mrope_length(const mrope_t *rope_in) { + assert(rope_in != NULL); - if(rope_in->root_node == NULL) { - return 0; - } + if (rope_in->root_node == NULL) { + return 0; + } - return rope_in->root_node->weight; + return rope_in->root_node->weight; } +char mrope_index(const mrope_t *rope_in, const size_t index) { + assert(rope_in != NULL); -char mrope_index(const mrope_t *rope_in, const size_t index) -{ - assert(rope_in != NULL); - - return mrope_index_node(rope_in->root_node, index); - + return mrope_index_node(rope_in->root_node, index); } +mreturn_t mrope_clone(const mrope_t *rope_in, mrope_t *rope_out) { + struct mrope_node *cloned_root_node = NULL; + mreturn_t error = MROPE_OK; -mreturn_t mrope_clone(const mrope_t *rope_in, mrope_t * rope_out) -{ - struct mrope_node * cloned_root_node = NULL; - mreturn_t error = MROPE_OK; + assert(rope_in != NULL); + assert(rope_out != NULL); - assert(rope_in != NULL); - assert(rope_out != NULL); - - if(rope_in->root_node != NULL) { - if( (error = mrope_clone_node(rope_in->root_node, &cloned_root_node)) != MROPE_OK) { - return error; - } + if (rope_in->root_node != NULL) { + if ((error = mrope_clone_node(rope_in->root_node, &cloned_root_node)) != + MROPE_OK) { + return error; } + } - rope_out->root_node = cloned_root_node; - return MROPE_OK; + rope_out->root_node = cloned_root_node; + return MROPE_OK; } +mreturn_t mrope_delete(mrope_t *rope_inout, const size_t index, + const size_t length) { + mrope_t temp_lhs, temp_rhs; + mreturn_t error = MROPE_OK; -mreturn_t mrope_delete(mrope_t *rope_inout, const size_t index, const size_t length) -{ - mrope_t temp_lhs, temp_rhs; - mreturn_t error = MROPE_OK; - - assert(rope_inout != NULL); - - mrope_init(&temp_lhs); - mrope_init(&temp_rhs); + assert(rope_inout != NULL); - if(mrope_length(rope_inout) < index || mrope_length(rope_inout) < index+length) { - return MROPE_OUT_OF_RANGE; - } + mrope_init(&temp_lhs); + mrope_init(&temp_rhs); - error = mrope_split(rope_inout,index, &temp_lhs, &temp_rhs); - if(error != MROPE_OK) { - return error; - } + if (mrope_length(rope_inout) < index || + mrope_length(rope_inout) < index + length) { + return MROPE_OUT_OF_RANGE; + } - mrope_free(rope_inout); + error = mrope_split(rope_inout, index, &temp_lhs, &temp_rhs); + if (error != MROPE_OK) { + return error; + } - error = mrope_append_rope(rope_inout, &temp_lhs); - if(error != MROPE_OK) { - return error; - } + mrope_free(rope_inout); - error = mrope_split(&temp_rhs, length, &temp_lhs, &temp_rhs); - if(error != MROPE_OK) { - return error; - } + error = mrope_append_rope(rope_inout, &temp_lhs); + if (error != MROPE_OK) { + return error; + } + error = mrope_split(&temp_rhs, length, &temp_lhs, &temp_rhs); + if (error != MROPE_OK) { + return error; + } - error = mrope_append_rope(rope_inout, &temp_rhs); - if(error != MROPE_OK) { - return error; - } + error = mrope_append_rope(rope_inout, &temp_rhs); + if (error != MROPE_OK) { + return error; + } - error = mrope_free(&temp_lhs); - if(error != MROPE_OK) { - return error; - } + error = mrope_free(&temp_lhs); + if (error != MROPE_OK) { + return error; + } - return MROPE_OK; + return MROPE_OK; } diff --git a/src/rope_ops.c b/src/rope_ops.c index 78d896f..f7d19f4 100644 --- a/src/rope_ops.c +++ b/src/rope_ops.c @@ -6,352 +6,332 @@ #include "rope_stack.h" - -void mrope_init_branch_node(struct mrope_branch_node *node, struct mrope_node *lhs, struct mrope_node *rhs) -{ - assert(node != NULL); - - node->node.type = MROPE_NODE_BRANCH; - node->left = lhs; - node->right = rhs; - node->node.weight = 0; - node->node.weight += lhs == NULL? 0: lhs->weight; - node->node.weight += rhs == NULL? 0: rhs->weight; +void mrope_init_branch_node(struct mrope_branch_node *node, + struct mrope_node *lhs, struct mrope_node *rhs) { + assert(node != NULL); + + node->node.type = MROPE_NODE_BRANCH; + node->left = lhs; + node->right = rhs; + node->node.weight = 0; + node->node.weight += lhs == NULL ? 0 : lhs->weight; + node->node.weight += rhs == NULL ? 0 : rhs->weight; } -void mrope_init_leaf_node(struct mrope_leaf_node * node, char * text, const size_t length) -{ - assert(node != NULL); - node->node.type = MROPE_NODE_LEAF; - node->node.weight = length; - node->text = text; +void mrope_init_leaf_node(struct mrope_leaf_node *node, char *text, + const size_t length) { + assert(node != NULL); + node->node.type = MROPE_NODE_LEAF; + node->node.weight = length; + node->text = text; } -struct mrope_branch_node *mrope_make_branch_node(struct mrope_node *lhs, struct mrope_node *rhs) -{ - struct mrope_branch_node * node = NULL; +struct mrope_branch_node *mrope_make_branch_node(struct mrope_node *lhs, + struct mrope_node *rhs) { + struct mrope_branch_node *node = NULL; - if( (node = (struct mrope_branch_node *)malloc(sizeof(struct mrope_branch_node))) == NULL) - { - return NULL; - } + if ((node = (struct mrope_branch_node *)malloc( + sizeof(struct mrope_branch_node))) == NULL) { + return NULL; + } - /* avoid having a null LHS with a non-null RHS */ - if(lhs == NULL) { - mrope_init_branch_node(node, rhs, NULL); - } - else { - mrope_init_branch_node(node, lhs, rhs); - } + /* avoid having a null LHS with a non-null RHS */ + if (lhs == NULL) { + mrope_init_branch_node(node, rhs, NULL); + } else { + mrope_init_branch_node(node, lhs, rhs); + } - return node; + return node; } -struct mrope_leaf_node * mrope_make_leaf_node(void) -{ - struct mrope_leaf_node * node = NULL; +struct mrope_leaf_node *mrope_make_leaf_node(void) { + struct mrope_leaf_node *node = NULL; - if( (node = (struct mrope_leaf_node *)malloc(sizeof(struct mrope_leaf_node))) == NULL) - { - return NULL; - } + if ((node = (struct mrope_leaf_node *)malloc( + sizeof(struct mrope_leaf_node))) == NULL) { + return NULL; + } - mrope_init_leaf_node(node, NULL, 0); + mrope_init_leaf_node(node, NULL, 0); - return node; + return node; } -enum mrope_error_code mrope_free_branch_node(struct mrope_branch_node * branch_node) -{ - if(branch_node == NULL) { - return MROPE_OK; - } +enum mrope_error_code mrope_free_branch_node( + struct mrope_branch_node *branch_node) { + if (branch_node == NULL) { + return MROPE_OK; + } - enum mrope_error_code error = MROPE_OK; + enum mrope_error_code error = MROPE_OK; - if( (error = mrope_free_node(branch_node->left)) != MROPE_OK) { - return error; - } + if ((error = mrope_free_node(branch_node->left)) != MROPE_OK) { + return error; + } - if( (error = mrope_free_node(branch_node->right)) != MROPE_OK) { - return error; - } + if ((error = mrope_free_node(branch_node->right)) != MROPE_OK) { + return error; + } - free(branch_node); + free(branch_node); - return MROPE_OK; + return MROPE_OK; } -enum mrope_error_code mrope_free_leaf_node(struct mrope_leaf_node * leaf_node) -{ - if(leaf_node == NULL) { - return MROPE_OK; - } +enum mrope_error_code mrope_free_leaf_node(struct mrope_leaf_node *leaf_node) { + if (leaf_node == NULL) { + return MROPE_OK; + } - free(leaf_node->text); - leaf_node->text = NULL; - free(leaf_node); + free(leaf_node->text); + leaf_node->text = NULL; + free(leaf_node); - return MROPE_OK; + return MROPE_OK; } +enum mrope_error_code mrope_free_node(struct mrope_node *node) { + if (node == NULL) { + return MROPE_OK; + } -enum mrope_error_code mrope_free_node(struct mrope_node * node) -{ - if(node == NULL) { - return MROPE_OK; - } + switch (node->type) { + case MROPE_NODE_BRANCH: + return mrope_free_branch_node((struct mrope_branch_node *)node); - switch(node->type) - { - case MROPE_NODE_BRANCH: - return mrope_free_branch_node( (struct mrope_branch_node *)node); + case MROPE_NODE_LEAF: + return mrope_free_leaf_node((struct mrope_leaf_node *)node); - case MROPE_NODE_LEAF: - return mrope_free_leaf_node( (struct mrope_leaf_node *)node); - - default: - return MROPE_UNKNOWN_NODE_TYPE; - } + default: + return MROPE_UNKNOWN_NODE_TYPE; + } +} +mreturn_t mrope_clone_branch_node(struct mrope_branch_node *original, + struct mrope_branch_node *clone) { + struct mrope_branch_node *cloned_branch_node = NULL; + mreturn_t error = MROPE_OK; + struct mrope_node *lhs_node = NULL; + struct mrope_node *rhs_node = NULL; + + assert(original != NULL); + assert(clone != NULL); + + if ((error = mrope_clone_node(original->left, &lhs_node)) != MROPE_OK) { + return error; + } + + if ((error = mrope_clone_node(original->right, &rhs_node)) != MROPE_OK) { + mrope_free_node(lhs_node); + return error; + } + + cloned_branch_node = mrope_make_branch_node(lhs_node, rhs_node); + if (cloned_branch_node == NULL) { + mrope_free_node(lhs_node); + mrope_free_node(rhs_node); + return MROPE_MALLOC_FAILED; + } + + clone->node = cloned_branch_node->node; + clone->left = cloned_branch_node->left; + clone->right = cloned_branch_node->right; + + return MROPE_OK; } +mreturn_t mrope_clone_leaf_node(struct mrope_leaf_node *original, + struct mrope_leaf_node *clone) { + struct mrope_leaf_node cloned_leaf_node; + char *cloned_text = NULL; + size_t cloned_text_weight = 0; -mreturn_t mrope_clone_branch_node(struct mrope_branch_node *original, struct mrope_branch_node *clone) -{ - struct mrope_branch_node * cloned_branch_node = NULL; - mreturn_t error = MROPE_OK; - struct mrope_node * lhs_node = NULL; - struct mrope_node * rhs_node = NULL; + assert(original != NULL); + assert(clone != NULL); - assert(original != NULL); - assert(clone != NULL); + cloned_text_weight = original->node.weight; - if( (error = mrope_clone_node(original->left, &lhs_node)) != MROPE_OK) { - return error; - } + if (cloned_text_weight > 0) { + const size_t cloned_string_length = original->node.weight + 1; - if( (error = mrope_clone_node(original->right, &rhs_node)) != MROPE_OK) { - mrope_free_node(lhs_node); - return error; - } + cloned_text = (char *)malloc(cloned_string_length); + strncpy(cloned_text, original->text, cloned_string_length); + cloned_text[cloned_string_length] = '\0'; + } - cloned_branch_node = mrope_make_branch_node(lhs_node, rhs_node); - if(cloned_branch_node == NULL) { - mrope_free_node(lhs_node); - mrope_free_node(rhs_node); - return MROPE_MALLOC_FAILED; - } + mrope_init_leaf_node(&cloned_leaf_node, cloned_text, cloned_text_weight); - clone->node = cloned_branch_node->node; - clone->left = cloned_branch_node->left; - clone->right = cloned_branch_node->right; + clone->node = cloned_leaf_node.node; + clone->text = cloned_leaf_node.text; - return MROPE_OK; + return MROPE_OK; } +mreturn_t mrope_clone_node(struct mrope_node *original, + struct mrope_node **clone) { + assert(original != NULL); + assert(clone != NULL); + + switch (original->type) { + case MROPE_NODE_BRANCH: { + struct mrope_branch_node *node = mrope_make_branch_node(NULL, NULL); + if (node == NULL) { + return MROPE_MALLOC_FAILED; + } + *clone = (struct mrope_node *)node; + return mrope_clone_branch_node((struct mrope_branch_node *)original, + (struct mrope_branch_node *)*clone); + } + + case MROPE_NODE_LEAF: { + struct mrope_leaf_node *node = mrope_make_leaf_node(); + if (node == NULL) { + return MROPE_MALLOC_FAILED; + } + *clone = (struct mrope_node *)node; + return mrope_clone_leaf_node((struct mrope_leaf_node *)original, + (struct mrope_leaf_node *)*clone); + } + + default: + return MROPE_UNKNOWN_NODE_TYPE; + } +} -mreturn_t mrope_clone_leaf_node(struct mrope_leaf_node *original, struct mrope_leaf_node *clone) -{ - struct mrope_leaf_node cloned_leaf_node; - char * cloned_text = NULL; - size_t cloned_text_weight = 0; - - assert(original != NULL); - assert(clone != NULL); - - cloned_text_weight = original->node.weight; - - if(cloned_text_weight > 0) { - const size_t cloned_string_length = original->node.weight+1; - - cloned_text = (char *)malloc(cloned_string_length); - strncpy(cloned_text, original->text, cloned_string_length); - cloned_text[cloned_string_length] = '\0'; - } - - mrope_init_leaf_node(&cloned_leaf_node, cloned_text, cloned_text_weight); - - clone->node = cloned_leaf_node.node; - clone->text = cloned_leaf_node.text; +char mrope_index_node(struct mrope_node *node, const size_t index) { + assert(node != NULL); - return MROPE_OK; -} + switch (node->type) { + case MROPE_NODE_BRANCH: { + return mrope_index_branch_node((struct mrope_branch_node *)node, index); + } -mreturn_t mrope_clone_node(struct mrope_node *original, struct mrope_node **clone) -{ - assert(original != NULL); - assert(clone != NULL); - - switch(original->type) - { - case MROPE_NODE_BRANCH: - { - struct mrope_branch_node *node = mrope_make_branch_node(NULL, NULL); - if(node == NULL) - { - return MROPE_MALLOC_FAILED; - } - *clone = (struct mrope_node *)node; - return mrope_clone_branch_node((struct mrope_branch_node *)original, (struct mrope_branch_node *)*clone); - } - - case MROPE_NODE_LEAF: - { - struct mrope_leaf_node *node = mrope_make_leaf_node(); - if(node == NULL) - { - return MROPE_MALLOC_FAILED; - } - *clone = (struct mrope_node *)node; - return mrope_clone_leaf_node((struct mrope_leaf_node *)original, (struct mrope_leaf_node *)*clone); - } - - default: - return MROPE_UNKNOWN_NODE_TYPE; - } -} + case MROPE_NODE_LEAF: { + return mrope_index_leaf_node((struct mrope_leaf_node *)node, index); + } -char mrope_index_node(struct mrope_node *node, const size_t index) -{ - assert(node != NULL); - - switch(node->type) - { - case MROPE_NODE_BRANCH: - { - return mrope_index_branch_node( (struct mrope_branch_node *)node, index); - } - - case MROPE_NODE_LEAF: - { - return mrope_index_leaf_node( (struct mrope_leaf_node *)node, index); - } - - default: - return '\0'; - } + default: + return '\0'; + } } -char mrope_index_leaf_node(struct mrope_leaf_node *leaf_node, const size_t index) -{ - assert(leaf_node != NULL); - assert(leaf_node->text != NULL); +char mrope_index_leaf_node(struct mrope_leaf_node *leaf_node, + const size_t index) { + assert(leaf_node != NULL); + assert(leaf_node->text != NULL); - if(index >= leaf_node->node.weight) { - return '\0'; - } + if (index >= leaf_node->node.weight) { + return '\0'; + } - return leaf_node->text[index]; + return leaf_node->text[index]; } -char mrope_index_branch_node(struct mrope_branch_node *branch_node, const size_t index) -{ - size_t lhs_weight = 0; +char mrope_index_branch_node(struct mrope_branch_node *branch_node, + const size_t index) { + size_t lhs_weight = 0; - assert(branch_node != NULL); + assert(branch_node != NULL); - if(branch_node->left != NULL) { - lhs_weight = branch_node->left->weight; - if(lhs_weight > index) { - return mrope_index_node( (struct mrope_node *) branch_node->left, index); - } - } + if (branch_node->left != NULL) { + lhs_weight = branch_node->left->weight; + if (lhs_weight > index) { + return mrope_index_node((struct mrope_node *)branch_node->left, index); + } + } - if(branch_node->right == NULL) { - return '\0'; - } + if (branch_node->right == NULL) { + return '\0'; + } - if(index < lhs_weight + branch_node->right->weight) { - return mrope_index_node( (struct mrope_node *) branch_node->right, index - lhs_weight ); - } + if (index < lhs_weight + branch_node->right->weight) { + return mrope_index_node((struct mrope_node *)branch_node->right, + index - lhs_weight); + } - return '\0'; + return '\0'; } +mreturn_t mrope_make_leaf_node_from_text(struct mrope_leaf_node **leaf_node_out, + char *text) { + struct mrope_leaf_node *leaf_node = NULL; + size_t text_weight = 0; -mreturn_t mrope_make_leaf_node_from_text(struct mrope_leaf_node **leaf_node_out, char * text) -{ - struct mrope_leaf_node *leaf_node = NULL; - size_t text_weight = 0; - - assert(leaf_node_out != NULL); + assert(leaf_node_out != NULL); - leaf_node = mrope_make_leaf_node(); - if(leaf_node == NULL) { - return MROPE_MALLOC_FAILED; - } + leaf_node = mrope_make_leaf_node(); + if (leaf_node == NULL) { + return MROPE_MALLOC_FAILED; + } - text_weight = (text == NULL) ? 0 : strlen(text); - mrope_init_leaf_node(leaf_node, text, text_weight); + text_weight = (text == NULL) ? 0 : strlen(text); + mrope_init_leaf_node(leaf_node, text, text_weight); - (*leaf_node_out) = leaf_node; + (*leaf_node_out) = leaf_node; - return MROPE_OK; + return MROPE_OK; } - -mreturn_t mrope_split_leaf_node(struct mrope_leaf_node *original, const size_t index, struct mrope_leaf_node *lhs, struct mrope_leaf_node *rhs) -{ - char * lhs_text = NULL; - size_t lhs_text_length = 0; - char * rhs_text = NULL; - size_t rhs_text_length = 0; - - assert(original != NULL); - assert(lhs != NULL); - assert(rhs != NULL); - - if(index > original->node.weight) { - return MROPE_OUT_OF_RANGE; - } - - if(index == 0) { - rhs_text_length = index; - rhs_text = (char *)malloc(rhs_text_length+1); - strncpy(rhs_text, original->text, rhs_text_length); - rhs_text[rhs_text_length+1] = '\0'; - } - else if (index == original->node.weight) { - lhs_text_length = index; - lhs_text = (char *)malloc(lhs_text_length+1); - strncpy(lhs_text, original->text, lhs_text_length); - lhs_text[lhs_text_length+1] = '\0'; - } - else { - lhs_text_length = index; - lhs_text = (char *)malloc(lhs_text_length+1); - strncpy(lhs_text, original->text, lhs_text_length); - lhs_text[lhs_text_length+1] = '\0'; - - rhs_text_length = original->node.weight - index; - rhs_text = (char *)malloc(rhs_text_length + 1); - strncpy(rhs_text, &original->text[index], rhs_text_length); - rhs_text[rhs_text_length+1] = '\0'; - } - - mrope_init_leaf_node(lhs, lhs_text, lhs_text_length); - mrope_init_leaf_node(rhs, rhs_text, rhs_text_length); - - return MROPE_OK; +mreturn_t mrope_split_leaf_node(struct mrope_leaf_node *original, + const size_t index, struct mrope_leaf_node *lhs, + struct mrope_leaf_node *rhs) { + char *lhs_text = NULL; + size_t lhs_text_length = 0; + char *rhs_text = NULL; + size_t rhs_text_length = 0; + + assert(original != NULL); + assert(lhs != NULL); + assert(rhs != NULL); + + if (index > original->node.weight) { + return MROPE_OUT_OF_RANGE; + } + + if (index == 0) { + rhs_text_length = index; + rhs_text = (char *)malloc(rhs_text_length + 1); + strncpy(rhs_text, original->text, rhs_text_length); + rhs_text[rhs_text_length + 1] = '\0'; + } else if (index == original->node.weight) { + lhs_text_length = index; + lhs_text = (char *)malloc(lhs_text_length + 1); + strncpy(lhs_text, original->text, lhs_text_length); + lhs_text[lhs_text_length + 1] = '\0'; + } else { + lhs_text_length = index; + lhs_text = (char *)malloc(lhs_text_length + 1); + strncpy(lhs_text, original->text, lhs_text_length); + lhs_text[lhs_text_length + 1] = '\0'; + + rhs_text_length = original->node.weight - index; + rhs_text = (char *)malloc(rhs_text_length + 1); + strncpy(rhs_text, &original->text[index], rhs_text_length); + rhs_text[rhs_text_length + 1] = '\0'; + } + + mrope_init_leaf_node(lhs, lhs_text, lhs_text_length); + mrope_init_leaf_node(rhs, rhs_text, rhs_text_length); + + return MROPE_OK; } +size_t mrope_calculate_weights(struct mrope_node *node) { + if (node == NULL) { + return 0; + } -size_t mrope_calculate_weights(struct mrope_node *node) -{ - if(node == NULL) { - return 0; - } - - if(node->type == MROPE_NODE_LEAF) { - return node->weight; - } + if (node->type == MROPE_NODE_LEAF) { + return node->weight; + } - if(node->type == MROPE_NODE_BRANCH) { - struct mrope_branch_node* branch_node = (struct mrope_branch_node*)node; - return mrope_calculate_weights(branch_node->left) + mrope_calculate_weights(branch_node->right); - } + if (node->type == MROPE_NODE_BRANCH) { + struct mrope_branch_node *branch_node = (struct mrope_branch_node *)node; + return mrope_calculate_weights(branch_node->left) + + mrope_calculate_weights(branch_node->right); + } - /*FIXIT if this part was reached then we've stumbled on a bad node */ - return 0; + /*FIXIT if this part was reached then we've stumbled on a bad node */ + return 0; } diff --git a/src/rope_ops.h b/src/rope_ops.h index fee24fa..f26af4e 100644 --- a/src/rope_ops.h +++ b/src/rope_ops.h @@ -3,27 +3,38 @@ #include -void mrope_init_branch_node(struct mrope_branch_node *node, struct mrope_node *lhs, struct mrope_node *rhs); -void mrope_init_leaf_node(struct mrope_leaf_node * node, char * text, const size_t length); - -struct mrope_branch_node * mrope_make_branch_node(struct mrope_node *lhs, struct mrope_node *rhs); -struct mrope_leaf_node * mrope_make_leaf_node(void); - -enum mrope_error_code mrope_free_branch_node(struct mrope_branch_node * node); -enum mrope_error_code mrope_free_leaf_node(struct mrope_leaf_node * node); -enum mrope_error_code mrope_free_node(struct mrope_node * node); - -mreturn_t mrope_split_leaf_node(struct mrope_leaf_node * original, const size_t index, struct mrope_leaf_node *lhs, struct mrope_leaf_node *rhs); - -mreturn_t mrope_clone_branch_node(struct mrope_branch_node *original, struct mrope_branch_node *clone); -mreturn_t mrope_clone_leaf_node(struct mrope_leaf_node *original, struct mrope_leaf_node *clone); -mreturn_t mrope_clone_node(struct mrope_node *original, struct mrope_node **clone); - -char mrope_index_branch_node(struct mrope_branch_node *branch_node, const size_t index); -char mrope_index_leaf_node(struct mrope_leaf_node *leaf_node, const size_t index); +void mrope_init_branch_node(struct mrope_branch_node *node, + struct mrope_node *lhs, struct mrope_node *rhs); +void mrope_init_leaf_node(struct mrope_leaf_node *node, char *text, + const size_t length); + +struct mrope_branch_node *mrope_make_branch_node(struct mrope_node *lhs, + struct mrope_node *rhs); +struct mrope_leaf_node *mrope_make_leaf_node(void); + +enum mrope_error_code mrope_free_branch_node(struct mrope_branch_node *node); +enum mrope_error_code mrope_free_leaf_node(struct mrope_leaf_node *node); +enum mrope_error_code mrope_free_node(struct mrope_node *node); + +mreturn_t mrope_split_leaf_node(struct mrope_leaf_node *original, + const size_t index, struct mrope_leaf_node *lhs, + struct mrope_leaf_node *rhs); + +mreturn_t mrope_clone_branch_node(struct mrope_branch_node *original, + struct mrope_branch_node *clone); +mreturn_t mrope_clone_leaf_node(struct mrope_leaf_node *original, + struct mrope_leaf_node *clone); +mreturn_t mrope_clone_node(struct mrope_node *original, + struct mrope_node **clone); + +char mrope_index_branch_node(struct mrope_branch_node *branch_node, + const size_t index); +char mrope_index_leaf_node(struct mrope_leaf_node *leaf_node, + const size_t index); char mrope_index_node(struct mrope_node *node, const size_t index); -mreturn_t mrope_make_leaf_node_from_text(struct mrope_leaf_node **leaf_node_out, char *text); +mreturn_t mrope_make_leaf_node_from_text(struct mrope_leaf_node **leaf_node_out, + char *text); size_t mrope_calculate_weights(struct mrope_node *node); diff --git a/src/rope_stack.c b/src/rope_stack.c index f5fb857..95bbacc 100644 --- a/src/rope_stack.c +++ b/src/rope_stack.c @@ -4,82 +4,76 @@ #include #include -mreturn_t mrope_stack_init(mrope_stack_t *stack) -{ - assert(stack != NULL); +mreturn_t mrope_stack_init(mrope_stack_t *stack) { + assert(stack != NULL); - stack->pos = 0; - stack->size = 8; - stack->data = NULL; - stack->data = malloc(stack->size); + stack->pos = 0; + stack->size = 8; + stack->data = NULL; + stack->data = malloc(stack->size); - if(stack->data == NULL) { - stack->size = 0; - return MROPE_MALLOC_FAILED; - } + if (stack->data == NULL) { + stack->size = 0; + return MROPE_MALLOC_FAILED; + } - return MROPE_OK; + return MROPE_OK; } -void mrope_stack_free(mrope_stack_t *stack) -{ - assert(stack != NULL); +void mrope_stack_free(mrope_stack_t *stack) { + assert(stack != NULL); - if(stack->data != NULL) { - free(stack->data); - stack->data = NULL; - } - stack->pos = 0; - stack->size = 0; + if (stack->data != NULL) { + free(stack->data); + stack->data = NULL; + } + stack->pos = 0; + stack->size = 0; } -mreturn_t mrope_stack_push(mrope_stack_t *stack, struct mrope_node *node) -{ - assert(stack != NULL); +mreturn_t mrope_stack_push(mrope_stack_t *stack, struct mrope_node *node) { + assert(stack != NULL); - if(stack->pos == stack->size) { - enum mrope_error_code error = mrope_stack_grow_stack(stack); - if(error != MROPE_OK) { - return error; - } - } + if (stack->pos == stack->size) { + enum mrope_error_code error = mrope_stack_grow_stack(stack); + if (error != MROPE_OK) { + return error; + } + } - stack->data[stack->pos++] = node; + stack->data[stack->pos++] = node; - return MROPE_OK; + return MROPE_OK; } -mreturn_t mrope_stack_grow_stack(mrope_stack_t *stack) -{ - assert(stack != NULL); +mreturn_t mrope_stack_grow_stack(mrope_stack_t *stack) { + assert(stack != NULL); - const size_t new_size = stack->size << 1; + const size_t new_size = stack->size << 1; - struct mrope_node ** new_data = realloc(stack->data, new_size); - if(new_data == NULL) { - return MROPE_MALLOC_FAILED; - } + struct mrope_node **new_data = realloc(stack->data, new_size); + if (new_data == NULL) { + return MROPE_MALLOC_FAILED; + } - stack->data = new_data; - stack->size = new_size; + stack->data = new_data; + stack->size = new_size; - return MROPE_OK; + return MROPE_OK; } -struct mrope_node * mrope_stack_top(mrope_stack_t *stack) -{ - assert(stack != NULL); +struct mrope_node *mrope_stack_top(mrope_stack_t *stack) { + assert(stack != NULL); - return (stack->pos == 0) ? NULL : stack->data[stack->pos-1]; + return (stack->pos == 0) ? NULL : stack->data[stack->pos - 1]; } -mreturn_t mrope_stack_pop(mrope_stack_t *stack, struct mrope_node **node) -{ - assert(stack != NULL); +mreturn_t mrope_stack_pop(mrope_stack_t *stack, struct mrope_node **node) { + assert(stack != NULL); - *node = mrope_stack_top(stack); + *node = mrope_stack_top(stack); - if(stack->pos > 0) stack->pos--; + if (stack->pos > 0) stack->pos--; - return MROPE_OK; + return MROPE_OK; } diff --git a/src/rope_stack.h b/src/rope_stack.h index ced0dfc..c9a3824 100644 --- a/src/rope_stack.h +++ b/src/rope_stack.h @@ -3,11 +3,10 @@ #include -struct mrope_stack -{ - struct mrope_node **data; - size_t size; - size_t pos; +struct mrope_stack { + struct mrope_node **data; + size_t size; + size_t pos; }; typedef struct mrope_stack mrope_stack_t; @@ -15,9 +14,9 @@ typedef struct mrope_stack mrope_stack_t; mreturn_t mrope_stack_init(mrope_stack_t *stack); void mrope_stack_free(mrope_stack_t *stack); -struct mrope_node * mrope_stack_top(mrope_stack_t *stack); +struct mrope_node *mrope_stack_top(mrope_stack_t *stack); mreturn_t mrope_stack_grow_stack(mrope_stack_t *stack); -mreturn_t mrope_stack_push(mrope_stack_t *stack, struct mrope_node * node); +mreturn_t mrope_stack_push(mrope_stack_t *stack, struct mrope_node *node); mreturn_t mrope_stack_pop(mrope_stack_t *stack, struct mrope_node **node); #endif From dcba5a48964e3e6a1e4e62d4dd6a77adc6e46768 Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 11:39:23 +0200 Subject: [PATCH 06/11] Migrate project to C99 --- CMakeLists.txt | 2 +- Changelog.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6701b50..7caa2c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ target_include_directories(${PROJECT_NAME} set_target_properties(${PROJECT_NAME} PROPERTIES - C_STANDARD 90 + C_STANDARD 99 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF SOVERSION 1 diff --git a/Changelog.md b/Changelog.md index b183c97..0555282 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed +- Convert project to C99 - Adopt .clang-format spec ## [1.0.0] 2023-06-05 From 176d85fdafdb47b4c9841ce0448e9fdfa217c4ab Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Fri, 1 Sep 2023 16:07:14 +0200 Subject: [PATCH 07/11] Adopt a .editorconfig spec --- .editorconfig | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1639887 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,59 @@ +[*] +cpp_indent_braces=false +cpp_indent_multi_line_relative_to=innermost_parenthesis +cpp_indent_within_parentheses=indent +cpp_indent_preserve_within_parentheses=false +cpp_indent_case_labels=false +cpp_indent_case_contents=true +cpp_indent_case_contents_when_block=false +cpp_indent_lambda_braces_when_parameter=true +cpp_indent_goto_labels=one_left +cpp_indent_preprocessor=leftmost_column +cpp_indent_access_specifiers=false +cpp_indent_namespace_contents=true +cpp_indent_preserve_comments=false +cpp_new_line_before_open_brace_namespace=ignore +cpp_new_line_before_open_brace_type=ignore +cpp_new_line_before_open_brace_function=ignore +cpp_new_line_before_open_brace_block=ignore +cpp_new_line_before_open_brace_lambda=ignore +cpp_new_line_scope_braces_on_separate_lines=false +cpp_new_line_close_brace_same_line_empty_type=false +cpp_new_line_close_brace_same_line_empty_function=false +cpp_new_line_before_catch=true +cpp_new_line_before_else=true +cpp_new_line_before_while_in_do_while=false +cpp_space_before_function_open_parenthesis=remove +cpp_space_within_parameter_list_parentheses=false +cpp_space_between_empty_parameter_list_parentheses=false +cpp_space_after_keywords_in_control_flow_statements=true +cpp_space_within_control_flow_statement_parentheses=false +cpp_space_before_lambda_open_parenthesis=false +cpp_space_within_cast_parentheses=false +cpp_space_after_cast_close_parenthesis=false +cpp_space_within_expression_parentheses=false +cpp_space_before_block_open_brace=true +cpp_space_between_empty_braces=false +cpp_space_before_initializer_list_open_brace=false +cpp_space_within_initializer_list_braces=true +cpp_space_preserve_in_initializer_list=true +cpp_space_before_open_square_bracket=false +cpp_space_within_square_brackets=false +cpp_space_before_empty_square_brackets=false +cpp_space_between_empty_square_brackets=false +cpp_space_group_square_brackets=true +cpp_space_within_lambda_brackets=false +cpp_space_between_empty_lambda_brackets=false +cpp_space_before_comma=false +cpp_space_after_comma=true +cpp_space_remove_around_member_operators=true +cpp_space_before_inheritance_colon=true +cpp_space_before_constructor_colon=true +cpp_space_remove_before_semicolon=true +cpp_space_after_semicolon=false +cpp_space_remove_around_unary_operator=true +cpp_space_around_binary_operator=insert +cpp_space_around_assignment_operator=insert +cpp_space_pointer_reference_alignment=left +cpp_space_around_ternary_operator=insert +cpp_wrap_preserve_blocks=one_liners From a71f4561860b6fa9241af2083da50668702032c2 Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Sun, 12 Nov 2023 18:24:02 +0000 Subject: [PATCH 08/11] Offboard project from Travis CICD --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6f3a844..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -dist: xenial - -language: c - -compiler: gcc - -addons: - apt: - packages: - - gcc-5 - - cmake - - check - - libsubunit-dev - -script: -- mkdir -p build -- cd build -- cmake -DENABLE_TESTS=ON .. -- make -- make test From 05900a856dfcb7edadbb55d4d45b700af13cda7a Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Sun, 12 Nov 2023 18:26:08 +0000 Subject: [PATCH 09/11] CMake: updates minimum required version to 3.22 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7caa2c7..531638f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.22 FATAL_ERROR) project(mropes VERSION 1.0.0.1 From 318b7c2c08645a5e4e4b162f06751dbb89714333 Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Sun, 12 Nov 2023 18:33:05 +0000 Subject: [PATCH 10/11] GitHub Actions: build project by invoking cmake --- .github/workflows/ccpp.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 7313575..5a2eb58 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -10,15 +10,11 @@ jobs: steps: - uses: actions/checkout@v1 - name: install dependencies - run: sudo apt-get install check - - name: create build directory - run: mkdir build - - name: configure - run: cmake .. -DENABLE_TESTS=OFF - working-directory: ./build - - name: make - run: make - working-directory: ./build + run: sudo apt-get install -y cmake check + - name: configure cmake + run: cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_TESTS=OFF -B./build -G "Unix Makefiles" + - name: build with cmake + run: cmake --build ./build --config Debug --target all - name: Generate packages with CPack run: make package working-directory: ./build From c1288f3bc7f26e60fdd7dfa6d18e64c8ae51c62b Mon Sep 17 00:00:00 2001 From: Rui Maciel Date: Sun, 12 Nov 2023 18:49:57 +0000 Subject: [PATCH 11/11] Bump version number to v1.0.1.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 531638f..e580303 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR) project(mropes - VERSION 1.0.0.1 + VERSION 1.0.1.0 LANGUAGES C )