]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common/array.h: add wl_array_for_each_reverse macro
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 21 Nov 2023 02:07:10 +0000 (03:07 +0100)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 21 Nov 2023 21:31:05 +0000 (22:31 +0100)
include/common/array.h
scripts/checkpatch.pl

index 4f6e6237debecafe31fea9e690b061b429f739f0..f6c51fc91481fac5803794878c405fef5df59bc5 100644 (file)
@@ -30,4 +30,15 @@ wl_array_len(struct wl_array *array)
        return array->size / sizeof(const char *);
 }
 
+/**
+ * Iterates in reverse over an array.
+ * @pos: pointer that each array element will be assigned to
+ * @array: wl_array to iterate over
+ */
+#define wl_array_for_each_reverse(pos, array)                                          \
+       for (pos = !(array)->data ? NULL                                               \
+               : (void *)((const char *)(array)->data + (array)->size - sizeof(pos)); \
+               pos && (const char *)pos >= (const char *)(array)->data;               \
+               (pos)--)
+
 #endif /* LABWC_ARRAY_H */
index 53d6d268b44babaec66a43220adcedc61ed74485..14fdb88e9eff367e371e40158c60df691dc4f4db 100755 (executable)
@@ -5531,6 +5531,7 @@ sub process {
                        #
                        if ($starts_with_if_while_etc && !length($s)
                                        && $filename ne "include/view.h"
+                                       && $filename ne "include/common/array.h"
                                        && $filename ne "include/ssd-internal.h") {
                                CHK("BRACES", "[labwc-custom] open brace { expected after if/while/for/switch - even with single statement blocks");
                        }