#include "common.hpp" using dtl::Diff; typedef unsigned char elem; typedef std::vector sequence; static int create_byte_seq(const char *fs, sequence &seq); static int create_byte_seq(const char *fs, sequence &seq) { int fd; int siz; elem buf[BUFSIZ]; if ((fd = open(fs, O_RDONLY)) == -1) { std::cout << "Opening failed." << std::endl; return -1; } while ((siz = read(fd, buf, sizeof(buf))) > 0) { for (int i = 0; i < siz; ++i) { seq.push_back(buf[i]); } } if (siz < 0) { close(fd); std::cout << "Read error." << std::endl; return -1; } close(fd); return 0; } int main(int argc, char *argv[]) { if (isFewArgs(argc)) { std::cerr << "Too few arguments." << std::endl; return -1; } std::string fs1(argv[1]); std::string fs2(argv[2]); sequence seq1; sequence seq2; create_byte_seq(fs1.c_str(), seq1); create_byte_seq(fs2.c_str(), seq2); Diff d(seq1, seq2); d.compose(); if (d.getEditDistance() == 0) { std::cout << fs1 << " is the same as " << fs2 << std::endl; } else { std::cout << fs1 << " is different from " << fs2 << std::endl; } return 0; }