pretty smooth, printnormal is not working its still beta

master
Chris Nutter 2019-05-12 23:13:57 -07:00
parent 045939cb08
commit 9903c8cf44
4 changed files with 17 additions and 11 deletions

BIN
diff-rcm

Binary file not shown.

11
diff.c
View File

@ -79,6 +79,7 @@ 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));
@ -96,11 +97,6 @@ void loadfiles(const char* filename1, const char* filename2) {
}
void version() {
// printf("\n _ _ __ __ \n");
// printf(" __| (_)/ _|/ _| _ __ ___ _ __ ___ \n");
// printf(" / _` | | |_| |_ _____| '__/ __| '_ ` _ \\ \n");
// printf("| (_| | | _| _|_____| | | (__| | | | | | \n");
// printf(" \\__,_|_|_| |_| |_| \\___|_| |_| |_| \n\n");
printf("\n\n ██ ██ ████ ████ \n");
printf(" ░██░░ ░██░ ░██░ \n");
printf(" ░██ ██ ██████ ██████ ██████ █████ ██████████ \n");
@ -144,8 +140,7 @@ int normal(const char* filename1, const char* filename2) {
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");
pa_print(p, printleft);
pa_print(q, printright);
pa_print(p, printnormal);
return 0;
}
@ -161,7 +156,7 @@ int sideside(const char* filename1, const char* filename2) {
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 equal.\n"); }
if (pa_equal(p, q) != 0) { printf("The files are identical.\n"); }
else { normal(files[0], files[1]); }
}

16
pa.c
View File

@ -57,6 +57,13 @@ void printboth(const char* left_right) {
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; }
@ -70,11 +77,14 @@ char* pa_info(pa* p) {
}
int pa_equal(pa* p, pa* q) {
if (p == NULL || q == NULL) { return 0; }
if (pa_size(p) != pa_size(q)) { return 0; }
int i = p->start, j = q->start, equal = 0;
while ((equal = strcmp(p->base[i], q->base[i])) == 0) { ++i; ++j; }
return equal;
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) {

1
pa.h
View File

@ -30,6 +30,7 @@ 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);
FILE* openfile(const char* filename, const char* openflags);
char* yesorno(int condition);