From c2e8a3dd4ad01a8be61740efb587ca83ceb585ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 30 Dec 2016 17:06:14 +0100 Subject: 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. --- sam.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'sam.c') diff --git a/sam.c b/sam.c index b4d8a5f..6592229 100644 --- a/sam.c +++ b/sam.c @@ -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) { -- cgit v1.2.3