formatting and fixes
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif // HAVE_UNISTD_H
|
||||
@@ -17,57 +17,55 @@ using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
typedef unsigned char elem;
|
||||
typedef vector< elem > sequence;
|
||||
typedef unsigned char elem;
|
||||
typedef vector<elem> 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) {
|
||||
cout << "Opening failed." << 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);
|
||||
cout << "Read error." << endl;
|
||||
return -1;
|
||||
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) {
|
||||
cout << "Opening failed." << 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);
|
||||
return 0;
|
||||
cout << "Read error." << endl;
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string fs1(argv[1]);
|
||||
string fs2(argv[2]);
|
||||
sequence seq1;
|
||||
sequence seq2;
|
||||
|
||||
create_byte_seq(fs1.c_str(), seq1);
|
||||
create_byte_seq(fs2.c_str(), seq2);
|
||||
|
||||
Diff< elem, sequence > d(seq1, seq2);
|
||||
d.compose();
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (d.getEditDistance() == 0) {
|
||||
cout << fs1 << " is the same as " << fs2 << endl;
|
||||
} else {
|
||||
cout << fs1 << " is different from " << fs2 << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string fs1(argv[1]);
|
||||
string fs2(argv[2]);
|
||||
sequence seq1;
|
||||
sequence seq2;
|
||||
|
||||
create_byte_seq(fs1.c_str(), seq1);
|
||||
create_byte_seq(fs2.c_str(), seq2);
|
||||
|
||||
Diff<elem, sequence> d(seq1, seq2);
|
||||
d.compose();
|
||||
|
||||
if (d.getEditDistance() == 0) {
|
||||
cout << fs1 << " is the same as " << fs2 << endl;
|
||||
} else {
|
||||
cout << fs1 << " is different from " << fs2 << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,20 +1,19 @@
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
bool isFileExist (string& fs) {
|
||||
FILE *fp;
|
||||
if ((fp = fopen(fs.c_str(), "r")) == NULL) {
|
||||
return false;
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
bool isFileExist(string &fs) {
|
||||
FILE *fp;
|
||||
if ((fp = fopen(fs.c_str(), "r")) == NULL) {
|
||||
return false;
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isFewArgs (int argc, int limit) {
|
||||
bool ret = false;
|
||||
if (argc < limit) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
bool isFewArgs(int argc, int limit) {
|
||||
bool ret = false;
|
||||
if (argc < limit) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -2,12 +2,12 @@
|
||||
#ifndef DTL_EXAMPLE_COMMON_H
|
||||
#define DTL_EXAMPLE_COMMON_H
|
||||
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isFileExist (string& fs);
|
||||
bool isFewArgs (int argc, int limit = 3);
|
||||
bool isFileExist(string &fs);
|
||||
bool isFewArgs(int argc, int limit = 3);
|
||||
|
||||
#endif
|
||||
|
@@ -1,73 +1,73 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <cassert>
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string A(argv[1]);
|
||||
string B(argv[2]);
|
||||
bool fileExist = true;
|
||||
|
||||
if (!isFileExist(A)) {
|
||||
cerr << "file A does not exist" << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!isFileExist(B)) {
|
||||
cerr << "file B does not exist" << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!fileExist) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef string elem;
|
||||
typedef vector< elem > sequence;
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
ifstream Aifs(A.c_str());
|
||||
ifstream Bifs(B.c_str());
|
||||
elem buf;
|
||||
sequence ALines, BLines;
|
||||
ostringstream ossLine, ossInfo;
|
||||
|
||||
while(getline(Aifs, buf)){
|
||||
ALines.push_back(buf);
|
||||
}
|
||||
while(getline(Bifs, buf)){
|
||||
BLines.push_back(buf);
|
||||
}
|
||||
|
||||
Diff< elem > d(ALines, BLines);
|
||||
d.compose();
|
||||
|
||||
sequence s1 = ALines;
|
||||
sequence s2 = d.patch(s1);
|
||||
|
||||
// fpatch
|
||||
assert(BLines == s2);
|
||||
cout << "fpatch succeeded" << endl;
|
||||
|
||||
d.composeUnifiedHunks();
|
||||
sequence s3 = d.uniPatch(s1);
|
||||
|
||||
// unipatch
|
||||
assert(BLines == s3);
|
||||
cout << "unipatch succeeded" << endl;
|
||||
|
||||
return 0;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string A(argv[1]);
|
||||
string B(argv[2]);
|
||||
bool fileExist = true;
|
||||
|
||||
if (!isFileExist(A)) {
|
||||
cerr << "file A does not exist" << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!isFileExist(B)) {
|
||||
cerr << "file B does not exist" << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!fileExist) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef string elem;
|
||||
typedef vector<elem> sequence;
|
||||
|
||||
ifstream Aifs(A.c_str());
|
||||
ifstream Bifs(B.c_str());
|
||||
elem buf;
|
||||
sequence ALines, BLines;
|
||||
ostringstream ossLine, ossInfo;
|
||||
|
||||
while (getline(Aifs, buf)) {
|
||||
ALines.push_back(buf);
|
||||
}
|
||||
while (getline(Bifs, buf)) {
|
||||
BLines.push_back(buf);
|
||||
}
|
||||
|
||||
Diff<elem> d(ALines, BLines);
|
||||
d.compose();
|
||||
|
||||
sequence s1 = ALines;
|
||||
sequence s2 = d.patch(s1);
|
||||
|
||||
// fpatch
|
||||
assert(BLines == s2);
|
||||
cout << "fpatch succeeded" << endl;
|
||||
|
||||
d.composeUnifiedHunks();
|
||||
sequence s3 = d.uniPatch(s1);
|
||||
|
||||
// unipatch
|
||||
assert(BLines == s3);
|
||||
cout << "unipatch succeeded" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,49 +1,49 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <dtl/dtl.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int, char**){
|
||||
|
||||
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
int b[] = {3, 5, 1, 4, 5, 1, 7, 9, 6, 10};
|
||||
int asiz = sizeof(a) / sizeof(int);
|
||||
int bsiz = sizeof(b) / sizeof(int);
|
||||
for (int i=0;i<asiz;++i) {
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
for (int i=0;i<bsiz;++i) {
|
||||
cout << b[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
typedef int elem;
|
||||
typedef vector< int > sequence;
|
||||
int main(int, char **) {
|
||||
|
||||
sequence A(&a[0], &a[asiz]);
|
||||
sequence B(&b[0], &b[bsiz]);
|
||||
Diff< elem > d(A, B);
|
||||
d.compose();
|
||||
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
int b[] = {3, 5, 1, 4, 5, 1, 7, 9, 6, 10};
|
||||
int asiz = sizeof(a) / sizeof(int);
|
||||
int bsiz = sizeof(b) / sizeof(int);
|
||||
for (int i = 0; i < asiz; ++i) {
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
for (int i = 0; i < bsiz; ++i) {
|
||||
cout << b[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
// editDistance
|
||||
cout << "editDistance:" << d.getEditDistance() << endl;
|
||||
typedef int elem;
|
||||
typedef vector<int> sequence;
|
||||
|
||||
// Longest Common Subsequence
|
||||
sequence lcs_v = d.getLcsVec();
|
||||
cout << "LCS: ";
|
||||
for (sequence::iterator vit=lcs_v.begin();vit!=lcs_v.end();++vit) {
|
||||
cout << *vit << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
d.printSES();
|
||||
|
||||
return 0;
|
||||
sequence A(&a[0], &a[asiz]);
|
||||
sequence B(&b[0], &b[bsiz]);
|
||||
Diff<elem> d(A, B);
|
||||
d.compose();
|
||||
|
||||
// editDistance
|
||||
cout << "editDistance:" << d.getEditDistance() << endl;
|
||||
|
||||
// Longest Common Subsequence
|
||||
sequence lcs_v = d.getLcsVec();
|
||||
cout << "LCS: ";
|
||||
for (sequence::iterator vit = lcs_v.begin(); vit != lcs_v.end(); ++vit) {
|
||||
cout << *vit << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
d.printSES();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,57 +1,57 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using dtl::Diff3;
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
int a[10] = {1, 2, 3, 4, 5, 6, 7, 3, 9, 10};
|
||||
int b[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
int c[10] = {1, 2, 3, 9, 5, 6, 7, 8, 9, 10};
|
||||
int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10};
|
||||
|
||||
cout << "a:";
|
||||
for (int i=0;i<10;++i) {
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "b:";
|
||||
for (int i=0;i<10;++i) {
|
||||
cout << b[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "c:";
|
||||
for (int i=0;i<10;++i) {
|
||||
cout << c[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
typedef int elem;
|
||||
typedef vector< int > sequence;
|
||||
sequence A(&a[0], &a[10]);
|
||||
sequence B(&b[0], &b[10]);
|
||||
sequence C(&c[0], &c[10]);
|
||||
sequence Answer(&answer[0], &answer[10]);
|
||||
Diff3< elem > diff3(A, B, C);
|
||||
diff3.compose();
|
||||
if (!diff3.merge()) {
|
||||
cerr << "conflict." << endl;
|
||||
return -1;
|
||||
}
|
||||
sequence s = diff3.getMergedSequence();
|
||||
cout << "s:";
|
||||
for (sequence::iterator it=s.begin();it!=s.end();++it) {
|
||||
cout << *it << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
assert(s == Answer);
|
||||
cout << "intdiff3 OK" << endl;
|
||||
|
||||
return 0;
|
||||
int main(int, char **) {
|
||||
|
||||
int a[10] = {1, 2, 3, 4, 5, 6, 7, 3, 9, 10};
|
||||
int b[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
int c[10] = {1, 2, 3, 9, 5, 6, 7, 8, 9, 10};
|
||||
int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10};
|
||||
|
||||
cout << "a:";
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "b:";
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
cout << b[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "c:";
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
cout << c[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
typedef int elem;
|
||||
typedef vector<int> sequence;
|
||||
sequence A(&a[0], &a[10]);
|
||||
sequence B(&b[0], &b[10]);
|
||||
sequence C(&c[0], &c[10]);
|
||||
sequence Answer(&answer[0], &answer[10]);
|
||||
Diff3<elem> diff3(A, B, C);
|
||||
diff3.compose();
|
||||
if (!diff3.merge()) {
|
||||
cerr << "conflict." << endl;
|
||||
return -1;
|
||||
}
|
||||
sequence s = diff3.getMergedSequence();
|
||||
cout << "s:";
|
||||
for (sequence::iterator it = s.begin(); it != s.end(); ++it) {
|
||||
cout << *it << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
assert(s == Answer);
|
||||
cout << "intdiff3 OK" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,44 +1,44 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <cassert>
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff< elem, sequence > d(A, B);
|
||||
d.compose();
|
||||
|
||||
sequence s1(A);
|
||||
sequence s2 = d.patch(s1);
|
||||
d.composeUnifiedHunks();
|
||||
sequence s3 = d.uniPatch(s1);
|
||||
|
||||
cout << "before:" << s1 << endl;
|
||||
cout << "after :" << s2 << endl;
|
||||
assert(B == s2);
|
||||
cout << "patch succeeded" << endl;
|
||||
|
||||
cout << "before:" << s1 << endl;
|
||||
cout << "after :" << s3 << endl;
|
||||
assert(B == s3);
|
||||
cout << "unipatch succeeded" << endl;
|
||||
|
||||
return 0;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff<elem, sequence> d(A, B);
|
||||
d.compose();
|
||||
|
||||
sequence s1(A);
|
||||
sequence s2 = d.patch(s1);
|
||||
d.composeUnifiedHunks();
|
||||
sequence s3 = d.uniPatch(s1);
|
||||
|
||||
cout << "before:" << s1 << endl;
|
||||
cout << "after :" << s2 << endl;
|
||||
assert(B == s2);
|
||||
cout << "patch succeeded" << endl;
|
||||
|
||||
cout << "before:" << s1 << endl;
|
||||
cout << "after :" << s3 << endl;
|
||||
assert(B == s3);
|
||||
cout << "unipatch succeeded" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -3,26 +3,25 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
|
||||
template <typename sesElem, typename stream = ostream >
|
||||
class customChangePrinter : public dtl::Printer < sesElem, stream >
|
||||
{
|
||||
public :
|
||||
customChangePrinter () : dtl::Printer < sesElem, stream > () {}
|
||||
customChangePrinter (stream& out) : dtl::Printer < sesElem, stream > (out) {}
|
||||
~customChangePrinter () {}
|
||||
void operator() (const sesElem& se) const {
|
||||
switch (se.second.type) {
|
||||
case dtl::SES_ADD:
|
||||
this->out_ << "Add: " << se.first << std::endl;
|
||||
break;
|
||||
case dtl::SES_DELETE:
|
||||
this->out_ << "Delete: " << se.first << std::endl;
|
||||
break;
|
||||
case dtl::SES_COMMON:
|
||||
this->out_ << "Common: " << se.first << std::endl;
|
||||
break;
|
||||
}
|
||||
template <typename sesElem, typename stream = ostream>
|
||||
class customChangePrinter : public dtl::Printer<sesElem, stream> {
|
||||
public:
|
||||
customChangePrinter() : dtl::Printer<sesElem, stream>() {}
|
||||
customChangePrinter(stream &out) : dtl::Printer<sesElem, stream>(out) {}
|
||||
~customChangePrinter() {}
|
||||
void operator()(const sesElem &se) const {
|
||||
switch (se.second.type) {
|
||||
case dtl::SES_ADD:
|
||||
this->out_ << "Add: " << se.first << std::endl;
|
||||
break;
|
||||
case dtl::SES_DELETE:
|
||||
this->out_ << "Delete: " << se.first << std::endl;
|
||||
break;
|
||||
case dtl::SES_COMMON:
|
||||
this->out_ << "Common: " << se.first << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DTL_PRINTERS
|
||||
|
@@ -1,35 +1,36 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <iostream>
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace dtl;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc, 2)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
typedef string elem;
|
||||
typedef vector< string > sequence;
|
||||
if (isFewArgs(argc, 2)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string s(argv[1]);
|
||||
typedef string elem;
|
||||
typedef vector<string> sequence;
|
||||
|
||||
if (!isFileExist(s)) {
|
||||
cerr << s << " is invalid." << endl;
|
||||
return -1;
|
||||
}
|
||||
string s(argv[1]);
|
||||
|
||||
ifstream fs(s.c_str());
|
||||
const Ses< elem > ses = Diff< elem, sequence >::composeSesFromStream< ifstream >(fs);
|
||||
dtl::Diff< elem, sequence >::printSES(ses);
|
||||
|
||||
return 0;
|
||||
if (!isFileExist(s)) {
|
||||
cerr << s << " is invalid." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifstream fs(s.c_str());
|
||||
const Ses<elem> ses =
|
||||
Diff<elem, sequence>::composeSesFromStream<ifstream>(fs);
|
||||
dtl::Diff<elem, sequence>::printSES(ses);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -3,25 +3,24 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
|
||||
template <typename sesElem, typename storedData >
|
||||
class CustomStorage : public dtl::Storage < sesElem, storedData >
|
||||
{
|
||||
public :
|
||||
CustomStorage(storedData& sd) : dtl::Storage < sesElem, storedData > (sd) {}
|
||||
~CustomStorage() {}
|
||||
void operator() (const sesElem& se) const {
|
||||
switch (se.second.type) {
|
||||
case dtl::SES_ADD:
|
||||
this->storedData_ = this->storedData_ + "Add: " + se.first + "\n";
|
||||
break;
|
||||
case dtl::SES_DELETE:
|
||||
this->storedData_ = this->storedData_ + "Delete: " + se.first + "\n";
|
||||
break;
|
||||
case dtl::SES_COMMON:
|
||||
this->storedData_ = this->storedData_ + "Common: " + se.first + "\n";
|
||||
break;
|
||||
}
|
||||
template <typename sesElem, typename storedData>
|
||||
class CustomStorage : public dtl::Storage<sesElem, storedData> {
|
||||
public:
|
||||
CustomStorage(storedData &sd) : dtl::Storage<sesElem, storedData>(sd) {}
|
||||
~CustomStorage() {}
|
||||
void operator()(const sesElem &se) const {
|
||||
switch (se.second.type) {
|
||||
case dtl::SES_ADD:
|
||||
this->storedData_ = this->storedData_ + "Add: " + se.first + "\n";
|
||||
break;
|
||||
case dtl::SES_DELETE:
|
||||
this->storedData_ = this->storedData_ + "Delete: " + se.first + "\n";
|
||||
break;
|
||||
case dtl::SES_COMMON:
|
||||
this->storedData_ = this->storedData_ + "Common: " + se.first + "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DTL_STORAGE
|
||||
|
@@ -1,42 +1,42 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff< elem, sequence > d(A, B);
|
||||
//d.onOnlyEditDistance();
|
||||
d.compose();
|
||||
|
||||
// editDistance
|
||||
cout << "editDistance:" << d.getEditDistance() << endl;
|
||||
|
||||
// Longest Common Subsequence
|
||||
vector< elem > lcs_v = d.getLcsVec();
|
||||
sequence lcs_s(lcs_v.begin(), lcs_v.end());
|
||||
cout << "LCS:" << lcs_s << endl;
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
d.printSES();
|
||||
|
||||
return 0;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff<elem, sequence> d(A, B);
|
||||
// d.onOnlyEditDistance();
|
||||
d.compose();
|
||||
|
||||
// editDistance
|
||||
cout << "editDistance:" << d.getEditDistance() << endl;
|
||||
|
||||
// Longest Common Subsequence
|
||||
vector<elem> lcs_v = d.getLcsVec();
|
||||
sequence lcs_s(lcs_v.begin(), lcs_v.end());
|
||||
cout << "LCS:" << lcs_s << endl;
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
d.printSES();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,35 +1,35 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using dtl::Diff3;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc, 4)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
sequence C(argv[3]);
|
||||
|
||||
Diff3< elem, sequence > diff3(A, B, C);
|
||||
diff3.compose();
|
||||
if (!diff3.merge()) {
|
||||
cerr << "conflict." << endl;
|
||||
return 0;
|
||||
}
|
||||
cout << "result:" << diff3.getMergedSequence() << endl;
|
||||
|
||||
if (isFewArgs(argc, 4)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
sequence C(argv[3]);
|
||||
|
||||
Diff3<elem, sequence> diff3(A, B, C);
|
||||
diff3.compose();
|
||||
if (!diff3.merge()) {
|
||||
cerr << "conflict." << endl;
|
||||
return 0;
|
||||
}
|
||||
cout << "result:" << diff3.getMergedSequence() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -10,26 +10,26 @@ using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff< elem, sequence > d(A, B);
|
||||
d.compose();
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
d.printSES < ostream, customChangePrinter > (cout);
|
||||
|
||||
return 0;
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff<elem, sequence> d(A, B);
|
||||
d.compose();
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
|
||||
d.printSES<ostream, customChangePrinter>(cout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@@ -9,30 +9,30 @@ using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff< elem, sequence > d(A, B);
|
||||
d.compose();
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string result;
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
d.storeSES < string, CustomStorage > (result);
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
cout << result;
|
||||
|
||||
return 0;
|
||||
Diff<elem, sequence> d(A, B);
|
||||
d.compose();
|
||||
|
||||
// Shortest Edit Script
|
||||
cout << "SES" << endl;
|
||||
|
||||
string result;
|
||||
|
||||
d.storeSES<string, CustomStorage>(result);
|
||||
|
||||
cout << result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <iostream>
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -15,97 +15,93 @@ using dtl::Diff;
|
||||
using dtl::elemInfo;
|
||||
using dtl::uniHunk;
|
||||
|
||||
static void showStats (string fp1, string fp2);
|
||||
static void unifiedDiff (string fp1, string fp2);
|
||||
static void showStats(string fp1, string fp2);
|
||||
static void unifiedDiff(string fp1, string fp2);
|
||||
|
||||
static void showStats (string fp1, string fp2)
|
||||
{
|
||||
const int MAX_LENGTH = 255;
|
||||
char time_format[] = "%Y-%m-%d %H:%M:%S %z";
|
||||
time_t rawtime[2];
|
||||
struct tm *timeinfo[2];
|
||||
struct stat st[2];
|
||||
|
||||
if (stat(fp1.c_str(), &st[0]) == -1) {
|
||||
cerr << "argv1 is invalid." << endl;
|
||||
exit(-1);
|
||||
}
|
||||
if (stat(fp2.c_str(), &st[1]) == -1) {
|
||||
cerr << "argv2 is invalid" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
char buf[2][MAX_LENGTH + 1];
|
||||
rawtime[0] = st[0].st_mtime;
|
||||
timeinfo[0] = localtime(&rawtime[0]);
|
||||
strftime(buf[0], MAX_LENGTH, time_format, timeinfo[0]);
|
||||
cout << "--- " << fp1 << '\t' << buf[0] << endl;
|
||||
rawtime[1] = st[1].st_mtime;
|
||||
timeinfo[1] = localtime(&rawtime[1]);
|
||||
strftime(buf[1], MAX_LENGTH, time_format, timeinfo[1]);
|
||||
cout << "+++ " << fp2 << '\t' << buf[1] << endl;
|
||||
static void showStats(string fp1, string fp2) {
|
||||
const int MAX_LENGTH = 255;
|
||||
char time_format[] = "%Y-%m-%d %H:%M:%S %z";
|
||||
time_t rawtime[2];
|
||||
struct tm *timeinfo[2];
|
||||
struct stat st[2];
|
||||
|
||||
if (stat(fp1.c_str(), &st[0]) == -1) {
|
||||
cerr << "argv1 is invalid." << endl;
|
||||
exit(-1);
|
||||
}
|
||||
if (stat(fp2.c_str(), &st[1]) == -1) {
|
||||
cerr << "argv2 is invalid" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
char buf[2][MAX_LENGTH + 1];
|
||||
rawtime[0] = st[0].st_mtime;
|
||||
timeinfo[0] = localtime(&rawtime[0]);
|
||||
strftime(buf[0], MAX_LENGTH, time_format, timeinfo[0]);
|
||||
cout << "--- " << fp1 << '\t' << buf[0] << endl;
|
||||
rawtime[1] = st[1].st_mtime;
|
||||
timeinfo[1] = localtime(&rawtime[1]);
|
||||
strftime(buf[1], MAX_LENGTH, time_format, timeinfo[1]);
|
||||
cout << "+++ " << fp2 << '\t' << buf[1] << endl;
|
||||
}
|
||||
|
||||
static void unifiedDiff (string fp1, string fp2)
|
||||
{
|
||||
typedef string elem;
|
||||
typedef vector< elem > sequence;
|
||||
typedef pair< elem, elemInfo > sesElem;
|
||||
static void unifiedDiff(string fp1, string fp2) {
|
||||
typedef string elem;
|
||||
typedef vector<elem> sequence;
|
||||
typedef pair<elem, elemInfo> sesElem;
|
||||
|
||||
ifstream Aifs(fp1.c_str());
|
||||
ifstream Bifs(fp2.c_str());
|
||||
elem buf;
|
||||
sequence ALines, BLines;
|
||||
|
||||
while(getline(Aifs, buf)){
|
||||
ALines.push_back(buf);
|
||||
}
|
||||
while(getline(Bifs, buf)){
|
||||
BLines.push_back(buf);
|
||||
}
|
||||
|
||||
Diff< elem > diff(ALines, BLines);
|
||||
diff.onHuge();
|
||||
//diff.onUnserious();
|
||||
diff.compose();
|
||||
|
||||
// type unihunk definition test
|
||||
uniHunk< sesElem > hunk;
|
||||
|
||||
if (diff.getEditDistance() > 0) {
|
||||
showStats(fp1, fp2); // show file info
|
||||
}
|
||||
|
||||
diff.composeUnifiedHunks();
|
||||
diff.printUnifiedFormat();
|
||||
ifstream Aifs(fp1.c_str());
|
||||
ifstream Bifs(fp2.c_str());
|
||||
elem buf;
|
||||
sequence ALines, BLines;
|
||||
|
||||
while (getline(Aifs, buf)) {
|
||||
ALines.push_back(buf);
|
||||
}
|
||||
while (getline(Bifs, buf)) {
|
||||
BLines.push_back(buf);
|
||||
}
|
||||
|
||||
Diff<elem> diff(ALines, BLines);
|
||||
diff.onHuge();
|
||||
// diff.onUnserious();
|
||||
diff.compose();
|
||||
|
||||
// type unihunk definition test
|
||||
uniHunk<sesElem> hunk;
|
||||
|
||||
if (diff.getEditDistance() > 0) {
|
||||
showStats(fp1, fp2); // show file info
|
||||
}
|
||||
|
||||
diff.composeUnifiedHunks();
|
||||
diff.printUnifiedFormat();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string s1(argv[1]);
|
||||
string s2(argv[2]);
|
||||
bool fileExist = true;
|
||||
|
||||
if (!isFileExist(s1)) {
|
||||
cerr << s1 << " is invalid." << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!isFileExist(s2)) {
|
||||
cerr << s2 << " is invalid." << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!fileExist) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
unifiedDiff(s1, s2);
|
||||
return 0;
|
||||
string s1(argv[1]);
|
||||
string s2(argv[2]);
|
||||
bool fileExist = true;
|
||||
|
||||
if (!isFileExist(s1)) {
|
||||
cerr << s1 << " is invalid." << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!isFileExist(s2)) {
|
||||
cerr << s2 << " is invalid." << endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!fileExist) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
unifiedDiff(s1, s2);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
|
||||
#include <dtl/dtl.hpp>
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
@@ -8,33 +8,33 @@ using namespace std;
|
||||
|
||||
using dtl::Diff;
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff<elem, sequence > d(A, B);
|
||||
d.compose();
|
||||
d.composeUnifiedHunks();
|
||||
|
||||
// editDistance
|
||||
cout << "editDistance:" << d.getEditDistance() << endl;
|
||||
|
||||
// Longest Common Subsequence
|
||||
vector<elem> lcs_v = d.getLcsVec();
|
||||
sequence lcs_s(lcs_v.begin(), lcs_v.end());
|
||||
cout << "LCS:" << lcs_s << endl;
|
||||
|
||||
// print Unified Format
|
||||
d.printUnifiedFormat();
|
||||
|
||||
return 0;
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef char elem;
|
||||
typedef string sequence;
|
||||
|
||||
sequence A(argv[1]);
|
||||
sequence B(argv[2]);
|
||||
|
||||
Diff<elem, sequence> d(A, B);
|
||||
d.compose();
|
||||
d.composeUnifiedHunks();
|
||||
|
||||
// editDistance
|
||||
cout << "editDistance:" << d.getEditDistance() << endl;
|
||||
|
||||
// Longest Common Subsequence
|
||||
vector<elem> lcs_v = d.getLcsVec();
|
||||
sequence lcs_s(lcs_v.begin(), lcs_v.end());
|
||||
cout << "LCS:" << lcs_s << endl;
|
||||
|
||||
// print Unified Format
|
||||
d.printUnifiedFormat();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user