From b775c0e501df5e7c0a340bfb67a2f4a8646ea0de Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Thu, 31 Dec 2020 11:07:16 -0800 Subject: [PATCH] add crude tool for enormous line-by-line diffs --- dumpdiffs.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dumpdiffs.cpp diff --git a/dumpdiffs.cpp b/dumpdiffs.cpp new file mode 100644 index 0000000..8f68c0d --- /dev/null +++ b/dumpdiffs.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ + FILE *dump1 = fopen(argv[1], "r"); + FILE *dump2 = fopen(argv[2], "r"); + + int fieldSize = std::max(strlen(argv[1]), strlen(argv[2])); + + char line1[512]; + char line2[512]; + + time_t then = time(0); + int linecount = 0; + size_t bytecount = 0; + + unsigned int clockhigh = 0; + unsigned int clocklow = 0; + + while(fgets(line1, sizeof(line1) - 1, dump1)) { + bytecount += strlen(line1); + line1[strlen(line1) - 1] = '\0'; + + if(strncmp(line1, "clock", 5) == 0) { + if(sscanf(line1, "clock = %u, %u", &clockhigh, &clocklow) != 2) { + printf("Failed to read clock values\n"); + exit(1); + } + } + + fgets(line2, sizeof(line2) - 1, dump2); + line2[strlen(line2) - 1] = '\0'; + + if(strcmp(line1, line2) != 0) { + printf("line %d differed; clock %u, %u\n", linecount, clockhigh, clocklow); + printf(" %*s : %s\n", fieldSize, argv[1], line1); + printf(" %*s : %s\n", fieldSize, argv[2], line2); + exit(1); + } + + time_t now = time(0); + if(now > then) { + then = now; + printf("byte %zd, clock %u, %u\n", bytecount, clockhigh, clocklow); + } + + linecount++; + } +}