11.9Srillig/* $NetBSD: ps_ind_level.c,v 1.9 2023/06/15 09:19:07 rillig Exp $ */ 21.1Srillig 31.1Srillig/* 41.1Srillig * The indentation of the very first line of a file determines the 51.8Srillig * indentation of the remaining code. This mode is meant for code snippets from 61.8Srillig * function bodies. At this level, function definitions are not recognized 71.8Srillig * properly. 81.8Srillig * 91.8Srillig * Even if later code has a smaller indentation, it is nevertheless indented to 101.8Srillig * the level given by the first line of code. 111.1Srillig * 121.1Srillig * In this particular test, the indentation is set to 5 and the tabulator 131.1Srillig * width is set to 8, to demonstrate an off-by-one error in 141.1Srillig * main_prepare_parsing that has been fixed in indent.c 1.107 from 2021-10-05. 151.1Srillig * 161.1Srillig * The declaration in the first line is indented by 3 tabs, amounting to 24 171.1Srillig * spaces. The initial indentation of the code is intended to be rounded down, 181.1Srillig * to 4 levels of indentation, amounting to 20 spaces. 191.1Srillig */ 201.6Srillig//indent input 211.3Srillig int indented_by_24; 221.1Srillig 231.1Srilligvoid function_in_column_1(void){} 241.8Srillig 251.8Srillig #if indented 261.8Srillig#endif 271.6Srillig//indent end 281.1Srillig 291.1Srillig/* 5 spaces indentation, 8 spaces per tabulator */ 301.6Srillig//indent run -i5 -ts8 311.3Srillig int indented_by_24; 321.1Srillig 331.7Srillig void function_in_column_1(void) { 341.1Srillig } 351.8Srillig 361.8Srillig#if indented 371.8Srillig#endif 381.6Srillig//indent end 391.1Srillig 401.1Srillig 411.1Srillig/* 421.1Srillig * Labels are always indented 2 levels left of the code. The first line starts 431.1Srillig * at indentation level 3, the code in the function is therefore at level 4, 441.1Srillig * and the label is at level 2, sticking out of the code. 451.1Srillig */ 461.6Srillig//indent input 471.1Srillig int indent_by_24; 481.1Srillig 491.1Srilligvoid function(void) { 501.1Srilliglabel:; 511.1Srillig} 521.6Srillig//indent end 531.1Srillig 541.6Srillig//indent run -i8 -ts8 -di0 551.1Srillig int indent_by_24; 561.1Srillig 571.7Srillig void function(void) { 581.1Srillig label: ; 591.1Srillig } 601.6Srillig//indent end 611.2Srillig 621.2Srillig 631.2Srillig/* Test the indentation computation in code_add_decl_indent. */ 641.6Srillig//indent input 651.2Srilligint level_0; 661.2Srillig{ 671.2Srilligint level_1; 681.2Srillig{ 691.2Srilligint level_2; 701.2Srillig{ 711.2Srilligint level_3; 721.2Srillig{ 731.2Srilligint level_4; 741.2Srillig} 751.2Srillig} 761.2Srillig} 771.2Srillig} 781.6Srillig//indent end 791.2Srillig 801.2Srillig/* 811.2Srillig * The variables are indented by 16, 21, 26, 31, 36. 821.2Srillig * The variables end up in columns 17, 22, 27, 32, 37. 831.2Srillig */ 841.6Srillig//indent run -i5 -ts8 -di16 -ldi16 851.2Srilligint level_0; 861.2Srillig{ 871.2Srillig int level_1; 881.2Srillig { 891.2Srillig int level_2; 901.2Srillig { 911.2Srillig int level_3; 921.2Srillig { 931.2Srillig int level_4; 941.2Srillig } 951.2Srillig } 961.2Srillig } 971.2Srillig} 981.6Srillig//indent end 991.2Srillig 1001.2Srillig/* 1011.2Srillig * The variables are indented by 7, 12, 17, 22, 27. 1021.2Srillig * The variables end up in columns 8, 13, 18, 23, 28. 1031.2Srillig */ 1041.6Srillig//indent run -i5 -ts8 -di7 -ldi7 1051.2Srilligint level_0; 1061.2Srillig{ 1071.2Srillig int level_1; 1081.2Srillig { 1091.2Srillig int level_2; 1101.2Srillig { 1111.2Srillig int level_3; 1121.2Srillig { 1131.2Srillig int level_4; 1141.2Srillig } 1151.2Srillig } 1161.2Srillig } 1171.2Srillig} 1181.6Srillig//indent end 1191.9Srillig 1201.9Srillig 1211.9Srillig/* 1221.9Srillig * Having function definitions indented to the right is not supported. In that 1231.9Srillig * case, indent does not recognize it as a function definition, and it doesn't 1241.9Srillig * indent the old-style parameter declarations one level further to the right. 1251.9Srillig */ 1261.9Srillig//indent input 1271.9Srillig int old_style(a) 1281.9Srillig int a; 1291.9Srillig { 1301.9Srillig } 1311.9Srillig//indent end 1321.9Srillig 1331.9Srillig//indent run-equals-input 134