diff --git a/deprecated/newfiles/__MACOSX/._diff_02.c b/deprecated/newfiles/__MACOSX/._diff_02.c deleted file mode 100644 index cca5a7d..0000000 Binary files a/deprecated/newfiles/__MACOSX/._diff_02.c and /dev/null differ diff --git a/deprecated/newfiles/__MACOSX/._left.txt b/deprecated/newfiles/__MACOSX/._left.txt deleted file mode 100644 index 21263e9..0000000 Binary files a/deprecated/newfiles/__MACOSX/._left.txt and /dev/null differ diff --git a/deprecated/newfiles/__MACOSX/._para.c b/deprecated/newfiles/__MACOSX/._para.c deleted file mode 100644 index cbfd2c1..0000000 Binary files a/deprecated/newfiles/__MACOSX/._para.c and /dev/null differ diff --git a/deprecated/newfiles/__MACOSX/._para.h b/deprecated/newfiles/__MACOSX/._para.h deleted file mode 100644 index a459444..0000000 Binary files a/deprecated/newfiles/__MACOSX/._para.h and /dev/null differ diff --git a/deprecated/newfiles/__MACOSX/._right.txt b/deprecated/newfiles/__MACOSX/._right.txt deleted file mode 100644 index c24fbbd..0000000 Binary files a/deprecated/newfiles/__MACOSX/._right.txt and /dev/null differ diff --git a/deprecated/newfiles/__MACOSX/._util.c b/deprecated/newfiles/__MACOSX/._util.c deleted file mode 100644 index 84cc988..0000000 Binary files a/deprecated/newfiles/__MACOSX/._util.c and /dev/null differ diff --git a/deprecated/newfiles/__MACOSX/._util.h b/deprecated/newfiles/__MACOSX/._util.h deleted file mode 100644 index ec18b79..0000000 Binary files a/deprecated/newfiles/__MACOSX/._util.h and /dev/null differ diff --git a/deprecated/newfiles/test_diff b/deprecated/newfiles/test_diff new file mode 100755 index 0000000..b0513e9 Binary files /dev/null and b/deprecated/newfiles/test_diff differ diff --git a/diff-rcm b/diff-rcm index 1dd2e21..6c03fc5 100755 Binary files a/diff-rcm and b/diff-rcm differ diff --git a/diff.c b/diff.c index bc10a31..bb8532d 100644 --- a/diff.c +++ b/diff.c @@ -79,7 +79,6 @@ void diff_output_conflict_error(void) { void loadfiles(const char* filename1, const char* filename2) { if (filename2 == NULL) { printf("Usage: ./diff [options] file1 file2\n"); exit(1); } - if (*filename1 == *filename2) { exit(0); } memset(buf, 0, sizeof(buf)); memset(strings1, 0, sizeof(strings1)); @@ -135,28 +134,53 @@ void help() { int normal(const char* filename1, const char* filename2) { + identical(filename1, filename2); + printf("\nTHIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n"); printf("THIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n"); printf("THIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n"); - printf("THIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n\n\n"); + printf("THIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n\n"); - pa_print(p, printnormal); + //pa_print(p, printnormal); return 0; } int sideside(const char* filename1, const char* filename2) { - if (pa_equal(p, q)) { pa_print(p, printboth); return 0; } - pa_print(q, printright); - while ((q = pa_next(q)) != NULL && !equal) { equal = pa_equal(p, q); pa_print(q, equal ? printboth : printright); } - pa_print((p = pa_next(p)), printleft); + pa* qlast = q; + while (p != NULL) { + qlast = q; + foundmatch = 0; + while (q != NULL && (foundmatch = pa_equal(p, q)) == 0) { q = pa_next(q); } + q = qlast; + + if (foundmatch) { + while ((foundmatch = pa_equal(p, q)) == 0) { + pa_print(q, printright); + q = pa_next(q); + qlast = q; + } + pa_print(q, printboth); + p = pa_next(p); + q = pa_next(q); + } else { + pa_print(p, printleft); + p = pa_next(p); + } + } + while (q != NULL) { + pa_print(q, printright); + q = pa_next(q); + } return 0; } void quiet(const char* filename1, const char* filename2) { if (pa_equal(p, q) == 0) { printf("The files are not the same.\n"); } else { return; } } void loud(const char* filename1, const char* filename2) { - if (pa_equal(p, q) != 0) { printf("The files are identical.\n"); } + if (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("The files are identical.\n"); } else { normal(files[0], files[1]); } } + +void identical(const char* filename1, const char* filename2) { if (*filename1 == *filename2) { exit(0); } else return; } diff --git a/diff.h b/diff.h index 41213a4..a7d79be 100644 --- a/diff.h +++ b/diff.h @@ -32,7 +32,7 @@ char *strings1[MAXSTRINGS], *strings2[MAXSTRINGS]; int showversion = 0, showbrief = 0, ignorecase = 0, report_identical = 0, showsidebyside = 0; int showleftcolumn = 0, showunified = 0, showcontext = 0, suppresscommon = 0, diffnormal = 0; -int showhelp = 0; +int showhelp = 0, foundmatch = 0; int equal = 0, cnt = 0, count = 0; @@ -53,3 +53,5 @@ int normal(const char* filename1, const char* filename2); int sideside(const char* filename1, const char* filename2); void quiet(const char* filename1, const char* filename2); void loud(const char* filename1, const char* filename2); + +void identical(const char* filename1, const char* filename2); diff --git a/left.txt b/left.txt new file mode 100644 index 0000000..bbae935 --- /dev/null +++ b/left.txt @@ -0,0 +1,25 @@ +This part of the +document has stayed the +sme from version to +version. It shouldn't +be shown if it doesn't +change. Otherwise, that +would not be helping to +compress the size of the +changes. + +This paragraph contains +text that is outdated. +It will be deleted in the +near future. + +It is important to spell +check this dokument. On +the other hand, a +misspelled word isn't +the end of the world. +Nothing in the rest of +this paragraph needs to +be changed. Things can +be added after it. + diff --git a/pa.c b/pa.c index 8503f77..18f947f 100644 --- a/pa.c +++ b/pa.c @@ -12,29 +12,83 @@ pa* pa_make(char* base[], int filesize, int start, int stop) { p->filesize = filesize; p->start = start; p->stop = stop; + p->firstline = (p == NULL || start < 0) ? NULL : p->base[start]; + p->secondline = (p == NULL || start < 0 || filesize < 2) ? NULL : p->base[start + 1]; return p; } + pa* pa_first(char* base[], int size) { pa* p = pa_make(base, size, 0, -1); return pa_next(p); } + +void pa_destroy(pa* p) { free(p); } + pa* pa_next(pa* p) { - if (p->stop == p->filesize) { return NULL; } + if (p == NULL || p->stop == p->filesize) { return NULL; } int i; pa* pnew = pa_make(p->base, p->filesize, p->stop + 1, p->stop + 1); for (i = pnew->start; i < p->filesize && strcmp(p->base[i], "\n") != 0; ++i) { } pnew->stop = i; + if (pnew->start >= p->filesize) { + free(pnew); + pnew = NULL; + } return pnew; } +size_t pa_filesize(pa* p) { return p == NULL ? 0 : p->filesize; } + +size_t pa_size(pa* p) { return p == NULL || p->stop < p->start ? 0 : p->stop - p->start + 1; } + +char** pa_base(pa* p) { return p->base; } + +char* pa_info(pa* p) { + static char buf[BUFLEN]; // static for a reason + snprintf(buf, sizeof(buf), "base: %p, filesize: %d, start: %d, stop: %d\n", + p->base, p->filesize, p->start, p->stop); + return buf; // buf MUST be static +} + +int pa_equal(pa* p, pa* q) { + if (p == NULL || q == NULL) { return 0; } + if (pa_size(p) != pa_size(q)) { return 0; } + if (p->start >= p->filesize || q->start >= q->filesize) { return 0; } + int i = p->start, j = q->start, equal = 0; + while ((equal = strcmp(p->base[i], q->base[i])) == 0) { ++i; ++j; } + return 1; +} void pa_print(pa* p, void (*fp)(const char*)) { if (p == NULL) { return; } for (int i = p->start; i <= p->stop && i != p->filesize; ++i) { fp(p->base[i]); } } -void pa_destroy(pa* p) { free(p); } + +void pa_printfile(char* base[], int count, void (*fp)(const char*)) { + pa* p = pa_first(base, count); + while (p != NULL) { + pa_print(p, fp); + p = pa_next(p); + } + printline(); +} + +char* yesorno(int condition) { return condition == 0 ? "no" : "YES"; } + +FILE* openfile(const char* filename, const char* openflags) { + FILE* f; + if ((f = fopen(filename, openflags)) == NULL) { printf("can't open '%s'\n", filename); exit(1); } + return f; +} + +void printline(void) { + for (int i = 0; i < 10; ++i) { printf("=========="); } + printf("\n"); +} + + void printleft(const char* left) { char buf[BUFLEN]; @@ -45,10 +99,12 @@ void printleft(const char* left) { buf[len + j++] = '\0'; printf("%s\n", buf); } + void printright(const char* right) { if (right == NULL) { return; } printf("%50s %s", ">", right); } + void printboth(const char* left_right) { char buf[BUFLEN]; size_t len = strlen(left_right); @@ -56,39 +112,3 @@ void printboth(const char* left_right) { buf[len - 1] = '\0'; printf("%-50s %s", buf, left_right); } - -void printnormal(const char* first) { - char buf[BUFLEN]; - size_t len1 = strlen(first); - if (len1 > 0) { strncpy(buf, first, len1); } - buf[len1 - 1] = '\0'; -} - -size_t pa_filesize(pa* p) { return p == NULL ? 0 : p->filesize; } -size_t pa_size(pa* p) { return p == NULL || p->stop < p->start ? 0 : p->stop - p->start + 1; } - -char** pa_base(pa* p) { return p->base; } -char* yesorno(int condition) { return condition == 0 ? "no" : "YES"; } -char* pa_info(pa* p) { - static char buf[BUFLEN]; // static for a reason - snprintf(buf, sizeof(buf), "base: %p, filesize: %d, start: %d, stop: %d\n", - p->base, p->filesize, p->start, p->stop); - return buf; // buf MUST be static -} - -int pa_equal(pa* p, pa* q) { - - if (p == NULL || q == NULL) { return 0; } - if (pa_size(p) != pa_size(q)) { return 0; } - if (p->start >= p->filesize || q->start >= q->filesize) { return 0; } - int i = p->start, j = q->start, equal = 0, psize = p->filesize, qsize = q->filesize; - while (i < psize && j < qsize && (equal = strcmp(p->base[i], q->base[i])) == 0) { ++i; ++j; } - return 1; - -} - -FILE* openfile(const char* filename, const char* openflags) { - FILE* f; - if ((f = fopen(filename, openflags)) == NULL) { printf("can't open '%s'\n", filename); exit(1); } - return f; -} diff --git a/pa.h b/pa.h index c7ba8ba..647d092 100644 --- a/pa.h +++ b/pa.h @@ -13,6 +13,8 @@ struct pa { int filesize; int start; int stop; + char* firstline; // DEBUG only + char* secondline; }; pa* p; @@ -30,8 +32,9 @@ void pa_print(pa* p, void (*fp)(const char*)); void printboth(const char* left_right); void printleft(const char* left); void printright(const char* right); -void printnormal(const char* first); +void pa_printfile(char* base[], int count, void (*fp)(const char*)); FILE* openfile(const char* filename, const char* openflags); char* yesorno(int condition); +void printline(void); #endif diff --git a/right.txt b/right.txt new file mode 100644 index 0000000..2d7f33d --- /dev/null +++ b/right.txt @@ -0,0 +1,31 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + +This part of the +document has stayed the +sme from version to +version. It shouldn't +be shown if it doesn't +change. Otherwise, that +would not be helping to +compress the size of the +changes. + +It is important to spell +check this document. On +the other hand, a +misspelled word isn't +the end of the world. +Nothing in the rest of +this paragraph needs to +be changed. Things can +be added after it. + +This pragraph contains +important new additions +to this document. + +