nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 1a28b08694ca4b0403bfaea5505677e8aafeec52
parent 3b3a6b12a7bb18a16b51cda5577919b60a6b4324
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 28 Feb 2020 12:34:28 +0100

tweaks: frob two statements, condense another, and add a comment

Also, remove two superfluous closings of file descriptors.  The second
one has most likely already been closed by send_data(), by closing the
tube, and the first one will be closed by exiting from the process.

Diffstat:
Msrc/text.c | 12++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -289,7 +289,7 @@ void handle_indent_action(undostruct *u, bool undoing, bool add_indent) goto_line_posx(u->head_lineno, u->head_x); /* For each line in the group, add or remove the individual indent. */ - while (line && line->lineno <= group->bottom_line) { + while (line != NULL && line->lineno <= group->bottom_line) { char *blanks = group->indentations[line->lineno - group->top_line]; if (undoing ^ add_indent) @@ -468,10 +468,7 @@ void handle_comment_action(undostruct *u, bool undoing, bool add_comment) /* Undo a cut, or redo a paste. */ void undo_cut(undostruct *u) { - if (u->xflags & WAS_WHOLE_LINE) - goto_line_posx(u->tail_lineno, 0); - else - goto_line_posx(u->tail_lineno, u->tail_x); + goto_line_posx(u->tail_lineno, (u->xflags & WAS_WHOLE_LINE) ? 0 : u->tail_x); copy_from_buffer(u->cutbuffer); @@ -910,7 +907,7 @@ void send_data(const linestruct *line, int fd) FILE *tube = fdopen(fd, "w"); if (tube == NULL) - return; + exit(4); /* Send each line, except a final empty line. */ while (line != NULL && (line->next != NULL || line->data[0] != '\0')) { @@ -1000,10 +997,9 @@ bool execute_command(const char *command) update_undo(CUT); } + /* Create a separate process for piping the data to the command. */ if (fork() == 0) { - close(to_fd[0]); send_data(cutbuffer != NULL ? cutbuffer : openfile->filetop, to_fd[1]); - close(to_fd[1]); exit(0); }