📄 indent.1
字号:
.SH "INVOKING INDENT"As of version 1.3, the format of the \fBindent\fR command is:.in +5.nf.naindent [\fIoptions\fR] [\fIinput-files\fR]indent [\fIoptions\fR] [\fIsingle-input-file\fR] [-o \fIoutput-file\fR].in -5.ad.fiThis format is different from earlier versions and other versions of.B indent\fR.In the first form, one or more input files are specified. \fBindent\fRmakes a backup copy of each file, and the original file is replaced withits indented version. See \fBBACKUP\ FILES\fR, for an explanation of howbackups are made.In the second form, only one input file is specified. In this case, orwhen the standard input is used, you may specify an output file afterthe \`-o\' option.To cause \fBindent\fR to write to standard output, use the \`-st\'option. This is only allowed when there is only one input file, or whenthe standard input is used.If no input files are named, the standard input is read for input.Also, if a filename named \`-\' is specified, then the standard inputis read.As an example, each of the following commands will input the program\`slithy_toves.c\' and write its indented text to\`slithy_toves.out\':.in +5.nf.naindent slithy_toves.c -o slithy_toves.outindent -st slithy_toves.c > slithy_toves.outcat slithy_toves.c | indent -o slithy_toves.out.in -5.ad.fiMost other options to \fBindent\fR control how programs are formatted.As of version 1.2, \fBindent\fR also recognizes a long name for eachoption name. Long options are prefixed by either \`--\' or\`+\'.[ \`+\' is being superseded by \`--\' tomaintain consistency with the POSIX standard.] In most of this document,the traditional, short names are used for the sake of brevity.See \fBOPTION\ SUMMARY\fR, for a list of options, including both long andshort names.Here is another example:.in +5.nf.naindent -br test/metabolism.c -l85.in -5.ad.fiThis 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\'.Equivalent invocations using long option names for this example wouldbe:.in +5.nf.naindent --braces-on-if-line --line-length185 test/metabolism.cindent +braces-on-if-line +line-length185 test/metabolism.c.in -5.ad.fiIf you find that you often use \fBindent\fR with the same options, youmay put those options into a file named \`.indent.pro\'..B indent\fR will look for a profile file in three places. First it will checkthe environment variable \fBINDENT_PROFILE\fR. If that exists its value is expected to name the file that is to be used. If the environment variable does not exist, indent looks for \`.indent.pro\' in the current directory and use that if found. Finally \fBindent\fR will searchyour home directory for \`.indent.pro\' and use that file if it isfound. This behaviour is different from that of other versions of.B indent\fR, which load both files if they both exist.The format of \`.indent.pro\' is simply a list of options, just asthey would appear on the command line, separated by white space (tabs,spaces, and newlines). Options in \`.indent.pro\' may be surrounded by Cor C++ comments, in which case they are ignored.Command line switches are handled \fIafter\fR processing\`.indent.pro\'. Options specified later override argumentsspecified earlier, with one exception: Explicitly specified optionsalways override background options (See \fBCOMMON\ STYLES\fR). You canprevent \fBindent\fR from reading an \`.indent.pro\' file byspecifying the \`-npro\' option..SH "BACKUP FILES"As of version 1.3, GNU \fBindent\fR makes GNU-style backup files, thesame way GNU Emacs does. This means that either \fIsimple\fR or.I numbered\fR backup filenames may be made.Simple backup file names are generated by appending a suffix to theoriginal file name. The default for this suffix is theone-character string \`~\' (tilde). Thus, the backup file for\`python.c\' would be \`python.c~\'.Instead of the default, you may specify any string as a suffix bysetting the environment variable \fBSIMPLE_BACKUP_SUFFIX\fR toyour preferred suffix.Numbered backup versions of a file \`momeraths.c\' look like\`momeraths.c.~23~\', where 23 is the version of this particularbackup. When making a numbered backup of the file \`src/momeraths.c\',the backup file will be named \`src/momeraths.c.~\fIV\fR~\', where.I V\fR is one greater than the highest version currently existing inthe directory \`src\'. The environment variable \fBVERSION_WIDTH\fRcontrols the number of digits, using left zero padding when necessary.For instance, setting this variable to "2" will lead to the backupfile being named \`momeraths.c.~04~\'.The type of backup file made is controlled by the value of theenvironment variable \fBVERSION_CONTROL\fR. If it is the string\`simple\', then only simple backups will be made. If its value isthe string \`numbered\', then numbered backups will be made. If itsvalue is \`numbered-existing\', then numbered backups will be made ifthere \fIalready exist\fR numbered backups for the file being indented;otherwise, a simple backup is made. If \fBVERSION_CONTROL\fR is notset, then \fBindent\fR assumes the behaviour of\`numbered-existing\'.Other versions of \fBindent\fR use the suffix \`.BAK\' in namingbackup files. This behaviour can be emulated by setting.B SIMPLE_BACKUP_SUFFIX\fR to \`.BAK\'.Note also that other versions of \fBindent\fR make backups in thecurrent directory, rather than in the directory of the source file asGNU \fBindent\fR now does..SH "COMMON STYLES"There are several common styles of C code, including the GNU style, theKernighan & Ritchie style, and the original Berkeley style. A style maybe selected with a single \fIbackground\fR option, which specifies a setof values for all other options. However, explicitly specified optionsalways override options implied by a background option.As of version 1.2, the default style of GNU \fBindent\fR is the GNUstyle. Thus, it is no longer necessary to specify the option\`-gnu\' to obtain this format, although doing so will not cause anerror. Option settings which correspond to the GNU style are:.in +5.nf.na-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai-saw -nsc -nsob.in -5.ad.fiThe GNU coding style is that preferred by the GNU project. It is thestyle that the GNU Emacs C mode encourages and which is used in the Cportions of GNU Emacs. (People interested in writing programs forProject GNU should get a copy of "The GNU Coding Standards", whichalso covers semantic and portability issues such as memory usage, thesize of integers, etc.)The Kernighan & Ritchie style is used throughout their well-known book"The C Programming Language". It is enabled with the \`-kr\'option. The Kernighan & Ritchie style corresponds to the following setof options:.in +5.nf.na-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs-nprs -npsl -saf -sai -saw -nsc -nsob -nss.in -5.ad.fiKernighan & Ritchie style does not put comments to the right of code inthe same column at all times (nor does it use only one space to theright of the code), so for this style \fBindent\fR has arbitrarilychosen column 33.The style of the original Berkeley \fBindent\fR may be obtained byspecifying \`-orig\' (or by specifying \`--original\', using thelong option name). This style is equivalent to the following settings:.in +5.nf.na-nbad -nbap -bbo -bc -br -brs -c33 -cd33 -cdb -ce -ci4 -cli0-cp33 -di16 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -psl-saf -sai -saw -sc -nsob -nss -ts8.in -5.ad.fi.SH "BLANK LINES"Various programming styles use blank lines in different places..B indent\fR has a number of options to insert or delete blank lines inspecific places.The \`-bad\' option causes \fBindent\fR to force a blank line afterevery block of declarations. The \`-nbad\' option causes.B indent\fR not to force such blank lines.The \`-bap\' option forces a blank line after every procedure body.The \`-nbap\' option forces no such blank line.The \`-bbb\' option forces a blank line before every boxed comment(See \fBCOMMENTS\fR.)The \`-nbbb\' option does not force such blank lines.The \`-sob\' option causes \fBindent\fR to swallow optional blanklines (that is, any optional blank lines present in the input will beremoved from the output). If the \`-nsob\' is specified, any blanklines present in the input file will be copied to the output file..SH "--blank-lines-after-declarations"The \`-bad\' option forces a blank line after every block ofdeclarations. The \`-nbad\' option does not add any such blanklines.For example, given the input.in +5.nf.nachar *foo;char *bar;/* This separates blocks of declarations. */int baz;.in -5.ad.fi.B indent -bad\fR produces.in +5.nf.nachar *foo;char *bar;/* This separates blocks of declarations. */int baz;.in -5.ad.fiand \fBindent -nbad\fR produces.in +5.nf.nachar *foo;char *bar;/* This separates blocks of declarations. */int baz;.in -5.ad.fi.SH "--blank-lines-after-procedures"The \`-bap\' option forces a blank line after every procedure body.For example, given the input.in +5.nf.naintfoo (){ puts("Hi");}/* The procedure bar is even less interesting. */char *bar (){ puts("Hello");}.in -5.ad.fi.B indent -bap\fR produces.in +5.nf.naintfoo (){ puts ("Hi");}/* The procedure bar is even less interesting. */char *bar (){ puts ("Hello");}.in -5.ad.fiand \fBindent -nbap\fR produces.in +5.nf.naintfoo (){ puts ("Hi");}/* The procedure bar is even less interesting. */char *bar (){ puts ("Hello");}.in -5.ad.fiNo blank line will be added after the procedure \fBfoo\fR..SH "COMMENTS".B indent\fR formats both C and C++ comments. C comments are begun with\`/*\', terminated with \`*/\' and may contain newline characters.C++ comments begin with the delimiter \`//\' and end at the newline..B indent\fR handles comments differently depending upon their context..B indent\fR attempts to distinguish between comments which followstatements, comments which follow declarations, comments followingpreprocessor directives, and comments which are not preceded by code ofany sort, i.e., they begin the text of the line (although notneccessarily in column 1)..B indent\fR further distinguishes between comments found outside ofprocedures and aggregates, and those found within them. In particular,comments beginning a line found within a procedure will be indented tothe column at which code is currently indented. The exception to this acomment beginning in the leftmost column; such a comment is outputat that column..B indent\fR attempts to leave \fIboxed comments\fR unmodified. Thegeneral idea of such a comment is that it is enclosed in a rectangle or\`\`box\'\' of stars or dashes to visually set it apart. More precisely,boxed comments are defined as those in which the initial \`/*\' isfollowed immediately by the character \`*\', \`=\', \`_\', or\`-\', or those in which the beginning comment delimiter (\`/*\')is on a line by itself, and the following line begins with a \`*\' inthe same column as the star of the opening delimiter.Examples of boxed comments are:.in +5.nf.na/********************** * Comment in a box!! * **********************/ /* * A different kind of scent, * for a different kind of comment. */.in -5.ad.fi.B indent\fR attempts to leave boxed comments exactly as they are foundin the source file. Thus the indentation of the comment is unchanged,and its length is not checked in any way. The only alteration made isthat an embedded tab character may be converted into the appropriatenumber of spaces.If the \`-bbb\' option is specified, all such boxed comments will bepreceded by a blank line, unless such a comment is preceded by code.Comments which are not boxed comments may be formatted, which means thatthe line is broken to fit within a right margin and left-filled withwhitespace. Single newlines are equivalent to a space, but blank lines(two or more newlines in a row) are taken to mean a paragraph break.Formatting of comments which begin after the first column is enabledwith the \`-fca\' option. To format those beginning in column one,specify \`-fc1\'. Such formatting is disabled by default.The right margin for formatting defaults to 78, but may be changed withthe \`-lc\' option. If the margin specified does not allow thecomment to be printed, the margin will be automatically extended for theduration of that comment. The margin is not respected if the comment isnot being formatted.If the comment begins a line (i.e., there is no program text to itsleft), it will be indented to the column it was found in unless thecomment is within a block of code. In that case, such a comment will bealigned with the indented code of that block (unless the comment beganin the first column). This alignment may be affected by the \`-d\'option, which specifies an amount by which such comments are moved to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -