Guest User

Untitled

a guest
Nov 20th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include <iostream>
  2. #include "help.h"
  3. #include <fstream>
  4.  
  5. // terminal text colors
  6. #define RST "\x1B[0m"
  7. #define KRED "\x1B[31m"
  8. #define KGRN "\x1B[32m"
  9. #define KYEL "\x1B[33m"
  10. #define KBLU "\x1B[34m"
  11. #define KMAG "\x1B[35m"
  12. #define KCYN "\x1B[36m"
  13. #define KWHT "\x1B[37m"
  14.  
  15. #define FRED(x) KRED x RST
  16. #define FGRN(x) KGRN x RST
  17. #define FYEL(x) KYEL x RST
  18. #define FBLU(x) KBLU x RST
  19. #define FMAG(x) KMAG x RST
  20. #define FCYN(x) KCYN x RST
  21. #define FWHT(x) KWHT x RST
  22.  
  23. #define BOLD(x) "\x1B[1m" x RST
  24. #define UNDL(x) "\x1B[4m" x RST
  25.  
  26. int global_remember = 0;
  27.  
  28. using namespace std;
  29.  
  30. int file_lenght(ifstream& is){
  31. is.seekg (0, is.end);
  32. int length = is.tellg();
  33. return length;
  34.  
  35. }
  36.  
  37.  
  38. void print_line(int* diff_chars, string& line1, string& line2, int length1, int length2){
  39. for(int i = 0; i < length2 && i < length1; i++){
  40. if(i == *diff_chars++){
  41. cout << line1[i] << "\033[1;31m" << line2[i] << "\033[0m;";
  42. } else {
  43. cout << line1[i] << line2[i] << '\n';
  44. }
  45. }
  46. }
  47.  
  48. void difffiles(ifstream& fs1, ifstream& fs2){
  49. string line1;
  50. string line2;
  51. int len = file_lenght(fs1);
  52.  
  53. int* diff_chars = new int[len];
  54. while(getline(fs1, line1)){
  55. if(getline(fs2, line2)){ // stopped here because getline won't work
  56. cout << "executed 0;";
  57. global_remember = 0;
  58. size_t length1 = line1.length();
  59. size_t length2 = line2.length();
  60. for(int i = 0; i < length1 && i < length2; i++){
  61. if(line1[i] != line2[i]){
  62. diff_chars[global_remember++] = i;
  63. continue;
  64. }
  65.  
  66. }
  67. print_line(diff_chars, line1, line2, length1, length2);
  68. }
  69. }
  70. delete[] diff_chars;
  71. }
  72.  
  73. void openfiles(char* file1, char* file2){
  74. ifstream fs1(file1);
  75. ifstream fs2(file2);
  76. if(fs1.is_open() && fs2.is_open()){
  77. difffiles(fs1, fs2);
  78. } else{
  79. cout << "File doesn't exist" << '\n';
  80. exit(1);
  81. }
  82. }
  83.  
  84. int main(int argc, char* argv[]){
  85. if(argc <= 1){
  86. help(*argv);
  87. exit(1);
  88. } else if(argc == 4 || argc == 2){
  89. while(*argv++ != NULL && **argv == '-'){
  90. switch(*++*argv){
  91. case 'h':
  92. help(*--argv);
  93. return 0;
  94. break;
  95. case 'f':
  96. openfiles(*argv, *++argv);
  97. break;
  98.  
  99. }
  100. }
  101. }
  102. exit(0);
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment