aboutsummaryrefslogblamecommitdiffstats
path: root/libpatch_next_hunk.c
blob: 4fcb8f4edd2f2881fcd83e0da9482c3cab08c7de (plain) (tree)






























                                                                                            
/* 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;
}