[m-rev.] diff: use io.write_prefixed_lines in more places

Julien Fischer jfischer at opturion.com
Sun Sep 3 23:27:18 AEST 2023


Use io.write_prefixed_lines in more places.

profiler/options.m:
     Use io.write_prefixed_lines for writing the usage message.

     Add -? as a synonym for --help.

samples/diff/options.m:
samples/mcowsay.m:
     Use io.write_prefixed_lines for writing the usage messages.

Julien.

diff --git a/profiler/options.m b/profiler/options.m
index a1396bc..4276131 100644
--- a/profiler/options.m
+++ b/profiler/options.m
@@ -1,7 +1,8 @@
  %---------------------------------------------------------------------------%
  % vim: ft=mercury ts=4 sw=4 et
  %---------------------------------------------------------------------------%
-% Copyright (C) 1995-1997, 2000-2001, 2004-2006, 2011 The University of Melbourne.
+% Copyright (C) 1995-1997, 2000-2001, 2004-2006, 2011-2012 The University of Melbourne.
+% Copyright (C) 2015, 2019, 2021, 2023 The Mercury team.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
  %---------------------------------------------------------------------------%
@@ -84,6 +85,7 @@ short_option('C', countfile).
  short_option('c', call_graph).
  short_option('d', dynamic_cg).
  short_option('D', declfile).
+short_option('?', help).
  short_option('h', help).
  short_option('L', libraryfile).
  short_option('m', profile_memory_words).
@@ -165,60 +167,73 @@ valid_profile_option("memory-words", "Prof.MemoryWords").
  valid_profile_option("memory-cells", "Prof.MemoryCells").
  valid_profile_option("time", "Prof.Counts").

