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