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