-options_help(OutputStream, !IO) :-
-    io.write_strings(OutputStream, [
-        "-h, --help\n",
-        "\t\tPrint this usage message.\n",
-        "\n",
-        "Profiler Options:\n",
-        "\t-c, --call-graph\n",
-        "\t\tInclude the call graph profile.\n",
-        "\t-d, --use-dynamic\n",
-        "\t\tBuild the call graph dynamically.\n",
-        "\t-p, --profile {time, memory-words, memory-cells}\n",
-        "\t\tSelect what to profile: time, amount of memory allocated, or\n",
-        "\t\tnumber of memory allocations (regardless of size).\n",
-        "\t-m\n",
-        "\t\tSame as `--profile memory-words'\n",
-        "\t-M\n",
-        "\t\tSame as `--profile memory-cells'.\n",
-        "\t-t\n",
-        "\t\tSame as `--profile time'.\n",
-        "\t--no-demangle\n",
-        "\t\tOutput the mangled predicate and function names.\n",
-        "\n",
-        "Filename Options:\n",
-        "\t-C <file>, --count-file <file>\n",
-        "\t\tName of the count file. Usually `Prof.Counts',\n",
-        "\t\t`Prof.MemoryWords', or `Prof.MemoryCells'.\n",
-        "\t-D <file>, --declaration-file <file>\n",
-        "\t\tName of the declaration file. Usually `Prof.Decl'.\n",
-        "\t-P <file>, --call-pair-file <file>\n",
-        "\t\tName of the call-pair file. Usually `Prof.CallPair'.\n",
-        "\t-L <file>, --library-callgraph <file>\n",
-        "\t\tName of the file which contains the call graph for\n",
-        "\t\tthe library modules.\n",
-        "\n",
-        "Snapshot options:\n",
-        "\t-s, --snapshots\n",
-        "\t\tShow summary of heap objects at the times\n",
-        "\t\t`benchmarking.report_memory_attribution' was called.\n",
-        "\t\tThis overrides other profiler modes.\n",
-        "\t--snapshots-file <file>\n",
-        "\t\tName of the snapshots file. Usually `Prof.Snapshots'.\n",
-        "\t-T, --snapshots-by-type\n",
-        "\t\tGroup results by type.\n",
-        "\t-b, --snapshots-brief\n",
-        "\t\tGenerate a brief profile.\n",
-        "\t-r, --snapshots-include-runtime\n",
-        "\t\tInclude internal Mercury runtime structures in the\n",
-        "\t\tprofile. These are excluded by default.\n",
-        "\n",
-        "Verbosity Options:\n",
-        "\t-v, --verbose\n",
-        "\t\tOutput progress messages at each stage.\n",
-        "\t-V, --very-verbose\n",
-        "\t\tOutput very verbose progress messages.\n"], !IO).
+options_help(Stream, !IO) :-
+    io.write_strings(Stream, [
+        "\t-?, -h, --help\n",
+        "\t\tPrint this usage message.\n"
+    ], !IO),
+    io.nl(Stream, !IO),
+
+    io.write_string(Stream, "Profiler Options:\n", !IO),
+    io.write_prefixed_lines(Stream, "\t", [
+        "-c, --call-graph",
+        "\tInclude the call graph profile.",
+        "-d, --use-dynamic",
+        "\tBuild the call graph dynamically.",
+        "-p, --profile {time, memory-words, memory-cells}",
+        "\tSelect what to profile: time, amount of memory allocated, or",
+        "\tnumber of memory allocations (regardless of size).",
+        "-m",
+        "\tSame as `--profile memory-words'",
+        "-M",
+        "\tSame as `--profile memory-cells'.",
+        "-t",
+        "\tSame as `--profile time'.",
+        "--no-demangle",
+        "\tOutput the mangled predicate and function names."
+    ], !IO),
+    io.nl(Stream, !IO),
+
+    io.write_string(Stream, "Filename Options:\n", !IO),
+    io.write_prefixed_lines(Stream, "\t", [
+        "-C <file>, --count-file <file>",
+        "\tName of the count file. Usually `Prof.Counts',",
+        "\t`Prof.MemoryWords', or `Prof.MemoryCells'.",
+        "-D <file>, --declaration-file <file>",
+        "\tName of the declaration file. Usually `Prof.Decl'.",
+        "-P <file>, --call-pair-file <file>",
+        "\tName of the call-pair file. Usually `Prof.CallPair'.",
+        "-L <file>, --library-callgraph <file>",
+        "\tName of the file which contains the call graph for",
+        "\tthe library modules."
+    ], !IO),
+    io.nl(Stream, !IO),
+
+    io.write_string(Stream, "Snapshot options:\n", !IO),
+    io.write_prefixed_lines(Stream, "\t", [
+        "-s, --snapshots",
+        "\tShow summary of heap objects at the times",
+        "\t`benchmarking.report_memory_attribution' was called.",
+        "\tThis overrides other profiler modes.",
+        "--snapshots-file <file>",
+        "\tName of the snapshots file. Usually `Prof.Snapshots'.",
+        "-T, --snapshots-by-type",
+        "\tGroup results by type.",
+        "-b, --snapshots-brief",
+        "\tGenerate a brief profile.",
+        "-r, --snapshots-include-runtime",
+        "\tInclude internal Mercury runtime structures in the",
+        "\tprofile. These are excluded by default."
+    ], !IO),
+    io.nl(Stream, !IO),
+
+    io.write_string(Stream, "Verbosity Options:\n", !IO),
+    io.write_prefixed_lines(Stream, "\t", [
+        "-v, --verbose",
+        "\tOutput progress messages at each stage.",
+        "-V, --very-verbose\n",
+        "\tOutput very verbose progress messages."
+    ], !IO).

  %---------------------------------------------------------------------------%

diff --git a/samples/diff/options.m b/samples/diff/options.m
index e30cd8b..673d219 100644
--- a/samples/diff/options.m
+++ b/samples/diff/options.m
@@ -2,6 +2,7 @@
  % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
  %-----------------------------------------------------------------------------%
  % Copyright (C) 1998, 2006, 2011 The University of Melbourne.
+% Copyright (C) 2015, 2019, 2023 The Mercury team.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
  %-----------------------------------------------------------------------------%
@@ -451,39 +452,43 @@ postprocess_output_style_2(no, no, no, no, no, no, no, no, no, no, yes,
  %-----------------------------------------------------------------------------%

  options_help(!IO) :-
-    io.write_strings([
-        "Output styles:\n",
-        "\t--help\n",
-        "\t\tOutput this help.\n",
-        "\t-v, --version\n",
-        "\t\tOutput version info.\n",
-        "\t-c, -C <num>, --context <num>\n",
-        "\t\tOutput <num> (default 2) lines of copied context.\n",
-        "\t-u, -U <num>, --unified <num>\n",
-        "\t\tOutput <num> (default 2) lines of unified context.\n",
-        "\t\t-L <label>, --label <label>  Use <label> instead of file name.\n",
-        "\t-e, --ed\n",
-        "\t\tOutput an ed script.\n",
-        "\t-f, --forward-ed\n",
-        "\t\tProduce output similar to --ed, not useful to ed(1),\n",
-        "\t\tand in the opposite order.\n",
-        "\t-n, --rcs\n",
-        "\t\tOutput an RCS format diff.\n",
-        "\t-q, --brief\n",
-        "\t\tOutput only whether or not files differ.\n",
-        "\t-D <name>, --ifdef <name>\n",
-        "\t\tProduce output in #ifdef <name> format.\n",
-        "\t-y, --side-by-side\n",
-        "\t\tProduce output in side-by-side format.\n",
-        "\t\t-w <num>, --width <num>  Output at most <num> (default 130)\n",
-        "\t\t\tcharacters per line.\n",
-        "\t\t--left-column  Output only the left column of common lines.\n",
-        "\t\t--suppress-common-lines  Do not output common lines.\n",
-        "\nMatching options:\n",
-        "\t-d, --minimal\n",
-        "\t\tTry hard to find as small a set of changes as possible.\n",
-        "\t-B, --ignore-blank-lines\n",
-        "\t\tIgnore changes whose lines are all blank.\n"
+    io.write_string("Output styles:\n", !IO),
+    io.write_prefixed_lines("\t", [
+        "--help",
+        "\tOutput this help.",
+        "-v, --version",
+        "\tOutput version info.",
+        "-c, -C <num>, --context <num>",
+        "\tOutput <num> (default 2) lines of copied context.",
+        "-u, -U <num>, --unified <num>",
+        "\tOutput <num> (default 2) lines of unified context.",
+        "\t-L <label>, --label <label>  Use <label> instead of file name.",
+        "-e, --ed",
+        "\tOutput an ed script.",
+        "-f, --forward-ed",
+        "\tProduce output similar to --ed, not useful to ed(1),",
+        "\tand in the opposite order.",
+        "-n, --rcs",
+        "\tOutput an RCS format diff.",
+        "-q, --brief",
+        "\tOutput only whether or not files differ.",
+        "-D <name>, --ifdef <name>",
+        "\tProduce output in #ifdef <name> format.",
+        "-y, --side-by-side",
+        "\tProduce output in side-by-side format.",
+        "\t-w <num>, --width <num>  Output at most <num> (default 130)",
+        "\t\tcharacters per line.",
+        "\t--left-column  Output only the left column of common lines.",
+        "\t--suppress-common-lines  Do not output common lines."
+    ], !IO),
+    io.nl(!IO),
+
+    io.write_string("Matching options:\n", !IO),
+    io.write_prefixed_lines("\t", [
+        "-d, --minimal",
+        "\tTry hard to find as small a set of changes as possible.",
+        "-B, --ignore-blank-lines",
+        "\tIgnore changes whose lines are all blank."
      ], !IO).

  %-----------------------------------------------------------------------------%
diff --git a/samples/mcowsay.m b/samples/mcowsay.m
index 6fd0817..acb92de 100644
--- a/samples/mcowsay.m
+++ b/samples/mcowsay.m
@@ -443,49 +443,57 @@ print_help_message(!IO) :-
          "\n",
          "Usage: mcowsay [<options>] [<message>]\n",
          "\n",
-        "Description:\n",
-        "\tPrints an ASCII art picture of a cow saying a message provided\n",
-        "\tby the user. If the message is not provided as an argument on\n",
-        "\tthe command line, then it will be read from the standard input.\n",
-        "\n",
-        "\tAny tab characters in the message will be replaced in the output\n",
-        "\tby a sequence of four space characters.\n",
-        "\n",
-        "\tIf the program is invoked as 'mcowthink' or 'cowthink' then the\n",
-        "\tcow will think its message instead of saying it.\n",
-        "\n",
-        "Options:\n",
-        "\t-h, --help\n",
-        "\t\tPrint this information and exit.\n",
-        "\t--version\n",
-        "\t\tPrint version information and exit.\n",
-        "\t-n, --no-wrap\n",
-        "\t\tDo not wrap lines.\n",
-        "\t-W <wrap-col>, --width <wrap-col>\n",
-        "\t\tSpecify the column at which to wrap words.\n",
-        "\t\t<wrap-col> must be greater than zero and defaults to 40.\n",
-        "\t-b, --borg\n",
-        "\t\t\"Borg mode\", uses == for the cow's eyes.\n",
-        "\t-d, --dead\n",
-        "\t\t\"Dead mode\", uses XX for the cow's eyes and U for its tongue.\n",
-        "\t-g, --greedy\n",
-        "\t\t\"Greedy mode\", uses $$ for the cow's eyes.\n",
-        "\t-p, --paranoid\n",
-        "\t\t\"Paranoid mode\", uses @@ for the cow's eyes.\n",
-        "\t-s, --stoned\n",
-        "\t\t\"Stoned mode\", uses ** for the cow's eyes and U for its tongue.\n",
-        "\t-t, --tired\n",
-        "\t\t\"Tired mode\", uses -- for the cow's eyes.\n",
-        "\t-w, --wired\n",
-        "\t\t\"Wired mode\", uses OO for the cow's eyes.\n",
-        "\t-y, --youthful\n",
-        "\t\t\"Youthful mode\", uses .. for the cow's eyes.\n",
-        "\t-e <eye-string>, --eyes <eye-string>\n",
-        "\t\tSpecifies the cow's eye type. Only the first two characters of\n",
-        "\t\t<eye-string> are used.\n",
-        "\t-T <tongue-string>, --tongue <tongue-string>\n",
-        "\t\tSpecifies the cow's tongue shape. Only the first two characters of\n",
-        "\t\t<tongue-string> are used.\n"
+        "Description:\n"
+    ], !IO),
+    io.write_prefixed_lines("\t", [
+        "Prints an ASCII art picture of a cow saying a message provided",
+        "by the user. If the message is not provided as an argument on",
+        "the command line, then it will be read from the standard input."
+    ], !IO),
+    io.nl(!IO),
+    io.write_prefixed_lines("\t", [
+        "Any tab characters in the message will be replaced in the output",
+        "by a sequence of four space characters."
+    ], !IO),
+    io.nl(!IO),
+    io.write_prefixed_lines("\t", [
+        "If the program is invoked as 'mcowthink' or 'cowthink' then the",
+        "cow will think its message instead of saying it."
+    ], !IO),
+    io.nl(!IO),
+    io.write_string("Options:\n", !IO),
+    io.write_prefixed_lines("\t", [
+        "-h, --help",
+        "\tPrint this information and exit.",
+        "--version",
+        "\tPrint version information and exit.",
+        "-n, --no-wrap",
+        "\tDo not wrap lines.",
+        "-W <wrap-col>, --width <wrap-col>",
+        "\tSpecify the column at which to wrap words.",
+        "\t<wrap-col> must be greater than zero and defaults to 40.",
+        "-b, --borg",
+        "\t\"Borg mode\", uses == for the cow's eyes.",
+        "-d, --dead",
+        "\t\"Dead mode\", uses XX for the cow's eyes and U for its tongue.",
+        "-g, --greedy",
+        "\t\"Greedy mode\", uses $$ for the cow's eyes.",
+        "-p, --paranoid",
+        "\t\"Paranoid mode\", uses @@ for the cow's eyes.",
+        "-s, --stoned",
+        "\t\"Stoned mode\", uses ** for the cow's eyes and U for its tongue.",
+        "-t, --tired",
+        "\t\"Tired mode\", uses -- for the cow's eyes.",
+        "-w, --wired",
+        "\t\"Wired mode\", uses OO for the cow's eyes.",
+        "-y, --youthful",
+        "\t\"Youthful mode\", uses .. for the cow's eyes.",
+        "-e <eye-string>, --eyes <eye-string>",
+        "\tSpecifies the cow's eye type. Only the first two characters of",
+        "\t<eye-string> are used.",
+        "-T <tongue-string>, --tongue <tongue-string>",
+        "\tSpecifies the cow's tongue shape. Only the first two characters of",
+        "\t<tongue-string> are used."
      ], !IO).

  :- pred print_version_message(io::di, io::uo) is det.


More information about the reviews mailing list