1- #include < iostream>
21#include < cstring>
32#include < fstream>
3+ #include < iostream>
44
55#include " LuaFormat.h"
6- #include " Util/format.h"
76#include " Util/CommandLine.h"
87#include " Util/StringUtil.h"
8+ #include " Util/format.h"
99
1010// https://stackoverflow.com/questions/1598985/c-read-binary-stdin
1111#ifdef _WIN32
1212
13- # include < io .h>
14- # include < fcntl .h>
13+ #include < fcntl .h>
14+ #include < io .h>
1515
16- # define SET_BINARY_MODE () _setmode(_fileno(stdin), _O_BINARY);\
16+ #define SET_BINARY_MODE () \
17+ _setmode (_fileno(stdin), _O_BINARY); \
1718 _setmode (_fileno(stdout), _O_BINARY)
1819#else
19- # define SET_BINARY_MODE () ((void )0 )
20+ #define SET_BINARY_MODE () ((void ) 0 )
2021#endif
2122
22- bool InitFormat (CommandLine& cmd, LuaFormat& format);
23- bool InitCheck (CommandLine& cmd, LuaFormat& format);
24- bool InitRangeFormat (CommandLine& cmd, LuaFormat& format);
23+ bool InitFormat (CommandLine & cmd, LuaFormat & format);
24+ bool InitCheck (CommandLine & cmd, LuaFormat & format);
25+ bool InitRangeFormat (CommandLine & cmd, LuaFormat & format);
2526
2627int main (int argc, char **argv) {
2728 CommandLine cmd;
@@ -34,8 +35,7 @@ int main(int argc, char **argv) {
3435 " \t CodeFormat check -w . -d --ignores \" Test/*.lua;src/**.lua\"\n "
3536 " \t CodeFormat check -w . -d --ignores-file \" .gitignore\"\n "
3637 " \t CodeFormat rangeformat -i -d --rangeline 1:10\n "
37- " \t CodeFormat rangeformat -i -d --rangeOffset 0:100\n "
38- );
38+ " \t CodeFormat rangeformat -i -d --rangeOffset 0:100\n " );
3939 cmd.AddTarget (" format" )
4040 .Add <std::string>(" file" , " f" , " Specify the input file" )
4141 .Add <bool >(" overwrite" , " ow" , " Format overwrite the input file" )
@@ -50,12 +50,11 @@ int main(int argc, char **argv) {
5050 .Add <std::string>(" outfile" , " o" ,
5151 " Specify output file" )
5252 .Add <std::string>(" ignores-file" , " igf" ,
53- " Specify which files to ignore through configuration file,for example \" .gitignore\" "
54- )
53+ " Specify which files to ignore through configuration file,for example \" .gitignore\" " )
5554 .Add <std::string>(" ignores" , " ig" ,
5655 " Use file wildcards to specify how to ignore files\n "
57- " \t\t separated by ';'"
58- )
56+ " \t\t separated by ';'" )
57+ . Add < bool >( " non-standard " , " " , " Enable non-standard formatting " )
5958 .EnableKeyValueArgs ();
6059 cmd.AddTarget (" rangeformat" )
6160 .Add <std::string>(" file" , " f" , " Specify the input file" )
@@ -71,6 +70,7 @@ int main(int argc, char **argv) {
7170 " If true, all content will be output" )
7271 .Add <std::string>(" range-line" , " " , " the format is startline:endline, for eg: 1:10" )
7372 .Add <std::string>(" range-offset" , " " , " the format is startOffset:endOffset, for eg: 0:256" )
73+ .Add <bool >(" non-standard" , " " , " Enable non-standard rangeformatting" )
7474 .EnableKeyValueArgs ();
7575 cmd.AddTarget (" check" )
7676 .Add <std::string>(" file" , " f" , " Specify the input file" )
@@ -83,13 +83,12 @@ int main(int argc, char **argv) {
8383 " \t\t If this option is set, the config option has no effect" )
8484 .Add <bool >(" diagnosis-as-error" , " DAE" , " if exist error or diagnosis info , return -1" )
8585 .Add <std::string>(" ignores-file" , " igf" ,
86- " Specify which files to ignore through configuration file,for example \" .gitignore\" "
87- )
86+ " Specify which files to ignore through configuration file,for example \" .gitignore\" " )
8887 .Add <std::string>(" ignores" , " ig" ,
8988 " Use file wildcards to specify how to ignore files\n "
90- " \t\t separated by ';'"
91- )
89+ " \t\t separated by ';'" )
9290 .Add <bool >(" name-style" , " ns" , " Enable name-style check" )
91+ .Add <bool >(" non-standard" , " " , " Enable non-standard checking" )
9392 .EnableKeyValueArgs ();
9493
9594
@@ -110,7 +109,7 @@ int main(int argc, char **argv) {
110109 if (!format.Check () && cmd.Get <bool >(" diagnosis-as-error" )) {
111110 return -1 ;
112111 }
113- } else if (cmd.GetTarget () == " rangeformat" ) {
112+ } else if (cmd.GetTarget () == " rangeformat" ) {
114113 InitRangeFormat (cmd, format);
115114 if (!format.RangeReformat ()) {
116115 // special return code for intellij
@@ -121,7 +120,7 @@ int main(int argc, char **argv) {
121120 return 0 ;
122121}
123122
124- bool InitFormat (CommandLine &cmd, LuaFormat& format) {
123+ bool InitFormat (CommandLine &cmd, LuaFormat & format) {
125124 if (cmd.HasOption (" file" ) || cmd.HasOption (" stdin" )) {
126125 if (cmd.HasOption (" file" )) {
127126 format.SetInputFile (cmd.Get <std::string>(" file" ));
@@ -175,11 +174,15 @@ bool InitFormat(CommandLine &cmd, LuaFormat& format) {
175174 format.SetConfigPath (cmd.Get <std::string>(" config" ));
176175 }
177176
177+ if (cmd.Get <bool >(" non-standard" )) {
178+ format.SupportNonStandardLua ();
179+ }
180+
178181 format.SetDefaultStyle (cmd.GetKeyValueOptions ());
179182 return true ;
180183}
181184
182- bool InitCheck (CommandLine &cmd, LuaFormat& format) {
185+ bool InitCheck (CommandLine &cmd, LuaFormat & format) {
183186
184187 if (cmd.HasOption (" file" ) || cmd.HasOption (" stdin" )) {
185188 if (cmd.HasOption (" file" )) {
@@ -230,13 +233,17 @@ bool InitCheck(CommandLine &cmd, LuaFormat& format) {
230233
231234 format.SetDefaultStyle (cmd.GetKeyValueOptions ());
232235
233- if (cmd.Get <bool >(" name-style" )){
236+ if (cmd.Get <bool >(" name-style" )) {
234237 format.SupportNameStyleCheck ();
235238 }
239+
240+ if (cmd.Get <bool >(" non-standard" )) {
241+ format.SupportNonStandardLua ();
242+ }
236243 return true ;
237244}
238245
239- bool InitRangeFormat (CommandLine &cmd, LuaFormat& format) {
246+ bool InitRangeFormat (CommandLine &cmd, LuaFormat & format) {
240247 if (cmd.HasOption (" file" ) || cmd.HasOption (" stdin" )) {
241248 if (cmd.HasOption (" file" )) {
242249 format.SetInputFile (cmd.Get <std::string>(" file" ));
@@ -285,16 +292,17 @@ bool InitRangeFormat(CommandLine &cmd, LuaFormat& format) {
285292 }
286293
287294 format.SetDefaultStyle (cmd.GetKeyValueOptions ());
288- if (cmd.Get <bool >(" complete-output" )) {
295+ if (cmd.Get <bool >(" complete-output" )) {
289296 format.SupportCompleteOutputRange ();
290297 }
291298
292- if (cmd.HasOption (" range-line" )) {
299+ if (cmd.HasOption (" range-line" )) {
293300 format.SetFormatRange (true , cmd.Get <std::string>(" range-line" ));
294- }
295- else if (cmd.HasOption (" range-offset" )){
301+ } else if (cmd.HasOption (" range-offset" )) {
296302 format.SetFormatRange (false , cmd.Get <std::string>(" range-offset" ));
297303 }
298-
304+ if (cmd.Get <bool >(" non-standard" )) {
305+ format.SupportNonStandardLua ();
306+ }
299307 return true ;
300308}
0 commit comments