summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-09-11 09:40:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-09-11 09:40:05 +0200
commit5a16bda0fa232eaaf3a497f569939a4f1bcf727f (patch)
tree56d3f38d68d934a299374d1c0baed36f3442c5f7
parent0d9c416f2e8452a1f4d1c38727f81c420a4f5cd0 (diff)
Recognize --file-list value `-` as request to write to stdout
-rw-r--r--xsd/doc/pregenerated/xsd.17
-rw-r--r--xsd/doc/pregenerated/xsd.xhtml10
-rw-r--r--xsd/xsd/options.cli8
-rw-r--r--xsd/xsd/pregenerated/xsd/options.cxx3
-rw-r--r--xsd/xsd/xsd.cxx25
5 files changed, 31 insertions, 22 deletions
diff --git a/xsd/doc/pregenerated/xsd.1 b/xsd/doc/pregenerated/xsd.1
index 6a060a8..5864e0c 100644
--- a/xsd/doc/pregenerated/xsd.1
+++ b/xsd/doc/pregenerated/xsd.1
@@ -580,9 +580,10 @@ option is primarily useful when trying to minimize the amount of object code
that is linked to an executable by packaging compiled generated code into a
static (archive) library\.
.IP "\fB--file-list\fR \fIfile\fR"
-Write a list of generated C++ files to \fIfile\fR\. This option is primarily
-useful in the file-per-type compilation mode (\fB--file-per-type\fR) to create
-a list of generated C++ files, for example, as a makefile fragment\.
+Write a list of generated C++ files to \fIfile\fR or to \fBstdout\fR if
+\fIfile\fR is \fB-\fR\. This option is primarily useful in the file-per-type
+compilation mode (\fB--file-per-type\fR) to create a list of generated C++
+files, for example, as a makefile fragment\.
.IP "\fB--file-list-prologue\fR \fItext\fR"
Insert \fItext\fR at the beginning of the file list\. As a convenience, all
occurrences of the \fB\en\fR character sequence in \fItext\fR are replaced
diff --git a/xsd/doc/pregenerated/xsd.xhtml b/xsd/doc/pregenerated/xsd.xhtml
index a172f13..95d7264 100644
--- a/xsd/doc/pregenerated/xsd.xhtml
+++ b/xsd/doc/pregenerated/xsd.xhtml
@@ -733,10 +733,12 @@
compiled generated code into a static (archive) library.</dd>
<dt><code><b>--file-list</b></code> <code><i>file</i></code></dt>
- <dd>Write a list of generated C++ files to <code><i>file</i></code>. This
- option is primarily useful in the file-per-type compilation mode
- (<code><b>--file-per-type</b></code>) to create a list of generated C++
- files, for example, as a makefile fragment.</dd>
+ <dd>Write a list of generated C++ files to <code><i>file</i></code> or to
+ <code><b>stdout</b></code> if <code><i>file</i></code> is
+ <code><b>-</b></code>. This option is primarily useful in the
+ file-per-type compilation mode (<code><b>--file-per-type</b></code>) to
+ create a list of generated C++ files, for example, as a makefile
+ fragment.</dd>
<dt><code><b>--file-list-prologue</b></code> <code><i>text</i></code></dt>
<dd>Insert <code><i>text</i></code> at the beginning of the file list. As
diff --git a/xsd/xsd/options.cli b/xsd/xsd/options.cli
index 6c327a4..e81052a 100644
--- a/xsd/xsd/options.cli
+++ b/xsd/xsd/options.cli
@@ -277,10 +277,10 @@ class options = 0
NarrowString --file-list
{
"<file>",
- "Write a list of generated C++ files to <file>. This option is primarily
- useful in the file-per-type compilation mode (\cb{--file-per-type}) to
- create a list of generated C++ files, for example, as a makefile
- fragment."
+ "Write a list of generated C++ files to <file> or to \cb{stdout} if
+ <file> is \cb{-}. This option is primarily useful in the file-per-type
+ compilation mode (\cb{--file-per-type}) to create a list of generated
+ C++ files, for example, as a makefile fragment."
};
NarrowString --file-list-prologue
diff --git a/xsd/xsd/pregenerated/xsd/options.cxx b/xsd/xsd/pregenerated/xsd/options.cxx
index 83cf67e..d8e59f6 100644
--- a/xsd/xsd/pregenerated/xsd/options.cxx
+++ b/xsd/xsd/pregenerated/xsd/options.cxx
@@ -1175,7 +1175,8 @@ print_usage (::std::wostream& os, ::cli::usage_para p)
<< " into type files instead of schema files when the" << ::std::endl
<< " --type-file-regex option is specified." << ::std::endl;
- os << "--file-list <file> Write a list of generated C++ files to <file>." << ::std::endl;
+ os << "--file-list <file> Write a list of generated C++ files to <file> or" << ::std::endl
+ << " to stdout if <file> is -." << ::std::endl;
os << "--file-list-prologue <text> Insert <text> at the beginning of the file list." << ::std::endl;
diff --git a/xsd/xsd/xsd.cxx b/xsd/xsd/xsd.cxx
index 0df4ea0..5a239d5 100644
--- a/xsd/xsd/xsd.cxx
+++ b/xsd/xsd/xsd.cxx
@@ -770,38 +770,43 @@ main (int argc, char* argv[])
try
{
OutputFileStream ofs;
- SemanticGraph::Path path (fl);
+ if (fl != "-")
+ {
+ SemanticGraph::Path path (fl);
- ofs.open (path.string ().c_str (), ios_base::out);
+ ofs.open (path.string ().c_str (), ios_base::out);
- if (!ofs.is_open ())
- {
- wcerr << path << ": error: unable to open in write mode" << endl;
- return 1;
+ if (!ofs.is_open ())
+ {
+ wcerr << path << ": error: unable to open in write mode" << endl;
+ return 1;
+ }
}
+ std::ostream& os (ofs.is_open () ? ofs : cout);
+
NarrowString d (common_ops.file_list_delim ());
expand_nl (d);
if (NarrowString p = common_ops.file_list_prologue ())
{
expand_nl (p);
- ofs << p;
+ os << p;
}
for (FileList::iterator i (file_list.begin ()), e (file_list.end ());
i != e;)
{
- ofs << *i;
+ os << *i;
if (++i != e)
- ofs << d;
+ os << d;
}
if (NarrowString e = common_ops.file_list_epilogue ())
{
expand_nl (e);
- ofs << e;
+ os << e;
}
}
catch (SemanticGraph::InvalidPath const&)