Home | History | Annotate | Line # | Download | only in indent
indent_off_on.c revision 1.4
      1 /* $NetBSD: indent_off_on.c,v 1.4 2021/11/19 22:24:29 rillig Exp $ */
      2 /* $FreeBSD$ */
      3 
      4 /*
      5  * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
      6  * disable formatting, copying the input directly to the output.  Internally,
      7  * indent still keeps track of the number of braces and other indentation.
      8  */
      9 
     10 #indent input
     11 {}
     12 
     13 /*INDENT OFF*/
     14 /*INDENT ON*/
     15 
     16 {}
     17 #indent end
     18 
     19 /*
     20  * XXX: It is asymmetric that 'INDENT OFF' is kept as is, while 'INDENT ON'
     21  * gets enclosed with spaces.
     22  */
     23 #indent run
     24 {
     25 }
     26 /* $ FIXME: This empty line must stay. */
     27 /*INDENT OFF*/
     28 /* INDENT ON */
     29 
     30 {
     31 }
     32 #indent end
     33 
     34 
     35 #indent input
     36 {}
     37 
     38 
     39 /*INDENT OFF*/
     40 /*INDENT ON*/
     41 #indent end
     42 
     43 #indent run
     44 {
     45 }
     46 /* $ FIXME: This empty line must stay. */
     47 /* $ FIXME: This empty line must stay. */
     48 /*INDENT OFF*/
     49 /* INDENT ON */
     50 #indent end
     51 
     52 
     53 #indent input
     54 {}
     55  /* INDENT OFF */
     56  /* INDENT ON */
     57 {}
     58 #indent end
     59 
     60 /*
     61  * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
     62  * is aligned.
     63  */
     64 #indent run
     65 {
     66 }
     67  /* INDENT OFF */
     68 /* INDENT ON */
     69 {
     70 }
     71 #indent end
     72 
     73 
     74 #indent input
     75 {}
     76 	/* INDENT OFF */
     77 	/* INDENT ON */
     78 {}
     79 #indent end
     80 
     81 /*
     82  * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
     83  * is aligned.
     84  */
     85 #indent run
     86 {
     87 }
     88 	/* INDENT OFF */
     89 /* INDENT ON */
     90 {
     91 }
     92 #indent end
     93 
     94 /*
     95  * The INDENT comments can be written without space between the words, but
     96  * nobody does this.
     97  */
     98 #indent input
     99 int   decl   ;
    100 /*INDENTOFF*/
    101 int   decl   ;
    102 /*INDENTON*/
    103 int   decl   ;
    104 #indent end
    105 
    106 #indent run -di0
    107 int decl;
    108 /*INDENTOFF*/
    109 int   decl   ;
    110 /* INDENTON */
    111 int decl;
    112 #indent end
    113 
    114 
    115 /*
    116  * Any whitespace around the 'INDENT ON/OFF' is ignored, as is any whitespace
    117  * between the two words.
    118  */
    119 #indent input
    120 int   decl   ;
    121 /*		INDENT		OFF		*/
    122 int   decl   ;
    123 /*		INDENT		ON		*/
    124 int   decl   ;
    125 #indent end
    126 
    127 /*
    128  * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
    129  * is pushed to the start of the line.
    130  */
    131 #indent run -di0
    132 int decl;
    133 /*		INDENT		OFF		*/
    134 int   decl   ;
    135 /* INDENT		ON		*/
    136 int decl;
    137 #indent end
    138 
    139 
    140 #indent input
    141 /*INDENT OFF*/
    142 /* No formatting takes place here. */
    143 int format( void ) {{{
    144 /*INDENT ON*/
    145 }}}
    146 #indent end
    147 
    148 #indent run
    149 /*INDENT OFF*/
    150 /* No formatting takes place here. */
    151 int format( void ) {{{
    152 /* $ XXX: Why is the INDENT ON comment indented? */
    153 /* $ XXX: Why does the INDENT ON comment get spaces, but not the OFF comment? */
    154 			/* INDENT ON */
    155 }
    156 }
    157 }
    158 #indent end
    159 
    160 
    161 #indent input
    162 /* INDENT OFF */
    163 void indent_off ( void ) ;
    164 /*  INDENT */
    165 void indent_on ( void ) ;
    166 /* INDENT OFF */
    167 void indent_off ( void ) ;
    168 	/* INDENT ON */
    169 void indent_on ( void ) ;	/* the comment may be indented */
    170 /* INDENT		OFF					*/
    171 void indent_off ( void ) ;
    172 /* INDENTATION ON */
    173 void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
    174 /* INDENT ON * */
    175 void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
    176 /* INDENT ON */
    177 void indent_on ( void ) ;
    178 /* INDENT: OFF */
    179 void indent_still_on ( void ) ;	/* due to the colon in the middle */
    180 /* INDENT OFF */		/* extra comment */
    181 void indent_still_on ( void ) ;	/* due to the extra comment to the right */
    182 #indent end
    183 
    184 #indent run
    185 /* INDENT OFF */
    186 void indent_off ( void ) ;
    187 /* $ XXX: The double space from the below comment got merged to a single */
    188 /* $ XXX: space even though the comment might be regarded to be still in */
    189 /* $ XXX: the OFF section. */
    190 /* INDENT */
    191 void
    192 indent_on(void);
    193 /* INDENT OFF */
    194 void indent_off ( void ) ;
    195 /* $ XXX: The below comment got moved from column 9 to column 1. */
    196 /* INDENT ON */
    197 void
    198 indent_on(void);		/* the comment may be indented */
    199 /* INDENT		OFF					*/
    200 void indent_off ( void ) ;
    201 /* INDENTATION ON */
    202 void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
    203 /* INDENT ON * */
    204 void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
    205 /* INDENT ON */
    206 void
    207 indent_on(void);
    208 /* INDENT: OFF */
    209 void
    210 indent_still_on(void);		/* due to the colon in the middle */
    211 /* $ The extra comment got moved to the left since there is no code in */
    212 /* $ that line. */
    213 /* INDENT OFF *//* extra comment */
    214 void
    215 indent_still_on(void);		/* due to the extra comment to the right */
    216 #indent end
    217 
    218 
    219 /*
    220  * Try to confuse indent by having a string literal that has an embedded
    221  * INDENT comment.  Indent doesn't get confused though because it requires the
    222  * INDENT comment to go from the very beginning of the line to the very end of
    223  * the line.
    224  */
    225 #indent input
    226 const char *str = "\
    227 /* INDENT OFF */\
    228 "   ,   ch;
    229 #indent end
    230 
    231 #indent run
    232 const char     *str = "\
    233 /* INDENT OFF */\
    234 ", ch;
    235 #indent end
    236 
    237 
    238 /*
    239  * The keywords in the INDENT comments must all be uppercase.
    240  */
    241 #indent input
    242 int   on   ;
    243 /* indent off */
    244 int   still_on   ;
    245 /* INDENT off */
    246 int   still_on   ;
    247 /* indent OFF */
    248 int   still_on   ;
    249 /* INDENT OFF */
    250 int   finally_off   ;
    251 #indent end
    252 
    253 #indent run -di0
    254 int on;
    255 /* indent off */
    256 int still_on;
    257 /* INDENT off */
    258 int still_on;
    259 /* indent OFF */
    260 int still_on;
    261 /* INDENT OFF */
    262 int   finally_off   ;
    263 #indent end
    264