Home | History | Annotate | Line # | Download | only in indent
      1 /* $NetBSD: opt_di.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
      2 
      3 /*
      4  * Test the option '-di', which specifies the indentation of the first
      5  * variable name in a declaration.
      6  */
      7 
      8 //indent input
      9 int space;
     10 int	tab;
     11 int		tab16;
     12 
     13 struct long_name long_name;
     14 //indent end
     15 
     16 //indent run -di8
     17 int	space;
     18 int	tab;
     19 int	tab16;
     20 
     21 struct long_name long_name;
     22 //indent end
     23 
     24 
     25 /*
     26  * The declarator can be a simple variable name. It can also be prefixed by
     27  * asterisks, for pointer variables. These asterisks are placed to the left of
     28  * the indentation line, so that the variable names are aligned.
     29  *
     30  * There can be multiple declarators in a single declaration, separated by
     31  * commas. Only the first of them is aligned to the indentation given by
     32  * '-di', the others are separated with a single space.
     33  */
     34 //indent input
     35 int var;
     36 int *ptr, *****ptr;
     37 //indent end
     38 
     39 //indent run -di12
     40 int	    var;
     41 int	   *ptr, *****ptr;
     42 //indent end
     43 
     44 
     45 /*
     46  * Test the various values for indenting.
     47  */
     48 //indent input
     49 int decl ;
     50 //indent end
     51 
     52 /*
     53  * An indentation of 0 columns uses a single space between the declaration
     54  * specifiers (in this case 'int') and the declarator.
     55  */
     56 //indent run -di0
     57 int decl;
     58 //indent end
     59 
     60 /*
     61  * An indentation of 7 columns uses spaces for indentation since in the
     62  * default configuration, the next tab stop would be at indentation 8.
     63  */
     64 //indent run -di7
     65 int    decl;
     66 //indent end
     67 
     68 /* The indentation consists of a single tab. */
     69 //indent run -di8
     70 int	decl;
     71 //indent end
     72 
     73 /* The indentation consists of a tab and a space. */
     74 //indent run -di9
     75 int	 decl;
     76 //indent end
     77 
     78 //indent run -di16
     79 int		decl;
     80 //indent end
     81 
     82 
     83 /*
     84  * Ensure that all whitespace is normalized to be indented by 8 columns,
     85  * which in the default configuration amounts to a single tab.
     86  */
     87 //indent input
     88 int space;
     89 int	tab;
     90 int		tab16;
     91 struct long_name long_name;
     92 //indent end
     93 
     94 //indent run -di8
     95 int	space;
     96 int	tab;
     97 int	tab16;
     98 struct long_name long_name;
     99 //indent end
    100 
    101 
    102 /*
    103  * A variable that has an ad-hoc struct/union/enum type does not need to be
    104  * indented to the right of the keyword 'struct', it only needs a single space
    105  * of indentation.
    106  *
    107  * Before NetBSD indent.c 1.151 from 2021-10-24, the indentation depended on
    108  * the length of the keyword 'struct', 'union' or 'enum', together with type
    109  * qualifiers like 'const' or the storage class like 'static'.
    110  */
    111 //indent input
    112 struct {
    113 	int member;
    114 } var = {
    115 	3,
    116 };
    117 //indent end
    118 
    119 //indent run-equals-input -di0
    120 
    121 //indent run
    122 struct {
    123 	int		member;
    124 }		var = {
    125 	3,
    126 };
    127 //indent end
    128