Home | History | Annotate | Line # | Download | only in indent
opt_ci.c revision 1.6
      1 /* $NetBSD: opt_ci.c,v 1.6 2022/04/22 21:21:20 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the option '-ci', which controls the indentation of continuation
      5  * lines in statements and declarations, but only inside a function.
      6  */
      7 
      8 /*
      9  * Top level expressions with and without parentheses.
     10  */
     11 #indent input
     12 int top_level = 1 +
     13  2;
     14 int top_level = (1 +
     15  2 + (
     16   3));
     17 #indent end
     18 
     19 #indent run -ci0
     20 int		top_level = 1 +
     21 2;
     22 int		top_level = (1 +
     23 			     2 + (
     24 				  3));
     25 #indent end
     26 #indent run-equals-prev-output -ci2
     27 #indent run-equals-prev-output -ci4
     28 #indent run-equals-prev-output -ci8
     29 
     30 #indent run -ci0 -nlp
     31 int		top_level = 1 +
     32 2;
     33 int		top_level = (1 +
     34 	2 + (
     35 		3));
     36 #indent end
     37 
     38 #indent run -ci2 -nlp
     39 int		top_level = 1 +
     40 2;
     41 int		top_level = (1 +
     42   2 + (
     43     3));
     44 #indent end
     45 
     46 /*
     47  * Since '-ci4' is half an indentation level, indent all continuations using
     48  * the same level, no matter how many parentheses there are. The rationale for
     49  * this may have been to prevent that the continuation line has the same
     50  * indentation as a follow-up statement, such as in 'if' statements.
     51  */
     52 #indent run -ci4 -nlp
     53 int		top_level = 1 +
     54 2;
     55 int		top_level = (1 +
     56     2 + (
     57     3));
     58 #indent end
     59 
     60 
     61 /*
     62  * Declarations in functions without parentheses.
     63  */
     64 #indent input
     65 int
     66 sum(int a, int b)
     67 {
     68 	return a +
     69 	 b;
     70 	return first +
     71 	 second;
     72 }
     73 #indent end
     74 
     75 #indent run -ci0
     76 int
     77 sum(int a, int b)
     78 {
     79 	return a +
     80 		b;
     81 	return first +
     82 		second;
     83 }
     84 #indent end
     85 
     86 #indent run -ci2
     87 int
     88 sum(int a, int b)
     89 {
     90 	return a +
     91 	  b;
     92 	return first +
     93 	  second;
     94 }
     95 #indent end
     96 
     97 #indent run -ci4
     98 int
     99 sum(int a, int b)
    100 {
    101 	return a +
    102 	    b;
    103 	return first +
    104 	    second;
    105 }
    106 #indent end
    107 
    108 #indent run -ci8
    109 int
    110 sum(int a, int b)
    111 {
    112 	return a +
    113 		b;
    114 	return first +
    115 		second;
    116 }
    117 #indent end
    118 
    119 
    120 /*
    121  * Continued statements with expressions in parentheses.
    122  */
    123 #indent input
    124 int
    125 sum(int a, int b)
    126 {
    127 	return (a +
    128 	b);
    129 	return (first +
    130 	second + (
    131 	third));
    132 }
    133 #indent end
    134 
    135 #indent run -ci0
    136 int
    137 sum(int a, int b)
    138 {
    139 	return (a +
    140 		b);
    141 	return (first +
    142 		second + (
    143 			  third));
    144 }
    145 #indent end
    146 #indent run-equals-prev-output -ci2
    147 #indent run-equals-prev-output -ci4
    148 #indent run-equals-prev-output -ci8
    149 
    150 #indent run -ci2 -nlp
    151 int
    152 sum(int a, int b)
    153 {
    154 	return (a +
    155 	  b);
    156 	return (first +
    157 	  second + (
    158 	    third));
    159 }
    160 #indent end
    161 
    162 /*
    163  * Since '-ci4' is half an indentation level, indent all continuations using
    164  * the same level, no matter how many parentheses there are. The rationale for
    165  * this may have been to prevent that the continuation line has the same
    166  * indentation as a follow-up statement, such as in 'if' statements.
    167  */
    168 #indent run -ci4 -nlp
    169 int
    170 sum(int a, int b)
    171 {
    172 	return (a +
    173 	    b);
    174 	return (first +
    175 	    second + (
    176 	    third));
    177 }
    178 #indent end
    179 
    180 #indent run -ci8 -nlp
    181 int
    182 sum(int a, int b)
    183 {
    184 	return (a +
    185 		b);
    186 	return (first +
    187 		second + (
    188 			third));
    189 }
    190 #indent end
    191 
    192 
    193 /*
    194  * In the default configuration, the indentation level from '-i' is the same
    195  * as the continuation indentation from '-ci'.  The difference between these
    196  * becomes visible for structural macros like 'forever' or 'foreach'.
    197  */
    198 #indent input
    199 #define forever for (;;)
    200 void
    201 function(void)
    202 {
    203 	forever
    204 		stmt();
    205 
    206 	forever {
    207 		stmt();
    208 	}
    209 }
    210 #indent end
    211 
    212 #indent run-equals-input
    213 
    214 /*
    215  * The difference between the block indentation and the continuation
    216  * indentation only becomes visible when these two differ.
    217  */
    218 #indent run -i8 -ci4
    219 #define forever for (;;)
    220 void
    221 function(void)
    222 {
    223 	forever
    224 	    stmt();
    225 
    226 	forever {
    227 		stmt();
    228 	}
    229 }
    230 #indent end
    231