diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..5008ddf
Binary files /dev/null and b/.DS_Store differ
diff --git a/diff-rcm b/diff-rcm
index 6c03fc5..acf8d83 100755
Binary files a/diff-rcm and b/diff-rcm differ
diff --git a/diff-rcm.dSYM/Contents/Info.plist b/diff-rcm.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..f39ac94
--- /dev/null
+++ b/diff-rcm.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ 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
new file mode 100644
index 0000000..b49374b
Binary files /dev/null and b/diff-rcm.dSYM/Contents/Resources/DWARF/diff-rcm differ
diff --git a/diff.c b/diff.c
index bb8532d..aa243d4 100644
--- a/diff.c
+++ b/diff.c
@@ -12,7 +12,7 @@ int main(int argc, const char* argv[]) {
init(--argc, ++argv);
loadfiles(files[0], files[1]);
- if (**argv != '-') { normal(files[0], files[1]); }
+ if (**argv != '-' || diffnormal == 1) { standard(files[0], files[1]); }
if (showsidebyside) { sideside(files[0], files[1]); }
if (showbrief) { quiet(files[0], files[1]); }
@@ -39,7 +39,7 @@ void init(int argc, const char* argv[]) {
setoption(arg, "--suppress-common-lines", NULL, &suppresscommon);
setoption(arg, "-c", "--context", &showcontext);
setoption(arg, "-u", "showunified", &showunified);
- setoption(arg, "-h", "--help", &showhelp);
+ setoption(arg, "--help", NULL, &showhelp);
if (arg[0] != '-') {
if (cnt == 2) {
@@ -70,8 +70,8 @@ void setoption(const char* arg, const char* s, const char* t, int* value) {
}
void diff_output_conflict_error(void) {
- fprintf(stderr, "diff: conflicting output style options\n");
- fprintf(stderr, "diff: Try `diff --help' for more information.)\n");
+ fprintf(stderr, "diff-rcm: Conflicting output style options.\n");
+ fprintf(stderr, "diff-rcm: Try `diff --help' for more information.)\n");
exit(CONFLICTING_OUTPUT_OPTIONS);
}
@@ -114,7 +114,7 @@ void help() {
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 --normal\t\t output a normal diff (the default)\n");
+ printf("\t --standard\t\t output a standard 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");
@@ -132,54 +132,61 @@ void help() {
printf("diff-rcm homepage: \n\n");
}
-int normal(const char* filename1, const char* filename2) {
+int standard(const char* filename1, const char* filename2) {
identical(filename1, filename2);
- printf("\nTHIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n");
- printf("THIS IS NOT NORMAL FOR NOW. THIS IS PLACEHOLDER. MMKAY.\n");
- 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");
+ 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_print(p, printnormal);
+ //pa* qlast = q;
return 0;
}
+
int sideside(const char* filename1, const char* filename2) {
-
- 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) {
- pa_print(q, printright);
- q = pa_next(q);
+
+ pa* qlast = q;
+
+ while(p != NULL) {
+
qlast = q;
- }
- pa_print(q, printboth);
- p = pa_next(p);
- q = pa_next(q);
- } else {
- pa_print(p, printleft);
- p = pa_next(p);
+ 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) {
+ pa_print(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); }
+
+ p = pa_next(p);
+ q = pa_next(q);
+ }
+
+ else { pa_print(p, NULL, printleft); p = pa_next(p); }
}
- }
- while (q != NULL) {
- pa_print(q, printright);
- q = pa_next(q);
- }
-
- return 0;
+
+ while(q != NULL) { pa_print(q, NULL, printright); q = pa_next(q); }
+
+ return 0;
+
}
+
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 (*filename1 == *filename2 || (pa_equal(p, q) != 0)) { printf("The files are identical.\n"); }
- else { normal(files[0], files[1]); }
+ else { standard(files[0], files[1]); }
}
diff --git a/diff.h b/diff.h
index a7d79be..d6e7b7d 100644
--- a/diff.h
+++ b/diff.h
@@ -49,7 +49,7 @@ void loadfiles(const char* filename1, const char* filename2);
void version();
void help();
-int normal(const char* filename1, const char* filename2);
+int standard(const char* filename1, const char* filename2);
int sideside(const char* filename1, const char* filename2);
void quiet(const char* filename1, const char* filename2);
void loud(const char* filename1, const char* filename2);
diff --git a/left.txt b/left.txt
deleted file mode 100644
index bbae935..0000000
--- a/left.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-This part of the
-document has stayed the
-sme from version to
-version. It shouldn't
-be shown if it doesn't
-change. Otherwise, that
-would not be helping to
-compress the size of the
-changes.
-
-This paragraph contains
-text that is outdated.
-It will be deleted in the
-near future.
-
-It is important to spell
-check this dokument. On
-the other hand, a
-misspelled word isn't
-the end of the world.
-Nothing in the rest of
-this paragraph needs to
-be changed. Things can
-be added after it.
-
diff --git a/pa.c b/pa.c
index 18f947f..2eb2490 100644
--- a/pa.c
+++ b/pa.c
@@ -7,108 +7,152 @@
// ======================================================================= //
pa* pa_make(char* base[], int filesize, int start, int stop) {
- pa* p = (pa*) malloc(sizeof(pa));
- p->base = base;
- p->filesize = filesize;
- p->start = start;
- p->stop = stop;
- p->firstline = (p == NULL || start < 0) ? NULL : p->base[start];
- p->secondline = (p == NULL || start < 0 || filesize < 2) ? NULL : p->base[start + 1];
+
+ pa* p = (pa*)malloc(sizeof(pa));
+
+ p->base = base;
+ p->filesize = filesize;
+ p->start = start;
+ p->stop = stop;
+ p->firstline = (p == NULL || start < 0) ? NULL : p->base[start];
+ p->secondline = (p == NULL || start < 0 || filesize < 2) ? NULL : p->base[start + 1];
+
+ return p;
+
+}
- return p;
+pa* pa_next(pa* p) {
+
+ int i;
+
+ if (p->stop == p->filesize) { return NULL; }
+ pa* pnew = pa_make(p->base, p->filesize, p->stop + 1, p->stop + 1);
+
+ for (i = pnew->start; i < p->filesize && strcmp(p->base[i], "\n") != 0; ++i);
+ pnew->stop = i;
+ if (pnew->start >= p->filesize) { free(pnew); pnew = NULL; }
+
+ return pnew;
+
}
pa* pa_first(char* base[], int size) {
- pa* p = pa_make(base, size, 0, -1);
- return pa_next(p);
+
+ pa* p = pa_make(base, size, 0, -1);
+ return pa_next(p);
+
}
-void pa_destroy(pa* p) { free(p); }
+void pa_destroy(pa* p) { free(p); }
-pa* pa_next(pa* p) {
- if (p == NULL || p->stop == p->filesize) { return NULL; }
-
- int i;
- pa* pnew = pa_make(p->base, p->filesize, p->stop + 1, p->stop + 1);
- for (i = pnew->start; i < p->filesize && strcmp(p->base[i], "\n") != 0; ++i) { }
- pnew->stop = i;
-
- if (pnew->start >= p->filesize) {
- free(pnew);
- pnew = NULL;
- }
- return pnew;
-}
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; }
-
-char** pa_base(pa* p) { return p->base; }
+size_t pa_size(pa* p) { return p == NULL || p->stop < p->start ? 0 : p->stop - p->start + 1; }
+char** pa_base(pa* p) { return p->base; }
char* pa_info(pa* p) {
- static char buf[BUFLEN]; // static for a reason
- snprintf(buf, sizeof(buf), "base: %p, filesize: %d, start: %d, stop: %d\n",
- p->base, p->filesize, p->start, p->stop);
- return buf; // buf MUST be static
+
+ static char buf[BUFLEN];
+ snprintf(buf, sizeof(buf), "base: %p, filesize: %d, start: %d, stop: %d\n", p->base, p->filesize, p->start, p->stop);
+ return buf;
+
}
int pa_equal(pa* p, pa* q) {
- 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; }
- int i = p->start, j = q->start, equal = 0;
- while ((equal = strcmp(p->base[i], q->base[i])) == 0) { ++i; ++j; }
- return 1;
+
+ 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; }
+
+ int i = p->start, j = q->start, equal = 0;
+ while ((equal = strcmp(p->base[i], q->base[i])) == 0) { ++i; ++j; }
+
+ return 1;
+
}
-void pa_print(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 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("%-61s %c ", buf, symbol);
+ if (symbol == '|') { printf("%s", right); }
+ else { printf("%s", (leftparen ? "\n" : right)); }
+
}
-void pa_printfile(char* base[], int count, void (*fp)(const char*)) {
- pa* p = pa_first(base, count);
- while (p != NULL) {
- pa_print(p, fp);
- p = pa_next(p);
- }
- printline();
+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]); }
+
}
-char* yesorno(int condition) { return condition == 0 ? "no" : "YES"; }
+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); }
+
+}
+
+void printleftparen(const char* left, const char* right) { sideside_type(left, right, 1, 0, ' '); }
+void printnocommon(const char* left, const char* right) { sideside_type(left, right, 0, 1, '('); }
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;
+
+ FILE* f;
+ if ((f = fopen(filename, openflags)) == NULL) { printf("can't open '%s'\n", filename); exit(1); }
+ return f;
+
}
-void printline(void) {
- for (int i = 0; i < 10; ++i) { printf("=========="); }
- printf("\n");
+void printleft(const char* left, const char* n) {
+
+ 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 printleft(const char* left) {
- 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 printright(const char* right, const char* n) {
+
+ if (right == NULL) { return; }
+ printf("%50s %s", ">", right);
+
}
-void printright(const char* right) {
- if (right == NULL) { return; }
- printf("%50s %s", ">", right);
-}
-
-void printboth(const char* left_right) {
- 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 printboth(const char* left_right, const char* n) {
+
+ 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);
+
}
diff --git a/pa.h b/pa.h
index 647d092..f7a03f8 100644
--- a/pa.h
+++ b/pa.h
@@ -23,18 +23,24 @@ pa* q;
pa* pa_make(char* base[], int size, int start, int stop);
pa* pa_first(char* base[], int size);
pa* pa_next(pa* p);
+void pa_destroy(pa* p);
size_t pa_filesize(pa* p);
size_t pa_size(pa* p);
char** pa_base(pa* p);
char* pa_info(pa* p);
-int pa_equal(pa* p, pa* q);
-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 pa_printfile(char* base[], int count, void (*fp)(const char*));
-FILE* openfile(const char* filename, const char* openflags);
+int pa_equal(pa* p, pa* q);
+void sideside_type(const char* left, const char* right, int nocommon, int leftparen, char symbol);
+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);
-void printline(void);
+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);
#endif
diff --git a/right.txt b/right.txt
deleted file mode 100644
index 2d7f33d..0000000
--- a/right.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-This is an important
-notice! It should
-therefore be located at
-the beginning of this
-document!
-
-This part of the
-document has stayed the
-sme from version to
-version. It shouldn't
-be shown if it doesn't
-change. Otherwise, that
-would not be helping to
-compress the size of the
-changes.
-
-It is important to spell
-check this document. On
-the other hand, a
-misspelled word isn't
-the end of the world.
-Nothing in the rest of
-this paragraph needs to
-be changed. Things can
-be added after it.
-
-This pragraph contains
-important new additions
-to this document.
-
-