well, that's all the time ive got, i gotta get back to playing animal crossing new leaf on my nintendo 3ds

master
Chris Nutter 2019-05-19 22:56:43 -07:00
parent aa1a5fb145
commit cf438e7385
4 changed files with 299 additions and 110 deletions

121
diff.c
View File

@ -24,6 +24,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "diff.h" #include "diff.h"
#include "pa.h" #include "pa.h"
@ -44,8 +47,8 @@ int main(int argc, const char* argv[]) {
if (**argv != '-' || diffnormal == 1) { lineline(); } if (**argv != '-' || diffnormal == 1) { lineline(); }
if (showcontext) { context(); } if (showcontext) { context(files[0], files[1]); }
if (showunified) { unified(); } if (showunified) { unified(files[0], files[1]); }
return 0; return 0;
@ -141,7 +144,7 @@ void version(void) {
printf(" ░░██████░██ ░██ ░██ ░███ ░░█████ ███ ░██ ░██ \n"); printf(" ░░██████░██ ░██ ░██ ░███ ░░█████ ███ ░██ ░██ \n");
printf(" ░░░░░░ ░░ ░░ ░░ ░░░ ░░░░░ ░░░ ░░ ░░ \n\n"); printf(" ░░░░░░ ░░ ░░ ░░ ░░░ ░░░░░ ░░░ ░░ ░░ \n\n");
printf("\n"); printf("\n");
printf("\tv0.8 alpha | Smoking is bad for your health. <3\n\n"); printf("\tv1.0 GM | Well, that's all the time I've got.\n\n");
printf("Copyright (C) 2019 | All Rights Reserved.\n"); printf("Copyright (C) 2019 | All Rights Reserved.\n");
printf("Any unauthorized use or re-distribution of this code is permitted.\n\n"); printf("Any unauthorized use or re-distribution of this code is permitted.\n\n");
printf("\tChris Nutter\tWilliam McCarthy Rasputin\n\n\n"); printf("\tChris Nutter\tWilliam McCarthy Rasputin\n\n\n");
@ -195,7 +198,7 @@ void lineline(void) {
q = pa_next(q); q = pa_next(q);
qlast = q; qlast = q;
} }
print_check(p, q, line_check); print_check(p, q, line_check_normal);
p = pa_next(p); p = pa_next(p);
q = pa_next(q); q = pa_next(q);
@ -210,8 +213,8 @@ void lineline(void) {
void sideside(const char* filename1, const char* filename2) { void sideside(const char* filename1, const char* filename2) {
int foundmatch = 0; pa* qlast = q; int foundmatch = 0; pa* qlast = q;
if (*filename1 == *filename2) { if (*filename1 == *filename2) { // This allows printing of side-by-side with the same file contents.
while (p != NULL && q != NULL) { print_check(p, q, print_both); while (p != NULL && q != NULL) { print_check(p, q, print_side_both);
p = pa_next(p); } p = pa_next(p); }
return; return;
} }
@ -224,38 +227,126 @@ void sideside(const char* filename1, const char* filename2) {
if (foundmatch) { if (foundmatch) {
while ((foundmatch = pa_equal(p, q)) == 0) { while ((foundmatch = pa_equal(p, q)) == 0) {
print_check(q, NULL, print_right); print_check(q, NULL, print_side_right);
q = pa_next(q); q = pa_next(q);
qlast = q; qlast = q;
} }
if (showleftcolumn) { print_check(p, q, print_left_paren); } if (showleftcolumn) { print_check(p, q, print_left_paren); } // Checks if the parameters for side-by-side are filled.
else if (suppresscommon) { print_check(p, q, print_no_common); } else if (suppresscommon) { print_check(p, q, print_no_common); }
else { print_check(p, q, print_side_normal); } else { print_check(p, q, print_side_default); }
p = pa_next(p); p = pa_next(p);
q = pa_next(q); q = pa_next(q);
} }
else { print_check(p, NULL, print_left); p = pa_next(p); } else { print_check(p, NULL, print_side_left); p = pa_next(p); }
} }
while (q != NULL) { print_check(q, NULL, print_right); q = pa_next(q); } while (q != NULL) { print_check(q, NULL, print_side_right); q = pa_next(q); }
} }
void context(void) {} void context(const char* filename1, const char* filename2) {
void unified(void) {}
int foundmatch = 0; pa* qlast = q;
struct stat filestat1;
struct stat filestat2;
stat(filename1, &filestat1);
stat(filename2, &filestat2);
printf("*** %s %s", filename1, ctime(&filestat1.st_mtime));
printf("--- %s %s", filename2, ctime(&filestat2.st_mtime));
printf("***************\n");
// ========================= //
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) {
print_check(q, NULL, print_context_right);
q = pa_next(q);
qlast = q;
}
print_check(p, q, line_check_context);
p = pa_next(p);
q = pa_next(q);
}
else { print_check(p, NULL, print_context_left); p = pa_next(p); }
}
while (q != NULL) { print_check(q, NULL, print_context_right); q = pa_next(q); }
}
void unified(const char* filename1, const char* filename2) {
struct stat filestat1;
struct stat filestat2;
stat(filename1, &filestat1);
stat(filename2, &filestat2);
printf("--- %s %s", filename1, ctime(&filestat1.st_mtime));
printf("+++ %s %s", filename2, ctime(&filestat2.st_mtime));
// ========================= //
int foundmatch = 0; 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) {
print_check(q, NULL, print_unified_right);
q = pa_next(q);
qlast = q;
}
print_check(p, q, line_check_unified);
p = pa_next(p);
q = pa_next(q);
}
else { print_check(p, NULL, print_unified_left); p = pa_next(p); }
}
while (q != NULL) { print_check(q, NULL, print_unified_right); q = pa_next(q); }
}
void quiet(const char* filename1, const char* filename2) { if (identical(filename1, filename2) == 0) { printf("Files %s and %s differ.\n", filename1, filename2); } exit(0); } void quiet(const char* filename1, const char* filename2) { if (identical(filename1, filename2) == 0) { printf("Files %s and %s differ.\n", filename1, filename2); } exit(0); }
void loud (const char* filename1, const char* filename2) { void loud (const char* filename1, const char* filename2) {
if (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("Files %s and %s are identical.\n", filename1, filename2); } if (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("Files %s and %s are identical.\n", filename1, filename2); }
else if (showsidebyside) { sideside(files[0], files[1]); exit(0); } else if (showsidebyside) { sideside(files[0], files[1]); exit(0); }
else if (showcontext) { context(); exit(0); } else if (showcontext) { context(files[0], files[1]); exit(0); }
else if (showunified) { unified(); exit(0); } else if (showunified) { unified(files[0], files[1]); exit(0); }
else { lineline(); exit(0); } else { lineline(); exit(0); }
} }
// ============================================================================= // // ============================================================================= //
// :P

