feat: initial commit

This commit is contained in:
lisk77 2025-08-16 00:45:53 +02:00
commit c18a85f1cc
7 changed files with 153 additions and 0 deletions

37
src/action_list.c Normal file
View file

@ -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;
}

17
src/main.c Normal file
View file

@ -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;
}

3
src/myers.c Normal file
View file

@ -0,0 +1,3 @@
#include "myers.h"