Home | History | Annotate | Line # | Download | only in indent
opt_bl_br.c revision 1.7
      1 /* $NetBSD: opt_bl_br.c,v 1.7 2023/05/11 09:28:53 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 example(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 example(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 example(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 function(void)
    102 {
    103 	if (expr) // C99 comment
    104 		stmt();
    105 
    106 	if (expr) // C99 comment
    107 	{
    108 		stmt();
    109 	}
    110 }
    111 //indent end
    112 
    113 //indent run
    114 void
    115 function(void)
    116 {
    117 	if (expr)		// C99 comment
    118 		stmt();
    119 
    120 	if (expr)		// C99 comment
    121 	{
    122 		stmt();
    123 	}
    124 }
    125 //indent end
    126 
    127 
    128 /*
    129  * Test multiple mixed comments after 'if (expr)'.
    130  */
    131 //indent input
    132 void
    133 function(void)
    134 {
    135 	if (expr)	// C99 comment 1
    136 			// C99 comment 2
    137 			// C99 comment 3
    138 		stmt();
    139 }
    140 //indent end
    141 
    142 //indent run
    143 void
    144 function(void)
    145 {
    146 	if (expr)		// C99 comment 1
    147 		// C99 comment 2
    148 		// C99 comment 3
    149 		stmt();
    150 }
    151 //indent end
    152 
    153 
    154 /*
    155  * The combination of the options '-br' and '-ei' (both active by default)
    156  * remove extra newlines between the tokens '}', 'else' and 'if'.
    157  */
    158 //indent input
    159 void
    160 function(void)
    161 {
    162 	if (cond)
    163 	{
    164 		stmt();
    165 	}
    166 	else
    167 	if (cond)
    168 	{
    169 		stmt();
    170 	}
    171 }
    172 //indent end
    173 
    174 /* TODO: Remove the newline between ')' and '{'. */
    175 //indent run-equals-input -br
    176