16
diff.h
View File

@ -12,16 +12,6 @@
#define HASHLEN 200 #define HASHLEN 200
#define BUFLEN 256 #define BUFLEN 256
// ================================================================ //
/*
TODO: check line by line in a pagraph, using '|' for differences"); ----------------------- DONE
TODO: this starter code does not yet handle printing all of fin1's pagraphs."); ----------- DONE
TODO: handle the rest of diff's options");
TODO: fix lineline printing with no pameters");
TODO: implement multiple types of pameters\n");
*/
// ================================================================= // // ================================================================= //
FILE *fin1, *fin2; FILE *fin1, *fin2;
@ -53,10 +43,10 @@ void ignore_case(void);
void lineline(void); void lineline(void);
void sideside(const char* filename1, const char* filename2); void sideside(const char* filename1, const char* filename2);
void context (void); void context (const char* filename1, const char* filename2);
void unified (void); void unified (const char* filename1, const char* filename2);
void quiet(const char* filename1, const char* filename2); void quiet(const char* filename1, const char* filename2);
void loud(const char* filename1, const char* filename2); void loud (const char* filename1, const char* filename2);
int identical(const char* filename1, const char* filename2); int identical(const char* filename1, const char* filename2);

224
pa.c
View File

@ -4,7 +4,7 @@
#include "pa.h" #include "pa.h"
// ============================================================================================================= // // =================================================== FILE STRUCTURE ===================================================== //
FILE* openfile(const char* filename, const char* openflags) { FILE* openfile(const char* filename, const char* openflags) {
@ -14,7 +14,7 @@ FILE* openfile(const char* filename, const char* openflags) {
} }
// ============================================================================================================= // // ================================================== PARA STRUCTURE ====================================================== //
pa* pa_make(char* base[], int filesize, int start, int stop) { pa* pa_make(char* base[], int filesize, int start, int stop) {
@ -80,72 +80,7 @@ int pa_equal(pa* p, pa* q) {
} }
// ============================================================================================================= // // =========================================== PRINT STRUCTURE ============================================ //
void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol) {
char buf[BUFLEN];
symbol = ((strcmp(left, right) == 0) ? symbol : '|');
size_t len = strlen(left);
if(len > 0) { strncpy(buf, left, len); }
buf[len - 1] = '\0';
if(symbol != '|' && nocommon == 1) { return; }
printf("%-48s %c ", buf, symbol);
if (symbol == '|') { printf("%s", right); }
else { printf("%s", (leftparen ? "\n" : right)); }
}
// ============================================== SIDE-BY-SIDE ================================================ //
void print_left_paren(const char* left, const char* right) { sideside_type(left, right, 0, 1, '('); }
void print_no_common(const char* left, const char* right) { sideside_type(left, right, 1, 0, ' '); }
void print_side_normal(const char* left, const char* right) { sideside_type(left, right, 0, 0, ' '); }
void print_left(const char* left, const char* _) {
char buf[BUFLEN];
strcpy(buf, left);
int j = 0, len = (int)strlen(buf) - 1;
for (j = 0; j <= 48 - len ; ++j) { buf[len + j] = ' '; }
buf[len + j++] = '<';
buf[len + j++] = '\0';
printf("%s\n", buf);
}
void print_right(const char* right, const char* _) {
if (right == NULL) { return; }
printf("%50s %s", ">", right);
}
void print_both(const char* left_right, const char* _) {
char buf[BUFLEN];
size_t len = strlen(left_right);
if (len > 0) { strncpy(buf, left_right, len); }
buf[len - 1] = '\0';
printf("%-50s %s", buf, left_right);
}
void print_check(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*)) { void print_first(pa* p, void (*fp)(const char*)) {
@ -165,6 +100,71 @@ void print_second(pa* p, pa* q, void (*fp)(const char*, const char*)) {
} }
void print_check(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); }
}
// ============================================== SIDE-BY-SIDE ================================================ //
void print_left_paren (const char* left, const char* right) { sideside_type(left, right, 0, 1, '('); }
void print_no_common (const char* left, const char* right) { sideside_type(left, right, 1, 0, ' '); }
void print_side_default(const char* left, const char* right) { sideside_type(left, right, 0, 0, ' '); }
void print_side_left(const char* left, const char* _) {
char buf[BUFLEN];
strcpy(buf, left);
int j = 0, len = (int)strlen(buf) - 1;
for (j = 0; j <= 48 - len ; ++j) { buf[len + j] = ' '; }
buf[len + j++] = '<';
buf[len + j++] = '\0';
printf("%s\n", buf);
}
void print_side_right(const char* right, const char* _) {
if (right == NULL) { return; }
printf("%50s %s", ">", right);
}
void print_side_both(const char* left_right, const char* _) {
char buf[BUFLEN];
size_t len = strlen(left_right);
if (len > 0) { strncpy(buf, left_right, len); }
buf[len - 1] = '\0';
printf("%-50s %s", buf, left_right);
}
void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol) {
char buf[BUFLEN];
symbol = ((strcmp(left, right) == 0) ? symbol : '|');
size_t len = strlen(left);
if(len > 0) { strncpy(buf, left, len); }
buf[len - 1] = '\0';
if(symbol != '|' && nocommon == 1) { return; }
printf("%-48s %c ", buf, symbol);
if (symbol == '|') { printf("%s", right); }
else { printf("%s", (leftparen ? "\n" : right)); }
}
// ================================================ NORMAL ================================================== // // ================================================ NORMAL ================================================== //
@ -195,18 +195,102 @@ void print_normal_right(const char* right, const char* _) {
} }
void line_check(const char* left, const char* right) { void line_check_normal(const char* left, const char* right) {
if (strcmp(left, right) == 0); if (strcmp(left, right) == 0);
else { printf("< %s---\n> %s", left, right); } else { printf("< %s---\n> %s", left, right); }
} }
int line_number(const char* left, const char* right) { int line_number_normal(const char* left, const char* right) {
// This does nothing and probably will stay that way. Sadly... Sorry. :/
return 0; return 0;
} }
// ================================================ CONTEXT ================================================== // // ================================================ CONTEXT ================================================== //
void print_context_left(const char* left, const char* _) {
char buf[BUFLEN];
strcpy(buf, left);
int j = 0, len = (int)strlen(buf) - 1;
for (j = 0; j <= 52 - len ; ++j) { buf[len + j] = ' '; }
printf("%s %s\n", "*", buf);
}
void print_context_right(const char* right, const char* _) {
char buf[BUFLEN];
strcpy(buf, right);
int j = 0, len = (int)strlen(buf) - 1;
for (j = 0; j <= 52 - len ; ++j) {
buf[len + j] = ' ';
}
printf("%s %s\n", "-", buf);
}
void line_check_context(const char* left, const char* right) {
if (strcmp(left, right) == 0);
else { printf("! %s---\n! %s", left, right); }
}
int line_number_context(const char* left, const char* right) {
// This does nothing and probably will stay that way. Sadly... Sorry. :/
return 0;
}
// ================================================ UNIFIED ================================================== //
void print_unified_left(const char* left, const char* _) {
char buf[BUFLEN];
strcpy(buf, left);
int j = 0, len = (int)strlen(buf) - 1;
for (j = 0; j <= 52 - len ; ++j) { buf[len + j] = ' '; }
printf("%s %s\n", "<", buf);
}
void print_unified_right(const char* right, const char* _) {
char buf[BUFLEN];
strcpy(buf, right);
int j = 0, len = (int)strlen(buf) - 1;
for (j = 0; j <= 52 - len ; ++j) {
buf[len + j] = ' ';
}
printf("%s %s\n", ">", buf);
}
void line_check_unified(const char* left, const char* right) {
if (strcmp(left, right) == 0);
else { printf("< %s---\n> %s", left, right); }
}
int line_number_unified(const char* left, const char* right) {
// This does nothing and probably will stay that way. Sadly... Sorry. :/
return 0;
}

