diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-02-15 07:58:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-02-15 07:58:46 -0800 |
commit | fd7012085f0fcd2ccf6e33be3e295b2a29dbd9d2 (patch) | |
tree | f562a566dc5265678aeab67c1800198917ee9e11 /linenoise | |
parent | b76c5760919b33fe15d9350a23ccaebcc905397c (diff) | |
download | txr-fd7012085f0fcd2ccf6e33be3e295b2a29dbd9d2.tar.gz txr-fd7012085f0fcd2ccf6e33be3e295b2a29dbd9d2.tar.bz2 txr-fd7012085f0fcd2ccf6e33be3e295b2a29dbd9d2.zip |
linenoise: preserve too-large-to-read file.
* linenoise.c (edit_in_editor): If we can't read the file,
then preserve the file, and replace the command line buffer
with an error message in which the name of that file appears.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 7e22d21f..4caeb35d 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1937,6 +1937,7 @@ static void edit_in_editor(lino_t *l) { if (fo) { char cmd[256]; snprintf(cmd, sizeof cmd, "%s %s", ed, path); + int preserve = 0; tr(l->data, '\r', '\n'); if (lino_os.puts_fn(fo, l->data) && lino_os.puts_fn(fo, L"\n")) @@ -1953,7 +1954,13 @@ static void edit_in_editor(lino_t *l) { record_undo(l); - l->data[len] = 0; + if (len == nelem(l->data) - 1) { + wcsnprintf(l->data, nelem(l->data), + L"%s: too large to read, preserved.", + path); + preserve = 1; + len = wcslen(l->data); + } if (len > 0 && l->data[len - 1] == '\n') l->data[--len] = 0; l->dpos = l->dlen = len; @@ -1966,7 +1973,9 @@ static void edit_in_editor(lino_t *l) { if (fo != 0) lino_os.close_fn(fo); - remove(path); + if (!preserve) + remove(path); + clear_sel(l); } } |