File tree Expand file tree Collapse file tree 4 files changed +32
-11
lines changed Expand file tree Collapse file tree 4 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -799,7 +799,9 @@ class cmdline_processor
799
799
[](auto & a, auto & b){ return a.group < b.group || (a.group == b.group && a.name < b.name ); }
800
800
);
801
801
802
- print (" \n Usage: cppfront [options] file ...\n\n Options:\n " );
802
+ print (" \n Usage: cppfront [options] file ...\n " );
803
+ print (" \n file source file(s) (can be 'stdin')\n " );
804
+ print (" \n Options: \n " );
803
805
int last_group = -1 ;
804
806
for (auto & flag : flags) {
805
807
// Skip hidden flags
Original file line number Diff line number Diff line change @@ -79,7 +79,12 @@ auto main(
79
79
80
80
auto & out = flag_cpp1_filename != " stdout" ? std::cout : std::cerr;
81
81
82
- if (!flag_quiet) {
82
+ if (
83
+ !flag_quiet
84
+ && arg.text != " stdin"
85
+ && flag_cpp1_filename != " stdout"
86
+ )
87
+ {
83
88
out << arg.text << " ..." ;
84
89
}
85
90
@@ -92,7 +97,10 @@ auto main(
92
97
// If there were no errors, say so and generate Cpp1
93
98
if (c.had_no_errors ())
94
99
{
95
- if (!flag_quiet)
100
+ if (
101
+ !flag_quiet
102
+ && flag_cpp1_filename != " stdout"
103
+ )
96
104
{
97
105
if (!c.has_cpp1 ()) {
98
106
out << " ok (all Cpp2, passes safety checks)\n " ;
Original file line number Diff line number Diff line change @@ -882,11 +882,17 @@ class source
882
882
)
883
883
-> bool
884
884
{
885
- std::ifstream in{ filename };
886
- if (!in.is_open ()) {
887
- return false ;
885
+ // If filename is stdin, we read from stdin, otherwise we try to read the file
886
+ //
887
+ auto is_stdin = filename == " stdin" ;
888
+ std::ifstream fss;
889
+ if (!is_stdin)
890
+ {
891
+ fss.open (filename);
892
+ if ( !fss.is_open ()) { return false ; }
888
893
}
889
-
894
+ std::istream& in = is_stdin ? std::cin : fss;
895
+
890
896
auto in_comment = false ;
891
897
auto in_string_literal = false ;
892
898
auto in_raw_string_literal = false ;
Original file line number Diff line number Diff line change @@ -1179,6 +1179,7 @@ class cppfront
1179
1179
if (
1180
1180
!sourcefile.ends_with (" .cpp2" )
1181
1181
&& !sourcefile.ends_with (" .h2" )
1182
+ && sourcefile != " stdin"
1182
1183
)
1183
1184
{
1184
1185
errors.emplace_back (
@@ -1257,14 +1258,18 @@ class cppfront
1257
1258
}
1258
1259
1259
1260
// Now we'll open the Cpp1 file
1260
- auto cpp1_filename = sourcefile.substr (0 , std::ssize (sourcefile) - 1 );
1261
+ // Default to stdout if input is stdin
1262
+ auto cpp1_filename = std::string{" stdout" };
1263
+ if (sourcefile != " stdin" ) {
1264
+ assert (sourcefile.ends_with (" 2" ));
1265
+ cpp1_filename = sourcefile.substr (0 , std::ssize (sourcefile) - 1 );
1266
+ }
1261
1267
1262
- // Use explicit filename override if present,
1263
- // otherwise strip leading path
1268
+ // Use explicit filename override if present, otherwise strip leading path
1264
1269
if (!flag_cpp1_filename.empty ()) {
1265
1270
cpp1_filename = flag_cpp1_filename;
1266
1271
}
1267
- else {
1272
+ else if (cpp1_filename != " stdout " ) {
1268
1273
cpp1_filename = std::filesystem::path (cpp1_filename).filename ().string ();
1269
1274
}
1270
1275
You can’t perform that action at this time.
0 commit comments