Commit 153859be1a0928d07ec2dc2b18847e32e180ff43

Authored by Stuart Brady
Committed by Blue Swirl
1 parent 3a2eeac0

Use hxtool for qemu-img command list

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>
.gitignore
@@ -19,6 +19,8 @@ qemu-nbd @@ -19,6 +19,8 @@ qemu-nbd
19 qemu-nbd.8 19 qemu-nbd.8
20 qemu-nbd.pod 20 qemu-nbd.pod
21 qemu-options.texi 21 qemu-options.texi
  22 +qemu-img-cmds.texi
  23 +qemu-img-cmds.h
22 qemu-io 24 qemu-io
23 .gdbinit 25 .gdbinit
24 *.a 26 *.a
Makefile
@@ -238,6 +238,8 @@ libqemu_user.a: $(USER_OBJS) @@ -238,6 +238,8 @@ libqemu_user.a: $(USER_OBJS)
238 238
239 ###################################################################### 239 ######################################################################
240 240
  241 +qemu-img.o: qemu-img-cmds.h
  242 +
241 qemu-img$(EXESUF): qemu-img.o qemu-tool.o tool-osdep.o $(BLOCK_OBJS) 243 qemu-img$(EXESUF): qemu-img.o qemu-tool.o tool-osdep.o $(BLOCK_OBJS)
242 244
243 qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o tool-osdep.o $(BLOCK_OBJS) 245 qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o tool-osdep.o $(BLOCK_OBJS)
@@ -246,6 +248,9 @@ qemu-io$(EXESUF): qemu-io.o qemu-tool.o tool-osdep.o cmd.o $(BLOCK_OBJS) @@ -246,6 +248,9 @@ qemu-io$(EXESUF): qemu-io.o qemu-tool.o tool-osdep.o cmd.o $(BLOCK_OBJS)
246 248
247 qemu-img$(EXESUF) qemu-nbd$(EXESUF) qemu-io$(EXESUF): LIBS += -lz 249 qemu-img$(EXESUF) qemu-nbd$(EXESUF) qemu-io$(EXESUF): LIBS += -lz
248 250
  251 +qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
  252 + $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@")
  253 +
249 clean: 254 clean:
250 # avoid old build problems by removing potentially incorrect old files 255 # avoid old build problems by removing potentially incorrect old files
251 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 256 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 @@ clean: @@ -257,7 +262,7 @@ clean:
257 done 262 done
258 263
259 distclean: clean 264 distclean: clean
260 - rm -f config-host.mak config-host.h $(DOCS) qemu-options.texi 265 + rm -f config-host.mak config-host.h $(DOCS) qemu-options.texi qemu-img-cmds.texi
261 rm -f qemu-{doc,tech}.{info,aux,cp,dvi,fn,info,ky,log,pg,toc,tp,vr} 266 rm -f qemu-{doc,tech}.{info,aux,cp,dvi,fn,info,ky,log,pg,toc,tp,vr}
262 for d in $(TARGET_DIRS) libhw32 libhw64; do \ 267 for d in $(TARGET_DIRS) libhw32 libhw64; do \
263 rm -rf $$d || exit 1 ; \ 268 rm -rf $$d || exit 1 ; \
@@ -335,13 +340,16 @@ qemu-options.texi: $(SRC_PATH)/qemu-options.hx @@ -335,13 +340,16 @@ qemu-options.texi: $(SRC_PATH)/qemu-options.hx
335 qemu-monitor.texi: $(SRC_PATH)/qemu-monitor.hx 340 qemu-monitor.texi: $(SRC_PATH)/qemu-monitor.hx
336 $(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@," GEN $@") 341 $(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@," GEN $@")
337 342
  343 +qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx
  344 + $(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@," GEN $@")
  345 +
338 qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi 346 qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi
339 $(call quiet-command, \ 347 $(call quiet-command, \
340 perl -Ww -- $(SRC_PATH)/texi2pod.pl $< qemu.pod && \ 348 perl -Ww -- $(SRC_PATH)/texi2pod.pl $< qemu.pod && \
341 pod2man --section=1 --center=" " --release=" " qemu.pod > $@, \ 349 pod2man --section=1 --center=" " --release=" " qemu.pod > $@, \
342 " GEN $@") 350 " GEN $@")
343 351
344 -qemu-img.1: qemu-img.texi 352 +qemu-img.1: qemu-img.texi qemu-img-cmds.texi
345 $(call quiet-command, \ 353 $(call quiet-command, \
346 perl -Ww -- $(SRC_PATH)/texi2pod.pl $< qemu-img.pod && \ 354 perl -Ww -- $(SRC_PATH)/texi2pod.pl $< qemu-img.pod && \
347 pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@, \ 355 pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@, \
@@ -359,7 +367,7 @@ dvi: qemu-doc.dvi qemu-tech.dvi @@ -359,7 +367,7 @@ dvi: qemu-doc.dvi qemu-tech.dvi
359 367
360 html: qemu-doc.html qemu-tech.html 368 html: qemu-doc.html qemu-tech.html
361 369
362 -qemu-doc.dvi qemu-doc.html qemu-doc.info: qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-monitor.texi 370 +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
363 371
364 VERSION ?= $(shell cat VERSION) 372 VERSION ?= $(shell cat VERSION)
365 FILE = qemu-$(VERSION) 373 FILE = qemu-$(VERSION)
qemu-img-cmds.hx 0 → 100644
  1 +HXCOMM Use DEFHEADING() to define headings in both help text and texi
  2 +HXCOMM Text between STEXI and ETEXI are copied to texi version and
  3 +HXCOMM discarded from C version
  4 +HXCOMM DEF(command, callback, arg_string) is used to construct
  5 +HXCOMM command structures and help message.
  6 +HXCOMM HXCOMM can be used for comments, discarded from both texi and C
  7 +
  8 +STEXI
  9 +@table @option
  10 +STEXI
  11 +
  12 +DEF("check", img_check,
  13 + "check [-f fmt] filename")
  14 +STEXI
  15 +@item check [-f @var{fmt}] @var{filename}
  16 +ETEXI
  17 +
  18 +DEF("create", img_create,
  19 + "create [-F fmt] [-b base_image] [-f fmt] [-o options] filename [size]")
  20 +STEXI
  21 +@item create [-F @var{base_fmt}] [-b @var{base_image}] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]
  22 +ETEXI
  23 +
  24 +DEF("commit", img_commit,
  25 + "commit [-f fmt] filename")
  26 +STEXI
  27 +@item commit [-f @var{fmt}] @var{filename}
  28 +ETEXI
  29 +
  30 +DEF("convert", img_convert,
  31 + "convert [-c] [-f fmt] [-O output_fmt] [-o options] [-B output_base_image] filename [filename2 [...]] output_filename")
  32 +STEXI
  33 +@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}
  34 +ETEXI
  35 +
  36 +DEF("info", img_info,
  37 + "info [-f fmt] filename")
  38 +STEXI
  39 +@item info [-f @var{fmt}] @var{filename}
  40 +ETEXI
  41 +
  42 +DEF("snapshot", img_snapshot,
  43 + "snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename")
  44 +STEXI
  45 +@item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
  46 +@end table
  47 +ETEXI
qemu-img.c
@@ -31,6 +31,11 @@ @@ -31,6 +31,11 @@
31 #include <windows.h> 31 #include <windows.h>
32 #endif 32 #endif
33 33
  34 +typedef struct img_cmd_t {
  35 + const char *name;
  36 + int (*handler)(int argc, char **argv);
  37 +} img_cmd_t;
  38 +
34 /* Default to cache=writeback as data integrity is not important for qemu-tcg. */ 39 /* Default to cache=writeback as data integrity is not important for qemu-tcg. */
35 #define BRDV_O_FLAGS BDRV_O_CACHE_WB 40 #define BRDV_O_FLAGS BDRV_O_CACHE_WB
36 41
@@ -58,12 +63,11 @@ static void help(void) @@ -58,12 +63,11 @@ static void help(void)
58 "QEMU disk image utility\n" 63 "QEMU disk image utility\n"
59 "\n" 64 "\n"
60 "Command syntax:\n" 65 "Command syntax:\n"
61 - " check [-f fmt] filename\n"  
62 - " create [-F fmt] [-b base_image] [-f fmt] [-o options] filename [size]\n"  
63 - " commit [-f fmt] filename\n"  
64 - " convert [-c] [-f fmt] [-O output_fmt] [-o options] [-B output_base_image] filename [filename2 [...]] output_filename\n"  
65 - " info [-f fmt] filename\n"  
66 - " snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename\n" 66 +#define DEF(option, callback, arg_string) \
  67 + " " arg_string "\n"
  68 +#include "qemu-img-cmds.h"
  69 +#undef DEF
  70 +#undef GEN_DOCS
