Home | History | Annotate | Line # | Download | only in indent
fmt_decl.c revision 1.4
      1 /*	$NetBSD: fmt_decl.c,v 1.4 2021/10/26 23:37:40 rillig Exp $	*/
      2 /* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
      3 
      4 /* See FreeBSD r303570 */
      5 
      6 #indent input
      7 typedef void	(*voidptr) (int *);
      8 #indent end
      9 
     10 #indent run
     11 typedef void (*voidptr)(int *);
     12 #indent end
     13 
     14 
     15 #indent input
     16 static const struct
     17 {
     18 	double		x;
     19 	double		y, z;
     20 } n[m + 1] =
     21 {
     22 	{
     23 		.0,
     24 		.9,
     25 		5
     26 	}
     27 };
     28 #indent end
     29 
     30 #indent run
     31 static const struct {
     32 	double		x;
     33 	double		y, z;
     34 }		n[m + 1] =
     35 {
     36 	{
     37 		.0,
     38 		.9,
     39 		5
     40 	}
     41 };
     42 #indent end
     43 
     44 
     45 #indent input
     46 typedef struct Complex
     47 {
     48 	double		x;
     49 	double		y;
     50 }	Complex;
     51 #indent end
     52 
     53 #indent run
     54 typedef struct Complex {
     55 	double		x;
     56 	double		y;
     57 }		Complex;
     58 #indent end
     59 
     60 
     61 #indent input
     62 void
     63 t1 (char *a, int b,
     64 	void (*fn)(void))
     65 {}
     66 #indent end
     67 
     68 #indent run
     69 void
     70 t1(char *a, int b,
     71    void (*fn)(void))
     72 {
     73 }
     74 #indent end
     75 
     76 
     77 #indent input
     78 void t2 (char *x, int y)
     79 {
     80 	int a,
     81 	b,
     82 	c;
     83 	int
     84 	*d,
     85 	*e,
     86 	*f;
     87 	int (*g)(),
     88 	(*h)(),
     89 	(*i)();
     90 	int j,
     91 	k,
     92 	l;
     93 	int m
     94 	,n
     95 	,o
     96 	;
     97 	int		chars[ /* push the comma beyond column 74 .... */ ], x;
     98 }
     99 #indent end
    100 
    101 #indent run
    102 void
    103 t2(char *x, int y)
    104 {
    105 	int		a, b, c;
    106 	int
    107 		       *d, *e, *f;
    108 	int		(*g)(), (*h)(), (*i)();
    109 	int		j, k, l;
    110 	int		m
    111 		       ,n
    112 		       ,o
    113 		       ;
    114 	int		chars[ /* push the comma beyond column 74 .... */ ],
    115 			x;
    116 }
    117 #indent end
    118 
    119 
    120 #indent input
    121 const int	int_minimum_size =
    122 MAXALIGN(offsetof(int, test)) + MAXIMUM_ALIGNOF;
    123 #indent end
    124 
    125 #indent run-equals-input
    126 
    127 
    128 #indent input
    129 int *int_create(void)
    130 {
    131 
    132 }
    133 #indent end
    134 
    135 #indent run
    136 int	       *
    137 int_create(void)
    138 {
    139 
    140 }
    141 #indent end
    142 
    143 
    144 #indent input
    145 static
    146 _attribute_printf(1, 2)
    147 void
    148 print_error(const char *fmt,...)
    149 {
    150 }
    151 #indent end
    152 
    153 #indent run
    154 static
    155 _attribute_printf(1, 2)
    156 void
    157 print_error(const char *fmt, ...)
    158 {
    159 }
    160 #indent end
    161 
    162 
    163 #indent input
    164 static _attribute_printf(1, 2)
    165 void
    166 print_error(const char *fmt,...)
    167 {
    168 }
    169 #indent end
    170 
    171 #indent run
    172 static _attribute_printf(1, 2)
    173 void
    174 print_error(const char *fmt, ...)
    175 {
    176 }
    177 #indent end
    178 
    179 
    180 #indent input
    181 static void _attribute_printf(1, 2)
    182 print_error(const char *fmt,...)
    183 {
    184 }
    185 #indent end
    186 
    187 #indent run
    188 static void
    189 _attribute_printf(1, 2)
    190 print_error(const char *fmt, ...)
    191 {
    192 }
    193 #indent end
    194 
    195 
    196 /* See FreeBSD r309380 */
    197 #indent input
    198 static LIST_HEAD(, alq) ald_active;
    199 static int ald_shutingdown = 0;
    200 struct thread *ald_thread;
    201 #indent end
    202 
    203 #indent run
    204 static LIST_HEAD(, alq) ald_active;
    205 static int	ald_shutingdown = 0;
    206 struct thread  *ald_thread;
    207 #indent end
    208 
    209 
    210 #indent input
    211 static int
    212 old_style_definition(a, b, c)
    213 	struct thread *a;
    214 	int b;
    215 	double ***c;
    216 {
    217 
    218 }
    219 #indent end
    220 
    221 #indent run
    222 static int
    223 old_style_definition(a, b, c)
    224 	struct thread  *a;
    225 	int		b;
    226 	double	     ***c;
    227 {
    228 
    229 }
    230 #indent end
    231 
    232 
    233 /*
    234  * Demonstrate how variable declarations are broken into several lines when
    235  * the line length limit is set quite low.
    236  */
    237 #indent input
    238 struct s0 a,b;
    239 struct s01 a,b;
    240 struct s012 a,b;
    241 struct s0123 a,b;
    242 struct s01234 a,b;
    243 struct s012345 a,b;
    244 struct s0123456 a,b;
    245 struct s01234567 a,b;
    246 struct s012345678 a,b;
    247 struct s0123456789 a,b;
    248 struct s01234567890 a,b;
    249 struct s012345678901 a,b;
    250 struct s0123456789012 a,b;
    251 struct s01234567890123 a,b;
    252 #indent end
    253 
    254 #indent run -l20 -di0
    255 /* $ XXX: Why is this declaration broken? There's plenty of space left. */
    256 struct s0 a,
    257    b;
    258 struct s01 a,
    259     b;
    260 struct s012 a,
    261      b;
    262 struct s0123 a,
    263       b;
    264 struct s01234 a,
    265        b;
    266 struct s012345 a,
    267         b;
    268 struct s0123456 a,
    269          b;
    270 struct s01234567 a,
    271           b;
    272 struct s012345678 a,
    273            b;
    274 struct s0123456789 a,
    275             b;
    276 struct s01234567890 a,
    277              b;
    278 struct s012345678901 a,
    279               b;
    280 struct s0123456789012 a,
    281                b;
    282 struct s01234567890123 a,
    283                 b;
    284 #indent end
    285 
    286 
    287 #indent input
    288 char * x(void)
    289 {
    290     type identifier;
    291     type *pointer;
    292     unused * value;
    293     (void)unused * value;
    294 
    295     dmax = (double)3 * 10.0;
    296     dmin = (double)dmax * 10.0;
    297     davg = (double)dmax * dmin;
    298 
    299     return NULL;
    300 }
    301 #indent end
    302 
    303 #indent run
    304 char *
    305 x(void)
    306 {
    307 	type		identifier;
    308 	type	       *pointer;
    309 	unused	       *value;
    310 	(void)unused * value;
    311 
    312 	dmax = (double)3 * 10.0;
    313 	dmin = (double)dmax * 10.0;
    314 	davg = (double)dmax * dmin;
    315 
    316 	return NULL;
    317 }
    318 #indent end
    319 
    320 #indent input
    321 int *
    322 y(void) {
    323 
    324 }
    325 
    326 int
    327 z(void) {
    328 
    329 }
    330 #indent end
    331 
    332 #indent run
    333 int *
    334 y(void)
    335 {
    336 
    337 }
    338 
    339 int
    340 z(void)
    341 {
    342 
    343 }
    344 #indent end
    345 
    346 
    347 #indent input
    348 int x;
    349 int *y;
    350 int * * * * z;
    351 #indent end
    352 
    353 #indent run
    354 int		x;
    355 int	       *y;
    356 int	    ****z;
    357 #indent end
    358 
    359 
    360 #indent input
    361 int main(void) {
    362     char (*f1)() = NULL;
    363     char *(*f1)() = NULL;
    364     char *(*f2)();
    365 }
    366 #indent end
    367 
    368 #indent run -ldi0
    369 int
    370 main(void)
    371 {
    372 	char (*f1)() = NULL;
    373 /* $ FIXME: The following declaration must be indented. */
    374 char *(*f1)() = NULL;
    375 /* $ FIXME: The following declaration must be indented. */
    376 char *(*f2)();
    377 }
    378 #indent end
    379