Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/diff/diffreg.c
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | struct context_vec { | ||||
int b; /* end line in old file */ | int b; /* end line in old file */ | ||||
int c; /* start line in new file */ | int c; /* start line in new file */ | ||||
int d; /* end line in new file */ | int d; /* end line in new file */ | ||||
}; | }; | ||||
enum readhash { RH_BINARY, RH_OK, RH_EOF }; | enum readhash { RH_BINARY, RH_OK, RH_EOF }; | ||||
#define MIN_PAD 1 | #define MIN_PAD 1 | ||||
static int diffreg_stone(char *, char *, int, int); | |||||
static FILE *opentemp(const char *); | static FILE *opentemp(const char *); | ||||
static void output(char *, FILE *, char *, FILE *, int); | static void output(char *, FILE *, char *, FILE *, int); | ||||
static void check(FILE *, FILE *, int); | static void check(FILE *, FILE *, int); | ||||
static void range(int, int, const char *); | static void range(int, int, const char *); | ||||
static void uni_range(int, int); | static void uni_range(int, int); | ||||
static void dump_context_vec(FILE *, FILE *, int); | static void dump_context_vec(FILE *, FILE *, int); | ||||
static void dump_unified_vec(FILE *, FILE *, int); | static void dump_unified_vec(FILE *, FILE *, int); | ||||
static bool prepare(int, FILE *, size_t, int); | static bool prepare(int, FILE *, size_t, int); | ||||
Show All 40 Lines | |||||
static struct context_vec *context_vec_end; | static struct context_vec *context_vec_end; | ||||
static struct context_vec *context_vec_ptr; | static struct context_vec *context_vec_ptr; | ||||
#define FUNCTION_CONTEXT_SIZE 55 | #define FUNCTION_CONTEXT_SIZE 55 | ||||
static char lastbuf[FUNCTION_CONTEXT_SIZE]; | static char lastbuf[FUNCTION_CONTEXT_SIZE]; | ||||
static int lastline; | static int lastline; | ||||
static int lastmatchline; | static int lastmatchline; | ||||
int | |||||
diffreg(char *file1, char *file2, int flags, int capsicum) | |||||
{ | |||||
/* First check if have picked the stone algorithm. */ | |||||
if (diff_algorithm == D_DIFFSTONE) | |||||
return diffreg_stone(file1, file2, flags, capsicum); | |||||
/* | |||||
* We can't use fifos with libdiff yet. DO NOT fallback to stone if we | |||||
* selected the algorithm explicitly. | |||||
*/ | |||||
if (S_ISFIFO(stb1.st_mode) || S_ISFIFO(stb2.st_mode)) { | |||||
if (algorithm_set) | |||||
err(2, "unable to use selected algorithm with requested options"); | |||||
else | |||||
return diffreg_stone(file1, file2, flags, capsicum); | |||||
} | |||||
/* Is this one of the supported input/output modes for diffreg_new? */ | |||||
if ((flags == 0 || !(flags & ~D_NEWALGO_FLAGS)) && ( | |||||
diff_format == D_NORMAL || | |||||
#if 0 | |||||
emaste: What's this? | |||||
diff_format == D_EDIT || | |||||
#endif | |||||
diff_format == D_UNIFIED) && | |||||
(diff_algorithm == D_DIFFMYERS || diff_algorithm == D_DIFFPATIENCE)) { | |||||
return diffreg_new(file1, file2, flags, capsicum); | |||||
} | |||||
/* | |||||
* If the algorithm was set explicitly and we can't support it DO NOT | |||||
* fallback to stone. | |||||
*/ | |||||
if (algorithm_set) | |||||
err(2, "unable to use selected algorithm with requested options"); | |||||
/* Fallback to using stone. */ | |||||
return diffreg_stone(file1, file2, flags, capsicum); | |||||
} | |||||
static int | static int | ||||
clow2low(int c) | clow2low(int c) | ||||
{ | { | ||||
return (c); | return (c); | ||||
} | } | ||||
static int | static int | ||||
cup2low(int c) | cup2low(int c) | ||||
{ | { | ||||
return (tolower(c)); | return (tolower(c)); | ||||
} | } | ||||
int | int | ||||
diffreg(char *file1, char *file2, int flags, int capsicum) | diffreg_stone(char *file1, char *file2, int flags, int capsicum) | ||||
{ | { | ||||
FILE *f1, *f2; | FILE *f1, *f2; | ||||
int i, rval; | int i, rval; | ||||
struct pr *pr = NULL; | struct pr *pr = NULL; | ||||
cap_rights_t rights_ro; | cap_rights_t rights_ro; | ||||
f1 = f2 = NULL; | f1 = f2 = NULL; | ||||
rval = D_SAME; | rval = D_SAME; | ||||
▲ Show 20 Lines • Show All 1,427 Lines • Show Last 20 Lines |
What's this?