summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hexdiff.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/hexdiff.c b/hexdiff.c
index d2a8bbb..81f0513 100644
--- a/hexdiff.c
+++ b/hexdiff.c
@@ -33,9 +33,11 @@ static const int diff_gradient[256] = {
[224 ... 255] = 196,
};
-static bool use_color = true;
static bool has_color = false;
-static bool show_all = false;
+
+static bool use_color = true;
+static bool show_all = true;
+static bool only_diff = false;
static inline void
color_byte(struct file *cur, struct file *other, size_t i)
@@ -64,12 +66,12 @@ main(int argc, const char **argv)
memset(&f2, 0, sizeof(f2));
for (arg = &argv[1]; *arg; arg++) {
- if (!strcmp(*arg, "-c")) {
- use_color = true;
- } else if (!strcmp(*arg, "-C")) {
- use_color = false;
- } else if (!strcmp(*arg, "-a")) {
- show_all = true;
+ if (!strcmp(*arg, "-c") || !strcmp(*arg, "-C")) {
+ use_color = (arg[0][1] == 'c');
+ } else if (!strcmp(*arg, "-d") || !strcmp(*arg, "-D")) {
+ only_diff = (arg[0][1] == 'd');
+ } else if (!strcmp(*arg, "-a") || !strcmp(*arg, "-A")) {
+ show_all = (arg[0][1] == 'a');
} else if (!f1.fname) {
f1.fname = *arg;
} else if (!f2.fname) {
@@ -80,7 +82,7 @@ main(int argc, const char **argv)
}
if (!f1.fname || !f2.fname || *arg) {
- fprintf(stderr, "Usage: hexdiff [-c] FILE FILE\n");
+ fprintf(stderr, "Usage: hexdiff [-cC] [-aA] [-bB] FILE FILE\n");
return 1;
}
@@ -91,10 +93,11 @@ main(int argc, const char **argv)
if (!f2.file) err(1, "fopen %s", f2.fname);
pos = 0;
- while (!feof(f1.file) && !feof(f2.file)) {
+ while (show_all ? !feof(f1.file) || !feof(f2.file)
+ : !feof(f1.file) && !feof(f2.file)) {
f1.buflen = fread(f1.buf, 1, 16, f1.file);
f2.buflen = fread(f2.buf, 1, 16, f2.file);
- if (!show_all && f1.buflen == f2.buflen
+ if (only_diff && f1.buflen == f2.buflen
&& !memcmp(f1.buf, f2.buf, f1.buflen))
continue;
if (!f1.buflen && !f2.buflen) break;