[m-rev.] for post-commit review: improve consistency of usage message for mmc, mprof and mcov

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Sep 4 17:28:27 AEST 2023


On 2023-09-04 17:20 +10:00 AEST, "Julien Fischer" <jfischer at opturion.com> wrote:
> @@ -3152,21 +3151,31 @@ long_usage(ProgressStream, !IO) :-
>      % copies of the long usage message. We can print both a short and along
>      % usage message, but there is no simple way to avoid that.
>      library.version(Version, Fullarch),
> -    Template =
> -        "Name: mmc -- Melbourne Mercury Compiler, version %s on %s\n" ++
> -        "Copyright (C) 1993-2012 The University of Melbourne\n" ++
> -        "Copyright (C) 2013-2023 The Mercury team\n" ++
> -        "Usage: mmc [<options>] <arguments>\n" ++
> -        "Arguments:\n" ++
> -        "\tArguments ending in `.m' are assumed to be source file names.\n" ++
> -        "\tArguments that do not end in `.m' " ++
> -            "are assumed to be module names.\n" ++
> -        "\tArguments in the form @file " ++
> -            "are replaced with the contents of the file.\n",
> -    io.format(ProgressStream, Template, [s(Version), s(Fullarch)], !IO),
> +    io.format(ProgressStream,
> +        "Name: mmc - Melbourne Mercury Compiler, version %s, on %s\n",
> +        [s(Version), s(Fullarch)], !IO),
> +    write_copyright_notice(ProgressStream, !IO),
> +    io.write_strings(ProgressStream, [
> +        "Usage: mmc [<options>] <arguments>\n",
> +        "Arguments:\n",
> +        "\tArguments ending in `.m' are assumed to be source file names.\n",
> +        "\tArguments that do not end in `.m' ",
> +            "are assumed to be module names.\n",
> +        "\tArguments in the form @file ",
> +            "are replaced with the contents of the file.\n"
> +    ], !IO),

Why not use write_prefixed_lines?

> +:- pred write_copyright_notice(io.text_output_stream::in, io::di, io::uo)
> +    is det.
> +
> +write_copyright_notice(Stream, !IO) :-
> +    io.write_strings(Stream, [
> +        "Copyright (C) 1993-2012 The University of Melbourne\n",
> +        "Copyright (C) 2013-2023 The Mercury team\n"
> +    ], !IO).

This code is still repeated in several places.

I would add a function to library/library.m that returns the copyright
message as a two-line string, and then just print that string with the
rest of whatever usage message each program has.

The diff is otherwise fine.

Zoltan.


More information about the reviews mailing list