├── tests ├── examples │ ├── international │ │ ├── result_astyle │ │ │ ├── .astylerc │ │ │ ├── wsmetric.txt │ │ │ └── IŋƫƐrnætiønæl.c │ │ ├── result_indent │ │ │ ├── .indent.pro │ │ │ ├── wsmetric.txt │ │ │ └── IŋƫƐrnætiønæl.c │ │ ├── result_uncrustify │ │ │ ├── uncrustify.cfg │ │ │ ├── wsmetric.txt │ │ │ └── IŋƫƐrnætiønæl.c │ │ ├── result_clang-format │ │ │ ├── .clang-format │ │ │ ├── wsmetric.txt │ │ │ └── IŋƫƐrnætiønæl.c │ │ └── IŋƫƐrnætiønæl.c │ ├── rustfmt │ │ ├── result_rustfmt │ │ │ ├── rustfmt.toml │ │ │ ├── wsmetric.txt │ │ │ └── checkstyle.rs │ │ ├── LICENSE-MIT │ │ └── checkstyle.rs │ ├── xv6 │ │ ├── result_astyle │ │ │ ├── .astylerc │ │ │ ├── wsmetric.txt │ │ │ └── printf.c │ │ ├── result_indent │ │ │ ├── wsmetric.txt │ │ │ ├── .indent.pro │ │ │ └── printf.c │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ ├── uncrustify.cfg │ │ │ └── printf.c │ │ ├── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ ├── .clang-format │ │ │ └── printf.c │ │ ├── LICENSE │ │ └── printf.c │ ├── maven │ │ ├── result_astyle │ │ │ ├── .astylerc │ │ │ └── wsmetric.txt │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ └── uncrustify.cfg │ │ └── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ └── .clang-format │ ├── spark │ │ ├── result_scalariform │ │ │ ├── formatterPreferences.properties │ │ │ ├── wsmetric.txt │ │ │ └── SparkLR.scala │ │ ├── result_scalafmt │ │ │ ├── wsmetric.txt │ │ │ ├── .scalafmt │ │ │ └── SparkLR.scala │ │ ├── LICENSE │ │ └── SparkLR.scala │ ├── ref_no_align │ │ ├── result_astyle │ │ │ ├── .astylerc │ │ │ ├── wsmetric.txt │ │ │ ├── .astylerc_diff │ │ │ └── noalign.c │ │ ├── result_indent │ │ │ ├── .indent.pro │ │ │ ├── wsmetric.txt │ │ │ ├── .indent.pro_diff │ │ │ └── noalign.c │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ ├── uncrustify.cfg │ │ │ ├── noalign.c │ │ │ └── uncrustify.cfg_diff │ │ ├── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ ├── .clang-format │ │ │ ├── noalign.c │ │ │ └── .clang-format_diff │ │ ├── noalign.c │ │ └── noalign_ref.c │ ├── ref_space_brace │ │ ├── result_indent │ │ │ ├── .indent.pro │ │ │ ├── wsmetric.txt │ │ │ ├── hello.c │ │ │ └── .indent.pro_diff │ │ ├── result_astyle │ │ │ ├── .astylerc │ │ │ ├── wsmetric.txt │ │ │ ├── hello.c │ │ │ └── .astylerc_diff │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ ├── uncrustify.cfg │ │ │ ├── hello.c │ │ │ └── uncrustify.cfg_diff │ │ ├── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ ├── .clang-format │ │ │ ├── hello.c │ │ │ └── .clang-format_diff │ │ ├── hello.c │ │ └── hello_ref.c │ ├── rfmt │ │ ├── result_rfmt │ │ │ ├── wsmetric.txt │ │ │ ├── .rfmtrc │ │ │ └── test.R │ │ └── test.R │ ├── polydraw │ │ ├── result_rustfmt │ │ │ ├── wsmetric.txt │ │ │ └── rustfmt.toml │ │ └── LICENSE │ ├── bottle_sqlalchemy │ │ ├── result_yapf │ │ │ ├── wsmetric.txt │ │ │ ├── .style.yapf │ │ │ └── bottle_sqlalchemy.py │ │ ├── LICENSE │ │ └── bottle_sqlalchemy.py │ ├── HexFiend │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ ├── uncrustify.cfg │ │ │ └── HFIndexSet.h │ │ ├── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ ├── .clang-format │ │ │ └── HFIndexSet.h │ │ ├── License.txt │ │ └── HFIndexSet.h │ ├── lua │ │ ├── result_indent │ │ │ ├── wsmetric.txt │ │ │ └── .indent.pro │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ └── uncrustify.cfg │ │ ├── result_astyle │ │ │ ├── wsmetric.txt │ │ │ └── .astylerc │ │ ├── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ └── .clang-format │ │ ├── LICENSE │ │ └── lstate.h │ ├── nginx │ │ ├── result_indent │ │ │ ├── .indent.pro │ │ │ ├── wsmetric.txt │ │ │ ├── ngx_buf.h │ │ │ └── ngx_buf.c │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ ├── uncrustify.cfg │ │ │ ├── ngx_buf.h │ │ │ └── ngx_buf.c │ │ ├── result_astyle │ │ │ ├── wsmetric.txt │ │ │ ├── .astylerc │ │ │ ├── ngx_buf.h │ │ │ └── ngx_buf.c │ │ ├── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ ├── .clang-format │ │ │ ├── ngx_buf.h │ │ │ └── ngx_buf.c │ │ ├── LICENSE │ │ ├── ngx_buf.h │ │ └── ngx_buf.c │ ├── gumbo-parser │ │ ├── result_uncrustify │ │ │ ├── wsmetric.txt │ │ │ └── uncrustify.cfg │ │ └── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ └── .clang-format │ ├── foundation6 │ │ ├── result_tidy │ │ │ ├── wsmetric.txt │ │ │ └── tidy.conf │ │ ├── LICENSE │ │ └── index.html │ ├── jasmine │ │ ├── result_clang-format │ │ │ ├── .clang-format │ │ │ ├── wsmetric.txt │ │ │ └── Clock.js │ │ ├── MIT.LICENSE │ │ └── Clock.js │ ├── lodepng │ │ └── result_clang-format │ │ │ ├── wsmetric.txt │ │ │ └── .clang-format │ └── README.md └── test_doc.py ├── setup.cfg ├── .style.yapf ├── .gitignore ├── tox.ini ├── MANIFEST.in ├── tools ├── reformat_project.sh ├── remove_resultdirs.py ├── indent_options.py ├── dumpformatoptions.py ├── outtakes.py └── show3diffs.py ├── LICENSE ├── Vagrantfile ├── setup.py └── README.rst /tests/examples/international/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/examples/rustfmt/result_rustfmt/rustfmt.toml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | --indent=spaces=2 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_indent/.indent.pro: -------------------------------------------------------------------------------- 1 | -kr 2 | -brf 3 | -------------------------------------------------------------------------------- /tests/examples/maven/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | --max-instatement-indent=62 2 | -------------------------------------------------------------------------------- /tests/examples/spark/result_scalariform/formatterPreferences.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | --min-conditional-indent=0 2 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_indent/.indent.pro: -------------------------------------------------------------------------------- 1 | -kr 2 | -blf 3 | -prs 4 | -------------------------------------------------------------------------------- /tests/examples/rfmt/result_rfmt/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 56, 138969, 0, 0, 8, 0, 76 # rfmt 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_columns = 4 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_indent/.indent.pro: -------------------------------------------------------------------------------- 1 | -gnu 2 | -npcs 3 | -npsl 4 | -nsaw 5 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | --pad-paren-in 2 | --style=allman 3 | -------------------------------------------------------------------------------- /tests/examples/rustfmt/result_rustfmt/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 0, 0, 1 # rustfmt 0.5.0 2 | -------------------------------------------------------------------------------- /tests/examples/polydraw/result_rustfmt/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 74, 5604, 0, 0, 8, 0, 343 # rustfmt 0.5.0 2 | -------------------------------------------------------------------------------- /tests/examples/spark/result_scalafmt/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 18, 2785, 0, 0, 4, 0, 99 # scalafmt 1.5.1 2 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_indent/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 32, 2352, 0, 0, 14, 0, 445 # GNU indent 2.2.11 2 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 6, 235, 0, 0, 6, 0, 2297 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/bottle_sqlalchemy/result_yapf/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 14, 4018, 0, 0, 6, 0, 72 # yapf 0.10.0 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_indent/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 4, 0, 30 # GNU indent 2.2.11 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 2, 0, 26 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/maven/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 216, 7866, 0, 0, 8, 0, 3072 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_indent/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 8, 7555, 0, 0, 8, 0, 1 # GNU indent 2.2.11 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 6, 0, 27 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/rfmt/result_rfmt/.rfmtrc: -------------------------------------------------------------------------------- 1 | cost1=10 2 | indent=1 3 | margin1=30 4 | space_arg_eq=false 5 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 82, 818, 0, 0, 12, 0, 3077 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 4 3 | -------------------------------------------------------------------------------- /tests/examples/lua/result_indent/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 244, 3006, 2649, 289555, 18, 0, 460 # GNU indent 2.2.11 2 | -------------------------------------------------------------------------------- /tests/examples/lua/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 28, 622, 910, 319184, 92, 0, 4551 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_indent/.indent.pro: -------------------------------------------------------------------------------- 1 | -kr 2 | -c0 3 | -cp0 4 | -di4 5 | -l86 6 | -psl 7 | -ts0 8 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_indent/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 212, 29585, 690, 76312, 14, 0, 508 # GNU indent 2.2.11 2 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 44, 689, 886, 78095, 76, 0, 4365 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_indent/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 6, 0, 396 # GNU indent 2.2.11 2 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 6, 0, 1396 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 28, 1529, 0, 0, 2, 0, 16 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /tests/examples/gumbo-parser/result_uncrustify/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 52, 4037, 0, 0, 10, 0, 3071 # uncrustify 0.63 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 0, 0, 1 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /tests/examples/lua/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 6, 88, 368, 13504, 14, 0, 596 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /tests/examples/maven/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 34, 11370, 0, 0, 2, 0, 66 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /tests/examples/spark/result_scalafmt/.scalafmt: -------------------------------------------------------------------------------- 1 | style = Scala.js 2 | includeCurlyBraceInSelectChains = false 3 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_indent/.indent.pro: -------------------------------------------------------------------------------- 1 | -orig 2 | -nbc 3 | -di0 4 | -i2 5 | -nsai 6 | -nsaw 7 | -ts0 8 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 3 | 4 | [egg_info] 5 | tag_build = 6 | tag_date = 0 7 | tag_svn_revision = 0 8 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 14, 5502, 692, 50806, 8, 0, 526 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 4, 3000, 0, 0, 2, 0, 1 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_astyle/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 4, 0, 318 # Artistic Style Version 2.05.1 2 | -------------------------------------------------------------------------------- /.style.yapf: -------------------------------------------------------------------------------- 1 | [style] 2 | based_on_style = pep8 3 | blank_line_before_nested_class_or_def = true 4 | column_limit = 94 5 | -------------------------------------------------------------------------------- /tests/examples/foundation6/result_tidy/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 307, 45570, 0, 0, 20, 0, 379 # HTML Tidy for Linux version 5.2.0 2 | -------------------------------------------------------------------------------- /tests/examples/spark/result_scalariform/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 16, 2724, 0, 0, 0, 0, 1 # Scalariform 0.1.7 (runtime Scala 2.11.6) 2 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_columns = 2 2 | indent_with_tabs = 0 3 | sp_after_sparen = remove 4 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_columns = 4 2 | indent_continue = -4 3 | indent_with_tabs = 0 4 | -------------------------------------------------------------------------------- /tests/examples/jasmine/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | ColumnLimit: 0 3 | IndentWrappedFunctionNames: true 4 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_columns = 4 2 | nl_fdef_brace = add 3 | sp_inside_fparen = add 4 | -------------------------------------------------------------------------------- /tests/examples/lua/result_indent/.indent.pro: -------------------------------------------------------------------------------- 1 | -gnu 2 | -br 3 | -brf 4 | -cd16 5 | -di0 6 | -nhnl 7 | -npcs 8 | -npsl 9 | -ts16 10 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | --convert-tabs 2 | --keep-one-line-blocks 3 | --max-instatement-indent=45 4 | --style=1tbs 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dist 3 | *.egg-info 4 | *.pyc 5 | *.pyo 6 | *~ 7 | docs/_build 8 | .DS_Store 9 | .idea 10 | .tox 11 | .vagrant 12 | -------------------------------------------------------------------------------- /tests/examples/maven/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 56, 5987, 0, 0, 10, 0, 380 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 6, 0, 1 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 32, 1882, 0, 0, 8, 0, 340 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 130, 3595, 0, 0, 28, 1, 337 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/gumbo-parser/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 6, 0, 306 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/international/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 4, 0, 119 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/jasmine/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 28, 1879, 0, 0, 6, 0, 253 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | BreakBeforeBinaryOperators: None 3 | BreakBeforeBraces: Allman 4 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 0, 0, 0, 0, 8, 0, 286 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/bottle_sqlalchemy/result_yapf/.style.yapf: -------------------------------------------------------------------------------- 1 | [style] 2 | based_on_style = pep8 3 | column_limit = 81 4 | split_before_named_assigns = false 5 | -------------------------------------------------------------------------------- /tests/examples/gumbo-parser/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AlignAfterOpenBracket: DontAlign 3 | SpaceAfterCStyleCast: true 4 | -------------------------------------------------------------------------------- /tests/examples/lua/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 318, 18453, 971, 149871, 30, 1, 407 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 178, 54281, 1094, 167940, 20, 0, 374 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char *argv[]) { 3 | printf("Hello world!\n"); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/examples/lodepng/result_clang-format/wsmetric.txt: -------------------------------------------------------------------------------- 1 | 350, 21801, 4123, 143961, 56, 1, 593 # clang-format version 3.8.0-2ubuntu3 (tags/RELEASE_380/final) 2 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | BreakBeforeBraces: Linux 3 | IndentWidth: 4 4 | SpacesInParentheses: true 5 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Mozilla 2 | DerivePointerAlignment: true 3 | SortIncludes: false 4 | SpaceBeforeParens: Never 5 | -------------------------------------------------------------------------------- /tests/examples/international/IŋƫƐrnætiønæl.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char *argv[]) { 3 | printf("Hello IŋƫƐrnætiønæls\n"); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/examples/maven/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_continue = -4 2 | indent_with_tabs = 0 3 | nl_fdef_brace = remove 4 | use_indent_func_call_param = false 5 | -------------------------------------------------------------------------------- /tests/examples/polydraw/result_rustfmt/rustfmt.toml: -------------------------------------------------------------------------------- 1 | match_block_trailing_comma = true 2 | match_wildcard_trailing_comma = false 3 | max_width = 91 4 | tab_spaces = 3 5 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/hello_ref.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main( int argc, char *argv[] ) 3 | { 4 | printf( "Hello world!\n" ); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_indent/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int 3 | main (int argc, char *argv[]) 4 | { 5 | printf ("Hello world!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_astyle/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main( int argc, char *argv[] ) 3 | { 4 | printf( "Hello world!\n" ); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/examples/international/result_astyle/IŋƫƐrnætiønæl.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char *argv[]) { 3 | printf("Hello IŋƫƐrnætiønæls\n"); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_clang-format/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main( int argc, char *argv[] ) 3 | { 4 | printf( "Hello world!\n" ); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_uncrustify/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main( int argc, char *argv[] ) 3 | { 4 | printf( "Hello world!\n" ); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/examples/international/result_clang-format/IŋƫƐrnætiønæl.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char *argv[]) { 3 | printf("Hello IŋƫƐrnætiønæls\n"); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/examples/international/result_indent/IŋƫƐrnætiønæl.c: -------------------------------------------------------------------------------- 1 | #include 2 | int 3 | main (int argc, char *argv[]) 4 | { 5 | printf ("Hello IŋƫƐrnætiønæls\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/examples/international/result_uncrustify/IŋƫƐrnætiønæl.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char *argv[]) { 3 | printf("Hello IŋƫƐrnætiønæls\n"); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/test_doc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import whatstyle 5 | 6 | if __name__ == "__main__": 7 | import doctest 8 | doctest.testmod(whatstyle) 9 | -------------------------------------------------------------------------------- /tests/examples/gumbo-parser/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_columns = 2 2 | indent_continue = 4 3 | indent_paren_nl = true 4 | indent_with_tabs = 0 5 | nl_func_leave_one_liners = true 6 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | cmt_indent_multi = false 2 | indent_columns = 4 3 | indent_with_tabs = 0 4 | nl_after_for = remove 5 | nl_before_for = remove 6 | sp_not = add 7 | -------------------------------------------------------------------------------- /tests/examples/lua/result_astyle/.astylerc: -------------------------------------------------------------------------------- 1 | --align-pointer=name 2 | --delete-empty-lines 3 | --indent=spaces=2 4 | --keep-one-line-statements 5 | --pad-header 6 | --remove-brackets 7 | --style=java 8 | -------------------------------------------------------------------------------- /tests/examples/maven/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | BreakBeforeBraces: Allman 3 | ColumnLimit: 0 4 | KeepEmptyLinesAtTheStartOfBlocks: true 5 | SpacesInParentheses: true 6 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py35, py36 3 | skip_missing_interpreters = True 4 | 5 | [testenv] 6 | setenv = LC_ALL=C 7 | commands = 8 | python tests/test_doc.py 9 | python tests/test_whatstyle.py 10 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_astyle/.astylerc_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | --min-conditional-indent=0 3 | 4 | # Best style for the to-files 5 | --min-conditional-indent=0 6 | 7 | # No style difference found. 8 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_indent/.indent.pro_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | -gnu 3 | -npcs 4 | -npsl 5 | -nsaw 6 | 7 | # Best style for the to-files 8 | -gnu 9 | -npcs 10 | -npsl 11 | -nsaw 12 | 13 | # No style difference found. 14 | -------------------------------------------------------------------------------- /tests/examples/foundation6/result_tidy/tidy.conf: -------------------------------------------------------------------------------- 1 | add-xml-space: yes 2 | doctype: omit 3 | indent: yes 4 | literal-attributes: yes 5 | output-encoding: ascii 6 | output-html: yes 7 | output-xhtml: yes 8 | quote-marks: yes 9 | tidy-mark: no 10 | wrap: 0 11 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_astyle/.astylerc_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | 3 | 4 | # Best style for the to-files 5 | --pad-paren-in 6 | --style=allman 7 | 8 | # These options are unique to the to-files: 9 | --pad-paren-in 10 | --style=allman 11 | 12 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | AllowShortIfStatementsOnASingleLine: true 3 | BraceWrapping: 4 | BeforeElse: true 5 | BreakBeforeBraces: Custom 6 | Cpp11BracedListStyle: true 7 | DerivePointerAlignment: true 8 | MaxEmptyLinesToKeep: 2 9 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/noalign.c: -------------------------------------------------------------------------------- 1 | /* Example from http://stackoverflow.com/questions/7730378/using-uncrustify-without-aligning-under-open-parenthesis */ 2 | 3 | void f(void) 4 | { 5 | while (one && 6 | two) 7 | { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/noalign_ref.c: -------------------------------------------------------------------------------- 1 | /* Example from http://stackoverflow.com/questions/7730378/using-uncrustify-without-aligning-under-open-parenthesis */ 2 | 3 | void f(void) 4 | { 5 | while (one && 6 | two) 7 | { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_indent/noalign.c: -------------------------------------------------------------------------------- 1 | /* Example from http://stackoverflow.com/questions/7730378/using-uncrustify-without-aligning-under-open-parenthesis */ 2 | 3 | void 4 | f (void) 5 | { 6 | while (one && two) 7 | { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_astyle/noalign.c: -------------------------------------------------------------------------------- 1 | /* Example from http://stackoverflow.com/questions/7730378/using-uncrustify-without-aligning-under-open-parenthesis */ 2 | 3 | void f(void) 4 | { 5 | while (one && 6 | two) 7 | { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_clang-format/noalign.c: -------------------------------------------------------------------------------- 1 | /* Example from http://stackoverflow.com/questions/7730378/using-uncrustify-without-aligning-under-open-parenthesis */ 2 | 3 | void f(void) 4 | { 5 | while (one && 6 | two) 7 | { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_uncrustify/noalign.c: -------------------------------------------------------------------------------- 1 | /* Example from http://stackoverflow.com/questions/7730378/using-uncrustify-without-aligning-under-open-parenthesis */ 2 | 3 | void f(void) 4 | { 5 | while (one && 6 | two) 7 | { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/examples/lua/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | BreakBeforeBraces: Custom 3 | ColumnLimit: 0 4 | DerivePointerAlignment: false 5 | IndentWrappedFunctionNames: true 6 | MaxEmptyLinesToKeep: 2 7 | PointerAlignment: Right 8 | ReflowComments: false 9 | SortIncludes: false 10 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_indent/.indent.pro_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | -kr 3 | -brf 4 | 5 | # Best style for the to-files 6 | -kr 7 | -blf 8 | -prs 9 | 10 | # These options are unique to the from-files: 11 | -brf 12 | 13 | # These options are unique to the to-files: 14 | -blf 15 | -prs 16 | 17 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_uncrustify/uncrustify.cfg_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | indent_columns = 4 3 | indent_with_tabs = 0 4 | 5 | # Best style for the to-files 6 | indent_columns = 4 7 | indent_continue = -4 8 | indent_with_tabs = 0 9 | 10 | # These options are unique to the to-files: 11 | indent_continue = -4 12 | 13 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_uncrustify/uncrustify.cfg_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | indent_columns = 4 3 | 4 | # Best style for the to-files 5 | indent_columns = 4 6 | nl_fdef_brace = add 7 | sp_inside_fparen = add 8 | 9 | # These options are unique to the to-files: 10 | nl_fdef_brace = add 11 | sp_inside_fparen = add 12 | 13 | -------------------------------------------------------------------------------- /tests/examples/ref_no_align/result_clang-format/.clang-format_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | BasedOnStyle: WebKit 3 | BreakBeforeBinaryOperators: None 4 | BreakBeforeBraces: Allman 5 | 6 | # Best style for the to-files 7 | BasedOnStyle: WebKit 8 | BreakBeforeBinaryOperators: None 9 | BreakBeforeBraces: Allman 10 | 11 | # No style difference found. 12 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | AlignOperands: true 3 | AlignTrailingComments: true 4 | AlwaysBreakAfterDefinitionReturnType: All 5 | BreakBeforeBinaryOperators: NonAssignment 6 | BreakBeforeTernaryOperators: false 7 | DerivePointerAlignment: false 8 | MaxEmptyLinesToKeep: 2 9 | PointerAlignment: Right 10 | SpaceAfterCStyleCast: true 11 | -------------------------------------------------------------------------------- /tests/examples/ref_space_brace/result_clang-format/.clang-format_diff: -------------------------------------------------------------------------------- 1 | # Best style for the from-files 2 | BasedOnStyle: Google 3 | IndentWidth: 4 4 | 5 | # Best style for the to-files 6 | BasedOnStyle: Google 7 | BreakBeforeBraces: Linux 8 | IndentWidth: 4 9 | SpacesInParentheses: true 10 | 11 | # These options are unique to the to-files: 12 | BreakBeforeBraces: Linux 13 | SpacesInParentheses: true 14 | 15 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | global-exclude *.pyc *.pyo .idea .DS_Store 2 | 3 | include whatstyle.py tox.ini README.rst MANIFEST.in LICENSE Vagrantfile 4 | include .style.yapf 5 | 6 | recursive-include tests COPYING LICENSE *.LICENSE 7 | recursive-include tests *.md *.txt 8 | recursive-include tests *.c *.cpp *.h *.html *.java *.js *.m *.py *.yapf 9 | recursive-include tests *.astylerc *.astylerc_diff 10 | recursive-include tests *.cfg *.cfg_diff 11 | recursive-include tests *.clang-format *.clang-format_diff 12 | recursive-include tests *.conf 13 | recursive-include tests *.pro *.pro_diff 14 | recursive-include tools *.sh *.py 15 | -------------------------------------------------------------------------------- /tools/reformat_project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Reformats the source file of the whatstyle project. 4 | # 5 | 6 | set -eEu -o pipefail 7 | shopt -s extdebug 8 | IFS=$'\n\t' 9 | 10 | TOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 11 | cd "$TOOLSDIR/.." 12 | 13 | while read filename ; do 14 | set +e 15 | ( set -x ; yapf --in-place "$filename" ) 16 | done <<-ENDOFFILES 17 | tests/test_examples.py 18 | tests/test_whatstyle.py 19 | tools/create_formatstyle_history.py 20 | tools/indent_options.py 21 | tools/outtakes.py 22 | tools/remove_resultdirs.py 23 | tools/show3diffs.py 24 | whatstyle.py 25 | ENDOFFILES 26 | -------------------------------------------------------------------------------- /tests/examples/lodepng/result_clang-format/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AlignAfterOpenBracket: AlwaysBreak 3 | AlignTrailingComments: false 4 | AllowShortBlocksOnASingleLine: true 5 | AllowShortCaseLabelsOnASingleLine: true 6 | BraceWrapping: 7 | AfterControlStatement: true 8 | AfterFunction: true 9 | AfterStruct: true 10 | BeforeElse: true 11 | BreakBeforeBraces: Custom 12 | BreakBeforeTernaryOperators: false 13 | ColumnLimit: 0 14 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 15 | ContinuationIndentWidth: 0 16 | Cpp11BracedListStyle: false 17 | IndentWrappedFunctionNames: true 18 | MaxEmptyLinesToKeep: 2 19 | SortIncludes: false 20 | SpaceBeforeParens: Never 21 | SpacesBeforeTrailingComments: 1 22 | Standard: Cpp03 23 | -------------------------------------------------------------------------------- /tests/examples/rfmt/result_rfmt/test.R: -------------------------------------------------------------------------------- 1 | ## Not run: 2 | new.data <- new.data[ 3 | , object$vars$all, 4 | drop=FALSE] 5 | 6 | if (others > 0 && 7 | others < 10) { 8 | object$model <- gsub( 9 | "parm1", # Alter model in 10 | # accordance with 11 | # new data 12 | paste("parm1=", others, 13 | sep=""), object$model) 14 | } 15 | 16 | ## Make data file 17 | data.fn <- makeNewDataFile( 18 | x=newdata, y=NULL) 19 | 20 | ## Finally, compute forecast for new data 21 | Z <- .C( 22 | "forecast", # See src/top.c 23 | as.character(data.fn), 24 | as.character(object$names), 25 | as.character(object$data), 26 | as.character(object$model), 27 | pred=double(nrow(new.data)), 28 | output=character(1), 29 | PACKAGE="test") 30 | ## End(**Not run**) 31 | -------------------------------------------------------------------------------- /tests/examples/spark/LICENSE: -------------------------------------------------------------------------------- 1 | Licensed to the Apache Software Foundation (ASF) under one or more 2 | contributor license agreements. See the NOTICE file distributed with 3 | this work for additional information regarding copyright ownership. 4 | The ASF licenses this file to You under the Apache License, Version 2.0 5 | (the "License"); you may not use this file except in compliance with 6 | the License. You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | -------------------------------------------------------------------------------- /tests/examples/README.md: -------------------------------------------------------------------------------- 1 | To test this project source code files from various open source projects 2 | are included in this directory. 3 | 4 | HexFiend (https://github.com/ridiculousfish/HexFiend) 5 | bottle-sqlalchemy (https://github.com/iurisilvio/bottle-sqlalchemy) 6 | foundation6 (https://foundation.zurb.com/sites/download/) 7 | gumbo-parser (https://github.com/google/gumbo-parser) 8 | jasmine (https://github.com/jasmine/jasmine) 9 | lodepng (https://github.com/lvandeve/lodepng) 10 | lua (https://github.com/lua/lua) 11 | maven (https://github.com/apache/maven) 12 | nginx (https://github.com/nginx/nginx) 13 | polydraw (https://github.com/polydraw/polydraw) 14 | rfmt (https://github.com/google/rfmt) 15 | rustfmt (https://github.com/rust-lang-nursery/rustfmt) 16 | spark (https://spark.apache.org) 17 | xv6 (https://github.com/guilleiguaran/xv6) 18 | -------------------------------------------------------------------------------- /tests/examples/rfmt/test.R: -------------------------------------------------------------------------------- 1 | ## Not run: 2 | new.data <- new.data[,object$vars$all,drop = FALSE] 3 | 4 | if(others > 0 && others < 10) { object$model <- gsub("parm1", # Alter model in accordance with new data 5 | paste("parm1=", 6 | others, 7 | sep = ""), 8 | object$model)} 9 | 10 | ## Make data file 11 | data.fn <- makeNewDataFile(x = newdata, 12 | y = NULL) 13 | 14 | ## Finally, compute forecast for new data 15 | Z <- .C("forecast", # See src/top.c 16 | as.character(data.fn), 17 | as.character(object$names), as.character(object$data), 18 | as.character(object$model), 19 | pred = double(nrow(new.data)), 20 | output = character(1), 21 | PACKAGE = "test" ) 22 | ## End(**Not run**) 23 | -------------------------------------------------------------------------------- /tools/remove_resultdirs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This script deletes all tests/examples/result_* directories. 5 | # --------------------------------------------------------------------- 6 | 7 | from __future__ import print_function 8 | 9 | import os 10 | import sys 11 | from os.path import abspath, basename, dirname, join 12 | 13 | PY2 = sys.version_info[0] == 2 14 | PY3 = sys.version_info[0] == 3 15 | 16 | 17 | def main(): 18 | exdir = join(dirname(dirname(abspath(__file__))), 'tests', 'examples') 19 | print(exdir) 20 | for path, dirs, files in os.walk(exdir): 21 | base = basename(path) 22 | if not base.startswith('result_'): 23 | continue 24 | for name in files: 25 | filename = os.path.join(path, name) 26 | print("Deleting %s" % filename) 27 | os.remove(filename) 28 | print("Deleting %s" % path) 29 | os.rmdir(path) 30 | 31 | 32 | if __name__ == '__main__': 33 | sys.exit(main()) 34 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | indent_columns = 4 2 | indent_func_def_param = true 3 | indent_func_proto_param = true 4 | indent_paren_nl = true 5 | indent_with_tabs = 0 6 | input_tab_size = 1 7 | mod_full_brace_for = add 8 | mod_full_brace_if = add 9 | nl_after_do = add 10 | nl_after_for = add 11 | nl_after_if = add 12 | nl_after_while = add 13 | nl_before_do = add 14 | nl_before_for = add 15 | nl_before_while = add 16 | nl_brace_else = remove 17 | nl_brace_struct_var = remove 18 | nl_do_brace = remove 19 | nl_else_brace = remove 20 | nl_fdef_brace = add 21 | nl_func_decl_end = remove 22 | nl_func_def_end = remove 23 | nl_return_expr = remove 24 | nl_struct_brace = remove 25 | nl_while_brace = remove 26 | sp_after_cast = add 27 | sp_after_comma = add 28 | sp_after_type = add 29 | sp_assign = add 30 | sp_before_sparen = add 31 | sp_before_unnamed_ptr_star = add 32 | sp_bool = add 33 | sp_brace_typedef = add 34 | sp_cond_colon = remove 35 | sp_endif_cmt = add 36 | sp_inside_fparen = remove 37 | sp_inside_paren = remove 38 | sp_inside_paren_cast = remove 39 | -------------------------------------------------------------------------------- /tests/examples/lua/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 1994–2015 Lua.org, PUC-Rio. 2 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 3 | 4 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 5 | 6 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 7 | -------------------------------------------------------------------------------- /tests/examples/jasmine/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2016 Pivotal Labs 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /tests/examples/bottle_sqlalchemy/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2014, Iuri de Silvio 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /tests/examples/foundation6/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2016 ZURB, inc. 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /tests/examples/polydraw/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 polydraw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Michael Krause ( http://krause-software.com ) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /tests/examples/rustfmt/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /tests/examples/xv6/LICENSE: -------------------------------------------------------------------------------- 1 | The xv6 software is: 2 | 3 | Copyright (c) 2006-2009 Frans Kaashoek, Robert Morris, Russ Cox, 4 | Massachusetts Institute of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /tests/examples/lua/result_uncrustify/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | align_keep_tabs = true 2 | cmt_convert_tab_to_spaces = true 3 | cmt_indent_multi = false 4 | eat_blanks_before_close_brace = true 5 | indent_columns = 2 6 | mod_full_brace_for = remove 7 | mod_full_brace_if = remove 8 | mod_paren_on_return = remove 9 | nl_after_for = remove 10 | nl_after_if = remove 11 | nl_before_for = remove 12 | nl_before_if = remove 13 | nl_before_while = remove 14 | nl_brace_struct_var = remove 15 | nl_fdef_brace = remove 16 | nl_func_decl_args = remove 17 | nl_func_decl_end = remove 18 | nl_func_def_args = remove 19 | nl_func_def_end = remove 20 | nl_if_brace = remove 21 | nl_return_expr = remove 22 | nl_struct_brace = remove 23 | nl_union_brace = remove 24 | nl_while_brace = remove 25 | pp_space = remove 26 | sp_after_ptr_star = remove 27 | sp_before_sparen = add 28 | sp_before_square = remove 29 | sp_before_unnamed_ptr_star = add 30 | sp_between_ptr_star = remove 31 | sp_bool = add 32 | sp_brace_typedef = add 33 | sp_compare = add 34 | sp_defined_paren = remove 35 | sp_fparen_brace = force 36 | sp_func_call_paren = remove 37 | sp_func_def_paren = add 38 | sp_inside_braces = add 39 | sp_inside_braces_struct = add 40 | sp_inside_fparen = remove 41 | sp_inside_fparens = remove 42 | sp_inside_paren = remove 43 | sp_inside_sparen = remove 44 | sp_inside_square = remove 45 | sp_paren_paren = remove 46 | sp_sizeof_paren = remove 47 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005-2011, Peter Ammon 2 | * All rights reserved. 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions are met: 5 | * 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * 12 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 13 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 16 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 19 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | -------------------------------------------------------------------------------- /tests/examples/nginx/LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002-2016 Igor Sysoev 3 | * Copyright (C) 2011-2016 Nginx, Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | # 4 | # This defines a Ubuntu 16.04 based VM in which some code formatters are installed 5 | # for testing whatstyle. 6 | 7 | Vagrant.configure(2) do |config| 8 | 9 | config.vm.box = "ubuntu/xenial64" 10 | config.vm.box_check_update = false 11 | 12 | config.vm.provider "virtualbox" do |vb| 13 | vb.memory = 2048 14 | vb.cpus = 4 15 | vb.name = nil 16 | end 17 | 18 | # Set disabled to false after provisioning. 19 | config.vm.synced_folder ".", "/vagrant", disabled: true 20 | 21 | config.vm.provision "shell", inline: <<-SHELL 22 | # Fix the "sudo: unable to resolve host ubuntu-xenial" message 23 | sudo sed -i -e "s/127.0.0.1 localhost$/127.0.0.1 localhost ubuntu-xenial/g" /etc/hosts 24 | 25 | sudo apt-get update 26 | 27 | # Install tools and formatters that come with Ubuntu 28 | sudo apt-get install -y autoconf cmake clang unzip python python-pip clang-format indent astyle 29 | 30 | # Install recent version of uncrustify 31 | export VERSION=0.63 32 | curl -L -O https://github.com/uncrustify/uncrustify/archive/uncrustify-${VERSION}.zip 33 | unzip uncrustify-${VERSION}.zip 34 | cd uncrustify-uncrustify-${VERSION} 35 | ./autogen.sh ; ./configure ; sudo make install 36 | 37 | # Compile tidy-html5 from source 38 | export VERSION=5.2.0 39 | curl -L -O https://github.com/htacg/tidy-html5/archive/${VERSION}.tar.gz 40 | sudo tar zxf ${VERSION}.tar.gz ; cd tidy-html5-${VERSION}; cmake . ; sudo make install 41 | 42 | # Install yapf 43 | sudo pip install yapf==0.10.0 44 | 45 | # Install VirtualBox Guest Additions kernel modules for the shared /vagrant directory. 46 | sudo apt-get install -y virtualbox-guest-dkms 47 | SHELL 48 | 49 | end 50 | -------------------------------------------------------------------------------- /tests/examples/xv6/printf.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "stat.h" 3 | #include "user.h" 4 | 5 | static void 6 | putc(int fd, char c) 7 | { 8 | write(fd, &c, 1); 9 | } 10 | 11 | static void 12 | printint(int fd, int xx, int base, int sgn) 13 | { 14 | static char digits[] = "0123456789ABCDEF"; 15 | char buf[16]; 16 | int i, neg; 17 | uint x; 18 | 19 | neg = 0; 20 | if(sgn && xx < 0){ 21 | neg = 1; 22 | x = -xx; 23 | } else { 24 | x = xx; 25 | } 26 | 27 | i = 0; 28 | do{ 29 | buf[i++] = digits[x % base]; 30 | }while((x /= base) != 0); 31 | if(neg) 32 | buf[i++] = '-'; 33 | 34 | while(--i >= 0) 35 | putc(fd, buf[i]); 36 | } 37 | 38 | // Print to the given fd. Only understands %d, %x, %p, %s. 39 | void 40 | printf(int fd, char *fmt, ...) 41 | { 42 | char *s; 43 | int c, i, state; 44 | uint *ap; 45 | 46 | state = 0; 47 | ap = (uint*)(void*)&fmt + 1; 48 | for(i = 0; fmt[i]; i++){ 49 | c = fmt[i] & 0xff; 50 | if(state == 0){ 51 | if(c == '%'){ 52 | state = '%'; 53 | } else { 54 | putc(fd, c); 55 | } 56 | } else if(state == '%'){ 57 | if(c == 'd'){ 58 | printint(fd, *ap, 10, 1); 59 | ap++; 60 | } else if(c == 'x' || c == 'p'){ 61 | printint(fd, *ap, 16, 0); 62 | ap++; 63 | } else if(c == 's'){ 64 | s = (char*)*ap; 65 | ap++; 66 | if(s == 0) 67 | s = "(null)"; 68 | while(*s != 0){ 69 | putc(fd, *s); 70 | s++; 71 | } 72 | } else if(c == 'c'){ 73 | putc(fd, *ap); 74 | ap++; 75 | } else if(c == '%'){ 76 | putc(fd, c); 77 | } else { 78 | // Unknown % sequence. Print it to draw attention. 79 | putc(fd, '%'); 80 | putc(fd, c); 81 | } 82 | state = 0; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_uncrustify/printf.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "stat.h" 3 | #include "user.h" 4 | 5 | static void 6 | putc(int fd, char c) 7 | { 8 | write(fd, &c, 1); 9 | } 10 | 11 | static void 12 | printint(int fd, int xx, int base, int sgn) 13 | { 14 | static char digits[] = "0123456789ABCDEF"; 15 | char buf[16]; 16 | int i, neg; 17 | uint x; 18 | 19 | neg = 0; 20 | if(sgn && xx < 0){ 21 | neg = 1; 22 | x = -xx; 23 | } else { 24 | x = xx; 25 | } 26 | 27 | i = 0; 28 | do { 29 | buf[i++] = digits[x % base]; 30 | } while((x /= base) != 0); 31 | if(neg) 32 | buf[i++] = '-'; 33 | 34 | while(--i >= 0) 35 | putc(fd, buf[i]); 36 | } 37 | 38 | // Print to the given fd. Only understands %d, %x, %p, %s. 39 | void 40 | printf(int fd, char *fmt, ...) 41 | { 42 | char *s; 43 | int c, i, state; 44 | uint *ap; 45 | 46 | state = 0; 47 | ap = (uint*)(void*)&fmt + 1; 48 | for(i = 0; fmt[i]; i++){ 49 | c = fmt[i] & 0xff; 50 | if(state == 0){ 51 | if(c == '%'){ 52 | state = '%'; 53 | } else { 54 | putc(fd, c); 55 | } 56 | } else if(state == '%'){ 57 | if(c == 'd'){ 58 | printint(fd, *ap, 10, 1); 59 | ap++; 60 | } else if(c == 'x' || c == 'p'){ 61 | printint(fd, *ap, 16, 0); 62 | ap++; 63 | } else if(c == 's'){ 64 | s = (char*)*ap; 65 | ap++; 66 | if(s == 0) 67 | s = "(null)"; 68 | while(*s != 0){ 69 | putc(fd, *s); 70 | s++; 71 | } 72 | } else if(c == 'c'){ 73 | putc(fd, *ap); 74 | ap++; 75 | } else if(c == '%'){ 76 | putc(fd, c); 77 | } else { 78 | // Unknown % sequence. Print it to draw attention. 79 | putc(fd, '%'); 80 | putc(fd, c); 81 | } 82 | state = 0; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_astyle/printf.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "stat.h" 3 | #include "user.h" 4 | 5 | static void 6 | putc(int fd, char c) 7 | { 8 | write(fd, &c, 1); 9 | } 10 | 11 | static void 12 | printint(int fd, int xx, int base, int sgn) 13 | { 14 | static char digits[] = "0123456789ABCDEF"; 15 | char buf[16]; 16 | int i, neg; 17 | uint x; 18 | 19 | neg = 0; 20 | if(sgn && xx < 0) { 21 | neg = 1; 22 | x = -xx; 23 | } else { 24 | x = xx; 25 | } 26 | 27 | i = 0; 28 | do { 29 | buf[i++] = digits[x % base]; 30 | } while((x /= base) != 0); 31 | if(neg) 32 | buf[i++] = '-'; 33 | 34 | while(--i >= 0) 35 | putc(fd, buf[i]); 36 | } 37 | 38 | // Print to the given fd. Only understands %d, %x, %p, %s. 39 | void 40 | printf(int fd, char *fmt, ...) 41 | { 42 | char *s; 43 | int c, i, state; 44 | uint *ap; 45 | 46 | state = 0; 47 | ap = (uint*)(void*)&fmt + 1; 48 | for(i = 0; fmt[i]; i++) { 49 | c = fmt[i] & 0xff; 50 | if(state == 0) { 51 | if(c == '%') { 52 | state = '%'; 53 | } else { 54 | putc(fd, c); 55 | } 56 | } else if(state == '%') { 57 | if(c == 'd') { 58 | printint(fd, *ap, 10, 1); 59 | ap++; 60 | } else if(c == 'x' || c == 'p') { 61 | printint(fd, *ap, 16, 0); 62 | ap++; 63 | } else if(c == 's') { 64 | s = (char*)*ap; 65 | ap++; 66 | if(s == 0) 67 | s = "(null)"; 68 | while(*s != 0) { 69 | putc(fd, *s); 70 | s++; 71 | } 72 | } else if(c == 'c') { 73 | putc(fd, *ap); 74 | ap++; 75 | } else if(c == '%') { 76 | putc(fd, c); 77 | } else { 78 | // Unknown % sequence. Print it to draw attention. 79 | putc(fd, '%'); 80 | putc(fd, c); 81 | } 82 | state = 0; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_clang-format/printf.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "stat.h" 3 | #include "user.h" 4 | 5 | static void 6 | putc(int fd, char c) 7 | { 8 | write(fd, &c, 1); 9 | } 10 | 11 | static void 12 | printint(int fd, int xx, int base, int sgn) 13 | { 14 | static char digits[] = "0123456789ABCDEF"; 15 | char buf[16]; 16 | int i, neg; 17 | uint x; 18 | 19 | neg = 0; 20 | if(sgn && xx < 0) { 21 | neg = 1; 22 | x = -xx; 23 | } else { 24 | x = xx; 25 | } 26 | 27 | i = 0; 28 | do { 29 | buf[i++] = digits[x % base]; 30 | } while((x /= base) != 0); 31 | if(neg) 32 | buf[i++] = '-'; 33 | 34 | while(--i >= 0) 35 | putc(fd, buf[i]); 36 | } 37 | 38 | // Print to the given fd. Only understands %d, %x, %p, %s. 39 | void 40 | printf(int fd, char *fmt, ...) 41 | { 42 | char *s; 43 | int c, i, state; 44 | uint *ap; 45 | 46 | state = 0; 47 | ap = (uint *)(void *)&fmt + 1; 48 | for(i = 0; fmt[i]; i++) { 49 | c = fmt[i] & 0xff; 50 | if(state == 0) { 51 | if(c == '%') { 52 | state = '%'; 53 | } else { 54 | putc(fd, c); 55 | } 56 | } else if(state == '%') { 57 | if(c == 'd') { 58 | printint(fd, *ap, 10, 1); 59 | ap++; 60 | } else if(c == 'x' || c == 'p') { 61 | printint(fd, *ap, 16, 0); 62 | ap++; 63 | } else if(c == 's') { 64 | s = (char *)*ap; 65 | ap++; 66 | if(s == 0) 67 | s = "(null)"; 68 | while(*s != 0) { 69 | putc(fd, *s); 70 | s++; 71 | } 72 | } else if(c == 'c') { 73 | putc(fd, *ap); 74 | ap++; 75 | } else if(c == '%') { 76 | putc(fd, c); 77 | } else { 78 | // Unknown % sequence. Print it to draw attention. 79 | putc(fd, '%'); 80 | putc(fd, c); 81 | } 82 | state = 0; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/examples/xv6/result_indent/printf.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "stat.h" 3 | #include "user.h" 4 | 5 | static void 6 | putc (int fd, char c) 7 | { 8 | write (fd, &c, 1); 9 | } 10 | 11 | static void 12 | printint (int fd, int xx, int base, int sgn) 13 | { 14 | static char digits[] = "0123456789ABCDEF"; 15 | char buf[16]; 16 | int i, neg; 17 | uint x; 18 | 19 | neg = 0; 20 | if (sgn && xx < 0) 21 | { 22 | neg = 1; 23 | x = -xx; 24 | } 25 | else 26 | { 27 | x = xx; 28 | } 29 | 30 | i = 0; 31 | do 32 | { 33 | buf[i++] = digits[x % base]; 34 | } 35 | while ((x /= base) != 0); 36 | if (neg) 37 | buf[i++] = '-'; 38 | 39 | while (--i >= 0) 40 | putc (fd, buf[i]); 41 | } 42 | 43 | // Print to the given fd. Only understands %d, %x, %p, %s. 44 | void 45 | printf (int fd, char *fmt, ...) 46 | { 47 | char *s; 48 | int c, i, state; 49 | uint *ap; 50 | 51 | state = 0; 52 | ap = (uint *) (void *) &fmt + 1; 53 | for (i = 0; fmt[i]; i++) 54 | { 55 | c = fmt[i] & 0xff; 56 | if (state == 0) 57 | { 58 | if (c == '%') 59 | { 60 | state = '%'; 61 | } 62 | else 63 | { 64 | putc (fd, c); 65 | } 66 | } 67 | else if (state == '%') 68 | { 69 | if (c == 'd') 70 | { 71 | printint (fd, *ap, 10, 1); 72 | ap++; 73 | } 74 | else if (c == 'x' || c == 'p') 75 | { 76 | printint (fd, *ap, 16, 0); 77 | ap++; 78 | } 79 | else if (c == 's') 80 | { 81 | s = (char *) *ap; 82 | ap++; 83 | if (s == 0) 84 | s = "(null)"; 85 | while (*s != 0) 86 | { 87 | putc (fd, *s); 88 | s++; 89 | } 90 | } 91 | else if (c == 'c') 92 | { 93 | putc (fd, *ap); 94 | ap++; 95 | } 96 | else if (c == '%') 97 | { 98 | putc (fd, c); 99 | } 100 | else 101 | { 102 | // Unknown % sequence. Print it to draw attention. 103 | putc (fd, '%'); 104 | putc (fd, c); 105 | } 106 | state = 0; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | try: 4 | from setuptools import setup, Command 5 | except ImportError: 6 | from distutils.core import setup, Command 7 | 8 | 9 | class RunTest(Command): 10 | 11 | user_options = [] 12 | 13 | def initialize_options(self): 14 | pass 15 | 16 | def finalize_options(self): 17 | pass 18 | 19 | def run(self): 20 | import sys 21 | import subprocess 22 | errno = subprocess.call([sys.executable, 'tests/test_whatstyle.py']) 23 | raise SystemExit(errno) 24 | 25 | 26 | with open('README.rst') as f: 27 | readme = f.read() 28 | 29 | setup( 30 | name='whatstyle', 31 | version='0.1.9', 32 | url='https://github.com/mikr/whatstyle', 33 | license='MIT', 34 | author='Michael Krause', 35 | author_email='michael@krause-software.com', 36 | description='whatstyle finds a code format style that fits given source files.', 37 | long_description=readme, 38 | py_modules=['whatstyle'], 39 | cmdclass={'test': RunTest}, 40 | zip_safe=False, 41 | platforms='any', 42 | keywords='formatter beautifier clang-format yapf tidy indent astyle uncrustify ' 43 | 'scalariform scalafmt rfmt rustfmt', 44 | classifiers=[ 45 | 'Development Status :: 4 - Beta', 46 | 'Environment :: Console', 47 | 'Intended Audience :: Developers', 48 | 'License :: OSI Approved :: MIT License', 49 | 'Natural Language :: English', 50 | 'Operating System :: OS Independent', 51 | 'Programming Language :: Python :: 2.7', 52 | 'Programming Language :: Python :: 3.4', 53 | 'Programming Language :: Python :: 3.5', 54 | 'Programming Language :: Python :: 3.6', 55 | 'Programming Language :: Python :: 3.7', 56 | 'Programming Language :: Python :: 3.8', 57 | 'Programming Language :: Python :: 3.9', 58 | 'Topic :: Software Development :: Libraries :: Python Modules', 59 | 'Topic :: Software Development :: Quality Assurance', 60 | 'Topic :: Utilities', 61 | ], 62 | entry_points={ 63 | 'console_scripts': [ 64 | 'whatstyle = whatstyle:main' 65 | ] 66 | }, 67 | ) 68 | -------------------------------------------------------------------------------- /tests/examples/rustfmt/checkstyle.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | use rustfmt_diff::{Mismatch, DiffLine}; 11 | use std::io::{self, Write}; 12 | use config::WriteMode; 13 | 14 | 15 | pub fn output_header(out: &mut T, mode: WriteMode) -> Result<(), io::Error> 16 | where T: Write 17 | { 18 | if mode == WriteMode::Checkstyle { 19 | let mut xml_heading = String::new(); 20 | xml_heading.push_str(""); 21 | xml_heading.push_str("\n"); 22 | xml_heading.push_str(""); 23 | try!(write!(out, "{}", xml_heading)); 24 | } 25 | Ok(()) 26 | } 27 | 28 | pub fn output_footer(out: &mut T, mode: WriteMode) -> Result<(), io::Error> 29 | where T: Write 30 | { 31 | if mode == WriteMode::Checkstyle { 32 | let mut xml_tail = String::new(); 33 | xml_tail.push_str(""); 34 | try!(write!(out, "{}", xml_tail)); 35 | } 36 | Ok(()) 37 | } 38 | 39 | pub fn output_checkstyle_file(mut writer: T, 40 | filename: &str, 41 | diff: Vec) 42 | -> Result<(), io::Error> 43 | where T: Write 44 | { 45 | try!(write!(writer, "", filename)); 46 | for mismatch in diff { 47 | for line in mismatch.lines { 48 | match line { 49 | DiffLine::Expected(ref str) => { 50 | let message = xml_escape_str(&str); 51 | try!(write!(writer, 52 | "", 54 | mismatch.line_number, 55 | message)); 56 | } 57 | _ => { 58 | // Do nothing with context and expected. 59 | } 60 | } 61 | } 62 | } 63 | try!(write!(writer, "")); 64 | Ok(()) 65 | } 66 | 67 | // Convert special characters into XML entities. 68 | // This is needed for checkstyle output. 69 | fn xml_escape_str(string: &str) -> String { 70 | let mut out = String::new(); 71 | for c in string.chars() { 72 | match c { 73 | '<' => out.push_str("<"), 74 | '>' => out.push_str(">"), 75 | '"' => out.push_str("""), 76 | '\'' => out.push_str("'"), 77 | '&' => out.push_str("&"), 78 | _ => out.push(c), 79 | } 80 | } 81 | out 82 | } 83 | -------------------------------------------------------------------------------- /tests/examples/rustfmt/result_rustfmt/checkstyle.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | use rustfmt_diff::{Mismatch, DiffLine}; 11 | use std::io::{self, Write}; 12 | use config::WriteMode; 13 | 14 | 15 | pub fn output_header(out: &mut T, mode: WriteMode) -> Result<(), io::Error> 16 | where T: Write 17 | { 18 | if mode == WriteMode::Checkstyle { 19 | let mut xml_heading = String::new(); 20 | xml_heading.push_str(""); 21 | xml_heading.push_str("\n"); 22 | xml_heading.push_str(""); 23 | try!(write!(out, "{}", xml_heading)); 24 | } 25 | Ok(()) 26 | } 27 | 28 | pub fn output_footer(out: &mut T, mode: WriteMode) -> Result<(), io::Error> 29 | where T: Write 30 | { 31 | if mode == WriteMode::Checkstyle { 32 | let mut xml_tail = String::new(); 33 | xml_tail.push_str(""); 34 | try!(write!(out, "{}", xml_tail)); 35 | } 36 | Ok(()) 37 | } 38 | 39 | pub fn output_checkstyle_file(mut writer: T, 40 | filename: &str, 41 | diff: Vec) 42 | -> Result<(), io::Error> 43 | where T: Write 44 | { 45 | try!(write!(writer, "", filename)); 46 | for mismatch in diff { 47 | for line in mismatch.lines { 48 | match line { 49 | DiffLine::Expected(ref str) => { 50 | let message = xml_escape_str(&str); 51 | try!(write!(writer, 52 | "", 54 | mismatch.line_number, 55 | message)); 56 | } 57 | _ => { 58 | // Do nothing with context and expected. 59 | } 60 | } 61 | } 62 | } 63 | try!(write!(writer, "")); 64 | Ok(()) 65 | } 66 | 67 | // Convert special characters into XML entities. 68 | // This is needed for checkstyle output. 69 | fn xml_escape_str(string: &str) -> String { 70 | let mut out = String::new(); 71 | for c in string.chars() { 72 | match c { 73 | '<' => out.push_str("<"), 74 | '>' => out.push_str(">"), 75 | '"' => out.push_str("""), 76 | '\'' => out.push_str("'"), 77 | '&' => out.push_str("&"), 78 | _ => out.push(c), 79 | } 80 | } 81 | out 82 | } 83 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/HFIndexSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // HFIndexSet.h 3 | // HexFiend_2 4 | // 5 | // Copyright 2010 ridiculous_fish. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | /*! @class HFIndexSet 12 | @brief Hex Fiend's answer to NSIndexSet. It can contain any unsigned long long value. 13 | */ 14 | @interface HFIndexSet : NSObject { 15 | @protected 16 | NSUInteger rangeCount; 17 | NSUInteger rangeCapacity; 18 | HFRange singleRange; 19 | HFRange *multipleRanges; 20 | } 21 | 22 | /*! Initializes the receiver as empty. */ 23 | - (instancetype)init; 24 | 25 | /*! Initializes the receiver with a single index. */ 26 | - (instancetype)initWithValue:(unsigned long long)value; 27 | 28 | /*! Initializes the receiver with the indexes in a single range. */ 29 | - (instancetype)initWithValuesInRange:(HFRange)range; 30 | 31 | /*! Initializes the receiver with the indexes in an NSIndexSet. */ 32 | - (instancetype)initWithIndexSet:(HFIndexSet *)otherSet; 33 | 34 | /*! Returns the number of ranges in the set. */ 35 | - (NSUInteger)numberOfRanges; 36 | 37 | /*! Returns the range at a given index. */ 38 | - (HFRange)rangeAtIndex:(NSUInteger)idx; 39 | 40 | /*! Returns the number of values in a given range. */ 41 | - (unsigned long long)countOfValuesInRange:(HFRange)range; 42 | 43 | /*! Returns the number of values in the set. */ 44 | - (unsigned long long)countOfValues; 45 | 46 | #if ! NDEBUG 47 | - (void)verifyIntegrity; 48 | #endif 49 | 50 | /*! Returns the range containing the given value. If the index is not present in the set, returns {ULLONG_MAX, ULLONG_MAX}. */ 51 | - (HFRange)rangeContainingValue:(unsigned long long)idx; 52 | 53 | /*! Indicates whether the receiver contains exactly the same indexes as the given NSIndexSet. */ 54 | - (BOOL)isEqualToNSIndexSet:(NSIndexSet *)indexSet; 55 | 56 | @end 57 | 58 | /*! @class HFMutableIndexSet 59 | @brief The mutable subclass of HFIndexSet 60 | */ 61 | @interface HFMutableIndexSet : HFIndexSet 62 | 63 | /*! Adds indexes in the given range. */ 64 | - (void)addIndexesInRange:(HFRange)range; 65 | 66 | /*! Removes indexes in the given range. */ 67 | - (void)removeIndexesInRange:(HFRange)range; 68 | 69 | /*! Shifts all values equal to or greater than the given value right (increase) by the given delta. This raises an exception if indexes are shifted past ULLONG_MAX. */ 70 | - (void)shiftValuesRightByAmount:(unsigned long long)delta startingAtValue:(unsigned long long)value; 71 | 72 | /*! Shifts all values equal to or greater than the given value left (decrease) by the given delta. Values within the range {value - delta, delta} are deleted. This raises an exception if indexes are shifted below 0. */ 73 | - (void)shiftValuesLeftByAmount:(unsigned long long)delta startingAtValue:(unsigned long long)value; 74 | 75 | /*! Shifts all values less than the given value left (decrease) by the given delta. This raises an exception of indexes are shifted below 0. */ 76 | - (void)shiftValuesLeftByAmount:(unsigned long long)delta endingAtValue:(unsigned long long)value; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/result_clang-format/HFIndexSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // HFIndexSet.h 3 | // HexFiend_2 4 | // 5 | // Copyright 2010 ridiculous_fish. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | /*! @class HFIndexSet 12 | @brief Hex Fiend's answer to NSIndexSet. It can contain any unsigned long long value. 13 | */ 14 | @interface HFIndexSet : NSObject { 15 | @protected 16 | NSUInteger rangeCount; 17 | NSUInteger rangeCapacity; 18 | HFRange singleRange; 19 | HFRange *multipleRanges; 20 | } 21 | 22 | /*! Initializes the receiver as empty. */ 23 | - (instancetype)init; 24 | 25 | /*! Initializes the receiver with a single index. */ 26 | - (instancetype)initWithValue:(unsigned long long)value; 27 | 28 | /*! Initializes the receiver with the indexes in a single range. */ 29 | - (instancetype)initWithValuesInRange:(HFRange)range; 30 | 31 | /*! Initializes the receiver with the indexes in an NSIndexSet. */ 32 | - (instancetype)initWithIndexSet:(HFIndexSet *)otherSet; 33 | 34 | /*! Returns the number of ranges in the set. */ 35 | - (NSUInteger)numberOfRanges; 36 | 37 | /*! Returns the range at a given index. */ 38 | - (HFRange)rangeAtIndex:(NSUInteger)idx; 39 | 40 | /*! Returns the number of values in a given range. */ 41 | - (unsigned long long)countOfValuesInRange:(HFRange)range; 42 | 43 | /*! Returns the number of values in the set. */ 44 | - (unsigned long long)countOfValues; 45 | 46 | #if !NDEBUG 47 | - (void)verifyIntegrity; 48 | #endif 49 | 50 | /*! Returns the range containing the given value. If the index is not present in the set, returns {ULLONG_MAX, ULLONG_MAX}. */ 51 | - (HFRange)rangeContainingValue:(unsigned long long)idx; 52 | 53 | /*! Indicates whether the receiver contains exactly the same indexes as the given NSIndexSet. */ 54 | - (BOOL)isEqualToNSIndexSet:(NSIndexSet *)indexSet; 55 | 56 | @end 57 | 58 | /*! @class HFMutableIndexSet 59 | @brief The mutable subclass of HFIndexSet 60 | */ 61 | @interface HFMutableIndexSet : HFIndexSet 62 | 63 | /*! Adds indexes in the given range. */ 64 | - (void)addIndexesInRange:(HFRange)range; 65 | 66 | /*! Removes indexes in the given range. */ 67 | - (void)removeIndexesInRange:(HFRange)range; 68 | 69 | /*! Shifts all values equal to or greater than the given value right (increase) by the given delta. This raises an exception if indexes are shifted past ULLONG_MAX. */ 70 | - (void)shiftValuesRightByAmount:(unsigned long long)delta startingAtValue:(unsigned long long)value; 71 | 72 | /*! Shifts all values equal to or greater than the given value left (decrease) by the given delta. Values within the range {value - delta, delta} are deleted. This raises an exception if indexes are shifted below 0. */ 73 | - (void)shiftValuesLeftByAmount:(unsigned long long)delta startingAtValue:(unsigned long long)value; 74 | 75 | /*! Shifts all values less than the given value left (decrease) by the given delta. This raises an exception of indexes are shifted below 0. */ 76 | - (void)shiftValuesLeftByAmount:(unsigned long long)delta endingAtValue:(unsigned long long)value; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /tests/examples/HexFiend/result_uncrustify/HFIndexSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // HFIndexSet.h 3 | // HexFiend_2 4 | // 5 | // Copyright 2010 ridiculous_fish. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | /*! @class HFIndexSet 12 | @brief Hex Fiend's answer to NSIndexSet. It can contain any unsigned long long value. 13 | */ 14 | @interface HFIndexSet : NSObject { 15 | @protected 16 | NSUInteger rangeCount; 17 | NSUInteger rangeCapacity; 18 | HFRange singleRange; 19 | HFRange *multipleRanges; 20 | } 21 | 22 | /*! Initializes the receiver as empty. */ 23 | - (instancetype)init; 24 | 25 | /*! Initializes the receiver with a single index. */ 26 | - (instancetype)initWithValue:(unsigned long long)value; 27 | 28 | /*! Initializes the receiver with the indexes in a single range. */ 29 | - (instancetype)initWithValuesInRange:(HFRange)range; 30 | 31 | /*! Initializes the receiver with the indexes in an NSIndexSet. */ 32 | - (instancetype)initWithIndexSet:(HFIndexSet *)otherSet; 33 | 34 | /*! Returns the number of ranges in the set. */ 35 | - (NSUInteger)numberOfRanges; 36 | 37 | /*! Returns the range at a given index. */ 38 | - (HFRange)rangeAtIndex:(NSUInteger)idx; 39 | 40 | /*! Returns the number of values in a given range. */ 41 | - (unsigned long long)countOfValuesInRange:(HFRange)range; 42 | 43 | /*! Returns the number of values in the set. */ 44 | - (unsigned long long)countOfValues; 45 | 46 | #if ! NDEBUG 47 | - (void)verifyIntegrity; 48 | #endif 49 | 50 | /*! Returns the range containing the given value. If the index is not present in the set, returns {ULLONG_MAX, ULLONG_MAX}. */ 51 | - (HFRange)rangeContainingValue:(unsigned long long)idx; 52 | 53 | /*! Indicates whether the receiver contains exactly the same indexes as the given NSIndexSet. */ 54 | - (BOOL)isEqualToNSIndexSet:(NSIndexSet *)indexSet; 55 | 56 | @end 57 | 58 | /*! @class HFMutableIndexSet 59 | @brief The mutable subclass of HFIndexSet 60 | */ 61 | @interface HFMutableIndexSet : HFIndexSet 62 | 63 | /*! Adds indexes in the given range. */ 64 | - (void)addIndexesInRange:(HFRange)range; 65 | 66 | /*! Removes indexes in the given range. */ 67 | - (void)removeIndexesInRange:(HFRange)range; 68 | 69 | /*! Shifts all values equal to or greater than the given value right (increase) by the given delta. This raises an exception if indexes are shifted past ULLONG_MAX. */ 70 | - (void)shiftValuesRightByAmount:(unsigned long long)delta startingAtValue:(unsigned long long)value; 71 | 72 | /*! Shifts all values equal to or greater than the given value left (decrease) by the given delta. Values within the range {value - delta, delta} are deleted. This raises an exception if indexes are shifted below 0. */ 73 | - (void)shiftValuesLeftByAmount:(unsigned long long)delta startingAtValue:(unsigned long long)value; 74 | 75 | /*! Shifts all values less than the given value left (decrease) by the given delta. This raises an exception of indexes are shifted below 0. */ 76 | - (void)shiftValuesLeftByAmount:(unsigned long long)delta endingAtValue:(unsigned long long)value; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /tests/examples/spark/SparkLR.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // scalastyle:off println 19 | package org.apache.spark.examples 20 | 21 | import java.util.Random 22 | 23 | import scala.math.exp 24 | 25 | import breeze.linalg.{DenseVector, Vector} 26 | 27 | import org.apache.spark.sql.SparkSession 28 | 29 | /** 30 | * Logistic regression based classification. 31 | * Usage: SparkLR [slices] 32 | * 33 | * This is an example implementation for learning how to use Spark. For more conventional use, 34 | * please refer to org.apache.spark.ml.classification.LogisticRegression. 35 | */ 36 | object SparkLR { 37 | val N = 10000 // Number of data points 38 | val D = 10 // Number of dimensions 39 | val R = 0.7 // Scaling factor 40 | val ITERATIONS = 5 41 | val rand = new Random(42) 42 | 43 | case class DataPoint(x: Vector[Double], y: Double) 44 | 45 | def generateData: Array[DataPoint] = { 46 | def generatePoint(i: Int): DataPoint = { 47 | val y = if (i % 2 == 0) -1 else 1 48 | val x = DenseVector.fill(D) {rand.nextGaussian + y * R} 49 | DataPoint(x, y) 50 | } 51 | Array.tabulate(N)(generatePoint) 52 | } 53 | 54 | def showWarning() { 55 | System.err.println( 56 | """WARN: This is a naive implementation of Logistic Regression and is given as an example! 57 | |Please use org.apache.spark.ml.classification.LogisticRegression 58 | |for more conventional use. 59 | """.stripMargin) 60 | } 61 | 62 | def main(args: Array[String]) { 63 | 64 | showWarning() 65 | 66 | val spark = SparkSession 67 | .builder 68 | .appName("SparkLR") 69 | .getOrCreate() 70 | 71 | val numSlices = if (args.length > 0) args(0).toInt else 2 72 | val points = spark.sparkContext.parallelize(generateData, numSlices).cache() 73 | 74 | // Initialize w to a random value 75 | var w = DenseVector.fill(D) {2 * rand.nextDouble - 1} 76 | println("Initial w: " + w) 77 | 78 | for (i <- 1 to ITERATIONS) { 79 | println("On iteration " + i) 80 | val gradient = points.map { p => 81 | p.x * (1 / (1 + exp(-p.y * (w.dot(p.x)))) - 1) * p.y 82 | }.reduce(_ + _) 83 | w -= gradient 84 | } 85 | 86 | println("Final w: " + w) 87 | 88 | spark.stop() 89 | } 90 | } 91 | // scalastyle:on println 92 | -------------------------------------------------------------------------------- /tests/examples/spark/result_scalafmt/SparkLR.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // scalastyle:off println 19 | package org.apache.spark.examples 20 | 21 | import java.util.Random 22 | 23 | import scala.math.exp 24 | 25 | import breeze.linalg.{DenseVector, Vector} 26 | 27 | import org.apache.spark.sql.SparkSession 28 | 29 | /** 30 | * Logistic regression based classification. 31 | * Usage: SparkLR [slices] 32 | * 33 | * This is an example implementation for learning how to use Spark. For more conventional use, 34 | * please refer to org.apache.spark.ml.classification.LogisticRegression. 35 | */ 36 | object SparkLR { 37 | val N = 10000 // Number of data points 38 | val D = 10 // Number of dimensions 39 | val R = 0.7 // Scaling factor 40 | val ITERATIONS = 5 41 | val rand = new Random(42) 42 | 43 | case class DataPoint(x: Vector[Double], y: Double) 44 | 45 | def generateData: Array[DataPoint] = { 46 | def generatePoint(i: Int): DataPoint = { 47 | val y = if (i % 2 == 0) -1 else 1 48 | val x = DenseVector.fill(D) { rand.nextGaussian + y * R } 49 | DataPoint(x, y) 50 | } 51 | Array.tabulate(N)(generatePoint) 52 | } 53 | 54 | def showWarning() { 55 | System.err.println( 56 | """WARN: This is a naive implementation of Logistic Regression and is given as an example! 57 | |Please use org.apache.spark.ml.classification.LogisticRegression 58 | |for more conventional use. 59 | """.stripMargin) 60 | } 61 | 62 | def main(args: Array[String]) { 63 | 64 | showWarning() 65 | 66 | val spark = SparkSession.builder 67 | .appName("SparkLR") 68 | .getOrCreate() 69 | 70 | val numSlices = if (args.length > 0) args(0).toInt else 2 71 | val points = spark.sparkContext.parallelize(generateData, numSlices).cache() 72 | 73 | // Initialize w to a random value 74 | var w = DenseVector.fill(D) { 2 * rand.nextDouble - 1 } 75 | println("Initial w: " + w) 76 | 77 | for (i <- 1 to ITERATIONS) { 78 | println("On iteration " + i) 79 | val gradient = points.map { p => 80 | p.x * (1 / (1 + exp(-p.y * (w.dot(p.x)))) - 1) * p.y 81 | }.reduce(_ + _) 82 | w -= gradient 83 | } 84 | 85 | println("Final w: " + w) 86 | 87 | spark.stop() 88 | } 89 | } 90 | // scalastyle:on println 91 | -------------------------------------------------------------------------------- /tests/examples/spark/result_scalariform/SparkLR.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // scalastyle:off println 19 | package org.apache.spark.examples 20 | 21 | import java.util.Random 22 | 23 | import scala.math.exp 24 | 25 | import breeze.linalg.{DenseVector, Vector} 26 | 27 | import org.apache.spark.sql.SparkSession 28 | 29 | /** 30 | * Logistic regression based classification. 31 | * Usage: SparkLR [slices] 32 | * 33 | * This is an example implementation for learning how to use Spark. For more conventional use, 34 | * please refer to org.apache.spark.ml.classification.LogisticRegression. 35 | */ 36 | object SparkLR { 37 | val N = 10000 // Number of data points 38 | val D = 10 // Number of dimensions 39 | val R = 0.7 // Scaling factor 40 | val ITERATIONS = 5 41 | val rand = new Random(42) 42 | 43 | case class DataPoint(x: Vector[Double], y: Double) 44 | 45 | def generateData: Array[DataPoint] = { 46 | def generatePoint(i: Int): DataPoint = { 47 | val y = if (i % 2 == 0) -1 else 1 48 | val x = DenseVector.fill(D) { rand.nextGaussian + y * R } 49 | DataPoint(x, y) 50 | } 51 | Array.tabulate(N)(generatePoint) 52 | } 53 | 54 | def showWarning() { 55 | System.err.println( 56 | """WARN: This is a naive implementation of Logistic Regression and is given as an example! 57 | |Please use org.apache.spark.ml.classification.LogisticRegression 58 | |for more conventional use. 59 | """.stripMargin 60 | ) 61 | } 62 | 63 | def main(args: Array[String]) { 64 | 65 | showWarning() 66 | 67 | val spark = SparkSession 68 | .builder 69 | .appName("SparkLR") 70 | .getOrCreate() 71 | 72 | val numSlices = if (args.length > 0) args(0).toInt else 2 73 | val points = spark.sparkContext.parallelize(generateData, numSlices).cache() 74 | 75 | // Initialize w to a random value 76 | var w = DenseVector.fill(D) { 2 * rand.nextDouble - 1 } 77 | println("Initial w: " + w) 78 | 79 | for (i <- 1 to ITERATIONS) { 80 | println("On iteration " + i) 81 | val gradient = points.map { p => 82 | p.x * (1 / (1 + exp(-p.y * (w.dot(p.x)))) - 1) * p.y 83 | }.reduce(_ + _) 84 | w -= gradient 85 | } 86 | 87 | println("Final w: " + w) 88 | 89 | spark.stop() 90 | } 91 | } 92 | // scalastyle:on println 93 | -------------------------------------------------------------------------------- /tests/examples/jasmine/Clock.js: -------------------------------------------------------------------------------- 1 | getJasmineRequireObj().Clock = function() { 2 | function Clock(global, delayedFunctionSchedulerFactory, mockDate) { 3 | var self = this, 4 | realTimingFunctions = { 5 | setTimeout: global.setTimeout, 6 | clearTimeout: global.clearTimeout, 7 | setInterval: global.setInterval, 8 | clearInterval: global.clearInterval 9 | }, 10 | fakeTimingFunctions = { 11 | setTimeout: setTimeout, 12 | clearTimeout: clearTimeout, 13 | setInterval: setInterval, 14 | clearInterval: clearInterval 15 | }, 16 | installed = false, 17 | delayedFunctionScheduler, 18 | timer; 19 | 20 | 21 | self.install = function() { 22 | if(!originalTimingFunctionsIntact()) { 23 | throw new Error('Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'); 24 | } 25 | replace(global, fakeTimingFunctions); 26 | timer = fakeTimingFunctions; 27 | delayedFunctionScheduler = delayedFunctionSchedulerFactory(); 28 | installed = true; 29 | 30 | return self; 31 | }; 32 | 33 | self.uninstall = function() { 34 | delayedFunctionScheduler = null; 35 | mockDate.uninstall(); 36 | replace(global, realTimingFunctions); 37 | 38 | timer = realTimingFunctions; 39 | installed = false; 40 | }; 41 | 42 | self.withMock = function(closure) { 43 | this.install(); 44 | try { 45 | closure(); 46 | } finally { 47 | this.uninstall(); 48 | } 49 | }; 50 | 51 | self.mockDate = function(initialDate) { 52 | mockDate.install(initialDate); 53 | }; 54 | 55 | self.setTimeout = function(fn, delay, params) { 56 | if (legacyIE()) { 57 | if (arguments.length > 2) { 58 | throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill'); 59 | } 60 | return timer.setTimeout(fn, delay); 61 | } 62 | return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); 63 | }; 64 | 65 | self.setInterval = function(fn, delay, params) { 66 | if (legacyIE()) { 67 | if (arguments.length > 2) { 68 | throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill'); 69 | } 70 | return timer.setInterval(fn, delay); 71 | } 72 | return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); 73 | }; 74 | 75 | self.clearTimeout = function(id) { 76 | return Function.prototype.call.apply(timer.clearTimeout, [global, id]); 77 | }; 78 | 79 | self.clearInterval = function(id) { 80 | return Function.prototype.call.apply(timer.clearInterval, [global, id]); 81 | }; 82 | 83 | self.tick = function(millis) { 84 | if (installed) { 85 | delayedFunctionScheduler.tick(millis, function(millis) { mockDate.tick(millis); }); 86 | } else { 87 | throw new Error('Mock clock is not installed, use jasmine.clock().install()'); 88 | } 89 | }; 90 | 91 | return self; 92 | 93 | function originalTimingFunctionsIntact() { 94 | return global.setTimeout === realTimingFunctions.setTimeout && 95 | global.clearTimeout === realTimingFunctions.clearTimeout && 96 | global.setInterval === realTimingFunctions.setInterval && 97 | global.clearInterval === realTimingFunctions.clearInterval; 98 | } 99 | 100 | function legacyIE() { 101 | //if these methods are polyfilled, apply will be present 102 | return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; 103 | } 104 | 105 | function replace(dest, source) { 106 | for (var prop in source) { 107 | dest[prop] = source[prop]; 108 | } 109 | } 110 | 111 | function setTimeout(fn, delay) { 112 | return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); 113 | } 114 | 115 | function clearTimeout(id) { 116 | return delayedFunctionScheduler.removeFunctionWithId(id); 117 | } 118 | 119 | function setInterval(fn, interval) { 120 | return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); 121 | } 122 | 123 | function clearInterval(id) { 124 | return delayedFunctionScheduler.removeFunctionWithId(id); 125 | } 126 | 127 | function argSlice(argsObj, n) { 128 | return Array.prototype.slice.call(argsObj, n); 129 | } 130 | } 131 | 132 | return Clock; 133 | }; 134 | -------------------------------------------------------------------------------- /tests/examples/jasmine/result_clang-format/Clock.js: -------------------------------------------------------------------------------- 1 | getJasmineRequireObj().Clock = function() { 2 | function Clock(global, delayedFunctionSchedulerFactory, mockDate) { 3 | var self = this, 4 | realTimingFunctions = { 5 | setTimeout: global.setTimeout, 6 | clearTimeout: global.clearTimeout, 7 | setInterval: global.setInterval, 8 | clearInterval: global.clearInterval 9 | }, 10 | fakeTimingFunctions = { 11 | setTimeout: setTimeout, 12 | clearTimeout: clearTimeout, 13 | setInterval: setInterval, 14 | clearInterval: clearInterval 15 | }, 16 | installed = false, 17 | delayedFunctionScheduler, 18 | timer; 19 | 20 | 21 | self.install = function() { 22 | if (!originalTimingFunctionsIntact()) { 23 | throw new Error('Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'); 24 | } 25 | replace(global, fakeTimingFunctions); 26 | timer = fakeTimingFunctions; 27 | delayedFunctionScheduler = delayedFunctionSchedulerFactory(); 28 | installed = true; 29 | 30 | return self; 31 | }; 32 | 33 | self.uninstall = function() { 34 | delayedFunctionScheduler = null; 35 | mockDate.uninstall(); 36 | replace(global, realTimingFunctions); 37 | 38 | timer = realTimingFunctions; 39 | installed = false; 40 | }; 41 | 42 | self.withMock = function(closure) { 43 | this.install(); 44 | try { 45 | closure(); 46 | } finally { 47 | this.uninstall(); 48 | } 49 | }; 50 | 51 | self.mockDate = function(initialDate) { 52 | mockDate.install(initialDate); 53 | }; 54 | 55 | self.setTimeout = function(fn, delay, params) { 56 | if (legacyIE()) { 57 | if (arguments.length > 2) { 58 | throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill'); 59 | } 60 | return timer.setTimeout(fn, delay); 61 | } 62 | return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); 63 | }; 64 | 65 | self.setInterval = function(fn, delay, params) { 66 | if (legacyIE()) { 67 | if (arguments.length > 2) { 68 | throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill'); 69 | } 70 | return timer.setInterval(fn, delay); 71 | } 72 | return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); 73 | }; 74 | 75 | self.clearTimeout = function(id) { 76 | return Function.prototype.call.apply(timer.clearTimeout, [global, id]); 77 | }; 78 | 79 | self.clearInterval = function(id) { 80 | return Function.prototype.call.apply(timer.clearInterval, [global, id]); 81 | }; 82 | 83 | self.tick = function(millis) { 84 | if (installed) { 85 | delayedFunctionScheduler.tick(millis, function(millis) { mockDate.tick(millis); }); 86 | } else { 87 | throw new Error('Mock clock is not installed, use jasmine.clock().install()'); 88 | } 89 | }; 90 | 91 | return self; 92 | 93 | function originalTimingFunctionsIntact() { 94 | return global.setTimeout === realTimingFunctions.setTimeout && 95 | global.clearTimeout === realTimingFunctions.clearTimeout && 96 | global.setInterval === realTimingFunctions.setInterval && 97 | global.clearInterval === realTimingFunctions.clearInterval; 98 | } 99 | 100 | function legacyIE() { 101 | //if these methods are polyfilled, apply will be present 102 | return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; 103 | } 104 | 105 | function replace(dest, source) { 106 | for (var prop in source) { 107 | dest[prop] = source[prop]; 108 | } 109 | } 110 | 111 | function setTimeout(fn, delay) { 112 | return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); 113 | } 114 | 115 | function clearTimeout(id) { 116 | return delayedFunctionScheduler.removeFunctionWithId(id); 117 | } 118 | 119 | function setInterval(fn, interval) { 120 | return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); 121 | } 122 | 123 | function clearInterval(id) { 124 | return delayedFunctionScheduler.removeFunctionWithId(id); 125 | } 126 | 127 | function argSlice(argsObj, n) { 128 | return Array.prototype.slice.call(argsObj, n); 129 | } 130 | } 131 | 132 | return Clock; 133 | }; 134 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_clang-format/ngx_buf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_BUF_H_INCLUDED_ 9 | #define _NGX_BUF_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef void *ngx_buf_tag_t; 17 | 18 | typedef struct ngx_buf_s ngx_buf_t; 19 | 20 | struct ngx_buf_s { 21 | u_char *pos; 22 | u_char *last; 23 | off_t file_pos; 24 | off_t file_last; 25 | 26 | u_char *start; /* start of buffer */ 27 | u_char *end; /* end of buffer */ 28 | ngx_buf_tag_t tag; 29 | ngx_file_t *file; 30 | ngx_buf_t *shadow; 31 | 32 | 33 | /* the buf's content could be changed */ 34 | unsigned temporary : 1; 35 | 36 | /* 37 | * the buf's content is in a memory cache or in a read only memory 38 | * and must not be changed 39 | */ 40 | unsigned memory : 1; 41 | 42 | /* the buf's content is mmap()ed and must not be changed */ 43 | unsigned mmap : 1; 44 | 45 | unsigned recycled : 1; 46 | unsigned in_file : 1; 47 | unsigned flush : 1; 48 | unsigned sync : 1; 49 | unsigned last_buf : 1; 50 | unsigned last_in_chain : 1; 51 | 52 | unsigned last_shadow : 1; 53 | unsigned temp_file : 1; 54 | 55 | /* STUB */ int num; 56 | }; 57 | 58 | 59 | struct ngx_chain_s { 60 | ngx_buf_t *buf; 61 | ngx_chain_t *next; 62 | }; 63 | 64 | 65 | typedef struct { 66 | ngx_int_t num; 67 | size_t size; 68 | } ngx_bufs_t; 69 | 70 | 71 | typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t; 72 | 73 | typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in); 74 | 75 | #if (NGX_HAVE_FILE_AIO) 76 | typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx, 77 | ngx_file_t *file); 78 | #endif 79 | 80 | struct ngx_output_chain_ctx_s { 81 | ngx_buf_t *buf; 82 | ngx_chain_t *in; 83 | ngx_chain_t *free; 84 | ngx_chain_t *busy; 85 | 86 | unsigned sendfile : 1; 87 | unsigned directio : 1; 88 | #if (NGX_HAVE_ALIGNED_DIRECTIO) 89 | unsigned unaligned : 1; 90 | #endif 91 | unsigned need_in_memory : 1; 92 | unsigned need_in_temp : 1; 93 | #if (NGX_HAVE_FILE_AIO || NGX_THREADS) 94 | unsigned aio : 1; 95 | #endif 96 | 97 | #if (NGX_HAVE_FILE_AIO) 98 | ngx_output_chain_aio_pt aio_handler; 99 | #if (NGX_HAVE_AIO_SENDFILE) 100 | ssize_t (*aio_preload)(ngx_buf_t *file); 101 | #endif 102 | #endif 103 | 104 | #if (NGX_THREADS) 105 | ngx_int_t (*thread_handler)(ngx_thread_task_t *task, 106 | ngx_file_t *file); 107 | ngx_thread_task_t *thread_task; 108 | #endif 109 | 110 | off_t alignment; 111 | 112 | ngx_pool_t *pool; 113 | ngx_int_t allocated; 114 | ngx_bufs_t bufs; 115 | ngx_buf_tag_t tag; 116 | 117 | ngx_output_chain_filter_pt output_filter; 118 | void *filter_ctx; 119 | }; 120 | 121 | 122 | typedef struct { 123 | ngx_chain_t *out; 124 | ngx_chain_t **last; 125 | ngx_connection_t *connection; 126 | ngx_pool_t *pool; 127 | off_t limit; 128 | } ngx_chain_writer_ctx_t; 129 | 130 | 131 | #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR 132 | 133 | 134 | #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) 135 | #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) 136 | 137 | #define ngx_buf_special(b) \ 138 | ((b->flush || b->last_buf || b->sync) \ 139 | && !ngx_buf_in_memory(b) && !b->in_file) 140 | 141 | #define ngx_buf_sync_only(b) \ 142 | (b->sync \ 143 | && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf) 144 | 145 | #define ngx_buf_size(b) \ 146 | (ngx_buf_in_memory(b) ? (off_t)(b->last - b->pos) : \ 147 | (b->file_last - b->file_pos)) 148 | 149 | ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size); 150 | ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); 151 | 152 | 153 | #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) 154 | #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) 155 | 156 | ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool); 157 | #define ngx_free_chain(pool, cl) \ 158 | cl->next = pool->chain; \ 159 | pool->chain = cl 160 | 161 | 162 | ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in); 163 | ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in); 164 | 165 | ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, 166 | ngx_chain_t *in); 167 | ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free); 168 | void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, 169 | ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag); 170 | 171 | off_t ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit); 172 | 173 | ngx_chain_t *ngx_chain_update_sent(ngx_chain_t *in, off_t sent); 174 | 175 | #endif /* _NGX_BUF_H_INCLUDED_ */ 176 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_indent/ngx_buf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_BUF_H_INCLUDED_ 9 | #define _NGX_BUF_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef void *ngx_buf_tag_t; 17 | 18 | typedef struct ngx_buf_s ngx_buf_t; 19 | 20 | struct ngx_buf_s 21 | { 22 | u_char *pos; 23 | u_char *last; 24 | off_t file_pos; 25 | off_t file_last; 26 | 27 | u_char *start; /* start of buffer */ 28 | u_char *end; /* end of buffer */ 29 | ngx_buf_tag_t tag; 30 | ngx_file_t *file; 31 | ngx_buf_t *shadow; 32 | 33 | 34 | /* the buf's content could be changed */ 35 | unsigned temporary:1; 36 | 37 | /* 38 | * the buf's content is in a memory cache or in a read only memory 39 | * and must not be changed 40 | */ 41 | unsigned memory:1; 42 | 43 | /* the buf's content is mmap()ed and must not be changed */ 44 | unsigned mmap:1; 45 | 46 | unsigned recycled:1; 47 | unsigned in_file:1; 48 | unsigned flush:1; 49 | unsigned sync:1; 50 | unsigned last_buf:1; 51 | unsigned last_in_chain:1; 52 | 53 | unsigned last_shadow:1; 54 | unsigned temp_file:1; 55 | 56 | /* STUB */ int num; 57 | }; 58 | 59 | 60 | struct ngx_chain_s 61 | { 62 | ngx_buf_t *buf; 63 | ngx_chain_t *next; 64 | }; 65 | 66 | 67 | typedef struct 68 | { 69 | ngx_int_t num; 70 | size_t size; 71 | } ngx_bufs_t; 72 | 73 | 74 | typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t; 75 | 76 | typedef ngx_int_t (*ngx_output_chain_filter_pt) (void *ctx, ngx_chain_t * in); 77 | 78 | #if (NGX_HAVE_FILE_AIO) 79 | typedef void (*ngx_output_chain_aio_pt) (ngx_output_chain_ctx_t * ctx, 80 | ngx_file_t * file); 81 | #endif 82 | 83 | struct ngx_output_chain_ctx_s 84 | { 85 | ngx_buf_t *buf; 86 | ngx_chain_t *in; 87 | ngx_chain_t *free; 88 | ngx_chain_t *busy; 89 | 90 | unsigned sendfile:1; 91 | unsigned directio:1; 92 | #if (NGX_HAVE_ALIGNED_DIRECTIO) 93 | unsigned unaligned:1; 94 | #endif 95 | unsigned need_in_memory:1; 96 | unsigned need_in_temp:1; 97 | #if (NGX_HAVE_FILE_AIO || NGX_THREADS) 98 | unsigned aio:1; 99 | #endif 100 | 101 | #if (NGX_HAVE_FILE_AIO) 102 | ngx_output_chain_aio_pt aio_handler; 103 | #if (NGX_HAVE_AIO_SENDFILE) 104 | ssize_t (*aio_preload) (ngx_buf_t * file); 105 | #endif 106 | #endif 107 | 108 | #if (NGX_THREADS) 109 | ngx_int_t (*thread_handler) (ngx_thread_task_t * task, ngx_file_t * file); 110 | ngx_thread_task_t *thread_task; 111 | #endif 112 | 113 | off_t alignment; 114 | 115 | ngx_pool_t *pool; 116 | ngx_int_t allocated; 117 | ngx_bufs_t bufs; 118 | ngx_buf_tag_t tag; 119 | 120 | ngx_output_chain_filter_pt output_filter; 121 | void *filter_ctx; 122 | }; 123 | 124 | 125 | typedef struct 126 | { 127 | ngx_chain_t *out; 128 | ngx_chain_t **last; 129 | ngx_connection_t *connection; 130 | ngx_pool_t *pool; 131 | off_t limit; 132 | } ngx_chain_writer_ctx_t; 133 | 134 | 135 | #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR 136 | 137 | 138 | #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) 139 | #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) 140 | 141 | #define ngx_buf_special(b) \ 142 | ((b->flush || b->last_buf || b->sync) \ 143 | && !ngx_buf_in_memory(b) && !b->in_file) 144 | 145 | #define ngx_buf_sync_only(b) \ 146 | (b->sync \ 147 | && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf) 148 | 149 | #define ngx_buf_size(b) \ 150 | (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \ 151 | (b->file_last - b->file_pos)) 152 | 153 | ngx_buf_t *ngx_create_temp_buf (ngx_pool_t * pool, size_t size); 154 | ngx_chain_t *ngx_create_chain_of_bufs (ngx_pool_t * pool, ngx_bufs_t * bufs); 155 | 156 | 157 | #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) 158 | #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) 159 | 160 | ngx_chain_t *ngx_alloc_chain_link (ngx_pool_t * pool); 161 | #define ngx_free_chain(pool, cl) \ 162 | cl->next = pool->chain; \ 163 | pool->chain = cl 164 | 165 | 166 | 167 | ngx_int_t ngx_output_chain (ngx_output_chain_ctx_t * ctx, ngx_chain_t * in); 168 | ngx_int_t ngx_chain_writer (void *ctx, ngx_chain_t * in); 169 | 170 | ngx_int_t ngx_chain_add_copy (ngx_pool_t * pool, ngx_chain_t ** chain, 171 | ngx_chain_t * in); 172 | ngx_chain_t *ngx_chain_get_free_buf (ngx_pool_t * p, ngx_chain_t ** free); 173 | void ngx_chain_update_chains (ngx_pool_t * p, ngx_chain_t ** free, 174 | ngx_chain_t ** busy, ngx_chain_t ** out, 175 | ngx_buf_tag_t tag); 176 | 177 | off_t ngx_chain_coalesce_file (ngx_chain_t ** in, off_t limit); 178 | 179 | ngx_chain_t *ngx_chain_update_sent (ngx_chain_t * in, off_t sent); 180 | 181 | #endif /* _NGX_BUF_H_INCLUDED_ */ 182 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | whatstyle 2 | ============= 3 | 4 | whatstyle finds a code format style that fits given source files. 5 | 6 | Code formatters like clang-format or uncrustify usually need a specific style 7 | definition how to reformat the code. 8 | This program looks at your source code and generates a style definition 9 | that the reformatted source fits its original formatting as closely 10 | as possible. 11 | 12 | It should help programmers to begin using a formatting tool right away 13 | without the need to invest hours of reading the formatting tool 14 | documentation. 15 | 16 | The currently supported formatters are `clang-format`_, YAPF_, Tidy_, indent_, 17 | `Artistic Style`_, Uncrustify_, scalariform_, scalafmt_, rfmt_ and rustfmt_. 18 | 19 | .. _`clang-format`: http://clang.llvm.org/docs/ClangFormat.html 20 | .. _YAPF: https://github.com/google/yapf 21 | .. _Tidy: http://www.html-tidy.org 22 | .. _indent: http://www.freebsd.org/cgi/man.cgi?query=indent 23 | .. _Artistic Style: http://astyle.sourceforge.net 24 | .. _Uncrustify: https://github.com/uncrustify/uncrustify 25 | .. _scalariform: https://github.com/scala-ide/scalariform 26 | .. _scalafmt: https://github.com/olafurpg/scalafmt 27 | .. _rfmt: https://github.com/google/rfmt 28 | .. _rustfmt: https://github.com/rust-lang-nursery/rustfmt 29 | 30 | .. contents:: 31 | 32 | How to run 33 | ------------------ 34 | 35 | First you choose one or more of your source files whose style you find 36 | representative of the style you want to keep. 37 | The source files should cover a wide range of language constructs and 38 | to keep runtime down not exceed a few thousand lines if possible. 39 | 40 | You specify the formatter and source files as follows: 41 | 42 | .. code-block:: bash 43 | 44 | $ whatstyle.py -f clang-format tests/examples/gumbo-parser/utf8.c 45 | 46 | whatstyle will then try different options while reporting intermediate results. 47 | After a while you get back a result like this: 48 | 49 | .. code-block:: bash 50 | 51 | ### This style was chosen for your .clang-format - it perfectly matches your sources. 52 | BasedOnStyle: Google 53 | AlignAfterOpenBracket: DontAlign 54 | SpaceAfterCStyleCast: true 55 | 56 | Adding the option ``--mode resilient`` will usually add more options to your style so 57 | that a heavily out of shape version of your sources can be better retransformed into your 58 | style. 59 | 60 | Style difference effects vs options documentation 61 | ------------------------------------------------- 62 | 63 | Reading the documention of the invidual options of a formatter takes time and does not 64 | necessarily make clear how an option influences the formatting. 65 | You can try something like this instead: 66 | 67 | .. code-block:: bash 68 | 69 | $ whatstyle.py --variants tests/examples/xv6/printf.c 70 | 71 | First the best matching style is chosen and then every option is replaced or augmented by 72 | every possible value. All combinations that actually made a difference are grouped and 73 | displayed side by side. 74 | The variant on the left is the original from the best style, on the right is another 75 | option setting that usually makes things worse. 76 | Below the option values, differing code fragments are shown, you can use ``--numhunks`` 77 | to show more diff hunks per variation. 78 | Use ``--ansi`` to display the variants table in an ANSI terminal, ``--html`` to open it 79 | in a browser or ``--ansihtml`` for a darker look in a browser. 80 | 81 | .. image:: https://raw.github.com/wiki/mikr/whatstyle/images/variants.png 82 | :target: https://raw.github.com/wiki/mikr/whatstyle/images/variants.png 83 | :alt: Format Style Variants 84 | 85 | Usage scenarios 86 | --------------- 87 | 88 | For information about some useful scenarios run: 89 | 90 | .. code-block:: bash 91 | 92 | $ whatstyle.py --usage-examples 93 | 94 | or read the text at the beginning of whatstyle.py. 95 | 96 | Requirements 97 | ------------------ 98 | 99 | whatstyle needs at least Python 2.7 and it works as well with 100 | Python 3.2, 3.3, 3.4 and 3.5. Jython and pypy are supported. 101 | 102 | Also whatstyle needs at least one code formatter in the current ``PATH``. 103 | 104 | The presence of either ``diff`` or ``git`` is optional but useful because the diff quality of 105 | both of them may be better than Python's difflib and this results in a different and usually 106 | better matching style. 107 | 108 | This program should work on OS X, Windows, Linux, FreeBSD and OpenBSD. 109 | 110 | How it works 111 | ------------------ 112 | 113 | The program basically works by reformatting the source with many 114 | combinations of options and running a diff between the original 115 | and the reformatted source code. 116 | 117 | First the major standard styles (e.g. WebKit, GNU, LLVM) are evaluated 118 | and the closest one chosen as a baseline. 119 | 120 | Successively every choice of every style option is added to test 121 | if the additional option further reduces the differences. 122 | When no more option settings can improve the result the most appropriate 123 | style has been found. 124 | 125 | Among a number of candidate styles with the same diff quality 126 | the one with the least number of explicit options is chosen 127 | to keep the style definition brief. 128 | 129 | Author 130 | ------ 131 | 132 | whatstyle was written by `Michael Krause `_. 133 | 134 | License 135 | ------- 136 | 137 | whatstyle is available under the `MIT license `_. See the LICENSE file for more info. 138 | 139 | The project specific Open Source licenses of the source codes in tests/examples are present in their respective directories. 140 | 141 | See also 142 | -------- 143 | 144 | `Unformat: Python3 utility to generate a .clang-format file from example code-base `_. 145 | -------------------------------------------------------------------------------- /tests/examples/nginx/ngx_buf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_BUF_H_INCLUDED_ 9 | #define _NGX_BUF_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef void * ngx_buf_tag_t; 17 | 18 | typedef struct ngx_buf_s ngx_buf_t; 19 | 20 | struct ngx_buf_s { 21 | u_char *pos; 22 | u_char *last; 23 | off_t file_pos; 24 | off_t file_last; 25 | 26 | u_char *start; /* start of buffer */ 27 | u_char *end; /* end of buffer */ 28 | ngx_buf_tag_t tag; 29 | ngx_file_t *file; 30 | ngx_buf_t *shadow; 31 | 32 | 33 | /* the buf's content could be changed */ 34 | unsigned temporary:1; 35 | 36 | /* 37 | * the buf's content is in a memory cache or in a read only memory 38 | * and must not be changed 39 | */ 40 | unsigned memory:1; 41 | 42 | /* the buf's content is mmap()ed and must not be changed */ 43 | unsigned mmap:1; 44 | 45 | unsigned recycled:1; 46 | unsigned in_file:1; 47 | unsigned flush:1; 48 | unsigned sync:1; 49 | unsigned last_buf:1; 50 | unsigned last_in_chain:1; 51 | 52 | unsigned last_shadow:1; 53 | unsigned temp_file:1; 54 | 55 | /* STUB */ int num; 56 | }; 57 | 58 | 59 | struct ngx_chain_s { 60 | ngx_buf_t *buf; 61 | ngx_chain_t *next; 62 | }; 63 | 64 | 65 | typedef struct { 66 | ngx_int_t num; 67 | size_t size; 68 | } ngx_bufs_t; 69 | 70 | 71 | typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t; 72 | 73 | typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in); 74 | 75 | #if (NGX_HAVE_FILE_AIO) 76 | typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx, 77 | ngx_file_t *file); 78 | #endif 79 | 80 | struct ngx_output_chain_ctx_s { 81 | ngx_buf_t *buf; 82 | ngx_chain_t *in; 83 | ngx_chain_t *free; 84 | ngx_chain_t *busy; 85 | 86 | unsigned sendfile:1; 87 | unsigned directio:1; 88 | #if (NGX_HAVE_ALIGNED_DIRECTIO) 89 | unsigned unaligned:1; 90 | #endif 91 | unsigned need_in_memory:1; 92 | unsigned need_in_temp:1; 93 | #if (NGX_HAVE_FILE_AIO || NGX_THREADS) 94 | unsigned aio:1; 95 | #endif 96 | 97 | #if (NGX_HAVE_FILE_AIO) 98 | ngx_output_chain_aio_pt aio_handler; 99 | #if (NGX_HAVE_AIO_SENDFILE) 100 | ssize_t (*aio_preload)(ngx_buf_t *file); 101 | #endif 102 | #endif 103 | 104 | #if (NGX_THREADS) 105 | ngx_int_t (*thread_handler)(ngx_thread_task_t *task, 106 | ngx_file_t *file); 107 | ngx_thread_task_t *thread_task; 108 | #endif 109 | 110 | off_t alignment; 111 | 112 | ngx_pool_t *pool; 113 | ngx_int_t allocated; 114 | ngx_bufs_t bufs; 115 | ngx_buf_tag_t tag; 116 | 117 | ngx_output_chain_filter_pt output_filter; 118 | void *filter_ctx; 119 | }; 120 | 121 | 122 | typedef struct { 123 | ngx_chain_t *out; 124 | ngx_chain_t **last; 125 | ngx_connection_t *connection; 126 | ngx_pool_t *pool; 127 | off_t limit; 128 | } ngx_chain_writer_ctx_t; 129 | 130 | 131 | #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR 132 | 133 | 134 | #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) 135 | #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) 136 | 137 | #define ngx_buf_special(b) \ 138 | ((b->flush || b->last_buf || b->sync) \ 139 | && !ngx_buf_in_memory(b) && !b->in_file) 140 | 141 | #define ngx_buf_sync_only(b) \ 142 | (b->sync \ 143 | && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf) 144 | 145 | #define ngx_buf_size(b) \ 146 | (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \ 147 | (b->file_last - b->file_pos)) 148 | 149 | ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size); 150 | ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); 151 | 152 | 153 | #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) 154 | #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) 155 | 156 | ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool); 157 | #define ngx_free_chain(pool, cl) \ 158 | cl->next = pool->chain; \ 159 | pool->chain = cl 160 | 161 | 162 | 163 | ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in); 164 | ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in); 165 | 166 | ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, 167 | ngx_chain_t *in); 168 | ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free); 169 | void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, 170 | ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag); 171 | 172 | off_t ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit); 173 | 174 | ngx_chain_t *ngx_chain_update_sent(ngx_chain_t *in, off_t sent); 175 | 176 | #endif /* _NGX_BUF_H_INCLUDED_ */ 177 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_uncrustify/ngx_buf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_BUF_H_INCLUDED_ 9 | #define _NGX_BUF_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef void * ngx_buf_tag_t; 17 | 18 | typedef struct ngx_buf_s ngx_buf_t; 19 | 20 | struct ngx_buf_s { 21 | u_char *pos; 22 | u_char *last; 23 | off_t file_pos; 24 | off_t file_last; 25 | 26 | u_char *start; /* start of buffer */ 27 | u_char *end; /* end of buffer */ 28 | ngx_buf_tag_t tag; 29 | ngx_file_t *file; 30 | ngx_buf_t *shadow; 31 | 32 | 33 | /* the buf's content could be changed */ 34 | unsigned temporary : 1; 35 | 36 | /* 37 | * the buf's content is in a memory cache or in a read only memory 38 | * and must not be changed 39 | */ 40 | unsigned memory : 1; 41 | 42 | /* the buf's content is mmap()ed and must not be changed */ 43 | unsigned mmap : 1; 44 | 45 | unsigned recycled : 1; 46 | unsigned in_file : 1; 47 | unsigned flush : 1; 48 | unsigned sync : 1; 49 | unsigned last_buf : 1; 50 | unsigned last_in_chain : 1; 51 | 52 | unsigned last_shadow : 1; 53 | unsigned temp_file : 1; 54 | 55 | /* STUB */ int num; 56 | }; 57 | 58 | 59 | struct ngx_chain_s { 60 | ngx_buf_t *buf; 61 | ngx_chain_t *next; 62 | }; 63 | 64 | 65 | typedef struct { 66 | ngx_int_t num; 67 | size_t size; 68 | } ngx_bufs_t; 69 | 70 | 71 | typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t; 72 | 73 | typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in); 74 | 75 | #if (NGX_HAVE_FILE_AIO) 76 | typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx, 77 | ngx_file_t *file); 78 | #endif 79 | 80 | struct ngx_output_chain_ctx_s { 81 | ngx_buf_t *buf; 82 | ngx_chain_t *in; 83 | ngx_chain_t *free; 84 | ngx_chain_t *busy; 85 | 86 | unsigned sendfile : 1; 87 | unsigned directio : 1; 88 | #if (NGX_HAVE_ALIGNED_DIRECTIO) 89 | unsigned unaligned : 1; 90 | #endif 91 | unsigned need_in_memory : 1; 92 | unsigned need_in_temp : 1; 93 | #if (NGX_HAVE_FILE_AIO || NGX_THREADS) 94 | unsigned aio : 1; 95 | #endif 96 | 97 | #if (NGX_HAVE_FILE_AIO) 98 | ngx_output_chain_aio_pt aio_handler; 99 | #if (NGX_HAVE_AIO_SENDFILE) 100 | ssize_t (*aio_preload)(ngx_buf_t *file); 101 | #endif 102 | #endif 103 | 104 | #if (NGX_THREADS) 105 | ngx_int_t (*thread_handler)(ngx_thread_task_t *task, 106 | ngx_file_t *file); 107 | ngx_thread_task_t *thread_task; 108 | #endif 109 | 110 | off_t alignment; 111 | 112 | ngx_pool_t *pool; 113 | ngx_int_t allocated; 114 | ngx_bufs_t bufs; 115 | ngx_buf_tag_t tag; 116 | 117 | ngx_output_chain_filter_pt output_filter; 118 | void *filter_ctx; 119 | }; 120 | 121 | 122 | typedef struct { 123 | ngx_chain_t *out; 124 | ngx_chain_t **last; 125 | ngx_connection_t *connection; 126 | ngx_pool_t *pool; 127 | off_t limit; 128 | } ngx_chain_writer_ctx_t; 129 | 130 | 131 | #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR 132 | 133 | 134 | #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) 135 | #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) 136 | 137 | #define ngx_buf_special(b) \ 138 | ((b->flush || b->last_buf || b->sync) \ 139 | && !ngx_buf_in_memory(b) && !b->in_file) 140 | 141 | #define ngx_buf_sync_only(b) \ 142 | (b->sync \ 143 | && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf) 144 | 145 | #define ngx_buf_size(b) \ 146 | (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \ 147 | (b->file_last - b->file_pos)) 148 | 149 | ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size); 150 | ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); 151 | 152 | 153 | #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) 154 | #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) 155 | 156 | ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool); 157 | #define ngx_free_chain(pool, cl) \ 158 | cl->next = pool->chain; \ 159 | pool->chain = cl 160 | 161 | 162 | 163 | ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in); 164 | ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in); 165 | 166 | ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, 167 | ngx_chain_t *in); 168 | ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free); 169 | void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, 170 | ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag); 171 | 172 | off_t ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit); 173 | 174 | ngx_chain_t *ngx_chain_update_sent(ngx_chain_t *in, off_t sent); 175 | 176 | #endif /* _NGX_BUF_H_INCLUDED_ */ 177 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_astyle/ngx_buf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_BUF_H_INCLUDED_ 9 | #define _NGX_BUF_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef void * ngx_buf_tag_t; 17 | 18 | typedef struct ngx_buf_s ngx_buf_t; 19 | 20 | struct ngx_buf_s { 21 | u_char *pos; 22 | u_char *last; 23 | off_t file_pos; 24 | off_t file_last; 25 | 26 | u_char *start; /* start of buffer */ 27 | u_char *end; /* end of buffer */ 28 | ngx_buf_tag_t tag; 29 | ngx_file_t *file; 30 | ngx_buf_t *shadow; 31 | 32 | 33 | /* the buf's content could be changed */ 34 | unsigned temporary:1; 35 | 36 | /* 37 | * the buf's content is in a memory cache or in a read only memory 38 | * and must not be changed 39 | */ 40 | unsigned memory:1; 41 | 42 | /* the buf's content is mmap()ed and must not be changed */ 43 | unsigned mmap:1; 44 | 45 | unsigned recycled:1; 46 | unsigned in_file:1; 47 | unsigned flush:1; 48 | unsigned sync:1; 49 | unsigned last_buf:1; 50 | unsigned last_in_chain:1; 51 | 52 | unsigned last_shadow:1; 53 | unsigned temp_file:1; 54 | 55 | /* STUB */ int num; 56 | }; 57 | 58 | 59 | struct ngx_chain_s { 60 | ngx_buf_t *buf; 61 | ngx_chain_t *next; 62 | }; 63 | 64 | 65 | typedef struct { 66 | ngx_int_t num; 67 | size_t size; 68 | } ngx_bufs_t; 69 | 70 | 71 | typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t; 72 | 73 | typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in); 74 | 75 | #if (NGX_HAVE_FILE_AIO) 76 | typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx, 77 | ngx_file_t *file); 78 | #endif 79 | 80 | struct ngx_output_chain_ctx_s { 81 | ngx_buf_t *buf; 82 | ngx_chain_t *in; 83 | ngx_chain_t *free; 84 | ngx_chain_t *busy; 85 | 86 | unsigned sendfile:1; 87 | unsigned directio:1; 88 | #if (NGX_HAVE_ALIGNED_DIRECTIO) 89 | unsigned unaligned:1; 90 | #endif 91 | unsigned need_in_memory:1; 92 | unsigned need_in_temp:1; 93 | #if (NGX_HAVE_FILE_AIO || NGX_THREADS) 94 | unsigned aio:1; 95 | #endif 96 | 97 | #if (NGX_HAVE_FILE_AIO) 98 | ngx_output_chain_aio_pt aio_handler; 99 | #if (NGX_HAVE_AIO_SENDFILE) 100 | ssize_t (*aio_preload)(ngx_buf_t *file); 101 | #endif 102 | #endif 103 | 104 | #if (NGX_THREADS) 105 | ngx_int_t (*thread_handler)(ngx_thread_task_t *task, 106 | ngx_file_t *file); 107 | ngx_thread_task_t *thread_task; 108 | #endif 109 | 110 | off_t alignment; 111 | 112 | ngx_pool_t *pool; 113 | ngx_int_t allocated; 114 | ngx_bufs_t bufs; 115 | ngx_buf_tag_t tag; 116 | 117 | ngx_output_chain_filter_pt output_filter; 118 | void *filter_ctx; 119 | }; 120 | 121 | 122 | typedef struct { 123 | ngx_chain_t *out; 124 | ngx_chain_t **last; 125 | ngx_connection_t *connection; 126 | ngx_pool_t *pool; 127 | off_t limit; 128 | } ngx_chain_writer_ctx_t; 129 | 130 | 131 | #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR 132 | 133 | 134 | #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) 135 | #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) 136 | 137 | #define ngx_buf_special(b) \ 138 | ((b->flush || b->last_buf || b->sync) \ 139 | && !ngx_buf_in_memory(b) && !b->in_file) 140 | 141 | #define ngx_buf_sync_only(b) \ 142 | (b->sync \ 143 | && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf) 144 | 145 | #define ngx_buf_size(b) \ 146 | (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \ 147 | (b->file_last - b->file_pos)) 148 | 149 | ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size); 150 | ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); 151 | 152 | 153 | #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) 154 | #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) 155 | 156 | ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool); 157 | #define ngx_free_chain(pool, cl) \ 158 | cl->next = pool->chain; \ 159 | pool->chain = cl 160 | 161 | 162 | 163 | ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in); 164 | ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in); 165 | 166 | ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, 167 | ngx_chain_t *in); 168 | ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free); 169 | void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, 170 | ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag); 171 | 172 | off_t ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit); 173 | 174 | ngx_chain_t *ngx_chain_update_sent(ngx_chain_t *in, off_t sent); 175 | 176 | #endif /* _NGX_BUF_H_INCLUDED_ */ 177 | -------------------------------------------------------------------------------- /tools/indent_options.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # The code formatter 'indent' exists in several variants with similar 5 | # options. 6 | # The script finds valid command line options given the ASCII manpages 7 | # which must reside in a subdirectory called 'indenters'. 8 | # To get the manpages in ASCII we use: man indent | col -bx 9 | # --------------------------------------------------------------------- 10 | 11 | from __future__ import print_function 12 | 13 | import os 14 | import re 15 | import sys 16 | from os.path import abspath, dirname, join 17 | from pprint import pprint 18 | 19 | PY2 = sys.version_info[0] == 2 20 | PY3 = sys.version_info[0] == 3 21 | 22 | 23 | def get_option_pairs(filename): 24 | """Returns a list of option pairs in the file. 25 | Each option pair falls into three categories: 26 | 1) (-opt, None) : This is a simple option 27 | 2) (-opt, -negative-opt): An option and its opposite option. 28 | 3) (-opt, --longopt): An option with its longopt equivalent (only used by GNU indent). 29 | """ 30 | re_dash = re.compile(r'^(\s+)(-[a-z0-9]+)(?:, (-[\w-]+))?') 31 | pairs = [] 32 | with open(filename) as fp: 33 | for line in fp.readlines(): 34 | line = line.rstrip() 35 | m = re_dash.match(line) 36 | if not m: 37 | continue 38 | spc, opt1, opt2 = m.groups() 39 | if len(spc) >= 10: 40 | # option is part of the description block 41 | continue 42 | if opt1 == '-v': 43 | # -v sort of is the last option for all indent variants. 44 | break 45 | pairs.append((opt1, opt2)) 46 | return pairs 47 | 48 | 49 | def classify_options(optset): 50 | handled = set() 51 | pairs = [] 52 | for pair in ['br bl', 'brs bls', 'brf blf', 'bbb nbbb', 'bfde nbfde', 'lps nlps']: 53 | a, b = pair.split() 54 | pairs.append((a, b)) 55 | handled.add(a) 56 | handled.add(b) 57 | # Ignore these 58 | handled.update(set('pmt troff ta v nv'.split())) 59 | # Ignore the predefined styles 60 | handled.update(set('orig linux kr gnu'.split())) 61 | 62 | optnames = set([opt[1:] for opt in optset]) 63 | options = [] 64 | for optname in optnames: 65 | if optname in handled: 66 | continue 67 | numeric = optname.endswith('n') 68 | isopposite = optname.startswith('n') 69 | theopposite = optname[1:] if isopposite else 'n' + optname 70 | has_opposite = theopposite in optnames 71 | if has_opposite: 72 | if not isopposite: 73 | pairs.append((optname, theopposite)) 74 | handled.add(optname) 75 | handled.add(theopposite) 76 | elif numeric: 77 | optname = optname[:-1] 78 | options.append((optname, 'int', tuple())) 79 | handled.add(optname) 80 | else: 81 | options.append((optname, 'enum', (optname, ))) 82 | handled.add(optname) 83 | for a, b in pairs: 84 | options.append((a, 'enum', (a, b))) 85 | 86 | return options 87 | 88 | 89 | def parse_options(): 90 | srcdir = join(dirname(abspath(__file__)), 'indenters') 91 | manpages = reversed(os.listdir(srcdir)) 92 | opts = set() 93 | for filename in manpages: 94 | pairs = get_option_pairs(join(srcdir, filename)) 95 | for opt1, opt2 in pairs: 96 | opts.add(opt1) 97 | if opt2 is not None and not opt2.startswith('--'): 98 | opts.add(opt2) 99 | copts = classify_options(opts) 100 | pprint(sorted(copts)) 101 | 102 | # This is the result for the man pages of indent for OS X, OpenBSD, FreeBSD and GNU indent: 103 | # [('bacc', 'enum', ('bacc', 'nbacc')), 104 | # ('bad', 'enum', ('bad', 'nbad')), 105 | # ('bap', 'enum', ('bap', 'nbap')), 106 | # ('bbb', 'enum', ('bbb', 'nbbb')), 107 | # ('bbo', 'enum', ('bbo', 'nbbo')), 108 | # ('bc', 'enum', ('bc', 'nbc')), 109 | # ('bfda', 'enum', ('bfda', 'nbfda')), 110 | # ('bfde', 'enum', ('bfde', 'nbfde')), 111 | # ('bli', 'int', ()), 112 | # ('br', 'enum', ('br', 'bl')), 113 | # ('brf', 'enum', ('brf', 'blf')), 114 | # ('brs', 'enum', ('brs', 'bls')), 115 | # ('bs', 'enum', ('bs',)), 116 | # ('c', 'int', ()), 117 | # ('cbi', 'int', ()), 118 | # ('cd', 'int', ()), 119 | # ('cdb', 'enum', ('cdb', 'ncdb')), 120 | # ('cdw', 'enum', ('cdw', 'ncdw')), 121 | # ('ce', 'enum', ('ce', 'nce')), 122 | # ('ci', 'int', ()), 123 | # ('cli', 'int', ()), 124 | # ('cp', 'int', ()), 125 | # ('cs', 'enum', ('cs', 'ncs')), 126 | # ('d', 'int', ()), 127 | # ('di', 'int', ()), 128 | # ('dj', 'enum', ('dj', 'ndj')), 129 | # ('djn', 'enum', ('djn', 'ndjn')), 130 | # ('eei', 'enum', ('eei', 'neei')), 131 | # ('ei', 'enum', ('ei', 'nei')), 132 | # ('fbs', 'enum', ('fbs', 'nfbs')), 133 | # ('fc1', 'enum', ('fc1', 'nfc1')), 134 | # ('fca', 'enum', ('fca', 'nfca')), 135 | # ('fcb', 'enum', ('fcb', 'nfcb')), 136 | # ('hnl', 'enum', ('hnl', 'nhnl')), 137 | # ('i', 'int', ()), 138 | # ('il', 'int', ()), 139 | # ('ip', 'int', ()), 140 | # ('l', 'int', ()), 141 | # ('lc', 'int', ()), 142 | # ('ldi', 'int', ()), 143 | # ('lp', 'enum', ('lp', 'nlp')), 144 | # ('lps', 'enum', ('lps', 'nlps')), 145 | # ('npro', 'enum', ('npro',)), 146 | # ('pcs', 'enum', ('pcs', 'npcs')), 147 | # ('pi', 'int', ()), 148 | # ('ppi', 'int', ()), 149 | # ('prs', 'enum', ('prs', 'nprs')), 150 | # ('psl', 'enum', ('psl', 'npsl')), 151 | # ('saf', 'enum', ('saf', 'nsaf')), 152 | # ('sai', 'enum', ('sai', 'nsai')), 153 | # ('saw', 'enum', ('saw', 'nsaw')), 154 | # ('sbi', 'int', ()), 155 | # ('sc', 'enum', ('sc', 'nsc')), 156 | # ('sob', 'enum', ('sob', 'nsob')), 157 | # ('ss', 'enum', ('ss', 'nss')), 158 | # ('st', 'enum', ('st',)), 159 | # ('ts', 'int', ()), 160 | # ('ut', 'enum', ('ut', 'nut'))] 161 | 162 | 163 | def main(): 164 | parse_options() 165 | 166 | 167 | if __name__ == '__main__': 168 | sys.exit(main()) 169 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_indent/ngx_buf.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_buf_t * 13 | ngx_create_temp_buf (ngx_pool_t * pool, size_t size) 14 | { 15 | ngx_buf_t *b; 16 | 17 | b = ngx_calloc_buf (pool); 18 | if (b == NULL) 19 | { 20 | return NULL; 21 | } 22 | 23 | b->start = ngx_palloc (pool, size); 24 | if (b->start == NULL) 25 | { 26 | return NULL; 27 | } 28 | 29 | /* 30 | * set by ngx_calloc_buf(): 31 | * 32 | * b->file_pos = 0; 33 | * b->file_last = 0; 34 | * b->file = NULL; 35 | * b->shadow = NULL; 36 | * b->tag = 0; 37 | * and flags 38 | */ 39 | 40 | b->pos = b->start; 41 | b->last = b->start; 42 | b->end = b->last + size; 43 | b->temporary = 1; 44 | 45 | return b; 46 | } 47 | 48 | 49 | ngx_chain_t * 50 | ngx_alloc_chain_link (ngx_pool_t * pool) 51 | { 52 | ngx_chain_t *cl; 53 | 54 | cl = pool->chain; 55 | 56 | if (cl) 57 | { 58 | pool->chain = cl->next; 59 | return cl; 60 | } 61 | 62 | cl = ngx_palloc (pool, sizeof (ngx_chain_t)); 63 | if (cl == NULL) 64 | { 65 | return NULL; 66 | } 67 | 68 | return cl; 69 | } 70 | 71 | 72 | ngx_chain_t * 73 | ngx_create_chain_of_bufs (ngx_pool_t * pool, ngx_bufs_t * bufs) 74 | { 75 | u_char *p; 76 | ngx_int_t i; 77 | ngx_buf_t *b; 78 | ngx_chain_t *chain, *cl, **ll; 79 | 80 | p = ngx_palloc (pool, bufs->num * bufs->size); 81 | if (p == NULL) 82 | { 83 | return NULL; 84 | } 85 | 86 | ll = &chain; 87 | 88 | for (i = 0; i < bufs->num; i++) 89 | { 90 | 91 | b = ngx_calloc_buf (pool); 92 | if (b == NULL) 93 | { 94 | return NULL; 95 | } 96 | 97 | /* 98 | * set by ngx_calloc_buf(): 99 | * 100 | * b->file_pos = 0; 101 | * b->file_last = 0; 102 | * b->file = NULL; 103 | * b->shadow = NULL; 104 | * b->tag = 0; 105 | * and flags 106 | * 107 | */ 108 | 109 | b->pos = p; 110 | b->last = p; 111 | b->temporary = 1; 112 | 113 | b->start = p; 114 | p += bufs->size; 115 | b->end = p; 116 | 117 | cl = ngx_alloc_chain_link (pool); 118 | if (cl == NULL) 119 | { 120 | return NULL; 121 | } 122 | 123 | cl->buf = b; 124 | *ll = cl; 125 | ll = &cl->next; 126 | } 127 | 128 | *ll = NULL; 129 | 130 | return chain; 131 | } 132 | 133 | 134 | ngx_int_t 135 | ngx_chain_add_copy (ngx_pool_t * pool, ngx_chain_t ** chain, ngx_chain_t * in) 136 | { 137 | ngx_chain_t *cl, **ll; 138 | 139 | ll = chain; 140 | 141 | for (cl = *chain; cl; cl = cl->next) 142 | { 143 | ll = &cl->next; 144 | } 145 | 146 | while (in) 147 | { 148 | cl = ngx_alloc_chain_link (pool); 149 | if (cl == NULL) 150 | { 151 | return NGX_ERROR; 152 | } 153 | 154 | cl->buf = in->buf; 155 | *ll = cl; 156 | ll = &cl->next; 157 | in = in->next; 158 | } 159 | 160 | *ll = NULL; 161 | 162 | return NGX_OK; 163 | } 164 | 165 | 166 | ngx_chain_t * 167 | ngx_chain_get_free_buf (ngx_pool_t * p, ngx_chain_t ** free) 168 | { 169 | ngx_chain_t *cl; 170 | 171 | if (*free) 172 | { 173 | cl = *free; 174 | *free = cl->next; 175 | cl->next = NULL; 176 | return cl; 177 | } 178 | 179 | cl = ngx_alloc_chain_link (p); 180 | if (cl == NULL) 181 | { 182 | return NULL; 183 | } 184 | 185 | cl->buf = ngx_calloc_buf (p); 186 | if (cl->buf == NULL) 187 | { 188 | return NULL; 189 | } 190 | 191 | cl->next = NULL; 192 | 193 | return cl; 194 | } 195 | 196 | 197 | void 198 | ngx_chain_update_chains (ngx_pool_t * p, ngx_chain_t ** free, 199 | ngx_chain_t ** busy, ngx_chain_t ** out, 200 | ngx_buf_tag_t tag) 201 | { 202 | ngx_chain_t *cl; 203 | 204 | if (*busy == NULL) 205 | { 206 | *busy = *out; 207 | 208 | } 209 | else 210 | { 211 | for (cl = *busy; cl->next; cl = cl->next) 212 | { /* void */ 213 | } 214 | 215 | cl->next = *out; 216 | } 217 | 218 | *out = NULL; 219 | 220 | while (*busy) 221 | { 222 | cl = *busy; 223 | 224 | if (ngx_buf_size (cl->buf) != 0) 225 | { 226 | break; 227 | } 228 | 229 | if (cl->buf->tag != tag) 230 | { 231 | *busy = cl->next; 232 | ngx_free_chain (p, cl); 233 | continue; 234 | } 235 | 236 | cl->buf->pos = cl->buf->start; 237 | cl->buf->last = cl->buf->start; 238 | 239 | *busy = cl->next; 240 | cl->next = *free; 241 | *free = cl; 242 | } 243 | } 244 | 245 | 246 | off_t 247 | ngx_chain_coalesce_file (ngx_chain_t ** in, off_t limit) 248 | { 249 | off_t total, size, aligned, fprev; 250 | ngx_fd_t fd; 251 | ngx_chain_t *cl; 252 | 253 | total = 0; 254 | 255 | cl = *in; 256 | fd = cl->buf->file->fd; 257 | 258 | do 259 | { 260 | size = cl->buf->file_last - cl->buf->file_pos; 261 | 262 | if (size > limit - total) 263 | { 264 | size = limit - total; 265 | 266 | aligned = (cl->buf->file_pos + size + ngx_pagesize - 1) 267 | & ~((off_t) ngx_pagesize - 1); 268 | 269 | if (aligned <= cl->buf->file_last) 270 | { 271 | size = aligned - cl->buf->file_pos; 272 | } 273 | } 274 | 275 | total += size; 276 | fprev = cl->buf->file_pos + size; 277 | cl = cl->next; 278 | 279 | } 280 | while (cl 281 | && cl->buf->in_file 282 | && total < limit 283 | && fd == cl->buf->file->fd && fprev == cl->buf->file_pos); 284 | 285 | *in = cl; 286 | 287 | return total; 288 | } 289 | 290 | 291 | ngx_chain_t * 292 | ngx_chain_update_sent (ngx_chain_t * in, off_t sent) 293 | { 294 | off_t size; 295 | 296 | for ( /* void */ ; in; in = in->next) 297 | { 298 | 299 | if (ngx_buf_special (in->buf)) 300 | { 301 | continue; 302 | } 303 | 304 | if (sent == 0) 305 | { 306 | break; 307 | } 308 | 309 | size = ngx_buf_size (in->buf); 310 | 311 | if (sent >= size) 312 | { 313 | sent -= size; 314 | 315 | if (ngx_buf_in_memory (in->buf)) 316 | { 317 | in->buf->pos = in->buf->last; 318 | } 319 | 320 | if (in->buf->in_file) 321 | { 322 | in->buf->file_pos = in->buf->file_last; 323 | } 324 | 325 | continue; 326 | } 327 | 328 | if (ngx_buf_in_memory (in->buf)) 329 | { 330 | in->buf->pos += (size_t) sent; 331 | } 332 | 333 | if (in->buf->in_file) 334 | { 335 | in->buf->file_pos += sent; 336 | } 337 | 338 | break; 339 | } 340 | 341 | return in; 342 | } 343 | -------------------------------------------------------------------------------- /tools/dumpformatoptions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # A tool to parse the FormatStyle struct from Format.h and update the 3 | # documentation in ../ClangFormatStyleOptions.rst automatically. 4 | # Run from the directory in which this file is located to update the docs. 5 | 6 | import re 7 | 8 | FORMAT_STYLE_FILE = '../../include/clang/Format/Format.h' 9 | INCLUDE_STYLE_FILE = '../../include/clang/Tooling/Inclusions/IncludeStyle.h' 10 | DOC_FILE = '../ClangFormatStyleOptions.rst' 11 | 12 | 13 | def substitute(text, tag, contents): 14 | replacement = '\n.. START_%s\n\n%s\n\n.. END_%s\n' % (tag, contents, tag) 15 | pattern = r'\n\.\. START_%s\n.*\n\.\. END_%s\n' % (tag, tag) 16 | return re.sub(pattern, '%s', text, flags=re.S) % replacement 17 | 18 | def doxygen2rst(text): 19 | text = re.sub(r'\s*(.*?)\s*<\/tt>', r'``\1``', text) 20 | text = re.sub(r'\\c ([^ ,;\.]+)', r'``\1``', text) 21 | text = re.sub(r'\\\w+ ', '', text) 22 | return text 23 | 24 | def indent(text, columns, indent_first_line=True): 25 | indent = ' ' * columns 26 | s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S) 27 | if not indent_first_line or s.startswith('\n'): 28 | return s 29 | return indent + s 30 | 31 | class Option: 32 | def __init__(self, name, type, comment): 33 | self.name = name 34 | self.type = type 35 | self.comment = comment.strip() 36 | self.enum = None 37 | self.nested_struct = None 38 | 39 | def __str__(self): 40 | s = '**%s** (``%s``)\n%s' % (self.name, self.type, 41 | doxygen2rst(indent(self.comment, 2))) 42 | if self.enum: 43 | s += indent('\n\nPossible values:\n\n%s\n' % self.enum, 2) 44 | if self.nested_struct: 45 | s += indent('\n\nNested configuration flags:\n\n%s\n' %self.nested_struct, 46 | 2) 47 | return s 48 | 49 | class NestedStruct: 50 | def __init__(self, name, comment): 51 | self.name = name 52 | self.comment = comment.strip() 53 | self.values = [] 54 | 55 | def __str__(self): 56 | return '\n'.join(map(str, self.values)) 57 | 58 | class NestedField: 59 | def __init__(self, name, comment): 60 | self.name = name 61 | self.comment = comment.strip() 62 | 63 | def __str__(self): 64 | return '\n* ``%s`` %s' % ( 65 | self.name, 66 | doxygen2rst(indent(self.comment, 2, indent_first_line=False))) 67 | 68 | class Enum: 69 | def __init__(self, name, comment): 70 | self.name = name 71 | self.comment = comment.strip() 72 | self.values = [] 73 | 74 | def __str__(self): 75 | return '\n'.join(map(str, self.values)) 76 | 77 | class EnumValue: 78 | def __init__(self, name, comment): 79 | self.name = name 80 | self.comment = comment 81 | 82 | def __str__(self): 83 | return '* ``%s`` (in configuration: ``%s``)\n%s' % ( 84 | self.name, 85 | re.sub('.*_', '', self.name), 86 | doxygen2rst(indent(self.comment, 2))) 87 | 88 | def clean_comment_line(line): 89 | match = re.match(r'^/// \\code(\{.(\w+)\})?$', line) 90 | if match: 91 | lang = match.groups()[1] 92 | if not lang: 93 | lang = 'c++' 94 | return '\n.. code-block:: %s\n\n' % lang 95 | if line == '/// \\endcode': 96 | return '' 97 | return line[4:] + '\n' 98 | 99 | def read_options(header, isknownoptiontype_func): 100 | class State: 101 | BeforeStruct, Finished, InStruct, InNestedStruct, InNestedFieldComent, \ 102 | InFieldComment, InEnum, InEnumMemberComment = range(8) 103 | state = State.BeforeStruct 104 | 105 | options = [] 106 | enums = {} 107 | nested_structs = {} 108 | comment = '' 109 | enum = None 110 | nested_struct = None 111 | 112 | for line in header: 113 | line = line.strip() 114 | if state == State.BeforeStruct: 115 | if line == 'struct FormatStyle {' or line == 'struct IncludeStyle {': 116 | state = State.InStruct 117 | elif state == State.InStruct: 118 | if line.startswith('///'): 119 | state = State.InFieldComment 120 | comment = clean_comment_line(line) 121 | elif line == '};': 122 | state = State.Finished 123 | break 124 | elif state == State.InFieldComment: 125 | if line.startswith('///'): 126 | comment += clean_comment_line(line) 127 | elif line.startswith('enum'): 128 | state = State.InEnum 129 | name = re.sub(r'enum\s+(\w+)\s*\{', '\\1', line) 130 | enum = Enum(name, comment) 131 | elif line.startswith('struct'): 132 | state = State.InNestedStruct 133 | name = re.sub(r'struct\s+(\w+)\s*\{', '\\1', line) 134 | nested_struct = NestedStruct(name, comment) 135 | elif line.endswith(';'): 136 | state = State.InStruct 137 | field_type, field_name = re.match(r'([<>:\w(,\s)]+)\s+(\w+);', 138 | line).groups() 139 | option = Option(str(field_name), str(field_type), comment) 140 | options.append(option) 141 | else: 142 | raise Exception('Invalid format, expected comment, field or enum') 143 | elif state == State.InNestedStruct: 144 | if line.startswith('///'): 145 | state = State.InNestedFieldComent 146 | comment = clean_comment_line(line) 147 | elif line == '};': 148 | state = State.InStruct 149 | nested_structs[nested_struct.name] = nested_struct 150 | elif state == State.InNestedFieldComent: 151 | if line.startswith('///'): 152 | comment += clean_comment_line(line) 153 | else: 154 | state = State.InNestedStruct 155 | nested_struct.values.append(NestedField(line.replace(';', ''), comment)) 156 | elif state == State.InEnum: 157 | if line.startswith('///'): 158 | state = State.InEnumMemberComment 159 | comment = clean_comment_line(line) 160 | elif line == '};': 161 | state = State.InStruct 162 | enums[enum.name] = enum 163 | else: 164 | raise Exception('Invalid format, expected enum field comment or };') 165 | elif state == State.InEnumMemberComment: 166 | if line.startswith('///'): 167 | comment += clean_comment_line(line) 168 | else: 169 | state = State.InEnum 170 | enum.values.append(EnumValue(line.replace(',', ''), comment)) 171 | if state != State.Finished: 172 | raise Exception('Not finished by the end of file') 173 | 174 | for option in options: 175 | if not isknownoptiontype_func(option.type): 176 | if option.type in enums: 177 | option.enum = enums[option.type] 178 | elif option.type in nested_structs: 179 | option.nested_struct = nested_structs[option.type]; 180 | else: 181 | raise Exception('Unknown type: %s' % option.type) 182 | return options 183 | -------------------------------------------------------------------------------- /tests/examples/bottle_sqlalchemy/bottle_sqlalchemy.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This bottle-sqlalchemy plugin integrates SQLAlchemy with your Bottle 3 | application. It connects to a database at the beginning of a request, 4 | passes the database handle to the route callback and closes the connection 5 | afterwards. 6 | 7 | The plugin inject an argument to all route callbacks that require a `db` 8 | keyword. 9 | 10 | Usage Example:: 11 | 12 | import bottle 13 | from bottle import HTTPError 14 | from bottle.ext import sqlalchemy 15 | from sqlalchemy import create_engine, Column, Integer, Sequence, String 16 | from sqlalchemy.ext.declarative import declarative_base 17 | 18 | Base = declarative_base() 19 | engine = create_engine('sqlite:///:memory:', echo=True) 20 | 21 | app = bottle.Bottle() 22 | plugin = sqlalchemy.Plugin(engine, Base.metadata, create=True) 23 | app.install(plugin) 24 | 25 | class Entity(Base): 26 | __tablename__ = 'entity' 27 | id = Column(Integer, Sequence('id_seq'), primary_key=True) 28 | name = Column(String(50)) 29 | 30 | def __init__(self, name): 31 | self.name = name 32 | 33 | def __repr__(self): 34 | return "" % (self.id, self.name) 35 | 36 | 37 | @app.get('/:name') 38 | def show(name, db): 39 | entity = db.query(Entity).filter_by(name=name).first() 40 | if entity: 41 | return {'id': entity.id, 'name': entity.name} 42 | return HTTPError(404, 'Entity not found.') 43 | 44 | @app.put('/:name') 45 | def put_name(name, db): 46 | entity = Entity(name) 47 | db.add(entity) 48 | 49 | 50 | It is up to you create engine and metadata, because SQLAlchemy has 51 | a lot of options to do it. The plugin just handles the SQLAlchemy 52 | session. 53 | 54 | Copyright (c) 2011-2012, Iuri de Silvio 55 | License: MIT (see LICENSE for details) 56 | ''' 57 | 58 | import inspect 59 | 60 | import bottle 61 | from sqlalchemy.exc import SQLAlchemyError 62 | from sqlalchemy.orm import sessionmaker 63 | from sqlalchemy.orm.scoping import ScopedSession 64 | 65 | # PluginError is defined to bottle >= 0.10 66 | if not hasattr(bottle, 'PluginError'): 67 | class PluginError(bottle.BottleException): 68 | pass 69 | bottle.PluginError = PluginError 70 | 71 | 72 | class SQLAlchemyPlugin(object): 73 | 74 | name = 'sqlalchemy' 75 | api = 2 76 | 77 | def __init__(self, engine, metadata=None, 78 | keyword='db', commit=True, create=False, use_kwargs=False, create_session=None): 79 | ''' 80 | :param engine: SQLAlchemy engine created with `create_engine` function 81 | :param metadata: SQLAlchemy metadata. It is required only if `create=True` 82 | :param keyword: Keyword used to inject session database in a route 83 | :param create: If it is true, execute `metadata.create_all(engine)` 84 | when plugin is applied 85 | :param commit: If it is true, commit changes after route is executed. 86 | :param use_kwargs: plugin inject session database even if it is not 87 | explicitly defined, using **kwargs argument if defined. 88 | :param create_session: SQLAlchemy session maker created with the 89 | 'sessionmaker' function. Will create its own if undefined. 90 | ''' 91 | self.engine = engine 92 | if create_session is None: 93 | create_session = sessionmaker() 94 | self.create_session = create_session 95 | self.metadata = metadata 96 | self.keyword = keyword 97 | self.create = create 98 | self.commit = commit 99 | self.use_kwargs = use_kwargs 100 | 101 | def setup(self, app): 102 | ''' Make sure that other installed plugins don't affect the same 103 | keyword argument and check if metadata is available.''' 104 | for other in app.plugins: 105 | if not isinstance(other, SQLAlchemyPlugin): 106 | continue 107 | if other.keyword == self.keyword: 108 | raise bottle.PluginError("Found another SQLAlchemy plugin with "\ 109 | "conflicting settings (non-unique keyword).") 110 | elif other.name == self.name: 111 | self.name += '_%s' % self.keyword 112 | if self.create and not self.metadata: 113 | raise bottle.PluginError('Define metadata value to create database.') 114 | 115 | def apply(self, callback, route): 116 | # hack to support bottle v0.9.x 117 | if bottle.__version__.startswith('0.9'): 118 | config = route['config'] 119 | _callback = route['callback'] 120 | else: 121 | config = route.config 122 | _callback = route.callback 123 | 124 | if "sqlalchemy" in config: # support for configuration before `ConfigDict` namespaces 125 | g = lambda key, default: config.get('sqlalchemy', {}).get(key, default) 126 | else: 127 | g = lambda key, default: config.get('sqlalchemy.' + key, default) 128 | 129 | keyword = g('keyword', self.keyword) 130 | create = g('create', self.create) 131 | commit = g('commit', self.commit) 132 | use_kwargs = g('use_kwargs', self.use_kwargs) 133 | 134 | try: 135 | # check if inspect.signature exists 136 | inspect.signature 137 | except AttributeError: 138 | argspec = inspect.getargspec(_callback) 139 | parameters = argspec.args 140 | accept_kwargs = argspec.keywords 141 | else: 142 | parameters = inspect.signature(_callback).parameters 143 | accept_kwargs = any(p.kind == inspect.Parameter.VAR_KEYWORD 144 | for p in parameters.values()) 145 | 146 | if not ((use_kwargs and accept_kwargs) or keyword in parameters): 147 | return callback 148 | 149 | if create: 150 | self.metadata.create_all(self.engine) 151 | 152 | def wrapper(*args, **kwargs): 153 | kwargs[keyword] = session = self.create_session(bind=self.engine) 154 | try: 155 | rv = callback(*args, **kwargs) 156 | if commit: 157 | session.commit() 158 | except (SQLAlchemyError, bottle.HTTPError): 159 | session.rollback() 160 | raise 161 | except bottle.HTTPResponse: 162 | if commit: 163 | session.commit() 164 | raise 165 | finally: 166 | if isinstance(self.create_session, ScopedSession): 167 | self.create_session.remove() 168 | else: 169 | session.close() 170 | return rv 171 | 172 | return wrapper 173 | 174 | 175 | Plugin = SQLAlchemyPlugin -------------------------------------------------------------------------------- /tests/examples/nginx/result_clang-format/ngx_buf.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_buf_t * 13 | ngx_create_temp_buf(ngx_pool_t *pool, size_t size) 14 | { 15 | ngx_buf_t *b; 16 | 17 | b = ngx_calloc_buf(pool); 18 | if (b == NULL) { 19 | return NULL; 20 | } 21 | 22 | b->start = ngx_palloc(pool, size); 23 | if (b->start == NULL) { 24 | return NULL; 25 | } 26 | 27 | /* 28 | * set by ngx_calloc_buf(): 29 | * 30 | * b->file_pos = 0; 31 | * b->file_last = 0; 32 | * b->file = NULL; 33 | * b->shadow = NULL; 34 | * b->tag = 0; 35 | * and flags 36 | */ 37 | 38 | b->pos = b->start; 39 | b->last = b->start; 40 | b->end = b->last + size; 41 | b->temporary = 1; 42 | 43 | return b; 44 | } 45 | 46 | 47 | ngx_chain_t * 48 | ngx_alloc_chain_link(ngx_pool_t *pool) 49 | { 50 | ngx_chain_t *cl; 51 | 52 | cl = pool->chain; 53 | 54 | if (cl) { 55 | pool->chain = cl->next; 56 | return cl; 57 | } 58 | 59 | cl = ngx_palloc(pool, sizeof(ngx_chain_t)); 60 | if (cl == NULL) { 61 | return NULL; 62 | } 63 | 64 | return cl; 65 | } 66 | 67 | 68 | ngx_chain_t * 69 | ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) 70 | { 71 | u_char *p; 72 | ngx_int_t i; 73 | ngx_buf_t *b; 74 | ngx_chain_t *chain, *cl, **ll; 75 | 76 | p = ngx_palloc(pool, bufs->num * bufs->size); 77 | if (p == NULL) { 78 | return NULL; 79 | } 80 | 81 | ll = &chain; 82 | 83 | for (i = 0; i < bufs->num; i++) { 84 | 85 | b = ngx_calloc_buf(pool); 86 | if (b == NULL) { 87 | return NULL; 88 | } 89 | 90 | /* 91 | * set by ngx_calloc_buf(): 92 | * 93 | * b->file_pos = 0; 94 | * b->file_last = 0; 95 | * b->file = NULL; 96 | * b->shadow = NULL; 97 | * b->tag = 0; 98 | * and flags 99 | * 100 | */ 101 | 102 | b->pos = p; 103 | b->last = p; 104 | b->temporary = 1; 105 | 106 | b->start = p; 107 | p += bufs->size; 108 | b->end = p; 109 | 110 | cl = ngx_alloc_chain_link(pool); 111 | if (cl == NULL) { 112 | return NULL; 113 | } 114 | 115 | cl->buf = b; 116 | *ll = cl; 117 | ll = &cl->next; 118 | } 119 | 120 | *ll = NULL; 121 | 122 | return chain; 123 | } 124 | 125 | 126 | ngx_int_t 127 | ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) 128 | { 129 | ngx_chain_t *cl, **ll; 130 | 131 | ll = chain; 132 | 133 | for (cl = *chain; cl; cl = cl->next) { 134 | ll = &cl->next; 135 | } 136 | 137 | while (in) { 138 | cl = ngx_alloc_chain_link(pool); 139 | if (cl == NULL) { 140 | return NGX_ERROR; 141 | } 142 | 143 | cl->buf = in->buf; 144 | *ll = cl; 145 | ll = &cl->next; 146 | in = in->next; 147 | } 148 | 149 | *ll = NULL; 150 | 151 | return NGX_OK; 152 | } 153 | 154 | 155 | ngx_chain_t * 156 | ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free) 157 | { 158 | ngx_chain_t *cl; 159 | 160 | if (*free) { 161 | cl = *free; 162 | *free = cl->next; 163 | cl->next = NULL; 164 | return cl; 165 | } 166 | 167 | cl = ngx_alloc_chain_link(p); 168 | if (cl == NULL) { 169 | return NULL; 170 | } 171 | 172 | cl->buf = ngx_calloc_buf(p); 173 | if (cl->buf == NULL) { 174 | return NULL; 175 | } 176 | 177 | cl->next = NULL; 178 | 179 | return cl; 180 | } 181 | 182 | 183 | void 184 | ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy, 185 | ngx_chain_t **out, ngx_buf_tag_t tag) 186 | { 187 | ngx_chain_t *cl; 188 | 189 | if (*busy == NULL) { 190 | *busy = *out; 191 | 192 | } else { 193 | for (cl = *busy; cl->next; cl = cl->next) { /* void */ 194 | } 195 | 196 | cl->next = *out; 197 | } 198 | 199 | *out = NULL; 200 | 201 | while (*busy) { 202 | cl = *busy; 203 | 204 | if (ngx_buf_size(cl->buf) != 0) { 205 | break; 206 | } 207 | 208 | if (cl->buf->tag != tag) { 209 | *busy = cl->next; 210 | ngx_free_chain(p, cl); 211 | continue; 212 | } 213 | 214 | cl->buf->pos = cl->buf->start; 215 | cl->buf->last = cl->buf->start; 216 | 217 | *busy = cl->next; 218 | cl->next = *free; 219 | *free = cl; 220 | } 221 | } 222 | 223 | 224 | off_t 225 | ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit) 226 | { 227 | off_t total, size, aligned, fprev; 228 | ngx_fd_t fd; 229 | ngx_chain_t *cl; 230 | 231 | total = 0; 232 | 233 | cl = *in; 234 | fd = cl->buf->file->fd; 235 | 236 | do { 237 | size = cl->buf->file_last - cl->buf->file_pos; 238 | 239 | if (size > limit - total) { 240 | size = limit - total; 241 | 242 | aligned = (cl->buf->file_pos + size + ngx_pagesize - 1) 243 | & ~((off_t) ngx_pagesize - 1); 244 | 245 | if (aligned <= cl->buf->file_last) { 246 | size = aligned - cl->buf->file_pos; 247 | } 248 | } 249 | 250 | total += size; 251 | fprev = cl->buf->file_pos + size; 252 | cl = cl->next; 253 | 254 | } while (cl 255 | && cl->buf->in_file 256 | && total < limit 257 | && fd == cl->buf->file->fd 258 | && fprev == cl->buf->file_pos); 259 | 260 | *in = cl; 261 | 262 | return total; 263 | } 264 | 265 | 266 | ngx_chain_t * 267 | ngx_chain_update_sent(ngx_chain_t *in, off_t sent) 268 | { 269 | off_t size; 270 | 271 | for (/* void */; in; in = in->next) { 272 | 273 | if (ngx_buf_special(in->buf)) { 274 | continue; 275 | } 276 | 277 | if (sent == 0) { 278 | break; 279 | } 280 | 281 | size = ngx_buf_size(in->buf); 282 | 283 | if (sent >= size) { 284 | sent -= size; 285 | 286 | if (ngx_buf_in_memory(in->buf)) { 287 | in->buf->pos = in->buf->last; 288 | } 289 | 290 | if (in->buf->in_file) { 291 | in->buf->file_pos = in->buf->file_last; 292 | } 293 | 294 | continue; 295 | } 296 | 297 | if (ngx_buf_in_memory(in->buf)) { 298 | in->buf->pos += (size_t) sent; 299 | } 300 | 301 | if (in->buf->in_file) { 302 | in->buf->file_pos += sent; 303 | } 304 | 305 | break; 306 | } 307 | 308 | return in; 309 | } 310 | -------------------------------------------------------------------------------- /tests/examples/nginx/ngx_buf.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_buf_t * 13 | ngx_create_temp_buf(ngx_pool_t *pool, size_t size) 14 | { 15 | ngx_buf_t *b; 16 | 17 | b = ngx_calloc_buf(pool); 18 | if (b == NULL) { 19 | return NULL; 20 | } 21 | 22 | b->start = ngx_palloc(pool, size); 23 | if (b->start == NULL) { 24 | return NULL; 25 | } 26 | 27 | /* 28 | * set by ngx_calloc_buf(): 29 | * 30 | * b->file_pos = 0; 31 | * b->file_last = 0; 32 | * b->file = NULL; 33 | * b->shadow = NULL; 34 | * b->tag = 0; 35 | * and flags 36 | */ 37 | 38 | b->pos = b->start; 39 | b->last = b->start; 40 | b->end = b->last + size; 41 | b->temporary = 1; 42 | 43 | return b; 44 | } 45 | 46 | 47 | ngx_chain_t * 48 | ngx_alloc_chain_link(ngx_pool_t *pool) 49 | { 50 | ngx_chain_t *cl; 51 | 52 | cl = pool->chain; 53 | 54 | if (cl) { 55 | pool->chain = cl->next; 56 | return cl; 57 | } 58 | 59 | cl = ngx_palloc(pool, sizeof(ngx_chain_t)); 60 | if (cl == NULL) { 61 | return NULL; 62 | } 63 | 64 | return cl; 65 | } 66 | 67 | 68 | ngx_chain_t * 69 | ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) 70 | { 71 | u_char *p; 72 | ngx_int_t i; 73 | ngx_buf_t *b; 74 | ngx_chain_t *chain, *cl, **ll; 75 | 76 | p = ngx_palloc(pool, bufs->num * bufs->size); 77 | if (p == NULL) { 78 | return NULL; 79 | } 80 | 81 | ll = &chain; 82 | 83 | for (i = 0; i < bufs->num; i++) { 84 | 85 | b = ngx_calloc_buf(pool); 86 | if (b == NULL) { 87 | return NULL; 88 | } 89 | 90 | /* 91 | * set by ngx_calloc_buf(): 92 | * 93 | * b->file_pos = 0; 94 | * b->file_last = 0; 95 | * b->file = NULL; 96 | * b->shadow = NULL; 97 | * b->tag = 0; 98 | * and flags 99 | * 100 | */ 101 | 102 | b->pos = p; 103 | b->last = p; 104 | b->temporary = 1; 105 | 106 | b->start = p; 107 | p += bufs->size; 108 | b->end = p; 109 | 110 | cl = ngx_alloc_chain_link(pool); 111 | if (cl == NULL) { 112 | return NULL; 113 | } 114 | 115 | cl->buf = b; 116 | *ll = cl; 117 | ll = &cl->next; 118 | } 119 | 120 | *ll = NULL; 121 | 122 | return chain; 123 | } 124 | 125 | 126 | ngx_int_t 127 | ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) 128 | { 129 | ngx_chain_t *cl, **ll; 130 | 131 | ll = chain; 132 | 133 | for (cl = *chain; cl; cl = cl->next) { 134 | ll = &cl->next; 135 | } 136 | 137 | while (in) { 138 | cl = ngx_alloc_chain_link(pool); 139 | if (cl == NULL) { 140 | return NGX_ERROR; 141 | } 142 | 143 | cl->buf = in->buf; 144 | *ll = cl; 145 | ll = &cl->next; 146 | in = in->next; 147 | } 148 | 149 | *ll = NULL; 150 | 151 | return NGX_OK; 152 | } 153 | 154 | 155 | ngx_chain_t * 156 | ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free) 157 | { 158 | ngx_chain_t *cl; 159 | 160 | if (*free) { 161 | cl = *free; 162 | *free = cl->next; 163 | cl->next = NULL; 164 | return cl; 165 | } 166 | 167 | cl = ngx_alloc_chain_link(p); 168 | if (cl == NULL) { 169 | return NULL; 170 | } 171 | 172 | cl->buf = ngx_calloc_buf(p); 173 | if (cl->buf == NULL) { 174 | return NULL; 175 | } 176 | 177 | cl->next = NULL; 178 | 179 | return cl; 180 | } 181 | 182 | 183 | void 184 | ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy, 185 | ngx_chain_t **out, ngx_buf_tag_t tag) 186 | { 187 | ngx_chain_t *cl; 188 | 189 | if (*busy == NULL) { 190 | *busy = *out; 191 | 192 | } else { 193 | for (cl = *busy; cl->next; cl = cl->next) { /* void */ } 194 | 195 | cl->next = *out; 196 | } 197 | 198 | *out = NULL; 199 | 200 | while (*busy) { 201 | cl = *busy; 202 | 203 | if (ngx_buf_size(cl->buf) != 0) { 204 | break; 205 | } 206 | 207 | if (cl->buf->tag != tag) { 208 | *busy = cl->next; 209 | ngx_free_chain(p, cl); 210 | continue; 211 | } 212 | 213 | cl->buf->pos = cl->buf->start; 214 | cl->buf->last = cl->buf->start; 215 | 216 | *busy = cl->next; 217 | cl->next = *free; 218 | *free = cl; 219 | } 220 | } 221 | 222 | 223 | off_t 224 | ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit) 225 | { 226 | off_t total, size, aligned, fprev; 227 | ngx_fd_t fd; 228 | ngx_chain_t *cl; 229 | 230 | total = 0; 231 | 232 | cl = *in; 233 | fd = cl->buf->file->fd; 234 | 235 | do { 236 | size = cl->buf->file_last - cl->buf->file_pos; 237 | 238 | if (size > limit - total) { 239 | size = limit - total; 240 | 241 | aligned = (cl->buf->file_pos + size + ngx_pagesize - 1) 242 | & ~((off_t) ngx_pagesize - 1); 243 | 244 | if (aligned <= cl->buf->file_last) { 245 | size = aligned - cl->buf->file_pos; 246 | } 247 | } 248 | 249 | total += size; 250 | fprev = cl->buf->file_pos + size; 251 | cl = cl->next; 252 | 253 | } while (cl 254 | && cl->buf->in_file 255 | && total < limit 256 | && fd == cl->buf->file->fd 257 | && fprev == cl->buf->file_pos); 258 | 259 | *in = cl; 260 | 261 | return total; 262 | } 263 | 264 | 265 | ngx_chain_t * 266 | ngx_chain_update_sent(ngx_chain_t *in, off_t sent) 267 | { 268 | off_t size; 269 | 270 | for ( /* void */ ; in; in = in->next) { 271 | 272 | if (ngx_buf_special(in->buf)) { 273 | continue; 274 | } 275 | 276 | if (sent == 0) { 277 | break; 278 | } 279 | 280 | size = ngx_buf_size(in->buf); 281 | 282 | if (sent >= size) { 283 | sent -= size; 284 | 285 | if (ngx_buf_in_memory(in->buf)) { 286 | in->buf->pos = in->buf->last; 287 | } 288 | 289 | if (in->buf->in_file) { 290 | in->buf->file_pos = in->buf->file_last; 291 | } 292 | 293 | continue; 294 | } 295 | 296 | if (ngx_buf_in_memory(in->buf)) { 297 | in->buf->pos += (size_t) sent; 298 | } 299 | 300 | if (in->buf->in_file) { 301 | in->buf->file_pos += sent; 302 | } 303 | 304 | break; 305 | } 306 | 307 | return in; 308 | } 309 | -------------------------------------------------------------------------------- /tests/examples/bottle_sqlalchemy/result_yapf/bottle_sqlalchemy.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This bottle-sqlalchemy plugin integrates SQLAlchemy with your Bottle 3 | application. It connects to a database at the beginning of a request, 4 | passes the database handle to the route callback and closes the connection 5 | afterwards. 6 | 7 | The plugin inject an argument to all route callbacks that require a `db` 8 | keyword. 9 | 10 | Usage Example:: 11 | 12 | import bottle 13 | from bottle import HTTPError 14 | from bottle.ext import sqlalchemy 15 | from sqlalchemy import create_engine, Column, Integer, Sequence, String 16 | from sqlalchemy.ext.declarative import declarative_base 17 | 18 | Base = declarative_base() 19 | engine = create_engine('sqlite:///:memory:', echo=True) 20 | 21 | app = bottle.Bottle() 22 | plugin = sqlalchemy.Plugin(engine, Base.metadata, create=True) 23 | app.install(plugin) 24 | 25 | class Entity(Base): 26 | __tablename__ = 'entity' 27 | id = Column(Integer, Sequence('id_seq'), primary_key=True) 28 | name = Column(String(50)) 29 | 30 | def __init__(self, name): 31 | self.name = name 32 | 33 | def __repr__(self): 34 | return "" % (self.id, self.name) 35 | 36 | 37 | @app.get('/:name') 38 | def show(name, db): 39 | entity = db.query(Entity).filter_by(name=name).first() 40 | if entity: 41 | return {'id': entity.id, 'name': entity.name} 42 | return HTTPError(404, 'Entity not found.') 43 | 44 | @app.put('/:name') 45 | def put_name(name, db): 46 | entity = Entity(name) 47 | db.add(entity) 48 | 49 | 50 | It is up to you create engine and metadata, because SQLAlchemy has 51 | a lot of options to do it. The plugin just handles the SQLAlchemy 52 | session. 53 | 54 | Copyright (c) 2011-2012, Iuri de Silvio 55 | License: MIT (see LICENSE for details) 56 | ''' 57 | 58 | import inspect 59 | 60 | import bottle 61 | from sqlalchemy.exc import SQLAlchemyError 62 | from sqlalchemy.orm import sessionmaker 63 | from sqlalchemy.orm.scoping import ScopedSession 64 | 65 | # PluginError is defined to bottle >= 0.10 66 | if not hasattr(bottle, 'PluginError'): 67 | 68 | class PluginError(bottle.BottleException): 69 | pass 70 | 71 | bottle.PluginError = PluginError 72 | 73 | 74 | class SQLAlchemyPlugin(object): 75 | 76 | name = 'sqlalchemy' 77 | api = 2 78 | 79 | def __init__(self, engine, metadata=None, keyword='db', commit=True, 80 | create=False, use_kwargs=False, create_session=None): 81 | ''' 82 | :param engine: SQLAlchemy engine created with `create_engine` function 83 | :param metadata: SQLAlchemy metadata. It is required only if `create=True` 84 | :param keyword: Keyword used to inject session database in a route 85 | :param create: If it is true, execute `metadata.create_all(engine)` 86 | when plugin is applied 87 | :param commit: If it is true, commit changes after route is executed. 88 | :param use_kwargs: plugin inject session database even if it is not 89 | explicitly defined, using **kwargs argument if defined. 90 | :param create_session: SQLAlchemy session maker created with the 91 | 'sessionmaker' function. Will create its own if undefined. 92 | ''' 93 | self.engine = engine 94 | if create_session is None: 95 | create_session = sessionmaker() 96 | self.create_session = create_session 97 | self.metadata = metadata 98 | self.keyword = keyword 99 | self.create = create 100 | self.commit = commit 101 | self.use_kwargs = use_kwargs 102 | 103 | def setup(self, app): 104 | ''' Make sure that other installed plugins don't affect the same 105 | keyword argument and check if metadata is available.''' 106 | for other in app.plugins: 107 | if not isinstance(other, SQLAlchemyPlugin): 108 | continue 109 | if other.keyword == self.keyword: 110 | raise bottle.PluginError("Found another SQLAlchemy plugin with "\ 111 | "conflicting settings (non-unique keyword).") 112 | elif other.name == self.name: 113 | self.name += '_%s' % self.keyword 114 | if self.create and not self.metadata: 115 | raise bottle.PluginError('Define metadata value to create database.') 116 | 117 | def apply(self, callback, route): 118 | # hack to support bottle v0.9.x 119 | if bottle.__version__.startswith('0.9'): 120 | config = route['config'] 121 | _callback = route['callback'] 122 | else: 123 | config = route.config 124 | _callback = route.callback 125 | 126 | if "sqlalchemy" in config: # support for configuration before `ConfigDict` namespaces 127 | g = lambda key, default: config.get('sqlalchemy', {}).get(key, default) 128 | else: 129 | g = lambda key, default: config.get('sqlalchemy.' + key, default) 130 | 131 | keyword = g('keyword', self.keyword) 132 | create = g('create', self.create) 133 | commit = g('commit', self.commit) 134 | use_kwargs = g('use_kwargs', self.use_kwargs) 135 | 136 | try: 137 | # check if inspect.signature exists 138 | inspect.signature 139 | except AttributeError: 140 | argspec = inspect.getargspec(_callback) 141 | parameters = argspec.args 142 | accept_kwargs = argspec.keywords 143 | else: 144 | parameters = inspect.signature(_callback).parameters 145 | accept_kwargs = any(p.kind == inspect.Parameter.VAR_KEYWORD 146 | for p in parameters.values()) 147 | 148 | if not ((use_kwargs and accept_kwargs) or keyword in parameters): 149 | return callback 150 | 151 | if create: 152 | self.metadata.create_all(self.engine) 153 | 154 | def wrapper(*args, **kwargs): 155 | kwargs[keyword] = session = self.create_session(bind=self.engine) 156 | try: 157 | rv = callback(*args, **kwargs) 158 | if commit: 159 | session.commit() 160 | except (SQLAlchemyError, bottle.HTTPError): 161 | session.rollback() 162 | raise 163 | except bottle.HTTPResponse: 164 | if commit: 165 | session.commit() 166 | raise 167 | finally: 168 | if isinstance(self.create_session, ScopedSession): 169 | self.create_session.remove() 170 | else: 171 | session.close() 172 | return rv 173 | 174 | return wrapper 175 | 176 | 177 | Plugin = SQLAlchemyPlugin 178 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_uncrustify/ngx_buf.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_buf_t * 13 | ngx_create_temp_buf(ngx_pool_t *pool, size_t size) 14 | { 15 | ngx_buf_t *b; 16 | 17 | b = ngx_calloc_buf(pool); 18 | if (b == NULL) { 19 | return NULL; 20 | } 21 | 22 | b->start = ngx_palloc(pool, size); 23 | if (b->start == NULL) { 24 | return NULL; 25 | } 26 | 27 | /* 28 | * set by ngx_calloc_buf(): 29 | * 30 | * b->file_pos = 0; 31 | * b->file_last = 0; 32 | * b->file = NULL; 33 | * b->shadow = NULL; 34 | * b->tag = 0; 35 | * and flags 36 | */ 37 | 38 | b->pos = b->start; 39 | b->last = b->start; 40 | b->end = b->last + size; 41 | b->temporary = 1; 42 | 43 | return b; 44 | } 45 | 46 | 47 | ngx_chain_t * 48 | ngx_alloc_chain_link(ngx_pool_t *pool) 49 | { 50 | ngx_chain_t *cl; 51 | 52 | cl = pool->chain; 53 | 54 | if (cl) { 55 | pool->chain = cl->next; 56 | return cl; 57 | } 58 | 59 | cl = ngx_palloc(pool, sizeof(ngx_chain_t)); 60 | if (cl == NULL) { 61 | return NULL; 62 | } 63 | 64 | return cl; 65 | } 66 | 67 | 68 | ngx_chain_t * 69 | ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) 70 | { 71 | u_char *p; 72 | ngx_int_t i; 73 | ngx_buf_t *b; 74 | ngx_chain_t *chain, *cl, **ll; 75 | 76 | p = ngx_palloc(pool, bufs->num * bufs->size); 77 | if (p == NULL) { 78 | return NULL; 79 | } 80 | 81 | ll = &chain; 82 | 83 | for (i = 0; i < bufs->num; i++) { 84 | 85 | b = ngx_calloc_buf(pool); 86 | if (b == NULL) { 87 | return NULL; 88 | } 89 | 90 | /* 91 | * set by ngx_calloc_buf(): 92 | * 93 | * b->file_pos = 0; 94 | * b->file_last = 0; 95 | * b->file = NULL; 96 | * b->shadow = NULL; 97 | * b->tag = 0; 98 | * and flags 99 | * 100 | */ 101 | 102 | b->pos = p; 103 | b->last = p; 104 | b->temporary = 1; 105 | 106 | b->start = p; 107 | p += bufs->size; 108 | b->end = p; 109 | 110 | cl = ngx_alloc_chain_link(pool); 111 | if (cl == NULL) { 112 | return NULL; 113 | } 114 | 115 | cl->buf = b; 116 | *ll = cl; 117 | ll = &cl->next; 118 | } 119 | 120 | *ll = NULL; 121 | 122 | return chain; 123 | } 124 | 125 | 126 | ngx_int_t 127 | ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) 128 | { 129 | ngx_chain_t *cl, **ll; 130 | 131 | ll = chain; 132 | 133 | for (cl = *chain; cl; cl = cl->next) { 134 | ll = &cl->next; 135 | } 136 | 137 | while (in) { 138 | cl = ngx_alloc_chain_link(pool); 139 | if (cl == NULL) { 140 | return NGX_ERROR; 141 | } 142 | 143 | cl->buf = in->buf; 144 | *ll = cl; 145 | ll = &cl->next; 146 | in = in->next; 147 | } 148 | 149 | *ll = NULL; 150 | 151 | return NGX_OK; 152 | } 153 | 154 | 155 | ngx_chain_t * 156 | ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free) 157 | { 158 | ngx_chain_t *cl; 159 | 160 | if (*free) { 161 | cl = *free; 162 | *free = cl->next; 163 | cl->next = NULL; 164 | return cl; 165 | } 166 | 167 | cl = ngx_alloc_chain_link(p); 168 | if (cl == NULL) { 169 | return NULL; 170 | } 171 | 172 | cl->buf = ngx_calloc_buf(p); 173 | if (cl->buf == NULL) { 174 | return NULL; 175 | } 176 | 177 | cl->next = NULL; 178 | 179 | return cl; 180 | } 181 | 182 | 183 | void 184 | ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy, 185 | ngx_chain_t **out, ngx_buf_tag_t tag) 186 | { 187 | ngx_chain_t *cl; 188 | 189 | if (*busy == NULL) { 190 | *busy = *out; 191 | 192 | } else { 193 | for (cl = *busy; cl->next; cl = cl->next) { /* void */ } 194 | 195 | cl->next = *out; 196 | } 197 | 198 | *out = NULL; 199 | 200 | while (*busy) { 201 | cl = *busy; 202 | 203 | if (ngx_buf_size(cl->buf) != 0) { 204 | break; 205 | } 206 | 207 | if (cl->buf->tag != tag) { 208 | *busy = cl->next; 209 | ngx_free_chain(p, cl); 210 | continue; 211 | } 212 | 213 | cl->buf->pos = cl->buf->start; 214 | cl->buf->last = cl->buf->start; 215 | 216 | *busy = cl->next; 217 | cl->next = *free; 218 | *free = cl; 219 | } 220 | } 221 | 222 | 223 | off_t 224 | ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit) 225 | { 226 | off_t total, size, aligned, fprev; 227 | ngx_fd_t fd; 228 | ngx_chain_t *cl; 229 | 230 | total = 0; 231 | 232 | cl = *in; 233 | fd = cl->buf->file->fd; 234 | 235 | do { 236 | size = cl->buf->file_last - cl->buf->file_pos; 237 | 238 | if (size > limit - total) { 239 | size = limit - total; 240 | 241 | aligned = (cl->buf->file_pos + size + ngx_pagesize - 1) 242 | & ~((off_t) ngx_pagesize - 1); 243 | 244 | if (aligned <= cl->buf->file_last) { 245 | size = aligned - cl->buf->file_pos; 246 | } 247 | } 248 | 249 | total += size; 250 | fprev = cl->buf->file_pos + size; 251 | cl = cl->next; 252 | 253 | } while (cl 254 | && cl->buf->in_file 255 | && total < limit 256 | && fd == cl->buf->file->fd 257 | && fprev == cl->buf->file_pos); 258 | 259 | *in = cl; 260 | 261 | return total; 262 | } 263 | 264 | 265 | ngx_chain_t * 266 | ngx_chain_update_sent(ngx_chain_t *in, off_t sent) 267 | { 268 | off_t size; 269 | 270 | for ( /* void */; in; in = in->next) { 271 | 272 | if (ngx_buf_special(in->buf)) { 273 | continue; 274 | } 275 | 276 | if (sent == 0) { 277 | break; 278 | } 279 | 280 | size = ngx_buf_size(in->buf); 281 | 282 | if (sent >= size) { 283 | sent -= size; 284 | 285 | if (ngx_buf_in_memory(in->buf)) { 286 | in->buf->pos = in->buf->last; 287 | } 288 | 289 | if (in->buf->in_file) { 290 | in->buf->file_pos = in->buf->file_last; 291 | } 292 | 293 | continue; 294 | } 295 | 296 | if (ngx_buf_in_memory(in->buf)) { 297 | in->buf->pos += (size_t) sent; 298 | } 299 | 300 | if (in->buf->in_file) { 301 | in->buf->file_pos += sent; 302 | } 303 | 304 | break; 305 | } 306 | 307 | return in; 308 | } 309 | -------------------------------------------------------------------------------- /tests/examples/nginx/result_astyle/ngx_buf.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_buf_t * 13 | ngx_create_temp_buf(ngx_pool_t *pool, size_t size) 14 | { 15 | ngx_buf_t *b; 16 | 17 | b = ngx_calloc_buf(pool); 18 | if (b == NULL) { 19 | return NULL; 20 | } 21 | 22 | b->start = ngx_palloc(pool, size); 23 | if (b->start == NULL) { 24 | return NULL; 25 | } 26 | 27 | /* 28 | * set by ngx_calloc_buf(): 29 | * 30 | * b->file_pos = 0; 31 | * b->file_last = 0; 32 | * b->file = NULL; 33 | * b->shadow = NULL; 34 | * b->tag = 0; 35 | * and flags 36 | */ 37 | 38 | b->pos = b->start; 39 | b->last = b->start; 40 | b->end = b->last + size; 41 | b->temporary = 1; 42 | 43 | return b; 44 | } 45 | 46 | 47 | ngx_chain_t * 48 | ngx_alloc_chain_link(ngx_pool_t *pool) 49 | { 50 | ngx_chain_t *cl; 51 | 52 | cl = pool->chain; 53 | 54 | if (cl) { 55 | pool->chain = cl->next; 56 | return cl; 57 | } 58 | 59 | cl = ngx_palloc(pool, sizeof(ngx_chain_t)); 60 | if (cl == NULL) { 61 | return NULL; 62 | } 63 | 64 | return cl; 65 | } 66 | 67 | 68 | ngx_chain_t * 69 | ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) 70 | { 71 | u_char *p; 72 | ngx_int_t i; 73 | ngx_buf_t *b; 74 | ngx_chain_t *chain, *cl, **ll; 75 | 76 | p = ngx_palloc(pool, bufs->num * bufs->size); 77 | if (p == NULL) { 78 | return NULL; 79 | } 80 | 81 | ll = &chain; 82 | 83 | for (i = 0; i < bufs->num; i++) { 84 | 85 | b = ngx_calloc_buf(pool); 86 | if (b == NULL) { 87 | return NULL; 88 | } 89 | 90 | /* 91 | * set by ngx_calloc_buf(): 92 | * 93 | * b->file_pos = 0; 94 | * b->file_last = 0; 95 | * b->file = NULL; 96 | * b->shadow = NULL; 97 | * b->tag = 0; 98 | * and flags 99 | * 100 | */ 101 | 102 | b->pos = p; 103 | b->last = p; 104 | b->temporary = 1; 105 | 106 | b->start = p; 107 | p += bufs->size; 108 | b->end = p; 109 | 110 | cl = ngx_alloc_chain_link(pool); 111 | if (cl == NULL) { 112 | return NULL; 113 | } 114 | 115 | cl->buf = b; 116 | *ll = cl; 117 | ll = &cl->next; 118 | } 119 | 120 | *ll = NULL; 121 | 122 | return chain; 123 | } 124 | 125 | 126 | ngx_int_t 127 | ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) 128 | { 129 | ngx_chain_t *cl, **ll; 130 | 131 | ll = chain; 132 | 133 | for (cl = *chain; cl; cl = cl->next) { 134 | ll = &cl->next; 135 | } 136 | 137 | while (in) { 138 | cl = ngx_alloc_chain_link(pool); 139 | if (cl == NULL) { 140 | return NGX_ERROR; 141 | } 142 | 143 | cl->buf = in->buf; 144 | *ll = cl; 145 | ll = &cl->next; 146 | in = in->next; 147 | } 148 | 149 | *ll = NULL; 150 | 151 | return NGX_OK; 152 | } 153 | 154 | 155 | ngx_chain_t * 156 | ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free) 157 | { 158 | ngx_chain_t *cl; 159 | 160 | if (*free) { 161 | cl = *free; 162 | *free = cl->next; 163 | cl->next = NULL; 164 | return cl; 165 | } 166 | 167 | cl = ngx_alloc_chain_link(p); 168 | if (cl == NULL) { 169 | return NULL; 170 | } 171 | 172 | cl->buf = ngx_calloc_buf(p); 173 | if (cl->buf == NULL) { 174 | return NULL; 175 | } 176 | 177 | cl->next = NULL; 178 | 179 | return cl; 180 | } 181 | 182 | 183 | void 184 | ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy, 185 | ngx_chain_t **out, ngx_buf_tag_t tag) 186 | { 187 | ngx_chain_t *cl; 188 | 189 | if (*busy == NULL) { 190 | *busy = *out; 191 | 192 | } else { 193 | for (cl = *busy; cl->next; cl = cl->next) { /* void */ } 194 | 195 | cl->next = *out; 196 | } 197 | 198 | *out = NULL; 199 | 200 | while (*busy) { 201 | cl = *busy; 202 | 203 | if (ngx_buf_size(cl->buf) != 0) { 204 | break; 205 | } 206 | 207 | if (cl->buf->tag != tag) { 208 | *busy = cl->next; 209 | ngx_free_chain(p, cl); 210 | continue; 211 | } 212 | 213 | cl->buf->pos = cl->buf->start; 214 | cl->buf->last = cl->buf->start; 215 | 216 | *busy = cl->next; 217 | cl->next = *free; 218 | *free = cl; 219 | } 220 | } 221 | 222 | 223 | off_t 224 | ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit) 225 | { 226 | off_t total, size, aligned, fprev; 227 | ngx_fd_t fd; 228 | ngx_chain_t *cl; 229 | 230 | total = 0; 231 | 232 | cl = *in; 233 | fd = cl->buf->file->fd; 234 | 235 | do { 236 | size = cl->buf->file_last - cl->buf->file_pos; 237 | 238 | if (size > limit - total) { 239 | size = limit - total; 240 | 241 | aligned = (cl->buf->file_pos + size + ngx_pagesize - 1) 242 | & ~((off_t) ngx_pagesize - 1); 243 | 244 | if (aligned <= cl->buf->file_last) { 245 | size = aligned - cl->buf->file_pos; 246 | } 247 | } 248 | 249 | total += size; 250 | fprev = cl->buf->file_pos + size; 251 | cl = cl->next; 252 | 253 | } while (cl 254 | && cl->buf->in_file 255 | && total < limit 256 | && fd == cl->buf->file->fd 257 | && fprev == cl->buf->file_pos); 258 | 259 | *in = cl; 260 | 261 | return total; 262 | } 263 | 264 | 265 | ngx_chain_t * 266 | ngx_chain_update_sent(ngx_chain_t *in, off_t sent) 267 | { 268 | off_t size; 269 | 270 | for ( /* void */ ; in; in = in->next) { 271 | 272 | if (ngx_buf_special(in->buf)) { 273 | continue; 274 | } 275 | 276 | if (sent == 0) { 277 | break; 278 | } 279 | 280 | size = ngx_buf_size(in->buf); 281 | 282 | if (sent >= size) { 283 | sent -= size; 284 | 285 | if (ngx_buf_in_memory(in->buf)) { 286 | in->buf->pos = in->buf->last; 287 | } 288 | 289 | if (in->buf->in_file) { 290 | in->buf->file_pos = in->buf->file_last; 291 | } 292 | 293 | continue; 294 | } 295 | 296 | if (ngx_buf_in_memory(in->buf)) { 297 | in->buf->pos += (size_t) sent; 298 | } 299 | 300 | if (in->buf->in_file) { 301 | in->buf->file_pos += sent; 302 | } 303 | 304 | break; 305 | } 306 | 307 | return in; 308 | } 309 | -------------------------------------------------------------------------------- /tools/outtakes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This script extracts program crashes from a dump file that was recorded with: 5 | # whatstyle.py --color on --keeptempfiles --debug popenio ... 6 | # The "--color on" is necessary so that it can be distinguished if a space character 7 | # seperates two arguments or is part of the argument itself. 8 | # 9 | # Running 'outtakes.py < dump.txt' will create nested directories like 10 | # outtakes/c_-4_396 that contain the returncode, standard input, output and error and 11 | # an eventually a configfile from the dump. 12 | # It should be sufficient to enter one of these directories and call ./callfmt.sh 13 | # to reproduce a crash. 14 | 15 | from __future__ import print_function 16 | 17 | import sys 18 | 19 | if (((sys.version_info[0] == 2) and (sys.version_info[1] < 7)) or ( 20 | (sys.version_info[0] == 3) and (sys.version_info[1] < 2))): 21 | sys.stderr.write('Error: Python 2.7 or when running on Python 3 at least Python 3.2' 22 | ' is required to run whatstyle\n') 23 | sys.exit(1) 24 | 25 | import argparse 26 | import errno 27 | import os 28 | import re 29 | import shutil 30 | try: 31 | from shlex import quote as shellquote 32 | except ImportError: 33 | from pipes import quote as shellquote 34 | 35 | from collections import Counter 36 | 37 | PY2 = sys.version_info[0] == 2 38 | PY3 = sys.version_info[0] == 3 39 | 40 | if PY2: 41 | text_type = unicode 42 | binary_type = str 43 | else: 44 | text_type = str 45 | binary_type = bytes 46 | 47 | DESTDIR = 'outtakes' 48 | 49 | HAS_FSCODEC = hasattr(os, 'fsdecode') 50 | 51 | 52 | def unistr(text, errors='strict'): 53 | if isinstance(text, text_type): 54 | return text 55 | try: 56 | return text.decode('utf-8', errors=errors) 57 | except UnicodeDecodeError: 58 | if HAS_FSCODEC: 59 | return os.fsdecode(text) 60 | raise 61 | 62 | 63 | def bytestr(text): 64 | if isinstance(text, binary_type): 65 | return text 66 | try: 67 | return text.encode('utf-8') 68 | except UnicodeEncodeError: 69 | if HAS_FSCODEC: 70 | return os.fsencode(text) 71 | raise 72 | 73 | 74 | def rawstream(fp): 75 | if PY3: 76 | try: 77 | return fp.buffer 78 | except AttributeError: 79 | # There might be a BytesIO behind fp. 80 | pass 81 | return fp 82 | 83 | 84 | def write(s, fp=None): 85 | """Write s to the binary stream fp (default is stdout). 86 | """ 87 | efp = fp if fp is not None else sys.stdout 88 | rawstream(efp).write(bytestr(s)) 89 | 90 | 91 | def outline(s=b'', end=b'\n', fp=None): 92 | write(bytestr(s) + bytestr(end), fp=fp) 93 | 94 | 95 | re_ansi = re.compile(br'\x1b\[(?:\d*(?:;\d+)*)m') 96 | 97 | 98 | def extract_outtakes(filename, maxpercode=0): 99 | re_lengths = re.compile(br'debug_popen: len\(stdin\):(\d+) => returncode:(-?\d+)' 100 | br' len\(stdout\):(\d+) len\(stderr\):(\d+)') 101 | valid_retcodes = set(range(100)) 102 | retcounters = Counter() 103 | with open(filename, 'rb') as fp: 104 | count = 0 105 | cfgfile = None 106 | command = None 107 | while True: 108 | line = fp.readline() 109 | if not line: 110 | break 111 | prefix = b'debug_popen: ' 112 | m = re_lengths.match(line) 113 | if m: 114 | lin, retcode, lout, lerr = [int(x) for x in m.groups()] 115 | if retcode in valid_retcodes: 116 | continue 117 | if 1 <= maxpercode <= retcounters[retcode]: 118 | continue 119 | retcounters[retcode] += 1 120 | otdir = os.path.join(DESTDIR, "c_%s_%s" % (str(retcode), str(count))) 121 | try: 122 | os.makedirs(otdir) 123 | except OSError as exc: 124 | if exc.errno != errno.EEXIST: 125 | raise 126 | if command: 127 | fname = os.path.join(otdir, 'callfmt.sh') 128 | with open(fname, 'wb') as cfg: 129 | if lin > 0: 130 | command = command + b' < stdin.txt' 131 | cfg.write(command + b'\n') 132 | os.chmod(fname, 0o755) 133 | command = None 134 | with open(os.path.join(otdir, 'retcode.txt'), 'wb') as cfg: 135 | cfg.write(bytestr(str(retcode)) + b'\n') 136 | if cfgfile: 137 | shutil.copyfile(cfgfile, os.path.join(otdir, os.path.basename(cfgfile))) 138 | cfgfile = None 139 | for chan, chanlen in zip(['stdin', 'stdout', 'stderr'], [lin, lout, lerr]): 140 | if chanlen == 0: 141 | continue 142 | line = fp.readline() 143 | if line == b'debug_popenio: ' + bytestr(chan) + b':"""\\\n': 144 | data = fp.read(chanlen) 145 | with open(os.path.join(otdir, '%s.txt' % chan), 'wb') as cfp: 146 | cfp.write(data) 147 | fp.readline() # This should be """ 148 | elif line.startswith(prefix): 149 | line = line[len(prefix):] 150 | line = line.rstrip(b'\r\n') 151 | args = re_ansi.split(line) 152 | cmdargs = [] 153 | if len(args) > 1 and not args[0] and not args[-1]: 154 | for idx, arg in enumerate(args[1:-1]): 155 | if idx % 2 == 1: 156 | if arg == b' ': 157 | continue 158 | else: 159 | write(b"Unexpected debug_popen line: " + line, fp=sys.stderr) 160 | uarg = arg.decode('raw-unicode-escape') 161 | if idx > 0 and os.path.abspath(arg) and os.path.isfile(arg): 162 | cfgfile = uarg 163 | uarg = os.path.basename(uarg) 164 | cmdargs.append(shellquote(uarg).encode('raw-unicode-escape')) 165 | if cmdargs: 166 | command = b' '.join(cmdargs) 167 | count += 1 168 | return 0 169 | 170 | 171 | def main(): 172 | parser = argparse.ArgumentParser(description='Extract data from formatter crashes') 173 | parser.add_argument('filename', help='input dump filename') 174 | parser.add_argument('--maxpercode', 175 | type=int, 176 | default=-1, 177 | help='only extract this many calls per returncode\n' 178 | ' 0 means unlimited (default: 10)') 179 | args = parser.parse_args() 180 | 181 | if not args.filename: 182 | parser.error('Please specify the input dump filename') 183 | 184 | return extract_outtakes(args.filename, maxpercode=args.maxpercode) 185 | 186 | 187 | if __name__ == '__main__': 188 | sys.exit(main()) 189 | -------------------------------------------------------------------------------- /tools/show3diffs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This script opens a 3-way file comparison of files of which one is pulled out of git. 5 | # 6 | # If for example the argument is 7 | # tests/examples/foundation6/result_tidy/index.html, then: 8 | # 9 | # 1) tests/examples/foundation6/index.html is the basefile, 10 | # 2) the latest version of the argument in git is the second file to compare and 11 | # 3) the argument itself is the third file to compare. 12 | # 13 | # The option '--results' opens diffs for all modified source code result files. 14 | # 15 | # The results from test_examples.py are present in the git repo. 16 | # When changing formatters, algorithms or diff metrics we can run remove_resultdirs.py 17 | # and then test_examples.py. 18 | # Then we can use this script to get an overview if the changes have influenced the 19 | # reformatted source code test files for better or worse by looking at the 3-way diff 20 | # between the original source, the previous test result and the new test result. 21 | # The merge conflict hunks show how the test results differ in context with the original. 22 | 23 | from __future__ import print_function 24 | 25 | import sys 26 | 27 | if (((sys.version_info[0] == 2) and (sys.version_info[1] < 7)) or ( 28 | (sys.version_info[0] == 3) and (sys.version_info[1] < 2))): 29 | sys.stderr.write('Error: Python 2.7 or when running on Python 3 at least Python 3.2' 30 | ' is required to run whatstyle\n') 31 | sys.exit(1) 32 | 33 | import argparse 34 | import threading 35 | import os 36 | import subprocess 37 | import tempfile 38 | 39 | from collections import namedtuple 40 | from os.path import abspath, dirname, basename, join 41 | 42 | DIFF3_VARNAME = 'WHATSTYLE_DIFF3' 43 | 44 | PY2 = sys.version_info[0] == 2 45 | PY3 = sys.version_info[0] == 3 46 | 47 | if PY2: 48 | text_type = unicode 49 | binary_type = str 50 | else: 51 | text_type = str 52 | binary_type = bytes 53 | 54 | 55 | def unistr(text): 56 | if not isinstance(text, text_type): 57 | text = text.decode('utf-8') 58 | return text 59 | 60 | 61 | def bytestr(text): 62 | if not isinstance(text, binary_type): 63 | text = text.encode('utf-8') 64 | return text 65 | 66 | 67 | def sysfilename(filename): 68 | if not isinstance(filename, text_type): 69 | return filename 70 | try: 71 | return filename.encode(sys.getfilesystemencoding()) 72 | except UnicodeEncodeError: 73 | return filename.encode('utf-8') 74 | 75 | 76 | ExeResult = namedtuple('ExeResult', ['returncode', 'stdout', 'stderr']) 77 | 78 | 79 | def call_executable(executable, cmdargs): 80 | cmdargs = [sysfilename(x) for x in cmdargs] 81 | subprocess.call([executable] + cmdargs) 82 | 83 | 84 | def run_executable(executable, cmdargs, stdindata=None): 85 | cmdargs = [sysfilename(x) for x in cmdargs] 86 | proc = subprocess.Popen([executable] + cmdargs, 87 | stdin=subprocess.PIPE, 88 | stdout=subprocess.PIPE, 89 | stderr=subprocess.PIPE) 90 | stdout, stderr = proc.communicate(input=stdindata) 91 | return ExeResult(proc.returncode, stdout, stderr) 92 | 93 | 94 | def gitcmd(cmdargs): 95 | return run_executable('git', cmdargs) 96 | 97 | 98 | def gitcat(cwd, commit, filename): 99 | """Returns the file content for a commit. 100 | """ 101 | ret, stdout, stderr = gitcmd(['-C', cwd, 'show', '%s:%s' % (commit, unistr(filename))]) 102 | return stdout 103 | 104 | 105 | def git_commits(cwd, relpath): 106 | """Return a list of commit hashes for relpath sorted from newest to oldest. 107 | """ 108 | ret, stdout, stderr = gitcmd(['-C', cwd, 'log', '--pretty=oneline', relpath]) 109 | lines = unistr(stdout).splitlines() 110 | return list([l.split()[0] for l in lines]) 111 | 112 | 113 | def open_for_filename(tool, filename): 114 | """Creates a temporary file from a git revision of a result file and runs the diff 115 | tool with it and the parent and other sibling file. 116 | """ 117 | base = basename(filename) 118 | parts = [base] 119 | workdir = dirname(filename) 120 | firstworkdir = workdir 121 | prev = None 122 | while workdir and workdir != prev: 123 | if os.path.isdir(join(workdir, b'.git')): 124 | break 125 | parts.insert(0, basename(workdir)) 126 | prev = workdir 127 | workdir = dirname(workdir) 128 | else: 129 | print('error: did not find .git in %s or its parent directories' % firstworkdir) 130 | return 2 131 | 132 | relpath = bytestr(os.sep).join(parts) 133 | commits = git_commits(workdir, relpath) 134 | content = gitcat(workdir, commits[0], relpath) 135 | td = sysfilename(tempfile.gettempdir()) 136 | tmpfile = os.path.join(td, b'whatstyle_3gdiff_' + base) 137 | with open(tmpfile, 'wb') as fp: 138 | fp.write(content) 139 | 140 | file1 = join(dirname(dirname(filename)), base) 141 | file2 = tmpfile 142 | file3 = filename 143 | 144 | t = threading.Thread(target=call_executable, args=[tool, [file1, file2, file3]]) 145 | t.start() 146 | return t 147 | 148 | 149 | def modified_results(tool): 150 | workdir = dirname(dirname(abspath(__file__))) 151 | exeresult = run_executable('git', ['-C', workdir, 'ls-files', '-z', '-m', 152 | 'tests/examples/*/result_*']) 153 | files = exeresult.stdout.split(b'\x00') 154 | ignoreexts = bytestr('.cfg .cfg_diff .conf .pro .pro_diff .txt').split() 155 | result_filenames = [] 156 | for f in files: 157 | if not f: 158 | continue 159 | filename = join(bytestr(workdir), f) 160 | _, ext = os.path.splitext(filename) 161 | if not ext or ext in ignoreexts: 162 | continue 163 | if not os.path.exists(filename): 164 | continue 165 | result_filenames.append(filename) 166 | diff_for_files(tool, result_filenames) 167 | 168 | 169 | def diff_for_files(tool, filenames): 170 | threads = [open_for_filename(tool, f) for f in filenames] 171 | for t in threads: 172 | t.join() 173 | 174 | 175 | def main(): 176 | parser = argparse.ArgumentParser(description='Open a diff tool with three files') 177 | parser.add_argument('filename', nargs='*', help='input filename') 178 | # The info and debug options were inspired by rsync. 179 | parser.add_argument('--tool', help='path of diff tool') 180 | parser.add_argument('--results', action='store_true', help='show results diffs') 181 | 182 | args = parser.parse_args() 183 | tool = args.tool 184 | if tool is None: 185 | tool = os.environ.get(DIFF3_VARNAME) 186 | if tool is None: 187 | parser.error('Please specify the 3-way file comparison tool with --tool or set %s' % 188 | DIFF3_VARNAME) 189 | if args.results: 190 | return modified_results(tool) 191 | filenames = args.filename 192 | if not filenames: 193 | parser.error('Please specify at least one source file') 194 | 195 | filenames = [os.path.abspath(f) for f in filenames] 196 | diff_for_files(tool, filenames) 197 | return 0 198 | 199 | 200 | if __name__ == '__main__': 201 | sys.exit(main()) 202 | -------------------------------------------------------------------------------- /tests/examples/foundation6/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Foundation | Welcome 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |

