diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-30 17:06:14 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-30 17:52:17 +0100 |
| commit | c2e8a3dd4ad01a8be61740efb587ca83ceb585ed (patch) | |
| tree | 0eea669f2f26b3a5276633cc67896cfc8384a168 /sam.c | |
| parent | efa32c506969184a054de7224b7d01f93004e9f7 (diff) | |
| download | vis-c2e8a3dd4ad01a8be61740efb587ca83ceb585ed.tar.gz vis-c2e8a3dd4ad01a8be61740efb587ca83ceb585ed.tar.xz | |
sam: change write command implementation to not change argv[]
The same Command struct might be used for multiple command executions.
An example is `:X wq` which is roughly equivalent to `:wqa` in vim.
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1292,10 +1292,10 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs return false; File *file = win->file; Text *text = file->text; - bool noname = !argv[1]; - if (!argv[1]) - argv[1] = file->name ? strdup(file->name) : NULL; - if (!argv[1]) { + const char *filename = argv[1]; + if (!filename) + filename = file->name; + if (!filename) { if (file->fd == -1) { vis_info_show(vis, "Filename expected"); return false; @@ -1330,7 +1330,7 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs return true; } - if (noname && cmd->flags != '!') { + if (!argv[1] && cmd->flags != '!') { if (vis->mode->visual) { vis_info_show(vis, "WARNING: file will be reduced to active selection"); return false; @@ -1342,7 +1342,7 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs } } - for (const char **name = &argv[1]; *name; name++) { + for (const char **name = argv[1] ? &argv[1] : (const char*[]){ filename, NULL }; *name; name++) { struct stat meta; if (cmd->flags != '!' && file->stat.st_mtime && stat(*name, &meta) == 0 && file->stat.st_mtime < meta.st_mtime) { |
