/* 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)