aboutsummaryrefslogblamecommitdiffstats
path: root/libpatch_plain_diff2_printer__.c
blob: f345e8677190c40102ea7f8eb926dcf24dc967e3 (plain) (tree)
















































































                                                                                                       
/* See LICENSE file for copyright and license details. */
#include "common.h"


#define PUT(THIS, TEXT, LEN)\
	(((struct printer_internals *)(THIS)->user_data)->put((THIS), (TEXT), (LEN)))


static void
put_text(struct libpatch_diff2_printer *printer, const char *text)
{
	PUT(printer, text, strlen(text));
}

static void
put_text_zu_discard_i(struct libpatch_diff2_printer *printer, const char *text1, size_t text2, int a)
{
	char buf[3 * sizeof(text2) + 1];
	(void) a;
	PUT(printer, text1, strlen(text1));
	PUT(printer, buf, (size_t)sprintf(buf, "%zu", text2));
}

static void
put_text_discard_i(struct libpatch_diff2_printer *printer, const char *text, int a)
{
	(void) a;
	PUT(printer, text, strlen(text));
}

static void
put_text_discard_ii(struct libpatch_diff2_printer *printer, const char *text, int a, int b)
{
	(void) a;
	(void) b;
	PUT(printer, text, strlen(text));
}

static void
put_text_discard_iizu(struct libpatch_diff2_printer *printer, const char *text, int a, int b, size_t c)
{
	(void) a;
	(void) b;
	(void) c;
	PUT(printer, text, strlen(text));
}

static void
put_newline(struct libpatch_diff2_printer *printer)
{
	PUT(printer, "\n", 1);
}

static void
put_line(struct libpatch_diff2_printer *printer, struct libpatch_line *line)
{
	PUT(printer, line->text, line->len);
}


void
libpatch_plain_diff2_printer__(struct libpatch_diff2_printer *printer)
{
	printer->put_end_of_change = &put_text;
	printer->put_syntactical_escape = &put_text;
	printer->put_syntactical_garbage = &put_text;
	printer->put_hunk_head_prefix = &put_text_discard_i;
	printer->put_hunk_head_suffix = &put_text_discard_i;
	printer->put_hunk_start = &put_text_zu_discard_i;
	printer->put_hunk_end = &put_text_zu_discard_i;
	printer->put_hunk_length = &put_text_zu_discard_i;
	printer->put_hunk_operation = &put_text_discard_ii;
	printer->put_label_prefix = &put_text_discard_i;
	printer->put_label = &put_text_discard_i;
	printer->put_context_prefix = &put_text_discard_iizu;
	printer->put_change_prefix = &put_text_discard_iizu;
	printer->put_line = &put_line;
	printer->put_whitespace = &put_text;
	printer->put_newline = &put_newline;
	printer->put_no_newline = &put_text;
}