move to cmake
This commit is contained in:
@@ -1,24 +1,13 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include <dtl/dtl.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
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(std::string fp1, std::string fp2);
|
||||
static void unifiedDiff(std::string fp1, std::string fp2);
|
||||
|
||||
static void showStats(string fp1, string fp2) {
|
||||
static void showStats(std::string fp1, std::string fp2) {
|
||||
const int MAX_LENGTH = 255;
|
||||
char time_format[] = "%Y-%m-%d %H:%M:%S %z";
|
||||
time_t rawtime[2];
|
||||
@@ -26,11 +15,11 @@ static void showStats(string fp1, string fp2) {
|
||||
struct stat st[2];
|
||||
|
||||
if (stat(fp1.c_str(), &st[0]) == -1) {
|
||||
cerr << "argv1 is invalid." << endl;
|
||||
std::cerr << "argv1 is invalid." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
if (stat(fp2.c_str(), &st[1]) == -1) {
|
||||
cerr << "argv2 is invalid" << endl;
|
||||
std::cerr << "argv2 is invalid" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -38,20 +27,20 @@ static void showStats(string fp1, string fp2) {
|
||||
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;
|
||||
std::cout << "--- " << fp1 << '\t' << buf[0] << std::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;
|
||||
std::cout << "+++ " << fp2 << '\t' << buf[1] << std::endl;
|
||||
}
|
||||
|
||||
static void unifiedDiff(string fp1, string fp2) {
|
||||
typedef string elem;
|
||||
typedef vector<elem> sequence;
|
||||
typedef pair<elem, elemInfo> sesElem;
|
||||
static void unifiedDiff(std::string fp1, std::string fp2) {
|
||||
typedef std::string elem;
|
||||
typedef std::vector<elem> sequence;
|
||||
typedef std::pair<elem, elemInfo> sesElem;
|
||||
|
||||
ifstream Aifs(fp1.c_str());
|
||||
ifstream Bifs(fp2.c_str());
|
||||
std::ifstream Aifs(fp1.c_str());
|
||||
std::ifstream Bifs(fp2.c_str());
|
||||
elem buf;
|
||||
sequence ALines, BLines;
|
||||
|
||||
@@ -80,21 +69,21 @@ static void unifiedDiff(string fp1, string fp2) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (isFewArgs(argc)) {
|
||||
cerr << "Too few arguments." << endl;
|
||||
std::cerr << "Too few arguments." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string s1(argv[1]);
|
||||
string s2(argv[2]);
|
||||
std::string s1(argv[1]);
|
||||
std::string s2(argv[2]);
|
||||
bool fileExist = true;
|
||||
|
||||
if (!isFileExist(s1)) {
|
||||
cerr << s1 << " is invalid." << endl;
|
||||
std::cerr << s1 << " is invalid." << std::endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
if (!isFileExist(s2)) {
|
||||
cerr << s2 << " is invalid." << endl;
|
||||
std::cerr << s2 << " is invalid." << std::endl;
|
||||
fileExist = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user