📄 indent.texinfo
字号:
\input texinfo @c -*-texinfo-*-@c %**start of header@setfilename indent.info@settitle @command{indent}: Indent and Format C Program Source@finalout@include version.texi@c %**end of header@c smallbook@c Note: some of the long options are too long for the index in@c smallbook format. This will need some thought. --rjc@dircategory Indent Code Formatter@direntry* Indent: (indent). C code formatter.@end direntry@synindex cp ky@setchapternewpage odd@c !BEGIN INTRO@ifinfoThis is Edition @value{EDITION} of @cite{The @command{indent} Manual},for Indent Version @value{VERSION}, last updated @value{UPDATED}.@c !END INTRO@c @vskip 0pt plus 1filll@c !BEGIN COPYINGCopyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.Copyright (C) 1995, 1996 Joseph Arceneaux.Copyright (C) 1999 Carlo Wood.Copyright (C) 2001 David Ingamells.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also that thesection entitled ``GNU General Public License'' is included exactly asin the original, and provided that the entire resulting derived work isdistributed under the terms of a permission notice identical to thisone.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that the section entitled ``GNU General Public License'' may beincluded in a translation approved by the author instead of in theoriginal English.@end ignore@c !END COPYING@end ifinfo@titlepage@title Indent@subtitle Format C Code@sp 1@subtitle Edition @value{EDITION}, for Indent Version @value{VERSION}@subtitle @value{UPDATED}@c !BEGIN AUTHORS@author Carlo Wood@author Joseph Arceneaux@author Jim Kingdon@author David Ingamells@c !END AUTHORS@page@vskip 0pt plus1filllCopyright @copyright{} 1989, 1992, 1993, 1994, 1995, 1996 Free SoftwareFoundation, Inc.Copyright @copyright{} 1995, 1996 Joseph Arceneaux.Copyright @copyright{} 1999, Carlo Wood.Copyright @copyright{} 2001, David Ingamells.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that the entireresulting derived work is distributed under the terms of a permissionnotice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Foundation.@end titlepage@page@c put the following line in the the file dir in the info directory@c under wherever you have installed emacs (assuming that@c the info file made from this file is in the file "indent")@c * indent:(indent). How to change the appearance of a C program.@ifinfo@node Top, Indent Program, (dir), (dir)@top @command{indent}: Indent and Format C Program SourceThe @command{indent} program@c !BEGIN NAMEchanges the appearance of a C program by inserting or deleting whitespace. @c !END NAMEThis is Edition @value{EDITION}, @value{UPDATED}, of @cite{The @command{indent} Manual},for Indent Version @value{VERSION}.@menu* Indent Program:: The @command{indent} Program* Option Summary:: Option Summary* Index:: Index@end menu@end ifinfo@node Indent Program, Option Summary, Top, Top@chapter The @command{indent} Program@c !BEGIN DESCRIPTION@iftexThe @command{indent} program changes the appearance of a C program byinserting or deleting whitespace.@end iftex@ifinfoThe @command{indent} program@end ifinfo@iftexIt@end iftexcan be used to make code easier to read. It can also convert from onestyle of writing C to another. @command{indent} understands a substantial amount about the syntax of C,but it also attempts to cope with incomplete and misformed syntax.In version 1.2 and more recent versions, the GNU style of indenting isthe default.@c !END DESCRIPTION@menu* Invoking indent:: Invoking @command{indent}* Backup files:: Backup Files* Common styles:: Common styles* Blank lines:: Blank lines* Comments:: Comments* Statements:: Statements* Declarations:: Declarations* Indentation:: Indentation* Breaking long lines:: Breaking long lines* Disabling Formatting:: Disabling Formatting* Miscellaneous options:: Miscellaneous options* Bugs:: Bugs* Copyright:: Copyright@end menu@c !BEGIN THEREST@node Invoking indent, Backup files, , Indent Program@section Invoking @command{indent}@cindex Invoking @command{indent}@cindex Starting @command{indent}@cindex Beginning @command{indent}As of version 1.3, the format of the @command{indent} command is:@example@groupindent [@var{options}] [@var{input-files}]indent [@var{options}] [@var{single-input-file}] [-o @var{output-file}]@end group@end exampleThis format is different from earlier versions and other versions of@command{indent}.In the first form, one or more input files are specified. @command{indent}makes a backup copy of each file, and the original file is replaced withits indented version. @xref{Backup files}, for an explanation of howbackups are made.@cindex Output File Specification@kindex -o@kindex --output-fileIn 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 @option{-o} option.@cindex Standard Output@kindex -st@kindex --standard-outputTo cause @command{indent} to write to standard output, use the @option{-st}option. This is only allowed when there is only one input file, or whenthe standard input is used.@cindex Using Standard InputIf no input files are named, the standard input is read for input.Also, if a filename named @option{-} is specified, then the standard inputis read.As an example, each of the following commands will input the program@file{slithy_toves.c} and write its indented text to@file{slithy_toves.out}:@example@groupindent slithy_toves.c -o slithy_toves.outindent -st slithy_toves.c > slithy_toves.outcat slithy_toves.c | indent -o slithy_toves.out@end group@end example@cindex Long options, use ofMost other options to @command{indent} control how programs are formatted.As of version 1.2, @command{indent} also recognizes a long name for eachoption name. Long options are prefixed by either @option{--} or@option{+}.@footnote{ @option{+} is being superseded by @option{--} tomaintain consistency with the POSIX standard.} In most of this document,the traditional, short names are used for the sake of brevity.@xref{Option Summary}, for a list of options, including both long andshort names.Here is another example:@exampleindent -br test/metabolism.c -l85@end exampleThis will indent the program @file{test/metabolism.c} using the@option{-br} and @option{-l85} options, write the output back to@file{test/metabolism.c}, and write the original contents of@file{test/metabolism.c} to a backup file in the directory @file{test}.Equivalent invocations using long option names for this example wouldbe:@example@groupindent --braces-on-if-line --line-length185 test/metabolism.cindent +braces-on-if-line +line-length185 test/metabolism.c@end group@end example@cindex @file{.indent.pro} file@cindex Initialization file@kindex -npro@kindex --ignore-profileIf you find that you often use @command{indent} with the same options, youmay put those options into a file named @file{.indent.pro}.@command{indent} will look for a profile file in three places. First it will checkthe environment variable @env{INDENT_PROFILE}. 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 @file{.indent.pro} in the current directory and use that if found. Finally @command{indent} will searchyour home directory for @file{.indent.pro} and use that file if it isfound. This behaviour is different from that of other versions of@command{indent}, which load both files if they both exist.The format of @file{.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 @file{.indent.pro} may be surrounded by Cor C++ comments, in which case they are ignored.Command line switches are handled @emph{after} processing@file{.indent.pro}. Options specified later override argumentsspecified earlier, with one exception: Explicitly specified optionsalways override background options (@pxref{Common styles}). You canprevent @command{indent} from reading an @file{.indent.pro} file byspecifying the @option{-npro} option.@refill@node Backup files, Common styles, Invoking indent, Indent Program@comment node-name, next, previous, up@section Backup Files@cindex backup filesAs of version 1.3, GNU @command{indent} makes GNU-style backup files, thesame way GNU Emacs does. This means that either @dfn{simple} or@dfn{numbered} 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 @file{~} (tilde). Thus, the backup file for@file{python.c} would be @file{python.c~}.Instead of the default, you may specify any string as a suffix bysetting the environment variable @env{SIMPLE_BACKUP_SUFFIX} toyour preferred suffix.Numbered backup versions of a file @file{momeraths.c} look like@file{momeraths.c.~23~}, where 23 is the version of this particularbackup. When making a numbered backup of the file @file{src/momeraths.c},the backup file will be named @file{src/momeraths.c.~@var{V}~}, where@var{V} is one greater than the highest version currently existing inthe directory @file{src}. The environment variable @env{VERSION_WIDTH}controls the number of digits, using left zero padding when necessary.For instance, setting this variable to "2" will lead to the backupfile being named @file{momeraths.c.~04~}.The type of backup file made is controlled by the value of theenvironment variable @env{VERSION_CONTROL}. If it is the string@samp{simple}, then only simple backups will be made. If its value isthe string @samp{numbered}, then numbered backups will be made. If itsvalue is @samp{numbered-existing}, then numbered backups will be made ifthere @emph{already exist} numbered backups for the file being indented;otherwise, a simple backup is made. If @env{VERSION_CONTROL} is notset, then @command{indent} assumes the behaviour of@samp{numbered-existing}.Other versions of @command{indent} use the suffix @file{.BAK} in namingbackup files. This behaviour can be emulated by setting@env{SIMPLE_BACKUP_SUFFIX} to @samp{.BAK}.Note also that other versions of @command{indent} make backups in thecurrent directory, rather than in the directory of the source file asGNU @command{indent} now does.@node Common styles, Blank lines, Backup files, Indent Program@comment node-name, next, previous, up@section Common stylesThere 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 @dfn{background} option, which specifies a setof values for all other options. However, explicitly specified optionsalways override options implied by a background option.@cindex GNU style@kindex -gnu@kindex --gnu-styleAs of version 1.2, the default style of GNU @command{indent} is the GNUstyle. Thus, it is no longer necessary to specify the option@option{-gnu} to obtain this format, although doing so will not cause anerror. Option settings which correspond to the GNU style are:@example@group-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@end group@end exampleThe 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 @cite{The GNU Coding Standards}, whichalso covers semantic and portability issues such as memory usage, thesize of integers, etc.)@cindex Kernighan & Ritchie style@kindex -kr@kindex --k-and-r-style@comment --kernighan-and-ritchie-style works, too, as does@comment --kernighan-and-ritchie. Which is most intuitive?The Kernighan & Ritchie style is used throughout their well-known book@cite{The C Programming Language}. It is enabled with the @option{-kr}option. The Kernighan & Ritchie style corresponds to the following setof options:@example@group-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@end group@end example@noindentKernighan & 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 @command{indent} has arbitrarilychosen column 33.@cindex Berkeley style@cindex Original Berkeley style@kindex -orig@kindex --originalThe style of the original Berkeley @command{indent} may be obtained byspecifying @option{-orig} (or by specifying @option{--original}, using thelong option name). This style is equivalent to the following settings:@example@group-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@end group@end example@node Blank lines, Comments, Common styles, Indent Program@comment node-name, next, previous, up@section Blank lines@cindex Blank linesVarious programming styles use blank lines in different places.@command{indent} has a number of options to insert or delete blank lines inspecific places.The @option{-bad} option causes @command{indent} to force a blank line afterevery block of declarations. The @option{-nbad} option causes@command{indent} not to force such blank lines.The @option{-bap} option forces a blank line after every procedure body.The @option{-nbap} option forces no such blank line.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -