aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/patch.c11
-rw-r--r--editors/sed.c11
2 files changed, 12 insertions, 10 deletions
diff --git a/editors/patch.c b/editors/patch.c
index cb25e4140..988021d77 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -372,10 +372,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
372 xmove_fd(xopen_stdin(argv[1]), STDIN_FILENO); 372 xmove_fd(xopen_stdin(argv[1]), STDIN_FILENO);
373 } 373 }
374 } 374 }
375 if (argv[0]) {
376 oldname = xstrdup(argv[0]);
377 newname = xstrdup(argv[0]);
378 }
379 375
380 // Loop through the lines in the patch 376 // Loop through the lines in the patch
381 for(;;) { 377 for(;;) {
@@ -486,10 +482,10 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
486 // or if new hunk is empty (zero context) after patching 482 // or if new hunk is empty (zero context) after patching
487 if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) { 483 if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) {
488 name = reverse ? newname : oldname; 484 name = reverse ? newname : oldname;
489 empty++; 485 empty = 1;
490 } 486 }
491 487
492 // handle -p path truncation. 488 // Handle -p path truncation.
493 for (i = 0, s = name; *s;) { 489 for (i = 0, s = name; *s;) {
494 if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i) 490 if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i)
495 break; 491 break;
@@ -500,6 +496,9 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
500 i++; 496 i++;
501 name = s; 497 name = s;
502 } 498 }
499 // If "patch FILE_TO_PATCH", completely ignore name from patch
500 if (argv[0])
501 name = argv[0];
503 502
504 if (empty) { 503 if (empty) {
505 // File is empty after the patches have been applied 504 // File is empty after the patches have been applied
diff --git a/editors/sed.c b/editors/sed.c
index a8c35388b..4c7f75521 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -113,7 +113,7 @@ typedef struct sed_cmd_s {
113 int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */ 113 int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */
114 int end_line_orig; 114 int end_line_orig;
115 115
116 FILE *sw_file; /* File (sw) command writes to, -1 for none. */ 116 FILE *sw_file; /* File (sw) command writes to, NULL for none. */
117 char *string; /* Data string for (saicytb) commands. */ 117 char *string; /* Data string for (saicytb) commands. */
118 118
119 unsigned which_match; /* (s) Which match to replace (0 for all) */ 119 unsigned which_match; /* (s) Which match to replace (0 for all) */
@@ -179,7 +179,7 @@ static void sed_free_and_close_stuff(void)
179 sed_cmd_t *sed_cmd_next = sed_cmd->next; 179 sed_cmd_t *sed_cmd_next = sed_cmd->next;
180 180
181 if (sed_cmd->sw_file) 181 if (sed_cmd->sw_file)
182 xprint_and_close_file(sed_cmd->sw_file); 182 fclose(sed_cmd->sw_file);
183 183
184 if (sed_cmd->beg_match) { 184 if (sed_cmd->beg_match) {
185 regfree(sed_cmd->beg_match); 185 regfree(sed_cmd->beg_match);
@@ -426,8 +426,11 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
426 /* Write to file */ 426 /* Write to file */
427 case 'w': 427 case 'w':
428 { 428 {
429 char *temp; 429 char *fname;
430 idx += parse_file_cmd(/*sed_cmd,*/ substr+idx, &temp); 430 idx += parse_file_cmd(/*sed_cmd,*/ substr+idx+1, &fname);
431 sed_cmd->sw_file = xfopen_for_write(fname);
432 sed_cmd->sw_last_char = '\n';
433 free(fname);
431 break; 434 break;
432 } 435 }
433 /* Ignore case (gnu exension) */ 436 /* Ignore case (gnu exension) */