Penguin
Annotated edit history of indent(1) version 1 showing authors affecting page license. View with all changes included.
Rev Author # Line
1 perry 1 INDENT
2 !!!INDENT
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 OPTIONS
7 INVOKING INDENT
8 BACKUP FILES
9 COMMON STYLES
10 BLANK LINES
11 --blank-lines-after-declarations
12 --blank-lines-after-procedures
13 COMMENTS
14 STATEMENTS
15 DECLARATIONS
16 INDENTATION
17 BREAKING LONG LINES
18 DISABLING FORMATTING
19 MISCELLANEOUS OPTIONS
20 BUGS
21 COPYRIGHT
22 Options Cross Key
23 RETURN VALUE
24 FILES
25 AUTHORS
26 HISTORY
27 COPYING
28 ----
29 !!NAME
30
31
32 indent - changes the appearance of a C program by inserting or deleting whitespace.
33 !!SYNOPSIS
34
35
36 __indent__ [[options] [[input-files]
37
38
39 __indent__ [[options] [[single-input-file] [[-o
40 output-file]
41
42
43 __indent__ --version
44 !!DESCRIPTION
45
46
47 This man page is generated from the file
48 ''indent.texinfo''. This is Edition of
49 ''indent__ Manual
50 __
51
52
53 The __indent__ program can be used to make code easier to
54 read. It can also convert from one style of writing C to
55 another.
56
57
58 __indent__ understands a substantial amount about the
59 syntax of C, but it also attempts to cope with incomplete
60 and misformed syntax.
61
62
63 In version 1.2 and more recent versions, the GNU style of
64 indenting is the default.
65 !!OPTIONS
66
67
68 __-bad__,
69 __--blank-lines-after-declarations__
70
71
72 Force blank lines after the declarations.
73 See __BLANK LINES__.
74
75
76 __-bap__,
77 __--blank-lines-after-procedures__
78
79
80 Force blank lines after procedure bodies.
81 See __BLANK LINES__.
82
83
84 __-bbb__,
85 __--blank-lines-before-block-comments__
86
87
88 Force blank lines before block comments.
89 See __BLANK LINES__.
90
91
92 __-bbo__,
93 __--break-before-boolean-operator__
94
95
96 Prefer to break long lines before boolean operators.
97 See __BREAKING LONG LINES__.
98
99
100 __-bc__, __--blank-lines-after-commas__
101
102
103 Force newline after comma in declaration.
104 See __DECLARATIONS__.
105
106
107 __-bl__, __--braces-after-if-line__
108
109
110 Put braces on line after __if__, etc.
111 See __STATEMENTS__.
112
113
114 __-bli__''n'',
115 __--brace-indent__''n''
116
117
118 Indent braces ''n'' spaces.
119 See __STATEMENTS__.
120
121
122 __-bls__,
123 __--braces-after-struct-decl-line__
124
125
126 Put braces on the line after __struct__ declaration
127 lines.
128 See __DECLARATIONS__.
129
130
131 __-br__, __--braces-on-if-line__
132
133
134 Put braces on line with __if__, etc.
135 See __STATEMENTS__.
136
137
138 __-brs__,
139 __--braces-on-struct-decl-line__
140
141
142 Put braces on __struct__ declaration line.
143 See __DECLARATIONS__.
144
145
146 __-bs__, __--Bill-Shannon__,
147 __--blank-before-sizeof__
148
149
150 Put a space between __sizeof__ and its argument.
151 See __STATEMENTS__.
152
153
154 __-c__''n'',
155 __--comment-indentation__''n''
156
157
158 Put comments to the right of code in column ''n''.
159 See __COMMENTS__.
160
161
162 __-cbi__''n'',
163 __--case-brace-indentation__''n''
164
165
166 Indent braces after a case label N spaces.
167 See __STATEMENTS__.
168
169
170 __-cd__''n'',
171 __--declaration-comment-column__''n''
172
173
174 Put comments to the right of the declarations in column
175 ''n''.
176 See __COMMENTS__.
177
178
179 __-cdb__,
180 __--comment-delimiters-on-blank-lines__
181
182
183 Put comment delimiters on blank lines.
184 See __COMMENTS__.
185
186
187 __-cdw__, __--cuddle-do-while__
188
189
190 Cuddle while of __do {} while;__ and preceeding }.
191 See __COMMENTS__.
192
193
194 __-ce__, __--cuddle-else__
195
196
197 Cuddle else and preceeding }.
198 See __COMMENTS__.
199
200
201 __-ci__''n'',
202 __--continuation-indentation__''n''
203
204
205 Continuation indent of ''n'' spaces.
206 See __STATEMENTS__.
207
208
209 __-cli__''n'',
210 __--case-indentation__''n''
211
212
213 Case label indent of ''n'' spaces.
214 See __STATEMENTS__.
215
216
217 __-cp__''n'',
218 __--else-endif-column__''n''
219
220
221 Put comments to the right of __#else__ and __#endif__
222 statements in column ''n''.
223 See __COMMENTS__.
224
225
226 __-cs__, __--space-after-cast__
227
228
229 Put a space after a cast operator.
230 See __STATEMENTS__.
231
232
233 __-d__''n'',
234 __--line-comments-indentation__''n''
235
236
237 Set indentation of comments not to the right of code to
238 ''n'' spaces.
239 See __COMMENTS__.
240
241
242 __-bfda__, __--break-function-decl-args__
243
244
245 Align all arguments in a declaration with opening paren.
246 See __DECLARATIONS__.
247
248
249 __-di__''n'',
250 __--declaration-indentation__''n''
251
252
253 Put variables in column ''n''.
254 See __DECLARATIONS__.
255
256
257 __-fc1__,
258 __--format-first-column-comments__
259
260
261 Format comments in the first column.
262 See __COMMENTS__.
263
264
265 __-fca__, __--format-all-comments__
266
267
268 Do not disable all formatting of comments.
269 See __COMMENTS__.
270
271
272 __-gnu__, __--gnu-style__
273
274
275 Use GNU coding style. This is the default.
276 See __COMMON STYLES__.
277
278
279 __-hnl__, __--honour-newlines__
280
281
282 Prefer to break long lines at the position of newlines in
283 the input.
284 See __BREAKING LONG LINES__.
285
286
287 __-i__''n'',
288 __--indent-level__''n''
289
290
291 Set indentation level to ''n'' spaces.
292 See __INDENTATION__.
293
294
295 __-ip__''n'',
296 __--parameter-indentation__''n''
297
298
299 Indent parameter types in old-style function definitions by
300 ''n'' spaces.
301 See __INDENTATION__.
302
303
304 __-kr__, __--k-and-r-style__
305
306
307 Use Kernighan
308 See __COMMON STYLES__.
309
310
311 __-l__''n'', __--line-length__''n''
312
313
314 Set maximum line length for non-comment lines to
315 ''n''.
316 See __BREAKING LONG LINES__.
317
318
319 __-lc__''n'',
320 __--comment-line-length__''n''
321
322
323 Set maximum line length for comment formatting to
324 ''n''.
325 See __COMMENTS__.
326
327
328 __-lp__, __--continue-at-parentheses__
329
330
331 Line up continued lines at parentheses.
332 See __INDENTATION__.
333
334
335 __-lps__, __--leave-preprocessor-space__
336
337
338 Leave space between # and preprocessor directive.
339 See __INDENTATION__.
340
341
342 __-nbad__,
343 __--no-blank-lines-after-declarations__
344
345
346 Do not force blank lines after declarations.
347 See __BLANK LINES__.
348
349
350 __-nbap__,
351 __--no-blank-lines-after-procedures__
352
353
354 Do not force blank lines after procedure bodies.
355 See __BLANK LINES__.
356
357
358 __-nbbo__,
359 __--break-after-boolean-operator__
360
361
362 Do not prefer to break long lines before boolean
363 operators.
364 See __BREAKING LONG LINES__.
365
366
367 __-nbc__,
368 __--no-blank-lines-after-commas__
369
370
371 Do not force newlines after commas in declarations.
372 See __DECLARATIONS__.
373
374
375 __-nbfda__,
376 __--dont-break-function-decl-args__
377
378
379 Dont put each argument in a function declaration on a
380 seperate line.
381 See __DECLARATIONS__.
382
383
384 __-ncdb__,
385 __--no-comment-delimiters-on-blank-lines__
386
387
388 Do not put comment delimiters on blank lines.
389 See __COMMENTS__.
390
391
392 __-ncdw__, __--dont-cuddle-do-while__
393
394
395 Do not cuddle __}__ and the __while__ of a __do {}
396 while;__.
397 See __STATEMENTS__.
398
399
400 __-nce__, __--dont-cuddle-else__
401
402
403 Do not cuddle __}__ and __else__.
404 See __STATEMENTS__.
405
406
407 __-ncs__, __--no-space-after-casts__
408
409
410 Do not put a space after cast operators.
411 See __STATEMENTS__.
412
413
414 __-nfc1__,
415 __--dont-format-first-column-comments__
416
417
418 Do not format comments in the first column as normal.
419 See __COMMENTS__.
420
421
422 __-nfca__, __--dont-format-comments__
423
424
425 Do not format any comments.
426 See __COMMENTS__.
427
428
429 __-nhnl__, __--ignore-newlines__
430
431
432 Do not prefer to break long lines at the position of
433 newlines in the input.
434 See __BREAKING LONG LINES__.
435
436
437 __-nip__, __--no-parameter-indentation__
438
439
440 Zero width indentation for parameters.
441 See __INDENTATION__.
442
443
444 __-nlp__, __--dont-line-up-parentheses__
445
446
447 Do not line up parentheses.
448 See __STATEMENTS__.
449
450
451 __-npcs__,
452 __--no-space-after-function-call-names__
453
454
455 Do not put space after the function in function calls.
456 See __STATEMENTS__.
457
458
459 __-nprs__,
460 __--no-space-after-parentheses__
461
462
463 Do not put a space after every ( and before every ).
464 See __STATEMENTS__.
465
466
467 __-npsl__,
468 __--dont-break-procedure-type__
469
470
471 Put the type of a procedure on the same line as its
472 name.
473 See __DECLARATIONS__.
474
475
476 __-nsaf__, __--no-space-after-for__
477
478
479 Do not put a space after every __for__.
480 See __STATEMENTS__.
481
482
483 __-nsai__, __--no-space-after-if__
484
485
486 Do not put a space after every __if__.
487 See __STATEMENTS__.
488
489
490 __-nsaw__, __--no-space-after-while__
491
492
493 Do not put a space after every __while__.
494 See __STATEMENTS__.
495
496
497 __-nsc__, __--dont-star-comments__
498
499
500 Do not put the * character at the left of comments.
501 See __COMMENTS__.
502
503
504 __-nsob__,
505 __--leave-optional-blank-lines__
506
507
508 Do not swallow optional blank lines.
509 See __BLANK LINES__.
510
511
512 __-nss__,
513 __--dont-space-special-semicolon__
514
515
516 Do not force a space before the semicolon after certain
517 statements. Disables -ss.
518 See __STATEMENTS__.
519
520
521 __-nut__, __--no-tabs__
522
523
524 Use spaces instead of tabs.
525 See __INDENTATION__.
526
527
528 __-nv__, __--no-verbosity__
529
530
531 Disable verbose mode.
532 See __MISCELLANEOUS OPTIONS__.
533
534
535 __-orig__, __--original__
536
537
538 Use the original Berkeley coding style.
539 See __COMMON STYLES__.
540
541
542 __-npro__, __--ignore-profile__
543
544
545 Do not read .indent.pro files.
546 See __INVOKING INDENT__.
547
548
549 __-pcs__,
550 __--space-after-procedure-calls__
551
552
553 Insert a space between the name of the procedure being
554 called and the (.
555 See __STATEMENTS__.
556
557
558 __-pi__''n'',
559 __--paren-indentation__''n''
560
561
562 Specify the extra indentation per open parentheses ( when a
563 statement is broken.See __STATEMENTS__.
564
565
566 __-pmt__, __--preserve-mtime__
567
568
569 Preserve access and modification times on output files.See
570 __MISCELLANEOUS OPTIONS__.
571
572
573 __-prs__, __--space-after-parentheses__
574
575
576 Put a space after every ( and before every ).
577 See __STATEMENTS__.
578
579
580 __-psl__, __--procnames-start-lines__
581
582
583 Put the type of a procedure on the line before its name.
584 See __DECLARATIONS__.
585
586
587 __-saf__, __--space-after-for__
588
589
590 Put a space after each __for__.
591 See __STATEMENTS__.
592
593
594 __-sai__, __--space-after-if__
595
596
597 Put a space after each __if__.
598 See __STATEMENTS__.
599
600
601 __-saw__, __--space-after-while__
602
603
604 Put a space after each __while__.
605 See __STATEMENTS__.
606
607
608 __-sbi__''n'',
609 __--struct-brace-indentation__''n''
610
611
612 Indent braces of a struct, union or enum N spaces.
613 See __STATEMENTS__.
614
615
616 __-sc__,
617 __--start-left-side-of-comments__
618
619
620 Put the * character at the left of comments.
621 See __COMMENTS__.
622
623
624 __-sob__,
625 __--swallow-optional-blank-lines__
626
627
628 Swallow optional blank lines.
629 See __BLANK LINES__.
630
631
632 __-ss__, __--space-special-semicolon__
633
634
635 On one-line __for__ and __while__ statments, force a
636 blank before the semicolon.
637 See __STATEMENTS__.
638
639
640 __-st__, __--standard-output__
641
642
643 Write to standard output.
644 See __INVOKING INDENT__.
645
646
647 __-T__
648
649
650 Tell __indent__ the name of typenames.
651 See __DECLARATIONS__.
652
653
654 __-ts__''n'', __--tab-size__''n''
655
656
657 Set tab size to ''n'' spaces.
658 See __INDENTATION__.
659
660
661 __-ut__, __--use-tabs__
662
663
664 Use tabs. This is the default.
665 See __INDENTATION__.
666
667
668 __-v__, __--verbose__
669
670
671 Enable verbose mode.
672 See __MISCELLANEOUS OPTIONS__.
673
674
675 __-version__
676
677
678 Output the version number of __indent__.
679 See __MISCELLANEOUS OPTIONS__.
680 !!INVOKING INDENT
681
682
683 As of version 1.3, the format of the __indent__ command
684 is:
685
686
687 indent [[''options''] [[''input-files'']
688 indent [[''options''] [[''single-input-file''] [[-o ''output-file'']
689 This format is different from earlier versions and other versions of __indent__.
690
691
692 In the first form, one or more input files are specified.
693 __indent__ makes a backup copy of each file, and the
694 original file is replaced with its indented version. See
695 __BACKUP FILES__, for an explanation of how backups are
696 made.
697
698
699 In the second form, only one input file is specified. In
700 this case, or when the standard input is used, you may
701 specify an output file after the -o option.
702
703
704 To cause __indent__ to write to standard output, use the
705 -st option. This is only allowed when there is only one
706 input file, or when the standard input is used.
707
708
709 If no input files are named, the standard input is read for
710 input. Also, if a filename named - is specified, then the
711 standard input is read.
712
713
714 As an example, each of the following commands will input the
715 program slithy_toves.c and write its indented text to
716 slithy_toves.out:
717
718
719 indent slithy_toves.c -o slithy_toves.out
720 indent -st slithy_toves.c
721 Most other options to __indent__ control how programs are formatted. As of version 1.2, __indent__ also recognizes a long name for each option name. Long options are prefixed by either -- or +. [[ + is being superseded by -- to maintain consistency with the POSIX standard.] In most of this document, the traditional, short names are used for the sake of brevity. See __OPTION SUMMARY__, for a list of options, including both long and short names.
722
723
724 Here is another example:
725
726
727 indent -br test/metabolism.c -l85
728 This will indent the program test/metabolism.c using the -br and -l85 options, write the output back to test/metabolism.c, and write the original contents of test/metabolism.c to a backup file in the directory test.
729
730
731 Equivalent invocations using long option names for this
732 example would be:
733
734
735 indent --braces-on-if-line --line-length185 test/metabolism.c
736 indent +braces-on-if-line +line-length185 test/metabolism.c
737 If you find that you often use __indent__ with the same options, you may put those options into a file named .indent.pro. __indent__ will first look for .indent.pro in the current directory and use that if found. Otherwise, __indent__ will search your home directory for .indent.pro and use that file if it is found. This behaviour is different from that of other versions of __indent__, which load both files if they both exist.
738
739
740 The format of .indent.pro is simply a list of options, just
741 as they would appear on the command line, separated by white
742 space (tabs, spaces, and newlines). Options in .indent.pro
743 may be surrounded by C or C++ comments, in which case they
744 are ignored.
745
746
747 Command line switches are handled ''after'' processing
748 .indent.pro. Options specified later override arguments
749 specified earlier, with one exception: Explicitly specified
750 options always override background options (See __COMMON
751 STYLES__). You can prevent __indent__ from reading an
752 .indent.pro file by specifying the -npro
753 option.
754 !!BACKUP FILES
755
756
757 As of version 1.3, GNU __indent__ makes GNU-style backup
758 files, the same way GNU Emacs does. This means that either
759 ''simple'' or ''numbered'' backup filenames may be
760 made.
761
762
763 Simple backup file names are generated by appending a suffix
764 to the original file name. The default for this suffix is
765 the one-character string ~ (tilde). Thus, the backup file
766 for python.c would be python.c~.
767
768
769 Instead of the default, you may specify any string as a
770 suffix by setting the environment variable
771 __SIMPLE_BACKUP_SUFFIX__ to your preferred
772 suffix.
773
774
775 Numbered backup versions of a file momeraths.c look like
776 momeraths.c.~23~, where 23 is the version of this particular
777 backup. When making a numbered backup of the file
778 src/momeraths.c, the backup file will be named
779 src/momeraths.c.~''V''~, where ''V'' is one greater
780 than the highest version currently existing in the directory
781 src. The environment variable __VERSION_WIDTH__ controls
782 the number of digits, using left zero padding when
783 necessary. For instance, setting this variable to
784 __
785
786
787 The type of backup file made is controlled by the value of
788 the environment variable __VERSION_CONTROL__. If it is
789 the string simple, then only simple backups will be made. If
790 its value is the string numbered, then numbered backups will
791 be made. If its value is numbered-existing, then numbered
792 backups will be made if there ''already exist'' numbered
793 backups for the file being indented; otherwise, a simple
794 backup is made. If __VERSION_CONTROL__ is not set, then
795 __indent__ assumes the behaviour of
796 numbered-existing.
797
798
799 Other versions of __indent__ use the suffix .BAK in
800 naming backup files. This behaviour can be emulated by
801 setting __SIMPLE_BACKUP_SUFFIX__ to .BAK.
802
803
804 Note also that other versions of __indent__ make backups
805 in the current directory, rather than in the directory of
806 the source file as GNU __indent__ now does.
807 !!COMMON STYLES
808
809
810 There are several common styles of C code, including the GNU
811 style, the Kernighan
812 background'' option, which specifies a set of values
813 for all other options. However, explicitly specified options
814 always override options implied by a background
815 option.
816
817
818 As of version 1.2, the default style of GNU __indent__ is
819 the GNU style. Thus, it is no longer necessary to specify
820 the option -gnu to obtain this format, although doing so
821 will not cause an error. Option settings which correspond to
822 the GNU style are:
823
824
825 -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
826 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
827 -saw -nsc -nsob
828 The GNU coding style is that preferred by the GNU project. It is the style that the GNU Emacs C mode encourages and which is used in the C portions of GNU Emacs. (People interested in writing programs for Project GNU should get a copy of
829
830
831 The Kernighan
832
833
834 -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
835 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
836 -nprs -npsl -saf -sai -saw -nsc -nsob -nss
837 Kernighan indent__ has arbitrarily chosen column 33.
838
839
840 The style of the original Berkeley __indent__ may be
841 obtained by specifying -orig (or by specifying --original,
842 using the long option name). This style is equivalent to the
843 following settings:
844
845
846 -nbad -nbap -bbo -bc -br -brs -c33 -cd33 -cdb -ce -ci4 -cli0
847 -cp33 -di16 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -psl
848 -saf -sai -saw -sc -nsob -nss -ts8
849 !!BLANK LINES
850
851
852 Various programming styles use blank lines in different
853 places. __indent__ has a number of options to insert or
854 delete blank lines in specific places.
855
856
857 The -bad option causes __indent__ to force a blank line
858 after every block of declarations. The -nbad option causes
859 __indent__ not to force such blank lines.
860
861
862 The -bap option forces a blank line after every procedure
863 body. The -nbap option forces no such blank
864 line.
865
866
867 The -bbb option forces a blank line before every boxed
868 comment (See __COMMENTS__.) The -nbbb option does not
869 force such blank lines.
870
871
872 The -sob option causes __indent__ to swallow optional
873 blank lines (that is, any optional blank lines present in
874 the input will be removed from the output). If the -nsob is
875 specified, any blank lines present in the input file will be
876 copied to the output file.
877 !!--blank-lines-after-declarations
878
879
880 The -bad option forces a blank line after every block of
881 declarations. The -nbad option does not add any such blank
882 lines.
883
884
885 For example, given the input
886
887
888 char *foo;
889 char *bar;
890 /* This separates blocks of declarations. */
891 int baz;
892 __indent -bad__ produces
893
894
895 char *foo;
896 char *bar;
897 /* This separates blocks of declarations. */
898 int baz;
899 and __indent -nbad__ produces
900
901
902 char *foo;
903 char *bar;
904 /* This separates blocks of declarations. */
905 int baz;
906 !!--blank-lines-after-procedures
907
908
909 The -bap option forces a blank line after every procedure
910 body.
911
912
913 For example, given the input
914
915
916 int
917 foo ()
918 {
919 puts(
920 __indent -bap__ produces
921
922
923 int
924 foo ()
925 {
926 puts (
927 and __indent -nbap__ produces
928
929
930 int
931 foo ()
932 {
933 puts (
934 No blank line will be added after the procedure __foo__.
935 !!COMMENTS
936
937
938 __indent__ formats both C and C++ comments. C comments
939 are begun with /*, terminated with */ and may contain
940 newline characters. C++ comments begin with the delimiter //
941 and end at the newline.
942
943
944 __indent__ handles comments differently depending upon
945 their context. __indent__ attempts to distinguish between
946 comments which follow statements, comments which follow
947 declarations, comments following preprocessor directives,
948 and comments which are not preceded by code of any sort,
949 i.e., they begin the text of the line (although not
950 neccessarily in column 1).
951
952
953 __indent__ further distinguishes between comments found
954 outside of procedures and aggregates, and those found within
955 them. In particular, comments beginning a line found within
956 a procedure will be indented to the column at which code is
957 currently indented. The exception to this a comment
958 beginning in the leftmost column; such a comment is output
959 at that column.
960
961
962 __indent__ attempts to leave ''boxed comments''
963 unmodified. The general idea of such a comment is that it is
964 enclosed in a rectangle or box of stars or dashes to
965 visually set it apart. More precisely, boxed comments are
966 defined as those in which the initial /* is followed
967 immediately by the character *, =, _, or -, or those in
968 which the beginning comment delimiter (/*) is on a line by
969 itself, and the following line begins with a * in the same
970 column as the star of the opening delimiter.
971
972
973 Examples of boxed comments are:
974
975
976 /**********************
977 * Comment in a box!! *
978 **********************/
979 /*
980 * A different kind of scent,
981 * for a different kind of comment.
982 */
983 __indent__ attempts to leave boxed comments exactly as they are found in the source file. Thus the indentation of the comment is unchanged, and its length is not checked in any way. The only alteration made is that an embedded tab character may be converted into the appropriate number of spaces.
984
985
986 If the -bbb option is specified, all such boxed comments
987 will be preceded by a blank line, unless such a comment is
988 preceded by code.
989
990
991 Comments which are not boxed comments may be formatted,
992 which means that the line is broken to fit within a right
993 margin and left-filled with whitespace. Single newlines are
994 equivalent to a space, but blank lines (two or more newlines
995 in a row) are taken to mean a paragraph break. Formatting of
996 comments which begin after the first column is enabled with
997 the -fca option. To format those beginning in column one,
998 specify -fc1. Such formatting is disabled by
999 default.
1000
1001
1002 The right margin for formatting defaults to 78, but may be
1003 changed with the -lc option. If the margin specified does
1004 not allow the comment to be printed, the margin will be
1005 automatically extended for the duration of that comment. The
1006 margin is not respected if the comment is not being
1007 formatted.
1008
1009
1010 If the comment begins a line (i.e., there is no program text
1011 to its left), it will be indented to the column it was found
1012 in unless the comment is within a block of code. In that
1013 case, such a comment will be aligned with the indented code
1014 of that block (unless the comment began in the first
1015 column). This alignment may be affected by the -d option,
1016 which specifies an amount by which such comments are moved
1017 to the ''left'', or unindented. For example, -d2 places
1018 comments two spaces to the left of code. By default,
1019 comments are aligned with code, unless they begin in the
1020 first column, in which case they are left there by default
1021 --- to get them aligned with the code, specify
1022 -fc1.
1023
1024
1025 Comments to the right of code will appear by default in
1026 column 33. This may be changed with one of three options. -c
1027 will specify the column for comments following code, -cd
1028 specifies the column for comments following declarations,
1029 and -cp specifies the column for comments following
1030 preprocessor directives __#else__ and
1031 __#endif__.
1032
1033
1034 If the code to the left of the comment exceeds the beginning
1035 column, the comment column will be extended to the next
1036 tabstop column past the end of the code, or in the case of
1037 preprocessor directives, to one space past the end of the
1038 directive. This extension lasts only for the output of that
1039 particular comment.
1040
1041
1042 The -cdb option places the comment delimiters on blank
1043 lines. Thus, a single line comment like __/* Loving hug
1044 */__ can be transformed into:
1045
1046
1047 /*
1048 Loving hug
1049 */
1050 Stars can be placed at the beginning of multi-line comments with the -sc option. Thus, the single-line comment above can be transformed (with -cdb -sc) into:
1051
1052
1053 /*
1054 * Loving hug
1055 */
1056 !!STATEMENTS
1057
1058
1059 The -br or -bl option specifies how to format
1060 braces.
1061
1062
1063 The -br option formats statement braces like
1064 this:
1065
1066
1067 if (x
1068 The -bl option formats them like this:
1069
1070
1071 if (x
1072 If you use the -bl option, you may also want to specify the -bli option. This option specifies the number of spaces by which braces are indented. -bli2, the default, gives the result shown above. -bli0 results in the following:
1073
1074
1075 if (x
1076 If you are using the -br option, you probably want to also use the -ce option. This causes the __else__ in an if-then-else construct to cuddle up to the immediately preceding }. For example, with -br -ce you get the following:
1077
1078
1079 if (x
1080 With -br -nce that code would appear as
1081
1082
1083 if (x
1084 This causes the __while__ in a do-while loop to cuddle up to the immediately preceding }. For example, with -cdw you get the following:
1085
1086
1087 do {
1088 x--;
1089 } while (x);
1090 With -ncdw that code would appear as
1091
1092
1093 do {
1094 x--;
1095 }
1096 while (x);
1097 The -cli option specifies the number of spaces that case labels should be indented to the right of the containing __switch__ statement.
1098
1099
1100 The default gives code like:
1101
1102
1103 switch (i)
1104 {
1105 case 0:
1106 break;
1107 case 1:
1108 {
1109 ++i;
1110 }
1111 default:
1112 break;
1113 }
1114 Using the -cli2 that would become:
1115
1116
1117 switch (i)
1118 {
1119 case 0:
1120 break;
1121 case 1:
1122 {
1123 ++i;
1124 }
1125 default:
1126 break;
1127 }
1128 The indentation of the braces below a case statement can be controlled with the -cbi''n'' option. For example, using -cli2 -cbi0 results in:
1129
1130
1131 switch (i)
1132 {
1133 case 0:
1134 break;
1135 case 1:
1136 {
1137 ++i;
1138 }
1139 default:
1140 break;
1141 }
1142 If a semicolon is on the same line as a __for__ or __while__ statement, the -ss option will cause a space to be placed before the semicolon. This emphasizes the semicolon, making it clear that the body of the __for__ or __while__ statement is an empty statement. -nss disables this feature.
1143
1144
1145 The -pcs option causes a space to be placed between the name
1146 of the procedure being called and the ( (for example,
1147 __puts (__. The -npcs option would give
1148 __puts(__).
1149
1150
1151 If the -cs option is specified, __indent__ puts a space
1152 after a cast operator.
1153
1154
1155 The -bs option ensures that there is a space between the
1156 keyword __sizeof__ and its argument. In some versions,
1157 this is known as the Bill_Shannon option.
1158
1159
1160 The -saf option forces a space between an __for__ and the
1161 following parenthesis. This is the default.
1162
1163
1164 The -sai option forces a space between an __if__ and the
1165 following parenthesis. This is the default.
1166
1167
1168 The -saw option forces a space between an __while__ and
1169 the following parenthesis. This is the default.
1170
1171
1172 The -prs option causes all parentheses to be seperated with
1173 a space from the what is between them. For example, using
1174 -prs results in code like:
1175
1176
1177 while ( ( e_code - s_code )
1178 !!DECLARATIONS
1179
1180
1181 By default __indent__ will line up identifiers, in the
1182 column specified by the -di option. For example, -di16 makes
1183 things look like:
1184
1185
1186 int foo;
1187 char *bar;
1188 Using a small value (such as one or two) for the -di option can be used to cause the identifiers to be placed in the first available position; for example:
1189
1190
1191 int foo;
1192 char *bar;
1193 The value given to the -di option will still affect variables which are put on separate lines from their types, for example -di2 will lead to:
1194
1195
1196 int
1197 foo;
1198 If the -bc option is specified, a newline is forced after each comma in a declaration. For example,
1199
1200
1201 int a,
1202 b,
1203 c;
1204 With the -nbc option this would look like
1205
1206
1207 int a, b, c;
1208 The -bfda option causes a newline to be forced after the comma separating the arguments of a function declaration. The arguments will appear at the current indention level matching the opening paren. This is particularly helpful for functions with long argument lists. For example,
1209
1210
1211 void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);
1212 With the -bfda option this would look like
1213
1214
1215 void foo (int arg1,
1216 char arg2,
1217 int *arg3,
1218 long arg4,
1219 char arg5);
1220 The -psl option causes the type of a procedure being defined to be placed on the line before the name of the procedure. This style is required for the __etags__ program to work correctly, as well as some of the __c-mode__ functions of Emacs.
1221
1222
1223 You must use the -T option to tell __indent__ the name of
1224 all the typenames in your program that are defined by
1225 __typedef__. -T can be specified more than once, and all
1226 names specified are used. For example, if your program
1227 contains
1228
1229
1230 typedef unsigned long CODE_ADDR;
1231 typedef enum {red, blue, green} COLOR;
1232 you would use the options -T CODE_ADDR -T COLOR.
1233
1234
1235 The -brs or -bls option specifies how to format braces in
1236 struct declarations. The -brs option formats braces like
1237 this:
1238
1239
1240 struct foo {
1241 int x;
1242 };
1243 The -bls option formats them like this:
1244
1245
1246 struct foo
1247 {
1248 int x;
1249 };
1250 !!INDENTATION
1251
1252
1253 One issue in the formatting of code is how far each line
1254 should be indented from the left margin. When the beginning
1255 of a statement such as __if__ or __for__ is
1256 encountered, the indentation level is increased by the value
1257 specified by the -i option. For example, use -i8 to specify
1258 an eight character indentation for each level. When a
1259 statement is broken across two lines, the second line is
1260 indented by a number of additional spaces specified by the
1261 -ci option. -ci defaults to 0. However, if the -lp option is
1262 specified, and a line has a left parenthesis which is not
1263 closed on that line, then continuation lines will be lined
1264 up to start at the character position just after the left
1265 parenthesis. This processing also applies to [[ and applies
1266 to { when it occurs in initialization lists. For example, a
1267 piece of continued code might look like this with -nlp -ci3
1268 in effect:
1269
1270
1271 p1 = first_procedure (second_procedure (p2, p3),
1272 third_procedure (p4, p5));
1273 With -lp in effect the code looks somewhat clearer:
1274
1275
1276 p1 = first_procedure (second_procedure (p2, p3),
1277 third_procedure (p4, p5));
1278 When a statement is broken in between two or more paren pairs (...), each extra pair causes the indentation level extra indentation:
1279
1280
1281 if ((((i
1282 The option -ip''N'' can be used to set the extra offset per paren. For instance, -ip0 would format the above as:
1283
1284
1285 if ((((i
1286 __indent__ assumes that tabs are placed at regular intervals of both input and output character streams. These intervals are by default 8 columns wide, but (as of version 1.2) may be changed by the -ts option. Tabs are treated as the equivalent number of spaces.
1287
1288
1289 The indentation of type declarations in old-style function
1290 definitions is controlled by the -ip parameter. This is a
1291 numeric parameter specifying how many spaces to indent type
1292 declarations. For example, the default -ip5 makes
1293 definitions look like this:
1294
1295
1296 char *
1297 create_world (x, y, scale)
1298 int x;
1299 int y;
1300 float scale;
1301 {
1302 . . .
1303 }
1304 For compatibility with other versions of indent, the option -nip is provided, which is equivalent to -ip0.
1305
1306
1307 ANSI C allows white space to be placed on preprocessor
1308 command lines between the character # and the command name.
1309 By default, __indent__ removes this space, but specifying
1310 the -lps option directs __indent__ to leave this space
1311 unmodified.
1312 !!BREAKING LONG LINES
1313
1314
1315 With the option -l''n'', or --line-length''n'', it is
1316 possible to specify the maximum length of a line of C code,
1317 not including possible comments that follow it.
1318
1319
1320 When lines become longer then the specified line length, GNU
1321 __indent__ tries to break the line at a logical place.
1322 This is new as of version 2.1 however and not very
1323 intelligent or flexible yet.
1324
1325
1326 Currently there are two options that allows one to interfere
1327 with the algorithm that determines where to break a
1328 line.
1329
1330
1331 The -bbo option causes GNU __indent__ to prefer to break
1332 long lines before the boolean operators ____
1333 and __||__. The -nbbo option causes GNU __indent__ not
1334 have that preference. For example, the default option -bbo
1335 (together with --line-length60 and --ignore-newlines) makes
1336 code look like this:
1337
1338
1339 if (mask
1340 Using the option -nbbo will make it look like this:
1341
1342
1343 if (mask
1344 The default -hnl, however, honours newlines in the input file by giving them the highest possible priority to break lines at. For example, when the input file looks like this:
1345
1346
1347 if (mask
1348 then using the option -hnl, or --honour-newlines, together with the previously mentioned -nbbo and --line-length60, will cause the output not to be what is given in the last example but instead will prefer to break at the positions where the code was broken in the input file:
1349
1350
1351 if (mask
1352 The idea behind this option is that lines which are too long, but are already broken up, will not be touched by GNU __indent__. Really messy code should be run through __indent__ at least once using the --ignore-newlines option though.
1353 !!DISABLING FORMATTING
1354
1355
1356 Formatting of C code may be disabled for portions of a
1357 program by embedding special ''control comments'' in the
1358 program. To turn off formatting for a section of a program,
1359 place the disabling control comment __/* *INDENT-OFF*
1360 */__ on a line by itself just before that section. Program
1361 text scanned after this control comment is output precisely
1362 as input with no modifications until the corresponding
1363 enabling comment is scanned on a line by itself. The
1364 disabling control comment is __/* *INDENT-ON* */__, and
1365 any text following the comment on the line is also output
1366 unformatted. Formatting begins again with the input line
1367 following the enabling control comment.
1368
1369
1370 More precisely, __indent__ does not attempt to verify the
1371 closing delimiter (__*/__) for these C comments, and any
1372 whitespace on the line is totally transparent.
1373
1374
1375 These control comments also function in their C++ formats,
1376 namely __// *INDENT-OFF*__ and __//
1377 *INDENT-ON*__.
1378
1379
1380 It should be noted that the internal state of __indent__
1381 remains unchanged over the course of the unformatted
1382 section. Thus, for example, turning off formatting in the
1383 middle of a function and continuing it after the end of the
1384 function may lead to bizarre results. It is therefore wise
1385 to be somewhat modular in selecting code to be left
1386 unformatted.
1387
1388
1389 As a historical note, some earlier versions of __indent__
1390 produced error messages beginning with __*INDENT**__.
1391 These versions of __indent__ were written to ignore any
1392 input text lines which began with such error messages. I
1393 have removed this incestuous feature from GNU
1394 __indent__.
1395 !!MISCELLANEOUS OPTIONS
1396
1397
1398 To find out what version of __indent__ you have, use the
1399 command __indent -version__. This will report the version
1400 number of __indent__, without doing any of the normal
1401 processing.
1402
1403
1404 The -v option can be used to turn on verbose mode. When in
1405 verbose mode, __indent__ reports when it splits one line
1406 of input into two more more lines of output, and gives some
1407 size statistics at completion.
1408
1409
1410 The -pmt option causes __indent__ to preserve the access
1411 and modification times on the output files. Using this
1412 option has the advantage that running indent on all source
1413 and header files in a project wont cause __make__ to
1414 rebuild all targets. This option is only available on
1415 Operating Systems that have the POSIX __utime(2)__
1416 function.
1417 !!BUGS
1418
1419
1420 Please report any bugs to bug-indent@gnu.org.
1421
1422
1423 When __indent__ is run twice on a file, with the same
1424 profile, it should ''never'' change that file the second
1425 time. With the current design of __indent__, this can not
1426 be guaranteed, however, and it has not been extensively
1427 tested.
1428
1429
1430 __indent__ does not understand C. In some cases this
1431 leads to the inability to join lines. The result is that
1432 running a file through __indent__ is ''irreversible'',
1433 even if the used input file was the result of running
1434 __indent__ with a given profile
1435 (.indent.pro).
1436
1437
1438 While an attempt was made to get __indent__ working for
1439 C++, it will not do a good job on any C++ source except the
1440 very simple.
1441
1442
1443 __indent__ does not look at the given --line-length
1444 option when writing comments to the output file. This
1445 results often in comments being put far to the right. In
1446 order to prohibit __indent__ from joining a broken line
1447 that has a comment at the end, make sure that the comments
1448 start on the first line of the break.
1449
1450
1451 __indent__ does not count lines and comments (see the -v
1452 option) when __indent__ is turned off with __/*
1453 *INDENT-OFF* */__.
1454
1455
1456 Comments of the form __/*UPPERCASE*/__ are not treated as
1457 comment but as an identifier, causing them to be joined with
1458 the next line. This renders comments of this type useless,
1459 unless they are embedded in the code to begin
1460 with.
1461 !!COPYRIGHT
1462
1463
1464 The following copyright notice applies to the __indent__
1465 program. The copyright and copying permissions for this
1466 manual appear near the beginning of indent.texinfo and
1467 indent.info, and near the end of indent.1.
1468
1469
1470 Copyright (c) 2001 David Ingamells.
1471 Copyright (c) 1999 Carlo Wood.
1472 Copyright (c) 1995, 1996 Joseph Arceneaux.
1473 Copyright (c) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation
1474 Copyright (c) 1985 Sun Microsystems, Inc.
1475 Copyright (c) 1980 The Regents of the University of California.
1476 Copyright (c) 1976 Board of Trustees of the University of Illinois.
1477 All rights reserved.
1478 Redistribution and use in source and binary forms are permitted
1479 provided that the above copyright notice and this paragraph are
1480 duplicated in all such forms and that any documentation,
1481 advertising materials, and other materials related to such
1482 distribution and use acknowledge that the software was developed
1483 by the University of California, Berkeley, the University of Illinois,
1484 Urbana, and Sun Microsystems, Inc. The name of either University
1485 or Sun Microsystems may not be used to endorse or promote products
1486 derived from this software without specific prior written permission.
1487 THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR
1488 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1489 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1490 PURPOSE.
1491 !!Options Cross Key
1492
1493
1494 Here is a list of options alphabetized by long option, to
1495 help you find the corresponding short option.
1496
1497
1498 --blank-lines-after-commas -bc
1499 --blank-lines-after-declarations -bad
1500 --blank-lines-after-procedures -bap
1501 --blank-lines-before-block-comments -bbb
1502 --braces-after-if-line -bl
1503 --brace-indent -bli
1504 --braces-after-struct-decl-line -bls
1505 --braces-on-if-line -br
1506 --braces-on-struct-decl-line -brs
1507 --break-after-boolean-operator -nbbo
1508 --break-before-boolean-operator -bbo
1509 --break-function-decl-args -bfda
1510 --case-indentation -cli''n
1511 ''--case-brace-indentation -cbi''n
1512 ''--comment-delimiters-on-blank-lines -cdb
1513 --comment-indentation -c''n
1514 ''--continuation-indentation -ci''n
1515 ''--continue-at-parentheses -lp
1516 --cuddle-do-while -cdw
1517 --cuddle-else -ce
1518 --declaration-comment-column -cd''n
1519 ''--declaration-indentation -di''n
1520 ''--dont-break-function-decl-args -nbfda
1521 --dont-break-procedure-type -npsl
1522 --dont-cuddle-do-while -ncdw
1523 --dont-cuddle-else -nce
1524 --dont-format-comments -nfca
1525 --dont-format-first-column-comments -nfc1
1526 --dont-line-up-parentheses -nlp
1527 --dont-space-special-semicolon -nss
1528 --dont-star-comments -nsc
1529 --else-endif-column -cp''n
1530 ''--format-all-comments -fca
1531 --format-first-column-comments -fc1
1532 --gnu-style -gnu
1533 --honour-newlines -hnl
1534 --ignore-newlines -nhnl
1535 --ignore-profile -npro
1536 --indent-level -i''n
1537 ''--k-and-r-style -kr
1538 --leave-optional-blank-lines -nsob
1539 --leave-preprocessor-space -lps
1540 --line-comments-indentation -d''n
1541 ''--line-length -l''n
1542 ''--no-blank-lines-after-commas -nbc
1543 --no-blank-lines-after-declarations -nbad
1544 --no-blank-lines-after-procedures -nbap
1545 --no-blank-lines-before-block-comments -nbbb
1546 --no-comment-delimiters-on-blank-lines -ncdb
1547 --no-space-after-casts -ncs
1548 --no-parameter-indentation -nip
1549 --no-space-after-for -nsaf
1550 --no-space-after-function-call-names -npcs
1551 --no-space-after-if -nsai
1552 --no-space-after-parentheses -nprs
1553 --no-space-after-while -nsaw
1554 --no-tabs -nut
1555 --no-verbosity -nv
1556 --original -orig
1557 --parameter-indentation -ip''n
1558 ''--paren-indentation -pi''n
1559 ''--preserve-mtime -pmt
1560 --procnames-start-lines -psl
1561 --space-after-cast -cs
1562 --space-after-for -saf
1563 --space-after-if -sai
1564 --space-after-parentheses -prs
1565 --space-after-procedure-calls -pcs
1566 --space-after-while -saw
1567 --space-special-semicolon -ss
1568 --standard-output -st
1569 --start-left-side-of-comments -sc
1570 --struct-brace-indentation -sbi''n
1571 ''--swallow-optional-blank-lines -sob
1572 --tab-size -ts''n
1573 ''--use-tabs -ut
1574 --verbose -v
1575 !!RETURN VALUE
1576
1577
1578 Unknown
1579 !!FILES
1580
1581
1582 ''$HOME/.indent.pro'' holds default options for indent.
1583 !!AUTHORS
1584
1585
1586 Carlo Wood
1587 Joseph Arceneaux
1588 Jim Kingdon
1589 David Ingamells
1590 !!HISTORY
1591
1592
1593 Derived from the UCB program
1594 !!COPYING
1595
1596
1597 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free
1598 Software Foundation, Inc. Copyright (C) 1995, 1996 Joseph
1599 Arceneaux. Copyright (C) 1999 Carlo Wood. Copyright (C) 2001
1600 David Ingamells.
1601
1602
1603 Permission is granted to make and distribute verbatim copies
1604 of this manual provided the copyright notice and this
1605 permission notice are preserved on all copies.
1606 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.