1/* $NetBSD: ps_ind_level.c,v 1.9 2023/06/15 09:19:07 rillig Exp $ */ 2 3/* 4 * The indentation of the very first line of a file determines the 5 * indentation of the remaining code. This mode is meant for code snippets from 6 * function bodies. At this level, function definitions are not recognized 7 * properly. 8 * 9 * Even if later code has a smaller indentation, it is nevertheless indented to 10 * the level given by the first line of code. 11 * 12 * In this particular test, the indentation is set to 5 and the tabulator 13 * width is set to 8, to demonstrate an off-by-one error in 14 * main_prepare_parsing that has been fixed in indent.c 1.107 from 2021-10-05. 15 * 16 * The declaration in the first line is indented by 3 tabs, amounting to 24 17 * spaces. The initial indentation of the code is intended to be rounded down, 18 * to 4 levels of indentation, amounting to 20 spaces. 19 */ 20//indent input 21 int indented_by_24; 22 23void function_in_column_1(void){} 24 25 #if indented 26#endif 27//indent end 28 29/* 5 spaces indentation, 8 spaces per tabulator */ 30//indent run -i5 -ts8 31 int indented_by_24; 32 33 void function_in_column_1(void) { 34 } 35 36#if indented 37#endif 38//indent end 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 49void function(void) { 50label:; 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 65int level_0; 66{ 67int level_1; 68{ 69int level_2; 70{ 71int level_3; 72{ 73int 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 85int 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 105int 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 120 121/* 122 * Having function definitions indented to the right is not supported. In that 123 * case, indent does not recognize it as a function definition, and it doesn't 124 * indent the old-style parameter declarations one level further to the right. 125 */ 126//indent input 127 int old_style(a) 128 int a; 129 { 130 } 131//indent end 132 133//indent run-equals-input 134