1 /* $NetBSD: opt_eei.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */ 2 3 /* 4 * Tests for the options '-eei' and '-neei'. 5 * 6 * The option '-eei' enables extra indentation on continuation lines of the 7 * expression part of 'if' and 'while' statements. These continuation lines 8 * are indented one extra level. 9 * 10 * The option '-neei' indents these conditions in the same way as all other 11 * continued statements. 12 */ 13 14 //indent input 15 bool 16 less(int a, int b) 17 { 18 if (a < 19 b) 20 return true; 21 if (a 22 < 23 b) 24 return true; 25 } 26 //indent end 27 28 //indent run -eei 29 bool 30 less(int a, int b) 31 { 32 if (a < 33 b) 34 return true; 35 if (a 36 < 37 b) 38 return true; 39 } 40 //indent end 41 42 //indent run-equals-input -neei 43 44 /* 45 * When a single indentation level is the same as the continuation 46 * indentation, the code does not clearly show whether the 'b' belongs to the 47 * condition or the body statement. 48 */ 49 //indent run -neei -i4 50 bool 51 less(int a, int b) 52 { 53 if (a < 54 b) 55 return true; 56 if (a 57 < 58 b) 59 return true; 60 } 61 //indent end 62 63 /* 64 * Adding the extra level of indentation is useful when the standard 65 * indentation is the same as the indentation of statement continuations. In 66 * such a case, the continued condition would have the same indentation as the 67 * following statement, which would be confusing. 68 */ 69 //indent run -eei -i4 70 bool 71 less(int a, int b) 72 { 73 if (a < 74 b) 75 return true; 76 if (a 77 < 78 b) 79 return true; 80 } 81 //indent end 82 83 /* 84 * With an indentation size of 4, the width of the code 'if (' is exactly one 85 * indentation level. With the option '-nlp', the option '-eei' has no effect. 86 * 87 * XXX: This is unexpected since this creates the exact ambiguity that the 88 * option '-eei' is supposed to prevent. 89 */ 90 //indent run -eei -i4 -nlp 91 bool 92 less(int a, int b) 93 { 94 if (a < 95 b) 96 return true; 97 if (a 98 < 99 b) 100 return true; 101 } 102 //indent end 103 104 105 /* 106 * The option '-eei' applies no matter whether the continued expression starts 107 * with a word or an operator like '&&'. The latter cannot start a statement, 108 * so there would be no ambiguity. 109 */ 110 //indent input 111 { 112 if (a 113 && b) 114 stmt(); 115 } 116 //indent end 117 118 /* 119 * XXX: The extra indentation is unnecessary since there is no possible 120 * confusion: the standard indentation is 8, the indentation of the continued 121 * condition could have stayed at 4. 122 */ 123 //indent run -eei 124 { 125 if (a 126 && b) 127 stmt(); 128 } 129 //indent end 130 131 /* 132 * The extra indentation is necessary here since otherwise the '&&' and the 133 * 'stmt()' would start at the same indentation. 134 */ 135 //indent run -eei -i4 136 { 137 if (a 138 && b) 139 stmt(); 140 } 141 //indent end 142 143 /* 144 * With an indentation size of 4, the width of the code 'if (' is exactly one 145 * indentation level. With the option '-nlp', the option '-eei' has no effect. 146 * 147 * XXX: This is unexpected since this creates the exact ambiguity that the 148 * option '-eei' is supposed to prevent. 149 */ 150 //indent run -eei -i4 -nlp 151 { 152 if (a 153 && b) 154 stmt(); 155 } 156 //indent end 157