summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-04-17 12:33:31 +0100
committerRichard Jones <rjones@redhat.com>2010-04-17 12:33:31 +0100
commit4f376dbafb78ee9b5ad1652360472a14de64753d (patch)
treedb16772e0033106c53d9d183eaef583a7515961d
parente64c1e5aacd605ea177972e56ede5be22ae13d4f (diff)
downloadlibguestfs-4f376dbafb78ee9b5ad1652360472a14de64753d.tar.gz
libguestfs-4f376dbafb78ee9b5ad1652360472a14de64753d.tar.xz
libguestfs-4f376dbafb78ee9b5ad1652360472a14de64753d.zip
fish: Print output from some commands in octal/hex as approp. (RHBZ#583242).
-rw-r--r--fish/guestfish.pod4
-rwxr-xr-xsrc/generator.ml38
2 files changed, 36 insertions, 6 deletions
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
index e5f0bbaa..dfacf6f1 100644
--- a/fish/guestfish.pod
+++ b/fish/guestfish.pod
@@ -313,7 +313,9 @@ the Unix L<chmod(1)> program):
chmod 0777 /public # OK
chmod 777 /public # WRONG! This is mode 777 decimal = 01411 octal.
-Commands that return numbers currently always print them in decimal.
+Commands that return numbers usually print them in decimal, but
+some commands print numbers in other radices (eg. C<umask> prints
+the mode in octal, preceeded by C<0>).
=head1 WILDCARDS AND GLOBBING
diff --git a/src/generator.ml b/src/generator.ml
index 279272e8..87855e7d 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -182,11 +182,16 @@ type flags =
| DangerWillRobinson (* flags particularly dangerous commands *)
| FishAlias of string (* provide an alias for this cmd in guestfish *)
| FishAction of string (* call this function in guestfish *)
+ | FishOutput of fish_output_t (* how to display output in guestfish *)
| NotInFish (* do not export via guestfish *)
| NotInDocs (* do not add this function to documentation *)
| DeprecatedBy of string (* function is deprecated, use .. instead *)
| Optional of string (* function is part of an optional group *)
+and fish_output_t =
+ | FishOutputOctal (* for int return, print in octal *)
+ | FishOutputHexadecimal (* for int return, print in hex *)
+
(* You can supply zero or as many tests as you want per API call.
*
* Note that the test environment has 3 block devices, of size 500MB,
@@ -2250,7 +2255,7 @@ to return the existing UUID of a filesystem.");
This returns the ext2/3/4 filesystem UUID of the filesystem on
C<device>.");
- ("fsck", (RInt "status", [String "fstype"; Device "device"]), 84, [],
+ ("fsck", (RInt "status", [String "fstype"; Device "device"]), 84, [FishOutput FishOutputHexadecimal],
[InitBasicFS, Always, TestOutputInt (
[["umount"; "/dev/sda1"];
["fsck"; "ext2"; "/dev/sda1"]], 0);
@@ -3012,7 +3017,7 @@ This call creates a char device node called C<path> with
mode C<mode> and device major/minor C<devmajor> and C<devminor>.
It is just a convenient wrapper around C<guestfs_mknod>.");
- ("umask", (RInt "oldmask", [Int "mask"]), 137, [],
+ ("umask", (RInt "oldmask", [Int "mask"]), 137, [FishOutput FishOutputOctal],
[], (* XXX umask is one of those stateful things that we should
* reset between each test.
*)
@@ -4419,7 +4424,7 @@ C<device> has the bootable flag set.
See also C<guestfs_part_set_bootable>.");
- ("part_get_mbr_id", (RInt "idbyte", [Device "device"; Int "partnum"]), 235, [],
+ ("part_get_mbr_id", (RInt "idbyte", [Device "device"; Int "partnum"]), 235, [FishOutput FishOutputHexadecimal],
[InitEmpty, Always, TestOutputInt (
[["part_init"; "/dev/sda"; "mbr"];
["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
@@ -7446,16 +7451,39 @@ and generate_fish_cmds () =
pr " free_strings (%s);\n" name
) (snd style);
+ (* Any output flags? *)
+ let fish_output =
+ let flags = filter_map (
+ function FishOutput flag -> Some flag | _ -> None
+ ) flags in
+ match flags with
+ | [] -> None
+ | [f] -> Some f
+ | _ ->
+ failwithf "%s: more than one FishOutput flag is not allowed" name in
+
(* Check return value for errors and display command results. *)
(match fst style with
| RErr -> pr " return r;\n"
| RInt _ ->
pr " if (r == -1) return -1;\n";
- pr " printf (\"%%d\\n\", r);\n";
+ (match fish_output with
+ | None ->
+ pr " printf (\"%%d\\n\", r);\n";
+ | Some FishOutputOctal ->
+ pr " printf (\"%%s%%o\\n\", r != 0 ? \"0\" : \"\", r);\n";
+ | Some FishOutputHexadecimal ->
+ pr " printf (\"%%s%%x\\n\", r != 0 ? \"0x\" : \"\", r);\n");
pr " return 0;\n"
| RInt64 _ ->
pr " if (r == -1) return -1;\n";
- pr " printf (\"%%\" PRIi64 \"\\n\", r);\n";
+ (match fish_output with
+ | None ->
+ pr " printf (\"%%\" PRIi64 \"\\n\", r);\n";
+ | Some FishOutputOctal ->
+ pr " printf (\"%%s%%\" PRIo64 \"\\n\", r != 0 ? \"0\" : \"\", r);\n";
+ | Some FishOutputHexadecimal ->
+ pr " printf (\"%%s%%\" PRIx64 \"\\n\", r != 0 ? \"0x\" : \"\", r);\n");
pr " return 0;\n"
| RBool _ ->
pr " if (r == -1) return -1;\n";