Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * builtin-help.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Builtin help command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "util/cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "util/config.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "util/strbuf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "builtin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <subcmd/exec-cmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "common-cmds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <subcmd/parse-options.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <subcmd/run-command.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <subcmd/help.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "util/debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct man_viewer_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct man_viewer_list *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	char name[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) } *man_viewer_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static struct man_viewer_info_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct man_viewer_info_list *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	const char *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	char name[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) } *man_viewer_info_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) enum help_format {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	HELP_FORMAT_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	HELP_FORMAT_MAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	HELP_FORMAT_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	HELP_FORMAT_WEB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static enum help_format parse_help_format(const char *format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!strcmp(format, "man"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return HELP_FORMAT_MAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (!strcmp(format, "info"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return HELP_FORMAT_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (!strcmp(format, "web") || !strcmp(format, "html"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return HELP_FORMAT_WEB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	pr_err("unrecognized help format '%s'", format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return HELP_FORMAT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static const char *get_man_viewer_info(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct man_viewer_info_list *viewer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	for (viewer = man_viewer_info_list; viewer; viewer = viewer->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		if (!strcasecmp(name, viewer->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			return viewer->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int check_emacsclient_version(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct strbuf buffer = STRBUF_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct child_process ec_process;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	const char *argv_ec[] = { "emacsclient", "--version", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* emacsclient prints its version number on stderr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	memset(&ec_process, 0, sizeof(ec_process));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	ec_process.argv = argv_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	ec_process.err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ec_process.stdout_to_stderr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (start_command(&ec_process)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		fprintf(stderr, "Failed to start emacsclient.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (strbuf_read(&buffer, ec_process.err, 20) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		fprintf(stderr, "Failed to read emacsclient version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	close(ec_process.err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * Don't bother checking return value, because "emacsclient --version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 * seems to always exits with code 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	finish_command(&ec_process);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (!strstarts(buffer.buf, "emacsclient")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		fprintf(stderr, "Failed to parse emacsclient version.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	version = atoi(buffer.buf + strlen("emacsclient"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (version < 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		fprintf(stderr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			"emacsclient version '%d' too old (< 22).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	strbuf_release(&buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void exec_failed(const char *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	char sbuf[STRERR_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	pr_warning("failed to exec '%s': %s", cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void exec_woman_emacs(const char *path, const char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!check_emacsclient_version()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		/* This works only with emacsclient version >= 22. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		char *man_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			path = "emacsclient";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (asprintf(&man_page, "(woman \"%s\")", page) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			execlp(path, "emacsclient", "-e", man_page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			free(man_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		exec_failed(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void exec_man_konqueror(const char *path, const char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	const char *display = getenv("DISPLAY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (display && *display) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		char *man_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		const char *filename = "kfmclient";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		/* It's simpler to launch konqueror using kfmclient. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			const char *file = strrchr(path, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			if (file && !strcmp(file + 1, "konqueror")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				char *new = strdup(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				char *dest = strrchr(new, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				/* strlen("konqueror") == strlen("kfmclient") */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				strcpy(dest + 1, "kfmclient");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				path = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			if (file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				filename = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			path = "kfmclient";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (asprintf(&man_page, "man:%s(1)", page) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			execlp(path, filename, "newTab", man_page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			free(man_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		exec_failed(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static void exec_man_man(const char *path, const char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		path = "man";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	execlp(path, "man", page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	exec_failed(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void exec_man_cmd(const char *cmd, const char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	char *shell_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		execl("/bin/sh", "sh", "-c", shell_cmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		free(shell_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	exec_failed(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static void add_man_viewer(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct man_viewer_list **p = &man_viewer_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	size_t len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	while (*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		p = &((*p)->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	*p = zalloc(sizeof(**p) + len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	strcpy((*p)->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int supported_man_viewer(const char *name, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return (!strncasecmp("man", name, len) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		!strncasecmp("woman", name, len) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		!strncasecmp("konqueror", name, len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void do_add_man_viewer_info(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				   size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				   const char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct man_viewer_info_list *new = zalloc(sizeof(*new) + len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	strncpy(new->name, name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	new->info = strdup(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	new->next = man_viewer_info_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	man_viewer_info_list = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static void unsupported_man_viewer(const char *name, const char *var)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	pr_warning("'%s': path for unsupported man viewer.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		   "Please consider using 'man.<tool>.%s' instead.", name, var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int add_man_viewer_path(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			       size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			       const char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (supported_man_viewer(name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		do_add_man_viewer_info(name, len, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		unsupported_man_viewer(name, "cmd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int add_man_viewer_cmd(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			      size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			      const char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (supported_man_viewer(name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		unsupported_man_viewer(name, "path");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		do_add_man_viewer_info(name, len, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int add_man_viewer_info(const char *var, const char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	const char *name = var + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	const char *subkey = strrchr(name, '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!subkey) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		pr_err("Config with no key for man viewer: %s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!strcmp(subkey, ".path")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			return config_error_nonbool(var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return add_man_viewer_path(name, subkey - name, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (!strcmp(subkey, ".cmd")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			return config_error_nonbool(var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return add_man_viewer_cmd(name, subkey - name, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	pr_warning("'%s': unsupported man viewer sub key.", subkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int perf_help_config(const char *var, const char *value, void *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	enum help_format *help_formatp = cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!strcmp(var, "help.format")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			return config_error_nonbool(var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		*help_formatp = parse_help_format(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (*help_formatp == HELP_FORMAT_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (!strcmp(var, "man.viewer")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			return config_error_nonbool(var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		add_man_viewer(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (strstarts(var, "man."))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		return add_man_viewer_info(var, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static struct cmdnames main_cmds, other_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void list_common_cmds_help(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	unsigned int i, longest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (longest < strlen(common_cmds[i].name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			longest = strlen(common_cmds[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	puts(" The most commonly used perf commands are:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		printf("   %-*s   ", longest, common_cmds[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		puts(common_cmds[i].help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static const char *cmd_to_page(const char *perf_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (!perf_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return "perf";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	else if (strstarts(perf_cmd, "perf"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return perf_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	return asprintf(&s, "perf-%s", perf_cmd) < 0 ? NULL : s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static void setup_man_path(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	char *new_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	const char *old_path = getenv("MANPATH");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	/* We should always put ':' after our path. If there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	 * old_path, the ':' at the end will let 'man' to try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	 * system-wide paths after ours to find the manual page. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	 * there is old_path, we need ':' as delimiter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (asprintf(&new_path, "%s:%s", system_path(PERF_MAN_PATH), old_path ?: "") > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		setenv("MANPATH", new_path, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		free(new_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		pr_err("Unable to setup man path");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static void exec_viewer(const char *name, const char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	const char *info = get_man_viewer_info(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (!strcasecmp(name, "man"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		exec_man_man(info, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	else if (!strcasecmp(name, "woman"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		exec_woman_emacs(info, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	else if (!strcasecmp(name, "konqueror"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		exec_man_konqueror(info, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	else if (info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		exec_man_cmd(info, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		pr_warning("'%s': unknown man viewer.", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int show_man_page(const char *perf_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct man_viewer_list *viewer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	const char *page = cmd_to_page(perf_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	const char *fallback = getenv("PERF_MAN_VIEWER");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	setup_man_path();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	for (viewer = man_viewer_list; viewer; viewer = viewer->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		exec_viewer(viewer->name, page); /* will return when unable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (fallback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		exec_viewer(fallback, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	exec_viewer("man", page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	pr_err("no man viewer handled the request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int show_info_page(const char *perf_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	const char *page = cmd_to_page(perf_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	setenv("INFOPATH", system_path(PERF_INFO_PATH), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	execlp("info", "info", "perfman", page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static int get_html_page_path(char **page_path, const char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct stat st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	const char *html_path = system_path(PERF_HTML_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* Check that we have a perf documentation directory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (stat(mkpath("%s/perf.html", html_path), &st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	    || !S_ISREG(st.st_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		pr_err("'%s': not a documentation directory.", html_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return asprintf(page_path, "%s/%s.html", html_path, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * If open_html is not defined in a platform-specific way (see for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * example compat/mingw.h), we use the script web--browse to display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * HTML.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #ifndef open_html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static void open_html(const char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	execl_cmd("web--browse", "-c", "help.browser", path, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int show_html_page(const char *perf_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	const char *page = cmd_to_page(perf_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	char *page_path; /* it leaks but we exec bellow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (get_html_page_path(&page_path, page) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	open_html(page_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) int cmd_help(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	bool show_all = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	enum help_format help_format = HELP_FORMAT_MAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct option builtin_help_options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	OPT_SET_UINT('w', "web", &help_format, "show manual in web browser",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			HELP_FORMAT_WEB),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	OPT_SET_UINT('i', "info", &help_format, "show info page",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			HELP_FORMAT_INFO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	OPT_END(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	const char * const builtin_help_subcommands[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		"buildid-cache", "buildid-list", "diff", "evlist", "help", "list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		"record", "report", "bench", "stat", "timechart", "top", "annotate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		"script", "sched", "kallsyms", "kmem", "lock", "kvm", "test", "inject", "mem", "data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) #ifdef HAVE_LIBELF_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		"probe",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) #if defined(HAVE_LIBAUDIT_SUPPORT) || defined(HAVE_SYSCALL_TABLE_SUPPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		"trace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	const char *builtin_help_usage[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		"perf help [--all] [--man|--web|--info] [command]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	load_command_list("perf-", &main_cmds, &other_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	rc = perf_config(perf_help_config, &help_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	argc = parse_options_subcommand(argc, argv, builtin_help_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			builtin_help_subcommands, builtin_help_usage, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	if (show_all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		printf("\n Usage: %s\n\n", perf_usage_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		list_commands("perf commands", &main_cmds, &other_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		printf(" %s\n\n", perf_more_info_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (!argv[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		printf("\n usage: %s\n\n", perf_usage_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		list_common_cmds_help();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		printf("\n %s\n\n", perf_more_info_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	switch (help_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	case HELP_FORMAT_MAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		rc = show_man_page(argv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	case HELP_FORMAT_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		rc = show_info_page(argv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	case HELP_FORMAT_WEB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		rc = show_html_page(argv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	case HELP_FORMAT_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		/* fall-through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }