From ae850b1ac755f471beac4dbfef4654fe3fbaaae9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 9 Jan 2024 22:04:24 +0100 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 common.h (limited to 'common.h') diff --git a/common.h b/common.h new file mode 100644 index 0000000..21e9ad8 --- /dev/null +++ b/common.h @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "libpatch.h" + +#include +#include +#include +#include +#include +#include +#include + +#define MIN(A, B) ((A) < (B) ? (A) : (B)) +#define MAX(A, B) ((A) > (B) ? (A) : (B)) + +#define IS_LINE(T) ((T) >= LIBPATCH_PATCH_CONTEXT && (T) <= LIBPATCH_PATCH_POSTCHANGE) + + +struct printer_internals { + void (*put)(struct libpatch_diff2_printer *this, const char *text, size_t len); + union { + FILE *stream; + int fd; + } f; +}; + + +void libpatch_plain_diff2_printer__(struct libpatch_diff2_printer *printer); +struct libpatch_diff2_printer *libpatch_stream_diff2_printer__(FILE *output); +struct libpatch_diff2_printer *libpatch_fd_diff2_printer__(int output); + +size_t libpatch_next_line__(const char **text, size_t *textlen, size_t lastlen); + +int libpatch_reverse_hunks__(struct libpatch_patch *patch, size_t patchlen, + const size_t *hunks, size_t nhunks, + struct libpatch_patch **patchcopy, size_t *patchcopysize); + +size_t libpatch_get_zu__(const char *text, size_t len, size_t *out); + +int libpatch_append_to_patch__(struct libpatch_patch **patch, size_t *patchlen, size_t *size, + size_t stroff, size_t strlen, int type); + +#define APPEND_STRING(OFF, TYPE)\ + do {\ + if (libpatch_append_to_patch__(patch, patchlen, &size,\ + (size_t)(&text[OFF] - patchtext),\ + len - (size_t)(OFF), (TYPE)))\ + goto fail;\ + } while (0) + +#define APPEND_OPTSTRING(OFF, TYPE)\ + APPEND_STRING((OFF) + ((OFF) < len && text[OFF] == ' '), (TYPE)) + +#define APPEND_NO_TEXT(TYPE)\ + APPEND_STRING(len, TYPE) -- cgit v1.2.3-70-g09d2