opt_lp.c revision 1.9 1 /* $NetBSD: opt_lp.c,v 1.9 2023/06/08 20:36:35 rillig Exp $ */
2
3 /*
4 * Tests for the options '-lp' and '-nlp'.
5 *
6 * The option '-lp' lines up code surrounded by parentheses in continuation
7 * lines. With '-lp', if a line has a left parenthesis that is not closed on
8 * that line, continuation lines are lined up to start at the character
9 * position just after the left parenthesis.
10 *
11 * The option '-nlp' indents continuation lines with the continuation
12 * indentation; see '-ci'.
13 */
14
15 //indent input
16 void
17 example(void)
18 {
19 p1 = first_procedure(second_procedure(p2, p3),
20 third_procedure(p4, p5));
21
22 p1 = first_procedure(second_procedure(p2,
23 p3),
24 third_procedure(p4,
25 p5));
26
27 p1 = first_procedure(
28 second_procedure(p2, p3),
29 third_procedure(p4, p5));
30 }
31 //indent end
32
33 //indent run -lp
34 void
35 example(void)
36 {
37 p1 = first_procedure(second_procedure(p2, p3),
38 third_procedure(p4, p5));
39
40 p1 = first_procedure(second_procedure(p2,
41 p3),
42 third_procedure(p4,
43 p5));
44
45 p1 = first_procedure(
46 second_procedure(p2, p3),
47 third_procedure(p4, p5));
48 }
49 //indent end
50
51 //indent run -nlp
52 void
53 example(void)
54 {
55 p1 = first_procedure(second_procedure(p2, p3),
56 third_procedure(p4, p5));
57
58 p1 = first_procedure(second_procedure(p2,
59 p3),
60 third_procedure(p4,
61 p5));
62
63 p1 = first_procedure(
64 second_procedure(p2, p3),
65 third_procedure(p4, p5));
66 }
67 //indent end
68
69 /*
70 * XXX: Combining the options '-nlp' and '-ci4' is counterproductive as the
71 * indentation does not make the nesting level of the function calls visible.
72 */
73 //indent run -nlp -ci4
74 void
75 example(void)
76 {
77 p1 = first_procedure(second_procedure(p2, p3),
78 third_procedure(p4, p5));
79
80 p1 = first_procedure(second_procedure(p2,
81 p3),
82 third_procedure(p4,
83 p5));
84
85 p1 = first_procedure(
86 second_procedure(p2, p3),
87 third_procedure(p4, p5));
88 }
89 //indent end
90
91
92 /*
93 * Ensure that in multi-line else-if conditions, all lines are indented by the
94 * correct amount. The 'else if' condition is tricky because it has the same
95 * indentation as the preceding 'if' condition.
96 */
97 //indent input
98 {
99 if (cond11a
100 && cond11b
101 && cond11c) {
102 stmt11;
103 } else if (cond12a
104 && cond12b
105 && cond12c) {
106 stmt12;
107 }
108 }
109
110 {
111 if (cond21a
112 && cond21b
113 && cond21c)
114 stmt21;
115 else if (cond22a
116 && cond22b
117 && cond22c)
118 stmt22;
119 }
120 //indent end
121
122 //indent run -ci4 -nlp
123 {
124 if (cond11a
125 && cond11b
126 && cond11c) {
127 stmt11;
128 } else if (cond12a
129 && cond12b
130 && cond12c) {
131 stmt12;
132 }
133 }
134
135 {
136 if (cond21a
137 && cond21b
138 && cond21c)
139 stmt21;
140 else if (cond22a
141 && cond22b
142 && cond22c)
143 stmt22;
144 }
145 //indent end
146