refactor: split up the utilities file into smaller modules

This commit is contained in:
lisk77 2025-09-19 03:48:08 +02:00
parent abaa6e12fc
commit ff71a92249
13 changed files with 572 additions and 488 deletions

View file

@ -50,4 +50,29 @@ void free_action_list(ActionList* list) {
free(list->actions); // Free the array of actions
free(list); // Free the ActionList itself
}
}
int compare_actions(const void* a, const void* b) {
const Action* action1 = (const Action*)a;
const Action* action2 = (const Action*)b;
if (action1->type != action2->type) {
return (action1->type == DELETE) ? -1 : 1;
}
if (action1->type == DELETE) {
if (action1->line_original < action2->line_original) return 1;
if (action1->line_original > action2->line_original) return -1;
return 0;
} else {
if (action1->line_changed < action2->line_changed) return -1;
if (action1->line_changed > action2->line_changed) return 1;
return 0;
}
}
void sort_action_list(ActionList* actions) {
if (!actions || actions->len <= 1) return;
qsort(actions->actions, actions->len, sizeof(Action), compare_actions);
}