aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compat.h29
-rw-r--r--src/da.h2
-rw-r--r--src/grab.c17
3 files changed, 9 insertions, 39 deletions
diff --git a/src/compat.h b/src/compat.h
deleted file mode 100644
index 87ab9fb..0000000
--- a/src/compat.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* This compatibility header was generated by the libcompat gen script.
- You can find it over at https://git.sr.ht/~mango/libcompat. */
-
-#ifndef LIBCOMPAT_COMPAT_H
-#define LIBCOMPAT_COMPAT_H
-
-#if __STDC_VERSION__ >= 202311L
-# define LIBCOMPAT_IS_23 1
-#endif
-
-#if !LIBCOMPAT_IS_23
-# include <stdbool.h> /* IWYU pragma: export */
-#endif
-
-#if !LIBCOMPAT_IS_23
-# ifndef NULL
-# include <stddef.h> /* IWYU pragma: export */
-# endif
-# define nullptr NULL
-#endif
-
-#if !LIBCOMPAT_IS_23
-# ifdef static_assert
-# undef static_assert
-# endif
-# define static_assert(e, ...) _Static_assert(e, ""__VA_ARGS__)
-#endif
-
-#endif /* !LIBCOMPAT_COMPAT_H */
diff --git a/src/da.h b/src/da.h
index 57b7ed1..8891971 100644
--- a/src/da.h
+++ b/src/da.h
@@ -116,6 +116,6 @@
} while (0)
#define da_foreach(a, p) \
- for (auto p = (a)->buf; (size_t)(p - (a)->buf) < (a)->len; p++)
+ for (typeof((a)->buf) p = (a)->buf; (size_t)(p - (a)->buf) < (a)->len; p++)
#endif /* !MANGO_DA_H */
diff --git a/src/grab.c b/src/grab.c
index 39eba58..f262451 100644
--- a/src/grab.c
+++ b/src/grab.c
@@ -27,7 +27,6 @@
#include <rune.h>
#include <utf8.h>
-#include "compat.h"
#include "da.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -254,9 +253,9 @@ main(int argc, char **argv)
# if GIT_GRAB
free(entry);
# endif
- for (size_t i = 0; i < ops.len; i++) {
- if (ops.buf[i].alloced)
- regfree(&ops.buf[i].pat);
+ da_foreach (&ops, op) {
+ if (op->alloced)
+ regfree(&op->pat);
}
free(ops.buf);
#endif
@@ -302,7 +301,7 @@ comppat(char8_t *s)
delimiter if this is the last operation in the query pattern. */
p = s;
len = strlen(s);
- if (!(s = (char8_t *)u8chr(s, ch, len)))
+ if (!(s = u8chr(s, ch, len)))
s = p + len;
if (s - p == 0) {
@@ -727,10 +726,10 @@ putm(struct sv sv, struct matches *ms, const char *filename)
}
p = sv.p;
- for (size_t i = 0; i < valid.len; i++) {
- struct sv m = valid.buf[i];
- printf("%.*s\33[%sm%.*s\33[0m", (int)(m.p - p), p, hl, (int)m.len, m.p);
- p = m.p + m.len;
+ da_foreach (&valid, m) {
+ printf("%.*s\33[%sm%.*s\33[0m", (int)(m->p - p), p, hl, (int)m->len,
+ m->p);
+ p = m->p + m->len;
}
fwrite(p, 1, sv.p + sv.len - p, stdout);