INDENT(1) UNIX Programmer's Manual INDENT(1) NNAAMMEE indent - indent and format C program source SSYYNNOOPPSSIISS iinnddeenntt [ _i_n_p_u_t-_f_i_l_e [ _o_u_t_p_u_t-_f_i_l_e ] ] [ --bbaadd | --nnbbaadd ] [ --bbaapp | --nnbbaapp ] [ --bbbbbb | --nnbbbbbb ] [ --bbcc | --nnbbcc ] [ --bbll | --bbrr ] [ --cc_n ] [ --ccdd_n ] [ --ccddbb | --nnccddbb ] [ --ccee | --nnccee ] [ --ccii_n ] [ --ccllii_n ] [ --dd_n ] [ --ddii_n ] [ --ddjj | --nnddjj ] [ --eeii | --nneeii ] [ --ffcc11 | --nnffcc11 ] [ --ii_n ] [ --iipp | --nniipp ] [ --ll_n ] [ --llcc_n ] [ --llpp | --nnllpp ] [ --nnpprroo ] [ --ppccss | --nnppccss ] [ --ppss | --nnppss ] [ --ppssll | --nnppssll ] [ --sscc | --nnsscc ] [ --ssoobb | --nnssoobb ] [ --sstt ] [ --ttrrooffff ] [ --vv | --nnvv ] DDEESSCCRRIIPPTTIIOONN _I_n_d_e_n_t is a CC program formatter. It reformats the CC program in the _i_n_p_u_t-_f_i_l_e according to the switches. The switches which can be specified are described below. They may appear before or after the file names. NNOOTTEE: If you only specify an _i_n_p_u_t-_f_i_l_e, the formatting is done `in-place', that is, the formatted file is written back into _i_n_p_u_t-_f_i_l_e and a backup copy of _i_n_p_u_t-_f_i_l_e is written in the current directory. If _i_n_p_u_t-_f_i_l_e is named `/blah/blah/file', the backup file is named file._B_A_K. If _o_u_t_p_u_t-_f_i_l_e is specified, _i_n_d_e_n_t checks to make sure it is different from _i_n_p_u_t-_f_i_l_e. OOPPTTIIOONNSS The options listed below control the formatting style imposed by _i_n_d_e_n_t. --bbaadd,--nnbbaadd If --bbaadd is specified, a blank line is forced after every block of declarations. Default: --nnbbaadd. --bbaapp,--nnbbaapp If --bbaapp is specified, a blank line is forced after every procedure body. Default: --nnbbaapp.. --bbbbbb,--nnbbbbbb If --bbbbbb is specified, a blank line is forced before every block comment. Default: --nnbbbbbb.. --bbcc,--nnbbcc If --bbcc is specified, then a newline is forced after each comma in a declaration. --nnbbcc turns off this option. The default is --nnbbcc. --bbrr,--bbll Specifying --bbll lines up compound statements like this: if (...) { code Printed 7/9/88 September 10, 1985 1 INDENT(1) UNIX Programmer's Manual INDENT(1) } Specifying --bbrr (the default) makes them look like this: if (...) { code } --cc_n The column in which comments on code start. The default is 33. --ccdd_n The column in which comments on declarations start. The default is for these comments to start in the same column as those on code. --ccddbb,--nnccddbb Enables (disables) the placement of comment delimiters on blank lines. With this option enabled, comments look like this: /* * this is a comment */ Rather than like this: /* this is a comment */ This only affects block comments, not com- ments to the right of code. The default is --ccddbb. --ccee,--nnccee Enables (disables) forcing `else's to cuddle up to the immediately preceding `}'. The default is --ccee. --ccii_n Sets the continuation indent to be _n. Con- tinuation lines will be indented that far from the beginning of the first line of the statement. Parenthesized expressions have extra indentation added to indicate the nest- ing, unless --llpp is in effect. --ccii defaults to the same value as --ii. --ccllii_n Causes case labels to be indented _n tab stops to the right of the containing sswwiittcchh state- ment. --ccllii00..55 causes case labels to be indented half a tab stop. The default is --ccllii00. (This is the only option that takes a fractional argument.) --dd_n Controls the placement of comments which are not to the right of code. Specifying --dd11 means that such comments are placed one indentation level to the left of code. The default --dd00 lines up these comments with the code. See the section on comment indentation below. Printed 7/9/88 September 10, 1985 2 INDENT(1) UNIX Programmer's Manual INDENT(1) --ddii_n Specifies the indentation, in character posi- tions, from a declaration keyword to the fol- lowing identifier. The default is --ddii1166. --ddjj,--nnddjj --ddjj left justifies declarations. --nnddjj indents declarations the same as code. The default is --nnddjj. --eeii,--nneeii Enables (disables) special eellssee--iiff process- ing. If enabled, iiffs following eellssees will have the same indentation as the preceding iiff statement. The default is --eeii. --ffcc11,--nnffcc11 Enables (disables) the formatting of comments that start in column 1. Often, comments whose leading `/' is in column 1 have been carefully hand formatted by the programmer. In such cases, --nnffcc11 should be used. The default is --ffcc11. --ii_n The number of spaces for one indentation level. The default is 8. --iipp,--nniipp Enables (disables) the indentation of parame- ter declarations from the left margin. The default is --iipp. --ll_n Maximum length of an output line. The default is 78. --llpp,--nnllpp Lines up code surrounded by parenthesis in continuation lines. If a line has a left paren which is not closed on that line, then continuation lines will be lined up to start at the character position just after the left paren. For example, here is how a piece of continued code looks with --nnllpp in effect: p1 = first_procedure(second_procedure(p2, p3), third_procedure(p4, p5)); With --llpp in effect (the default) the code looks somewhat clearer: p1 = first_procedure(second_procedure(p2, p3), third_procedure(p4, p5)); Inserting two more newlines we get: p1 = first_procedure(second_procedure(p2, p3), third_procedure(p4, p5)); --nnpprroo Causes the profile files, `./.indent.pro' and `~/.indent.pro', to be ignored. Printed 7/9/88 September 10, 1985 3 INDENT(1) UNIX Programmer's Manual INDENT(1) --ppccss,--nnppccss If true (--ppccss) all procedure calls will have a space inserted between the name and the `('. The default is --nnppccss. --ppss,--nnppss If true (--ppss) the pointer following operator `->' will be surrounded by spaces on either side. The default is --nnppss. --ppssll,--nnppssll If true (--ppssll) the names of procedures being defined are placed in column 1 - their types, if any, will be left on the previous lines. The default is --ppssll. --sscc,--nnsscc Enables (disables) the placement of asterisks (`*'s) at the left edge of all comments. The default is --sscc. --ssoobb,--nnssoobb If --ssoobb is specified, indent will swallow optional blank lines. You can use this to get rid of blank lines after declarations. Default: --nnssoobb. --sstt Causes iinnddeenntt to take its input from stdin, and put its output to stdout. --TT_t_y_p_e_n_a_m_e Adds _t_y_p_e_n_a_m_e to the list of type keywords. Names accumulate: --TT can be specified more than once. You need to specify all the typenames that appear in your program that are defined by ttyyppeeddeeffs - nothing will be harmed if you miss a few, but the program won't be formatted as nicely as it should. This sounds like a painful thing to have to do, but it's really a symptom of a problem in C: ttyyppeeddeeff causes a syntactic change in the language and _i_n_d_e_n_t can't find all ttyyppeeddeeffs. --ttrrooffff Causes iinnddeenntt to format the program for pro- cessing by troff. It will produce a fancy listing in much the same spirit as vvggrriinndd. If the output file is not specified, the default is standard output, rather than for- matting in place. --vv,--nnvv --vv turns on `verbose' mode; --nnvv turns it off. When in verbose mode, _i_n_d_e_n_t reports when it splits one line of input into two or more lines of output, and gives some size statis- tics at completion. The default is --nnvv. FFUURRTTHHEERR DDEESSCCRRIIPPTTIIOONN Printed 7/9/88 September 10, 1985 4 INDENT(1) UNIX Programmer's Manual INDENT(1) You may set up your own `profile' of defaults to _i_n_d_e_n_t by creating a file called .._i_n_d_e_n_t.._p_r_o in either your login directory and/or the current directory and including what- ever switches you like. Switches in `.indent.pro' in the current directory override those in your login directory (with the exception of --TT type definitions, which just accu- mulate). If _i_n_d_e_n_t is run and a profile file exists, then it is read to set up the program's defaults. The switches should be separated by spaces, tabs or newlines. Switches on the command line, however, override profile switches. CCoommmmeennttss `_B_o_x' _c_o_m_m_e_n_t_s. _I_n_d_e_n_t assumes that any comment with a dash or star immediately after the start of comment (that is, `/*-' or `/**') is a comment surrounded by a box of stars. Each line of such a comment is left unchanged, except that its indentation may be adjusted to account for the change in indentation of the first line of the comment. _S_t_r_a_i_g_h_t _t_e_x_t. All other comments are treated as straight text. _I_n_d_e_n_t fits as many words (separated by blanks, tabs, or newlines) on a line as possible. Blank lines break para- graphs. CCoommmmeenntt iinnddeennttaattiioonn If a comment is on a line with code it is started in the `comment column', which is set by the --cc_n command line parameter. Otherwise, the comment is started at _n indenta- tion levels less than where code is currently being placed, where _n is specified by the --dd_n command line parameter. If the code on a line extends past the comment column, the com- ment starts further to the right, and the right margin may be automatically extended in extreme cases. PPrreepprroocceessssoorr lliinneess In general, _i_n_d_e_n_t leaves preprocessor lines alone. The only reformatting that it will do is to straighten up trail- ing comments. It leaves embedded comments alone. Condi- tional compilation (##iiffddeeff......##eennddiiff) is recognized and _i_n_d_e_n_t attempts to correctly compensate for the syntactic peculiarities introduced. CC ssyynnttaaxx _I_n_d_e_n_t understands a substantial amount about the syntax of C, but it has a `forgiving' parser. It attempts to cope with the usual sorts of incomplete and misformed syntax. In particular, the use of macros like: #define forever for(;;) Printed 7/9/88 September 10, 1985 5 INDENT(1) UNIX Programmer's Manual INDENT(1) is handled properly. FFIILLEESS ./.indent.pro profile file ~/.indent.pro profile file BBUUGGSS _I_n_d_e_n_t has even more switches than _l_s. A common mistake that often causes grief is typing: indent *.c to the shell in an attempt to indent all the CC programs in a directory. This is probably a bug, not a feature. Printed 7/9/88 September 10, 1985 6