66#include " CodeService/LuaFormatter.h"
77#include " Util/CommandLine.h"
88
9+ // https://stackoverflow.com/questions/1598985/c-read-binary-stdin
10+ #ifdef _WIN32
11+ # include < io.h>
12+ # include < fcntl.h>
13+ # define SET_BINARY_MODE () _setmode(_fileno(stdin), _O_BINARY);\
14+ _setmode (_fileno(stdout), _O_BINARY)
15+ #else
16+ # define SET_BINARY_MODE () ((void )0 )
17+ #endif
18+
19+
920int main (int argc, char ** argv)
1021{
1122 CommandLine cmd;
@@ -32,6 +43,7 @@ int main(int argc, char** argv)
3243 }
3344 else if (cmd.Get <int >(" stdin" ) != 0 )
3445 {
46+ SET_BINARY_MODE ();
3547 std::size_t size = cmd.Get <int >(" stdin" );
3648
3749 std::string buffer;
@@ -42,15 +54,15 @@ int main(int argc, char** argv)
4254 parser = LuaParser::LoadFromBuffer (std::move (buffer));
4355 }
4456
45- LuaCodeStyleOptions options;
57+ std::shared_ptr< LuaCodeStyleOptions> options;
4658 if (!cmd.Get <std::string>(" config" ).empty ())
4759 {
4860 options = LuaCodeStyleOptions::ParseFromEditorConfig (cmd.Get <std::string>(" config" ));
4961 }
5062
5163 parser->BuildAstWithComment ();
5264
53- LuaFormatter formatter (parser, options);
65+ LuaFormatter formatter (parser, * options);
5466 formatter.BuildFormattedElement ();
5567
5668 if (cmd.GetTarget () == " format" )
0 commit comments