📄 indent.1
字号:
.\" $Id$.\".TH INDENT 1L .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection.\" other parms are allowed: see man(7), man(1).SH NAMEindent \- changes the appearance of a C program by inserting or deletingwhitespace..SH SYNOPSIS.nf.naindent [-bad] [-bap] [-bbb] [-bc] [-bl] [-bliN] [-br] [-cN] [-cdN] [-cdb] [-ce] [-ciN] [-cliN] [-cpN] [-cs] [-bs] [-dN] [-diN] [-fc1] [-fca] [-gnu] [-iN] [-ipN] [-kr] [-lN] [-lp] [-nbad] [-nbap] [-nbbb] [-nbc] [-ncdb] [-nce] [-ncs] [-nfc1] [-nfca] [-nip] [-nlp] [-npcs] [-npsl] [-nsc] [-nsob] [-nss] [-nv] [-orig] [-npro] [-pcs] [-psl] [-sc] [-sob] [-ss] [-st] [-T] [-tsN] [-v] [-version] [file].ad.fi.SH "DESCRIPTION"This man page is based on the Info file indent.info, produced by Makeinfo-1.47from the input file indent.texinfo. This is Edition 0.02, 5 May 1992, ofThe `indent' Manual, for Indent Version 1.3.Copyright (C) 1989, 1992 Free Software Foundation, Inc..SH "COPYING"Permission is granted to make and distribute verbatim copies of thismanual provided the copyright notice and this permission notice arepreserved on all copies..SH "INTRODUCTION"The `indent' program can be used to make code easier to read. Itcan also convert from one style of writing C to another.`indent' understands a substantial amount about the syntax of C, butit also attempts to cope with incomplete and misformed syntax.In version 1.2 and more recent versions, the GNU style of indentingis the default..SH "INVOKING INDENT"As of version 1.3, the format of the `indent' command is:.in +5indent [OPTIONS] [INPUT-FILES]indent [OPTIONS] [SINGLE-INPUT-FILE] [-o OUTPUT-FILE].in -5This format is different from earlier versions and other versions of`indent'.In the first form, one or more input files are specified. `indent'makes a backup copy of each file, and the original file is replaced withits indented version. *Note Backup files::, for an explanation of howbackups are made.In the second form, only one input file is specified. In this case,or when the standard input is used, you may specify an output file afterthe `-o' option.To cause `indent' to write to standard output, use the `-st' option.This is only allowed when there is only one input file, or when thestandard 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 input isread.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 +5indent slithy_toves.c -o slithy_toves.outindent -st slithy_toves.c > slithy_toves.outcat slithy_toves.c | indent -o slithy_toves.out.in -5Most other options to `indent' control how programs are formatted.As of version 1.2, `indent' also recognizes a long name for each optionname. Long options are prefixed by either `--' or `+'. `+' is beingsuperseded by `--' to maintain consistency with the POSIX standard.In most of this document, the traditional, short names are used for thesake of brevity.Here is another example:.in +5indent -br test/metabolism.c -l85.in -5This will indent the program `test/metabolism.c' using the `-br' and`-l85' options, write the output back to `test/metabolism.c', and writethe original contents of `test/metabolism.c' to a backup file in thedirectory `test'.Equivalent invocations using long option names for this example wouldbe:.in +5indent --braces-on-if-line --line-length185 test/metabolism.cindent +braces-on-if-line +line-length185 test/metabolism.c.in -5If you find that you often use `indent' with the same options, youmay put those options into a file called `.indent.pro'. `indent' willfirst look for `.indent.pro' in the current directory and use that iffound. Otherwise, `indent' will search your home directory for`.indent.pro' and use that file if it is found. This behaviour isdifferent from that of other versions of `indent', which load bothfiles if they both exist.Command line switches are handled *after* processing `.indent.pro'. Options specified later override arguments specified earlier, with oneexception: Explicitly specified options always override backgroundoptions (*note Common styles::.). You can prevent `indent' fromreading an `.indent.pro' file by specifying the `-npro' option..SH "BACKUP FILES"As of version 1.3, GNU `indent' makes GNU--style backup files, thesame way GNU Emacs does. This means that either "simple" or "numbered"backup filenames may be made.Simple backup file names are generated by appending a suffix to theoriginal file name. The default for the 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 `SIMPLE_BACKUP_SUFFIX' to yourpreferred suffix.Numbered backup versions of a file `momewraths' look like`momewraths.c.~23~', where 23 is the version of this particular backup.When making a numbered backup of the file `src/momewrath.c', thebackup file will be named `src/momewrath.c.~V~', where V is one greaterthan the highest version currently existing in the directory `src'.The type of backup file made is controlled by the value of theenvironment variable `VERSION_CONTROL'. If it is the string `simple',then only simple backups will be made. If its value is the string`numbered', then numbered backups will be made. If its value is`numbered-existing', then numbered backups will be made if there*already exist* numbered backups for the file being indented;otherwise, a simple backup is made. If `VERSION_CONTROL' is not set,then `indent' assumes the behaviour of `numbered-existing'.Other versions of `indent' use the suffix `.BAK' in naming backupfiles. This behaviour can be emulated by setting`SIMPLE_BACKUP_SUFFIX' to `.BAK'.Note also that other versions of `indent' make backups in thecurrent directory, rather than in the directory of the source file asGNU `indent' now does..SH "COMMON STYLES"There are several common styles of C code, including the GNU style,the Kernighan & Ritchie style, and the original Berkeley style. Astyle may be selected with a single "background" option, whichspecifies a set of values for all other options. However, explicitlyspecified options always override options implied by a backgroundoption.As of version 1.2, the default style of GNU `indent' is the GNUstyle. Thus, it is no longer neccessary to specify the option `-gnu'to obtain this format, although doing so will not cause an error. Option settings which correspond to the GNU style are:.in +5-nbad -bap -nbbb -nbc -bl -bli2 -c33 -cd33 -ncdb -nce-cli0 -cp1 -di0 -nfc1 -nfca -i2 -ip5 -lp -pcs -psl-nsc -nsob -nss -ts8.in -5The 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', which alsocovers semantic and portability issues such as memory usage, the sizeof integers, etc.)The Kernighan & Ritchie style is used throughout their well-knownbook `The C Programming Language'. It is enabled with the `-kr'option. The Kernighan & Ritchie style corresponds to the following setof options:.in +5-nbad -bap -nbbb -nbc -br -c33 -cd33 -ncdb -ce -ci4-cli0 -cp33 -d0 -di1 -nfc1 -nfca -i4 -ip0 -l75 -lp-npcs -npsl -nsc -nsob -nss -ts8.in -5Kernighan & 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 `indent' has arbitrarily chosencolumn 33.The style of the original Berkeley `indent' may be obtained byspecifying `-orig' (or by specifyfying `--original', using the longoption name). This style is equivalent to the following settings:.in +5-nbap -nbad -nbbb -bc -br -c33 -cd33 -cdb -ce -ci4-cli0 -cp33 -d4 -di16 -fc1 -fca -i4 -ip4 -l75 -lp-npcs -psl -sc -nsob -nss -ts8.in -5.SH "BLANK LINES"Various programming styles use blank lines in different places.`indent' has a number of options to insert or delete blank lines inspecific places.The `-bad' option causes `indent' to force a blank line after everyblock of declarations. The `-nbad' option causes `indent' not to forcesuch 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 block comment. Ablock comment is one which starts in column one when formatting of suchcomments is disabled, or one with `-' or `*' immediately following the`/*'. The `-nbbb' option does not force such blank lines.The `-sob' option causes `indent' to swallow optional blank lines(that is, any optional blank lines present in the input will be removedfrom the output). If the `-nsob' is specified, any blank lines presentin the input file will be copied to the output file.The `-bad' option forces a blank line after every block ofdeclarations. The `-nbad' option does not add any such blank lines.For example, given the input.in +5.nf.na char *foo; char *bar; /* This separates blocks of declarations. */ int baz;.in -5.ad.fi`indent -bad' produces.in +5.nf.na char *foo; char *bar; /* This separates blocks of declarations. */ int baz;.in -5.ad.fiand `indent -nbad' produces.in +5.nf.na char *foo; char *bar; /* This separates blocks of declarations. */ int baz;.in -5.ad.fiThe `-bap' option forces a blank line after every procedure body.For example, given the input.in +5.nf.na int foo () { puts("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts("Hello"); }.in -5.ad.fi`indent -bap' produces.in +5.nf.na int foo () { puts ("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts ("Hello"); }.in -5.ad.fiand `indent -nbap' produces.in +5.nf.na int foo () { 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 `foo'..SH "COMMENTS"Comments are no longer formatted by default as of version 1.2. Thiscan be enabled with the `-fca' option. Doing so will cause newlines inthe comment text to be ignored and the line will be filled up to thelength of a line (which can be modified with `-l'). When formatting isenabled, blank lines indicate paragraph breaks.The `-fc1' option enables the formatting of comments which begin inthe first column. The `-nfc1' option disables the formatting of firstcolumn comments. When comment formatting is disabled, overall commentindentation may still be adjusted.The indentation of comments which do not appear to the right of codeis set by the `-d' option, which specifies the number of spaces to theleft of the surrounding code that the comment appears. For example,`-d2' places comments two spaces to the left of code; `-d0' lines upcomments with the code. The `-cdb' option controls whether the `/*'and `*/' are placed on blank lines. With `-cdb', comments look likethis:.in +5.nf.na /* * this is a comment */.in -5.ad.fiWith `-ncdb', comments look like this:.in +5.nf.na /* this is a comment */.in -5.ad.fi`-cdb' only affects block comments, not comments to the right of code. The default is `-ncdb'.Comments which appear on the same line as code are placed to theright. The column in which comments on code start is controlled by the`-c' option. The column in which comments to the right of declarationsstart is controlled by the `-cd' option. By default, they start in thesame column as comments to the right of code, which is column 33. Thecolumn number for comments to the right of `#else' and `#endif'statements is controlled by the `-cp' option. If the code on a lineextends past the comment column, the comment starts further to theright, and the right margin may be automatically extended in extremecases.If the `-sc' option is specified, `*' is placed at the left edge ofall comments. For example:.in +5.nf.na /* This is a comment which extends from one line * onto the next line, thus causing us to consider * how it should continue. */.in -5.ad.fiinstead of.in +5.nf.na /* This is a comment which extends from one line onto the next line, thus causing us to consider how it should continue. */.in -5.ad.fi.SH "STATEMENTS"The `-br' or `-bl' option specifies how to format braces.The `-br' option formats braces like this:.in +5.nf.na if (x > 0) { x--; }.in -5.ad.fiThe `-bl' option formats them like this:.in +5.nf.na if (x > 0) { x--; }.in -5.ad.fiIf you use the `-bl' option, you may also want to specify the `-bli'option. This option specifies the number of spaces by which braces areindented. `-bli2', the default, gives the result shown above. `-bli0'results in the following:.in +5.nf.na if (x > 0) { x--; }.in -5.ad.fiIf 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 tocuddle up to the immediately preceding `}'. For example, with `-br-ce' you get the following:.in +5.nf.na if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); }.in -5.ad.fiWith `-br -nce' that code would appear as.in +5.nf.na if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); }.in -5.ad.fiThe `-cli' option specifies the number of spaces that case labelsshould be indented to the right of the containing `switch' statement.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 thisfeature.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -