1 /* $NetBSD: ps_ind_level.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */ 2 3 /* 4 * The indentation of the very first line of a file determines the 5 * indentation of the remaining code. Even if later code has a smaller 6 * indentation, it is nevertheless indented to the level given by the first 7 * line of code. 8 * 9 * In this particular test, the indentation is set to 5 and the tabulator 10 * width is set to 8, to demonstrate an off-by-one error in 11 * main_prepare_parsing that has been fixed in indent.c 1.107 from 2021-10-05. 12 * 13 * The declaration in the first line is indented by 3 tabs, amounting to 24 14 * spaces. The initial indentation of the code is intended to be rounded down, 15 * to 4 levels of indentation, amounting to 20 spaces. 16 */ 17 //indent input 18 int indented_by_24; 19 20 void function_in_column_1(void){} 21 //indent end 22 23 /* 5 spaces indentation, 8 spaces per tabulator */ 24 //indent run -i5 -ts8 25 int indented_by_24; 26 27 void function_in_column_1(void){ 28 } 29 //indent end 30 /* 31 * In the above function declaration, the space between '){' is missing. This 32 * is because the tokenizer only recognizes function definitions if they start 33 * at indentation level 0, but this declaration starts at indentation level 4, 34 * due to the indentation in line 1. It's an edge case that is probably not 35 * worth fixing. 36 * 37 * See 'in_func_def_params = true'. 38 */ 39 40 41 /* 42 * Labels are always indented 2 levels left of the code. The first line starts 43 * at indentation level 3, the code in the function is therefore at level 4, 44 * and the label is at level 2, sticking out of the code. 45 */ 46 //indent input 47 int indent_by_24; 48 49 void function(void) { 50 label:; 51 } 52 //indent end 53 54 //indent run -i8 -ts8 -di0 55 int indent_by_24; 56 57 void function(void){ 58 label: ; 59 } 60 //indent end 61 62 63 /* Test the indentation computation in code_add_decl_indent. */ 64 //indent input 65 int level_0; 66 { 67 int level_1; 68 { 69 int level_2; 70 { 71 int level_3; 72 { 73 int level_4; 74 } 75 } 76 } 77 } 78 //indent end 79 80 /* 81 * The variables are indented by 16, 21, 26, 31, 36. 82 * The variables end up in columns 17, 22, 27, 32, 37. 83 */ 84 //indent run -i5 -ts8 -di16 -ldi16 85 int level_0; 86 { 87 int level_1; 88 { 89 int level_2; 90 { 91 int level_3; 92 { 93 int level_4; 94 } 95 } 96 } 97 } 98 //indent end 99 100 /* 101 * The variables are indented by 7, 12, 17, 22, 27. 102 * The variables end up in columns 8, 13, 18, 23, 28. 103 */ 104 //indent run -i5 -ts8 -di7 -ldi7 105 int level_0; 106 { 107 int level_1; 108 { 109 int level_2; 110 { 111 int level_3; 112 { 113 int level_4; 114 } 115 } 116 } 117 } 118 //indent end 119