cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
34b321
From 8d6f59c923b536461df1aea18045535b090984fb Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Mon, 23 Nov 2015 17:38:27 +0100
34b321
Subject: [PATCH 08/27] qemu-io: Move 'help' function
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1448300320-7772-9-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68435
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 08/21] qemu-io: Move 'help' function
34b321
Bugzilla: 1272523
34b321
RH-Acked-by: Thomas Huth <thuth@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
34b321
From: Kevin Wolf <kwolf@redhat.com>
34b321
34b321
No reason to treat it different from other commands. Move it to
34b321
qemu-io-cmds.c, adapt the coding style and register it like any other
34b321
command.
34b321
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
(cherry picked from commit f18a834a92f0b490cefeb71410f3f25b969d336f)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
  qemu-io-cmds:  patch context (from sleep_f)
34b321
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
---
34b321
 cmd.c          | 79 ----------------------------------------------------------
34b321
 cmd.h          |  1 -
34b321
 qemu-io-cmds.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++-
34b321
 3 files changed, 65 insertions(+), 81 deletions(-)
34b321
34b321
diff --git a/cmd.c b/cmd.c
34b321
index 7ae978f..2941ad3 100644
34b321
--- a/cmd.c
34b321
+++ b/cmd.c
34b321
@@ -439,82 +439,3 @@ quit_init(void)
34b321
 
34b321
 	add_command(&quit_cmd);
34b321
 }
34b321
-
34b321
-/* from libxcmd/help.c */
34b321
-
34b321
-static cmdinfo_t help_cmd;
34b321
-static void help_onecmd(const char *cmd, const cmdinfo_t *ct);
34b321
-static void help_oneline(const char *cmd, const cmdinfo_t *ct);
34b321
-
34b321
-static void
34b321
-help_all(void)
34b321
-{
34b321
-	const cmdinfo_t	*ct;
34b321
-
34b321
-	for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++)
34b321
-		help_oneline(ct->name, ct);
34b321
-	printf(_("\nUse 'help commandname' for extended help.\n"));
34b321
-}
34b321
-
34b321
-static int
34b321
-help_f(
34b321
-    BlockDriverState *bs,
34b321
-	int		argc,
34b321
-	char		**argv)
34b321
-{
34b321
-	const cmdinfo_t	*ct;
34b321
-
34b321
-	if (argc == 1) {
34b321
-		help_all();
34b321
-		return 0;
34b321
-	}
34b321
-	ct = find_command(argv[1]);
34b321
-	if (ct == NULL) {
34b321
-		printf(_("command %s not found\n"), argv[1]);
34b321
-		return 0;
34b321
-	}
34b321
-	help_onecmd(argv[1], ct);
34b321
-	return 0;
34b321
-}
34b321
-
34b321
-static void
34b321
-help_onecmd(
34b321
-	const char	*cmd,
34b321
-	const cmdinfo_t	*ct)
34b321
-{
34b321
-	help_oneline(cmd, ct);
34b321
-	if (ct->help)
34b321
-		ct->help();
34b321
-}
34b321
-
34b321
-static void
34b321
-help_oneline(
34b321
-	const char	*cmd,
34b321
-	const cmdinfo_t	*ct)
34b321
-{
34b321
-	if (cmd)
34b321
-		printf("%s ", cmd);
34b321
-	else {
34b321
-		printf("%s ", ct->name);
34b321
-		if (ct->altname)
34b321
-			printf("(or %s) ", ct->altname);
34b321
-	}
34b321
-	if (ct->args)
34b321
-		printf("%s ", ct->args);
34b321
-	printf("-- %s\n", ct->oneline);
34b321
-}
34b321
-
34b321
-void
34b321
-help_init(void)
34b321
-{
34b321
-	help_cmd.name = _("help");
34b321
-	help_cmd.altname = _("?");
34b321
-	help_cmd.cfunc = help_f;
34b321
-	help_cmd.argmin = 0;
34b321
-	help_cmd.argmax = 1;
34b321
-	help_cmd.flags = CMD_FLAG_GLOBAL;
34b321
-	help_cmd.args = _("[command]");
34b321
-	help_cmd.oneline = _("help for one or all commands");
34b321
-
34b321
-	add_command(&help_cmd);
34b321
-}
34b321
diff --git a/cmd.h b/cmd.h
34b321
index d676408..89e7c6e 100644
34b321
--- a/cmd.h
34b321
+++ b/cmd.h
34b321
@@ -42,7 +42,6 @@ typedef struct cmdinfo {
34b321
 extern cmdinfo_t	*cmdtab;
34b321
 extern int		ncmds;
34b321
 
34b321
-void help_init(void);
34b321
 void quit_init(void);
34b321
 
34b321
 typedef int (*checkfunc_t)(BlockDriverState *bs, const cmdinfo_t *ci);
34b321
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
34b321
index 09e4099..a8e891a 100644
34b321
--- a/qemu-io-cmds.c
34b321
+++ b/qemu-io-cmds.c
34b321
@@ -1811,6 +1811,70 @@ static const cmdinfo_t sleep_cmd = {
34b321
        .oneline        = "waits for the given value in milliseconds",
34b321
 };
34b321
 
34b321
+static void help_oneline(const char *cmd, const cmdinfo_t *ct)
34b321
+{
34b321
+    if (cmd) {
34b321
+        printf("%s ", cmd);
34b321
+    } else {
34b321
+        printf("%s ", ct->name);
34b321
+        if (ct->altname) {
34b321
+            printf("(or %s) ", ct->altname);
34b321
+        }
34b321
+    }
34b321
+
34b321
+    if (ct->args) {
34b321
+        printf("%s ", ct->args);
34b321
+    }
34b321
+    printf("-- %s\n", ct->oneline);
34b321
+}
34b321
+
34b321
+static void help_onecmd(const char *cmd, const cmdinfo_t *ct)
34b321
+{
34b321
+    help_oneline(cmd, ct);
34b321
+    if (ct->help) {
34b321
+        ct->help();
34b321
+    }
34b321
+}
34b321
+
34b321
+static void help_all(void)
34b321
+{
34b321
+    const cmdinfo_t *ct;
34b321
+
34b321
+    for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
34b321
+        help_oneline(ct->name, ct);
34b321
+    }
34b321
+    printf("\nUse 'help commandname' for extended help.\n");
34b321
+}
34b321
+
34b321
+static int help_f(BlockDriverState *bs, int argc, char **argv)
34b321
+{
34b321
+    const cmdinfo_t *ct;
34b321
+
34b321
+    if (argc == 1) {
34b321
+        help_all();
34b321
+        return 0;
34b321
+    }
34b321
+
34b321
+    ct = find_command(argv[1]);
34b321
+    if (ct == NULL) {
34b321
+        printf("command %s not found\n", argv[1]);
34b321
+        return 0;
34b321
+    }
34b321
+
34b321
+    help_onecmd(argv[1], ct);
34b321
+    return 0;
34b321
+}
34b321
+
34b321
+static const cmdinfo_t help_cmd = {
34b321
+    .name       = "help",
34b321
+    .altname    = "?",
34b321
+    .cfunc      = help_f,
34b321
+    .argmin     = 0,
34b321
+    .argmax     = 1,
34b321
+    .flags      = CMD_FLAG_GLOBAL,
34b321
+    .args       = "[command]",
34b321
+    .oneline    = "help for one or all commands",
34b321
+};
34b321
 
34b321
 static int init_check_command(BlockDriverState *bs, const cmdinfo_t *ct)
34b321
 {
34b321
@@ -1851,7 +1915,7 @@ bool qemuio_command(const char *cmd)
34b321
 static void __attribute((constructor)) init_qemuio_commands(void)
34b321
 {
34b321
     /* initialize commands */
34b321
-    help_init();
34b321
+    add_command(&help_cmd);
34b321
     add_command(&read_cmd);
34b321
     add_command(&readv_cmd);
34b321
     add_command(&write_cmd);
34b321
-- 
34b321
1.8.3.1
34b321