mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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:
@@ -20,6 +20,7 @@
|
||||
|
||||
open Printf
|
||||
|
||||
open Common_utils
|
||||
open Types
|
||||
open Utils
|
||||
open Pr
|
||||
@@ -176,7 +177,7 @@ fill_lvm_pv (guestfs_h *g, struct guestfs_lvm_pv *pv, size_t i)
|
||||
let check_optarg n printf_args =
|
||||
pr " fprintf (fp, \"%s: \");\n" n;
|
||||
pr " if (optargs->bitmask & %s_%s_BITMASK) {\n" c_optarg_prefix
|
||||
(String.uppercase n);
|
||||
(String.uppercase_ascii n);
|
||||
pr " fprintf (fp, %s);\n" printf_args;
|
||||
pr " } else {\n";
|
||||
pr " fprintf (fp, \"unset\\n\");\n";
|
||||
@@ -200,7 +201,7 @@ fill_lvm_pv (guestfs_h *g, struct guestfs_lvm_pv *pv, size_t i)
|
||||
| OStringList n ->
|
||||
pr " fprintf (fp, \"%s: \");\n" n;
|
||||
pr " if (optargs->bitmask & %s_%s_BITMASK) {\n" c_optarg_prefix
|
||||
(String.uppercase n);
|
||||
(String.uppercase_ascii n);
|
||||
pr " print_strings (g, optargs->%s);\n" n;
|
||||
pr " } else {\n";
|
||||
pr " fprintf (fp, \"unset\\n\");\n";
|
||||
@@ -583,7 +584,7 @@ public class Bindtests {
|
||||
| CallBool b -> string_of_bool b
|
||||
| CallBuffer s ->
|
||||
"new byte[] { " ^ String.concat "," (
|
||||
map_chars (fun c -> string_of_int (Char.code c)) s
|
||||
String.map_chars (fun c -> string_of_int (Char.code c)) s
|
||||
) ^ " }"
|
||||
) args
|
||||
)
|
||||
@@ -845,7 +846,7 @@ and generate_golang_bindtests () =
|
||||
generate_lang_bindtests (
|
||||
fun f args optargs ->
|
||||
|
||||
pr " if err := g.%s (" (String.capitalize f);
|
||||
pr " if err := g.%s (" (String.capitalize_ascii f);
|
||||
|
||||
let needs_comma = ref false in
|
||||
List.iter (
|
||||
@@ -869,13 +870,13 @@ and generate_golang_bindtests () =
|
||||
| c -> sprintf "'%c'" c
|
||||
in
|
||||
pr "[]byte{%s}"
|
||||
(String.concat ", " (List.map quote_char (explode s)))
|
||||
(String.concat ", " (List.map quote_char (String.explode s)))
|
||||
) args;
|
||||
if !needs_comma then pr ", ";
|
||||
(match optargs with
|
||||
| None -> pr "nil"
|
||||
| Some optargs ->
|
||||
pr "&guestfs.Optargs%s{" (String.capitalize f);
|
||||
pr "&guestfs.Optargs%s{" (String.capitalize_ascii f);
|
||||
needs_comma := false;
|
||||
List.iter (
|
||||
fun optarg ->
|
||||
@@ -883,19 +884,19 @@ and generate_golang_bindtests () =
|
||||
needs_comma := true;
|
||||
match optarg with
|
||||
| CallOBool (n, v) ->
|
||||
let n = String.capitalize n in
|
||||
let n = String.capitalize_ascii n in
|
||||
pr "%s_is_set: true, %s: %b" n n v
|
||||
| CallOInt (n, v) ->
|
||||
let n = String.capitalize n in
|
||||
let n = String.capitalize_ascii n in
|
||||
pr "%s_is_set: true, %s: %d" n n v
|
||||
| CallOInt64 (n, v) ->
|
||||
let n = String.capitalize n in
|
||||
let n = String.capitalize_ascii n in
|
||||
pr "%s_is_set: true, %s: %Ld" n n v
|
||||
| CallOString (n, v) ->
|
||||
let n = String.capitalize n in
|
||||
let n = String.capitalize_ascii n in
|
||||
pr "%s_is_set: true, %s: \"%s\"" n n v
|
||||
| CallOStringList (n, xs) ->
|
||||
let n = String.capitalize n in
|
||||
let n = String.capitalize_ascii n in
|
||||
pr "%s_is_set: true, %s: []string{%s}"
|
||||
n n (String.concat ", " (List.map (sprintf "\"%s\"") xs))
|
||||
) optargs;
|
||||
@@ -971,7 +972,7 @@ and generate_php_bindtests () =
|
||||
let chan = open_in filename in
|
||||
let rec loop () =
|
||||
let line = input_line chan in
|
||||
(match string_split ":" line with
|
||||
(match String.nsplit ":" line with
|
||||
| ("obool"|"oint"|"oint64"|"ostring"|"ostringlist") as x :: _ ->
|
||||
pr "%s: unset\n" x
|
||||
| _ -> pr "%s\n" line
|
||||
|
||||
Reference in New Issue
Block a user