xref: /netbsd-src/tests/usr.bin/indent/opt_psl.c (revision 47306038c7d906b62edca1fd252c0e0d0772f5a0)
1 /* $NetBSD: opt_psl.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the options '-psl' and '-npsl' ("procedure definition in separate
5  * line").
6  *
7  * The option '-psl' starts a new line for the function name in a function
8  * definition.
9  *
10  * The option '-npsl' puts the function name in the same line as its return
11  * type.
12  */
13 
14 /* Single-line function declarations are not affected by these options. */
15 //indent input
16 void function_declaration(void);
17 //indent end
18 
19 //indent run -psl
20 void		function_declaration(void);
21 //indent end
22 
23 //indent run-equals-prev-output -npsl
24 
25 
26 /*
27  * Multi-line function declarations are affected by these options since indent
28  * wrongly assumes they were function definitions, not declarations.
29  *
30  * Before 1990, when C90 added function prototypes, this case was rare since
31  * function definitions consisted only of the return type (defaulting to
32  * 'int'), the function name and the list of parameter names, without
33  * parameter types or type qualifiers like 'const'.
34  */
35 //indent input
36 void function_declaration(
37 void);
38 //indent end
39 
40 //indent run -psl
41 void
42 function_declaration(
43 		     void);
44 //indent end
45 
46 /*
47  * In a function definition (which indent wrongly assumes here), in contrast
48  * to a declaration, the function name is not indented to column 17.
49  */
50 //indent run -npsl
51 void function_declaration(
52 			  void);
53 //indent end
54 
55 
56 /*
57  * In a function definition, in contrast to a declaration, the function name
58  * is not indented to column 17 since the other function definitions are too
59  * far away.
60  */
61 //indent input
function_definition(void)62 void function_definition(void) {}
63 //indent end
64 
65 //indent run -psl
66 void
function_definition(void)67 function_definition(void)
68 {
69 }
70 //indent end
71 
72 //indent run -npsl
function_definition(void)73 void function_definition(void)
74 {
75 }
76 //indent end
77