i'm getting really annoyed :/

master
Chris Nutter 2019-05-17 23:34:37 -07:00
parent 92f2d5dbe5
commit aecf981628
5 changed files with 85 additions and 81 deletions

BIN
diff-rcm

Binary file not shown.

75
diff.c
View File

@ -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);
}
@ -90,12 +90,11 @@ 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: <https://www.github.com/cdnutter/diff/>\n\n");
}
int standard(const char* filename1, const char* filename2) {
void standard(void) {
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;
}
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); }
while(q != NULL) {
return 0;
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; }

12
diff.h
View File

@ -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);

57
pa.c
View File

@ -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]);
}
}

14
pa.h
View File

@ -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