git-worktree.txt: keep subcommand listing in alphabetical order
[gitweb.git] / builtin / help.c
index fba8c01e242debd08dc450fa1ed4db587acfdb09..3c55ce456309ee7da95eac0517f11161ab3c1f7c 100644 (file)
@@ -140,17 +140,10 @@ static void exec_man_konqueror(const char *path, const char *page)
 
                /* It's simpler to launch konqueror using kfmclient. */
                if (path) {
-                       const char *file = strrchr(path, '/');
-                       if (file && !strcmp(file + 1, "konqueror")) {
-                               char *new = xstrdup(path);
-                               char *dest = strrchr(new, '/');
-
-                               /* strlen("konqueror") == strlen("kfmclient") */
-                               strcpy(dest + 1, "kfmclient");
-                               path = new;
-                       }
-                       if (file)
-                               filename = file;
+                       size_t len;
+                       if (strip_suffix(path, "/konqueror", &len))
+                               path = xstrfmt("%.*s/kfmclient", (int)len, path);
+                       filename = basename((char *)path);
                } else
                        path = "kfmclient";
                strbuf_addf(&man_page, "man:%s(1)", page);
@@ -178,12 +171,10 @@ static void exec_man_cmd(const char *cmd, const char *page)
 static void add_man_viewer(const char *name)
 {
        struct man_viewer_list **p = &man_viewer_list;
-       size_t len = strlen(name);
 
        while (*p)
                p = &((*p)->next);
-       *p = xcalloc(1, (sizeof(**p) + len + 1));
-       strncpy((*p)->name, name, len);
+       FLEX_ALLOC_STR(*p, name, name);
 }
 
 static int supported_man_viewer(const char *name, size_t len)
@@ -197,9 +188,8 @@ static void do_add_man_viewer_info(const char *name,
                                   size_t len,
                                   const char *value)
 {
-       struct man_viewer_info_list *new = xcalloc(1, sizeof(*new) + len + 1);
-
-       strncpy(new->name, name, len);
+       struct man_viewer_info_list *new;
+       FLEX_ALLOC_MEM(new, name, name, len);
        new->info = xstrdup(value);
        new->next = man_viewer_info_list;
        man_viewer_info_list = new;