xref: /freebsd/usr.bin/indent/indent.1 (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
19b50d902SRodney W. Grimes.\" Copyright (c) 1980, 1990, 1993
29b50d902SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
39b50d902SRodney W. Grimes.\" Copyright (c) 1976 Board of Trustees of the University of Illinois.
49b50d902SRodney W. Grimes.\" All rights reserved.
59b50d902SRodney W. Grimes.\"
69b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
79b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions
89b50d902SRodney W. Grimes.\" are met:
99b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
109b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
119b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
129b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
139b50d902SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
14dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors
159b50d902SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
169b50d902SRodney W. Grimes.\"    without specific prior written permission.
179b50d902SRodney W. Grimes.\"
189b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
209b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219b50d902SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
229b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
239b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
249b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
259b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
269b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
279b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289b50d902SRodney W. Grimes.\" SUCH DAMAGE.
299b50d902SRodney W. Grimes.\"
30*b5b9eaa9SDag-Erling Smørgrav.Dd June 28, 2023
319b50d902SRodney W. Grimes.Dt INDENT 1
3262500372SRuslan Ermilov.Os
339b50d902SRodney W. Grimes.Sh NAME
349b50d902SRodney W. Grimes.Nm indent
359b50d902SRodney W. Grimes.Nd indent and format C program source
369b50d902SRodney W. Grimes.Sh SYNOPSIS
37958d7c9fSPhilippe Charnier.Nm
389b50d902SRodney W. Grimes.Op Ar input-file Op Ar output-file
39d1b25cd9SEitan Adler.Op Fl bacc | Fl nbacc
409b50d902SRodney W. Grimes.Op Fl bad | Fl nbad
4186bd08e9SPedro F. Giffuni.Op Fl badp | Fl nbadp
429b50d902SRodney W. Grimes.Op Fl bap | Fl nbap
439b50d902SRodney W. Grimes.Op Fl bbb | Fl nbbb
449b50d902SRodney W. Grimes.Op Fl \&bc | Fl nbc
455834814eSPiotr Pawel Stefaniak.Op Fl \&bl | Fl \&br
4686bd08e9SPedro F. Giffuni.Op Fl bs | Fl nbs
479b50d902SRodney W. Grimes.Op Fl c Ns Ar n
489b50d902SRodney W. Grimes.Op Fl \&cd Ns Ar n
499b50d902SRodney W. Grimes.Bk -words
509b50d902SRodney W. Grimes.Op Fl cdb | Fl ncdb
519b50d902SRodney W. Grimes.Ek
529b50d902SRodney W. Grimes.Op Fl \&ce | Fl nce
539b50d902SRodney W. Grimes.Op Fl \&ci Ns Ar n
549b50d902SRodney W. Grimes.Op Fl cli Ns Ar n
55bb92a28bSPiotr Pawel Stefaniak.Op Fl cs | Fl ncs
569b50d902SRodney W. Grimes.Op Fl d Ns Ar n
579b50d902SRodney W. Grimes.Op Fl \&di Ns Ar n
585834814eSPiotr Pawel Stefaniak.Op Fl dj | Fl ndj
595834814eSPiotr Pawel Stefaniak.Bk -words
605834814eSPiotr Pawel Stefaniak.Op Fl ei | Fl nei
615834814eSPiotr Pawel Stefaniak.Op Fl eei | Fl neei
625834814eSPiotr Pawel Stefaniak.Ek
639b50d902SRodney W. Grimes.Bk -words
645ac16458SJens Schweikhardt.Op Fl fbs | Fl nfbs
659b50d902SRodney W. Grimes.Op Fl fc1 | Fl nfc1
66a5e1cac0SDavid E. O'Brien.Op Fl fcb | Fl nfcb
679b50d902SRodney W. Grimes.Ek
689b50d902SRodney W. Grimes.Op Fl i Ns Ar n
699b50d902SRodney W. Grimes.Op Fl \&ip | Fl nip
709b50d902SRodney W. Grimes.Op Fl l Ns Ar n
719b50d902SRodney W. Grimes.Op Fl \&lc Ns Ar n
7288ce0e7fSBruce Evans.Op Fl \&ldi Ns Ar n
739b50d902SRodney W. Grimes.Op Fl \&lp | Fl nlp
74aac30b75SPiotr Pawel Stefaniak.Op Fl \&lpl | Fl nlpl
759b50d902SRodney W. Grimes.Op Fl npro
7686adac04SPiotr Pawel Stefaniak.Op Fl P Ns Ar file
779b50d902SRodney W. Grimes.Op Fl pcs | Fl npcs
78*b5b9eaa9SDag-Erling Smørgrav.Op Fl ps | Fl nps
799b50d902SRodney W. Grimes.Op Fl psl | Fl npsl
809b50d902SRodney W. Grimes.Op Fl \&sc | Fl nsc
819b50d902SRodney W. Grimes.Bk -words
829b50d902SRodney W. Grimes.Op Fl sob | Fl nsob
839b50d902SRodney W. Grimes.Ek
849b50d902SRodney W. Grimes.Op Fl \&st
85c58c7416SAndriy Gapon.Op Fl \&ta
865834814eSPiotr Pawel Stefaniak.Op Fl T Ns Ar typename
87fbdbd284SPiotr Pawel Stefaniak.Op Fl ts Ns Ar n
88771aff0aSPedro F. Giffuni.Op Fl U Ns Ar file
895ac16458SJens Schweikhardt.Op Fl ut | Fl nut
909b50d902SRodney W. Grimes.Op Fl v | Fl \&nv
91d0f86f66SPiotr Pawel Stefaniak.Op Fl -version
929b50d902SRodney W. Grimes.Sh DESCRIPTION
93e8937ba0SPhilippe CharnierThe
94e8937ba0SPhilippe Charnier.Nm
95e8937ba0SPhilippe Charnierutility is a
96e8937ba0SPhilippe Charnier.Em C
976a3e8b0aSRuslan Ermilovprogram formatter.
986a3e8b0aSRuslan ErmilovIt reformats the
99e8937ba0SPhilippe Charnier.Em C
1009b50d902SRodney W. Grimesprogram in the
1019b50d902SRodney W. Grimes.Ar input-file
1026a3e8b0aSRuslan Ermilovaccording to the switches.
1036a3e8b0aSRuslan ErmilovThe switches which can be
1046a3e8b0aSRuslan Ermilovspecified are described below.
1056a3e8b0aSRuslan ErmilovThey may appear before or after the file
1069b50d902SRodney W. Grimesnames.
1079b50d902SRodney W. Grimes.Pp
1089b50d902SRodney W. Grimes.Sy NOTE :
1099b50d902SRodney W. GrimesIf you only specify an
1109b50d902SRodney W. Grimes.Ar input-file ,
1119b50d902SRodney W. Grimesthe formatting is
1129b50d902SRodney W. Grimesdone `in-place', that is, the formatted file is written back into
1139b50d902SRodney W. Grimes.Ar input-file
1149b50d902SRodney W. Grimesand a backup copy of
1159b50d902SRodney W. Grimes.Ar input-file
1166a3e8b0aSRuslan Ermilovis written in the current directory.
1176a3e8b0aSRuslan ErmilovIf
1189b50d902SRodney W. Grimes.Ar input-file
1199b50d902SRodney W. Grimesis named
1209b50d902SRodney W. Grimes.Sq Pa /blah/blah/file ,
1219b50d902SRodney W. Grimesthe backup file is named
122c6841b07SKyle Evans.Sq Pa file.BAK
1233d265fceSGordon Berglingby default.
1243d265fceSGordon BerglingThe extension used for the backup file may be overridden using the
125c6841b07SKyle Evans.Ev SIMPLE_BACKUP_SUFFIX
126c6841b07SKyle Evansenvironment variable.
1279b50d902SRodney W. Grimes.Pp
1289b50d902SRodney W. GrimesIf
1299b50d902SRodney W. Grimes.Ar output-file
1309b50d902SRodney W. Grimesis specified,
131958d7c9fSPhilippe Charnier.Nm
132fa5c581cSCeri Davieschecks to make sure that it is different from
1339b50d902SRodney W. Grimes.Ar input-file .
1349b50d902SRodney W. Grimes.Pp
1359b50d902SRodney W. GrimesThe options listed below control the formatting style imposed by
1368fe908efSRuslan Ermilov.Nm .
1379b50d902SRodney W. Grimes.Bl -tag -width Op
138d1b25cd9SEitan Adler.It Fl bacc , nbacc
139d1b25cd9SEitan AdlerIf
140d1b25cd9SEitan Adler.Fl bacc
141d1b25cd9SEitan Adleris specified, a blank line is forced around every conditional
142d1b25cd9SEitan Adlercompilation block.
143d1b25cd9SEitan AdlerFor example, in front of every #ifdef and after every #endif.
144d1b25cd9SEitan AdlerOther blank lines surrounding such blocks will be swallowed.
145d1b25cd9SEitan AdlerDefault:
146d1b25cd9SEitan Adler.Fl nbacc  .
1479b50d902SRodney W. Grimes.It Fl bad , nbad
1489b50d902SRodney W. GrimesIf
1499b50d902SRodney W. Grimes.Fl bad
1509b50d902SRodney W. Grimesis specified, a blank line is forced after every block of
1516a3e8b0aSRuslan Ermilovdeclarations.
1526a3e8b0aSRuslan ErmilovDefault:
1539b50d902SRodney W. Grimes.Fl nbad .
15486bd08e9SPedro F. Giffuni.It Fl badp , nbadp
15586bd08e9SPedro F. GiffuniThis is vaguely similar to
15686bd08e9SPedro F. Giffuni.Fl bad
157bde60d75SPedro F. Giffuniexcept that it only applies to the first set of declarations
15886bd08e9SPedro F. Giffuniin a procedure (just after the first `{') and it causes a blank
15986bd08e9SPedro F. Giffuniline to be generated even if there are no declarations.
16086bd08e9SPedro F. GiffuniThe default is
16186bd08e9SPedro F. Giffuni.Fl nbadp .
1629b50d902SRodney W. Grimes.It Fl bap , nbap
1639b50d902SRodney W. GrimesIf
1649b50d902SRodney W. Grimes.Fl bap
1656a3e8b0aSRuslan Ermilovis specified, a blank line is forced after every procedure body.
1666a3e8b0aSRuslan ErmilovDefault:
1679b50d902SRodney W. Grimes.Fl nbap .
1689b50d902SRodney W. Grimes.It Fl bbb , nbbb
1699b50d902SRodney W. GrimesIf
1709b50d902SRodney W. Grimes.Fl bbb
1716a3e8b0aSRuslan Ermilovis specified, a blank line is forced before every block comment.
1726a3e8b0aSRuslan ErmilovDefault:
1739b50d902SRodney W. Grimes.Fl nbbb .
1749b50d902SRodney W. Grimes.It Fl \&bc , nbc
1759b50d902SRodney W. GrimesIf
1769b50d902SRodney W. Grimes.Fl \&bc
1779b50d902SRodney W. Grimesis specified, then a newline is forced after each comma in a declaration.
1789b50d902SRodney W. Grimes.Fl nbc
1796a3e8b0aSRuslan Ermilovturns off this option.
1806a3e8b0aSRuslan ErmilovDefault:
1815b9513b2STim Vanderhoek.Fl \&nbc .
1825834814eSPiotr Pawel Stefaniak.It Fl \&bl , \&br
1839b50d902SRodney W. GrimesSpecifying
1849b50d902SRodney W. Grimes.Fl \&bl
1855834814eSPiotr Pawel Stefaniaklines up compound statements like this:
1869b50d902SRodney W. Grimes.Bd -literal -offset indent
1879b50d902SRodney W. Grimesif (...)
1889b50d902SRodney W. Grimes{
1899b50d902SRodney W. Grimes  code
1909b50d902SRodney W. Grimes}
1919b50d902SRodney W. Grimes.Ed
1929b50d902SRodney W. Grimes.Pp
1939b50d902SRodney W. GrimesSpecifying
1949b50d902SRodney W. Grimes.Fl \&br
1959b50d902SRodney W. Grimes(the default) makes them look like this:
1969b50d902SRodney W. Grimes.Bd -literal -offset indent
1979b50d902SRodney W. Grimesif (...) {
1989b50d902SRodney W. Grimes  code
1999b50d902SRodney W. Grimes}
2009b50d902SRodney W. Grimes.Ed
20186bd08e9SPedro F. Giffuni.It Fl bs , nbs
20286bd08e9SPedro F. GiffuniWhether a blank should always be inserted after sizeof.
20386bd08e9SPedro F. GiffuniThe default is
20486bd08e9SPedro F. Giffuni.Fl nbs .
205287c7db4SSteve Price.It Fl c Ns Ar n
2066a3e8b0aSRuslan ErmilovThe column in which comments on code start.
2076a3e8b0aSRuslan ErmilovThe default is 33.
208287c7db4SSteve Price.It Fl cd Ns Ar n
2096a3e8b0aSRuslan ErmilovThe column in which comments on declarations start.
2106a3e8b0aSRuslan ErmilovThe default
2119b50d902SRodney W. Grimesis for these comments to start in the same column as those on code.
2129b50d902SRodney W. Grimes.It Fl cdb , ncdb
2136a3e8b0aSRuslan ErmilovEnables (disables) the placement of comment delimiters on blank lines.
2146a3e8b0aSRuslan ErmilovWith
2159b50d902SRodney W. Grimesthis option enabled, comments look like this:
2169b50d902SRodney W. Grimes.Bd -literal -offset indent
2179b50d902SRodney W. Grimes	/*
2189b50d902SRodney W. Grimes	 * this is a comment
2199b50d902SRodney W. Grimes	 */
2209b50d902SRodney W. Grimes.Ed
2219b50d902SRodney W. Grimes.Pp
2229b50d902SRodney W. GrimesRather than like this:
2239b50d902SRodney W. Grimes.Bd -literal -offset indent
2249b50d902SRodney W. Grimes	/* this is a comment */
2259b50d902SRodney W. Grimes.Ed
2269b50d902SRodney W. Grimes.Pp
2279b50d902SRodney W. GrimesThis only affects block comments, not comments to the right of
2286a3e8b0aSRuslan Ermilovcode.
2296a3e8b0aSRuslan ErmilovThe default is
2309b50d902SRodney W. Grimes.Fl cdb .
2319b50d902SRodney W. Grimes.It Fl ce , nce
2325b9513b2STim VanderhoekEnables (disables) forcing of `else's to cuddle up to the immediately preceding
2336a3e8b0aSRuslan Ermilov`}'.
2346a3e8b0aSRuslan ErmilovThe default is
2359b50d902SRodney W. Grimes.Fl \&ce .
2369b50d902SRodney W. Grimes.It Fl \&ci Ns Ar n
2379b50d902SRodney W. GrimesSets the continuation indent to be
2389b50d902SRodney W. Grimes.Ar n .
2399b50d902SRodney W. GrimesContinuation
2409b50d902SRodney W. Grimeslines will be indented that far from the beginning of the first line of the
2416a3e8b0aSRuslan Ermilovstatement.
2426a3e8b0aSRuslan ErmilovParenthesized expressions have extra indentation added to
2439b50d902SRodney W. Grimesindicate the nesting, unless
2449b50d902SRodney W. Grimes.Fl \&lp
245a55a608eSBruce Evansis in effect
2466fb9b618SGiorgos Keramidasor the continuation indent is exactly half of the main indent.
2479b50d902SRodney W. Grimes.Fl \&ci
2489b50d902SRodney W. Grimesdefaults to the same value as
2499b50d902SRodney W. Grimes.Fl i .
2509b50d902SRodney W. Grimes.It Fl cli Ns Ar n
2519b50d902SRodney W. GrimesCauses case labels to be indented
2529b50d902SRodney W. Grimes.Ar n
2539b50d902SRodney W. Grimestab stops to the right of the containing
2549b50d902SRodney W. Grimes.Ic switch
2559b50d902SRodney W. Grimesstatement.
2569b50d902SRodney W. Grimes.Fl cli0.5
2576a3e8b0aSRuslan Ermilovcauses case labels to be indented half a tab stop.
2586a3e8b0aSRuslan ErmilovThe
2599b50d902SRodney W. Grimesdefault is
2609b50d902SRodney W. Grimes.Fl cli0 .
261bb92a28bSPiotr Pawel Stefaniak.It Fl cs , ncs
262bb92a28bSPiotr Pawel StefaniakControl whether parenthesized type names in casts are followed by a space or
263bb92a28bSPiotr Pawel Stefaniaknot.
264bb92a28bSPiotr Pawel StefaniakThe default is
265bb92a28bSPiotr Pawel Stefaniak.Fl ncs .
2669b50d902SRodney W. Grimes.It Fl d Ns Ar n
2679b50d902SRodney W. GrimesControls the placement of comments which are not to the
2686a3e8b0aSRuslan Ermilovright of code.
2696a3e8b0aSRuslan ErmilovFor example,
2709b50d902SRodney W. Grimes.Fl \&d\&1
2719b50d902SRodney W. Grimesmeans that such comments are placed one indentation level to the
2726a3e8b0aSRuslan Ermilovleft of code.
2736a3e8b0aSRuslan ErmilovSpecifying the default
2749b50d902SRodney W. Grimes.Fl \&d\&0
2755834814eSPiotr Pawel Stefaniaklines up these comments with the code.
2766a3e8b0aSRuslan ErmilovSee the section on comment
2779b50d902SRodney W. Grimesindentation below.
2789b50d902SRodney W. Grimes.It Fl \&di Ns Ar n
27988ce0e7fSBruce EvansSpecifies the indentation, in character positions,
28088ce0e7fSBruce Evansof global variable names and all struct/union member names
28188ce0e7fSBruce Evansrelative to the beginning of their type declaration.
28288ce0e7fSBruce EvansThe default is
2839b50d902SRodney W. Grimes.Fl di16 .
2849b50d902SRodney W. Grimes.It Fl dj , ndj
2859b50d902SRodney W. Grimes.Fl \&dj
2869b50d902SRodney W. Grimesleft justifies declarations.
2879b50d902SRodney W. Grimes.Fl ndj
2886a3e8b0aSRuslan Ermilovindents declarations the same as code.
2896a3e8b0aSRuslan ErmilovThe default is
2909b50d902SRodney W. Grimes.Fl ndj .
2919b50d902SRodney W. Grimes.It Fl \&ei , nei
2929b50d902SRodney W. GrimesEnables (disables) special
2939b50d902SRodney W. Grimes.Ic else-if
2946a3e8b0aSRuslan Ermilovprocessing.
29536a142c4SRuslan ErmilovIf it is enabled, an
2969b50d902SRodney W. Grimes.Ic if
2979b50d902SRodney W. Grimesfollowing an
2989b50d902SRodney W. Grimes.Ic else
2999b50d902SRodney W. Grimeswill have the same indentation as the preceding
3009b50d902SRodney W. Grimes.Ic \&if
3016a3e8b0aSRuslan Ermilovstatement.
3026a3e8b0aSRuslan ErmilovThe default is
3035b9513b2STim Vanderhoek.Fl ei .
304d1b25cd9SEitan Adler.It Fl eei , neei
305d1b25cd9SEitan AdlerEnables (disables) extra indentation on continuation lines of
306d1b25cd9SEitan Adlerthe expression part of
307d1b25cd9SEitan Adler.Ic if
308d1b25cd9SEitan Adlerand
309d1b25cd9SEitan Adler.Ic while
310d1b25cd9SEitan Adlerstatements.
311d1b25cd9SEitan AdlerThese continuation lines will be indented one extra level.
312d1b25cd9SEitan AdlerThe default is
313d1b25cd9SEitan Adler.Fl neei .
3145ac16458SJens Schweikhardt.It Fl fbs , nfbs
3155ac16458SJens SchweikhardtEnables (disables) splitting the function declaration and opening brace
3165ac16458SJens Schweikhardtacross two lines.
3175ac16458SJens SchweikhardtThe default is
3185ac16458SJens Schweikhardt.Fl fbs .
3199b50d902SRodney W. Grimes.It Fl fc1 , nfc1
3209b50d902SRodney W. GrimesEnables (disables) the formatting of comments that start in column 1.
3219b50d902SRodney W. GrimesOften, comments whose leading `/' is in column 1 have been carefully
3226a3e8b0aSRuslan Ermilovhand formatted by the programmer.
3236a3e8b0aSRuslan ErmilovIn such cases,
3249b50d902SRodney W. Grimes.Fl nfc1
3259b50d902SRodney W. Grimesshould be
3266a3e8b0aSRuslan Ermilovused.
3276a3e8b0aSRuslan ErmilovThe default is
3289b50d902SRodney W. Grimes.Fl fc1 .
329a5e1cac0SDavid E. O'Brien.It Fl fcb , nfcb
330a5e1cac0SDavid E. O'BrienEnables (disables) the formatting of block comments (ones that begin
3311261f234SDavid E. O'Brienwith `/*\\n').
3321261f234SDavid E. O'BrienOften, block comments have been not so carefully hand formatted by the
3331261f234SDavid E. O'Brienprogrammer, but reformatting that would just change the line breaks is not
3341261f234SDavid E. O'Brienwanted.
3351261f234SDavid E. O'BrienIn such cases,
336a5e1cac0SDavid E. O'Brien.Fl nfcb
3371261f234SDavid E. O'Brienshould be used.
3381261f234SDavid E. O'BrienBlock comments are then handled like box comments.
339a5e1cac0SDavid E. O'BrienThe default is
340a5e1cac0SDavid E. O'Brien.Fl fcb .
3419b50d902SRodney W. Grimes.It Fl i Ns Ar n
3425834814eSPiotr Pawel StefaniakThe number of columns for one indentation level.
3436a3e8b0aSRuslan ErmilovThe default is 8.
3449b50d902SRodney W. Grimes.It Fl \&ip , nip
3459b50d902SRodney W. GrimesEnables (disables) the indentation of parameter declarations from the left
3466a3e8b0aSRuslan Ermilovmargin.
3476a3e8b0aSRuslan ErmilovThe default is
3489b50d902SRodney W. Grimes.Fl \&ip .
3499b50d902SRodney W. Grimes.It Fl l Ns Ar n
3506a3e8b0aSRuslan ErmilovMaximum length of an output line.
3516a3e8b0aSRuslan ErmilovThe default is 78.
35286bd08e9SPedro F. Giffuni.It Fl lc Ns Ar n
35386bd08e9SPedro F. GiffuniMaximum length of an output line in a block comment.
35486bd08e9SPedro F. GiffuniThe default is 0, which means to limit block comment lines in accordance with
35586bd08e9SPedro F. Giffuni.Fl l .
35688ce0e7fSBruce Evans.It Fl \&ldi Ns Ar n
35788ce0e7fSBruce EvansSpecifies the indentation, in character positions,
35888ce0e7fSBruce Evansof local variable names
35988ce0e7fSBruce Evansrelative to the beginning of their type declaration.
36088ce0e7fSBruce EvansThe default is for local variable names to be indented
36188ce0e7fSBruce Evansby the same amount as global ones.
3629b50d902SRodney W. Grimes.It Fl \&lp , nlp
3635834814eSPiotr Pawel StefaniakLines up code surrounded by parentheses in continuation lines.
364aac30b75SPiotr Pawel StefaniakWith
365aac30b75SPiotr Pawel Stefaniak.Fl \&lp ,
366aac30b75SPiotr Pawel Stefaniakif a line
3679b50d902SRodney W. Grimeshas a left paren which is not closed on that line, then continuation lines
3689b50d902SRodney W. Grimeswill be lined up to start at the character position just after the left
3696a3e8b0aSRuslan Ermilovparen.
3706a3e8b0aSRuslan ErmilovFor example, here is how a piece of continued code looks with
3719b50d902SRodney W. Grimes.Fl nlp
3729b50d902SRodney W. Grimesin effect:
3739b50d902SRodney W. Grimes.Bd -literal -offset indent
3749b50d902SRodney W. Grimesp1 = first_procedure(second_procedure(p2, p3),
3759b50d902SRodney W. Grimes\ \ third_procedure(p4, p5));
3769b50d902SRodney W. Grimes.Ed
3779b50d902SRodney W. Grimes.Pp
3789b50d902SRodney W. GrimesWith
3799b50d902SRodney W. Grimes.Fl lp
3809b50d902SRodney W. Grimesin effect (the default) the code looks somewhat clearer:
3819b50d902SRodney W. Grimes.Bd -literal -offset indent
3829b50d902SRodney W. Grimesp1\ =\ first_procedure(second_procedure(p2,\ p3),
383287c7db4SSteve Price\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
3849b50d902SRodney W. Grimes.Ed
3859b50d902SRodney W. Grimes.Pp
3869b50d902SRodney W. GrimesInserting two more newlines we get:
3879b50d902SRodney W. Grimes.Bd -literal -offset indent
3889b50d902SRodney W. Grimesp1\ =\ first_procedure(second_procedure(p2,
3899b50d902SRodney W. Grimes\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
390287c7db4SSteve Price\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
3919b50d902SRodney W. Grimes\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
3929b50d902SRodney W. Grimes.Ed
393aac30b75SPiotr Pawel Stefaniak.It Fl \&lpl , nlpl
394aac30b75SPiotr Pawel StefaniakWith
395aac30b75SPiotr Pawel Stefaniak.Fl \&lpl ,
396aac30b75SPiotr Pawel Stefaniakcode surrounded by parentheses in continuation lines is lined up even if it
397aac30b75SPiotr Pawel Stefaniakwould extend past the right margin.
398aac30b75SPiotr Pawel StefaniakWith
399aac30b75SPiotr Pawel Stefaniak.Fl \&nlpl
400aac30b75SPiotr Pawel Stefaniak(the default), such a line that would extend past the right margin is moved
401aac30b75SPiotr Pawel Stefaniakleft to keep it within the margin, if that does not require placing it to
402aac30b75SPiotr Pawel Stefaniakthe left of the prevailing indentation level.
403aac30b75SPiotr Pawel StefaniakThese switches have no effect if
404aac30b75SPiotr Pawel Stefaniak.Fl nlp
405aac30b75SPiotr Pawel Stefaniakis selected.
4069b50d902SRodney W. Grimes.It Fl npro
4079b50d902SRodney W. GrimesCauses the profile files,
4089b50d902SRodney W. Grimes.Sq Pa ./.indent.pro
4099b50d902SRodney W. Grimesand
4109b50d902SRodney W. Grimes.Sq Pa ~/.indent.pro ,
4119b50d902SRodney W. Grimesto be ignored.
41286adac04SPiotr Pawel Stefaniak.It Fl P Ns Ar file
41386adac04SPiotr Pawel StefaniakRead profile from
41486adac04SPiotr Pawel Stefaniak.Ar file .
4159b50d902SRodney W. Grimes.It Fl pcs , npcs
4169b50d902SRodney W. GrimesIf true
4179b50d902SRodney W. Grimes.Pq Fl pcs
4189b50d902SRodney W. Grimesall procedure calls will have a space inserted between
4196a3e8b0aSRuslan Ermilovthe name and the `('.
4206a3e8b0aSRuslan ErmilovThe default is
4219b50d902SRodney W. Grimes.Fl npcs .
422*b5b9eaa9SDag-Erling Smørgrav.It Fl ps , nps
423*b5b9eaa9SDag-Erling SmørgravIf true
424*b5b9eaa9SDag-Erling Smørgrav.Pq Fl ps
425*b5b9eaa9SDag-Erling Smørgravthe pointer dereference operator (`->') is treated like any other
426*b5b9eaa9SDag-Erling Smørgravbinary operator.
427*b5b9eaa9SDag-Erling SmørgravThe default is
428*b5b9eaa9SDag-Erling Smørgrav.Fl nps .
4299b50d902SRodney W. Grimes.It Fl psl , npsl
4309b50d902SRodney W. GrimesIf true
4319b50d902SRodney W. Grimes.Pq Fl psl
4329b50d902SRodney W. Grimesthe names of procedures being defined are placed in
4336a3e8b0aSRuslan Ermilovcolumn 1 \- their types, if any, will be left on the previous lines.
4346a3e8b0aSRuslan ErmilovThe
4359b50d902SRodney W. Grimesdefault is
4369b50d902SRodney W. Grimes.Fl psl .
4379b50d902SRodney W. Grimes.It Fl \&sc , nsc
4389b50d902SRodney W. GrimesEnables (disables) the placement of asterisks (`*'s) at the left edge of all
4396a3e8b0aSRuslan Ermilovcomments.
4406a3e8b0aSRuslan ErmilovThe default is
4415b9513b2STim Vanderhoek.Fl sc .
4429b50d902SRodney W. Grimes.It Fl sob , nsob
4439b50d902SRodney W. GrimesIf
4449b50d902SRodney W. Grimes.Fl sob
4456a3e8b0aSRuslan Ermilovis specified, indent will swallow optional blank lines.
4466a3e8b0aSRuslan ErmilovYou can use this to
4476a3e8b0aSRuslan Ermilovget rid of blank lines after declarations.
4486a3e8b0aSRuslan ErmilovDefault:
4499b50d902SRodney W. Grimes.Fl nsob .
4509b50d902SRodney W. Grimes.It Fl \&st
4519b50d902SRodney W. GrimesCauses
452958d7c9fSPhilippe Charnier.Nm
4535b9513b2STim Vanderhoekto take its input from stdin and put its output to stdout.
454c58c7416SAndriy Gapon.It Fl ta
455c58c7416SAndriy GaponAutomatically add all identifiers ending in "_t" to the list
456c58c7416SAndriy Gaponof type keywords.
4579b50d902SRodney W. Grimes.It Fl T Ns Ar typename
4589b50d902SRodney W. GrimesAdds
4599b50d902SRodney W. Grimes.Ar typename
4606a3e8b0aSRuslan Ermilovto the list of type keywords.
4616a3e8b0aSRuslan ErmilovNames accumulate:
4629b50d902SRodney W. Grimes.Fl T
4636a3e8b0aSRuslan Ermilovcan be specified more than once.
4646a3e8b0aSRuslan ErmilovYou need to specify all the typenames that
4659b50d902SRodney W. Grimesappear in your program that are defined by
4669b50d902SRodney W. Grimes.Ic typedef
4679b50d902SRodney W. Grimes\- nothing will be
4680227791bSRuslan Ermilovharmed if you miss a few, but the program will not be formatted as nicely as
4696a3e8b0aSRuslan Ermilovit should.
47036a142c4SRuslan ErmilovThis sounds like a painful thing to have to do, but it is really
4719b50d902SRodney W. Grimesa symptom of a problem in C:
4729b50d902SRodney W. Grimes.Ic typedef
4739b50d902SRodney W. Grimescauses a syntactic change in the
4749b50d902SRodney W. Grimeslanguage and
475958d7c9fSPhilippe Charnier.Nm
4760227791bSRuslan Ermilovcannot find all
4779b50d902SRodney W. Grimesinstances of
4789b50d902SRodney W. Grimes.Ic typedef .
479fbdbd284SPiotr Pawel Stefaniak.It Fl ts Ns Ar n
480fbdbd284SPiotr Pawel StefaniakAssumed distance between tab stops.
481fbdbd284SPiotr Pawel StefaniakThe default is 8.
482771aff0aSPedro F. Giffuni.It Fl U Ns Ar file
483771aff0aSPedro F. GiffuniAdds type names from
484771aff0aSPedro F. Giffuni.Ar file
485771aff0aSPedro F. Giffunito the list of type keywords.
4865ac16458SJens Schweikhardt.It Fl ut , nut
4875ac16458SJens SchweikhardtEnables (disables) the use of tab characters in the output.
4885ac16458SJens SchweikhardtThe default is
4895ac16458SJens Schweikhardt.Fl ut .
4909b50d902SRodney W. Grimes.It Fl v , \&nv
4919b50d902SRodney W. Grimes.Fl v
4929b50d902SRodney W. Grimesturns on `verbose' mode;
4939b50d902SRodney W. Grimes.Fl \&nv
4946a3e8b0aSRuslan Ermilovturns it off.
4956a3e8b0aSRuslan ErmilovWhen in verbose mode,
496958d7c9fSPhilippe Charnier.Nm
4979b50d902SRodney W. Grimesreports when it splits one line of input into two or more lines of output,
4986a3e8b0aSRuslan Ermilovand gives some size statistics at completion.
4996a3e8b0aSRuslan ErmilovThe default is
5009b50d902SRodney W. Grimes.Fl \&nv .
501d0f86f66SPiotr Pawel Stefaniak.It Fl -version
502d0f86f66SPiotr Pawel StefaniakCauses
503d0f86f66SPiotr Pawel Stefaniak.Nm
504d0f86f66SPiotr Pawel Stefaniakto print its version number and exit.
5059b50d902SRodney W. Grimes.El
5069b50d902SRodney W. Grimes.Pp
5079b50d902SRodney W. GrimesYou may set up your own `profile' of defaults to
508958d7c9fSPhilippe Charnier.Nm
5099b50d902SRodney W. Grimesby creating a file called
5109b50d902SRodney W. Grimes.Pa .indent.pro
5119b50d902SRodney W. Grimesin your login directory and/or the current directory and including
5126a3e8b0aSRuslan Ermilovwhatever switches you like.
5136a3e8b0aSRuslan ErmilovA `.indent.pro' in the current directory takes
5146a3e8b0aSRuslan Ermilovprecedence over the one in your login directory.
5156a3e8b0aSRuslan ErmilovIf
516958d7c9fSPhilippe Charnier.Nm
5179b50d902SRodney W. Grimesis run and a profile file exists, then it is read to set up the program's
5186a3e8b0aSRuslan Ermilovdefaults.
5196a3e8b0aSRuslan ErmilovSwitches on the command line, though, always override profile
5206a3e8b0aSRuslan Ermilovswitches.
5216a3e8b0aSRuslan ErmilovThe switches should be separated by spaces, tabs or newlines.
5229b50d902SRodney W. Grimes.Pp
5239b50d902SRodney W. Grimes.Ss Comments
5249b50d902SRodney W. Grimes.Sq Em Box
5259b50d902SRodney W. Grimes.Em comments .
526e8937ba0SPhilippe CharnierThe
527e8937ba0SPhilippe Charnier.Nm
528e8937ba0SPhilippe Charnierutility
5299b50d902SRodney W. Grimesassumes that any comment with a dash or star immediately after the start of
5309b50d902SRodney W. Grimescomment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
5319b50d902SRodney W. GrimesEach line of such a comment is left unchanged, except that its indentation
5329b50d902SRodney W. Grimesmay be adjusted to account for the change in indentation of the first line
5339b50d902SRodney W. Grimesof the comment.
5349b50d902SRodney W. Grimes.Pp
5359b50d902SRodney W. Grimes.Em Straight text .
5369b50d902SRodney W. GrimesAll other comments are treated as straight text.
537e8937ba0SPhilippe CharnierThe
538e8937ba0SPhilippe Charnier.Nm
539e8937ba0SPhilippe Charnierutility fits as many words (separated by blanks, tabs, or newlines) on a
5406a3e8b0aSRuslan Ermilovline as possible.
5416a3e8b0aSRuslan ErmilovBlank lines break paragraphs.
5429b50d902SRodney W. Grimes.Ss Comment indentation
5439b50d902SRodney W. GrimesIf a comment is on a line with code it is started in the `comment column',
5449b50d902SRodney W. Grimeswhich is set by the
5459b50d902SRodney W. Grimes.Fl c Ns Ns Ar n
5466a3e8b0aSRuslan Ermilovcommand line parameter.
5476a3e8b0aSRuslan ErmilovOtherwise, the comment is started at
5489b50d902SRodney W. Grimes.Ar n
5499b50d902SRodney W. Grimesindentation levels less than where code is currently being placed, where
5509b50d902SRodney W. Grimes.Ar n
5519b50d902SRodney W. Grimesis specified by the
5529b50d902SRodney W. Grimes.Fl d Ns Ns Ar n
5536a3e8b0aSRuslan Ermilovcommand line parameter.
5546a3e8b0aSRuslan ErmilovIf the code on a line extends past the comment
5559b50d902SRodney W. Grimescolumn, the comment starts further to the right, and the right margin may be
5569b50d902SRodney W. Grimesautomatically extended in extreme cases.
5579b50d902SRodney W. Grimes.Ss Preprocessor lines
5589b50d902SRodney W. GrimesIn general,
559958d7c9fSPhilippe Charnier.Nm
5606a3e8b0aSRuslan Ermilovleaves preprocessor lines alone.
5616a3e8b0aSRuslan ErmilovThe only
5626a3e8b0aSRuslan Ermilovreformatting that it will do is to straighten up trailing comments.
5636a3e8b0aSRuslan ErmilovIt
5646a3e8b0aSRuslan Ermilovleaves embedded comments alone.
5656a3e8b0aSRuslan ErmilovConditional compilation
5669b50d902SRodney W. Grimes.Pq Ic #ifdef...#endif
5679b50d902SRodney W. Grimesis recognized and
568958d7c9fSPhilippe Charnier.Nm
5699b50d902SRodney W. Grimesattempts to correctly
5709b50d902SRodney W. Grimescompensate for the syntactic peculiarities introduced.
5719b50d902SRodney W. Grimes.Ss C syntax
572e8937ba0SPhilippe CharnierThe
573e8937ba0SPhilippe Charnier.Nm
574e8937ba0SPhilippe Charnierutility understands a substantial amount about the syntax of C, but it
5756a3e8b0aSRuslan Ermilovhas a `forgiving' parser.
5766a3e8b0aSRuslan ErmilovIt attempts to cope with the usual sorts of
577463a577bSEitan Adlerincomplete and malformed syntax.
5786a3e8b0aSRuslan ErmilovIn particular, the use of macros like:
5799b50d902SRodney W. Grimes.Pp
5809b50d902SRodney W. Grimes.Dl #define forever for(;;)
5819b50d902SRodney W. Grimes.Pp
5829b50d902SRodney W. Grimesis handled properly.
5839b50d902SRodney W. Grimes.Sh ENVIRONMENT
584e8937ba0SPhilippe CharnierThe
585e8937ba0SPhilippe Charnier.Nm
586e8937ba0SPhilippe Charnierutility uses the
5879b50d902SRodney W. Grimes.Ev HOME
5889b50d902SRodney W. Grimesenvironment variable.
5899b50d902SRodney W. Grimes.Sh FILES
5909b50d902SRodney W. Grimes.Bl -tag -width "./.indent.pro" -compact
5919b50d902SRodney W. Grimes.It Pa ./.indent.pro
5929b50d902SRodney W. Grimesprofile file
5939b50d902SRodney W. Grimes.It Pa ~/.indent.pro
5949b50d902SRodney W. Grimesprofile file
5959b50d902SRodney W. Grimes.El
5969b50d902SRodney W. Grimes.Sh HISTORY
5979b50d902SRodney W. GrimesThe
598958d7c9fSPhilippe Charnier.Nm
5999b50d902SRodney W. Grimescommand appeared in
6009b50d902SRodney W. Grimes.Bx 4.2 .
6019b50d902SRodney W. Grimes.Sh BUGS
602e8937ba0SPhilippe CharnierThe
603e8937ba0SPhilippe Charnier.Nm
604e8937ba0SPhilippe Charnierutility has even more switches than
6059b50d902SRodney W. Grimes.Xr ls 1 .
6069b50d902SRodney W. Grimes.Pp
607d8aa7ce5SGiorgos KeramidasA common mistake is to try to indent all the
608d8aa7ce5SGiorgos Keramidas.Em C
609d8aa7ce5SGiorgos Keramidasprograms in a directory by typing:
6109b50d902SRodney W. Grimes.Pp
6119b50d902SRodney W. Grimes.Dl indent *.c
6129b50d902SRodney W. Grimes.Pp
6139b50d902SRodney W. GrimesThis is probably a bug, not a feature.
614