master xplshn/aruu / shared / diffutil.h
 1/* See LICENSE file for copyright and license details. */
 2#ifndef ARUU_DIFFUTIL_H
 3#define ARUU_DIFFUTIL_H
 4
 5#include <stdio.h>
 6#include <sys/types.h>
 7
 8struct diffline {
 9  char  *data;
10  size_t len;
11};
12
13struct difffile {
14  struct diffline *lines;
15  size_t           nlines;
16};
17
18struct diffrange {
19  size_t from;
20  size_t to;
21};
22
23struct diffhunk {
24  struct diffrange old;
25  struct diffrange new;
26};
27
28struct diffhunks {
29  struct diffhunk *v;
30  size_t           n;
31};
32
33enum diffformat {
34  DIFF_NORMAL,
35  DIFF_UNIFIED,
36  DIFF_CONTEXT,
37  DIFF_ED,
38  DIFF_RCSED,
39  DIFF_BRIEF,
40};
41
42struct diffopts {
43  enum diffformat format;
44  size_t          context;
45  int             ignore_case;
46  int             ignore_blanks;
47  int             strip_cr;
48  int             treat_binary;
49};
50
51#define DIFF_SAME   0
52#define DIFF_DIFFER 1
53#define DIFF_ERROR  2
54
55int  diff_load(struct difffile *df, const char *path);
56void diff_free(struct difffile *df);
57int  diff_compute(
58    struct diffhunks      *hunks,
59    const struct difffile *old,
60    const struct difffile *new,
61    const struct diffopts *opts
62);
63void diff_hunks_free(struct diffhunks *hunks);
64int  diff_format(
65    FILE                   *out,
66    const struct diffhunks *hunks,
67    const struct difffile  *old,
68    const struct difffile *new,
69    const char            *oldlabel,
70    const char            *newlabel,
71    const struct diffopts *opts
72);
73int diff_looks_binary(const struct difffile *df);
74
75#endif