aboutsummaryrefslogtreecommitdiffstats
path: root/libpatch_next_hunk.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
committerMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
commitae850b1ac755f471beac4dbfef4654fe3fbaaae9 (patch)
tree319e7f7f1b99cd1ee75e100f0a29b0f7c827ccea /libpatch_next_hunk.c
downloadlibpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.gz
libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.bz2
libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.xz
First commitHEADmaster
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libpatch_next_hunk.c')
-rw-r--r--libpatch_next_hunk.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libpatch_next_hunk.c b/libpatch_next_hunk.c
new file mode 100644
index 0000000..4fcb8f4
--- /dev/null
+++ b/libpatch_next_hunk.c
@@ -0,0 +1,31 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+size_t
+libpatch_next_hunk(struct libpatch_diff2 *diff, size_t difflen, size_t *position,
+ size_t *ai, size_t *bi, size_t *an_out, size_t *bn_out, int skip_context)
+{
+ size_t n;
+ int mask = skip_context ? 0x03 : ~0;
+
+ while (*position < difflen && !(diff[*position].change & mask)) {
+ *ai += (size_t)diff[*position].repetition;
+ *bi += (size_t)diff[*position].repetition;
+ *position += 1;
+ }
+
+ *an_out = 0;
+ *bn_out = 0;
+ n = 0;
+
+ while (n < difflen - *position && (diff[*position + n].change & mask)) {
+ if (diff[*position + n].change != LIBPATCH_DIFF2_FILE2_ONLY)
+ *an_out += (size_t)diff[*position + n].repetition;
+ if (diff[*position + n].change != LIBPATCH_DIFF2_FILE1_ONLY)
+ *bn_out += (size_t)diff[*position + n].repetition;
+ n += 1;
+ }
+
+ return n;
+}