In "pr_wrap" we already print a sequence of spaces, and we'll print more in a subsequent patch. Copy the "spaces" function from libguestfs-common Std_utils, which lets us avoid open-coded loops.
"spaces" was added to libguestfs-common in commit e067192a90dc ("mllib: Split ‘Common_utils’ into ‘Std_utils’ + ‘Common_utils’.", 2017-07-10). The files declaring and defining "spaces" are licensed under the GPLv2+. Libnbd is licensed under the LGPLv2+, which is laxer. The copyright holder for "spaces" is Richard W.M. Jones <rjo...@redhat.com>; he has relicensed "spaces" for importing into libnbd <https://listman.redhat.com/archives/libguestfs/2023-April/031344.html>. Suggested-by: Richard W.M. Jones <rjo...@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <ler...@redhat.com> --- Notes: v2: - new patch [Rich] generator/utils.mli | 1 + generator/utils.ml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/generator/utils.mli b/generator/utils.mli index 62b86fddadbf..5bbb188fe934 100644 --- a/generator/utils.mli +++ b/generator/utils.mli @@ -45,6 +45,7 @@ val val span : string -> string -> int val cspan : string -> string -> int val quote : string -> string +val spaces : int -> string val files_equal : string -> string -> bool val generate_header : ?extra_sources:string list -> comment_style -> unit diff --git a/generator/utils.ml b/generator/utils.ml index 0121d92e1ab2..48bd6dd12ba8 100644 --- a/generator/utils.ml +++ b/generator/utils.ml @@ -149,6 +149,8 @@ let | Buffer b -> Buffer.add_string b str ) fs +let spaces n = String.make n ' ' + (* Wrap the output at maxcol, breaking up lines when a 'c' character * occurs. For example: * foobar = a, b, c, d, e, f, g @@ -179,8 +181,7 @@ let let fields = nsplit (String.make 1 c) line in let maybe_wrap field = if !col > wrapping_col && !col + String.length field >= maxcol then ( - pr "\n"; - for i = 0 to wrapping_col-1 do pr " " done; + pr "\n%s" (spaces wrapping_col); match span field " \t" with | 0 -> field | i -> String.sub field i (String.length field - i) _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs