From 48faa8e018673876b2a8489310853e0ef8628428 Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sat, 9 Aug 2025 22:45:07 +0530 Subject: engine: eachdo: sort atoms by priority --- src/engine/eachdo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/engine/eachdo.c b/src/engine/eachdo.c index 776e19c..463ae08 100644 --- a/src/engine/eachdo.c +++ b/src/engine/eachdo.c @@ -28,6 +28,15 @@ extern msg_t *msg; +/* + * Compares two atoms based on priority. Used for qsort() + */ +static int +comp(const void *a, const void *b) +{ + return ((atom_t *) b)->priority - ((atom_t *) a)->priority; +} + /* * A generic function that accepts keys, corresponding values and the * directives. It appends to the buffer the corresponding value of the key for @@ -174,6 +183,9 @@ handle_eachdo(char **buffer, key_match_t *match, directive_t *directive) return; } + /* Sort atoms by priority */ + qsort(atoms->elements, atoms->size, sizeof(atom_t), comp); + for (size_t i = 0; i < atoms->size; i++) { atom_t *atom = list_get(atoms, i); content = realloc(content, strlen(content) + strlen(atom->content) + 1); -- cgit v1.2.3