Change Err -> RErr for consistency with other return types.
[libguestfs.git] / src / generator.ml
index 54c691b..067ac90 100755 (executable)
@@ -25,7 +25,7 @@
  * After editing this file, run it (./src/generator.ml) to regenerate
  * all the output files.
  *
  * After editing this file, run it (./src/generator.ml) to regenerate
  * all the output files.
  *
- * IMPORTANT: This script should not print any warnings.  If it prints
+ * IMPORTANT: This script should NOT print any warnings.  If it prints
  * warnings, you should treat them as errors.
  * [Need to add -warn-error to ocaml command line]
  *)
  * warnings, you should treat them as errors.
  * [Need to add -warn-error to ocaml command line]
  *)
@@ -36,10 +36,10 @@ open Printf
 
 type style = ret * args
 and ret =
 
 type style = ret * args
 and ret =
-    (* "Err" as a return value means an int used as a simple error
+    (* "RErr" as a return value means an int used as a simple error
      * indication, ie. 0 or -1.
      *)
      * indication, ie. 0 or -1.
      *)
-  | Err
+  | RErr
     (* "RInt" as a return value means an int which is -1 for error
      * or any value >= 0 on success.
      *)
     (* "RInt" as a return value means an int which is -1 for error
      * or any value >= 0 on success.
      *)
@@ -63,12 +63,7 @@ and ret =
   | RPVList of string
   | RVGList of string
   | RLVList of string
   | RPVList of string
   | RVGList of string
   | RLVList of string
-and args =
-    (* 0 arguments, 1 argument, etc. The guestfs_h param is implicit. *)
-  | P0
-  | P1 of argt
-  | P2 of argt * argt
-  | P3 of argt * argt * argt
+and args = argt list   (* Function parameters, guestfs handle is implicit. *)
 and argt =
   | String of string   (* const char *name, cannot be NULL *)
   | OptString of string        (* const char *name, may be NULL *)
 and argt =
   | String of string   (* const char *name, cannot be NULL *)
   | OptString of string        (* const char *name, may be NULL *)