48
pa.h
View File

@ -7,7 +7,7 @@
#define MAXSTRINGS 1024 #define MAXSTRINGS 1024
#define BUFLEN 256 #define BUFLEN 256
// ================================================== // // ======================= STRUCT =========================== //
typedef struct pa pa; typedef struct pa pa;
struct pa { struct pa {
@ -15,12 +15,16 @@ struct pa {
int filesize; int filesize;
int start; int start;
int stop; int stop;
char* firstline; // DEBUG only char* firstline;
char* secondline; char* secondline;
}; };
// ======================== FILE STRUCTURE ========================== //
FILE* openfile(const char* filename, const char* openflags); FILE* openfile(const char* filename, const char* openflags);
// ======================== PARAGRAPH ========================== //
pa* p; pa* p;
pa* q; pa* q;
@ -35,27 +39,47 @@ char** pa_base(pa* p);
char* pa_info(pa* p); char* pa_info(pa* p);
int pa_equal(pa* p, pa* q); int pa_equal(pa* p, pa* q);
void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol); // ======================== PRINT STRUCTURE ========================== //
void print_check(pa* p, pa* q, void (*fp)(const char*, const char*)); void print_check (pa* p, pa* q, void (*fp)(const char*, const char*));
void print_first (pa* p, void (*fp)(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 print_second(pa* p, pa* q, void (*fp)(const char*, const char*));
void print_left_paren (const char* left, const char* right); // ================================== SIDE-BY-SIDE ================================== //
void print_no_common (const char* left, const char* right);
void print_side_normal(const char* left, const char* right);
void print_left (const char* left, const char*); void print_side_left (const char* left, const char*);
void print_right(const char* right, const char*); void print_side_right(const char* right, const char*);
void print_both (const char* left_right, const char*); void print_side_both (const char* left_right, const char*);
void print_left_paren (const char* left, const char* right);
void print_no_common (const char* left, const char* right);
void print_side_default(const char* left, const char* right);
void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol);
// ================================== NORMAL ================================== //
void print_normal_left (const char* left, const char*); void print_normal_left (const char* left, const char*);
void print_normal_right(const char* right, const char*); void print_normal_right(const char* right, const char*);
void print_normal_both (const char* left, const char* right, const char*); void print_normal_both (const char* left, const char* right, const char*);
void line_check(const char* right, const char*); void line_check_normal (const char* right, const char*);
int line_number(const char* left, const char* right); int line_number_normal(const char* left, const char* right);
// ================================== CONTEXT ================================== //
void print_context_left (const char* left, const char*);
void print_context_right(const char* right, const char*);
void line_check_context (const char* left, const char* right);
int line_number_context(const char* left, const char* right);
// ================================= UNIFIED ================================== //
void print_unified_left (const char* left, const char*);
void print_unified_right(const char* right, const char*);
void line_check_unified (const char* left, const char* right);
int line_number_unified(const char* left, const char* right);
#endif #endif