Home | History | Annotate | Line # | Download | only in indent
      1 /* $NetBSD: opt_bl_br.c,v 1.10 2025/01/03 23:37:18 rillig Exp $ */
      2 
      3 //indent input
      4 void
      5 standard_style(int n)
      6 {
      7 	if (n > 99) {
      8 		print("large");
      9 	} else if (n > 9) {
     10 		print("double-digit");
     11 	} else if (n > 0)
     12 		print("positive");
     13 	else {
     14 		print("negative");
     15 	}
     16 }
     17 //indent end
     18 
     19 //indent run-equals-input -br
     20 
     21 //indent run -bl
     22 void
     23 standard_style(int n)
     24 {
     25 	if (n > 99)
     26 	{
     27 		print("large");
     28 	} else if (n > 9)
     29 	{
     30 		print("double-digit");
     31 	} else if (n > 0)
     32 		print("positive");
     33 	else
     34 	{
     35 		print("negative");
     36 	}
     37 }
     38 //indent end
     39 
     40 
     41 /*
     42  * In this very condensed style, the additional newline between '}' and 'else'
     43  * is kept.
     44  */
     45 //indent input
     46 void
     47 condensed_style(int n)
     48 {
     49 	if (n > 99) { print("large"); }
     50 	else if (n > 9) { print("double-digit"); }
     51 	else if (n > 0) print("positive");
     52 	else { print("negative"); }
     53 }
     54 //indent end
     55 
     56 //indent run -bl
     57 void
     58 condensed_style(int n)
     59 {
     60 	if (n > 99)
     61 	{
     62 		print("large");
     63 	}
     64 	else if (n > 9)
     65 	{
     66 		print("double-digit");
     67 	}
     68 	else if (n > 0)
     69 		print("positive");
     70 	else
     71 	{
     72 		print("negative");
     73 	}
     74 }
     75 //indent end
     76 
     77 //indent run -br
     78 void
     79 condensed_style(int n)
     80 {
     81 	if (n > 99) {
     82 		print("large");
     83 	}
     84 	else if (n > 9) {
     85 		print("double-digit");
     86 	}
     87 	else if (n > 0)
     88 		print("positive");
     89 	else {
     90 		print("negative");
     91 	}
     92 }
     93 //indent end
     94 
     95 
     96 /*
     97  * An end-of-line comment after 'if (expr)' forces the '{' to go to the next
     98  * line.
     99  */
    100 //indent input
    101 void
    102 eol_comment(void)
    103 {
    104 	if (expr) // C99 comment
    105 		stmt();
    106 
    107 	if (expr) // C99 comment
    108 	{
    109 		stmt();
    110 	}
    111 }
    112 //indent end
    113 
    114 //indent run -br
    115 void
    116 eol_comment(void)
    117 {
    118 	if (expr)		// C99 comment
    119 		stmt();
    120 
    121 	if (expr)		// C99 comment
    122 	{
    123 		stmt();
    124 	}
    125 }
    126 //indent end
    127 
    128 //indent run-equals-prev-output -bl
    129 
    130 
    131 /*
    132  * Test multiple mixed comments after 'if (expr)'.
    133  */
    134 //indent input
    135 void
    136 function(void)
    137 {
    138 	if (expr)	// C99 comment 1
    139 			// C99 comment 2
    140 			// C99 comment 3
    141 		stmt();
    142 }
    143 //indent end
    144 
    145 //indent run
    146 void
    147 function(void)
    148 {
    149 	if (expr)		// C99 comment 1
    150 		// C99 comment 2
    151 		// C99 comment 3
    152 		stmt();
    153 }
    154 //indent end
    155 
    156 
    157 /*
    158  * The combination of the options '-br' and '-ei' (both active by default)
    159  * removes extra newlines between the tokens '}', 'else' and 'if'.
    160  */
    161 //indent input
    162 void
    163 function(void)
    164 {
    165 	if (cond)
    166 	{
    167 		stmt();
    168 	}
    169 	else if (cond)
    170 	{
    171 		stmt();
    172 	}
    173 }
    174 //indent end
    175 
    176 /* TODO: Remove the newline between ')' and '{'. */
    177 //indent run-equals-input -br
    178 
    179 
    180 //indent input
    181 void
    182 comments(void)
    183 {
    184 	if(cond){}
    185 
    186 	if (cond)
    187 	{}
    188 
    189 	if (cond) /* comment */
    190 	{}
    191 
    192 	if (cond)
    193 	/* comment */
    194 	{}
    195 
    196 	if (cond)
    197 	// comment1
    198 	// comment2
    199 	{}
    200 
    201 	if (cond) // comment
    202 	{}
    203 }
    204 //indent end
    205 
    206 //indent run -bl
    207 void
    208 comments(void)
    209 {
    210 	if (cond)
    211 	{
    212 	}
    213 
    214 	if (cond)
    215 	{
    216 	}
    217 
    218 	if (cond)		/* comment */
    219 	{
    220 	}
    221 
    222 	if (cond)
    223 		/* comment */
    224 	{
    225 	}
    226 
    227 	if (cond)
    228 		// comment1
    229 		// comment2
    230 	{
    231 	}
    232 
    233 	if (cond)		// comment
    234 	{
    235 	}
    236 }
    237 //indent end
    238 
    239 //indent run -br
    240 void
    241 comments(void)
    242 {
    243 	if (cond) {
    244 	}
    245 
    246 	if (cond)
    247 	{
    248 	}
    249 
    250 	if (cond)		/* comment */
    251 	{
    252 	}
    253 
    254 	if (cond)
    255 		/* comment */
    256 	{
    257 	}
    258 
    259 	if (cond)
    260 		// comment1
    261 		// comment2
    262 	{
    263 	}
    264 
    265 	if (cond)		// comment
    266 	{
    267 	}
    268 }
    269 //indent end
    270