@@ -90,7 +85,7 @@ type flags =
  *)
 
 let non_daemon_functions = [
  *)
 
 let non_daemon_functions = [
-  ("launch", (Err, P0), -1, [FishAlias "run"; FishAction "launch"],
+  ("launch", (RErr, []), -1, [FishAlias "run"; FishAction "launch"],
    "launch the qemu subprocess",
    "\
 Internally libguestfs is implemented by running a virtual machine
    "launch the qemu subprocess",
    "\
 Internally libguestfs is implemented by running a virtual machine
@@ -99,7 +94,7 @@ using L<qemu(1)>.
 You should call this after configuring the handle
 (eg. adding drives) but before performing any actions.");
 
 You should call this after configuring the handle
 (eg. adding drives) but before performing any actions.");
 
-  ("wait_ready", (Err, P0), -1, [NotInFish],
+  ("wait_ready", (RErr, []), -1, [NotInFish],
    "wait until the qemu subprocess launches",
    "\
 Internally libguestfs is implemented by running a virtual machine
    "wait until the qemu subprocess launches",
    "\
 Internally libguestfs is implemented by running a virtual machine
@@ -108,12 +103,12 @@ using L<qemu(1)>.
 You should call this after C<guestfs_launch> to wait for the launch
 to complete.");
 
 You should call this after C<guestfs_launch> to wait for the launch
 to complete.");
 
-  ("kill_subprocess", (Err, P0), -1, [],
+  ("kill_subprocess", (RErr, []), -1, [],
    "kill the qemu subprocess",
    "\
 This kills the qemu subprocess.  You should never need to call this.");
 
    "kill the qemu subprocess",
    "\
 This kills the qemu subprocess.  You should never need to call this.");
 
-  ("add_drive", (Err, P1 (String "filename")), -1, [FishAlias "add"],
+  ("add_drive", (RErr, [String "filename"]), -1, [FishAlias "add"],
    "add an image to examine or modify",
    "\
 This function adds a virtual machine disk image C<filename> to the
    "add an image to examine or modify",
    "\
 This function adds a virtual machine disk image C<filename> to the
@@ -129,14 +124,14 @@ image).
 
 This is equivalent to the qemu parameter C<-drive file=filename>.");
 
 
 This is equivalent to the qemu parameter C<-drive file=filename>.");
 
-  ("add_cdrom", (Err, P1 (String "filename")), -1, [FishAlias "cdrom"],
+  ("add_cdrom", (RErr, [String "filename"]), -1, [FishAlias "cdrom"],
    "add a CD-ROM disk image to examine",
    "\
 This function adds a virtual CD-ROM disk image to the guest.
 
 This is equivalent to the qemu parameter C<-cdrom filename>.");
 
    "add a CD-ROM disk image to examine",
    "\
 This function adds a virtual CD-ROM disk image to the guest.
 
 This is equivalent to the qemu parameter C<-cdrom filename>.");
 
-  ("config", (Err, P2 (String "qemuparam", OptString "qemuvalue")), -1, [],
+  ("config", (RErr, [String "qemuparam"; OptString "qemuvalue"]), -1, [],
    "add qemu parameters",
    "\
 This can be used to add arbitrary qemu command line parameters
    "add qemu parameters",
    "\
 This can be used to add arbitrary qemu command line parameters
@@ -148,7 +143,7 @@ The first character of C<param> string must be a C<-> (dash).
 
 C<value> can be NULL.");
 
 
 C<value> can be NULL.");
 
-  ("set_path", (Err, P1 (String "path")), -1, [FishAlias "path"],
+  ("set_path", (RErr, [String "path"]), -1, [FishAlias "path"],
    "set the search path",
    "\
 Set the path that libguestfs searches for kernel and initrd.img.
    "set the search path",
    "\
 Set the path that libguestfs searches for kernel and initrd.img.
@@ -161,7 +156,7 @@ must make sure it remains valid for the lifetime of the handle.
 
 Setting C<path> to C<NULL> restores the default path.");
 
 
 Setting C<path> to C<NULL> restores the default path.");
 
-  ("get_path", (RConstString "path", P0), -1, [],
+  ("get_path", (RConstString "path", []), -1, [],
    "get the search path",
    "\
 Return the current search path.
    "get the search path",
    "\
 Return the current search path.
@@ -169,19 +164,19 @@ Return the current search path.
 This is always non-NULL.  If it wasn't set already, then this will
 return the default path.");
 
 This is always non-NULL.  If it wasn't set already, then this will
 return the default path.");
 
-  ("set_autosync", (Err, P1 (Bool "autosync")), -1, [FishAlias "autosync"],
+  ("set_autosync", (RErr, [Bool "autosync"]), -1, [FishAlias "autosync"],
    "set autosync mode",
    "\
 If C<autosync> is true, this enables autosync.  Libguestfs will make a
 best effort attempt to run C<guestfs_sync> when the handle is closed
 (also if the program exits without closing handles).");
 
    "set autosync mode",
    "\
 If C<autosync> is true, this enables autosync.  Libguestfs will make a
 best effort attempt to run C<guestfs_sync> when the handle is closed
 (also if the program exits without closing handles).");
 
-  ("get_autosync", (RBool "autosync", P0), -1, [],
+  ("get_autosync", (RBool "autosync", []), -1, [],
    "get autosync mode",
    "\
 Get the autosync flag.");
 
    "get autosync mode",
    "\
 Get the autosync flag.");
 
-  ("set_verbose", (Err, P1 (Bool "verbose")), -1, [FishAlias "verbose"],
+  ("set_verbose", (RErr, [Bool "verbose"]), -1, [FishAlias "verbose"],
    "set verbose mode",
    "\
 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
    "set verbose mode",
    "\
 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
@@ -189,14 +184,14 @@ If C<verbose> is true, this turns on verbose messages (to C<stderr>).
 Verbose messages are disabled unless the environment variable
 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
 
 Verbose messages are disabled unless the environment variable
 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
 
-  ("get_verbose", (RBool "verbose", P0), -1, [],
+  ("get_verbose", (RBool "verbose", []), -1, [],
    "get verbose mode",
    "\
 This returns the verbose messages flag.")
 ]
 
 let daemon_functions = [
    "get verbose mode",
    "\
 This returns the verbose messages flag.")
 ]
 
 let daemon_functions = [
-  ("mount", (Err, P2 (String "device", String "mountpoint")), 1, [],
+  ("mount", (RErr, [String "device"; String "mountpoint"]), 1, [],
    "mount a guest disk at a position in the filesystem",
    "\
 Mount a guest disk at a position in the filesystem.  Block devices
    "mount a guest disk at a position in the filesystem",
    "\
 Mount a guest disk at a position in the filesystem.  Block devices
@@ -216,7 +211,7 @@ on the underlying device.
 The filesystem options C<sync> and C<noatime> are set with this
 call, in order to improve reliability.");
 
 The filesystem options C<sync> and C<noatime> are set with this
 call, in order to improve reliability.");
 
-  ("sync", (Err, P0), 2, [],
+  ("sync", (RErr, []), 2, [],
    "sync disks, writes are flushed through to the disk image",
    "\
 This syncs the disk, so that any writes are flushed through to the
    "sync disks, writes are flushed through to the disk image",
    "\
 This syncs the disk, so that any writes are flushed through to the
@@ -225,14 +220,14 @@ underlying disk image.
 You should always call this if you have modified a disk image, before
 closing the handle.");
 
 You should always call this if you have modified a disk image, before
 closing the handle.");
 
-  ("touch", (Err, P1 (String "path")), 3, [],
+  ("touch", (RErr, [String "path"]), 3, [],
    "update file timestamps or create a new file",
    "\
 Touch acts like the L<touch(1)> command.  It can be used to
 update the timestamps on a file, or, if the file does not exist,
 to create a new zero-length file.");
 
    "update file timestamps or create a new file",
    "\
 Touch acts like the L<touch(1)> command.  It can be used to
 update the timestamps on a file, or, if the file does not exist,
 to create a new zero-length file.");
 
-  ("cat", (RString "content", P1 (String "path")), 4, [ProtocolLimitWarning],
+  ("cat", (RString "content", [String "path"]), 4, [ProtocolLimitWarning],
    "list the contents of a file",
    "\
 Return the contents of the file named C<path>.
    "list the contents of a file",
    "\
 Return the contents of the file named C<path>.
@@ -242,7 +237,7 @@ Note that this function cannot correctly handle binary files
 as end of string).  For those you need to use the C<guestfs_read_file>
 function which has a more complex interface.");
 
 as end of string).  For those you need to use the C<guestfs_read_file>
 function which has a more complex interface.");
 
-  ("ll", (RString "listing", P1 (String "directory")), 5, [],
+  ("ll", (RString "listing", [String "directory"]), 5, [],
    "list the files in a directory (long format)",
    "\
 List the files in C<directory> (relative to the root directory,
    "list the files in a directory (long format)",
    "\
 List the files in C<directory> (relative to the root directory,
@@ -251,7 +246,7 @@ there is no cwd) in the format of 'ls -la'.
 This command is mostly useful for interactive sessions.  It
 is I<not> intended that you try to parse the output string.");
 
 This command is mostly useful for interactive sessions.  It
 is I<not> intended that you try to parse the output string.");
 
-  ("ls", (RStringList "listing", P1 (String "directory")), 6, [],
+  ("ls", (RStringList "listing", [String "directory"]), 6, [],
    "list the files in a directory",
    "\
 List the files in C<directory> (relative to the root directory,
    "list the files in a directory",
    "\
 List the files in C<directory> (relative to the root directory,
@@ -261,14 +256,14 @@ hidden files are shown.
 This command is mostly useful for interactive sessions.  Programs
 should probably use C<guestfs_readdir> instead.");
 
 This command is mostly useful for interactive sessions.  Programs
 should probably use C<guestfs_readdir> instead.");
 
-  ("list_devices", (RStringList "devices", P0), 7, [],
+  ("list_devices", (RStringList "devices", []), 7, [],
    "list the block devices",
    "\
 List all the block devices.
 
 The full block device names are returned, eg. C</dev/sda>");
 
    "list the block devices",
    "\
 List all the block devices.
 
 The full block device names are returned, eg. C</dev/sda>");
 
-  ("list_partitions", (RStringList "partitions", P0), 8, [],
+  ("list_partitions", (RStringList "partitions", []), 8, [],
    "list the partitions",
    "\
 List all the partitions detected on all block devices.
    "list the partitions",
    "\
 List all the partitions detected on all block devices.
@@ -278,7 +273,7 @@ The full partition device names are returned, eg. C</dev/sda1>
 This does not return logical volumes.  For that you will need to
 call C<guestfs_lvs>.");
 
 This does not return logical volumes.  For that you will need to
 call C<guestfs_lvs>.");
 
-  ("pvs", (RStringList "physvols", P0), 9, [],
+  ("pvs", (RStringList "physvols", []), 9, [],
    "list the LVM physical volumes (PVs)",
    "\
 List all the physical volumes detected.  This is the equivalent
    "list the LVM physical volumes (PVs)",
    "\
 List all the physical volumes detected.  This is the equivalent
@@ -289,7 +284,7 @@ PVs (eg. C</dev/sda2>).
 
 See also C<guestfs_pvs_full>.");
 
 
 See also C<guestfs_pvs_full>.");
 
-  ("vgs", (RStringList "volgroups", P0), 10, [],
+  ("vgs", (RStringList "volgroups", []), 10, [],
    "list the LVM volume groups (VGs)",
    "\
 List all the volumes groups detected.  This is the equivalent
    "list the LVM volume groups (VGs)",
    "\
 List all the volumes groups detected.  This is the equivalent
@@ -300,7 +295,7 @@ detected (eg. C<VolGroup00>).
 
 See also C<guestfs_vgs_full>.");
 
 
 See also C<guestfs_vgs_full>.");
 
-  ("lvs", (RStringList "logvols", P0), 11, [],
+  ("lvs", (RStringList "logvols", []), 11, [],
    "list the LVM logical volumes (LVs)",
    "\
 List all the logical volumes detected.  This is the equivalent
    "list the LVM logical volumes (LVs)",
    "\
 List all the logical volumes detected.  This is the equivalent
@@ -311,25 +306,25 @@ This returns a list of the logical volume device names
 
 See also C<guestfs_lvs_full>.");
 
 
 See also C<guestfs_lvs_full>.");
 
-  ("pvs_full", (RPVList "physvols", P0), 12, [],
+  ("pvs_full", (RPVList "physvols", []), 12, [],
    "list the LVM physical volumes (PVs)",
    "\
 List all the physical volumes detected.  This is the equivalent
 of the L<pvs(8)> command.  The \"full\" version includes all fields.");
 
    "list the LVM physical volumes (PVs)",
    "\
 List all the physical volumes detected.  This is the equivalent
 of the L<pvs(8)> command.  The \"full\" version includes all fields.");
 
-  ("vgs_full", (RVGList "volgroups", P0), 13, [],
+  ("vgs_full", (RVGList "volgroups", []), 13, [],
    "list the LVM volume groups (VGs)",
    "\
 List all the volumes groups detected.  This is the equivalent
 of the L<vgs(8)> command.  The \"full\" version includes all fields.");
 
    "list the LVM volume groups (VGs)",
    "\
 List all the volumes groups detected.  This is the equivalent
 of the L<vgs(8)> command.  The \"full\" version includes all fields.");
 
-  ("lvs_full", (RLVList "logvols", P0), 14, [],
+  ("lvs_full", (RLVList "logvols", []), 14, [],
    "list the LVM logical volumes (LVs)",
    "\
 List all the logical volumes detected.  This is the equivalent
 of the L<lvs(8)> command.  The \"full\" version includes all fields.");
 
    "list the LVM logical volumes (LVs)",
    "\
 List all the logical volumes detected.  This is the equivalent
 of the L<lvs(8)> command.  The \"full\" version includes all fields.");
 
-  ("read_lines", (RStringList "lines", P1 (String "path")), 15, [],
+  ("read_lines", (RStringList "lines", [String "path"]), 15, [],
    "read file as lines",
    "\
 Return the contents of the file named C<path>.
    "read file as lines",
    "\
 Return the contents of the file named C<path>.
@@ -342,7 +337,7 @@ Note that this function cannot correctly handle binary files
 as end of line).  For those you need to use the C<guestfs_read_file>
 function which has a more complex interface.");
 
 as end of line).  For those you need to use the C<guestfs_read_file>
 function which has a more complex interface.");
 
-  ("aug_init", (Err, P2 (String "root", Int "flags")), 16, [],
+  ("aug_init", (RErr, [String "root"; Int "flags"]), 16, [],
    "create a new Augeas handle",
    "\
 Create a new Augeas handle for editing configuration files.
    "create a new Augeas handle",
    "\
 Create a new Augeas handle for editing configuration files.
@@ -392,7 +387,7 @@ To close the handle, you can call C<guestfs_aug_close>.
 
 To find out more about Augeas, see L<http://augeas.net/>.");
 
 
 To find out more about Augeas, see L<http://augeas.net/>.");
 
-  ("aug_close", (Err, P0), 26, [],
+  ("aug_close", (RErr, []), 26, [],
    "close the current Augeas handle",
    "\
 Close the current Augeas handle and free up any resources
    "close the current Augeas handle",
    "\
 Close the current Augeas handle and free up any resources
@@ -400,7 +395,7 @@ used by it.  After calling this, you have to call
 C<guestfs_aug_init> again before you can use any other
 Augeas functions.");
 
 C<guestfs_aug_init> again before you can use any other
 Augeas functions.");
 
-  ("aug_defvar", (RInt "nrnodes", P2 (String "name", OptString "expr")), 17, [],
+  ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"]), 17, [],
    "define an Augeas variable",
    "\
 Defines an Augeas variable C<name> whose value is the result
    "define an Augeas variable",
    "\
 Defines an Augeas variable C<name> whose value is the result
@@ -410,7 +405,7 @@ undefined.
 On success this returns the number of nodes in C<expr>, or
 C<0> if C<expr> evaluates to something which is not a nodeset.");
 
 On success this returns the number of nodes in C<expr>, or
 C<0> if C<expr> evaluates to something which is not a nodeset.");
 
-  ("aug_defnode", (RIntBool ("nrnodes", "created"), P3 (String "name", String "expr", String "val")), 18, [],
+  ("aug_defnode", (RIntBool ("nrnodes", "created"), [String "name"; String "expr"; String "val"]), 18, [],
    "define an Augeas node",
    "\
 Defines a variable C<name> whose value is the result of
    "define an Augeas node",
    "\
 Defines a variable C<name> whose value is the result of
@@ -424,18 +419,18 @@ On success this returns a pair containing the
 number of nodes in the nodeset, and a boolean flag
 if a node was created.");
 
 number of nodes in the nodeset, and a boolean flag
 if a node was created.");
 
-  ("aug_get", (RString "val", P1 (String "path")), 19, [],
+  ("aug_get", (RString "val", [String "path"]), 19, [],
    "look up the value of an Augeas path",
    "\
 Look up the value associated with C<path>.  If C<path>
 matches exactly one node, the C<value> is returned.");
 
    "look up the value of an Augeas path",
    "\
 Look up the value associated with C<path>.  If C<path>
 matches exactly one node, the C<value> is returned.");
 
-  ("aug_set", (Err, P2 (String "path", String "val")), 20, [],
+  ("aug_set", (RErr, [String "path"; String "val"]), 20, [],
    "set Augeas path to value",
    "\
 Set the value associated with C<path> to C<value>.");
 
    "set Augeas path to value",
    "\
 Set the value associated with C<path> to C<value>.");
 
-  ("aug_insert", (Err, P3 (String "path", String "label", Bool "before")), 21, [],
+  ("aug_insert", (RErr, [String "path"; String "label"; Bool "before"]), 21, [],
    "insert a sibling Augeas node",
    "\
 Create a new sibling C<label> for C<path>, inserting it into
    "insert a sibling Augeas node",
    "\
 Create a new sibling C<label> for C<path>, inserting it into
@@ -446,27 +441,27 @@ C<path> must match exactly one existing node in the tree, and
 C<label> must be a label, ie. not contain C</>, C<*> or end
 with a bracketed index C<[N]>.");
 
 C<label> must be a label, ie. not contain C</>, C<*> or end
 with a bracketed index C<[N]>.");
 
-  ("aug_rm", (RInt "nrnodes", P1 (String "path")), 22, [],
+  ("aug_rm", (RInt "nrnodes", [String "path"]), 22, [],
    "remove an Augeas path",
    "\
 Remove C<path> and all of its children.
 
 On success this returns the number of entries which were removed.");
 
    "remove an Augeas path",
    "\
 Remove C<path> and all of its children.
 
 On success this returns the number of entries which were removed.");
 
-  ("aug_mv", (Err, P2 (String "src", String "dest")), 23, [],
+  ("aug_mv", (RErr, [String "src"; String "dest"]), 23, [],
    "move Augeas node",
    "\
 Move the node C<src> to C<dest>.  C<src> must match exactly
 one node.  C<dest> is overwritten if it exists.");
 
    "move Augeas node",
    "\
 Move the node C<src> to C<dest>.  C<src> must match exactly
 one node.  C<dest> is overwritten if it exists.");
 
-  ("aug_match", (RStringList "matches", P1 (String "path")), 24, [],
+  ("aug_match", (RStringList "matches", [String "path"]), 24, [],
    "return Augeas nodes which match path",
    "\
 Returns a list of paths which match the path expression C<path>.
 The returned paths are sufficiently qualified so that they match
 exactly one node in the current tree.");
 
    "return Augeas nodes which match path",
    "\
 Returns a list of paths which match the path expression C<path>.
 The returned paths are sufficiently qualified so that they match
 exactly one node in the current tree.");
 
-  ("aug_save", (Err, P0), 25, [],
+  ("aug_save", (RErr, []), 25, [],
    "write all pending Augeas changes to disk",
    "\
 This writes all pending changes to disk.
    "write all pending Augeas changes to disk",
    "\
 This writes all pending changes to disk.
@@ -474,7 +469,7 @@ This writes all pending changes to disk.
 The flags which were passed to C<guestfs_aug_init> affect exactly
 how files are saved.");
 
 The flags which were passed to C<guestfs_aug_init> affect exactly
 how files are saved.");
 
-  ("aug_load", (Err, P0), 27, [],
+  ("aug_load", (RErr, []), 27, [],
    "load files into the tree",
    "\
 Load files into the tree.
    "load files into the tree",
    "\
 Load files into the tree.
@@ -482,11 +477,12 @@ Load files into the tree.
 See C<aug_load> in the Augeas documentation for the full gory
 details.");
 
 See C<aug_load> in the Augeas documentation for the full gory
 details.");
 
-  ("aug_ls", (RStringList "matches", P1 (String "path")), 28, [],
+  ("aug_ls", (RStringList "matches", [String "path"]), 28, [],
    "list Augeas nodes under a path",
    "\
 This is just a shortcut for listing C<guestfs_aug_match>
 C<path/*> and sorting the resulting nodes into alphabetical order.");
    "list Augeas nodes under a path",
    "\
 This is just a shortcut for listing C<guestfs_aug_match>
 C<path/*> and sorting the resulting nodes into alphabetical order.");
+
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions
@@ -621,45 +617,69 @@ let iteri f xs =
   in
   loop 0 xs
 
   in
   loop 0 xs
 
-(* 'pr' prints to the current output file. *)
-let chan = ref stdout
-let pr fs = ksprintf (output_string !chan) fs
-
-let iter_args f = function
-  | P0 -> ()
-  | P1 arg1 -> f arg1
-  | P2 (arg1, arg2) -> f arg1; f arg2
-  | P3 (arg1, arg2, arg3) -> f arg1; f arg2; f arg3
+let name_of_argt = function String n | OptString n | Bool n | Int n -> n
 
 
-let iteri_args f = function
-  | P0 -> ()
-  | P1 arg1 -> f 0 arg1
-  | P2 (arg1, arg2) -> f 0 arg1; f 1 arg2
-  | P3 (arg1, arg2, arg3) -> f 0 arg1; f 1 arg2; f 2 arg3
+(* Check function names etc. for consistency. *)
+let check_functions () =
+  let contains_uppercase str =
+    let len = String.length str in
+    let rec loop i =
+      if i >= len then false
+      else (
+       let c = str.[i] in
+       if c >= 'A' && c <= 'Z' then true
+       else loop (i+1)
+      )
+    in
+    loop 0
+  in
 
 
-let map_args f = function
-  | P0 -> []
-  | P1 arg1 -> [f arg1]
-  | P2 (arg1, arg2) ->
-      let n1 = f arg1 in let n2 = f arg2 in [n1; n2]
-  | P3 (arg1, arg2, arg3) ->
-      let n1 = f arg1 in let n2 = f arg2 in let n3 = f arg3 in [n1; n2; n3]
+  (* Check function names. *)
+  List.iter (
+    fun (name, _, _, _, _, _) ->
+      if String.length name >= 7 && String.sub name 0 7 = "guestfs" then
+       failwithf "function name %s does not need 'guestfs' prefix" name;
+      if contains_uppercase name then
+       failwithf "function name %s should not contain uppercase chars" name;
+      if String.contains name '-' then
+       failwithf "function name %s should not contain '-', use '_' instead."
+         name
+  ) all_functions;
 
 
-let nr_args = function | P0 -> 0 | P1 _ -> 1 | P2 _ -> 2 | P3 _ -> 3
+  (* Check function parameter/return names. *)
+  List.iter (
+    fun (name, style, _, _, _, _) ->
+      let check_arg_ret_name n =
+       if contains_uppercase n then
+         failwithf "%s param/ret %s should not contain uppercase chars"
+           name n;
+       if String.contains n '-' || String.contains n '_' then
+         failwithf "%s param/ret %s should not contain '-' or '_'"
+           name n;
+       if n = "value" then
+         failwithf "%s has a param/ret called 'value', which causes conflicts in the OCaml bindings, use something like 'val' or a more descriptive name" n
+      in
 
 
-let name_of_argt = function String n | OptString n | Bool n | Int n -> n
+      (match fst style with
+       | RErr -> ()
+       | RInt n | RBool n | RConstString n | RString n
+       | RStringList n | RPVList n | RVGList n | RLVList n ->
+          check_arg_ret_name n
+       | RIntBool (n,m) ->
+          check_arg_ret_name n;
+          check_arg_ret_name m
+      );
+      List.iter (fun arg -> check_arg_ret_name (name_of_argt arg)) (snd style)
+  ) all_functions;
 
 
-(* Check function names etc. for consistency. *)
-let check_functions () =
+  (* Check long dscriptions. *)
   List.iter (
     fun (name, _, _, _, _, longdesc) ->
   List.iter (
     fun (name, _, _, _, _, longdesc) ->
-      if String.contains name '-' then
-       failwithf "function name '%s' should not contain '-', use '_' instead."
-         name;
       if longdesc.[String.length longdesc-1] = '\n' then
        failwithf "long description of %s should not end with \\n." name
   ) all_functions;
 
       if longdesc.[String.length longdesc-1] = '\n' then
        failwithf "long description of %s should not end with \\n." name
   ) all_functions;
 
+  (* Check proc_nrs. *)
   List.iter (
     fun (name, _, proc_nr, _, _, _) ->
       if proc_nr <= 0 then
   List.iter (
     fun (name, _, proc_nr, _, _, _) ->
       if proc_nr <= 0 then
@@ -683,16 +703,20 @@ let check_functions () =
     | (name1,nr1) :: ((name2,nr2) :: _ as rest) when nr1 < nr2 ->
        loop rest
     | (name1,nr1) :: (name2,nr2) :: _ ->
     | (name1,nr1) :: ((name2,nr2) :: _ as rest) when nr1 < nr2 ->
        loop rest
     | (name1,nr1) :: (name2,nr2) :: _ ->
-       failwithf "'%s' and '%s' have conflicting procedure numbers (%d, %d)"
+       failwithf "%s and %s have conflicting procedure numbers (%d, %d)"
          name1 name2 nr1 nr2
   in
   loop proc_nrs
 
          name1 name2 nr1 nr2
   in
   loop proc_nrs
 
+(* 'pr' prints to the current output file. *)
+let chan = ref stdout
+let pr fs = ksprintf (output_string !chan) fs
+
+(* Generate a header block in a number of standard styles. *)
 type comment_style = CStyle | HashStyle | OCamlStyle
 type license = GPLv2 | LGPLv2
 
 type comment_style = CStyle | HashStyle | OCamlStyle
 type license = GPLv2 | LGPLv2
 
-(* Generate a header block in a number of standard styles. *)
-let rec generate_header comment license =
+let generate_header comment license =
   let c = match comment with
     | CStyle ->     pr "/* "; " *"
     | HashStyle ->  pr "# ";  "#"
   let c = match comment with
     | CStyle ->     pr "/* "; " *"
     | HashStyle ->  pr "# ";  "#"
@@ -741,8 +765,10 @@ let rec generate_header comment license =
   );
   pr "\n"
 
   );
   pr "\n"
 
+(* Start of main code generation functions below this line. *)
+
 (* Generate the pod documentation for the C API. *)
 (* Generate the pod documentation for the C API. *)
-and generate_actions_pod () =
+let rec generate_actions_pod () =
   List.iter (
     fun (shortname, style, _, flags, _, longdesc) ->
       let name = "guestfs_" ^ shortname in
   List.iter (
     fun (shortname, style, _, flags, _, longdesc) ->
       let name = "guestfs_" ^ shortname in
@@ -752,7 +778,7 @@ and generate_actions_pod () =
       pr "\n\n";
       pr "%s\n\n" longdesc;
       (match fst style with
       pr "\n\n";
       pr "%s\n\n" longdesc;
       (match fst style with
-       | Err ->
+       | RErr ->
           pr "This function returns 0 on success or -1 on error.\n\n"
        | RInt _ ->
           pr "On error this function returns -1.\n\n"
           pr "This function returns 0 on success or -1 on error.\n\n"
        | RInt _ ->
           pr "On error this function returns -1.\n\n"
@@ -770,16 +796,16 @@ I<The caller must free the returned string after use>.\n\n"
 I<The caller must free the strings and the array after use>.\n\n"
        | RIntBool _ ->
           pr "This function returns a C<struct guestfs_int_bool *>.
 I<The caller must free the strings and the array after use>.\n\n"
        | RIntBool _ ->
           pr "This function returns a C<struct guestfs_int_bool *>.
-I<The caller must call C<guestfs_free_int_bool> after use.>.\n\n"
+I<The caller must call C<guestfs_free_int_bool> after use>.\n\n"
        | RPVList _ ->
           pr "This function returns a C<struct guestfs_lvm_pv_list *>.
        | RPVList _ ->
           pr "This function returns a C<struct guestfs_lvm_pv_list *>.
-I<The caller must call C<guestfs_free_lvm_pv_list> after use.>.\n\n"
+I<The caller must call C<guestfs_free_lvm_pv_list> after use>.\n\n"
        | RVGList _ ->
           pr "This function returns a C<struct guestfs_lvm_vg_list *>.
        | RVGList _ ->
           pr "This function returns a C<struct guestfs_lvm_vg_list *>.
-I<The caller must call C<guestfs_free_lvm_vg_list> after use.>.\n\n"
+I<The caller must call C<guestfs_free_lvm_vg_list> after use>.\n\n"
        | RLVList _ ->
           pr "This function returns a C<struct guestfs_lvm_lv_list *>.
        | RLVList _ ->
           pr "This function returns a C<struct guestfs_lvm_lv_list *>.
-I<The caller must call C<guestfs_free_lvm_lv_list> after use.>.\n\n"
+I<The caller must call C<guestfs_free_lvm_lv_list> after use>.\n\n"
       );
       if List.mem ProtocolLimitWarning flags then
        pr "Because of the message protocol, there is a transfer limit 
       );
       if List.mem ProtocolLimitWarning flags then
        pr "Because of the message protocol, there is a transfer limit 
@@ -818,8 +844,9 @@ and generate_structs_pod () =
   ) ["pv", pv_cols; "vg", vg_cols; "lv", lv_cols]
 
 (* Generate the protocol (XDR) file, 'guestfs_protocol.x' and
   ) ["pv", pv_cols; "vg", vg_cols; "lv", lv_cols]
 
 (* Generate the protocol (XDR) file, 'guestfs_protocol.x' and
- * indirectly 'guestfs_protocol.h' and 'guestfs_protocol.c'.  We
- * have to use an underscore instead of a dash because otherwise
+ * indirectly 'guestfs_protocol.h' and 'guestfs_protocol.c'.
+ *
+ * We have to use an underscore instead of a dash because otherwise
  * rpcgen generates incorrect code.
  *
  * This header is NOT exported to clients, but see also generate_structs_h.
  * rpcgen generates incorrect code.
  *
  * This header is NOT exported to clients, but see also generate_structs_h.
@@ -854,10 +881,10 @@ and generate_xdr () =
       let name = "guestfs_" ^ shortname in
 
       (match snd style with
       let name = "guestfs_" ^ shortname in
 
       (match snd style with
-       | P0 -> ()
+       | [] -> ()
        | args ->
           pr "struct %s_args {\n" name;
        | args ->
           pr "struct %s_args {\n" name;
-          iter_args (
+          List.iter (
             function
             | String n -> pr "  string %s<>;\n" n
             | OptString n -> pr "  str *%s;\n" n
             function
             | String n -> pr "  string %s<>;\n" n
             | OptString n -> pr "  str *%s;\n" n
@@ -867,7 +894,7 @@ and generate_xdr () =
           pr "};\n\n"
       );
       (match fst style with
           pr "};\n\n"
       );
       (match fst style with
-       | Err -> ()
+       | RErr -> ()
        | RInt n ->
           pr "struct %s_ret {\n" name;
           pr "  int %s;\n" n;
        | RInt n ->
           pr "struct %s_ret {\n" name;
           pr "  int %s;\n" n;
@@ -1028,7 +1055,7 @@ and generate_client_actions () =
       pr "  struct guestfs_message_header hdr;\n";
       pr "  struct guestfs_message_error err;\n";
       (match fst style with
       pr "  struct guestfs_message_header hdr;\n";
       pr "  struct guestfs_message_error err;\n";
       (match fst style with
-       | Err -> ()
+       | RErr -> ()
        | RConstString _ ->
           failwithf "RConstString cannot be returned from a daemon function"
        | RInt _
        | RConstString _ ->
           failwithf "RConstString cannot be returned from a daemon function"
        | RInt _
@@ -1057,7 +1084,7 @@ and generate_client_actions () =
       pr "  }\n";
 
       (match fst style with
       pr "  }\n";
 
       (match fst style with
-       | Err -> ()
+       | RErr -> ()
        | RConstString _ ->
           failwithf "RConstString cannot be returned from a daemon function"
        | RInt _
        | RConstString _ ->
           failwithf "RConstString cannot be returned from a daemon function"
        | RInt _
@@ -1081,7 +1108,7 @@ and generate_client_actions () =
 
       let error_code =
        match fst style with
 
       let error_code =
        match fst style with
-       | Err | RInt _ | RBool _ -> "-1"
+       | RErr | RInt _ | RBool _ -> "-1"
        | RConstString _ ->
            failwithf "RConstString cannot be returned from a daemon function"
        | RString _ | RStringList _ | RIntBool _
        | RConstString _ ->
            failwithf "RConstString cannot be returned from a daemon function"
        | RString _ | RStringList _ | RIntBool _
@@ -1091,7 +1118,7 @@ and generate_client_actions () =
       pr "{\n";
 
       (match snd style with
       pr "{\n";
 
       (match snd style with
-       | P0 -> ()
+       | [] -> ()
        | _ -> pr "  struct %s_args args;\n" name
       );
 
        | _ -> pr "  struct %s_args args;\n" name
       );
 
@@ -1109,11 +1136,11 @@ and generate_client_actions () =
       pr "\n";
 
       (match snd style with
       pr "\n";
 
       (match snd style with
-       | P0 ->
+       | [] ->
           pr "  serial = dispatch (g, GUESTFS_PROC_%s, NULL, NULL);\n"
             (String.uppercase shortname)
        | args ->
           pr "  serial = dispatch (g, GUESTFS_PROC_%s, NULL, NULL);\n"
             (String.uppercase shortname)
        | args ->
-          iter_args (
+          List.iter (
             function
             | String n ->
                 pr "  args.%s = (char *) %s;\n" n n
             function
             | String n ->
                 pr "  args.%s = (char *) %s;\n" n n
@@ -1157,7 +1184,7 @@ and generate_client_actions () =
       pr "\n";
 
       (match fst style with
       pr "\n";
 
       (match fst style with
-       | Err -> pr "  return 0;\n"
+       | RErr -> pr "  return 0;\n"
        | RInt n
        | RBool n -> pr "  return rv.ret.%s;\n" n
        | RConstString _ ->
        | RInt n
        | RBool n -> pr "  return rv.ret.%s;\n" n
        | RConstString _ ->
@@ -1229,7 +1256,7 @@ and generate_daemon_actions () =
       pr "{\n";
       let error_code =
        match fst style with
       pr "{\n";
       let error_code =
        match fst style with
-       | Err | RInt _ -> pr "  int r;\n"; "-1"
+       | RErr | RInt _ -> pr "  int r;\n"; "-1"
        | RBool _ -> pr "  int r;\n"; "-1"
        | RConstString _ ->
            failwithf "RConstString cannot be returned from a daemon function"
        | RBool _ -> pr "  int r;\n"; "-1"
        | RConstString _ ->
            failwithf "RConstString cannot be returned from a daemon function"
@@ -1241,10 +1268,10 @@ and generate_daemon_actions () =
        | RLVList _ -> pr "  guestfs_lvm_int_lv_list *r;\n"; "NULL" in
 
       (match snd style with
        | RLVList _ -> pr "  guestfs_lvm_int_lv_list *r;\n"; "NULL" in
 
       (match snd style with
-       | P0 -> ()
+       | [] -> ()
        | args ->
           pr "  struct guestfs_%s_args args;\n" name;
        | args ->
           pr "  struct guestfs_%s_args args;\n" name;
-          iter_args (
+          List.iter (
             function
             | String n
             | OptString n -> pr "  const char *%s;\n" n
             function
             | String n
             | OptString n -> pr "  const char *%s;\n" n
@@ -1255,7 +1282,7 @@ and generate_daemon_actions () =
       pr "\n";
 
       (match snd style with
       pr "\n";
 
       (match snd style with
-       | P0 -> ()
+       | [] -> ()
        | args ->
           pr "  memset (&args, 0, sizeof args);\n";
           pr "\n";
        | args ->
           pr "  memset (&args, 0, sizeof args);\n";
           pr "\n";
@@ -1263,7 +1290,7 @@ and generate_daemon_actions () =
           pr "    reply_with_error (\"%%s: daemon failed to decode procedure arguments\", \"%s\");\n" name;
           pr "    return;\n";
           pr "  }\n";
           pr "    reply_with_error (\"%%s: daemon failed to decode procedure arguments\", \"%s\");\n" name;
           pr "    return;\n";
           pr "  }\n";
-          iter_args (
+          List.iter (
             function
             | String n -> pr "  %s = args.%s;\n" n n
             | OptString n -> pr "  %s = args.%s ? *args.%s : NULL;\n" n n n
             function
             | String n -> pr "  %s = args.%s;\n" n n
             | OptString n -> pr "  %s = args.%s ? *args.%s : NULL;\n" n n n
@@ -1283,7 +1310,7 @@ and generate_daemon_actions () =
       pr "\n";
 
       (match fst style with
       pr "\n";
 
       (match fst style with
-       | Err -> pr "  reply (NULL, NULL);\n"
+       | RErr -> pr "  reply (NULL, NULL);\n"
        | RInt n ->
           pr "  struct guestfs_%s_ret ret;\n" name;
           pr "  ret.%s = r;\n" n;
        | RInt n ->
           pr "  struct guestfs_%s_ret ret;\n" name;
           pr "  ret.%s = r;\n" n;
@@ -1560,10 +1587,10 @@ and generate_fish_cmds () =
       let longdesc = replace_str longdesc "C<guestfs_" "C<" in
       let synopsis =
        match snd style with
       let longdesc = replace_str longdesc "C<guestfs_" "C<" in
       let synopsis =
        match snd style with
-       | P0 -> name2
+       | [] -> name2
        | args ->
            sprintf "%s <%s>"
        | args ->
            sprintf "%s <%s>"
-             name2 (String.concat "> <" (map_args name_of_argt args)) in
+             name2 (String.concat "> <" (List.map name_of_argt args)) in
 
       let warnings =
        if List.mem ProtocolLimitWarning flags then
 
       let warnings =
        if List.mem ProtocolLimitWarning flags then
@@ -1638,7 +1665,7 @@ FTP."
       pr "static int run_%s (const char *cmd, int argc, char *argv[])\n" name;
       pr "{\n";
       (match fst style with
       pr "static int run_%s (const char *cmd, int argc, char *argv[])\n" name;
       pr "{\n";
       (match fst style with
-       | Err
+       | RErr
        | RInt _
        | RBool _ -> pr "  int r;\n"
        | RConstString _ -> pr "  const char *r;\n"
        | RInt _
        | RBool _ -> pr "  int r;\n"
        | RConstString _ -> pr "  const char *r;\n"
@@ -1649,7 +1676,7 @@ FTP."
        | RVGList _ -> pr "  struct guestfs_lvm_vg_list *r;\n"
        | RLVList _ -> pr "  struct guestfs_lvm_lv_list *r;\n"
       );
        | RVGList _ -> pr "  struct guestfs_lvm_vg_list *r;\n"
        | RLVList _ -> pr "  struct guestfs_lvm_lv_list *r;\n"
       );
-      iter_args (
+      List.iter (
        function
        | String n -> pr "  const char *%s;\n" n
        | OptString n -> pr "  const char *%s;\n" n
        function
        | String n -> pr "  const char *%s;\n" n
        | OptString n -> pr "  const char *%s;\n" n
@@ -1658,14 +1685,14 @@ FTP."
       ) (snd style);
 
       (* Check and convert parameters. *)
       ) (snd style);
 
       (* Check and convert parameters. *)
-      let argc_expected = nr_args (snd style) in
+      let argc_expected = List.length (snd style) in
       pr "  if (argc != %d) {\n" argc_expected;
       pr "    fprintf (stderr, \"%%s should have %d parameter(s)\\n\", cmd);\n"
        argc_expected;
       pr "    fprintf (stderr, \"type 'help %%s' for help on %%s\\n\", cmd, cmd);\n";
       pr "    return -1;\n";
       pr "  }\n";
       pr "  if (argc != %d) {\n" argc_expected;
       pr "    fprintf (stderr, \"%%s should have %d parameter(s)\\n\", cmd);\n"
        argc_expected;
       pr "    fprintf (stderr, \"type 'help %%s' for help on %%s\\n\", cmd, cmd);\n";
       pr "    return -1;\n";
       pr "  }\n";
-      iteri_args (
+      iteri (
        fun i ->
          function
          | String name -> pr "  %s = argv[%d];\n" name i
        fun i ->
          function
          | String name -> pr "  %s = argv[%d];\n" name i
@@ -1688,7 +1715,7 @@ FTP."
 
       (* Check return value for errors and display command results. *)
       (match fst style with
 
       (* Check return value for errors and display command results. *)
       (match fst style with
-       | Err -> pr "  return r;\n"
+       | RErr -> pr "  return r;\n"
        | RInt _ ->
           pr "  if (r == -1) return -1;\n";
           pr "  if (r) printf (\"%%d\\n\", r);\n";
        | RInt _ ->
           pr "  if (r == -1) return -1;\n";
           pr "  if (r) printf (\"%%d\\n\", r);\n";
@@ -1785,7 +1812,7 @@ and generate_fish_actions_pod () =
       pr "\n";
       pr "\n";
       pr " %s" name;
       pr "\n";
       pr "\n";
       pr " %s" name;
-      iter_args (
+      List.iter (
        function
        | String n -> pr " %s" n
        | OptString n -> pr " %s" n
        function
        | String n -> pr " %s" n
        | OptString n -> pr " %s" n
@@ -1805,7 +1832,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true)
   if extern then pr "extern ";
   if static then pr "static ";
   (match fst style with
   if extern then pr "extern ";
   if static then pr "static ";
   (match fst style with
-   | Err -> pr "int "
+   | RErr -> pr "int "
    | RInt _ -> pr "int "
    | RBool _ -> pr "int "
    | RConstString _ -> pr "const char *"
    | RInt _ -> pr "int "
    | RBool _ -> pr "int "
    | RConstString _ -> pr "const char *"
@@ -1825,7 +1852,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true)
        else pr "guestfs_lvm_int_lv_list *"
   );
   pr "%s%s (" prefix name;
        else pr "guestfs_lvm_int_lv_list *"
   );
   pr "%s%s (" prefix name;
-  if handle = None && nr_args (snd style) = 0 then
+  if handle = None && List.length (snd style) = 0 then
     pr "void"
   else (
     let comma = ref false in
     pr "void"
   else (
     let comma = ref false in
@@ -1839,7 +1866,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true)
       );
       comma := true
     in
       );
       comma := true
     in
-    iter_args (
+    List.iter (
       function
       | String n -> next (); pr "const char *%s" n
       | OptString n -> next (); pr "const char *%s" n
       function
       | String n -> next (); pr "const char *%s" n
       | OptString n -> next (); pr "const char *%s" n
@@ -1859,7 +1886,7 @@ and generate_call_args ?handle style =
    | None -> ()
    | Some handle -> pr "%s" handle; comma := true
   );
    | None -> ()
    | Some handle -> pr "%s" handle; comma := true
   );
-  iter_args (
+  List.iter (
     fun arg ->
       if !comma then pr ", ";
       comma := true;
     fun arg ->
       if !comma then pr ", ";
       comma := true;
@@ -2015,13 +2042,13 @@ and generate_ocaml_c () =
     fun (name, style, _, _, _, _) ->
       pr "CAMLprim value\n";
       pr "ocaml_guestfs_%s (value gv" name;
     fun (name, style, _, _, _, _) ->
       pr "CAMLprim value\n";
       pr "ocaml_guestfs_%s (value gv" name;
-      iter_args (
+      List.iter (
        fun arg -> pr ", value %sv" (name_of_argt arg)
       ) (snd style);
       pr ")\n";
       pr "{\n";
        fun arg -> pr ", value %sv" (name_of_argt arg)
       ) (snd style);
       pr ")\n";
       pr "{\n";
-      pr "  CAMLparam%d (gv" (1 + (nr_args (snd style)));
-      iter_args (
+      pr "  CAMLparam%d (gv" (1 + (List.length (snd style)));
+      List.iter (
        fun arg -> pr ", %sv" (name_of_argt arg)
       ) (snd style);
       pr ");\n";
        fun arg -> pr ", %sv" (name_of_argt arg)
       ) (snd style);
       pr ");\n";
@@ -2033,7 +2060,7 @@ and generate_ocaml_c () =
       pr "    caml_failwith (\"%s: used handle after closing it\");\n" name;
       pr "\n";
 
       pr "    caml_failwith (\"%s: used handle after closing it\");\n" name;
       pr "\n";
 
-      iter_args (
+      List.iter (
        function
        | String n ->
            pr "  const char *%s = String_val (%sv);\n" n n
        function
        | String n ->
            pr "  const char *%s = String_val (%sv);\n" n n
@@ -2048,7 +2075,7 @@ and generate_ocaml_c () =
       ) (snd style);
       let error_code =
        match fst style with
       ) (snd style);
       let error_code =
        match fst style with
-       | Err -> pr "  int r;\n"; "-1"
+       | RErr -> pr "  int r;\n"; "-1"
        | RInt _ -> pr "  int r;\n"; "-1"
        | RBool _ -> pr "  int r;\n"; "-1"
        | RConstString _ -> pr "  const char *r;\n"; "NULL"
        | RInt _ -> pr "  int r;\n"; "-1"
        | RBool _ -> pr "  int r;\n"; "-1"
        | RConstString _ -> pr "  const char *r;\n"; "NULL"
@@ -2081,7 +2108,7 @@ and generate_ocaml_c () =
       pr "\n";
 
       (match fst style with
       pr "\n";
 
       (match fst style with
-       | Err -> pr "  rv = Val_unit;\n"
+       | RErr -> pr "  rv = Val_unit;\n"
        | RInt _ -> pr "  rv = Val_int (r);\n"
        | RBool _ -> pr "  rv = Val_bool (r);\n"
        | RConstString _ -> pr "  rv = caml_copy_string (r);\n"
        | RInt _ -> pr "  rv = Val_int (r);\n"
        | RBool _ -> pr "  rv = Val_bool (r);\n"
        | RConstString _ -> pr "  rv = caml_copy_string (r);\n"
@@ -2132,7 +2159,7 @@ and generate_ocaml_lvm_structure_decls () =
 and generate_ocaml_prototype ?(is_external = false) name style =
   if is_external then pr "external " else pr "val ";
   pr "%s : t -> " name;
 and generate_ocaml_prototype ?(is_external = false) name style =
   if is_external then pr "external " else pr "val ";
   pr "%s : t -> " name;
-  iter_args (
+  List.iter (
     function
     | String _ -> pr "string -> "
     | OptString _ -> pr "string option -> "
     function
     | String _ -> pr "string -> "
     | OptString _ -> pr "string option -> "
@@ -2140,7 +2167,7 @@ and generate_ocaml_prototype ?(is_external = false) name style =
     | Int _ -> pr "int -> "
   ) (snd style);
   (match fst style with
     | Int _ -> pr "int -> "
   ) (snd style);
   (match fst style with
-   | Err -> pr "unit" (* all errors are turned into exceptions *)
+   | RErr -> pr "unit" (* all errors are turned into exceptions *)
    | RInt _ -> pr "int"
    | RBool _ -> pr "bool"
    | RConstString _ -> pr "string"
    | RInt _ -> pr "int"
    | RBool _ -> pr "bool"
    | RConstString _ -> pr "string"
@@ -2236,7 +2263,7 @@ DESTROY (g)
   List.iter (
     fun (name, style, _, _, _, _) ->
       (match fst style with
   List.iter (
     fun (name, style, _, _, _, _) ->
       (match fst style with
-       | Err -> pr "void\n"
+       | RErr -> pr "void\n"
        | RInt _ -> pr "SV *\n"
        | RBool _ -> pr "SV *\n"
        | RConstString _ -> pr "SV *\n"
        | RInt _ -> pr "SV *\n"
        | RBool _ -> pr "SV *\n"
        | RConstString _ -> pr "SV *\n"
@@ -2251,7 +2278,7 @@ DESTROY (g)
       generate_call_args ~handle:"g" style;
       pr "\n";
       pr "      guestfs_h *g;\n";
       generate_call_args ~handle:"g" style;
       pr "\n";
       pr "      guestfs_h *g;\n";
-      iter_args (
+      List.iter (
        function
        | String n -> pr "      char *%s;\n" n
        | OptString n -> pr "      char *%s;\n" n
        function
        | String n -> pr "      char *%s;\n" n
        | OptString n -> pr "      char *%s;\n" n
@@ -2260,7 +2287,7 @@ DESTROY (g)
       ) (snd style);
       (* Code. *)
       (match fst style with
       ) (snd style);
       (* Code. *)
       (match fst style with
-       | Err ->
+       | RErr ->
           pr " PPCODE:\n";
           pr "      if (guestfs_%s " name;
           generate_call_args ~handle:"g" style;
           pr " PPCODE:\n";
           pr "      if (guestfs_%s " name;
           generate_call_args ~handle:"g" style;
@@ -2501,7 +2528,7 @@ L<guestfs(3)>, L<guestfish(1)>.
 
 and generate_perl_prototype name style =
   (match fst style with
 
 and generate_perl_prototype name style =
   (match fst style with
-   | Err -> ()
+   | RErr -> ()
    | RBool n
    | RInt n
    | RConstString n
    | RBool n
    | RInt n
    | RConstString n
@@ -2514,7 +2541,7 @@ and generate_perl_prototype name style =
   );
   pr "$h->%s (" name;
   let comma = ref false in
   );
   pr "$h->%s (" name;
   let comma = ref false in
-  iter_args (
+  List.iter (
     fun arg ->
       if !comma then pr ", ";
       comma := true;
     fun arg ->
       if !comma then pr ", ";
       comma := true;
@@ -2537,6 +2564,15 @@ let output_to filename =
 let () =
   check_functions ();
 
 let () =
   check_functions ();
 
+  if not (Sys.file_exists "configure.ac") then (
+    eprintf "\
+You are probably running this from the wrong directory.
+Run it from the top source directory using the command
+  src/generator.ml
+";
+    exit 1
+  );
+
   let close = output_to "src/guestfs_protocol.x" in
   generate_xdr ();
   close ();
   let close = output_to "src/guestfs_protocol.x" in
   generate_xdr ();
   close ();