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 /libpatch_format_rcs_patch.c | |
download | libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.gz libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.bz2 libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.xz |
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libpatch_format_rcs_patch.c')
-rw-r--r-- | libpatch_format_rcs_patch.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libpatch_format_rcs_patch.c b/libpatch_format_rcs_patch.c new file mode 100644 index 0000000..9d09923 --- /dev/null +++ b/libpatch_format_rcs_patch.c @@ -0,0 +1,48 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libpatch_format_rcs_patch(struct libpatch_diff2_printer *printer, struct libpatch_diff2 *diff, size_t difflen, + const struct libpatch_file *file1, const struct libpatch_file *file2) +{ + size_t i, j, n, ai, bi, an, bn; + + ai = 0; + bi = 0; + for (i = 0; (n = libpatch_next_hunk(diff, difflen, &i, &ai, &bi, &an, &bn, 1));) { + if (an) { + printer->put_hunk_head_prefix(printer, "", 0); + printer->put_hunk_operation(printer, "d", 0, 1); + printer->put_hunk_start(printer, " ", ai + 1, 1); + printer->put_hunk_length(printer, " ", an, 1); + printer->put_hunk_head_suffix(printer, "", 0); + printer->put_newline(printer); + } + if (bn) { + printer->put_hunk_head_prefix(printer, "", 0); + printer->put_hunk_operation(printer, "a", 0, 1); + printer->put_hunk_start(printer, " ", ai + an, 1); + printer->put_hunk_length(printer, " ", bn, 2); + printer->put_hunk_head_suffix(printer, "", 0); + printer->put_newline(printer); + } + + ai += an; + if (bn) { + for (n += i; i < n; i++) { + for (j = 0; j < diff[i].repetition; j++) { + if (diff[i].change != LIBPATCH_DIFF2_FILE1_ONLY) { + printer->put_change_prefix(printer, "", 2, 0, bi); + printer->put_line(printer, file2->lines[bi++]); + if (bi < file2->nlines || file2->lf_terminated) + printer->put_newline(printer); + } + } + } + } + } + + (void) file1; + return 0; +} |