Welcome to Foundation for Sites 6

16 |
17 |
18 | 19 |
20 |
21 |
22 |

We’re stoked you want to try Foundation!

23 |

To get going, this file (index.html) includes some basic styles you can modify, play around with, or totally destroy to get going.

24 |

Once you've exhausted the fun in this document, you should check out:

25 |
26 |
27 |

Foundation Documentation
Everything you need to know about using the framework.

28 |
29 |
30 |

Foundation Code Skills
These online courses offer you a chance to better understand how Foundation works and how you can master it to create awesome projects.

31 |
32 |
33 |

Foundation Forum
Join the Foundation community to ask a question or show off your knowlege.

34 |
35 |
36 |
37 |
38 |

Foundation on Github
Latest code, issue reports, feature requests and more.

39 |
40 |
41 |

@zurbfoundation
Ping us on Twitter if you have questions. When you build something with this we'd love to see it (and send you a totally boss sticker).

42 |
43 |
44 |
45 |
46 |
47 | 48 |
49 |
50 |
Here’s your basic grid:
51 | 52 | 53 |
54 |
55 |
56 |

This is a twelve column section in a row. Each of these includes a div.callout element so you can see where the columns are - it's not required at all for the grid.

57 |
58 |
59 |
60 |
61 |
62 |
63 |

