sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 572558ba046784005e5b5bfc8bbb17ed0444caec
родитељ 51906139b152f202a7929647fd40f8310b5cdb35
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Fri, 17 Oct 2025 07:44:10 +0200

sled.c(handle_key_event): Get callback logic in order; (save_file): Synchronize logic with handle_key_event

Diffstat:
MTODO | 4++++
Msled.c | 37++++++++++++++++++++++++++++---------
измењених датотека: 2, додавања: 32(+), брисања: 9(-)

diff --git a/TODO b/TODO @@ -3,6 +3,10 @@ TODO [~] Code optimization (struct coord...) +[ ] Hypothetical: editing a symlink to a file which gets deleted mid-editing, + then a save is attempted. Bail out (current behavior)? + - What if a file was on a USB flash which was pulled out? + [ ] Investigate: typing text (at the end of a line) sometimes erases text at the end of one of the previous lines in the same paragraph?! diff --git a/sled.c b/sled.c @@ -734,9 +734,11 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) && (current->ev.key == ev->key) && !ev->ch) || (current->ev.ch && (current->ev.ch == ev->ch))) - if (current->callback - && !current->callback(state)) + if (current->callback) + { + current->callback(state); return; + } } if (ev->ch) { @@ -756,8 +758,11 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) if (((current->ev.mod == ev->mod) && (current->ev.key == ev->key) && !ev->ch) || (current->ev.ch && (current->ev.ch == ev->ch))) - if (current->callback && !current->callback(state)) + if (current->callback) + { + current->callback(state); return; + } } if (IN(state->mode, M_HELP)) @@ -773,8 +778,11 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) if (((current->ev.mod == ev->mod) && (current->ev.key == ev->key) && !ev->ch) || (current->ev.ch && (current->ev.ch == ev->ch))) - if (current->callback && !current->callback(state)) + if (current->callback) + { + current->callback(state); return; + } } if (IN(state->mode, M_COMMAND)) @@ -787,9 +795,11 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) && (current->ev.key == ev->key) && !ev->ch) || (current->ev.ch && (current->ev.ch == ev->ch))) - if (current->callback - && !current->callback(state)) + if (current->callback) + { + current->callback(state); return; + } } } else @@ -801,9 +811,11 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) && (current->ev.key == ev->key) && !ev->ch) || (current->ev.ch && (current->ev.ch == ev->ch))) - if (current->callback - && !current->callback(state)) + if (current->callback) + { + current->callback(state); return; + } } if (ev->ch) { @@ -2012,6 +2024,7 @@ save_file(struct DrawState* state) char* buf = NULL; char* pbuf = NULL; ssize_t bufsize = LINE_DEFAULT; + int result = 0; assert(state != NULL); if (!(buf = calloc(bufsize, 1))) @@ -2030,6 +2043,7 @@ save_file(struct DrawState* state) if ((unlink(state->backup_filename) < 0) && (errno != ENOENT)) { state->error = ERR_ERRNO_SET; + result = 1; goto save_file_cleanup; } if (cp(state->rfn_len > 0 ? state->real_filename : state->filename, @@ -2038,6 +2052,7 @@ save_file(struct DrawState* state) if (backup_fail) { state->error = ERR_ERRNO_SET; + result = 1; goto save_file_cleanup; } else @@ -2050,6 +2065,7 @@ save_skip_backup_copy: "w"))) { state->error = ERR_ERRNO_SET; + result = 1; goto save_file_cleanup; } @@ -2061,6 +2077,7 @@ save_skip_backup_copy: < 0) { state->error = ERR_ERRNO_SET; + result = 1; goto save_file_cleanup; } @@ -2072,11 +2089,13 @@ save_skip_backup_copy: if (unlink(state->filename) == -1) { state->error = ERR_ERRNO_SET; + result = 1; goto save_file_cleanup; } if (symlink(state->orig_real_filename, state->filename) == -1) { state->error = ERR_ERRNO_SET; + result = 1; goto save_file_cleanup; } } @@ -2111,7 +2130,7 @@ save_file_cleanup: fclose(output); free(buf); state->action = ACT_IDLE; - return state->error; + return result; } static int