commit c18a85f1cc169e8acf05d83bf0d0c94be339ece8 Author: lisk77 Date: Sat Aug 16 00:45:53 2025 +0200 feat: initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1e253b9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.16) +project(merk LANGUAGES C CXX) + +# Standards +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(BUILD_SHARED_LIBS "Build shared libraries by default" OFF) + +# Collect all source files under src/ (recursively). +# CONFIGURE_DEPENDS makes CMake re-scan when files are added/removed. +file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS + "${CMAKE_SOURCE_DIR}/src/*.c" + "${CMAKE_SOURCE_DIR}/src/*.cc" + "${CMAKE_SOURCE_DIR}/src/*.cpp" + "${CMAKE_SOURCE_DIR}/src/*.cxx") + +# Decide: executable (if src/main.* exists) or library (otherwise). +set(MAIN_CANDIDATES + "${CMAKE_SOURCE_DIR}/src/main.c" + "${CMAKE_SOURCE_DIR}/src/main.cc" + "${CMAKE_SOURCE_DIR}/src/main.cpp" + "${CMAKE_SOURCE_DIR}/src/main.cxx") +set(HAVE_MAIN FALSE) +foreach(f IN LISTS MAIN_CANDIDATES) + if(EXISTS "${f}") + set(HAVE_MAIN TRUE) + endif() +endforeach() + +if(HAVE_MAIN) + add_executable(merk ${PROJECT_SOURCES}) + set(TARGET_NAME merk) +else() + add_library(${PROJECT_NAME} ${PROJECT_SOURCES}) + set(TARGET_NAME ${PROJECT_NAME}) +endif() + +# Public headers live in ./include +target_include_directories(${TARGET_NAME} + PUBLIC "${CMAKE_SOURCE_DIR}/include" +) + +# Sensible warnings +if(MSVC) + target_compile_options(${TARGET_NAME} PRIVATE /W4 /permissive-) +else() + target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -Wpedantic) +endif() + +# Put built artifacts under build/bin and build/lib +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + diff --git a/include/action_list.h b/include/action_list.h new file mode 100644 index 0000000..6149021 --- /dev/null +++ b/include/action_list.h @@ -0,0 +1,20 @@ +#ifndef ACTION_LIST_H +#define ACTION_LIST_H + +#include +#include +#include +#include +#include "myers.h" + +typedef struct { + Action* actions; + uint64_t capacity; + uint64_t len; +} ActionList; + +ActionList* new_list(); +void add_action(ActionList*, Action); +void append_list(ActionList*, ActionList*); + +#endif // ACTION_LIST_H diff --git a/include/myers.h b/include/myers.h new file mode 100644 index 0000000..1ce74b7 --- /dev/null +++ b/include/myers.h @@ -0,0 +1,19 @@ +#ifndef MYERS_H +#define MYERS_H + +#include + +typedef enum { + INSERT, + DELETE +} ActionType; + +typedef struct { + ActionType type; + uint64_t line_original; + uint64_t line_changed; +} Action; + + + +#endif // MYERS_H diff --git a/src/action_list.c b/src/action_list.c new file mode 100644 index 0000000..ab4b80b --- /dev/null +++ b/src/action_list.c @@ -0,0 +1,37 @@ +#include "action_list.h" + +ActionList* new_list() { + ActionList* list = calloc(1, sizeof(ActionList)); + list->capacity = 10; + list->actions = calloc(list->capacity, sizeof(Action)); + list->len = 0; + return list; +} + +void add_action(ActionList* list, Action action) { + if (list->len >= list->capacity) { + list->capacity *= 2; + list->actions = realloc(list->actions, list->capacity*sizeof(Action)); + if (list->actions == NULL) { + perror("Actions list reallocation failed!"); + exit(EXIT_FAILURE); + } + } + + list->actions[list->len++] = action; +} + +void append_list(ActionList* list1, ActionList* list2) { + uint64_t available_space = list1->capacity - list1->len; + if (available_space < list2->len) { + list1->capacity += list2->capacity; + list1->actions = realloc(list1->actions, list1->capacity*sizeof(Action)); + if (list1->actions == NULL) { + perror("Actions list reallaction failed!"); + exit(EXIT_FAILURE); + } + } + + memcpy(list1->actions + list1->len, list2->actions, list2->len * sizeof *list2->actions); + list1->len += list2->len; +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..65dd3b2 --- /dev/null +++ b/src/main.c @@ -0,0 +1,17 @@ +#include "myers.h" +#include "action_list.h" + +int main() { + Action act1 = (Action){.type=INSERT, .line_original=0, .line_changed=1}; + Action act2 = (Action){.type=DELETE, .line_original=1, .line_changed=2}; + + ActionList* list1 = new_list(); + add_action(list1, act1); + + ActionList* list2 = new_list(); + add_action(list2, act2); + + append_list(list1, list2); + + return 0; +} diff --git a/src/myers.c b/src/myers.c new file mode 100644 index 0000000..37e8fa2 --- /dev/null +++ b/src/myers.c @@ -0,0 +1,3 @@ +#include "myers.h" + +