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

@@ -18,6 +18,7 @@
(* Please read generator/README first. *)
open Common_utils
open Types
open Utils
@@ -13584,17 +13585,18 @@ let test_functions, non_daemon_functions, daemon_functions =
{ f with
c_name = f.name;
c_function = "guestfs_" ^ f.name;
c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name }
c_optarg_prefix = "GUESTFS_" ^ String.uppercase_ascii f.name }
| { style = _, _, (_::_); once_had_no_optargs = false } ->
{ f with
c_name = f.name;
c_function = "guestfs_" ^ f.name ^ "_argv";
c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name }
c_optarg_prefix = "GUESTFS_" ^ String.uppercase_ascii f.name }
| { style = _, _, (_::_); once_had_no_optargs = true } ->
{ f with
c_name = f.name ^ "_opts";
c_function = "guestfs_" ^ f.name ^ "_opts_argv";
c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name ^ "_OPTS";
c_optarg_prefix = "GUESTFS_" ^ String.uppercase_ascii f.name
^ "_OPTS";
non_c_aliases = [ f.name ^ "_opts" ] }
in
let test_functions = List.map make_c_function test_functions in
@@ -13609,7 +13611,7 @@ let non_daemon_functions, daemon_functions =
let make_camel_case name =
List.fold_left (
fun a b ->
a ^ String.uppercase (Str.first_chars b 1) ^ Str.string_after b 1
a ^ String.uppercase_ascii (Str.first_chars b 1) ^ Str.string_after b 1
) "" (Str.split (Str.regexp "_") name)
in
let make_camel_case_if_not_set f =