📄 standards.texi
字号:
External symbols that are not documented entry points for the usershould have names beginning with @samp{_}. They should also containthe chosen name prefix for the library, to prevent collisions withother libraries. These can go in the same files with user entrypoints if you like.Static functions and variables can be used as you like and need notfit any naming convention.@node Errors@section Formatting Error MessagesError messages from compilers should look like this:@example@var{source-file-name}:@var{lineno}: @var{message}@end exampleError messages from other noninteractive programs should look like this:@example@var{program}:@var{source-file-name}:@var{lineno}: @var{message}@end example@noindentwhen there is an appropriate source file, or like this:@example@var{program}: @var{message}@end example@noindentwhen there is no relevant source file.In an interactive program (one that is reading commands from aterminal), it is better not to include the program name in an errormessage. The place to indicate which program is running is in theprompt or with the screen layout. (When the same program runs withinput from a source other than a terminal, it is not interactive andwould do best to print error messages using the noninteractive style.)The string @var{message} should not begin with a capital letter whenit follows a program name and/or file name. Also, it should not endwith a period.Error messages from interactive programs, and other messages such asusage messages, should start with a capital letter. But they should notend with a period.@node User Interfaces@section Standards for Command Line InterfacesPlease don't make the behavior of a utility depend on the name usedto invoke it. It is useful sometimes to make a link to a utilitywith a different name, and that should not change what it does.Instead, use a run time option or a compilation switch or bothto select among the alternate behaviors.Likewise, please don't make the behavior of the program depend on thetype of output device it is used with. Device independence is animportant principle of the system's design; do not compromise itmerely to save someone from typing an option now and then.If you think one behavior is most useful when the output is to aterminal, and another is most useful when the output is a file or apipe, then it is usually best to make the default behavior the one thatis useful with output to a terminal, and have an option for the otherbehavior.Compatibility requires certain programs to depend on the type of outputdevice. It would be disastrous if @code{ls} or @code{sh} did not do soin the way all users expect. In some of these cases, we supplement theprogram with a preferred alternate version that does not depend on theoutput device type. For example, we provide a @code{dir} program muchlike @code{ls} except that its default output format is alwaysmulti-column format.It is a good idea to follow the @sc{POSIX} guidelines for thecommand-line options of a program. The easiest way to do this is to use@code{getopt} to parse them. Note that the GNU version of @code{getopt}will normally permit options anywhere among the arguments unless thespecial argument @samp{--} is used. This is not what @sc{POSIX}specifies; it is a GNU extension.Please define long-named options that are equivalent to thesingle-letter Unix-style options. We hope to make GNU more userfriendly this way. This is easy to do with the GNU function@code{getopt_long}.One of the advantages of long-named options is that they can beconsistent from program to program. For example, users should be ableto expect the ``verbose'' option of any GNU program which has one, to bespelled precisely @samp{--verbose}. To achieve this uniformity, look atthe table of common long-option names when you choose the option namesfor your program (@pxref{Option Table}).It is usually a good idea for file names given as ordinary arguments tobe input files only; any output files would be specified using options(preferably @samp{-o} or @samp{--output}). Even if you allow an outputfile name as an ordinary argument for compatibility, try to provide anoption as another way to specify it. This will lead to more consistencyamong GNU utilities, and fewer idiosyncracies for users to remember.All programs should support two standard options: @samp{--version}and @samp{--help}.@table @code@item --versionThis option should direct the program to information about its name,version, origin and legal status, all on standard output, and then exitsuccessfully. Other options and arguments should be ignored once thisis seen, and the program should not perform its normal function.The first line is meant to be easy for a program to parse; the versionnumber proper starts after the last space. In addition, it containsthe canonical name for this program, in this format:@exampleGNU Emacs 19.30@end example@noindentThe program's name should be a constant string; @emph{don't} compute itfrom @code{argv[0]}. The idea is to state the standard or canonicalname for the program, not its file name. There are other ways to findout the precise file name where a command is found in @code{PATH}.If the program is a subsidiary part of a larger package, mention thepackage name in parentheses, like this:@exampleemacsserver (GNU Emacs) 19.30@end example@noindentIf the package has a version number which is different from thisprogram's version number, you can mention the package version numberjust before the close-parenthesis.If you @strong{need} to mention the version numbers of libraries whichare distributed separately from the package which contains this program,you can do so by printing an additional line of version info for eachlibrary you want to mention. Use the same format for these lines as forthe first line.Please do not mention all of the libraries that the program uses ``justfor completeness''---that would produce a lot of unhelpful clutter.Please mention library version numbers only if you find in practice thatthey are very important to you in debugging.The following line, after the version number line or lines, should be acopyright notice. If more than one copyright notice is called for, puteach on a separate line.Next should follow a brief statement that the program is free software,and that users are free to copy and change it on certain conditions. Ifthe program is covered by the GNU GPL, say so here. Also mention thatthere is no warranty, to the extent permitted by law.It is ok to finish the output with a list of the major authors of theprogram, as a way of giving credit.Here's an example of output that follows these rules:@smallexampleGNU Emacs 19.34.5Copyright (C) 1996 Free Software Foundation, Inc.GNU Emacs comes with NO WARRANTY,to the extent permitted by law.You may redistribute copies of GNU Emacsunder the terms of the GNU General Public License.For more information about these matters,see the files named COPYING.@end smallexampleYou should adapt this to your program, of course, filling in the properyear, copyright holder, name of program, and the references todistribution terms, and changing the rest of the wording as necessary.This copyright notice only needs to mention the most recent year inwhich changes were made---there's no need to list the years for previousversions' changes. You don't have to mention the name of the program inthese notices, if that is inconvenient, since it appeared in the firstline.@item --helpThis option should output brief documentation for how to invoke theprogram, on standard output, then exit successfully. Other options andarguments should be ignored once this is seen, and the program shouldnot perform its normal function.Near the end of the @samp{--help} option's output there should be a linethat says where to mail bug reports. It should have this format:@exampleReport bugs to @var{mailing-address}.@end example@end table@node Option Table@section Table of Long OptionsHere is a table of long options used by GNU programs. It is surelyincomplete, but we aim to list all the options that a new program mightwant to be compatible with. If you use names not already in the table,please send @email{gnu@@gnu.org} a list of them, with theirmeanings, so we can update the table.@c Please leave newlines between items in this table; it's much easier@c to update when it isn't completely squashed together and unreadable.@c When there is more than one short option for a long option name, put@c a semicolon between the lists of the programs that use them, not a@c period. --friedman@table @samp@item after-date@samp{-N} in @code{tar}.@item all@samp{-a} in @code{du}, @code{ls}, @code{nm}, @code{stty}, @code{uname},and @code{unexpand}.@item all-text@samp{-a} in @code{diff}.@item almost-all@samp{-A} in @code{ls}.@item append@samp{-a} in @code{etags}, @code{tee}, @code{time};@samp{-r} in @code{tar}.@item archive@samp{-a} in @code{cp}.@item archive-name@samp{-n} in @code{shar}.@item arglength@samp{-l} in @code{m4}.@item ascii@samp{-a} in @code{diff}.@item assign@samp{-v} in @code{gawk}.@item assume-new@samp{-W} in Make.@item assume-old@samp{-o} in Make.@item auto-check@samp{-a} in @code{recode}.@item auto-pager@samp{-a} in @code{wdiff}.@item auto-reference@samp{-A} in @code{ptx}.@item avoid-wraps@samp{-n} in @code{wdiff}.@item backward-search@samp{-B} in @code{ctags}.@item basename@samp{-f} in @code{shar}.@item batchUsed in GDB.@item baudUsed in GDB.@item before@samp{-b} in @code{tac}.@item binary@samp{-b} in @code{cpio} and @code{diff}.@item bits-per-code@samp{-b} in @code{shar}.@item block-sizeUsed in @code{cpio} and @code{tar}.@item blocks@samp{-b} in @code{head} and @code{tail}.@item break-file@samp{-b} in @code{ptx}.@item briefUsed in various programs to make output shorter.@item bytes@samp{-c} in @code{head}, @code{split}, and @code{tail}.@item c@t{++}@samp{-C} in @code{etags}.@item catenate@samp{-A} in @code{tar}.@item cdUsed in various programs to specify the directory to use.@item changes@samp{-c} in @code{chgrp} and @code{chown}.@item classify@samp{-F} in @code{ls}.@item colons@samp{-c} in @code{recode}.@item command@samp{-c} in @code{su};@samp{-x} in GDB.@item compare@samp{-d} in @code{tar}.@item compatUsed in @code{gawk}.@item compress@samp{-Z} in @code{tar} and @code{shar}.@item concatenate@samp{-A} in @code{tar}.@item confirmation@samp{-w} in @code{tar}.@item contextUsed in @code{diff}.@item copyleft@samp{-W copyleft} in @code{gawk}.@item copyright@samp{-C} in @code{ptx}, @code{recode}, and @code{wdiff};@samp{-W copyright} in @code{gawk}.@item coreUsed in GDB.@item count@samp{-q} in @code{who}.@item count-links@samp{-l} in @code{du}.@item createUsed in @code{tar} and @code{cpio}.@item cut-mark@samp{-c} in @code{shar}.@item cxref@samp{-x} in @code{ctags}.@item date@samp{-d} in @code{touch}.@item debug@samp{-d} in Make and @code{m4};@samp{-t} in Bison.@item define@samp{-D} in @code{m4}.@item defines@samp{-d} in Bison and @code{ctags}.@item delete@samp{-D} in @code{tar}.@item dereference@samp{-L} in @code{chgrp}, @code{chown}, @code{cpio}, @code{du},@code{ls}, and @code{tar}.@item dereference-args@samp{-D} in @code{du}.@item diacritics@samp{-d} in @code{recode}.@item dictionary-order@samp{-d} in @code{look}.@item diff@samp{-d} in @code{tar}.@item digits@samp{-n} in @code{csplit}.@item directorySpecify the directory to use, in various programs. In @code{ls}, itmeans to show directories themselves rather than their contents. In@code{rm} and @code{ln}, it means to not treat links to directoriesspecially.@item discard-all@samp{-x} in @code{strip}.@item discard-locals@samp{-X} in @code{strip}.@item dry-run@samp{-n} in Make.@item ed@samp{-e} in @code{diff}.@item elide-empty-files@samp{-z} in @code{csplit}.@item end-delete@samp{-x} in @code{wdiff}.@item end-insert@samp{-z} in @code{wdiff}.@item entire-new-file@samp{-N} in @code{diff}.@item environment-overrides@samp{-e} in Make.@item eof@samp{-e} in @code{xargs}.@item epochUsed in GDB.@item error-limitUsed in @code{makeinfo}.@item error-output@samp{-o} in @code{m4}.@item escape@samp{-b} in @code{ls}.@item exclude-from@samp{-X} in @code{tar}.@item execUsed in GDB.@item exit@samp{-x} in @code{xargs}.@item exit-0@samp{-e} in @code{unshar}.@item expand-tabs@samp{-t} in @code{diff}.@item expression@samp{-e} in @code{sed}.@item extern-only@samp{-g} in @code{nm}.@item extract@samp{-i} in @code{cpio};@samp{-x} in @code{tar}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -