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