diff options
author | Mattias Andrée <maandree@kth.se> | 2024-01-09 22:04:24 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-01-09 22:04:24 +0100 |
commit | ae850b1ac755f471beac4dbfef4654fe3fbaaae9 (patch) | |
tree | 319e7f7f1b99cd1ee75e100f0a29b0f7c827ccea /common.h | |
download | libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.gz libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.bz2 libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'common.h')
-rw-r--r-- | common.h | 54 |
1 files changed, 54 insertions, 0 deletions
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 <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +#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) |