From aecf9816284ff5236ea3239196c0f05d86cd5248 Mon Sep 17 00:00:00 2001 From: Chris Nutter Date: Fri, 17 May 2019 23:34:37 -0700 Subject: [PATCH] i'm getting really annoyed :/ --- diff-rcm | Bin 23216 -> 23216 bytes diff.c | 83 +++++++++++++++++++++++++++---------------------------- diff.h | 12 ++++---- pa.c | 57 +++++++++++++++++++------------------- pa.h | 14 ++++++---- 5 files changed, 85 insertions(+), 81 deletions(-) diff --git a/diff-rcm b/diff-rcm index acf8d832bd8914e62f10d48511b4b5207ac1d6b6..01f84b65ee1539d47d3f3f3aad9272d4a928c478 100755 GIT binary patch delta 53 zcmdn6m2m?QdAKq~HgEQFUB?2Ve|d87u^AX9nwlnW=7?Cv$ewCwXlRn6H@PuXV)EI@ F#{dX5688WA delta 53 zcmdn6m2m?QdAKq)HE#BDUB?2Ve|d87v6-8ir&=0s=7?Cv$ew6moRn&yH@PuXV)EI@ F#{d)&6IB2J diff --git a/diff.c b/diff.c index aa243d4..66e55b6 100644 --- a/diff.c +++ b/diff.c @@ -12,9 +12,9 @@ int main(int argc, const char* argv[]) { init(--argc, ++argv); loadfiles(files[0], files[1]); - if (**argv != '-' || diffnormal == 1) { standard(files[0], files[1]); } + if (**argv != '-' || diffnormal == 1) { standard(); } - if (showsidebyside) { sideside(files[0], files[1]); } + if (showsidebyside) { sideside(); } if (showbrief) { quiet(files[0], files[1]); } if (report_identical) { loud(files[0], files[1]); } @@ -52,16 +52,16 @@ void init(int argc, const char* argv[]) { // ================================= // - if (showversion) { version(); exit(0); } - if (showhelp) { help(); exit(0); } + if (showversion) { version(); exit(0); } + if (showhelp) { help(); exit(0); } if (!showcontext && !showunified && - !showsidebyside && !showleftcolumn) { diffnormal = 1; } + !showsidebyside && !showleftcolumn) { diffnormal = 1; } if (((showsidebyside || showleftcolumn) && - (diffnormal || showcontext || showunified)) || - (showcontext && showunified) || (diffnormal && - (showcontext || showunified))) { diff_output_conflict_error(); } + (diffnormal || showcontext || showunified)) || + (showcontext && showunified) || (diffnormal && + (showcontext || showunified))) { diff_output_conflict_error(); } } @@ -71,8 +71,8 @@ void setoption(const char* arg, const char* s, const char* t, int* value) { void diff_output_conflict_error(void) { fprintf(stderr, "diff-rcm: Conflicting output style options.\n"); - fprintf(stderr, "diff-rcm: Try `diff --help' for more information.)\n"); - exit(CONFLICTING_OUTPUT_OPTIONS); + fprintf(stderr, "diff-rcm: Try `diff --help' for more information.\n"); + exit (CONFLICTING_OUTPUT_OPTIONS); } @@ -89,13 +89,12 @@ void loadfiles(const char* filename1, const char* filename2) { while (!feof(fin1) && fgets(buf, BUFLEN, fin1) != NULL) { strings1[count1++] = strdup(buf); } fclose(fin1); while (!feof(fin2) && fgets(buf, BUFLEN, fin2) != NULL) { strings2[count2++] = strdup(buf); } fclose(fin2); - - p = pa_first(strings1, count1); - q = pa_first(strings2, count2); + + fclose(fin1); fclose(fin2); } -void version() { +void version(void) { printf("\n\n ██ ██ ████ ████ \n"); printf(" ░██░░ ░██░ ░██░ \n"); printf(" ░██ ██ ██████ ██████ ██████ █████ ██████████ \n"); @@ -110,7 +109,7 @@ void version() { printf("Any unauthorized use or re-distribution of this code is permitted.\n\n"); printf("\tChris Nutter\tWilliam McCarthy Rasputin\n\n\n"); } -void help() { +void help(void) { printf("\nUsage: diff-rcm [OPTION]... FILES\n"); printf("Compare FILES line by line.\n\n"); printf("Mandatory arguments to long options are mandatory for short options too.\n\n"); @@ -132,24 +131,17 @@ void help() { printf("diff-rcm homepage: \n\n"); } -int standard(const char* filename1, const char* filename2) { - - identical(filename1, filename2); - - printf("\nTHIS IS NOT standard FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n"); - printf("THIS IS NOT standard FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n"); - printf("THIS IS NOT standard FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n"); - printf("THIS IS NOT standard FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n\n"); - - //pa* qlast = q; - - return 0; +void standard(void) { + } -int sideside(const char* filename1, const char* filename2) { +void sideside(void) { + + p = pa_first(strings1, count1); + q = pa_first(strings2, count2); + int foundmatch = 0; pa* qlast = q; - while(p != NULL) { qlast = q; @@ -159,35 +151,42 @@ int sideside(const char* filename1, const char* filename2) { q = qlast; if (foundmatch) { + while ((foundmatch = pa_equal(p, q)) == 0) { - pa_print(q, NULL, printright); + + printcheck(q, NULL, printright); q = pa_next(q); qlast = q; + } - if (showleftcolumn) { pa_print(p, q, printnocommon); } - else if (suppresscommon) { pa_print(p, q, printleftparen); } - else { pa_print(p, q, printboth); } + if (showleftcolumn) { printcheck(p, q, printnocommon); } + else if (suppresscommon) { printcheck(p, q, printleftparen); } + else { printcheck(p, q, printboth); } p = pa_next(p); q = pa_next(q); + } - else { pa_print(p, NULL, printleft); p = pa_next(p); } + else { printcheck(p, NULL, printleft); p = pa_next(p); } + } - while(q != NULL) { pa_print(q, NULL, printright); q = pa_next(q); } - - return 0; - + while(q != NULL) { + + printcheck(q, NULL, printright); + q = pa_next(q); + + } } -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 quiet(const char* filename1, const char* filename2) { if (identical(filename1, filename2) == 0) { printf("Files %s and %s differ.\n", filename1, filename2); } } void loud(const char* filename1, const char* filename2) { - if (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("The files are identical.\n"); } - else { standard(files[0], files[1]); } + if (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("Files %s and %s are identical.\n", filename1, filename2); } + else { standard(); } } -void identical(const char* filename1, const char* filename2) { if (*filename1 == *filename2) { exit(0); } else return; } +int identical(const char* filename1, const char* filename2) { if (*filename1 == *filename2) { exit(0); } else return 0; } diff --git a/diff.h b/diff.h index d6e7b7d..df3cffd 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, foundmatch = 0; +int showhelp = 0; int equal = 0, cnt = 0, count = 0; @@ -46,12 +46,12 @@ void diff_output_conflict_error(void); void loadfiles(const char* filename1, const char* filename2); -void version(); -void help(); +void version(void); +void help(void); -int standard(const char* filename1, const char* filename2); -int sideside(const char* filename1, const char* filename2); +void standard(void); +void sideside(void); void quiet(const char* filename1, const char* filename2); void loud(const char* filename1, const char* filename2); -void identical(const char* filename1, const char* filename2); +int identical(const char* filename1, const char* filename2); diff --git a/pa.c b/pa.c index 2eb2490..2099316 100644 --- a/pa.c +++ b/pa.c @@ -59,7 +59,7 @@ char* pa_info(pa* p) { int pa_equal(pa* p, pa* q) { - if (p == NULL || q == NULL) { return 0; } + 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; } @@ -82,34 +82,9 @@ void sideside_type(const char* left, const char* right, int nocommon, int leftpa if(symbol != '|' && nocommon == 1) { return; } - printf("%-61s %c ", buf, symbol); + printf("%-48s %c ", buf, symbol); if (symbol == '|') { printf("%s", right); } - else { printf("%s", (leftparen ? "\n" : right)); } - -} - -void print_first(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 print_second(pa* p, pa* q, void (*fp)(const char*, const char*)) { - - if(p == NULL || q == NULL) { return; } - for(int i = p->start, j = q->start; - i <= p->stop && i != p->filesize && - j <= q->stop && j != q->filesize; ++i, ++j) { - fp(p->base[i], q->base[j]); - } - -} - -void pa_print(pa* p, pa* q, void (*fp)(const char*, const char*)) { - - if(q == NULL) { print_first(p, (void (*)(const char*)) fp); } - else { print_second(p, q, fp); } + else { printf("%s", (leftparen ? "\n" : right)); } } @@ -134,6 +109,7 @@ void printleft(const char* left, const char* n) { buf[len + j++] = '<'; buf[len + j++] = '\0'; + printf("%s\n", buf); } @@ -156,3 +132,28 @@ void printboth(const char* left_right, const char* n) { printf("%-50s %s", buf, left_right); } + +void printcheck(pa* p, pa* q, void (*fp)(const char*, const char*)) { + + if (q == NULL) { print_first(p, (void (*)(const char*)) fp); } + else { print_second(p, q, fp); } + +} + +void print_first(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 print_second(pa* p, pa* q, void (*fp)(const char*, const char*)) { + + if(p == NULL || q == NULL) { return; } + for(int i = p->start, j = q->start; + i <= p->stop && i != p->filesize && + j <= q->stop && j != q->filesize; ++i, ++j) { + fp(p->base[i], q->base[j]); + } + +} diff --git a/pa.h b/pa.h index f7a03f8..5e6f9ab 100644 --- a/pa.h +++ b/pa.h @@ -29,18 +29,22 @@ size_t pa_size(pa* p); char** pa_base(pa* p); char* pa_info(pa* p); int pa_equal(pa* p, pa* q); + void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol); + +void printcheck(pa* p, pa* q, void (*fp)(const char*, const char*)); + void print_first(pa* p, void (*fp)(const char*)); void print_second(pa* p, pa* q, void (*fp)(const char*, const char*)); -void pa_print(pa* p, pa* q, void (*fp)(const char*, const char*)); + void printleftparen(const char* left, const char* right); void printnocommon(const char* left, const char* right); -void pa_printfile(char* base[], int count, void(*fp)(const char*, const char*)); -char* yesorno(int condition); + FILE* openfile(const char* filename, const char* openflags); -void pa_printline(void); + void printleft(const char* left, const char*); void printright(const char* right, const char*); -void printboth(const char* left_right, const char* n); +void printboth(const char* left_right, const char*); + #endif