seccomp.c: use print_array function

* seccomp.c (decode_filter, decode_seccomp_fprog): Remove.
(print_bpf_filter): New function.
(print_seccomp_fprog): Use it via print_array.
* tests/seccomp-filter-v.c (main): Update.
diff --git a/seccomp.c b/seccomp.c
index e62f99a..5d972f9 100644
--- a/seccomp.c
+++ b/seccomp.c
@@ -108,6 +108,8 @@
 
 }
 
+#endif /* HAVE_LINUX_FILTER_H */
+
 static void
 decode_bpf_stmt(const struct bpf_filter *filter)
 {
@@ -146,54 +148,44 @@
 #endif /* HAVE_LINUX_FILTER_H */
 }
 
-static void
-decode_filter(const struct bpf_filter *filter)
-{
-	if (filter->jt || filter->jf)
-		decode_bpf_jump(filter);
-	else
-		decode_bpf_stmt(filter);
-}
-
-#endif /* HAVE_LINUX_FILTER_H */
-
 #ifndef BPF_MAXINSNS
 # define BPF_MAXINSNS 4096
 #endif
 
-static void
-decode_seccomp_fprog(struct tcb *tcp, unsigned short len, unsigned long addr)
+static bool
+print_bpf_filter(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 {
-	struct bpf_filter filter;
-	const unsigned long start_addr = addr;
-	unsigned int i = 0;
+	const struct bpf_filter *filter = elem_buf;
+	unsigned int *pn = data;
 
-	for (; addr >= start_addr && i < len; ++i, addr += sizeof(filter)) {
-		if (i) {
-			tprints(", ");
-			if (i >= BPF_MAXINSNS) {
-				tprints("...");
-				break;
-			}
-		}
-		if (umove_or_printaddr(tcp, addr, &filter))
-			break;
-		if (!i)
-			tprints("[");
-		decode_filter(&filter);
+	if ((*pn)++ >= BPF_MAXINSNS) {
+		tprints("...");
+		return false;
 	}
-	if (i)
-		tprints("]");
+
+	if (filter->jt || filter->jf)
+		decode_bpf_jump(filter);
+	else
+		decode_bpf_stmt(filter);
+
+	return true;
 }
 
 static void
-print_seccomp_fprog(struct tcb *tcp, unsigned short len, unsigned long addr)
+print_seccomp_fprog(struct tcb *tcp, unsigned long addr, unsigned short len)
 {
 	tprintf("{len=%u, filter=", len);
-	if (abbrev(tcp) || !len)
+
+	if (abbrev(tcp)) {
 		printaddr(addr);
-	else
-		decode_seccomp_fprog(tcp, len, addr);
+	} else {
+		unsigned int insns = 0;
+		struct bpf_filter filter;
+
+		print_array(tcp, addr, len, &filter, sizeof(filter),
+			    umoven_or_printaddr, print_bpf_filter, &insns);
+	}
+
 	tprints("}");
 }
 
@@ -205,7 +197,7 @@
 	struct seccomp_fprog fprog;
 
 	if (fetch_seccomp_fprog(tcp, addr, &fprog))
-		print_seccomp_fprog(tcp, fprog.len, fprog.filter);
+		print_seccomp_fprog(tcp, fprog.filter, fprog.len);
 }
 
 static void