Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "help.h"
- #include <fstream>
- // terminal text colors
- #define RST "\x1B[0m"
- #define KRED "\x1B[31m"
- #define KGRN "\x1B[32m"
- #define KYEL "\x1B[33m"
- #define KBLU "\x1B[34m"
- #define KMAG "\x1B[35m"
- #define KCYN "\x1B[36m"
- #define KWHT "\x1B[37m"
- #define FRED(x) KRED x RST
- #define FGRN(x) KGRN x RST
- #define FYEL(x) KYEL x RST
- #define FBLU(x) KBLU x RST
- #define FMAG(x) KMAG x RST
- #define FCYN(x) KCYN x RST
- #define FWHT(x) KWHT x RST
- #define BOLD(x) "\x1B[1m" x RST
- #define UNDL(x) "\x1B[4m" x RST
- int global_remember = 0;
- using namespace std;
- int file_lenght(ifstream& is){
- is.seekg (0, is.end);
- int length = is.tellg();
- return length;
- }
- void print_line(int* diff_chars, string& line1, string& line2, int length1, int length2){
- for(int i = 0; i < length2 && i < length1; i++){
- if(i == *diff_chars++){
- cout << line1[i] << "\033[1;31m" << line2[i] << "\033[0m;";
- } else {
- cout << line1[i] << line2[i] << '\n';
- }
- }
- }
- void difffiles(ifstream& fs1, ifstream& fs2){
- string line1;
- string line2;
- int len = file_lenght(fs1);
- int* diff_chars = new int[len];
- while(getline(fs1, line1)){
- if(getline(fs2, line2)){ // stopped here because getline won't work
- cout << "executed 0;";
- global_remember = 0;
- size_t length1 = line1.length();
- size_t length2 = line2.length();
- for(int i = 0; i < length1 && i < length2; i++){
- if(line1[i] != line2[i]){
- diff_chars[global_remember++] = i;
- continue;
- }
- }
- print_line(diff_chars, line1, line2, length1, length2);
- }
- }
- delete[] diff_chars;
- }
- void openfiles(char* file1, char* file2){
- ifstream fs1(file1);
- ifstream fs2(file2);
- if(fs1.is_open() && fs2.is_open()){
- difffiles(fs1, fs2);
- } else{
- cout << "File doesn't exist" << '\n';
- exit(1);
- }
- }
- int main(int argc, char* argv[]){
- if(argc <= 1){
- help(*argv);
- exit(1);
- } else if(argc == 4 || argc == 2){
- while(*argv++ != NULL && **argv == '-'){
- switch(*++*argv){
- case 'h':
- help(*--argv);
- return 0;
- break;
- case 'f':
- openfiles(*argv, *++argv);
- break;
- }
- }
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment