qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Use hxtool for qemu-img command list
@ 2009-06-06 23:42 Stuart Brady
  2009-06-07  7:09 ` Blue Swirl
  0 siblings, 1 reply; 2+ messages in thread
From: Stuart Brady @ 2009-06-06 23:42 UTC (permalink / raw)
  To: qemu-devel

Use hxtool to generate the 'command syntax' section of qemu-img's help
message, and the corresponding section of the texinfo documentation.

This has the side-effect of adding 'check' to this list of commands in
the texinfo documentation.

Signed-off-by: Stuart Brady <stuart.brady@gmail.com>

diff -urN qemu-old/.gitignore qemu-new/.gitignore
--- qemu-old/.gitignore	2009-06-07 00:29:22.000000000 +0100
+++ qemu-new/.gitignore	2009-06-07 00:28:07.000000000 +0100
@@ -19,6 +19,8 @@
 qemu-nbd.8
 qemu-nbd.pod
 qemu-options.texi
+qemu-img-cmds.texi
+qemu-img-cmds.h
 qemu-io
 .gdbinit
 *.a
diff -urN qemu-old/Makefile qemu-new/Makefile
--- qemu-old/Makefile	2009-06-07 00:29:22.000000000 +0100
+++ qemu-new/Makefile	2009-06-07 00:03:44.000000000 +0100
@@ -238,6 +238,8 @@
 
 ######################################################################
 
+qemu-img.o: qemu-img-cmds.h
+
 qemu-img$(EXESUF): qemu-img.o qemu-tool.o tool-osdep.o $(BLOCK_OBJS)
 
 qemu-nbd$(EXESUF):  qemu-nbd.o qemu-tool.o tool-osdep.o $(BLOCK_OBJS)
@@ -246,6 +248,9 @@
 
 qemu-img$(EXESUF) qemu-nbd$(EXESUF) qemu-io$(EXESUF): LIBS += -lz
 
+qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
+	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $@")
+
 clean:
 # avoid old build problems by removing potentially incorrect old files
 	rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
@@ -257,7 +262,7 @@
         done
 
 distclean: clean
-	rm -f config-host.mak config-host.h $(DOCS) qemu-options.texi
+	rm -f config-host.mak config-host.h $(DOCS) qemu-options.texi qemu-img-cmds.texi
 	rm -f qemu-{doc,tech}.{info,aux,cp,dvi,fn,info,ky,log,pg,toc,tp,vr}
 	for d in $(TARGET_DIRS) libhw32 libhw64; do \
 	rm -rf $$d || exit 1 ; \
@@ -335,13 +340,16 @@
 qemu-monitor.texi: $(SRC_PATH)/qemu-monitor.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@,"  GEN   $@")
 
+qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx
+	$(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@,"  GEN   $@")
+
 qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi
 	$(call quiet-command, \
 	  perl -Ww -- $(SRC_PATH)/texi2pod.pl $< qemu.pod && \
 	  pod2man --section=1 --center=" " --release=" " qemu.pod > $@, \
 	  "  GEN   $@")
 
-qemu-img.1: qemu-img.texi
+qemu-img.1: qemu-img.texi qemu-img-cmds.texi
 	$(call quiet-command, \
 	  perl -Ww -- $(SRC_PATH)/texi2pod.pl $< qemu-img.pod && \
 	  pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@, \
@@ -359,7 +367,7 @@
 
 html: qemu-doc.html qemu-tech.html
 
-qemu-doc.dvi qemu-doc.html qemu-doc.info: qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-monitor.texi
+qemu-doc.dvi qemu-doc.html qemu-doc.info: qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-monitor.texi qemu-img-cmds.texi
 
 VERSION ?= $(shell cat VERSION)
 FILE = qemu-$(VERSION)
diff -urN qemu-old/qemu-img.c qemu-new/qemu-img.c
--- qemu-old/qemu-img.c	2009-06-07 00:29:22.000000000 +0100
+++ qemu-new/qemu-img.c	2009-06-07 00:18:05.000000000 +0100
@@ -31,6 +31,11 @@
 #include <windows.h>
 #endif
 
+typedef struct img_cmd_t {
+    const char *name;
+    int (*handler)(int argc, char **argv);
+} img_cmd_t;
+
 /* Default to cache=writeback as data integrity is not important for qemu-tcg. */
 #define BRDV_O_FLAGS BDRV_O_CACHE_WB
 
@@ -58,12 +63,11 @@
            "QEMU disk image utility\n"
            "\n"
            "Command syntax:\n"
-           "  check [-f fmt] filename\n"
-           "  create [-F fmt] [-b base_image] [-f fmt] [-o options] filename [size]\n"
-           "  commit [-f fmt] filename\n"
-           "  convert [-c] [-f fmt] [-O output_fmt] [-o options] [-B output_base_image] filename [filename2 [...]] output_filename\n"
-           "  info [-f fmt] filename\n"
-           "  snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename\n"
+#define DEF(option, callback, arg_string)        \
+           "  " arg_string "\n"
+#include "qemu-img-cmds.h"
+#undef DEF
+#undef GEN_DOCS
            "\n"
            "Command parameters:\n"
            "  'filename' is a disk image filename\n"
@@ -919,7 +923,7 @@
 #define SNAPSHOT_APPLY  3
 #define SNAPSHOT_DELETE 4
 
-static void img_snapshot(int argc, char **argv)
+static int img_snapshot(int argc, char **argv)
 {
     BlockDriverState *bs;
     QEMUSnapshotInfo sn;
@@ -936,18 +940,18 @@
         switch(c) {
         case 'h':
             help();
-            return;
+            return 0;
         case 'l':
             if (action) {
                 help();
-                return;
+                return 0;
             }
             action = SNAPSHOT_LIST;
             break;
         case 'a':
             if (action) {
                 help();
-                return;
+                return 0;
             }
             action = SNAPSHOT_APPLY;
             snapshot_name = optarg;
@@ -955,7 +959,7 @@
         case 'c':
             if (action) {
                 help();
-                return;
+                return 0;
             }
             action = SNAPSHOT_CREATE;
             snapshot_name = optarg;
@@ -963,7 +967,7 @@
         case 'd':
             if (action) {
                 help();
-                return;
+                return 0;
             }
             action = SNAPSHOT_DELETE;
             snapshot_name = optarg;
@@ -1021,31 +1025,38 @@
 
     /* Cleanup */
     bdrv_delete(bs);
+
+    return 0;
 }
 
+static const img_cmd_t img_cmds[] = {
+#define DEF(option, callback, arg_string)        \
+    { option, callback },
+#include "qemu-img-cmds.h"
+#undef DEF
+#undef GEN_DOCS
+    { NULL, NULL, },
+};
+
 int main(int argc, char **argv)
 {
-    const char *cmd;
+    const img_cmd_t *cmd;
+    const char *cmdname;
 
     bdrv_init();
     if (argc < 2)
         help();
-    cmd = argv[1];
+    cmdname = argv[1];
     argc--; argv++;
-    if (!strcmp(cmd, "create")) {
-        img_create(argc, argv);
-    } else if (!strcmp(cmd, "check")) {
-        img_check(argc, argv);
-    } else if (!strcmp(cmd, "commit")) {
-        img_commit(argc, argv);
-    } else if (!strcmp(cmd, "convert")) {
-        img_convert(argc, argv);
-    } else if (!strcmp(cmd, "info")) {
-        img_info(argc, argv);
-    } else if (!strcmp(cmd, "snapshot")) {
-        img_snapshot(argc, argv);
-    } else {
-        help();
+
+    /* find the command */
+    for(cmd = img_cmds; cmd->name != NULL; cmd++) {
+        if (!strcmp(cmdname, cmd->name)) {
+            return cmd->handler(argc, argv);
+        }
     }
+
+    /* not found */
+    help();
     return 0;
 }
diff -urN qemu-old/qemu-img-cmds.hx qemu-new/qemu-img-cmds.hx
--- qemu-old/qemu-img-cmds.hx	1970-01-01 01:00:00.000000000 +0100
+++ qemu-new/qemu-img-cmds.hx	2009-06-07 00:18:51.000000000 +0100
@@ -0,0 +1,47 @@
+HXCOMM Use DEFHEADING() to define headings in both help text and texi
+HXCOMM Text between STEXI and ETEXI are copied to texi version and
+HXCOMM discarded from C version
+HXCOMM DEF(command, callback, arg_string) is used to construct
+HXCOMM command structures and help message.
+HXCOMM HXCOMM can be used for comments, discarded from both texi and C
+
+STEXI
+@table @option
+STEXI
+
+DEF("check", img_check,
+    "check [-f fmt] filename")
+STEXI
+@item check [-f @var{fmt}] @var{filename}
+ETEXI
+
+DEF("create", img_create,
+    "create [-F fmt] [-b base_image] [-f fmt] [-o options] filename [size]")
+STEXI
+@item create [-F @var{base_fmt}] [-b @var{base_image}] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]
+ETEXI
+
+DEF("commit", img_commit,
+    "commit [-f fmt] filename")
+STEXI
+@item commit [-f @var{fmt}] @var{filename}
+ETEXI
+
+DEF("convert", img_convert,
+    "convert [-c] [-f fmt] [-O output_fmt] [-o options] [-B output_base_image] filename [filename2 [...]] output_filename")
+STEXI
+@item convert [-c] [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [-B @var{output_base_image}] @var{filename} [@var{filename2} [...]] @var{output_filename}
+ETEXI
+
+DEF("info", img_info,
+    "info [-f fmt] filename")
+STEXI
+@item info [-f @var{fmt}] @var{filename}
+ETEXI
+
+DEF("snapshot", img_snapshot,
+    "snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename")
+STEXI
+@item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
+@end table
+ETEXI
diff -urN qemu-old/qemu-img.texi qemu-new/qemu-img.texi
--- qemu-old/qemu-img.texi	2009-06-07 00:29:22.000000000 +0100
+++ qemu-new/qemu-img.texi	2009-06-07 00:03:44.000000000 +0100
@@ -7,13 +7,8 @@
 @c man begin OPTIONS
 
 The following commands are supported:
-@table @option
-@item create [-F @var{base_fmt}] [-b @var{base_image}] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]
-@item commit [-f @var{fmt}] @var{filename}
-@item convert [-c] [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [-B @var{output_base_image}] @var{filename} [@var{filename2} [...]] @var{output_filename}
-@item info [-f @var{fmt}] @var{filename}
-@item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
-@end table
+
+@include qemu-img-cmds.texi
 
 Command parameters:
 @table @var
-- 
Stuart Brady

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] Use hxtool for qemu-img command list
  2009-06-06 23:42 [Qemu-devel] [PATCH] Use hxtool for qemu-img command list Stuart Brady
@ 2009-06-07  7:09 ` Blue Swirl
  0 siblings, 0 replies; 2+ messages in thread
From: Blue Swirl @ 2009-06-07  7:09 UTC (permalink / raw)
  To: Stuart Brady; +Cc: qemu-devel

On 6/7/09, Stuart Brady <sdbrady@ntlworld.com> wrote:
> Use hxtool to generate the 'command syntax' section of qemu-img's help
>  message, and the corresponding section of the texinfo documentation.
>
>  This has the side-effect of adding 'check' to this list of commands in
>  the texinfo documentation.
>
>  Signed-off-by: Stuart Brady <stuart.brady@gmail.com>

Thanks, applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-07  7:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-06 23:42 [Qemu-devel] [PATCH] Use hxtool for qemu-img command list Stuart Brady
2009-06-07  7:09 ` Blue Swirl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).