aboutsummaryrefslogtreecommitdiff
path: root/editors/patch.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--editors/patch.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/editors/patch.c b/editors/patch.c
index 8837d1751..ee0ccd384 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -57,9 +57,7 @@ struct double_list {
57 struct double_list *next; 57 struct double_list *next;
58 struct double_list *prev; 58 struct double_list *prev;
59 char *data; 59 char *data;
60#if ENABLE_PLATFORM_MINGW32
61 int no_newline; 60 int no_newline;
62#endif
63}; 61};
64 62
65// Free all the elements of a linked list 63// Free all the elements of a linked list
@@ -79,11 +77,7 @@ static void dlist_free(struct double_list *list, void (*freeit)(void *data))
79static struct double_list *dlist_add(struct double_list **list, char *data) 77static struct double_list *dlist_add(struct double_list **list, char *data)
80{ 78{
81 struct double_list *llist; 79 struct double_list *llist;
82#if ENABLE_PLATFORM_MINGW32
83 struct double_list *line = xzalloc(sizeof(*line)); 80 struct double_list *line = xzalloc(sizeof(*line));
84#else
85 struct double_list *line = xmalloc(sizeof(*line));
86#endif
87 81
88 line->data = data; 82 line->data = data;
89 llist = *list; 83 llist = *list;
@@ -147,10 +141,8 @@ static void do_line(void *data)
147 141
148 if (TT.state > 1 && *dlist->data != TT.state) 142 if (TT.state > 1 && *dlist->data != TT.state)
149 fdprintf(TT.state == 2 ? 2 : TT.fileout, 143 fdprintf(TT.state == 2 ? 2 : TT.fileout,
150#if ENABLE_PLATFORM_MINGW32 144 dlist->no_newline && TT.state != 2 ? "%s" : "%s\n",
151 dlist->no_newline && TT.state != 2 ? "%s" : 145 dlist->data + (TT.state > 3 ? 1 : 0));
152#endif
153 "%s\n", dlist->data + (TT.state > 3 ? 1 : 0));
154 146
155 if (PATCH_DEBUG) fdprintf(2, "DO %d: %s\n", TT.state, dlist->data); 147 if (PATCH_DEBUG) fdprintf(2, "DO %d: %s\n", TT.state, dlist->data);
156 148
@@ -443,7 +435,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
443 435
444 // Are we assembling a hunk? 436 // Are we assembling a hunk?
445 if (state >= 2) { 437 if (state >= 2) {
446#if ENABLE_PLATFORM_MINGW32
447 switch (*patchline) { 438 switch (*patchline) {
448 case '\\': 439 case '\\':
449 // '\ No newline at end of file' detected, mark 440 // '\ No newline at end of file' detected, mark
@@ -455,9 +446,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
455 case ' ': 446 case ' ':
456 case '+': 447 case '+':
457 case '-': 448 case '-':
458#else
459 if (*patchline == ' ' || *patchline == '+' || *patchline == '-') {
460#endif
461 dlist_add(&TT.current_hunk, patchline); 449 dlist_add(&TT.current_hunk, patchline);
462 450
463 if (*patchline != '+') oldlen--; 451 if (*patchline != '+') oldlen--;
@@ -469,9 +457,9 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
469 457
470 // If we've consumed all expected hunk lines, apply the hunk. 458 // If we've consumed all expected hunk lines, apply the hunk.
471 459
472#if ENABLE_PLATFORM_MINGW32
473 if (!oldlen && !newlen) { 460 if (!oldlen && !newlen) {
474 // Peek ahead for '\ No newline at end of file' 461 // Peek ahead for '\ No newline at end of file', mark
462 // previous line, if it exists.
475 int c = getchar(); 463 int c = getchar();
476 ungetc(c, stdin); 464 ungetc(c, stdin);
477 if (c == '\\') { 465 if (c == '\\') {
@@ -483,9 +471,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
483 } 471 }
484 state = apply_one_hunk(); 472 state = apply_one_hunk();
485 } 473 }
486#else
487 if (!oldlen && !newlen) state = apply_one_hunk();
488#endif
489 continue; 474 continue;
490 } 475 }
491 fail_hunk(); 476 fail_hunk();