1.\" Copyright (c) 1980, 1990 The Regents of the University of California. 2.\" Copyright (c) 1985 Sun Microsystems, Inc. 3.\" Copyright (c) 1976 Board of Trustees of the University of Illinois. 4.\" All rights reserved. 5.\" 6.\" %sccs.include.redist.man% 7.\" 8.\" @(#)indent.1 6.9 (Berkeley) 03/14/91 9.\" 10.Vx 11.Vx 12.Dd 13.Dt INDENT 1 14.Sh NAME 15.Nm indent 16.Nd indent and format C program source 17.Sh SYNOPSIS 18.Nm indent 19.Op Ar input-file Op Ar output-file 20.Cx \&[ 21.Fl bad 22.Cx \&\ |\ \& 23.Fl nbad 24.Cx \&] 25.Cx 26.Cx \&[ 27.Fl bap 28.Cx \&\ |\ \& 29.Fl nbap 30.Cx \&] 31.Cx 32.Cx \&[ 33.Fl bbb 34.Cx \&\ |\ \& 35.Fl nbbb 36.Cx \&] 37.Cx 38.Cx \&[ 39.Fl bc 40.Cx \&\ |\ \& 41.Fl nbc 42.Cx \&] 43.Cx 44.Op Fl bl 45.Op Fl br 46.Oo 47.Op Fl c Ar n 48.Op Fl cd Ar n 49.Oo 50.Cx \&[ 51.Fl cdb 52.Cx \&\ |\ \& 53.Fl ncdb 54.Cx \&] 55.Cx 56.Cx \&[ 57.Fl ce 58.Cx \&\ |\ \& 59.Fl nce 60.Cx \&] 61.Cx 62.Oo 63.Op Fl ci Ar n 64.Op Fl cli Ar n 65.Op Fl d Ar n 66.Op Fl di Ar n 67.Oo 68.Cx \&[ 69.Fl fc1 70.Cx \&\ |\ \& 71.Fl nfc1 72.Cx \&] 73.Cx 74.Oo 75.Op Fl i Ar n 76.Oo 77.Cx \&[ 78.Fl ip 79.Cx \&\ |\ \& 80.Fl nip 81.Cx \&] 82.Cx 83.Oo 84.Op Fl l Ar n 85.Op Fl lc Ar n 86.Oo 87.Cx \&[ 88.Fl lp 89.Cx \&\ |\ \& 90.Fl nlp 91.Cx \&] 92.Cx 93.Op Fl npro 94.Cx \&[ 95.Fl pcs 96.Cx \&\ |\ \& 97.Fl npcs 98.Cx \&] 99.Cx 100.Cx \&[ 101.Fl psl 102.Cx \&\ |\ \& 103.Fl npsl 104.Cx \&] 105.Cx 106.Cx \&[ 107.Fl sc 108.Cx \&\ |\ \& 109.Fl nsc 110.Cx \&] 111.Cx 112.Cx \&[ 113.Fl sob 114.Cx \&\ |\ \& 115.Fl nsob 116.Cx \&] 117.Cx 118.Op Fl st 119.Op Fl troff 120.Cx \&[ 121.Fl v 122.Cx \&\ |\ \& 123.Fl nv 124.Cx \&] 125.Cx 126.Sh DESCRIPTION 127.Nm Indent 128is a 129.Ar C 130program formatter. It reformats the 131.Ar C 132program in the 133.Ar input-file 134according to the switches. The switches which can be 135specified are described below. They may appear before or after the file 136names. 137.Pp 138.Sy NOTE : 139If you only specify an 140.Ar input-file , 141the formatting is 142done `in-place', that is, the formatted file is written back into 143.Ar input-file 144and a backup copy of 145.Ar input-file 146is written in the current directory. If 147.Ar input-file 148is named 149.Sq Pa /blah/blah/file , 150the backup file is named 151.Pa file.BAK . 152.Pp 153If 154.Ar output-file 155is specified, 156.Nm indent 157checks to make sure it is different from 158.Ar input-file . 159.Pp 160The options listed below control the formatting style imposed by 161.Nm indent . 162.Tw Op 163.Tp Fl bad , nbad 164If 165.Fl bad 166is specified, a blank line is forced after every block of 167declarations. Default: 168.Fl nbad . 169.Tp Fl bap , nbap 170If 171.Fl bap 172is specified, a blank line is forced after every procedure body. Default: 173.Fl nbap . 174.Tp Fl bbb , nbbb 175If 176.Fl bbb 177is specified, a blank line is forced before every block comment. Default: 178.Fl nbbb . 179.Tp Fl bc , nbc 180If 181.Fl bc 182is specified, then a newline is forced after each comma in a declaration. 183.Fl nbc 184turns off this option. The default is 185.Fl bc . 186.Tp Fl br , bl 187Specifying 188.Fl bl 189lines up compound statements like this: 190.ne 4 191.Ds I 192if (...) 193{ 194 code 195} 196.De 197Specifying 198.Fl br 199(the default) makes them look like this: 200.ne 3 201.Ds I 202if (...) { 203 code 204} 205.De 206.Pp 207.Tp Fl c n 208The column in which comments on code start. The default is 33. 209.Tp Fl cd n 210The column in which comments on declarations start. The default 211is for these comments to start in the same column as those on code. 212.Tp Fl cdb , ncdb 213Enables (disables) the placement of comment delimiters on blank lines. With 214this option enabled, comments look like this: 215.Ds I 216.ne 3 217 /* 218 * this is a comment 219 */ 220.De 221Rather than like this: 222.Ds I 223 /* this is a comment */ 224.De 225This only affects block comments, not comments to the right of 226code. The default is 227.Fl cdb . 228.Tp Fl ce , nce 229Enables (disables) forcing `else's to cuddle up to the immediately preceding 230`}'. The default is 231.Fl ce . 232.Tp Cx Fl ci 233.Ar n 234.Cx 235Sets the continuation indent to be 236.Ar n . 237Continuation 238lines will be indented that far from the beginning of the first line of the 239statement. Parenthesized expressions have extra indentation added to 240indicate the nesting, unless 241.Fl lp 242is in effect. 243.Fl ci 244defaults to the same value as 245.Fl i . 246.Tp Cx Fl cli 247.Ar n 248.Cx 249Causes case labels to be indented 250.Ar n 251tab stops to the right of the containing 252.Ic switch 253statement. 254.Fl cli0 .5 255causes case labels to be indented half a tab stop. The 256default is 257.Fl cli0 . 258.Tp Cx Fl d 259.Ar n 260.Cx 261Controls the placement of comments which are not to the 262right of code. The default 263.Fl d1 264means that such comments are placed one indentation level to the 265left of code. Specifying 266.Fl d0 267lines up these comments with the code. See the section on comment 268indentation below. 269.Tp Cx Fl di 270.Ar n 271.Cx 272Specifies the indentation, in character positions, from a declaration keyword 273to the following identifier. The default is 274.Fl di16 . 275.Tp Fl dj , ndj 276.Fl dj 277left justifies declarations. 278.Fl ndj 279indents declarations the same as code. The default is 280.Fl ndj . 281.Tp Fl ei , nei 282Enables (disables) special 283.Ic else-if 284processing. If it's enabled, an 285.Ic if 286following an 287.Ic else 288will have the same indentation as the preceding 289.Ic if 290statement. 291.Tp Fl fc1 , nfc1 292Enables (disables) the formatting of comments that start in column 1. 293Often, comments whose leading `/' is in column 1 have been carefully 294hand formatted by the programmer. In such cases, 295.Fl nfc1 296should be 297used. The default is 298.Fl fc1 . 299.Tp Cx Fl i 300.Ar n 301.Cx 302The number of spaces for one indentation level. The default is 4. 303.Tp Fl ip , nip 304Enables (disables) the indentation of parameter declarations from the left 305margin. The default is 306.Fl ip . 307.Tp Cx Fl l 308.Ar n 309.Cx 310Maximum length of an output line. The default is 75. 311.Tp Fl lp , nlp 312Lines up code surrounded by parenthesis in continuation lines. If a line 313has a left paren which is not closed on that line, then continuation lines 314will be lined up to start at the character position just after the left 315paren. For example, here is how a piece of continued code looks with 316.Fl nlp 317in effect: 318.ne 2 319.Ds I 320.Li p1 = first_procedure(second_procedure(p2, p3), 321.Li \ \ third_procedure(p4,p5)); 322.De 323.ne 5 324With 325.Fl lp 326in effect (the default) the code looks somewhat clearer: 327.Ds I 328.Li p1\ =\ first_procedure(second_procedure(p2,\ p3), 329.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,p5)); 330.De 331.ne 5 332Inserting two more newlines we get: 333.Ds I 334.Li p1\ =\ first_procedure(second_procedure(p2, 335.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3), 336.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4 337.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5)); 338.De 339.Pp 340.Tp Fl npro 341Causes the profile files, 342.Sq Pa ./.indent.pro 343and 344.Sq Pa ~/.indent.pro , 345to be ignored. 346.Tp Fl pcs , npcs 347If true 348.Pq Fl pcs 349all procedure calls will have a space inserted between 350the name and the `('. The default is 351.Fl npcs . 352.Tp Fl psl , npsl 353If true 354.Pq Fl psl 355the names of procedures being defined are placed in 356column 1 \- their types, if any, will be left on the previous lines. The 357default is 358.Fl psl . 359.Tp Fl sc , nsc 360Enables (disables) the placement of asterisks (`*'s) at the left edge of all 361comments. 362.Tp Fl sob , nsob 363If 364.Fl sob 365is specified, indent will swallow optional blank lines. You can use this to 366get rid of blank lines after declarations. Default: 367.Fl nsob . 368.Tp Fl st 369Causes 370.Nm indent 371to take its input from stdin, and put its output to stdout. 372.Tp Cx Fl T 373.Ar typename 374.Cx 375Adds 376.Ar typename 377to the list of type keywords. Names accumulate: 378.Fl T 379can be specified more than once. You need to specify all the typenames that 380appear in your program that are defined by 381.Ic typedef 382\- nothing will be 383harmed if you miss a few, but the program won't be formatted as nicely as 384it should. This sounds like a painful thing to have to do, but it's really 385a symptom of a problem in C: 386.Ic typedef 387causes a syntactic change in the 388language and 389.Nm indent 390can't find all 391instances of 392.Ic typedef . 393.Tp Fl troff 394Causes 395.Nm indent 396to format the program for processing by troff. It will produce a fancy 397listing in much the same spirit as 398.Xr vgrind 1 . 399If the output file is not specified, the default is standard output, 400rather than formatting in place. 401.Tp Fl v , nv 402.Fl v 403turns on `verbose' mode; 404.Fl nv 405turns it off. When in verbose mode, 406.Nm indent 407reports when it splits one line of input into two or more lines of output, 408and gives some size statistics at completion. The default is 409.Fl nv . 410.Tp 411.Pp 412You may set up your own `profile' of defaults to 413.Nm indent 414by creating a file called 415.Pa .indent.pro 416in your login directory and/or the current directory and including 417whatever switches you like. A `.indent.pro' in the current directory takes 418precedence over the one in your login directory. If 419.Nm indent 420is run and a profile file exists, then it is read to set up the program's 421defaults. Switches on the command line, though, always override profile 422switches. The switches should be separated by spaces, tabs or newlines. 423.Pp 424.Ss Comments 425.Sq Em Box 426.Em comments . 427.Nm Indent 428assumes that any comment with a dash or star immediately after the start of 429comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars. 430Each line of such a comment is left unchanged, except that its indentation 431may be adjusted to account for the change in indentation of the first line 432of the comment. 433.Pp 434.Em Straight text . 435All other comments are treated as straight text. 436.Nm Indent 437fits as many words (separated by blanks, tabs, or newlines) on a 438line as possible. Blank lines break paragraphs. 439.Pp 440.Ss Comment indentation 441If a comment is on a line with code it is started in the `comment column', 442which is set by the 443.Cx Fl c 444.Ar n 445.Cx 446command line parameter. Otherwise, the comment is started at 447.Ar n 448indentation levels less than where code is currently being placed, where 449.Ar n 450is specified by the 451.Cx Fl d 452.Ar n 453.Cx 454command line parameter. If the code on a line extends past the comment 455column, the comment starts further to the right, and the right margin may be 456automatically extended in extreme cases. 457.Pp 458.Ss Preprocessor lines 459In general, 460.Nm indent 461leaves preprocessor lines alone. The only 462reformatting that it will do is to straighten up trailing comments. It 463leaves embedded comments alone. Conditional compilation 464.Pq Ic #ifdef...#endif 465is recognized and 466.Nm indent 467attempts to correctly 468compensate for the syntactic peculiarities introduced. 469.Pp 470.Ss C syntax 471.Nm Indent 472understands a substantial amount about the syntax of C, but it 473has a `forgiving' parser. It attempts to cope with the usual sorts of 474incomplete and misformed syntax. In particular, the use of macros like: 475.Dl #define forever for(;;) 476is handled properly. 477.Sh ENVIRONMENT 478.Nm Indent 479uses the 480.Ev HOME 481environment variable. 482.Sh FILES 483.Dw \&./.indent.pro 484.Di L 485.Dp Pa \&./.indent.pro 486profile file 487.Dp Pa ~/.indent.pro 488profile file 489.Dp 490.Sh HISTORY 491.Nm Indent 492appeared in 4.2 BSD. 493.Sh BUGS 494.Nm Indent 495has even more switches than 496.Xr ls 1 . 497.Pp 498.ne 5 499A common mistake that often causes grief is typing: 500.Dl indent *.c 501to the shell in an attempt to indent all the 502.Nm C 503programs in a directory. 504This is probably a bug, not a feature. 505