summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdiff-lua.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/bdiff-lua.c b/bdiff-lua.c
new file mode 100644
index 0000000..5b5fbe9
--- /dev/null
+++ b/bdiff-lua.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char ** argv) {
+ FILE * in1, * in2, * out;
+ size_t s1, s2, p, b, c;
+ int b1, b2;
+
+ if (argc != 4) { printf("Usage: %s fin1 fin2 fout\n", argv[0]); exit(-1); }
+
+ if ((in1 = fopen(argv[1], "rb")) == 0) { printf("Error opening %s\n", argv[1]); perror("fopen"); exit(-1); }
+ if ((in2 = fopen(argv[2], "rb")) == 0) { printf("Error opening %s\n", argv[2]); perror("fopen"); exit(-1); }
+ if ((out = fopen(argv[3], "wb")) == 0) { printf("Error opening %s\n", argv[3]); perror("fopen"); exit(-1); }
+
+ fseek(in1, 0, SEEK_END); s1 = ftell(in1); fseek(in1, 0, SEEK_SET);
+ fseek(in2, 0, SEEK_END); s2 = ftell(in2); fseek(in2, 0, SEEK_SET);
+
+ if (s1 != s2) { printf("Error: files are of different sizes.\n"); exit(-1); }
+
+ b = s1 - 1;
+
+ fprintf(out, "patch = {\n");
+
+ for (p = 0; p < s1; p++) {
+ b1 = fgetc(in1);
+ b2 = fgetc(in2);
+
+ if (b1 != b2) {
+ b++;
+ if ((b != p) && (b != s1)) fprintf(out, " },\n");
+ if (b != p) { fprintf(out, " [0x%06x] = { ", p); c = 0; } else { fprintf(out, ", "); c++; }
+ if (c == 16) { fprintf(out, "\n "); c = 0; }
+ fprintf(out, "0x%02x", b2);
+ b = p;
+ }
+ }
+
+ fprintf(out, " },\n}\n");
+
+ fclose(in1); fclose(in2); fclose(out);
+}