Six columns

64 |
65 |
66 |
67 |
68 |

Six columns

69 |
70 |
71 |
72 |
73 |
74 |
75 |

Four columns

76 |
77 |
78 |
79 |
80 |

Four columns

81 |
82 |
83 |
84 |
85 |

Four columns

86 |
87 |
88 |
89 | 90 |
91 | 92 |
We bet you’ll need a form somewhere:
93 |
94 |
95 |
96 | 97 | 98 |
99 |
100 |
101 |
102 | 103 | 104 |
105 |
106 | 107 | 108 |
109 |
110 | 111 |
112 | 113 | .com 114 |
115 |
116 |
117 |
118 |
119 | 120 | 126 |
127 |
128 |
129 |
130 | 131 | 132 | 133 |
134 |
135 | 136 | 137 | 138 |
139 |
140 |
141 |
142 | 143 | 144 |
145 |
146 |
147 |
148 | 149 |
150 |
Try one of these buttons:
151 |

Simple Button
152 | Success Button
153 | Alert Button
154 | Warning Button
155 | Secondary Button

156 |
157 |
So many components, girl!
158 |

A whole kitchen sink of goodies comes with Foundation. Check out the docs to see them all, along with details on making them your own.

159 | Go to Foundation Docs 160 |
161 |
162 |
163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /tests/examples/lua/lstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.h,v 2.128 2015/11/13 12:16:51 roberto Exp $ 3 | ** Global State 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstate_h 8 | #define lstate_h 9 | 10 | #include "lua.h" 11 | 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | #include "lzio.h" 15 | 16 | 17 | /* 18 | 19 | ** Some notes about garbage-collected objects: All objects in Lua must 20 | ** be kept somehow accessible until being freed, so all objects always 21 | ** belong to one (and only one) of these lists, using field 'next' of 22 | ** the 'CommonHeader' for the link: 23 | ** 24 | ** 'allgc': all objects not marked for finalization; 25 | ** 'finobj': all objects marked for finalization; 26 | ** 'tobefnz': all objects ready to be finalized; 27 | ** 'fixedgc': all objects that are not to be collected (currently 28 | ** only small strings, such as reserved words). 29 | 30 | */ 31 | 32 | 33 | struct lua_longjmp; /* defined in ldo.c */ 34 | 35 | 36 | 37 | /* extra stack space to handle TM calls and some other extras */ 38 | #define EXTRA_STACK 5 39 | 40 | 41 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) 42 | 43 | 44 | /* kinds of Garbage Collection */ 45 | #define KGC_NORMAL 0 46 | #define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */ 47 | 48 | 49 | typedef struct stringtable { 50 | TString **hash; 51 | int nuse; /* number of elements */ 52 | int size; 53 | } stringtable; 54 | 55 | 56 | /* 57 | ** Information about a call. 58 | ** When a thread yields, 'func' is adjusted to pretend that the 59 | ** top function has only the yielded values in its stack; in that 60 | ** case, the actual 'func' value is saved in field 'extra'. 61 | ** When a function calls another with a continuation, 'extra' keeps 62 | ** the function index so that, in case of errors, the continuation 63 | ** function can be called with the correct top. 64 | */ 65 | typedef struct CallInfo { 66 | StkId func; /* function index in the stack */ 67 | StkId top; /* top for this function */ 68 | struct CallInfo *previous, *next; /* dynamic call link */ 69 | union { 70 | struct { /* only for Lua functions */ 71 | StkId base; /* base for this function */ 72 | const Instruction *savedpc; 73 | } l; 74 | struct { /* only for C functions */ 75 | lua_KFunction k; /* continuation in case of yields */ 76 | ptrdiff_t old_errfunc; 77 | lua_KContext ctx; /* context info. in case of yields */ 78 | } c; 79 | } u; 80 | ptrdiff_t extra; 81 | short nresults; /* expected number of results from this function */ 82 | lu_byte callstatus; 83 | } CallInfo; 84 | 85 | 86 | /* 87 | ** Bits in CallInfo status 88 | */ 89 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ 90 | #define CIST_LUA (1<<1) /* call is running a Lua function */ 91 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ 92 | #define CIST_FRESH (1<<3) /* call is running on a fresh invocation 93 | of luaV_execute */ 94 | #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ 95 | #define CIST_TAIL (1<<5) /* call was tail called */ 96 | #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ 97 | #define CIST_LEQ (1<<7) /* using __lt for __le */ 98 | 99 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) 100 | 101 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ 102 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) 103 | #define getoah(st) ((st) & CIST_OAH) 104 | 105 | 106 | /* 107 | ** 'global state', shared by all threads of this state 108 | */ 109 | typedef struct global_State { 110 | lua_Alloc frealloc; /* function to reallocate memory */ 111 | void *ud; /* auxiliary data to 'frealloc' */ 112 | l_mem totalbytes; /* number of bytes currently allocated - GCdebt */ 113 | l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ 114 | lu_mem GCmemtrav; /* memory traversed by the GC */ 115 | lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ 116 | stringtable strt; /* hash table for strings */ 117 | TValue l_registry; 118 | unsigned int seed; /* randomized seed for hashes */ 119 | lu_byte currentwhite; 120 | lu_byte gcstate; /* state of garbage collector */ 121 | lu_byte gckind; /* kind of GC running */ 122 | lu_byte gcrunning; /* true if GC is running */ 123 | GCObject *allgc; /* list of all collectable objects */ 124 | GCObject **sweepgc; /* current position of sweep in list */ 125 | GCObject *finobj; /* list of collectable objects with finalizers */ 126 | GCObject *gray; /* list of gray objects */ 127 | GCObject *grayagain; /* list of objects to be traversed atomically */ 128 | GCObject *weak; /* list of tables with weak values */ 129 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ 130 | GCObject *allweak; /* list of all-weak tables */ 131 | GCObject *tobefnz; /* list of userdata to be GC */ 132 | GCObject *fixedgc; /* list of objects not to be collected */ 133 | struct lua_State *twups; /* list of threads with open upvalues */ 134 | unsigned int gcfinnum; /* number of finalizers to call in each GC step */ 135 | int gcpause; /* size of pause between successive GCs */ 136 | int gcstepmul; /* GC 'granularity' */ 137 | lua_CFunction panic; /* to be called in unprotected errors */ 138 | struct lua_State *mainthread; 139 | const lua_Number *version; /* pointer to version number */ 140 | TString *memerrmsg; /* memory-error message */ 141 | TString *tmname[TM_N]; /* array with tag-method names */ 142 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ 143 | TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ 144 | } global_State; 145 | 146 | 147 | /* 148 | ** 'per thread' state 149 | */ 150 | struct lua_State { 151 | CommonHeader; 152 | unsigned short nci; /* number of items in 'ci' list */ 153 | lu_byte status; 154 | StkId top; /* first free slot in the stack */ 155 | global_State *l_G; 156 | CallInfo *ci; /* call info for current function */ 157 | const Instruction *oldpc; /* last pc traced */ 158 | StkId stack_last; /* last free slot in the stack */ 159 | StkId stack; /* stack base */ 160 | UpVal *openupval; /* list of open upvalues in this stack */ 161 | GCObject *gclist; 162 | struct lua_State *twups; /* list of threads with open upvalues */ 163 | struct lua_longjmp *errorJmp; /* current error recover point */ 164 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ 165 | lua_Hook hook; 166 | ptrdiff_t errfunc; /* current error handling function (stack index) */ 167 | int stacksize; 168 | int basehookcount; 169 | int hookcount; 170 | unsigned short nny; /* number of non-yieldable calls in stack */ 171 | unsigned short nCcalls; /* number of nested C calls */ 172 | lu_byte hookmask; 173 | lu_byte allowhook; 174 | }; 175 | 176 | 177 | #define G(L) (L->l_G) 178 | 179 | 180 | /* 181 | ** Union of all collectable objects (only for conversions) 182 | */ 183 | union GCUnion { 184 | GCObject gc; /* common header */ 185 | struct TString ts; 186 | struct Udata u; 187 | union Closure cl; 188 | struct Table h; 189 | struct Proto p; 190 | struct lua_State th; /* thread */ 191 | }; 192 | 193 | 194 | #define cast_u(o) cast(union GCUnion *, (o)) 195 | 196 | /* macros to convert a GCObject into a specific value */ 197 | #define gco2ts(o) \ 198 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) 199 | #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) 200 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) 201 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) 202 | #define gco2cl(o) \ 203 | check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) 204 | #define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h)) 205 | #define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p)) 206 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) 207 | 208 | 209 | /* macro to convert a Lua object into a GCObject */ 210 | #define obj2gco(v) \ 211 | check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc))) 212 | 213 | 214 | /* actual number of total bytes allocated */ 215 | #define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt) 216 | 217 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); 218 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 219 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 220 | LUAI_FUNC void luaE_freeCI (lua_State *L); 221 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); 222 | 223 | 224 | #endif 225 | 226 | --------------------------------------------------------------------------------