generator: Share Common_utils code.

For a very long time we have maintained two sets of utility functions,
in mllib/common_utils.ml and generator/utils.ml.  This changes things
so that the same set of utility functions can be shared with both
directories.

It's not possible to use common_utils.ml directly in the generator
because it provides several functions that use modules outside the
OCaml stdlib.  Therefore we add some lightweight post-processing which
extracts the functions using only the stdlib:

  (*<stdlib>*)
  ...
  (*</stdlib>*)

and creates generator/common_utils.ml and generator/common_utils.mli
from that.  The effect is we only need to write utility functions
once.

As with other tools, we still have generator-specific utility
functions in generator/utils.ml.

Also in this change:

 - Use String.uppercase_ascii and String.lowercase_ascii in place
   of deprecated String.uppercase/String.lowercase.

 - Implement String.capitalize_ascii to replace deprecated
   String.capitalize.

 - Move isspace, isdigit, isxdigit functions to Char module.
This commit is contained in:
Richard W.M. Jones
2016-12-08 09:53:50 +00:00
parent 865d070ddc
commit 2cc348448a
32 changed files with 400 additions and 383 deletions

View File

@@ -20,6 +20,7 @@
open Printf
open Common_utils
open Types
open Utils
open Pr
@@ -156,7 +157,8 @@ public class GuestFS {
pr " *\n";
pr " * @see #set_event_callback\n";
pr " */\n";
pr " public static final long EVENT_%s = 0x%x;\n" (String.uppercase name) bitmask;
pr " public static final long EVENT_%s = 0x%x;\n"
(String.uppercase_ascii name) bitmask;
pr "\n";
) events;
@@ -259,7 +261,7 @@ public class GuestFS {
let ret, args, optargs = f.style in
if is_documented f then (
let doc = replace_str f.longdesc "C<guestfs_" "C<g." in
let doc = String.replace f.longdesc "C<guestfs_" "C<g." in
let doc =
if optargs <> [] then
doc ^ "\n\nOptional arguments are supplied in the final Map<String,Object> parameter, which is a hash of the argument name to its value (cast to Object). Pass an empty Map or null for no optional arguments."
@@ -625,7 +627,7 @@ throw_out_of_memory (JNIEnv *env, const char *msg)
);
pr "JNICALL\n";
pr "Java_com_redhat_et_libguestfs_GuestFS_";
pr "%s" (replace_str ("_" ^ name) "_" "_1");
pr "%s" (String.replace ("_" ^ name) "_" "_1");
pr " (JNIEnv *env, jobject obj, jlong jg";
List.iter (
function