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 | da7ec2ff9c0b6150071c4252eb62d8dc21d0287a (patch) | |
tree | f562a566dc5265678aeab67c1800198917ee9e11 | |
parent | a2a05e3b288ca6231cfb9a7a49bb147380412a48 (diff) | |
download | txr-da7ec2ff9c0b6150071c4252eb62d8dc21d0287a.tar.gz txr-da7ec2ff9c0b6150071c4252eb62d8dc21d0287a.tar.bz2 txr-da7ec2ff9c0b6150071c4252eb62d8dc21d0287a.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.
-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); } } |