opt_bacc.c revision 1.12
1/* $NetBSD: opt_bacc.c,v 1.12 2023/05/20 10:09:03 rillig Exp $ */
2
3/*
4 * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional
5 * compilation").
6 *
7 * The option '-bacc' forces a blank line around every conditional compilation
8 * block.  For example, in front of every #ifdef and after every #endif.
9 * Other blank lines surrounding such blocks are swallowed.
10 *
11 * The option '-nbacc' leaves the vertical spacing as-is.
12 */
13
14
15/* Example code without surrounding blank lines. */
16//indent input
17int		a;
18#if 0
19int		b;
20#endif
21int		c;
22//indent end
23
24//indent run -bacc
25int		a;
26
27#if 0
28int		b;
29#endif
30
31int		c;
32//indent end
33
34/* The option '-nbacc' does not remove anything. */
35//indent run-equals-input -nbacc
36
37
38/* Example code containing blank lines. */
39//indent input
40int		space_a;
41
42#if 0
43
44int		space_b;
45
46#endif
47
48int		space_c;
49//indent end
50
51//indent run-equals-input -bacc
52
53/* The option '-nbacc' does not remove anything. */
54//indent run-equals-input -nbacc
55
56
57/*
58 * Preprocessing directives can also occur in function bodies.
59 */
60//indent input
61const char *
62os_name(void)
63{
64#if defined(__NetBSD__) || defined(__FreeBSD__)
65	return "BSD";
66#else
67	return "unknown";
68#endif
69}
70//indent end
71
72//indent run -bacc
73const char *
74os_name(void)
75{
76
77#if defined(__NetBSD__) || defined(__FreeBSD__)
78	return "BSD";
79#else
80	return "unknown";
81#endif
82
83}
84//indent end
85
86//indent run-equals-input -nbacc
87
88
89/*
90 * Test nested preprocessor directives.
91 */
92//indent input
93#if outer
94#if inner
95int decl;
96#endif
97#endif
98//indent end
99
100//indent run-equals-input -di0 -bacc
101
102//indent run-equals-input -di0 -nbacc
103
104
105/*
106 * Test nested preprocessor directives that are interleaved with declarations.
107 */
108//indent input
109#ifdef outer
110int outer_above;
111#ifdef inner
112int inner;
113#endif
114int outer_below;
115#endif
116//indent end
117
118//indent run -di0 -bacc
119#ifdef outer
120int outer_above;
121
122#ifdef inner
123int inner;
124#endif
125
126int outer_below;
127#endif
128//indent end
129
130//indent run-equals-input -di0 -nbacc
131