vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit bc940b0d873d24e26526715e8f71a39030371477 parent aca4eb69c9b7720889ee3f885c9f93d61cbb0e2b Author: Marc André Tanner <mat@brain-dump.org> Date: Sat, 8 Aug 2015 10:41:34 +0200 text: rename some functions to improve consistency Diffstat:
| M | text.c | | | 14 | +++++++------- |
| M | text.h | | | 4 | ++-- |
| M | vis.c | | | 8 | ++++---- |
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/text.c b/text.c @@ -795,7 +795,7 @@ static bool preserve_selinux_context(int src, int dest) { * - POSXI ACL can not be preserved (if enabled) * - SELinux security context can not be preserved (if enabled) */ -static bool text_range_save_atomic(Text *txt, Filerange *range, const char *filename) { +static bool text_save_atomic_range(Text *txt, Filerange *range, const char *filename) { struct stat meta = { 0 }, oldmeta = { 0 }; int fd = -1, oldfd = -1, saved_errno; char *tmpname = NULL; @@ -895,17 +895,17 @@ err: bool text_save(Text *txt, const char *filename) { Filerange r = (Filerange){ .start = 0, .end = text_size(txt) }; - return text_range_save(txt, &r, filename); + return text_save_range(txt, &r, filename); } /* First try to save the file atomically using rename(2) if this does not * work overwrite the file in place. However if something goes wrong during * this overwrite the original file is permanently damaged. */ -bool text_range_save(Text *txt, Filerange *range, const char *filename) { +bool text_save_range(Text *txt, Filerange *range, const char *filename) { struct stat meta; int fd = -1, newfd = -1; - if (!filename || text_range_save_atomic(txt, range, filename)) + if (!filename || text_save_atomic_range(txt, range, filename)) goto ok; if ((fd = open(filename, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR)) == -1) goto err; @@ -951,7 +951,7 @@ bool text_range_save(Text *txt, Filerange *range, const char *filename) { * here we are screwed, TODO: make a backup before? */ if (ftruncate(fd, 0) == -1) goto err; - ssize_t written = text_range_write(txt, range, fd); + ssize_t written = text_write_range(txt, range, fd); if (written == -1 || (size_t)written != text_range_size(range)) goto err; @@ -974,10 +974,10 @@ err: ssize_t text_write(Text *txt, int fd) { Filerange r = (Filerange){ .start = 0, .end = text_size(txt) }; - return text_range_write(txt, &r, fd); + return text_write_range(txt, &r, fd); } -ssize_t text_range_write(Text *txt, Filerange *range, int fd) { +ssize_t text_write_range(Text *txt, Filerange *range, int fd) { size_t size = text_range_size(range), rem = size; for (Iterator it = text_iterator_get(txt, range->start); rem > 0 && text_iterator_valid(&it); diff --git a/text.h b/text.h @@ -116,11 +116,11 @@ enum TextNewLine text_newline_type(Text*); * In which case an implicit snapshot is taken. The save might associate a * new inode to file. */ bool text_save(Text*, const char *filename); -bool text_range_save(Text*, Filerange*, const char *file); +bool text_save_range(Text*, Filerange*, const char *file); /* write the text content to the given file descriptor `fd'. Return the * number of bytes written or -1 in case there was an error. */ ssize_t text_write(Text*, int fd); -ssize_t text_range_write(Text*, Filerange*, int fd); +ssize_t text_write_range(Text*, Filerange*, int fd); /* release all ressources associated with this text instance */ void text_free(Text*); diff --git a/vis.c b/vis.c @@ -1936,13 +1936,13 @@ static bool cmd_write(Filerange *range, enum CmdOpt opt, const char *argv[]) { if (!argv[1]) { if (file->is_stdin) { if (strchr(argv[0], 'q')) { - ssize_t written = text_range_write(text, range, STDOUT_FILENO); + ssize_t written = text_write_range(text, range, STDOUT_FILENO); if (written == -1 || (size_t)written != text_range_size(range)) { editor_info_show(vis, "Can not write to stdout"); return false; } /* make sure the file is marked as saved i.e. not modified */ - text_range_save(text, range, NULL); + text_save_range(text, range, NULL); return true; } editor_info_show(vis, "No filename given, use 'wq' to write to stdout"); @@ -1958,7 +1958,7 @@ static bool cmd_write(Filerange *range, enum CmdOpt opt, const char *argv[]) { editor_info_show(vis, "WARNING: file has been changed since reading it"); return false; } - if (!text_range_save(text, range, *name)) { + if (!text_save_range(text, range, *name)) { editor_info_show(vis, "Can't write `%s'", *name); return false; } @@ -2110,7 +2110,7 @@ static bool cmd_filter(Filerange *range, enum CmdOpt opt, const char *argv[]) { Filerange junk = *range; if (junk.end > junk.start + PIPE_BUF) junk.end = junk.start + PIPE_BUF; - ssize_t len = text_range_write(text, &junk, pin[1]); + ssize_t len = text_write_range(text, &junk, pin[1]); if (len > 0) { range->start += len; if (text_range_size(range) == 0) {