about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2023-05-10 09:41:59 +0200
committerMichael Vetter <jubalh@iodoru.org>2023-05-10 09:41:59 +0200
commit60c197487daee968d504a5f73fac391b6a6c6971 (patch)
tree8243fe9a036e5660939f40eb9655840660b92e70
parent79efe56d64fb639f96f3ed3e421b9bb7ee37957e (diff)
downloadprofani-tty-60c197487daee968d504a5f73fac391b6a6c6971.tar.gz
Add helper function for individual cmd_executable_*() functions
Each of the cmd_executable_editor(), cmd_executable_urlopen() etc calls
this helper function since they were all doing the same just for
different configurations.
-rw-r--r--src/command/cmd_funcs.c53
1 files changed, 7 insertions, 46 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 3c982213..ccba8827 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9634,6 +9634,9 @@ _cmd_executable_template(const preference_t setting, const char* command, gchar*
     } else if (g_strcmp0(args[1], "default") == 0) {
         prefs_set_string(setting, NULL);
         gchar* def = prefs_get_string(setting);
+        if (def == NULL) {
+            def = g_strdup("built-in method");
+        }
         cons_show("`%s` command set to invoke %s (default)", command, def);
         g_free(def);
     } else {
@@ -9658,63 +9661,21 @@ cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args)
 gboolean
 cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args)
 {
-    guint num_args = g_strv_length(args);
-    if (num_args < 2) {
-        cons_bad_cmd_usage(command);
-        return TRUE;
-    }
-
-    if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) {
-        gchar* str = g_strjoinv(" ", &args[2]);
-        prefs_set_string(PREF_URL_SAVE_CMD, str);
-        cons_show("`url save` command set to invoke '%s'", str);
-        g_free(str);
-
-    } else if (g_strcmp0(args[1], "default") == 0) {
-        prefs_set_string(PREF_URL_SAVE_CMD, NULL);
-        cons_show("`url save` will use built-in download method (default)");
-    } else {
-        cons_bad_cmd_usage(command);
-    }
-
-    return TRUE;
+    return _cmd_executable_template(PREF_URL_SAVE_CMD, args[0], args);
 }
 
 gboolean
 cmd_executable_editor(ProfWin* window, const char* const command, gchar** args)
 {
-    guint num_args = g_strv_length(args);
-
-    if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) {
-        prefs_set_string(PREF_COMPOSE_EDITOR, args[2]);
-        cons_show("`editor` command set to invoke '%s'", args[2]);
-    } else if (g_strcmp0(args[1], "default") == 0) {
-        prefs_set_string(PREF_COMPOSE_EDITOR, NULL);
-        cons_show("`editor` will use built-in download method (default)");
-    } else {
-        cons_bad_cmd_usage(command);
-    }
-
-    return TRUE;
+    return _cmd_executable_template(PREF_COMPOSE_EDITOR, args[0], args);
 }
 
 gboolean
 cmd_executable_vcard_photo(ProfWin* window, const char* const command, gchar** args)
 {
-    if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
-        prefs_set_string(PREF_VCARD_PHOTO_CMD, args[2]);
-        cons_show("`vcard photo open` command set to invoke '%s'", args[2]);
-    } else if (g_strcmp0(args[1], "default") == 0) {
-        prefs_set_string(PREF_VCARD_PHOTO_CMD, NULL);
-        char* cmd = prefs_get_string(PREF_VCARD_PHOTO_CMD);
-        cons_show("`vcard photo open` command set to invoke '%s' (default)", cmd);
-        g_free(cmd);
-    } else {
-        cons_bad_cmd_usage(command);
-    }
-
-    return TRUE;
+    return _cmd_executable_template(PREF_VCARD_PHOTO_CMD, args[0], args);
 }
+
 gboolean
 cmd_mam(ProfWin* window, const char* const command, gchar** args)
 {