#include "common.hpp" using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { std::cerr << "Too few arguments." << std::endl; return -1; } std::string A(argv[1]); std::string B(argv[2]); bool fileExist = true; if (!isFileExist(A)) { std::cerr << "file A does not exist" << std::endl; fileExist = false; } if (!isFileExist(B)) { std::cerr << "file B does not exist" << std::endl; fileExist = false; } if (!fileExist) { return -1; } typedef std::string elem; typedef std::vector sequence; std::ifstream Aifs(A.c_str()); std::ifstream Bifs(B.c_str()); elem buf; sequence ALines, BLines; std::ostringstream ossLine, ossInfo; while (getline(Aifs, buf)) { ALines.push_back(buf); } while (getline(Bifs, buf)) { BLines.push_back(buf); } Diff d(ALines, BLines); d.compose(); sequence s1 = ALines; sequence s2 = d.patch(s1); // fpatch assert(BLines == s2); std::cout << "fpatch succeeded" << std::endl; d.composeUnifiedHunks(); sequence s3 = d.uniPatch(s1); // unipatch assert(BLines == s3); std::cout << "unipatch succeeded" << std::endl; return 0; }