Home | History | Annotate | Line # | Download | only in indent
      1 /* $NetBSD: opt_lp.c,v 1.10 2023/06/09 06:36:58 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the options '-lp' and '-nlp'.
      5  *
      6  * The option '-lp' lines up code surrounded by parentheses in continuation
      7  * lines. With '-lp', if a line has a left parenthesis that is not closed on
      8  * that line, continuation lines are lined up to start at the character
      9  * position just after the left parenthesis.
     10  *
     11  * The option '-nlp' indents continuation lines with the continuation
     12  * indentation; see '-ci'.
     13  */
     14 
     15 //indent input
     16 void
     17 example(void)
     18 {
     19 	p1 = first_procedure(second_procedure(p2, p3),
     20 	    third_procedure(p4, p5));
     21 
     22 	p1 = first_procedure(second_procedure(p2,
     23 	    p3),
     24 	    third_procedure(p4,
     25 	        p5));
     26 
     27 	p1 = first_procedure(
     28 	 second_procedure(p2, p3),
     29 	 third_procedure(p4, p5));
     30 }
     31 //indent end
     32 
     33 //indent run -lp
     34 void
     35 example(void)
     36 {
     37 	p1 = first_procedure(second_procedure(p2, p3),
     38 			     third_procedure(p4, p5));
     39 
     40 	p1 = first_procedure(second_procedure(p2,
     41 					      p3),
     42 			     third_procedure(p4,
     43 					     p5));
     44 
     45 	p1 = first_procedure(
     46 			     second_procedure(p2, p3),
     47 			     third_procedure(p4, p5));
     48 }
     49 //indent end
     50 
     51 //indent run -nlp
     52 void
     53 example(void)
     54 {
     55 	p1 = first_procedure(second_procedure(p2, p3),
     56 		third_procedure(p4, p5));
     57 
     58 	p1 = first_procedure(second_procedure(p2,
     59 			p3),
     60 		third_procedure(p4,
     61 			p5));
     62 
     63 	p1 = first_procedure(
     64 		second_procedure(p2, p3),
     65 		third_procedure(p4, p5));
     66 }
     67 //indent end
     68 
     69 //indent run -nlp -ci4
     70 void
     71 example(void)
     72 {
     73 	p1 = first_procedure(second_procedure(p2, p3),
     74 	    third_procedure(p4, p5));
     75 
     76 	p1 = first_procedure(second_procedure(p2,
     77 		p3),
     78 	    third_procedure(p4,
     79 		p5));
     80 
     81 	p1 = first_procedure(
     82 	    second_procedure(p2, p3),
     83 	    third_procedure(p4, p5));
     84 }
     85 //indent end
     86 
     87 
     88 /*
     89  * Ensure that in multi-line else-if conditions, all lines are indented by the
     90  * correct amount.  The 'else if' condition is tricky because it has the same
     91  * indentation as the preceding 'if' condition.
     92  */
     93 //indent input
     94 {
     95 if (cond11a
     96 && cond11b
     97 && cond11c) {
     98 stmt11;
     99 } else if (cond12a
    100 && cond12b
    101 && cond12c) {
    102 stmt12;
    103 }
    104 }
    105 
    106 {
    107 if (cond21a
    108 && cond21b
    109 && cond21c)
    110 stmt21;
    111 else if (cond22a
    112 && cond22b
    113 && cond22c)
    114 stmt22;
    115 }
    116 //indent end
    117 
    118 //indent run -ci4 -nlp
    119 {
    120 	if (cond11a
    121 	    && cond11b
    122 	    && cond11c) {
    123 		stmt11;
    124 	} else if (cond12a
    125 	    && cond12b
    126 	    && cond12c) {
    127 		stmt12;
    128 	}
    129 }
    130 
    131 {
    132 	if (cond21a
    133 	    && cond21b
    134 	    && cond21c)
    135 		stmt21;
    136 	else if (cond22a
    137 	    && cond22b
    138 	    && cond22c)
    139 		stmt22;
    140 }
    141 //indent end
    142