diff --git a/diff-rcm b/diff-rcm
deleted file mode 100755
index c5d3627..0000000
Binary files a/diff-rcm and /dev/null differ
diff --git a/diff-rcm.dSYM/Contents/Info.plist b/diff-rcm.dSYM/Contents/Info.plist
deleted file mode 100644
index f39ac94..0000000
--- a/diff-rcm.dSYM/Contents/Info.plist
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
- CFBundleDevelopmentRegion
- English
- CFBundleIdentifier
- com.apple.xcode.dsym.diff-rcm
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundlePackageType
- dSYM
- CFBundleSignature
- ????
- CFBundleShortVersionString
- 1.0
- CFBundleVersion
- 1
-
-
diff --git a/diff-rcm.dSYM/Contents/Resources/DWARF/diff-rcm b/diff-rcm.dSYM/Contents/Resources/DWARF/diff-rcm
deleted file mode 100644
index 37d61bb..0000000
Binary files a/diff-rcm.dSYM/Contents/Resources/DWARF/diff-rcm and /dev/null differ
diff --git a/diff.c b/diff.c
index 9fc934a..01b2d99 100644
--- a/diff.c
+++ b/diff.c
@@ -9,16 +9,23 @@
int main(int argc, const char* argv[]) {
- init(--argc, ++argv);
- loadfiles(files[0], files[1]);
+ init(--argc, ++argv);
+ loadfiles(files[0], files[1]);
- if (**argv != '-' || diffnormal == 1) { standard(); }
+ if (ignorecase) { ignore_case(); }
- if (showsidebyside) { sideside(); }
- if (showbrief) { quiet(files[0], files[1]); }
- if (report_identical) { loud(files[0], files[1]); }
+ if (report_identical) { loud (files[0], files[1]); }
+ if (showsidebyside) { sideside(files[0], files[1]); }
+ identical(files[0], files[1]); // -s and -y work for identical file names so I manipulated load order.
+
+ if (showbrief) { quiet(files[0], files[1]); }
+
+ if (**argv != '-' || diffnormal == 1) { lineline(); }
- return 0;
+ if (showcontext) { context(); }
+ if (showunified) { unified(); }
+
+ return 0;
}
@@ -52,22 +59,25 @@ 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(); }
}
void setoption(const char* arg, const char* s, const char* t, int* value) {
+
if ((strcmp(arg, s) == 0) || ((t != NULL && strcmp(arg, t) == 0))) { *value = 1; }
+
}
+
void diff_output_conflict_error(void) {
fprintf(stderr, "diff-rcm: Conflicting output style options.\n");
@@ -97,6 +107,8 @@ void loadfiles(const char* filename1, const char* filename2) {
}
+// ============================================================================= //
+
void version(void) {
printf("\n\n ██ ██ ████ ████ \n");
printf(" ░██░░ ░██░ ░██░ \n");
@@ -116,7 +128,7 @@ 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");
- printf("\t --standard\t\t output a standard diff (the default)\n");
+ printf("\t --lineline\t\t output a lineline diff (the default)\n");
printf("\t-q, --brief\t\t report only when files differ\n");
printf("\t-s, --report-identical-files report when two files are the same\n");
printf("\t-c, -C NUM, --context[=NUM] output NUM (default 3) lines of copied context\n");
@@ -126,68 +138,99 @@ void help(void) {
printf("\t --help\t\t display this help and exit\n");
printf("\t-v, --version\t\t output version information and exit\n\n");
- printf("FILES are 'FILE1 FILE2'\n");
- printf("If --from-file or --to-file is given, there are no restrictions on FILE(s).\n");
- printf("If a FILE is '-', read standard input.\n");
- printf("Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.\n\n");
printf("Report bugs to: cdnutter@gmail.com\n");
printf("diff-rcm homepage: \n\n");
}
-void standard(void) {
+// ============================================================================= //
+
+void ignore_case(void) {
+
}
-void sideside(void) {
+int identical(const char* filename1, const char* filename2) { if (*filename1 == *filename2) { exit(0); } else return 0; }
+
+// ============================================================================= //
+
+void lineline(void) {
- int foundmatch = 0;
+ int foundmatch = 0; pa* qlast = q;
- pa* qlast = q;
- while(p != NULL) {
+ while (p != NULL) {
+ qlast = q; foundmatch = 0;
+
+ while (q != NULL && (foundmatch = pa_equal(p, q)) == 0) { q = pa_next(q); }
+ q = qlast;
- qlast = q;
- foundmatch = 0;
+ if (foundmatch) {
+ while ((foundmatch = pa_equal(p, q)) == 0) {
+
+ print_check(q, NULL, print_normal_right);
+ q = pa_next(q);
+ qlast = q;
+ }
+ print_check(p, q, line_check);
+
+ p = pa_next(p);
+ q = pa_next(q);
+ }
+ else { print_check(p, NULL, print_normal_left); p = pa_next(p); }
+ }
+
+ while (q != NULL) { print_check(q, NULL, print_normal_right); q = pa_next(q); }
+
+}
+
+void sideside(const char* filename1, const char* filename2) {
+
+ int foundmatch = 0; pa* qlast = q;
+ if (*filename1 == *filename2) {
+ while (p != NULL && q != NULL) { print_check(p, q, print_both);
+ p = pa_next(p); }
+ return;
+ }
+
+ 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_right);
q = pa_next(q);
qlast = q;
-
}
- if (showleftcolumn) { print_check(p, q, print_left_paren); }
- else if (suppresscommon) { print_check(p, q, print_no_common); }
+ if (showleftcolumn) { print_check(p, q, print_left_paren); }
+ else if (suppresscommon) { print_check(p, q, print_no_common); }
else { print_check(p, q, print_side_normal); }
p = pa_next(p);
q = pa_next(q);
-
}
else { print_check(p, NULL, print_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_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); } }
-void loud(const char* filename1, const char* filename2) {
+void context(void) {}
+void unified(void) {}
+
+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) {
if (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("Files %s and %s are identical.\n", filename1, filename2); }
- else { standard(); }
+ else if (showsidebyside) { sideside(files[0], files[1]); exit(0); }
+ else if (showcontext) { context(); exit(0); }
+ else if (showunified) { unified(); exit(0); }
+ else { lineline(); exit(0); }
}
-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 df3cffd..148f113 100644
--- a/diff.h
+++ b/diff.h
@@ -18,7 +18,7 @@
TODO: check line by line in a pagraph, using '|' for differences");
TODO: this starter code does not yet handle printing all of fin1's pagraphs.");
TODO: handle the rest of diff's options");
- TODO: fix standard printing with no pameters");
+ TODO: fix lineline printing with no pameters");
TODO: implement multiple types of pameters\n");
*/
@@ -49,8 +49,13 @@ void loadfiles(const char* filename1, const char* filename2);
void version(void);
void help(void);
-void standard(void);
-void sideside(void);
+void ignore_case(void);
+
+void lineline(void);
+void sideside(const char* filename1, const char* filename2);
+void context (void);
+void unified (void);
+
void quiet(const char* filename1, const char* filename2);
void loud(const char* filename1, const char* filename2);
diff --git a/pa.c b/pa.c
index cae845d..a05563d 100644
--- a/pa.c
+++ b/pa.c
@@ -4,7 +4,17 @@
#include "pa.h"
-// ======================================================================= //
+// ============================================================================================================= //
+
+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;
+
+}
+
+// ============================================================================================================= //
pa* pa_make(char* base[], int filesize, int start, int stop) {
@@ -70,7 +80,7 @@ int pa_equal(pa* p, pa* q) {
}
-// ======================================================================================================= //
+// ============================================================================================================= //
void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol) {
@@ -90,21 +100,13 @@ void sideside_type(const char* left, const char* right, int nocommon, int leftpa
}
-// ======================================================================================================= //
+// ============================================== 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, ' '); }
-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 print_left(const char* left, const char* n) {
+void print_left(const char* left, const char* _) {
char buf[BUFLEN];
strcpy(buf, left);
@@ -162,3 +164,49 @@ void print_second(pa* p, pa* q, void (*fp)(const char*, const char*)) {
}
}
+
+// ================================================ NORMAL ================================================== //
+
+
+void print_normal_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_normal_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(const char* left, const char* right) {
+
+ if (strcmp(left, right) == 0);
+ else { printf("< %s---\n> %s", left, right); }
+
+}
+
+int line_number(const char* left, const char* right) {
+
+ return 0;
+
+}
+
+// ================================================ CONTEXT ================================================== //
+
diff --git a/pa.h b/pa.h
index e0f4fc6..907aafa 100644
--- a/pa.h
+++ b/pa.h
@@ -39,16 +39,23 @@ void sideside_type(const char* left, const char* right, int nocommon, int leftpa
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_left_paren(const char* left, const char* right);
-void print_no_common(const char* left, const char* right);
+void print_left_paren (const char* left, const char* right);
+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_left (const char* left, const char*);
void print_right(const char* right, const char*);
-void print_both(const char* left_right, const char*);
+void print_both (const char* left_right, const char*);
+
+void print_normal_left (const char* left, const char*);
+void print_normal_right(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*);
+int line_number(const char* left, const char* right);
#endif