diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-08-09 22:45:07 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-08-09 22:45:07 +0530 |
commit | 48faa8e018673876b2a8489310853e0ef8628428 (patch) | |
tree | d7bbb8b2833d9390a1f5a1606c5a43ab6c90a1e8 | |
parent | e27a70f4dbc835c7dcdb840e70999fafaf2be28a (diff) |
engine: eachdo: sort atoms by priority
-rw-r--r-- | src/engine/eachdo.c | 12 |
1 files changed, 12 insertions, 0 deletions
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 @@ -29,6 +29,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 * each PUT in the directives. @@ -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); |