On Thu, Apr 20, 2023 at 04:04:58PM +0200, Laszlo Ersek wrote:
Change the optional "parens" parameter of
"print_arg_list" from bool to a
new union type. The new union type has three data constructors, NoParens
(matching the previous "false" value), ParensSameLine (matching the
previous "true" value), and a third constructor called
"ParensNewLine",
which wraps an "int". [ParensNewLine n] stands for the following
formatting construct (with wrapping):
> ret_type foobar (
> type1 param1, type2 param2, type3 param3, type4 param4,
> type5 param5
> );
> <---n--->
I would have called it ParensNewLineWithIndent, and I would
have called this:
+type args_style = NoParens | ParensSameLine | ParensNewLine of int
parens_style or parens_t just to tie it back to the only parameter
where it is used.
+let rec print_arg_list ?(wrap = false) ?maxcol ?handle ?types
+ ?(parens = ParensSameLine) ?closure_style args optargs =
+ (match parens with
+ | NoParens -> ()
+ | ParensSameLine -> pr "("
+ | ParensNewLine indent ->
+ pr "(\n";
+ for i = 0 to indent + 2 - 1 do
+ pr " "
+ done
libguestfs common/mlstdutils/std_utils.ml has a "spaces" function
which might be worth grabbing for this. The license is compatible
enough, and if not as author I give you permission.
if wrap then
pr_wrap ?maxcol ','
(fun () -> print_arg_list' ?handle ?types ?closure_style args optargs)
else
print_arg_list' ?handle ?types ?closure_style args optargs;
- if parens then pr ")"
+ (match parens with
+ | NoParens -> ()
+ | ParensSameLine -> pr ")"
+ | ParensNewLine indent ->
+ pr "\n";
+ for i = 0 to indent - 1 do
+ pr " "
+ done;
+ pr ")"
+ )
& here.
The rest looks good to me.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top