From c02d14a730341c6bed428afc7be75626b0ee2a75 Mon Sep 17 00:00:00 2001 From: Josh Milthorpe Date: Wed, 20 Dec 2023 06:42:41 -0500 Subject: [PATCH] add optional fileWriter parameters to ChapelIO.write* Added overloads or optional parameters to each of the ChapelIO.write* procs to allow them to be called with a fileWriter other than stdout. This allows user code to call e.g. writeln(IO.stderr, ...) to write to stderr without exception handling code. Signed-off-by: Josh Milthorpe --- modules/standard/ChapelIO.chpl | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/standard/ChapelIO.chpl b/modules/standard/ChapelIO.chpl index aca016bd0573..ef7fc327ec16 100644 --- a/modules/standard/ChapelIO.chpl +++ b/modules/standard/ChapelIO.chpl @@ -779,15 +779,24 @@ module ChapelIO { proc write(const args ...?n) { try! stdout.write((...args)); } + /* Equivalent to ``try! writer.write``. See :proc:`IO.fileWriter.write` */ + proc write(writer: fileWriter, const args ...?n) { + try! writer.write((...args)); + } + /* Equivalent to ``try! stdout.writeln``. See :proc:`IO.fileWriter.writeln` */ proc writeln(const args ...?n) { try! stdout.writeln((...args)); } + /* Equivalent to ``try! writer.writeln``. See :proc:`IO.fileWriter.writeln` */ + proc writeln(writer: fileWriter, const args ...?n) { + try! writer.writeln((...args)); + } // documented in the arguments version. @chpldoc.nodoc - proc writeln() { - try! stdout.writeln(); + proc writeln(writer: fileWriter = stdout) { + try! writer.writeln(); } /* Equivalent to ``try! stdout.writef``. See @@ -797,6 +806,13 @@ module ChapelIO { { try! { stdout.writef(fmt, (...args)); } } + /* Equivalent to ``try! writer.writef``. See + :proc:`FormattedIO.fileWriter.writef`. */ + proc writef(writer: fileWriter, fmt:?t, const args ...?k) + where isStringType(t) || isBytesType(t) + { + try! { writer.writef(fmt, (...args)); } + } // documented in string version @chpldoc.nodoc proc writef(fmt:?t) @@ -804,6 +820,13 @@ module ChapelIO { { try! { stdout.writef(fmt); } } + // documented in string version + @chpldoc.nodoc + proc writef(writer: fileWriter, fmt:?t) + where isStringType(t) || isBytesType(t) + { + try! { writer.writef(fmt); } + } @chpldoc.nodoc proc chpl_stringify_wrapper(const args ...):string {