diff options
author | Michael Vetter <jubalh@iodoru.org> | 2021-03-12 10:29:06 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2021-03-12 10:29:06 +0100 |
commit | cb0adae63ab746472d7debc23456500256b51838 (patch) | |
tree | 5862a7a7c5087312f28f199a9997f153b9c9058d /src/command | |
parent | 537b14da508eb475f1f786590cc1001d962a5c01 (diff) | |
download | profani-tty-cb0adae63ab746472d7debc23456500256b51838.tar.gz |
Dont build paths manually in cmd_funcs.c
Some time ago we introduced get_expanded_path(). No need to build paths manually anymore to get ~.
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_funcs.c | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 77422dc6..6faa64b8 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1117,20 +1117,11 @@ cmd_export(ProfWin* window, const char* const command, gchar** args) cons_show(""); return TRUE; } else { - GString* fname = g_string_new(""); - GSList* list = NULL; int fd; + GSList* list = NULL; + char* path = get_expanded_path(args[0]); - /* deal with the ~ convention for $HOME */ - if (args[0][0] == '~') { - fname = g_string_append(fname, getenv("HOME")); - fname = g_string_append(fname, args[0] + 1); - } else { - fname = g_string_append(fname, args[0]); - } - - fd = open(fname->str, O_WRONLY | O_CREAT, 00600); - g_string_free(fname, TRUE); + fd = open(path, O_WRONLY | O_CREAT, 00600); if (-1 == fd) { cons_show("error: cannot open %s: %s", args[0], strerror(errno)); @@ -6863,20 +6854,12 @@ cmd_plugins_sourcepath(ProfWin* window, const char* const command, gchar** args) } if (g_strcmp0(args[1], "set") == 0) { - char* path = args[2]; - if (path == NULL) { + if (args[2] == NULL) { cons_bad_cmd_usage(command); return TRUE; } - // expand ~ to $HOME - if (path[0] == '~' && path[1] == '/') { - if (asprintf(&path, "%s/%s", getenv("HOME"), path + 2) == -1) { - return TRUE; - } - } else { - path = strdup(path); - } + char *path = get_expanded_path(args[2]); if (!is_dir(path)) { cons_show("Plugins sourcepath must be a directory."); @@ -6897,8 +6880,9 @@ cmd_plugins_sourcepath(ProfWin* window, const char* const command, gchar** args) gboolean cmd_plugins_install(ProfWin* window, const char* const command, gchar** args) { - char* path = args[1]; - if (path == NULL) { + char *path; + + if (args[1] == NULL) { char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH); if (sourcepath) { path = strdup(sourcepath); @@ -6907,12 +6891,8 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args) cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins"); return TRUE; } - } else if (path[0] == '~' && path[1] == '/') { - if (asprintf(&path, "%s/%s", getenv("HOME"), path + 2) == -1) { - return TRUE; - } } else { - path = strdup(path); + path = get_expanded_path(args[1]); } if (is_regular_file(path)) { @@ -6972,8 +6952,9 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args) gboolean cmd_plugins_update(ProfWin* window, const char* const command, gchar** args) { - char* path = args[1]; - if (path == NULL) { + char* path; + + if (args[1] == NULL) { char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH); if (sourcepath) { path = strdup(sourcepath); @@ -6982,12 +6963,8 @@ cmd_plugins_update(ProfWin* window, const char* const command, gchar** args) cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins"); return TRUE; } - } else if (path[0] == '~' && path[1] == '/') { - if (asprintf(&path, "%s/%s", getenv("HOME"), path + 2) == -1) { - return TRUE; - } } else { - path = strdup(path); + path = get_expanded_path(args[1]); } if (access(path, R_OK) != 0) { |