67 "\n" 71 "\n"
68 "Command parameters:\n" 72 "Command parameters:\n"
69 " 'filename' is a disk image filename\n" 73 " 'filename' is a disk image filename\n"
@@ -919,7 +923,7 @@ static int img_info(int argc, char **argv) @@ -919,7 +923,7 @@ static int img_info(int argc, char **argv)
919 #define SNAPSHOT_APPLY 3 923 #define SNAPSHOT_APPLY 3
920 #define SNAPSHOT_DELETE 4 924 #define SNAPSHOT_DELETE 4
921 925
922 -static void img_snapshot(int argc, char **argv) 926 +static int img_snapshot(int argc, char **argv)
923 { 927 {
924 BlockDriverState *bs; 928 BlockDriverState *bs;
925 QEMUSnapshotInfo sn; 929 QEMUSnapshotInfo sn;
@@ -936,18 +940,18 @@ static void img_snapshot(int argc, char **argv) @@ -936,18 +940,18 @@ static void img_snapshot(int argc, char **argv)
936 switch(c) { 940 switch(c) {
937 case 'h': 941 case 'h':
938 help(); 942 help();
939 - return; 943 + return 0;
940 case 'l': 944 case 'l':
941 if (action) { 945 if (action) {
942 help(); 946 help();
943 - return; 947 + return 0;
944 } 948 }
945 action = SNAPSHOT_LIST; 949 action = SNAPSHOT_LIST;
946 break; 950 break;
947 case 'a': 951 case 'a':
948 if (action) { 952 if (action) {
949 help(); 953 help();
950 - return; 954 + return 0;
951 } 955 }
952 action = SNAPSHOT_APPLY; 956 action = SNAPSHOT_APPLY;
953 snapshot_name = optarg; 957 snapshot_name = optarg;
@@ -955,7 +959,7 @@ static void img_snapshot(int argc, char **argv) @@ -955,7 +959,7 @@ static void img_snapshot(int argc, char **argv)
955 case 'c': 959 case 'c':
956 if (action) { 960 if (action) {
957 help(); 961 help();
958 - return; 962 + return 0;
959 } 963 }
960 action = SNAPSHOT_CREATE; 964 action = SNAPSHOT_CREATE;
961 snapshot_name = optarg; 965 snapshot_name = optarg;
@@ -963,7 +967,7 @@ static void img_snapshot(int argc, char **argv) @@ -963,7 +967,7 @@ static void img_snapshot(int argc, char **argv)
963 case 'd': 967 case 'd':
964 if (action) { 968 if (action) {
965 help(); 969 help();
966 - return; 970 + return 0;
967 } 971 }
968 action = SNAPSHOT_DELETE; 972 action = SNAPSHOT_DELETE;
969 snapshot_name = optarg; 973 snapshot_name = optarg;
@@ -1021,31 +1025,38 @@ static void img_snapshot(int argc, char **argv) @@ -1021,31 +1025,38 @@ static void img_snapshot(int argc, char **argv)
1021 1025
1022 /* Cleanup */ 1026 /* Cleanup */
1023 bdrv_delete(bs); 1027 bdrv_delete(bs);
  1028 +
  1029 + return 0;
1024 } 1030 }
1025 1031
  1032 +static const img_cmd_t img_cmds[] = {
  1033 +#define DEF(option, callback, arg_string) \
  1034 + { option, callback },
  1035 +#include "qemu-img-cmds.h"
  1036 +#undef DEF
  1037 +#undef GEN_DOCS
  1038 + { NULL, NULL, },
  1039 +};
  1040 +
1026 int main(int argc, char **argv) 1041 int main(int argc, char **argv)
1027 { 1042 {
1028 - const char *cmd; 1043 + const img_cmd_t *cmd;
  1044 + const char *cmdname;
1029 1045
1030 bdrv_init(); 1046 bdrv_init();
1031 if (argc < 2) 1047 if (argc < 2)
1032 help(); 1048 help();
1033 - cmd = argv[1]; 1049 + cmdname = argv[1];
1034 argc--; argv++; 1050 argc--; argv++;
1035 - if (!strcmp(cmd, "create")) {  
1036 - img_create(argc, argv);  
1037 - } else if (!strcmp(cmd, "check")) {  
1038 - img_check(argc, argv);  
1039 - } else if (!strcmp(cmd, "commit")) {  
1040 - img_commit(argc, argv);  
1041 - } else if (!strcmp(cmd, "convert")) {  
1042 - img_convert(argc, argv);  
1043 - } else if (!strcmp(cmd, "info")) {  
1044 - img_info(argc, argv);  
1045 - } else if (!strcmp(cmd, "snapshot")) {  
1046 - img_snapshot(argc, argv);  
1047 - } else {  
1048 - help(); 1051 +
  1052 + /* find the command */
  1053 + for(cmd = img_cmds; cmd->name != NULL; cmd++) {
  1054 + if (!strcmp(cmdname, cmd->name)) {
  1055 + return cmd->handler(argc, argv);
  1056 + }
1049 } 1057 }
  1058 +
  1059 + /* not found */
  1060 + help();
1050 return 0; 1061 return 0;
1051 } 1062 }
qemu-img.texi
@@ -7,13 +7,8 @@ usage: qemu-img command [command options] @@ -7,13 +7,8 @@ usage: qemu-img command [command options]
7 @c man begin OPTIONS 7 @c man begin OPTIONS
8 8
9 The following commands are supported: 9 The following commands are supported:
10 -@table @option  
11 -@item create [-F @var{base_fmt}] [-b @var{base_image}] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]  
12 -@item commit [-f @var{fmt}] @var{filename}  
13 -@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}  
14 -@item info [-f @var{fmt}] @var{filename}  
15 -@item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}  
16 -@end table 10 +
  11 +@include qemu-img-cmds.texi
17 12
18 Command parameters: 13 Command parameters:
19 @table @var 14 @table @var