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