Debian Codegraph @

doc/standards.texi

raw
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename standards.info
4 @settitle GNU Coding Standards
5 @c This date is automagically updated when you save this file:
6 @set lastupdate March 23, 2001
7 @c %**end of header
8
9 @ifinfo
10 @format
11 START-INFO-DIR-ENTRY
12 * Standards: (standards). GNU coding standards.
13 END-INFO-DIR-ENTRY
14 @end format
15 @end ifinfo
16
17 @c @setchapternewpage odd
18 @setchapternewpage off
19
20 @c Put everything in one index (arbitrarily chosen to be the concept index).
21 @syncodeindex fn cp
22 @syncodeindex ky cp
23 @syncodeindex pg cp
24 @syncodeindex vr cp
25
26 @c This is used by a cross ref in make-stds.texi
27 @set CODESTD 1
28 @iftex
29 @set CHAPTER chapter
30 @end iftex
31 @ifinfo
32 @set CHAPTER node
33 @end ifinfo
34
35 @ifinfo
36 GNU Coding Standards
37 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
38
39 Permission is granted to make and distribute verbatim copies of
40 this manual provided the copyright notice and this permission notice
41 are preserved on all copies.
42
43 @ignore
44 Permission is granted to process this file through TeX and print the
45 results, provided the printed document carries copying permission
46 notice identical to this one except for the removal of this paragraph
47 (this paragraph not being relevant to the printed manual).
48 @end ignore
49
50 Permission is granted to copy and distribute modified versions of this
51 manual under the conditions for verbatim copying, provided that the entire
52 resulting derived work is distributed under the terms of a permission
53 notice identical to this one.
54
55 Permission is granted to copy and distribute translations of this manual
56 into another language, under the above conditions for modified versions,
57 except that this permission notice may be stated in a translation approved
58 by the Free Software Foundation.
59 @end ifinfo
60
61 @titlepage
62 @title GNU Coding Standards
63 @author Richard Stallman
64 @author last updated @value{lastupdate}
65 @page
66
67 @vskip 0pt plus 1filll
68 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
69
70 Permission is granted to make and distribute verbatim copies of
71 this manual provided the copyright notice and this permission notice
72 are preserved on all copies.
73
74 Permission is granted to copy and distribute modified versions of this
75 manual under the conditions for verbatim copying, provided that the entire
76 resulting derived work is distributed under the terms of a permission
77 notice identical to this one.
78
79 Permission is granted to copy and distribute translations of this manual
80 into another language, under the above conditions for modified versions,
81 except that this permission notice may be stated in a translation approved
82 by the Free Software Foundation.
83 @end titlepage
84
85 @ifinfo
86 @node Top, Preface, (dir), (dir)
87 @top Version
88
89 Last updated @value{lastupdate}.
90 @end ifinfo
91
92 @menu
93 * Preface:: About the GNU Coding Standards
94 * Legal Issues:: Keeping Free Software Free
95 * Design Advice:: General Program Design
96 * Program Behavior:: Program Behavior for All Programs
97 * Writing C:: Making The Best Use of C
98 * Documentation:: Documenting Programs
99 * Managing Releases:: The Release Process
100 * References:: References to Non-Free Software or Documentation
101 * Index::
102 @end menu
103
104 @node Preface
105 @chapter About the GNU Coding Standards
106
107 The GNU Coding Standards were written by Richard Stallman and other GNU
108 Project volunteers. Their purpose is to make the GNU system clean,
109 consistent, and easy to install. This document can also be read as a
110 guide to writing portable, robust and reliable programs. It focuses on
111 programs written in C, but many of the rules and principles are useful
112 even if you write in another programming language. The rules often
113 state reasons for writing in a certain way.
114
115 This release of the GNU Coding Standards was last updated
116 @value{lastupdate}.
117
118 @cindex where to obtain @code{standards.texi}
119 @cindex downloading this manual
120 If you did not obtain this file directly from the GNU project and
121 recently, please check for a newer version. You can ftp the GNU
122 Coding Standards from any GNU FTP host in the directory
123 @file{/pub/gnu/standards/}. The GNU Coding Standards are available
124 there in several different formats: @file{standards.text},
125 @file{standards.info}, and @file{standards.dvi}, as well as the
126 Texinfo ``source'' which is divided in two files:
127 @file{standards.texi} and @file{make-stds.texi}. The GNU Coding
128 Standards are also available on the GNU World Wide Web server:
129 @uref{http://www.gnu.org/prep/standards_toc.html}.
130
131 Corrections or suggestions for this document should be sent to
132 @email{bug-standards@@gnu.org}. If you make a suggestion, please include a
133 suggested new wording for it; our time is limited. We prefer a context
134 diff to the @file{standards.texi} or @file{make-stds.texi} files, but if
135 you don't have those files, please mail your suggestion anyway.
136
137 @node Legal Issues
138 @chapter Keeping Free Software Free
139 @cindex legal aspects
140
141 This @value{CHAPTER} discusses how you can make sure that GNU software
142 avoids legal difficulties, and other related issues.
143
144 @menu
145 * Reading Non-Free Code:: Referring to Proprietary Programs
146 * Contributions:: Accepting Contributions
147 * Trademarks:: How We Deal with Trademark Issues
148 @end menu
149
150 @node Reading Non-Free Code
151 @section Referring to Proprietary Programs
152 @cindex proprietary programs
153 @cindex avoiding proprietary code
154
155 Don't in any circumstances refer to Unix source code for or during
156 your work on GNU! (Or to any other proprietary programs.)
157
158 If you have a vague recollection of the internals of a Unix program,
159 this does not absolutely mean you can't write an imitation of it, but
160 do try to organize the imitation internally along different lines,
161 because this is likely to make the details of the Unix version
162 irrelevant and dissimilar to your results.
163
164 For example, Unix utilities were generally optimized to minimize
165 memory use; if you go for speed instead, your program will be very
166 different. You could keep the entire input file in core and scan it
167 there instead of using stdio. Use a smarter algorithm discovered more
168 recently than the Unix program. Eliminate use of temporary files. Do
169 it in one pass instead of two (we did this in the assembler).
170
171 Or, on the contrary, emphasize simplicity instead of speed. For some
172 applications, the speed of today's computers makes simpler algorithms
173 adequate.
174
175 Or go for generality. For example, Unix programs often have static
176 tables or fixed-size strings, which make for arbitrary limits; use
177 dynamic allocation instead. Make sure your program handles NULs and
178 other funny characters in the input files. Add a programming language
179 for extensibility and write part of the program in that language.
180
181 Or turn some parts of the program into independently usable libraries.
182 Or use a simple garbage collector instead of tracking precisely when
183 to free memory, or use a new GNU facility such as obstacks.
184
185 @node Contributions
186 @section Accepting Contributions
187 @cindex legal papers
188 @cindex accepting contributions
189
190 If the program you are working on is copyrighted by the Free Software
191 Foundation, then when someone else sends you a piece of code to add to
192 the program, we need legal papers to use it---just as we asked you to
193 sign papers initially. @emph{Each} person who makes a nontrivial
194 contribution to a program must sign some sort of legal papers in order
195 for us to have clear title to the program; the main author alone is not
196 enough.
197
198 So, before adding in any contributions from other people, please tell
199 us, so we can arrange to get the papers. Then wait until we tell you
200 that we have received the signed papers, before you actually use the
201 contribution.
202
203 This applies both before you release the program and afterward. If
204 you receive diffs to fix a bug, and they make significant changes, we
205 need legal papers for that change.
206
207 This also applies to comments and documentation files. For copyright
208 law, comments and code are just text. Copyright applies to all kinds of
209 text, so we need legal papers for all kinds.
210
211 We know it is frustrating to ask for legal papers; it's frustrating for
212 us as well. But if you don't wait, you are going out on a limb---for
213 example, what if the contributor's employer won't sign a disclaimer?
214 You might have to take that code out again!
215
216 You don't need papers for changes of a few lines here or there, since
217 they are not significant for copyright purposes. Also, you don't need
218 papers if all you get from the suggestion is some ideas, not actual code
219 which you use. For example, if someone send you one implementation, but
220 you write a different implementation of the same idea, you don't need to
221 get papers.
222
223 The very worst thing is if you forget to tell us about the other
224 contributor. We could be very embarrassed in court some day as a
225 result.
226
227 We have more detailed advice for maintainers of programs; if you have
228 reached the stage of actually maintaining a program for GNU (whether
229 released or not), please ask us for a copy.
230
231 @node Trademarks
232 @section Trademarks
233 @cindex trademarks
234
235 Please do not include any trademark acknowledgements in GNU software
236 packages or documentation.
237
238 Trademark acknowledgements are the statements that such-and-such is a
239 trademark of so-and-so. The GNU Project has no objection to the basic
240 idea of trademarks, but these acknowledgements feel like kowtowing, so
241 we don't use them. There is no legal requirement for them.
242
243 What is legally required, as regards other people's trademarks, is to
244 avoid using them in ways which a reader might read as naming or labeling
245 our own programs or activities. For example, since ``Objective C'' is
246 (or at least was) a trademark, we made sure to say that we provide a
247 ``compiler for the Objective C language'' rather than an ``Objective C
248 compiler''. The latter is meant to be short for the former, but it does
249 not explicitly state the relationship, so it could be misinterpreted as
250 using ``Objective C'' as a label for the compiler rather than for the
251 language.
252
253 @node Design Advice
254 @chapter General Program Design
255 @cindex program design
256
257 This @value{CHAPTER} discusses some of the issues you should take into
258 account when designing your program.
259
260 @c Standard or ANSI C
261 @c
262 @c In 1989 the American National Standards Institute (ANSI) standardized
263 @c C as standard X3.159-1989. In December of that year the
264 @c International Standards Organization ISO adopted the ANSI C standard
265 @c making minor changes. In 1990 ANSI then re-adopted ISO standard
266 @c C. This version of C is known as either ANSI C or Standard C.
267
268 @c A major revision of the C Standard appeared in 1999.
269
270 @menu
271 * Source Language:: Which languages to use.
272 * Compatibility:: Compatibility with other implementations
273 * Using Extensions:: Using non-standard features
274 * Standard C:: Using Standard C features
275 @end menu
276
277 @node Source Language
278 @section Which Languages to Use
279 @cindex programming languages
280
281 When you want to use a language that gets compiled and runs at high
282 speed, the best language to use is C. Using another language is like
283 using a non-standard feature: it will cause trouble for users. Even if
284 GCC supports the other language, users may find it inconvenient to have
285 to install the compiler for that other language in order to build your
286 program. For example, if you write your program in C++, people will
287 have to install the GNU C++ compiler in order to compile your program.
288
289 C has one other advantage over C++ and other compiled languages: more
290 people know C, so more people will find it easy to read and modify the
291 program if it is written in C.
292
293 So in general it is much better to use C, rather than the
294 comparable alternatives.
295
296 But there are two exceptions to that conclusion:
297
298 @itemize @bullet
299 @item
300 It is no problem to use another language to write a tool specifically
301 intended for use with that language. That is because the only people
302 who want to build the tool will be those who have installed the other
303 language anyway.
304
305 @item
306 If an application is of interest only to a narrow part of the community,
307 then the question of which language it is written in has less effect on
308 other people, so you may as well please yourself.
309 @end itemize
310
311 Many programs are designed to be extensible: they include an interpreter
312 for a language that is higher level than C. Often much of the program
313 is written in that language, too. The Emacs editor pioneered this
314 technique.
315
316 @cindex GUILE
317 The standard extensibility interpreter for GNU software is GUILE, which
318 implements the language Scheme (an especially clean and simple dialect
319 of Lisp). @uref{http://www.gnu.org/software/guile/}. We don't reject
320 programs written in other ``scripting languages'' such as Perl and
321 Python, but using GUILE is very important for the overall consistency of
322 the GNU system.
323
324 @node Compatibility
325 @section Compatibility with Other Implementations
326 @cindex compatibility with C and @sc{posix} standards
327 @cindex @sc{posix} compatibility
328
329 With occasional exceptions, utility programs and libraries for GNU
330 should be upward compatible with those in Berkeley Unix, and upward
331 compatible with Standard C if Standard C specifies their
332 behavior, and upward compatible with @sc{posix} if @sc{posix} specifies
333 their behavior.
334
335 When these standards conflict, it is useful to offer compatibility
336 modes for each of them.
337
338 @cindex options for compatibility
339 Standard C and @sc{posix} prohibit many kinds of extensions. Feel
340 free to make the extensions anyway, and include a @samp{--ansi},
341 @samp{--posix}, or @samp{--compatible} option to turn them off.
342 However, if the extension has a significant chance of breaking any real
343 programs or scripts, then it is not really upward compatible. So you
344 should try to redesign its interface to make it upward compatible.
345
346 @cindex @code{POSIXLY_CORRECT}, environment variable
347 Many GNU programs suppress extensions that conflict with @sc{posix} if the
348 environment variable @code{POSIXLY_CORRECT} is defined (even if it is
349 defined with a null value). Please make your program recognize this
350 variable if appropriate.
351
352 When a feature is used only by users (not by programs or command
353 files), and it is done poorly in Unix, feel free to replace it
354 completely with something totally different and better. (For example,
355 @code{vi} is replaced with Emacs.) But it is nice to offer a compatible
356 feature as well. (There is a free @code{vi} clone, so we offer it.)
357
358 Additional useful features are welcome regardless of whether
359 there is any precedent for them.
360
361 @node Using Extensions
362 @section Using Non-standard Features
363 @cindex non-standard extensions
364
365 Many GNU facilities that already exist support a number of convenient
366 extensions over the comparable Unix facilities. Whether to use these
367 extensions in implementing your program is a difficult question.
368
369 On the one hand, using the extensions can make a cleaner program.
370 On the other hand, people will not be able to build the program
371 unless the other GNU tools are available. This might cause the
372 program to work on fewer kinds of machines.
373
374 With some extensions, it might be easy to provide both alternatives.
375 For example, you can define functions with a ``keyword'' @code{INLINE}
376 and define that as a macro to expand into either @code{inline} or
377 nothing, depending on the compiler.
378
379 In general, perhaps it is best not to use the extensions if you can
380 straightforwardly do without them, but to use the extensions if they
381 are a big improvement.
382
383 An exception to this rule are the large, established programs (such as
384 Emacs) which run on a great variety of systems. Using GNU extensions in
385 such programs would make many users unhappy, so we don't do that.
386
387 Another exception is for programs that are used as part of compilation:
388 anything that must be compiled with other compilers in order to
389 bootstrap the GNU compilation facilities. If these require the GNU
390 compiler, then no one can compile them without having them installed
391 already. That would be extremely troublesome in certain cases.
392
393 @node Standard C
394 @section Standard C and Pre-Standard C
395 @cindex @sc{ansi} C standard
396
397 1989 Standard C is widespread enough now that it is ok to use its
398 features in new programs. There is one exception: do not ever use the
399 ``trigraph'' feature of Standard C.
400
401 1999 Standard C is not widespread yet, so please do not require its
402 features in programs. It is ok to use its features if they are present.
403
404 However, it is easy to support pre-standard compilers in most programs,
405 so if you know how to do that, feel free. If a program you are
406 maintaining has such support, you should try to keep it working.
407
408 @cindex function prototypes
409 To support pre-standard C, instead of writing function definitions in
410 standard prototype form,
411
412 @example
413 int
414 foo (int x, int y)
415 @dots{}
416 @end example
417
418 @noindent
419 write the definition in pre-standard style like this,
420
421 @example
422 int
423 foo (x, y)
424 int x, y;
425 @dots{}
426 @end example
427
428 @noindent
429 and use a separate declaration to specify the argument prototype:
430
431 @example
432 int foo (int, int);
433 @end example
434
435 You need such a declaration anyway, in a header file, to get the benefit
436 of prototypes in all the files where the function is called. And once
437 you have the declaration, you normally lose nothing by writing the
438 function definition in the pre-standard style.
439
440 This technique does not work for integer types narrower than @code{int}.
441 If you think of an argument as being of a type narrower than @code{int},
442 declare it as @code{int} instead.
443
444 There are a few special cases where this technique is hard to use. For
445 example, if a function argument needs to hold the system type
446 @code{dev_t}, you run into trouble, because @code{dev_t} is shorter than
447 @code{int} on some machines; but you cannot use @code{int} instead,
448 because @code{dev_t} is wider than @code{int} on some machines. There
449 is no type you can safely use on all machines in a non-standard
450 definition. The only way to support non-standard C and pass such an
451 argument is to check the width of @code{dev_t} using Autoconf and choose
452 the argument type accordingly. This may not be worth the trouble.
453
454 In order to support pre-standard compilers that do not recognize
455 prototypes, you may want to use a preprocessor macro like this:
456
457 @example
458 /* Declare the prototype for a general external function. */
459 #if defined (__STDC__) || defined (WINDOWSNT)
460 #define P_(proto) proto
461 #else
462 #define P_(proto) ()
463 #endif
464 @end example
465
466 @node Program Behavior
467 @chapter Program Behavior for All Programs
468
469 This @value{CHAPTER} describes conventions for writing robust
470 software. It also describes general standards for error messages, the
471 command line interface, and how libraries should behave.
472
473 @menu
474 * Semantics:: Writing robust programs
475 * Libraries:: Library behavior
476 * Errors:: Formatting error messages
477 * User Interfaces:: Standards about interfaces generally
478 * Graphical Interfaces:: Standards for graphical interfaces
479 * Command-Line Interfaces:: Standards for command line interfaces
480 * Option Table:: Table of long options
481 * Memory Usage:: When and how to care about memory needs
482 * File Usage:: Which files to use, and where
483 @end menu
484
485 @node Semantics
486 @section Writing Robust Programs
487
488 @cindex arbitrary limits on data
489 Avoid arbitrary limits on the length or number of @emph{any} data
490 structure, including file names, lines, files, and symbols, by allocating
491 all data structures dynamically. In most Unix utilities, ``long lines
492 are silently truncated''. This is not acceptable in a GNU utility.
493
494 @cindex @code{NUL} characters
495 Utilities reading files should not drop NUL characters, or any other
496 nonprinting characters @emph{including those with codes above 0177}.
497 The only sensible exceptions would be utilities specifically intended
498 for interface to certain types of terminals or printers
499 that can't handle those characters.
500 Whenever possible, try to make programs work properly with
501 sequences of bytes that represent multibyte characters, using encodings
502 such as UTF-8 and others.
503
504 @cindex error messages
505 Check every system call for an error return, unless you know you wish to
506 ignore errors. Include the system error text (from @code{perror} or
507 equivalent) in @emph{every} error message resulting from a failing
508 system call, as well as the name of the file if any and the name of the
509 utility. Just ``cannot open foo.c'' or ``stat failed'' is not
510 sufficient.
511
512 @cindex @code{malloc} return value
513 @cindex memory allocation failure
514 Check every call to @code{malloc} or @code{realloc} to see if it
515 returned zero. Check @code{realloc} even if you are making the block
516 smaller; in a system that rounds block sizes to a power of 2,
517 @code{realloc} may get a different block if you ask for less space.
518
519 In Unix, @code{realloc} can destroy the storage block if it returns
520 zero. GNU @code{realloc} does not have this bug: if it fails, the
521 original block is unchanged. Feel free to assume the bug is fixed. If
522 you wish to run your program on Unix, and wish to avoid lossage in this
523 case, you can use the GNU @code{malloc}.
524
525 You must expect @code{free} to alter the contents of the block that was
526 freed. Anything you want to fetch from the block, you must fetch before
527 calling @code{free}.
528
529 If @code{malloc} fails in a noninteractive program, make that a fatal
530 error. In an interactive program (one that reads commands from the
531 user), it is better to abort the command and return to the command
532 reader loop. This allows the user to kill other processes to free up
533 virtual memory, and then try the command again.
534
535 @cindex command-line arguments, decoding
536 Use @code{getopt_long} to decode arguments, unless the argument syntax
537 makes this unreasonable.
538
539 When static storage is to be written in during program execution, use
540 explicit C code to initialize it. Reserve C initialized declarations
541 for data that will not be changed.
542 @c ADR: why?
543
544 Try to avoid low-level interfaces to obscure Unix data structures (such
545 as file directories, utmp, or the layout of kernel memory), since these
546 are less likely to work compatibly. If you need to find all the files
547 in a directory, use @code{readdir} or some other high-level interface.
548 These are supported compatibly by GNU.
549
550 @cindex signal handling
551 The preferred signal handling facilities are the BSD variant of
552 @code{signal}, and the @sc{posix} @code{sigaction} function; the
553 alternative USG @code{signal} interface is an inferior design.
554
555 Nowadays, using the @sc{posix} signal functions may be the easiest way
556 to make a program portable. If you use @code{signal}, then on GNU/Linux
557 systems running GNU libc version 1, you should include
558 @file{bsd/signal.h} instead of @file{signal.h}, so as to get BSD
559 behavior. It is up to you whether to support systems where
560 @code{signal} has only the USG behavior, or give up on them.
561
562 @cindex impossible conditions
563 In error checks that detect ``impossible'' conditions, just abort.
564 There is usually no point in printing any message. These checks
565 indicate the existence of bugs. Whoever wants to fix the bugs will have
566 to read the source code and run a debugger. So explain the problem with
567 comments in the source. The relevant data will be in variables, which
568 are easy to examine with the debugger, so there is no point moving them
569 elsewhere.
570
571 Do not use a count of errors as the exit status for a program.
572 @emph{That does not work}, because exit status values are limited to 8
573 bits (0 through 255). A single run of the program might have 256
574 errors; if you try to return 256 as the exit status, the parent process
575 will see 0 as the status, and it will appear that the program succeeded.
576
577 @cindex temporary files
578 @cindex @code{TMPDIR} environment variable
579 If you make temporary files, check the @code{TMPDIR} environment
580 variable; if that variable is defined, use the specified directory
581 instead of @file{/tmp}.
582
583 In addition, be aware that there is a possible security problem when
584 creating temporary files in world-writable directories. In C, you can
585 avoid this problem by creating temporary files in this manner:
586
587 @example
588 fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
589 @end example
590
591 @noindent
592 or by using the @code{mkstemps} function from libiberty.
593
594 In bash, use @code{set -C} to avoid this problem.
595
596 @node Libraries
597 @section Library Behavior
598 @cindex libraries
599
600 Try to make library functions reentrant. If they need to do dynamic
601 storage allocation, at least try to avoid any nonreentrancy aside from
602 that of @code{malloc} itself.
603
604 Here are certain name conventions for libraries, to avoid name
605 conflicts.
606
607 Choose a name prefix for the library, more than two characters long.
608 All external function and variable names should start with this
609 prefix. In addition, there should only be one of these in any given
610 library member. This usually means putting each one in a separate
611 source file.
612
613 An exception can be made when two external symbols are always used
614 together, so that no reasonable program could use one without the
615 other; then they can both go in the same file.
616
617 External symbols that are not documented entry points for the user
618 should have names beginning with @samp{_}. The @samp{_} should be
619 followed by the chosen name prefix for the library, to prevent
620 collisions with other libraries. These can go in the same files with
621 user entry points if you like.
622
623 Static functions and variables can be used as you like and need not
624 fit any naming convention.
625
626 @node Errors
627 @section Formatting Error Messages
628 @cindex formatting error messages
629 @cindex error messages, formatting
630
631 Error messages from compilers should look like this:
632
633 @example
634 @var{source-file-name}:@var{lineno}: @var{message}
635 @end example
636
637 @noindent
638 If you want to mention the column number, use this format:
639
640 @example
641 @var{source-file-name}:@var{lineno}:@var{column}: @var{message}
642 @end example
643
644 @noindent
645 Line numbers should start from 1 at the beginning of the file, and
646 column numbers should start from 1 at the beginning of the line. (Both
647 of these conventions are chosen for compatibility.) Calculate column
648 numbers assuming that space and all ASCII printing characters have
649 equal width, and assuming tab stops every 8 columns.
650
651 Error messages from other noninteractive programs should look like this:
652
653 @example
654 @var{program}:@var{source-file-name}:@var{lineno}: @var{message}
655 @end example
656
657 @noindent
658 when there is an appropriate source file, or like this:
659
660 @example
661 @var{program}: @var{message}
662 @end example
663
664 @noindent
665 when there is no relevant source file.
666
667 If you want to mention the column number, use this format:
668
669 @example
670 @var{program}:@var{source-file-name}:@var{lineno}:@var{column}: @var{message}
671 @end example
672
673 In an interactive program (one that is reading commands from a
674 terminal), it is better not to include the program name in an error
675 message. The place to indicate which program is running is in the
676 prompt or with the screen layout. (When the same program runs with
677 input from a source other than a terminal, it is not interactive and
678 would do best to print error messages using the noninteractive style.)
679
680 The string @var{message} should not begin with a capital letter when
681 it follows a program name and/or file name. Also, it should not end
682 with a period.
683
684 Error messages from interactive programs, and other messages such as
685 usage messages, should start with a capital letter. But they should not
686 end with a period.
687
688 @node User Interfaces
689 @section Standards for Interfaces Generally
690
691 @cindex program name and its behavior
692 @cindex behavior, dependent on program's name
693 Please don't make the behavior of a utility depend on the name used
694 to invoke it. It is useful sometimes to make a link to a utility
695 with a different name, and that should not change what it does.
696
697 Instead, use a run time option or a compilation switch or both
698 to select among the alternate behaviors.
699
700 @cindex output device and program's behavior
701 Likewise, please don't make the behavior of the program depend on the
702 type of output device it is used with. Device independence is an
703 important principle of the system's design; do not compromise it merely
704 to save someone from typing an option now and then. (Variation in error
705 message syntax when using a terminal is ok, because that is a side issue
706 that people do not depend on.)
707
708 If you think one behavior is most useful when the output is to a
709 terminal, and another is most useful when the output is a file or a
710 pipe, then it is usually best to make the default behavior the one that
711 is useful with output to a terminal, and have an option for the other
712 behavior.
713
714 Compatibility requires certain programs to depend on the type of output
715 device. It would be disastrous if @code{ls} or @code{sh} did not do so
716 in the way all users expect. In some of these cases, we supplement the
717 program with a preferred alternate version that does not depend on the
718 output device type. For example, we provide a @code{dir} program much
719 like @code{ls} except that its default output format is always
720 multi-column format.
721
722 @node Graphical Interfaces
723 @section Standards for Graphical Interfaces
724 @cindex graphical user interface
725
726 @cindex gtk
727 When you write a program that provides a graphical user interface,
728 please make it work with X Windows and the GTK toolkit unless the
729 functionality specifically requires some alternative (for example,
730 ``displaying jpeg images while in console mode'').
731
732 In addition, please provide a command-line interface to control the
733 functionality. (In many cases, the graphical user interface can be a
734 separate program which invokes the command-line program.) This is
735 so that the same jobs can be done from scripts.
736
737 @cindex corba
738 @cindex gnome
739 Please also consider providing a CORBA interface (for use from GNOME), a
740 library interface (for use from C), and perhaps a keyboard-driven
741 console interface (for use by users from console mode). Once you are
742 doing the work to provide the functionality and the graphical interface,
743 these won't be much extra work.
744
745 @node Command-Line Interfaces
746 @section Standards for Command Line Interfaces
747 @cindex command-line interface
748
749 @findex getopt
750 It is a good idea to follow the @sc{posix} guidelines for the
751 command-line options of a program. The easiest way to do this is to use
752 @code{getopt} to parse them. Note that the GNU version of @code{getopt}
753 will normally permit options anywhere among the arguments unless the
754 special argument @samp{--} is used. This is not what @sc{posix}
755 specifies; it is a GNU extension.
756
757 @cindex long-named options
758 Please define long-named options that are equivalent to the
759 single-letter Unix-style options. We hope to make GNU more user
760 friendly this way. This is easy to do with the GNU function
761 @code{getopt_long}.
762
763 One of the advantages of long-named options is that they can be
764 consistent from program to program. For example, users should be able
765 to expect the ``verbose'' option of any GNU program which has one, to be
766 spelled precisely @samp{--verbose}. To achieve this uniformity, look at
767 the table of common long-option names when you choose the option names
768 for your program (@pxref{Option Table}).
769
770 It is usually a good idea for file names given as ordinary arguments to
771 be input files only; any output files would be specified using options
772 (preferably @samp{-o} or @samp{--output}). Even if you allow an output
773 file name as an ordinary argument for compatibility, try to provide an
774 option as another way to specify it. This will lead to more consistency
775 among GNU utilities, and fewer idiosyncrasies for users to remember.
776
777 @cindex standard command-line options
778 All programs should support two standard options: @samp{--version}
779 and @samp{--help}.
780
781 @table @code
782 @cindex @samp{--version} option
783 @item --version
784 This option should direct the program to print information about its name,
785 version, origin and legal status, all on standard output, and then exit
786 successfully. Other options and arguments should be ignored once this
787 is seen, and the program should not perform its normal function.
788
789 @cindex canonical name of a program
790 @cindex program's canonical name
791 The first line is meant to be easy for a program to parse; the version
792 number proper starts after the last space. In addition, it contains
793 the canonical name for this program, in this format:
794
795 @example
796 GNU Emacs 19.30
797 @end example
798
799 @noindent
800 The program's name should be a constant string; @emph{don't} compute it
801 from @code{argv[0]}. The idea is to state the standard or canonical
802 name for the program, not its file name. There are other ways to find
803 out the precise file name where a command is found in @code{PATH}.
804
805 If the program is a subsidiary part of a larger package, mention the
806 package name in parentheses, like this:
807
808 @example
809 emacsserver (GNU Emacs) 19.30
810 @end example
811
812 @noindent
813 If the package has a version number which is different from this
814 program's version number, you can mention the package version number
815 just before the close-parenthesis.
816
817 If you @strong{need} to mention the version numbers of libraries which
818 are distributed separately from the package which contains this program,
819 you can do so by printing an additional line of version info for each
820 library you want to mention. Use the same format for these lines as for
821 the first line.
822
823 Please do not mention all of the libraries that the program uses ``just
824 for completeness''---that would produce a lot of unhelpful clutter.
825 Please mention library version numbers only if you find in practice that
826 they are very important to you in debugging.
827
828 The following line, after the version number line or lines, should be a
829 copyright notice. If more than one copyright notice is called for, put
830 each on a separate line.
831
832 Next should follow a brief statement that the program is free software,
833 and that users are free to copy and change it on certain conditions. If
834 the program is covered by the GNU GPL, say so here. Also mention that
835 there is no warranty, to the extent permitted by law.
836
837 It is ok to finish the output with a list of the major authors of the
838 program, as a way of giving credit.
839
840 Here's an example of output that follows these rules:
841
842 @smallexample
843 GNU Emacs 19.34.5
844 Copyright (C) 1996 Free Software Foundation, Inc.
845 GNU Emacs comes with NO WARRANTY,
846 to the extent permitted by law.
847 You may redistribute copies of GNU Emacs
848 under the terms of the GNU General Public License.
849 For more information about these matters,
850 see the files named COPYING.
851 @end smallexample
852
853 You should adapt this to your program, of course, filling in the proper
854 year, copyright holder, name of program, and the references to
855 distribution terms, and changing the rest of the wording as necessary.
856
857 This copyright notice only needs to mention the most recent year in
858 which changes were made---there's no need to list the years for previous
859 versions' changes. You don't have to mention the name of the program in
860 these notices, if that is inconvenient, since it appeared in the first
861 line.
862
863 @cindex @samp{--help} option
864 @item --help
865 This option should output brief documentation for how to invoke the
866 program, on standard output, then exit successfully. Other options and
867 arguments should be ignored once this is seen, and the program should
868 not perform its normal function.
869
870 @cindex address for bug reports
871 @cindex bug reports
872 Near the end of the @samp{--help} option's output there should be a line
873 that says where to mail bug reports. It should have this format:
874
875 @example
876 Report bugs to @var{mailing-address}.
877 @end example
878 @end table
879
880 @node Option Table
881 @section Table of Long Options
882 @cindex long option names
883 @cindex table of long options
884
885 Here is a table of long options used by GNU programs. It is surely
886 incomplete, but we aim to list all the options that a new program might
887 want to be compatible with. If you use names not already in the table,
888 please send @email{bug-standards@@gnu.org} a list of them, with their
889 meanings, so we can update the table.
890
891 @c Please leave newlines between items in this table; it's much easier
892 @c to update when it isn't completely squashed together and unreadable.
893 @c When there is more than one short option for a long option name, put
894 @c a semicolon between the lists of the programs that use them, not a
895 @c period. --friedman
896
897 @table @samp
898 @item after-date
899 @samp{-N} in @code{tar}.
900
901 @item all
902 @samp{-a} in @code{du}, @code{ls}, @code{nm}, @code{stty}, @code{uname},
903 and @code{unexpand}.
904
905 @item all-text
906 @samp{-a} in @code{diff}.
907
908 @item almost-all
909 @samp{-A} in @code{ls}.
910
911 @item append
912 @samp{-a} in @code{etags}, @code{tee}, @code{time};
913 @samp{-r} in @code{tar}.
914
915 @item archive
916 @samp{-a} in @code{cp}.
917
918 @item archive-name
919 @samp{-n} in @code{shar}.
920
921 @item arglength
922 @samp{-l} in @code{m4}.
923
924 @item ascii
925 @samp{-a} in @code{diff}.
926
927 @item assign
928 @samp{-v} in @code{gawk}.
929
930 @item assume-new
931 @samp{-W} in Make.
932
933 @item assume-old
934 @samp{-o} in Make.
935
936 @item auto-check
937 @samp{-a} in @code{recode}.
938
939 @item auto-pager
940 @samp{-a} in @code{wdiff}.
941
942 @item auto-reference
943 @samp{-A} in @code{ptx}.
944
945 @item avoid-wraps
946 @samp{-n} in @code{wdiff}.
947
948 @item background
949 For server programs, run in the background.
950
951 @item backward-search
952 @samp{-B} in @code{ctags}.
953
954 @item basename
955 @samp{-f} in @code{shar}.
956
957 @item batch
958 Used in GDB.
959
960 @item baud
961 Used in GDB.
962
963 @item before
964 @samp{-b} in @code{tac}.
965
966 @item binary
967 @samp{-b} in @code{cpio} and @code{diff}.
968
969 @item bits-per-code
970 @samp{-b} in @code{shar}.
971
972 @item block-size
973 Used in @code{cpio} and @code{tar}.
974
975 @item blocks
976 @samp{-b} in @code{head} and @code{tail}.
977
978 @item break-file
979 @samp{-b} in @code{ptx}.
980
981 @item brief
982 Used in various programs to make output shorter.
983
984 @item bytes
985 @samp{-c} in @code{head}, @code{split}, and @code{tail}.
986
987 @item c@t{++}
988 @samp{-C} in @code{etags}.
989
990 @item catenate
991 @samp{-A} in @code{tar}.
992
993 @item cd
994 Used in various programs to specify the directory to use.
995
996 @item changes
997 @samp{-c} in @code{chgrp} and @code{chown}.
998
999 @item classify
1000 @samp{-F} in @code{ls}.
1001
1002 @item colons
1003 @samp{-c} in @code{recode}.
1004
1005 @item command
1006 @samp{-c} in @code{su};
1007 @samp{-x} in GDB.
1008
1009 @item compare
1010 @samp{-d} in @code{tar}.
1011
1012 @item compat
1013 Used in @code{gawk}.
1014
1015 @item compress
1016 @samp{-Z} in @code{tar} and @code{shar}.
1017
1018 @item concatenate
1019 @samp{-A} in @code{tar}.
1020
1021 @item confirmation
1022 @samp{-w} in @code{tar}.
1023
1024 @item context
1025 Used in @code{diff}.
1026
1027 @item copyleft
1028 @samp{-W copyleft} in @code{gawk}.
1029
1030 @item copyright
1031 @samp{-C} in @code{ptx}, @code{recode}, and @code{wdiff};
1032 @samp{-W copyright} in @code{gawk}.
1033
1034 @item core
1035 Used in GDB.
1036
1037 @item count
1038 @samp{-q} in @code{who}.
1039
1040 @item count-links
1041 @samp{-l} in @code{du}.
1042
1043 @item create
1044 Used in @code{tar} and @code{cpio}.
1045
1046 @item cut-mark
1047 @samp{-c} in @code{shar}.
1048
1049 @item cxref
1050 @samp{-x} in @code{ctags}.
1051
1052 @item date
1053 @samp{-d} in @code{touch}.
1054
1055 @item debug
1056 @samp{-d} in Make and @code{m4};
1057 @samp{-t} in Bison.
1058
1059 @item define
1060 @samp{-D} in @code{m4}.
1061
1062 @item defines
1063 @samp{-d} in Bison and @code{ctags}.
1064
1065 @item delete
1066 @samp{-D} in @code{tar}.
1067
1068 @item dereference
1069 @samp{-L} in @code{chgrp}, @code{chown}, @code{cpio}, @code{du},
1070 @code{ls}, and @code{tar}.
1071
1072 @item dereference-args
1073 @samp{-D} in @code{du}.
1074
1075 @item device
1076 Specify an I/O device (special file name).
1077
1078 @item diacritics
1079 @samp{-d} in @code{recode}.
1080
1081 @item dictionary-order
1082 @samp{-d} in @code{look}.
1083
1084 @item diff
1085 @samp{-d} in @code{tar}.
1086
1087 @item digits
1088 @samp{-n} in @code{csplit}.
1089
1090 @item directory
1091 Specify the directory to use, in various programs. In @code{ls}, it
1092 means to show directories themselves rather than their contents. In
1093 @code{rm} and @code{ln}, it means to not treat links to directories
1094 specially.
1095
1096 @item discard-all
1097 @samp{-x} in @code{strip}.
1098
1099 @item discard-locals
1100 @samp{-X} in @code{strip}.
1101
1102 @item dry-run
1103 @samp{-n} in Make.
1104
1105 @item ed
1106 @samp{-e} in @code{diff}.
1107
1108 @item elide-empty-files
1109 @samp{-z} in @code{csplit}.
1110
1111 @item end-delete
1112 @samp{-x} in @code{wdiff}.
1113
1114 @item end-insert
1115 @samp{-z} in @code{wdiff}.
1116
1117 @item entire-new-file
1118 @samp{-N} in @code{diff}.
1119
1120 @item environment-overrides
1121 @samp{-e} in Make.
1122
1123 @item eof
1124 @samp{-e} in @code{xargs}.
1125
1126 @item epoch
1127 Used in GDB.
1128
1129 @item error-limit
1130 Used in @code{makeinfo}.
1131
1132 @item error-output
1133 @samp{-o} in @code{m4}.
1134
1135 @item escape
1136 @samp{-b} in @code{ls}.
1137
1138 @item exclude-from
1139 @samp{-X} in @code{tar}.
1140
1141 @item exec
1142 Used in GDB.
1143
1144 @item exit
1145 @samp{-x} in @code{xargs}.
1146
1147 @item exit-0
1148 @samp{-e} in @code{unshar}.
1149
1150 @item expand-tabs
1151 @samp{-t} in @code{diff}.
1152
1153 @item expression
1154 @samp{-e} in @code{sed}.
1155
1156 @item extern-only
1157 @samp{-g} in @code{nm}.
1158
1159 @item extract
1160 @samp{-i} in @code{cpio};
1161 @samp{-x} in @code{tar}.
1162
1163 @item faces
1164 @samp{-f} in @code{finger}.
1165
1166 @item fast
1167 @samp{-f} in @code{su}.
1168
1169 @item fatal-warnings
1170 @samp{-E} in @code{m4}.
1171
1172 @item file
1173 @samp{-f} in @code{info}, @code{gawk}, Make, @code{mt}, and @code{tar};
1174 @samp{-n} in @code{sed};
1175 @samp{-r} in @code{touch}.
1176
1177 @item field-separator
1178 @samp{-F} in @code{gawk}.
1179
1180 @item file-prefix
1181 @samp{-b} in Bison.
1182
1183 @item file-type
1184 @samp{-F} in @code{ls}.
1185
1186 @item files-from
1187 @samp{-T} in @code{tar}.
1188
1189 @item fill-column
1190 Used in @code{makeinfo}.
1191
1192 @item flag-truncation
1193 @samp{-F} in @code{ptx}.
1194
1195 @item fixed-output-files
1196 @samp{-y} in Bison.
1197
1198 @item follow
1199 @samp{-f} in @code{tail}.
1200
1201 @item footnote-style
1202 Used in @code{makeinfo}.
1203
1204 @item force
1205 @samp{-f} in @code{cp}, @code{ln}, @code{mv}, and @code{rm}.
1206
1207 @item force-prefix
1208 @samp{-F} in @code{shar}.
1209
1210 @item foreground
1211 For server programs, run in the foreground;
1212 in other words, don't do anything special to run the server
1213 in the background.
1214
1215 @item format
1216 Used in @code{ls}, @code{time}, and @code{ptx}.
1217
1218 @item freeze-state
1219 @samp{-F} in @code{m4}.
1220
1221 @item fullname
1222 Used in GDB.
1223
1224 @item gap-size
1225 @samp{-g} in @code{ptx}.
1226
1227 @item get
1228 @samp{-x} in @code{tar}.
1229
1230 @item graphic
1231 @samp{-i} in @code{ul}.
1232
1233 @item graphics
1234 @samp{-g} in @code{recode}.
1235
1236 @item group
1237 @samp{-g} in @code{install}.
1238
1239 @item gzip
1240 @samp{-z} in @code{tar} and @code{shar}.
1241
1242 @item hashsize
1243 @samp{-H} in @code{m4}.
1244
1245 @item header
1246 @samp{-h} in @code{objdump} and @code{recode}
1247
1248 @item heading
1249 @samp{-H} in @code{who}.
1250
1251 @item help
1252 Used to ask for brief usage information.
1253
1254 @item here-delimiter
1255 @samp{-d} in @code{shar}.
1256
1257 @item hide-control-chars
1258 @samp{-q} in @code{ls}.
1259
1260 @item html
1261 In @code{makeinfo}, output HTML.
1262
1263 @item idle
1264 @samp{-u} in @code{who}.
1265
1266 @item ifdef
1267 @samp{-D} in @code{diff}.
1268
1269 @item ignore
1270 @samp{-I} in @code{ls};
1271 @samp{-x} in @code{recode}.
1272
1273 @item ignore-all-space
1274 @samp{-w} in @code{diff}.
1275
1276 @item ignore-backups
1277 @samp{-B} in @code{ls}.
1278
1279 @item ignore-blank-lines
1280 @samp{-B} in @code{diff}.
1281
1282 @item ignore-case
1283 @samp{-f} in @code{look} and @code{ptx};
1284 @samp{-i} in @code{diff} and @code{wdiff}.
1285
1286 @item ignore-errors
1287 @samp{-i} in Make.
1288
1289 @item ignore-file
1290 @samp{-i} in @code{ptx}.
1291
1292 @item ignore-indentation
1293 @samp{-I} in @code{etags}.
1294
1295 @item ignore-init-file
1296 @samp{-f} in Oleo.
1297
1298 @item ignore-interrupts
1299 @samp{-i} in @code{tee}.
1300
1301 @item ignore-matching-lines
1302 @samp{-I} in @code{diff}.
1303
1304 @item ignore-space-change
1305 @samp{-b} in @code{diff}.
1306
1307 @item ignore-zeros
1308 @samp{-i} in @code{tar}.
1309
1310 @item include
1311 @samp{-i} in @code{etags};
1312 @samp{-I} in @code{m4}.
1313
1314 @item include-dir
1315 @samp{-I} in Make.
1316
1317 @item incremental
1318 @samp{-G} in @code{tar}.
1319
1320 @item info
1321 @samp{-i}, @samp{-l}, and @samp{-m} in Finger.
1322
1323 @item init-file
1324 In some programs, specify the name of the file to read as the user's
1325 init file.
1326
1327 @item initial
1328 @samp{-i} in @code{expand}.
1329
1330 @item initial-tab
1331 @samp{-T} in @code{diff}.
1332
1333 @item inode
1334 @samp{-i} in @code{ls}.
1335
1336 @item interactive
1337 @samp{-i} in @code{cp}, @code{ln}, @code{mv}, @code{rm};
1338 @samp{-e} in @code{m4};
1339 @samp{-p} in @code{xargs};
1340 @samp{-w} in @code{tar}.
1341
1342 @item intermix-type
1343 @samp{-p} in @code{shar}.
1344
1345 @item iso-8601
1346 Used in @code{date}
1347
1348 @item jobs
1349 @samp{-j} in Make.
1350
1351 @item just-print
1352 @samp{-n} in Make.
1353
1354 @item keep-going
1355 @samp{-k} in Make.
1356
1357 @item keep-files
1358 @samp{-k} in @code{csplit}.
1359
1360 @item kilobytes
1361 @samp{-k} in @code{du} and @code{ls}.
1362
1363 @item language
1364 @samp{-l} in @code{etags}.
1365
1366 @item less-mode
1367 @samp{-l} in @code{wdiff}.
1368
1369 @item level-for-gzip
1370 @samp{-g} in @code{shar}.
1371
1372 @item line-bytes
1373 @samp{-C} in @code{split}.
1374
1375 @item lines
1376 Used in @code{split}, @code{head}, and @code{tail}.
1377
1378 @item link
1379 @samp{-l} in @code{cpio}.
1380
1381 @item lint
1382 @itemx lint-old
1383 Used in @code{gawk}.
1384
1385 @item list
1386 @samp{-t} in @code{cpio};
1387 @samp{-l} in @code{recode}.
1388
1389 @item list
1390 @samp{-t} in @code{tar}.
1391
1392 @item literal
1393 @samp{-N} in @code{ls}.
1394
1395 @item load-average
1396 @samp{-l} in Make.
1397
1398 @item login
1399 Used in @code{su}.
1400
1401 @item machine
1402 No listing of which programs already use this;
1403 someone should check to
1404 see if any actually do, and tell @email{gnu@@gnu.org}.
1405
1406 @item macro-name
1407 @samp{-M} in @code{ptx}.
1408
1409 @item mail
1410 @samp{-m} in @code{hello} and @code{uname}.
1411
1412 @item make-directories
1413 @samp{-d} in @code{cpio}.
1414
1415 @item makefile
1416 @samp{-f} in Make.
1417
1418 @item mapped
1419 Used in GDB.
1420
1421 @item max-args
1422 @samp{-n} in @code{xargs}.
1423
1424 @item max-chars
1425 @samp{-n} in @code{xargs}.
1426
1427 @item max-lines
1428 @samp{-l} in @code{xargs}.
1429
1430 @item max-load
1431 @samp{-l} in Make.
1432
1433 @item max-procs
1434 @samp{-P} in @code{xargs}.
1435
1436 @item mesg
1437 @samp{-T} in @code{who}.
1438
1439 @item message
1440 @samp{-T} in @code{who}.
1441
1442 @item minimal
1443 @samp{-d} in @code{diff}.
1444
1445 @item mixed-uuencode
1446 @samp{-M} in @code{shar}.
1447
1448 @item mode
1449 @samp{-m} in @code{install}, @code{mkdir}, and @code{mkfifo}.
1450
1451 @item modification-time
1452 @samp{-m} in @code{tar}.
1453
1454 @item multi-volume
1455 @samp{-M} in @code{tar}.
1456
1457 @item name-prefix
1458 @samp{-a} in Bison.
1459
1460 @item nesting-limit
1461 @samp{-L} in @code{m4}.
1462
1463 @item net-headers
1464 @samp{-a} in @code{shar}.
1465
1466 @item new-file
1467 @samp{-W} in Make.
1468
1469 @item no-builtin-rules
1470 @samp{-r} in Make.
1471
1472 @item no-character-count
1473 @samp{-w} in @code{shar}.
1474
1475 @item no-check-existing
1476 @samp{-x} in @code{shar}.
1477
1478 @item no-common
1479 @samp{-3} in @code{wdiff}.
1480
1481 @item no-create
1482 @samp{-c} in @code{touch}.
1483
1484 @item no-defines
1485 @samp{-D} in @code{etags}.
1486
1487 @item no-deleted
1488 @samp{-1} in @code{wdiff}.
1489
1490 @item no-dereference
1491 @samp{-d} in @code{cp}.
1492
1493 @item no-inserted
1494 @samp{-2} in @code{wdiff}.
1495
1496 @item no-keep-going
1497 @samp{-S} in Make.
1498
1499 @item no-lines
1500 @samp{-l} in Bison.
1501
1502 @item no-piping
1503 @samp{-P} in @code{shar}.
1504
1505 @item no-prof
1506 @samp{-e} in @code{gprof}.
1507
1508 @item no-regex
1509 @samp{-R} in @code{etags}.
1510
1511 @item no-sort
1512 @samp{-p} in @code{nm}.
1513
1514 @item no-split
1515 Used in @code{makeinfo}.
1516
1517 @item no-static
1518 @samp{-a} in @code{gprof}.
1519
1520 @item no-time
1521 @samp{-E} in @code{gprof}.
1522
1523 @item no-timestamp
1524 @samp{-m} in @code{shar}.
1525
1526 @item no-validate
1527 Used in @code{makeinfo}.
1528
1529 @item no-wait
1530 Used in @code{emacsclient}.
1531
1532 @item no-warn
1533 Used in various programs to inhibit warnings.
1534
1535 @item node
1536 @samp{-n} in @code{info}.
1537
1538 @item nodename
1539 @samp{-n} in @code{uname}.
1540
1541 @item nonmatching
1542 @samp{-f} in @code{cpio}.
1543
1544 @item nstuff
1545 @samp{-n} in @code{objdump}.
1546
1547 @item null
1548 @samp{-0} in @code{xargs}.
1549
1550 @item number
1551 @samp{-n} in @code{cat}.
1552
1553 @item number-nonblank
1554 @samp{-b} in @code{cat}.
1555
1556 @item numeric-sort
1557 @samp{-n} in @code{nm}.
1558
1559 @item numeric-uid-gid
1560 @samp{-n} in @code{cpio} and @code{ls}.
1561
1562 @item nx
1563 Used in GDB.
1564
1565 @item old-archive
1566 @samp{-o} in @code{tar}.
1567
1568 @item old-file
1569 @samp{-o} in Make.
1570
1571 @item one-file-system
1572 @samp{-l} in @code{tar}, @code{cp}, and @code{du}.
1573
1574 @item only-file
1575 @samp{-o} in @code{ptx}.
1576
1577 @item only-prof
1578 @samp{-f} in @code{gprof}.
1579
1580 @item only-time
1581 @samp{-F} in @code{gprof}.
1582
1583 @item options
1584 @samp{-o} in @code{getopt}, @code{fdlist}, @code{fdmount},
1585 @code{fdmountd}, and @code{fdumount}.
1586
1587 @item output
1588 In various programs, specify the output file name.
1589
1590 @item output-prefix
1591 @samp{-o} in @code{shar}.
1592
1593 @item override
1594 @samp{-o} in @code{rm}.
1595
1596 @item overwrite
1597 @samp{-c} in @code{unshar}.
1598
1599 @item owner
1600 @samp{-o} in @code{install}.
1601
1602 @item paginate
1603 @samp{-l} in @code{diff}.
1604
1605 @item paragraph-indent
1606 Used in @code{makeinfo}.
1607
1608 @item parents
1609 @samp{-p} in @code{mkdir} and @code{rmdir}.
1610
1611 @item pass-all
1612 @samp{-p} in @code{ul}.
1613
1614 @item pass-through
1615 @samp{-p} in @code{cpio}.
1616
1617 @item port
1618 @samp{-P} in @code{finger}.
1619
1620 @item portability
1621 @samp{-c} in @code{cpio} and @code{tar}.
1622
1623 @item posix
1624 Used in @code{gawk}.
1625
1626 @item prefix-builtins
1627 @samp{-P} in @code{m4}.
1628
1629 @item prefix
1630 @samp{-f} in @code{csplit}.
1631
1632 @item preserve
1633 Used in @code{tar} and @code{cp}.
1634
1635 @item preserve-environment
1636 @samp{-p} in @code{su}.
1637
1638 @item preserve-modification-time
1639 @samp{-m} in @code{cpio}.
1640
1641 @item preserve-order
1642 @samp{-s} in @code{tar}.
1643
1644 @item preserve-permissions
1645 @samp{-p} in @code{tar}.
1646
1647 @item print
1648 @samp{-l} in @code{diff}.
1649
1650 @item print-chars
1651 @samp{-L} in @code{cmp}.
1652
1653 @item print-data-base
1654 @samp{-p} in Make.
1655
1656 @item print-directory
1657 @samp{-w} in Make.
1658
1659 @item print-file-name
1660 @samp{-o} in @code{nm}.
1661
1662 @item print-symdefs
1663 @samp{-s} in @code{nm}.
1664
1665 @item printer
1666 @samp{-p} in @code{wdiff}.
1667
1668 @item prompt
1669 @samp{-p} in @code{ed}.
1670
1671 @item proxy
1672 Specify an HTTP proxy.
1673
1674 @item query-user
1675 @samp{-X} in @code{shar}.
1676
1677 @item question
1678 @samp{-q} in Make.
1679
1680 @item quiet
1681 Used in many programs to inhibit the usual output. @strong{Note:} every
1682 program accepting @samp{--quiet} should accept @samp{--silent} as a
1683 synonym.
1684
1685 @item quiet-unshar
1686 @samp{-Q} in @code{shar}
1687
1688 @item quote-name
1689 @samp{-Q} in @code{ls}.
1690
1691 @item rcs
1692 @samp{-n} in @code{diff}.
1693
1694 @item re-interval
1695 Used in @code{gawk}.
1696
1697 @item read-full-blocks
1698 @samp{-B} in @code{tar}.
1699
1700 @item readnow
1701 Used in GDB.
1702
1703 @item recon
1704 @samp{-n} in Make.
1705
1706 @item record-number
1707 @samp{-R} in @code{tar}.
1708
1709 @item recursive
1710 Used in @code{chgrp}, @code{chown}, @code{cp}, @code{ls}, @code{diff},
1711 and @code{rm}.
1712
1713 @item reference-limit
1714 Used in @code{makeinfo}.
1715
1716 @item references
1717 @samp{-r} in @code{ptx}.
1718
1719 @item regex
1720 @samp{-r} in @code{tac} and @code{etags}.
1721
1722 @item release
1723 @samp{-r} in @code{uname}.
1724
1725 @item reload-state
1726 @samp{-R} in @code{m4}.
1727
1728 @item relocation
1729 @samp{-r} in @code{objdump}.
1730
1731 @item rename
1732 @samp{-r} in @code{cpio}.
1733
1734 @item replace
1735 @samp{-i} in @code{xargs}.
1736
1737 @item report-identical-files
1738 @samp{-s} in @code{diff}.
1739
1740 @item reset-access-time
1741 @samp{-a} in @code{cpio}.
1742
1743 @item reverse
1744 @samp{-r} in @code{ls} and @code{nm}.
1745
1746 @item reversed-ed
1747 @samp{-f} in @code{diff}.
1748
1749 @item right-side-defs
1750 @samp{-R} in @code{ptx}.
1751
1752 @item same-order
1753 @samp{-s} in @code{tar}.
1754
1755 @item same-permissions
1756 @samp{-p} in @code{tar}.
1757
1758 @item save
1759 @samp{-g} in @code{stty}.
1760
1761 @item se
1762 Used in GDB.
1763
1764 @item sentence-regexp
1765 @samp{-S} in @code{ptx}.
1766
1767 @item separate-dirs
1768 @samp{-S} in @code{du}.
1769
1770 @item separator
1771 @samp{-s} in @code{tac}.
1772
1773 @item sequence
1774 Used by @code{recode} to chose files or pipes for sequencing passes.
1775
1776 @item shell
1777 @samp{-s} in @code{su}.
1778
1779 @item show-all
1780 @samp{-A} in @code{cat}.
1781
1782 @item show-c-function
1783 @samp{-p} in @code{diff}.
1784
1785 @item show-ends
1786 @samp{-E} in @code{cat}.
1787
1788 @item show-function-line
1789 @samp{-F} in @code{diff}.
1790
1791 @item show-tabs
1792 @samp{-T} in @code{cat}.
1793
1794 @item silent
1795 Used in many programs to inhibit the usual output.
1796 @strong{Note:} every program accepting
1797 @samp{--silent} should accept @samp{--quiet} as a synonym.
1798
1799 @item size
1800 @samp{-s} in @code{ls}.
1801
1802 @item socket
1803 Specify a file descriptor for a network server to use for its socket,
1804 instead of opening and binding a new socket. This provides a way to
1805 run, in a nonpriveledged process, a server that normally needs a
1806 reserved port number.
1807
1808 @item sort
1809 Used in @code{ls}.
1810
1811 @item source
1812 @samp{-W source} in @code{gawk}.
1813
1814 @item sparse
1815 @samp{-S} in @code{tar}.
1816
1817 @item speed-large-files
1818 @samp{-H} in @code{diff}.
1819
1820 @item split-at
1821 @samp{-E} in @code{unshar}.
1822
1823 @item split-size-limit
1824 @samp{-L} in @code{shar}.
1825
1826 @item squeeze-blank
1827 @samp{-s} in @code{cat}.
1828
1829 @item start-delete
1830 @samp{-w} in @code{wdiff}.
1831
1832 @item start-insert
1833 @samp{-y} in @code{wdiff}.
1834
1835 @item starting-file
1836 Used in @code{tar} and @code{diff} to specify which file within
1837 a directory to start processing with.
1838
1839 @item statistics
1840 @samp{-s} in @code{wdiff}.
1841
1842 @item stdin-file-list
1843 @samp{-S} in @code{shar}.
1844
1845 @item stop
1846 @samp{-S} in Make.
1847
1848 @item strict
1849 @samp{-s} in @code{recode}.
1850
1851 @item strip
1852 @samp{-s} in @code{install}.
1853
1854 @item strip-all
1855 @samp{-s} in @code{strip}.
1856
1857 @item strip-debug
1858 @samp{-S} in @code{strip}.
1859
1860 @item submitter
1861 @samp{-s} in @code{shar}.
1862
1863 @item suffix
1864 @samp{-S} in @code{cp}, @code{ln}, @code{mv}.
1865
1866 @item suffix-format
1867 @samp{-b} in @code{csplit}.
1868
1869 @item sum
1870 @samp{-s} in @code{gprof}.
1871
1872 @item summarize
1873 @samp{-s} in @code{du}.
1874
1875 @item symbolic
1876 @samp{-s} in @code{ln}.
1877
1878 @item symbols
1879 Used in GDB and @code{objdump}.
1880
1881 @item synclines
1882 @samp{-s} in @code{m4}.
1883
1884 @item sysname
1885 @samp{-s} in @code{uname}.
1886
1887 @item tabs
1888 @samp{-t} in @code{expand} and @code{unexpand}.
1889
1890 @item tabsize
1891 @samp{-T} in @code{ls}.
1892
1893 @item terminal
1894 @samp{-T} in @code{tput} and @code{ul}.
1895 @samp{-t} in @code{wdiff}.
1896
1897 @item text
1898 @samp{-a} in @code{diff}.
1899
1900 @item text-files
1901 @samp{-T} in @code{shar}.
1902
1903 @item time
1904 Used in @code{ls} and @code{touch}.
1905
1906 @item timeout
1907 Specify how long to wait before giving up on some operation.
1908
1909 @item to-stdout
1910 @samp{-O} in @code{tar}.
1911
1912 @item total
1913 @samp{-c} in @code{du}.
1914
1915 @item touch
1916 @samp{-t} in Make, @code{ranlib}, and @code{recode}.
1917
1918 @item trace
1919 @samp{-t} in @code{m4}.
1920
1921 @item traditional
1922 @samp{-t} in @code{hello};
1923 @samp{-W traditional} in @code{gawk};
1924 @samp{-G} in @code{ed}, @code{m4}, and @code{ptx}.
1925
1926 @item tty
1927 Used in GDB.
1928
1929 @item typedefs
1930 @samp{-t} in @code{ctags}.
1931
1932 @item typedefs-and-c++
1933 @samp{-T} in @code{ctags}.
1934
1935 @item typeset-mode
1936 @samp{-t} in @code{ptx}.
1937
1938 @item uncompress
1939 @samp{-z} in @code{tar}.
1940
1941 @item unconditional
1942 @samp{-u} in @code{cpio}.
1943
1944 @item undefine
1945 @samp{-U} in @code{m4}.
1946
1947 @item undefined-only
1948 @samp{-u} in @code{nm}.
1949
1950 @item update
1951 @samp{-u} in @code{cp}, @code{ctags}, @code{mv}, @code{tar}.
1952
1953 @item usage
1954 Used in @code{gawk}; same as @samp{--help}.
1955
1956 @item uuencode
1957 @samp{-B} in @code{shar}.
1958
1959 @item vanilla-operation
1960 @samp{-V} in @code{shar}.
1961
1962 @item verbose
1963 Print more information about progress. Many programs support this.
1964
1965 @item verify
1966 @samp{-W} in @code{tar}.
1967
1968 @item version
1969 Print the version number.
1970
1971 @item version-control
1972 @samp{-V} in @code{cp}, @code{ln}, @code{mv}.
1973
1974 @item vgrind
1975 @samp{-v} in @code{ctags}.
1976
1977 @item volume
1978 @samp{-V} in @code{tar}.
1979
1980 @item what-if
1981 @samp{-W} in Make.
1982
1983 @item whole-size-limit
1984 @samp{-l} in @code{shar}.
1985
1986 @item width
1987 @samp{-w} in @code{ls} and @code{ptx}.
1988
1989 @item word-regexp
1990 @samp{-W} in @code{ptx}.
1991
1992 @item writable
1993 @samp{-T} in @code{who}.
1994
1995 @item zeros
1996 @samp{-z} in @code{gprof}.
1997 @end table
1998
1999 @node Memory Usage
2000 @section Memory Usage
2001 @cindex memory usage
2002
2003 If a program typically uses just a few meg of memory, don't bother making any
2004 effort to reduce memory usage. For example, if it is impractical for
2005 other reasons to operate on files more than a few meg long, it is
2006 reasonable to read entire input files into core to operate on them.
2007
2008 However, for programs such as @code{cat} or @code{tail}, that can
2009 usefully operate on very large files, it is important to avoid using a
2010 technique that would artificially limit the size of files it can handle.
2011 If a program works by lines and could be applied to arbitrary
2012 user-supplied input files, it should keep only a line in memory, because
2013 this is not very hard and users will want to be able to operate on input
2014 files that are bigger than will fit in core all at once.
2015
2016 If your program creates complicated data structures, just make them in
2017 core and give a fatal error if @code{malloc} returns zero.
2018
2019 @node File Usage
2020 @section File Usage
2021 @cindex file usage
2022
2023 Programs should be prepared to operate when @file{/usr} and @file{/etc}
2024 are read-only file systems. Thus, if the program manages log files,
2025 lock files, backup files, score files, or any other files which are
2026 modified for internal purposes, these files should not be stored in
2027 @file{/usr} or @file{/etc}.
2028
2029 There are two exceptions. @file{/etc} is used to store system
2030 configuration information; it is reasonable for a program to modify
2031 files in @file{/etc} when its job is to update the system configuration.
2032 Also, if the user explicitly asks to modify one file in a directory, it
2033 is reasonable for the program to store other files in the same
2034 directory.
2035
2036 @node Writing C
2037 @chapter Making The Best Use of C
2038
2039 This @value{CHAPTER} provides advice on how best to use the C language
2040 when writing GNU software.
2041
2042 @menu
2043 * Formatting:: Formatting Your Source Code
2044 * Comments:: Commenting Your Work
2045 * Syntactic Conventions:: Clean Use of C Constructs
2046 * Names:: Naming Variables and Functions
2047 * System Portability:: Portability between different operating systems
2048 * CPU Portability:: Supporting the range of CPU types
2049 * System Functions:: Portability and ``standard'' library functions
2050 * Internationalization:: Techniques for internationalization
2051 * Mmap:: How you can safely use @code{mmap}.
2052 @end menu
2053
2054 @node Formatting
2055 @section Formatting Your Source Code
2056 @cindex formatting source code
2057
2058 @cindex open brace
2059 @cindex braces, in C source
2060 It is important to put the open-brace that starts the body of a C
2061 function in column zero, and avoid putting any other open-brace or
2062 open-parenthesis or open-bracket in column zero. Several tools look
2063 for open-braces in column zero to find the beginnings of C functions.
2064 These tools will not work on code not formatted that way.
2065
2066 It is also important for function definitions to start the name of the
2067 function in column zero. This helps people to search for function
2068 definitions, and may also help certain tools recognize them. Thus,
2069 the proper format is this:
2070
2071 @example
2072 static char *
2073 concat (s1, s2) /* Name starts in column zero here */
2074 char *s1, *s2;
2075 @{ /* Open brace in column zero here */
2076 @dots{}
2077 @}
2078 @end example
2079
2080 @noindent
2081 or, if you want to use Standard C syntax, format the definition like
2082 this:
2083
2084 @example
2085 static char *
2086 concat (char *s1, char *s2)
2087 @{
2088 @dots{}
2089 @}
2090 @end example
2091
2092 In Standard C, if the arguments don't fit nicely on one line,
2093 split it like this:
2094
2095 @example
2096 int
2097 lots_of_args (int an_integer, long a_long, short a_short,
2098 double a_double, float a_float)
2099 @dots{}
2100 @end example
2101
2102 The rest of this section gives our recommendations for other aspects of
2103 C formatting style, which is also the default style of the @code{indent}
2104 program in version 1.2 and newer. It corresponds to the options
2105
2106 @smallexample
2107 -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
2108 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob
2109 @end smallexample
2110
2111 We don't think of these recommendations as requirements, because it
2112 causes no problems for users if two different programs have different
2113 formatting styles.
2114
2115 But whatever style you use, please use it consistently, since a mixture
2116 of styles within one program tends to look ugly. If you are
2117 contributing changes to an existing program, please follow the style of
2118 that program.
2119
2120 For the body of the function, our recommended style looks like this:
2121
2122 @example
2123 if (x < foo (y, z))
2124 haha = bar[4] + 5;
2125 else
2126 @{
2127 while (z)
2128 @{
2129 haha += foo (z, z);
2130 z--;
2131 @}
2132 return ++x + bar ();
2133 @}
2134 @end example
2135
2136 @cindex spaces before open-paren
2137 We find it easier to read a program when it has spaces before the
2138 open-parentheses and after the commas. Especially after the commas.
2139
2140 When you split an expression into multiple lines, split it
2141 before an operator, not after one. Here is the right way:
2142
2143 @cindex expressions, splitting
2144 @example
2145 if (foo_this_is_long && bar > win (x, y, z)
2146 && remaining_condition)
2147 @end example
2148
2149 Try to avoid having two operators of different precedence at the same
2150 level of indentation. For example, don't write this:
2151
2152 @example
2153 mode = (inmode[j] == VOIDmode
2154 || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
2155 ? outmode[j] : inmode[j]);
2156 @end example
2157
2158 Instead, use extra parentheses so that the indentation shows the nesting:
2159
2160 @example
2161 mode = ((inmode[j] == VOIDmode
2162 || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
2163 ? outmode[j] : inmode[j]);
2164 @end example
2165
2166 Insert extra parentheses so that Emacs will indent the code properly.
2167 For example, the following indentation looks nice if you do it by hand,
2168
2169 @example
2170 v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
2171 + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
2172 @end example
2173
2174 @noindent
2175 but Emacs would alter it. Adding a set of parentheses produces
2176 something that looks equally nice, and which Emacs will preserve:
2177
2178 @example
2179 v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
2180 + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
2181 @end example
2182
2183 Format do-while statements like this:
2184
2185 @example
2186 do
2187 @{
2188 a = foo (a);
2189 @}
2190 while (a > 0);
2191 @end example
2192
2193 @cindex formfeed
2194 @cindex control-L
2195 Please use formfeed characters (control-L) to divide the program into
2196 pages at logical places (but not within a function). It does not matter
2197 just how long the pages are, since they do not have to fit on a printed
2198 page. The formfeeds should appear alone on lines by themselves.
2199
2200 @node Comments
2201 @section Commenting Your Work
2202 @cindex commenting
2203
2204 Every program should start with a comment saying briefly what it is for.
2205 Example: @samp{fmt - filter for simple filling of text}.
2206
2207 Please write the comments in a GNU program in English, because English
2208 is the one language that nearly all programmers in all countries can
2209 read. If you do not write English well, please write comments in
2210 English as well as you can, then ask other people to help rewrite them.
2211 If you can't write comments in English, please find someone to work with
2212 you and translate your comments into English.
2213
2214 Please put a comment on each function saying what the function does,
2215 what sorts of arguments it gets, and what the possible values of
2216 arguments mean and are used for. It is not necessary to duplicate in
2217 words the meaning of the C argument declarations, if a C type is being
2218 used in its customary fashion. If there is anything nonstandard about
2219 its use (such as an argument of type @code{char *} which is really the
2220 address of the second character of a string, not the first), or any
2221 possible values that would not work the way one would expect (such as,
2222 that strings containing newlines are not guaranteed to work), be sure
2223 to say so.
2224
2225 Also explain the significance of the return value, if there is one.
2226
2227 Please put two spaces after the end of a sentence in your comments, so
2228 that the Emacs sentence commands will work. Also, please write
2229 complete sentences and capitalize the first word. If a lower-case
2230 identifier comes at the beginning of a sentence, don't capitalize it!
2231 Changing the spelling makes it a different identifier. If you don't
2232 like starting a sentence with a lower case letter, write the sentence
2233 differently (e.g., ``The identifier lower-case is @dots{}'').
2234
2235 The comment on a function is much clearer if you use the argument
2236 names to speak about the argument values. The variable name itself
2237 should be lower case, but write it in upper case when you are speaking
2238 about the value rather than the variable itself. Thus, ``the inode
2239 number NODE_NUM'' rather than ``an inode''.
2240
2241 There is usually no purpose in restating the name of the function in
2242 the comment before it, because the reader can see that for himself.
2243 There might be an exception when the comment is so long that the function
2244 itself would be off the bottom of the screen.
2245
2246 There should be a comment on each static variable as well, like this:
2247
2248 @example
2249 /* Nonzero means truncate lines in the display;
2250 zero means continue them. */
2251 int truncate_lines;
2252 @end example
2253
2254 @cindex conditionals, comments for
2255 @cindex @code{#endif}, commenting
2256 Every @samp{#endif} should have a comment, except in the case of short
2257 conditionals (just a few lines) that are not nested. The comment should
2258 state the condition of the conditional that is ending, @emph{including
2259 its sense}. @samp{#else} should have a comment describing the condition
2260 @emph{and sense} of the code that follows. For example:
2261
2262 @example
2263 @group
2264 #ifdef foo
2265 @dots{}
2266 #else /* not foo */
2267 @dots{}
2268 #endif /* not foo */
2269 @end group
2270 @group
2271 #ifdef foo
2272 @dots{}
2273 #endif /* foo */
2274 @end group
2275 @end example
2276
2277 @noindent
2278 but, by contrast, write the comments this way for a @samp{#ifndef}:
2279
2280 @example
2281 @group
2282 #ifndef foo
2283 @dots{}
2284 #else /* foo */
2285 @dots{}
2286 #endif /* foo */
2287 @end group
2288 @group
2289 #ifndef foo
2290 @dots{}
2291 #endif /* not foo */
2292 @end group
2293 @end example
2294
2295 @node Syntactic Conventions
2296 @section Clean Use of C Constructs
2297 @cindex syntactic conventions
2298
2299 @cindex implicit @code{int}
2300 @cindex function argument, declaring
2301 Please explicitly declare the types of all objects. For example, you
2302 should explicitly declare all arguments to functions, and you should
2303 declare functions to return @code{int} rather than omitting the
2304 @code{int}.
2305
2306 @cindex compiler warnings
2307 @cindex @samp{-Wall} compiler option
2308 Some programmers like to use the GCC @samp{-Wall} option, and change the
2309 code whenever it issues a warning. If you want to do this, then do.
2310 Other programmers prefer not to use @samp{-Wall}, because it gives
2311 warnings for valid and legitimate code which they do not want to change.
2312 If you want to do this, then do. The compiler should be your servant,
2313 not your master.
2314
2315 Declarations of external functions and functions to appear later in the
2316 source file should all go in one place near the beginning of the file
2317 (somewhere before the first function definition in the file), or else
2318 should go in a header file. Don't put @code{extern} declarations inside
2319 functions.
2320
2321 @cindex temporary variables
2322 It used to be common practice to use the same local variables (with
2323 names like @code{tem}) over and over for different values within one
2324 function. Instead of doing this, it is better declare a separate local
2325 variable for each distinct purpose, and give it a name which is
2326 meaningful. This not only makes programs easier to understand, it also
2327 facilitates optimization by good compilers. You can also move the
2328 declaration of each local variable into the smallest scope that includes
2329 all its uses. This makes the program even cleaner.
2330
2331 Don't use local variables or parameters that shadow global identifiers.
2332
2333 @cindex multiple variables in a line
2334 Don't declare multiple variables in one declaration that spans lines.
2335 Start a new declaration on each line, instead. For example, instead
2336 of this:
2337
2338 @example
2339 @group
2340 int foo,
2341 bar;
2342 @end group
2343 @end example
2344
2345 @noindent
2346 write either this:
2347
2348 @example
2349 int foo, bar;
2350 @end example
2351
2352 @noindent
2353 or this:
2354
2355 @example
2356 int foo;
2357 int bar;
2358 @end example
2359
2360 @noindent
2361 (If they are global variables, each should have a comment preceding it
2362 anyway.)
2363
2364 When you have an @code{if}-@code{else} statement nested in another
2365 @code{if} statement, always put braces around the @code{if}-@code{else}.
2366 Thus, never write like this:
2367
2368 @example
2369 if (foo)
2370 if (bar)
2371 win ();
2372 else
2373 lose ();
2374 @end example
2375
2376 @noindent
2377 always like this:
2378
2379 @example
2380 if (foo)
2381 @{
2382 if (bar)
2383 win ();
2384 else
2385 lose ();
2386 @}
2387 @end example
2388
2389 If you have an @code{if} statement nested inside of an @code{else}
2390 statement, either write @code{else if} on one line, like this,
2391
2392 @example
2393 if (foo)
2394 @dots{}
2395 else if (bar)
2396 @dots{}
2397 @end example
2398
2399 @noindent
2400 with its @code{then}-part indented like the preceding @code{then}-part,
2401 or write the nested @code{if} within braces like this:
2402
2403 @example
2404 if (foo)
2405 @dots{}
2406 else
2407 @{
2408 if (bar)
2409 @dots{}
2410 @}
2411 @end example
2412
2413 Don't declare both a structure tag and variables or typedefs in the
2414 same declaration. Instead, declare the structure tag separately
2415 and then use it to declare the variables or typedefs.
2416
2417 Try to avoid assignments inside @code{if}-conditions. For example,
2418 don't write this:
2419
2420 @example
2421 if ((foo = (char *) malloc (sizeof *foo)) == 0)
2422 fatal ("virtual memory exhausted");
2423 @end example
2424
2425 @noindent
2426 instead, write this:
2427
2428 @example
2429 foo = (char *) malloc (sizeof *foo);
2430 if (foo == 0)
2431 fatal ("virtual memory exhausted");
2432 @end example
2433
2434 @pindex lint
2435 Don't make the program ugly to placate @code{lint}. Please don't insert any
2436 casts to @code{void}. Zero without a cast is perfectly fine as a null
2437 pointer constant, except when calling a varargs function.
2438
2439 @node Names
2440 @section Naming Variables and Functions
2441
2442 @cindex names of variables and functions
2443 The names of global variables and functions in a program serve as
2444 comments of a sort. So don't choose terse names---instead, look for
2445 names that give useful information about the meaning of the variable or
2446 function. In a GNU program, names should be English, like other
2447 comments.
2448
2449 Local variable names can be shorter, because they are used only within
2450 one context, where (presumably) comments explain their purpose.
2451
2452 Try to limit your use of abbreviations in symbol names. It is ok to
2453 make a few abbreviations, explain what they mean, and then use them
2454 frequently, but don't use lots of obscure abbreviations.
2455
2456 Please use underscores to separate words in a name, so that the Emacs
2457 word commands can be useful within them. Stick to lower case; reserve
2458 upper case for macros and @code{enum} constants, and for name-prefixes
2459 that follow a uniform convention.
2460
2461 For example, you should use names like @code{ignore_space_change_flag};
2462 don't use names like @code{iCantReadThis}.
2463
2464 Variables that indicate whether command-line options have been
2465 specified should be named after the meaning of the option, not after
2466 the option-letter. A comment should state both the exact meaning of
2467 the option and its letter. For example,
2468
2469 @example
2470 @group
2471 /* Ignore changes in horizontal whitespace (-b). */
2472 int ignore_space_change_flag;
2473 @end group
2474 @end example
2475
2476 When you want to define names with constant integer values, use
2477 @code{enum} rather than @samp{#define}. GDB knows about enumeration
2478 constants.
2479
2480 @cindex file-name limitations
2481 @pindex doschk
2482 You might want to make sure that none of the file names would conflict
2483 the files were loaded onto an MS-DOS file system which shortens the
2484 names. You can use the program @code{doschk} to test for this.
2485
2486 Some GNU programs were designed to limit themselves to file names of 14
2487 characters or less, to avoid file name conflicts if they are read into
2488 older System V systems. Please preserve this feature in the existing
2489 GNU programs that have it, but there is no need to do this in new GNU
2490 programs. @code{doschk} also reports file names longer than 14
2491 characters.
2492
2493 @node System Portability
2494 @section Portability between System Types
2495 @cindex portability, between system types
2496
2497 In the Unix world, ``portability'' refers to porting to different Unix
2498 versions. For a GNU program, this kind of portability is desirable, but
2499 not paramount.
2500
2501 The primary purpose of GNU software is to run on top of the GNU kernel,
2502 compiled with the GNU C compiler, on various types of @sc{cpu}. So the
2503 kinds of portability that are absolutely necessary are quite limited.
2504 But it is important to support Linux-based GNU systems, since they
2505 are the form of GNU that is popular.
2506
2507 Beyond that, it is good to support the other free operating systems
2508 (*BSD), and it is nice to support other Unix-like systems if you want
2509 to. Supporting a variety of Unix-like systems is desirable, although
2510 not paramount. It is usually not too hard, so you may as well do it.
2511 But you don't have to consider it an obligation, if it does turn out to
2512 be hard.
2513
2514 @pindex autoconf
2515 The easiest way to achieve portability to most Unix-like systems is to
2516 use Autoconf. It's unlikely that your program needs to know more
2517 information about the host platform than Autoconf can provide, simply
2518 because most of the programs that need such knowledge have already been
2519 written.
2520
2521 Avoid using the format of semi-internal data bases (e.g., directories)
2522 when there is a higher-level alternative (@code{readdir}).
2523
2524 @cindex non-@sc{posix} systems, and portability
2525 As for systems that are not like Unix, such as MSDOS, Windows, the
2526 Macintosh, VMS, and MVS, supporting them is often a lot of work. When
2527 that is the case, it is better to spend your time adding features that
2528 will be useful on GNU and GNU/Linux, rather than on supporting other
2529 incompatible systems.
2530
2531 It is a good idea to define the ``feature test macro''
2532 @code{_GNU_SOURCE} when compiling your C files. When you compile on GNU
2533 or GNU/Linux, this will enable the declarations of GNU library extension
2534 functions, and that will usually give you a compiler error message if
2535 you define the same function names in some other way in your program.
2536 (You don't have to actually @emph{use} these functions, if you prefer
2537 to make the program more portable to other systems.)
2538
2539 But whether or not you use these GNU extensions, you should avoid
2540 using their names for any other meanings. Doing so would make it hard
2541 to move your code into other GNU programs.
2542
2543 @node CPU Portability
2544 @section Portability between @sc{cpu}s
2545
2546 @cindex data types, and portability
2547 @cindex portability, and data types
2548 Even GNU systems will differ because of differences among @sc{cpu}
2549 types---for example, difference in byte ordering and alignment
2550 requirements. It is absolutely essential to handle these differences.
2551 However, don't make any effort to cater to the possibility that an
2552 @code{int} will be less than 32 bits. We don't support 16-bit machines
2553 in GNU.
2554
2555 Similarly, don't make any effort to cater to the possibility that
2556 @code{long} will be smaller than predefined types like @code{size_t}.
2557 For example, the following code is ok:
2558
2559 @example
2560 printf ("size = %lu\n", (unsigned long) sizeof array);
2561 printf ("diff = %ld\n", (long) (pointer2 - pointer1));
2562 @end example
2563
2564 1989 Standard C requires this to work, and we know of only one
2565 counterexample: 64-bit programs on Microsoft Windows IA-64. We will
2566 leave it to those who want to port GNU programs to that environment
2567 to figure out how to do it.
2568
2569 Predefined file-size types like @code{off_t} are an exception: they are
2570 longer than @code{long} on many platforms, so code like the above won't
2571 work with them. One way to print an @code{off_t} value portably is to
2572 print its digits yourself, one by one.
2573
2574 Don't assume that the address of an @code{int} object is also the
2575 address of its least-significant byte. This is false on big-endian
2576 machines. Thus, don't make the following mistake:
2577
2578 @example
2579 int c;
2580 @dots{}
2581 while ((c = getchar()) != EOF)
2582 write(file_descriptor, &c, 1);
2583 @end example
2584
2585 When calling functions, you need not worry about the difference between
2586 pointers of various types, or between pointers and integers. On most
2587 machines, there's no difference anyway. As for the few machines where
2588 there is a difference, all of them support Standard C prototypes, so you can
2589 use prototypes (perhaps conditionalized to be active only in Standard C)
2590 to make the code work on those systems.
2591
2592 In certain cases, it is ok to pass integer and pointer arguments
2593 indiscriminately to the same function, and use no prototype on any
2594 system. For example, many GNU programs have error-reporting functions
2595 that pass their arguments along to @code{printf} and friends:
2596
2597 @example
2598 error (s, a1, a2, a3)
2599 char *s;
2600 char *a1, *a2, *a3;
2601 @{
2602 fprintf (stderr, "error: ");
2603 fprintf (stderr, s, a1, a2, a3);
2604 @}
2605 @end example
2606
2607 @noindent
2608 In practice, this works on all machines, since a pointer is generally
2609 the widest possible kind of argument; it is much simpler than any
2610 ``correct'' alternative. Be sure @emph{not} to use a prototype for such
2611 functions.
2612
2613 If you have decided to use Standard C, then you can instead define
2614 @code{error} using @file{stdarg.h}, and pass the arguments along to
2615 @code{vfprintf}.
2616
2617 @cindex casting pointers to integers
2618 Avoid casting pointers to integers if you can. Such casts greatly
2619 reduce portability, and in most programs they are easy to avoid. In the
2620 cases where casting pointers to integers is essential---such as, a Lisp
2621 interpreter which stores type information as well as an address in one
2622 word---you'll have to make explicit provisions to handle different word
2623 sizes. You will also need to make provision for systems in which the
2624 normal range of addresses you can get from @code{malloc} starts far away
2625 from zero.
2626
2627 @node System Functions
2628 @section Calling System Functions
2629 @cindex library functions, and portability
2630 @cindex portability, and library functions
2631
2632 C implementations differ substantially. Standard C reduces but does
2633 not eliminate the incompatibilities; meanwhile, many GNU packages still
2634 support pre-standard compilers because this is not hard to do. This
2635 chapter gives recommendations for how to use the more-or-less standard C
2636 library functions to avoid unnecessary loss of portability.
2637
2638 @itemize @bullet
2639 @item
2640 Don't use the return value of @code{sprintf}. It returns the number of
2641 characters written on some systems, but not on all systems.
2642
2643 @item
2644 Be aware that @code{vfprintf} is not always available.
2645
2646 @item
2647 @code{main} should be declared to return type @code{int}. It should
2648 terminate either by calling @code{exit} or by returning the integer
2649 status code; make sure it cannot ever return an undefined value.
2650
2651 @cindex declaration for system functions
2652 @item
2653 Don't declare system functions explicitly.
2654
2655 Almost any declaration for a system function is wrong on some system.
2656 To minimize conflicts, leave it to the system header files to declare
2657 system functions. If the headers don't declare a function, let it
2658 remain undeclared.
2659
2660 While it may seem unclean to use a function without declaring it, in
2661 practice this works fine for most system library functions on the
2662 systems where this really happens; thus, the disadvantage is only
2663 theoretical. By contrast, actual declarations have frequently caused
2664 actual conflicts.
2665
2666 @item
2667 If you must declare a system function, don't specify the argument types.
2668 Use an old-style declaration, not a Standard C prototype. The more you
2669 specify about the function, the more likely a conflict.
2670
2671 @item
2672 In particular, don't unconditionally declare @code{malloc} or
2673 @code{realloc}.
2674
2675 Most GNU programs use those functions just once, in functions
2676 conventionally named @code{xmalloc} and @code{xrealloc}. These
2677 functions call @code{malloc} and @code{realloc}, respectively, and
2678 check the results.
2679
2680 Because @code{xmalloc} and @code{xrealloc} are defined in your program,
2681 you can declare them in other files without any risk of type conflict.
2682
2683 On most systems, @code{int} is the same length as a pointer; thus, the
2684 calls to @code{malloc} and @code{realloc} work fine. For the few
2685 exceptional systems (mostly 64-bit machines), you can use
2686 @strong{conditionalized} declarations of @code{malloc} and
2687 @code{realloc}---or put these declarations in configuration files
2688 specific to those systems.
2689
2690 @cindex string library functions
2691 @item
2692 The string functions require special treatment. Some Unix systems have
2693 a header file @file{string.h}; others have @file{strings.h}. Neither
2694 file name is portable. There are two things you can do: use Autoconf to
2695 figure out which file to include, or don't include either file.
2696
2697 @item
2698 If you don't include either strings file, you can't get declarations for
2699 the string functions from the header file in the usual way.
2700
2701 That causes less of a problem than you might think. The newer standard
2702 string functions should be avoided anyway because many systems still
2703 don't support them. The string functions you can use are these:
2704
2705 @example
2706 strcpy strncpy strcat strncat
2707 strlen strcmp strncmp
2708 strchr strrchr
2709 @end example
2710
2711 The copy and concatenate functions work fine without a declaration as
2712 long as you don't use their values. Using their values without a
2713 declaration fails on systems where the width of a pointer differs from
2714 the width of @code{int}, and perhaps in other cases. It is trivial to
2715 avoid using their values, so do that.
2716
2717 The compare functions and @code{strlen} work fine without a declaration
2718 on most systems, possibly all the ones that GNU software runs on.
2719 You may find it necessary to declare them @strong{conditionally} on a
2720 few systems.
2721
2722 The search functions must be declared to return @code{char *}. Luckily,
2723 there is no variation in the data type they return. But there is
2724 variation in their names. Some systems give these functions the names
2725 @code{index} and @code{rindex}; other systems use the names
2726 @code{strchr} and @code{strrchr}. Some systems support both pairs of
2727 names, but neither pair works on all systems.
2728
2729 You should pick a single pair of names and use it throughout your
2730 program. (Nowadays, it is better to choose @code{strchr} and
2731 @code{strrchr} for new programs, since those are the standard
2732 names.) Declare both of those names as functions returning @code{char
2733 *}. On systems which don't support those names, define them as macros
2734 in terms of the other pair. For example, here is what to put at the
2735 beginning of your file (or in a header) if you want to use the names
2736 @code{strchr} and @code{strrchr} throughout:
2737
2738 @example
2739 #ifndef HAVE_STRCHR
2740 #define strchr index
2741 #endif
2742 #ifndef HAVE_STRRCHR
2743 #define strrchr rindex
2744 #endif
2745
2746 char *strchr ();
2747 char *strrchr ();
2748 @end example
2749 @end itemize
2750
2751 Here we assume that @code{HAVE_STRCHR} and @code{HAVE_STRRCHR} are
2752 macros defined in systems where the corresponding functions exist.
2753 One way to get them properly defined is to use Autoconf.
2754
2755 @node Internationalization
2756 @section Internationalization
2757 @cindex internationalization
2758
2759 @pindex gettext
2760 GNU has a library called GNU gettext that makes it easy to translate the
2761 messages in a program into various languages. You should use this
2762 library in every program. Use English for the messages as they appear
2763 in the program, and let gettext provide the way to translate them into
2764 other languages.
2765
2766 Using GNU gettext involves putting a call to the @code{gettext} macro
2767 around each string that might need translation---like this:
2768
2769 @example
2770 printf (gettext ("Processing file `%s'..."));
2771 @end example
2772
2773 @noindent
2774 This permits GNU gettext to replace the string @code{"Processing file
2775 `%s'..."} with a translated version.
2776
2777 Once a program uses gettext, please make a point of writing calls to
2778 @code{gettext} when you add new strings that call for translation.
2779
2780 Using GNU gettext in a package involves specifying a @dfn{text domain
2781 name} for the package. The text domain name is used to separate the
2782 translations for this package from the translations for other packages.
2783 Normally, the text domain name should be the same as the name of the
2784 package---for example, @samp{fileutils} for the GNU file utilities.
2785
2786 @cindex message text, and internationalization
2787 To enable gettext to work well, avoid writing code that makes
2788 assumptions about the structure of words or sentences. When you want
2789 the precise text of a sentence to vary depending on the data, use two or
2790 more alternative string constants each containing a complete sentences,
2791 rather than inserting conditionalized words or phrases into a single
2792 sentence framework.
2793
2794 Here is an example of what not to do:
2795
2796 @example
2797 printf ("%d file%s processed", nfiles,
2798 nfiles != 1 ? "s" : "");
2799 @end example
2800
2801 @noindent
2802 The problem with that example is that it assumes that plurals are made
2803 by adding `s'. If you apply gettext to the format string, like this,
2804
2805 @example
2806 printf (gettext ("%d file%s processed"), nfiles,
2807 nfiles != 1 ? "s" : "");
2808 @end example
2809
2810 @noindent
2811 the message can use different words, but it will still be forced to use
2812 `s' for the plural. Here is a better way:
2813
2814 @example
2815 printf ((nfiles != 1 ? "%d files processed"
2816 : "%d file processed"),
2817 nfiles);
2818 @end example
2819
2820 @noindent
2821 This way, you can apply gettext to each of the two strings
2822 independently:
2823
2824 @example
2825 printf ((nfiles != 1 ? gettext ("%d files processed")
2826 : gettext ("%d file processed")),
2827 nfiles);
2828 @end example
2829
2830 @noindent
2831 This can be any method of forming the plural of the word for ``file'', and
2832 also handles languages that require agreement in the word for
2833 ``processed''.
2834
2835 A similar problem appears at the level of sentence structure with this
2836 code:
2837
2838 @example
2839 printf ("# Implicit rule search has%s been done.\n",
2840 f->tried_implicit ? "" : " not");
2841 @end example
2842
2843 @noindent
2844 Adding @code{gettext} calls to this code cannot give correct results for
2845 all languages, because negation in some languages requires adding words
2846 at more than one place in the sentence. By contrast, adding
2847 @code{gettext} calls does the job straightfowardly if the code starts
2848 out like this:
2849
2850 @example
2851 printf (f->tried_implicit
2852 ? "# Implicit rule search has been done.\n",
2853 : "# Implicit rule search has not been done.\n");
2854 @end example
2855
2856 @node Mmap
2857 @section Mmap
2858 @findex mmap
2859
2860 Don't assume that @code{mmap} either works on all files or fails
2861 for all files. It may work on some files and fail on others.
2862
2863 The proper way to use @code{mmap} is to try it on the specific file for
2864 which you want to use it---and if @code{mmap} doesn't work, fall back on
2865 doing the job in another way using @code{read} and @code{write}.
2866
2867 The reason this precaution is needed is that the GNU kernel (the HURD)
2868 provides a user-extensible file system, in which there can be many
2869 different kinds of ``ordinary files.'' Many of them support
2870 @code{mmap}, but some do not. It is important to make programs handle
2871 all these kinds of files.
2872
2873 @node Documentation
2874 @chapter Documenting Programs
2875 @cindex documentation
2876
2877 A GNU program should ideally come with full free documentation, adequate
2878 for both reference and tutorial purposes. If the package can be
2879 programmed or extended, the documentation should cover programming or
2880 extending it, as well as just using it.
2881
2882 @menu
2883 * GNU Manuals:: Writing proper manuals.
2884 * Doc Strings and Manuals:: Compiling doc strings doesn't make a manual.
2885 * Manual Structure Details:: Specific structure conventions.
2886 * License for Manuals:: Writing the distribution terms for a manual.
2887 * Manual Credits:: Giving credit to documentation contributors.
2888 * Printed Manuals:: Mentioning the printed manual.
2889 * NEWS File:: NEWS files supplement manuals.
2890 * Change Logs:: Recording Changes
2891 * Man Pages:: Man pages are secondary.
2892 * Reading other Manuals:: How far you can go in learning
2893 from other manuals.
2894 @end menu
2895
2896 @node GNU Manuals
2897 @section GNU Manuals
2898
2899 The preferred document format for the GNU system is the Texinfo
2900 formatting language. Every GNU package should (ideally) have
2901 documentation in Texinfo both for reference and for learners. Texinfo
2902 makes it possible to produce a good quality formatted book, using
2903 @TeX{}, and to generate an Info file. It is also possible to generate
2904 HTML output from Texinfo source. See the Texinfo manual, either the
2905 hardcopy, or the on-line version available through @code{info} or the
2906 Emacs Info subsystem (@kbd{C-h i}).
2907
2908 Nowadays some other formats such as Docbook and Sgmltexi can be
2909 converted automatically into Texinfo. It is ok to produce the Texinfo
2910 documentation by conversion this way, as long as it gives good results.
2911
2912 Programmers often find it most natural to structure the documentation
2913 following the structure of the implementation, which they know. But
2914 this structure is not necessarily good for explaining how to use the
2915 program; it may be irrelevant and confusing for a user.
2916
2917 At every level, from the sentences in a paragraph to the grouping of
2918 topics into separate manuals, the right way to structure documentation
2919 is according to the concepts and questions that a user will have in mind
2920 when reading it. Sometimes this structure of ideas matches the
2921 structure of the implementation of the software being documented---but
2922 often they are different. Often the most important part of learning to
2923 write good documentation is learning to notice when you are structuring
2924 the documentation like the implementation, and think about better
2925 alternatives.
2926
2927 For example, each program in the GNU system probably ought to be
2928 documented in one manual; but this does not mean each program should
2929 have its own manual. That would be following the structure of the
2930 implementation, rather than the structure that helps the user
2931 understand.
2932
2933 Instead, each manual should cover a coherent @emph{topic}. For example,
2934 instead of a manual for @code{diff} and a manual for @code{diff3}, we
2935 have one manual for ``comparison of files'' which covers both of those
2936 programs, as well as @code{cmp}. By documenting these programs
2937 together, we can make the whole subject clearer.
2938
2939 The manual which discusses a program should certainly document all of
2940 the program's command-line options and all of its commands. It should
2941 give examples of their use. But don't organize the manual as a list of
2942 features. Instead, organize it logically, by subtopics. Address the
2943 questions that a user will ask when thinking about the job that the
2944 program does.
2945
2946 In general, a GNU manual should serve both as tutorial and reference.
2947 It should be set up for convenient access to each topic through Info,
2948 and for reading straight through (appendixes aside). A GNU manual
2949 should give a good introduction to a beginner reading through from the
2950 start, and should also provide all the details that hackers want.
2951 The Bison manual is a good example of this---please take a look at it
2952 to see what we mean.
2953
2954 That is not as hard as it first sounds. Arrange each chapter as a
2955 logical breakdown of its topic, but order the sections, and write their
2956 text, so that reading the chapter straight through makes sense. Do
2957 likewise when structuring the book into chapters, and when structuring a
2958 section into paragraphs. The watchword is, @emph{at each point, address
2959 the most fundamental and important issue raised by the preceding text.}
2960
2961 If necessary, add extra chapters at the beginning of the manual which
2962 are purely tutorial and cover the basics of the subject. These provide
2963 the framework for a beginner to understand the rest of the manual. The
2964 Bison manual provides a good example of how to do this.
2965
2966 To serve as a reference, a manual should have an Index that list all the
2967 functions, variables, options, and important concepts that are part of
2968 the program. One combined Index should do for a short manual, but
2969 sometimes for a complex package it is better to use multiple indices.
2970 The Texinfo manual includes advice on preparing good index entries, see
2971 @ref{Index Entries, , Making Index Entries, texinfo, The GNU Texinfo
2972 Manual}, and see @ref{Indexing Commands, , Defining the Entries of an
2973 Index, texinfo, The GNU Texinfo manual}.
2974
2975 Don't use Unix man pages as a model for how to write GNU documentation;
2976 most of them are terse, badly structured, and give inadequate
2977 explanation of the underlying concepts. (There are, of course, some
2978 exceptions.) Also, Unix man pages use a particular format which is
2979 different from what we use in GNU manuals.
2980
2981 Please include an email address in the manual for where to report
2982 bugs @emph{in the manual}.
2983
2984 Please do not use the term ``pathname'' that is used in Unix
2985 documentation; use ``file name'' (two words) instead. We use the term
2986 ``path'' only for search paths, which are lists of directory names.
2987
2988 Please do not use the term ``illegal'' to refer to erroneous input to a
2989 computer program. Please use ``invalid'' for this, and reserve the term
2990 ``illegal'' for activities punishable by law.
2991
2992 @node Doc Strings and Manuals
2993 @section Doc Strings and Manuals
2994
2995 Some programming systems, such as Emacs, provide a documentation string
2996 for each function, command or variable. You may be tempted to write a
2997 reference manual by compiling the documentation strings and writing a
2998 little additional text to go around them---but you must not do it. That
2999 approach is a fundamental mistake. The text of well-written
3000 documentation strings will be entirely wrong for a manual.
3001
3002 A documentation string needs to stand alone---when it appears on the
3003 screen, there will be no other text to introduce or explain it.
3004 Meanwhile, it can be rather informal in style.
3005
3006 The text describing a function or variable in a manual must not stand
3007 alone; it appears in the context of a section or subsection. Other text
3008 at the beginning of the section should explain some of the concepts, and
3009 should often make some general points that apply to several functions or
3010 variables. The previous descriptions of functions and variables in the
3011 section will also have given information about the topic. A description
3012 written to stand alone would repeat some of that information; this
3013 redundance looks bad. Meanwhile, the informality that is acceptable in
3014 a documentation string is totally unacceptable in a manual.
3015
3016 The only good way to use documentation strings in writing a good manual
3017 is to use them as a source of information for writing good text.
3018
3019 @node Manual Structure Details
3020 @section Manual Structure Details
3021 @cindex manual structure
3022
3023 The title page of the manual should state the version of the programs or
3024 packages documented in the manual. The Top node of the manual should
3025 also contain this information. If the manual is changing more
3026 frequently than or independent of the program, also state a version
3027 number for the manual in both of these places.
3028
3029 Each program documented in the manual should have a node named
3030 @samp{@var{program} Invocation} or @samp{Invoking @var{program}}. This
3031 node (together with its subnodes, if any) should describe the program's
3032 command line arguments and how to run it (the sort of information people
3033 would look in a man page for). Start with an @samp{@@example}
3034 containing a template for all the options and arguments that the program
3035 uses.
3036
3037 Alternatively, put a menu item in some menu whose item name fits one of
3038 the above patterns. This identifies the node which that item points to
3039 as the node for this purpose, regardless of the node's actual name.
3040
3041 The @samp{--usage} feature of the Info reader looks for such a node
3042 or menu item in order to find the relevant text, so it is essential
3043 for every Texinfo file to have one.
3044
3045 If one manual describes several programs, it should have such a node for
3046 each program described in the manual.
3047
3048 @node License for Manuals
3049 @section License for Manuals
3050 @cindex license for manuals
3051
3052 Please use the GNU Free Documentation License for all GNU manuals that
3053 are more than a few pages long. Likewise for a collection of short
3054 documents---you only need one copy of the GNU FDL for the whole
3055 collection. For a single short document, you can use a very permissive
3056 non-copyleft license, to avoid taking up space with a long license.
3057
3058 See @uref{http://www.gnu.org/copyleft/fdl-howto.html} for more explanation
3059 of how to employ the GFDL.
3060
3061 Note that it is not obligatory to include a copy of the GNU GPL or GNU
3062 LGPL in a manual whose license is neither the GPL nor the LGPL. It can
3063 be a good idea to include the program's license in a large manual; in a
3064 short manual, whose size would be increased considerably by including
3065 the program's license, it is probably better not to include it.
3066
3067 @node Manual Credits
3068 @section Manual Credits
3069 @cindex credits for manuals
3070
3071 Please credit the principal human writers of the manual as the authors,
3072 on the title page of the manual. If a company sponsored the work, thank
3073 the company in a suitable place in the manual, but do not cite the
3074 company as an author.
3075
3076 @node Printed Manuals
3077 @section Printed Manuals
3078
3079 The FSF publishes some GNU manuals in printed form. To encourage sales
3080 of these manuals, the on-line versions of the manual should mention at
3081 the very start that the printed manual is available and should point at
3082 information for getting it---for instance, with a link to the page
3083 @url{http://www.gnu.org/order/order.html}. This should not be included
3084 in the printed manual, though, because there it is redundant.
3085
3086 It is also useful to explain in the on-line forms of the manual how the
3087 user can print out the manual from the sources.
3088
3089 @node NEWS File
3090 @section The NEWS File
3091 @cindex @file{NEWS} file
3092
3093 In addition to its manual, the package should have a file named
3094 @file{NEWS} which contains a list of user-visible changes worth
3095 mentioning. In each new release, add items to the front of the file and
3096 identify the version they pertain to. Don't discard old items; leave
3097 them in the file after the newer items. This way, a user upgrading from
3098 any previous version can see what is new.
3099
3100 If the @file{NEWS} file gets very long, move some of the older items
3101 into a file named @file{ONEWS} and put a note at the end referring the
3102 user to that file.
3103
3104 @node Change Logs
3105 @section Change Logs
3106 @cindex change logs
3107
3108 Keep a change log to describe all the changes made to program source
3109 files. The purpose of this is so that people investigating bugs in the
3110 future will know about the changes that might have introduced the bug.
3111 Often a new bug can be found by looking at what was recently changed.
3112 More importantly, change logs can help you eliminate conceptual
3113 inconsistencies between different parts of a program, by giving you a
3114 history of how the conflicting concepts arose and who they came from.
3115
3116 @menu
3117 * Change Log Concepts::
3118 * Style of Change Logs::
3119 * Simple Changes::
3120 * Conditional Changes::
3121 * Indicating the Part Changed::
3122 @end menu
3123
3124 @node Change Log Concepts
3125 @subsection Change Log Concepts
3126
3127 You can think of the change log as a conceptual ``undo list'' which
3128 explains how earlier versions were different from the current version.
3129 People can see the current version; they don't need the change log
3130 to tell them what is in it. What they want from a change log is a
3131 clear explanation of how the earlier version differed.
3132
3133 The change log file is normally called @file{ChangeLog} and covers an
3134 entire directory. Each directory can have its own change log, or a
3135 directory can use the change log of its parent directory--it's up to
3136 you.
3137
3138 Another alternative is to record change log information with a version
3139 control system such as RCS or CVS. This can be converted automatically
3140 to a @file{ChangeLog} file using @code{rcs2log}; in Emacs, the command
3141 @kbd{C-x v a} (@code{vc-update-change-log}) does the job.
3142
3143 There's no need to describe the full purpose of the changes or how they
3144 work together. If you think that a change calls for explanation, you're
3145 probably right. Please do explain it---but please put the explanation
3146 in comments in the code, where people will see it whenever they see the
3147 code. For example, ``New function'' is enough for the change log when
3148 you add a function, because there should be a comment before the
3149 function definition to explain what it does.
3150
3151 However, sometimes it is useful to write one line to describe the
3152 overall purpose of a batch of changes.
3153
3154 The easiest way to add an entry to @file{ChangeLog} is with the Emacs
3155 command @kbd{M-x add-change-log-entry}. An entry should have an
3156 asterisk, the name of the changed file, and then in parentheses the name
3157 of the changed functions, variables or whatever, followed by a colon.
3158 Then describe the changes you made to that function or variable.
3159
3160 @node Style of Change Logs
3161 @subsection Style of Change Logs
3162 @cindex change logs, style
3163
3164 Here are some simple examples of change log entries, starting with the
3165 header line that says who made the change and when, followed by
3166 descriptions of specific changes. (These examples are drawn from Emacs
3167 and GCC.)
3168
3169 @example
3170 1998-08-17 Richard Stallman <rms@@gnu.org>
3171
3172 * register.el (insert-register): Return nil.
3173 (jump-to-register): Likewise.
3174
3175 * sort.el (sort-subr): Return nil.
3176
3177 * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
3178 Restart the tex shell if process is gone or stopped.
3179 (tex-shell-running): New function.
3180
3181 * expr.c (store_one_arg): Round size up for move_block_to_reg.
3182 (expand_call): Round up when emitting USE insns.
3183 * stmt.c (assign_parms): Round size up for move_block_from_reg.
3184 @end example
3185
3186 It's important to name the changed function or variable in full. Don't
3187 abbreviate function or variable names, and don't combine them.
3188 Subsequent maintainers will often search for a function name to find all
3189 the change log entries that pertain to it; if you abbreviate the name,
3190 they won't find it when they search.
3191
3192 For example, some people are tempted to abbreviate groups of function
3193 names by writing @samp{* register.el (@{insert,jump-to@}-register)};
3194 this is not a good idea, since searching for @code{jump-to-register} or
3195 @code{insert-register} would not find that entry.
3196
3197 Separate unrelated change log entries with blank lines. When two
3198 entries represent parts of the same change, so that they work together,
3199 then don't put blank lines between them. Then you can omit the file
3200 name and the asterisk when successive entries are in the same file.
3201
3202 Break long lists of function names by closing continued lines with
3203 @samp{)}, rather than @samp{,}, and opening the continuation with
3204 @samp{(} as in this example:
3205
3206 @example
3207 * keyboard.c (menu_bar_items, tool_bar_items)
3208 (Fexecute_extended_command): Deal with `keymap' property.
3209 @end example
3210
3211 @node Simple Changes
3212 @subsection Simple Changes
3213
3214 Certain simple kinds of changes don't need much detail in the change
3215 log.
3216
3217 When you change the calling sequence of a function in a simple fashion,
3218 and you change all the callers of the function to use the new calling
3219 sequence, there is no need to make individual entries for all the
3220 callers that you changed. Just write in the entry for the function
3221 being called, ``All callers changed''---like this:
3222
3223 @example
3224 * keyboard.c (Fcommand_execute): New arg SPECIAL.
3225 All callers changed.
3226 @end example
3227
3228 When you change just comments or doc strings, it is enough to write an
3229 entry for the file, without mentioning the functions. Just ``Doc
3230 fixes'' is enough for the change log.
3231
3232 There's no need to make change log entries for documentation files.
3233 This is because documentation is not susceptible to bugs that are hard
3234 to fix. Documentation does not consist of parts that must interact in a
3235 precisely engineered fashion. To correct an error, you need not know
3236 the history of the erroneous passage; it is enough to compare what the
3237 documentation says with the way the program actually works.
3238
3239 @node Conditional Changes
3240 @subsection Conditional Changes
3241 @cindex conditional changes, and change logs
3242 @cindex change logs, conditional changes
3243
3244 C programs often contain compile-time @code{#if} conditionals. Many
3245 changes are conditional; sometimes you add a new definition which is
3246 entirely contained in a conditional. It is very useful to indicate in
3247 the change log the conditions for which the change applies.
3248
3249 Our convention for indicating conditional changes is to use square
3250 brackets around the name of the condition.
3251
3252 Here is a simple example, describing a change which is conditional but
3253 does not have a function or entity name associated with it:
3254
3255 @example
3256 * xterm.c [SOLARIS2]: Include string.h.
3257 @end example
3258
3259 Here is an entry describing a new definition which is entirely
3260 conditional. This new definition for the macro @code{FRAME_WINDOW_P} is
3261 used only when @code{HAVE_X_WINDOWS} is defined:
3262
3263 @example
3264 * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined.
3265 @end example
3266
3267 Here is an entry for a change within the function @code{init_display},
3268 whose definition as a whole is unconditional, but the changes themselves
3269 are contained in a @samp{#ifdef HAVE_LIBNCURSES} conditional:
3270
3271 @example
3272 * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
3273 @end example
3274
3275 Here is an entry for a change that takes affect only when
3276 a certain macro is @emph{not} defined:
3277
3278 @example
3279 (gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
3280 @end example
3281
3282 @node Indicating the Part Changed
3283 @subsection Indicating the Part Changed
3284
3285 Indicate the part of a function which changed by using angle brackets
3286 enclosing an indication of what the changed part does. Here is an entry
3287 for a change in the part of the function @code{sh-while-getopts} that
3288 deals with @code{sh} commands:
3289
3290 @example
3291 * progmodes/sh-script.el (sh-while-getopts) <sh>: Handle case that
3292 user-specified option string is empty.
3293 @end example
3294
3295
3296 @node Man Pages
3297 @section Man Pages
3298 @cindex man pages
3299
3300 In the GNU project, man pages are secondary. It is not necessary or
3301 expected for every GNU program to have a man page, but some of them do.
3302 It's your choice whether to include a man page in your program.
3303
3304 When you make this decision, consider that supporting a man page
3305 requires continual effort each time the program is changed. The time
3306 you spend on the man page is time taken away from more useful work.
3307
3308 For a simple program which changes little, updating the man page may be
3309 a small job. Then there is little reason not to include a man page, if
3310 you have one.
3311
3312 For a large program that changes a great deal, updating a man page may
3313 be a substantial burden. If a user offers to donate a man page, you may
3314 find this gift costly to accept. It may be better to refuse the man
3315 page unless the same person agrees to take full responsibility for
3316 maintaining it---so that you can wash your hands of it entirely. If
3317 this volunteer later ceases to do the job, then don't feel obliged to
3318 pick it up yourself; it may be better to withdraw the man page from the
3319 distribution until someone else agrees to update it.
3320
3321 When a program changes only a little, you may feel that the
3322 discrepancies are small enough that the man page remains useful without
3323 updating. If so, put a prominent note near the beginning of the man
3324 page explaining that you don't maintain it and that the Texinfo manual
3325 is more authoritative. The note should say how to access the Texinfo
3326 documentation.
3327
3328 @node Reading other Manuals
3329 @section Reading other Manuals
3330
3331 There may be non-free books or documentation files that describe the
3332 program you are documenting.
3333
3334 It is ok to use these documents for reference, just as the author of a
3335 new algebra textbook can read other books on algebra. A large portion
3336 of any non-fiction book consists of facts, in this case facts about how
3337 a certain program works, and these facts are necessarily the same for
3338 everyone who writes about the subject. But be careful not to copy your
3339 outline structure, wording, tables or examples from preexisting non-free
3340 documentation. Copying from free documentation may be ok; please check
3341 with the FSF about the individual case.
3342
3343 @node Managing Releases
3344 @chapter The Release Process
3345 @cindex releasing
3346
3347 Making a release is more than just bundling up your source files in a
3348 tar file and putting it up for FTP. You should set up your software so
3349 that it can be configured to run on a variety of systems. Your Makefile
3350 should conform to the GNU standards described below, and your directory
3351 layout should also conform to the standards discussed below. Doing so
3352 makes it easy to include your package into the larger framework of
3353 all GNU software.
3354
3355 @menu
3356 * Configuration:: How Configuration Should Work
3357 * Makefile Conventions:: Makefile Conventions
3358 * Releases:: Making Releases
3359 @end menu
3360
3361 @node Configuration
3362 @section How Configuration Should Work
3363 @cindex program configuration
3364
3365 @pindex configure
3366 Each GNU distribution should come with a shell script named
3367 @code{configure}. This script is given arguments which describe the
3368 kind of machine and system you want to compile the program for.
3369
3370 The @code{configure} script must record the configuration options so
3371 that they affect compilation.
3372
3373 One way to do this is to make a link from a standard name such as
3374 @file{config.h} to the proper configuration file for the chosen system.
3375 If you use this technique, the distribution should @emph{not} contain a
3376 file named @file{config.h}. This is so that people won't be able to
3377 build the program without configuring it first.
3378
3379 Another thing that @code{configure} can do is to edit the Makefile. If
3380 you do this, the distribution should @emph{not} contain a file named
3381 @file{Makefile}. Instead, it should include a file @file{Makefile.in} which
3382 contains the input used for editing. Once again, this is so that people
3383 won't be able to build the program without configuring it first.
3384
3385 If @code{configure} does write the @file{Makefile}, then @file{Makefile}
3386 should have a target named @file{Makefile} which causes @code{configure}
3387 to be rerun, setting up the same configuration that was set up last
3388 time. The files that @code{configure} reads should be listed as
3389 dependencies of @file{Makefile}.
3390
3391 All the files which are output from the @code{configure} script should
3392 have comments at the beginning explaining that they were generated
3393 automatically using @code{configure}. This is so that users won't think
3394 of trying to edit them by hand.
3395
3396 The @code{configure} script should write a file named @file{config.status}
3397 which describes which configuration options were specified when the
3398 program was last configured. This file should be a shell script which,
3399 if run, will recreate the same configuration.
3400
3401 The @code{configure} script should accept an option of the form
3402 @samp{--srcdir=@var{dirname}} to specify the directory where sources are found
3403 (if it is not the current directory). This makes it possible to build
3404 the program in a separate directory, so that the actual source directory
3405 is not modified.
3406
3407 If the user does not specify @samp{--srcdir}, then @code{configure} should
3408 check both @file{.} and @file{..} to see if it can find the sources. If
3409 it finds the sources in one of these places, it should use them from
3410 there. Otherwise, it should report that it cannot find the sources, and
3411 should exit with nonzero status.
3412
3413 Usually the easy way to support @samp{--srcdir} is by editing a
3414 definition of @code{VPATH} into the Makefile. Some rules may need to
3415 refer explicitly to the specified source directory. To make this
3416 possible, @code{configure} can add to the Makefile a variable named
3417 @code{srcdir} whose value is precisely the specified directory.
3418
3419 The @code{configure} script should also take an argument which specifies the
3420 type of system to build the program for. This argument should look like
3421 this:
3422
3423 @example
3424 @var{cpu}-@var{company}-@var{system}
3425 @end example
3426
3427 For example, a Sun 3 might be @samp{m68k-sun-sunos4.1}.
3428
3429 The @code{configure} script needs to be able to decode all plausible
3430 alternatives for how to describe a machine. Thus, @samp{sun3-sunos4.1}
3431 would be a valid alias. For many programs, @samp{vax-dec-ultrix} would
3432 be an alias for @samp{vax-dec-bsd}, simply because the differences
3433 between Ultrix and @sc{bsd} are rarely noticeable, but a few programs
3434 might need to distinguish them.
3435 @c Real 4.4BSD now runs on some Suns.
3436
3437 There is a shell script called @file{config.sub} that you can use
3438 as a subroutine to validate system types and canonicalize aliases.
3439
3440 @cindex optional features, configure-time
3441 Other options are permitted to specify in more detail the software
3442 or hardware present on the machine, and include or exclude optional
3443 parts of the package:
3444
3445 @table @samp
3446 @item --enable-@var{feature}@r{[}=@var{parameter}@r{]}
3447 Configure the package to build and install an optional user-level
3448 facility called @var{feature}. This allows users to choose which
3449 optional features to include. Giving an optional @var{parameter} of
3450 @samp{no} should omit @var{feature}, if it is built by default.
3451
3452 No @samp{--enable} option should @strong{ever} cause one feature to
3453 replace another. No @samp{--enable} option should ever substitute one
3454 useful behavior for another useful behavior. The only proper use for
3455 @samp{--enable} is for questions of whether to build part of the program
3456 or exclude it.
3457
3458 @item --with-@var{package}
3459 @c @r{[}=@var{parameter}@r{]}
3460 The package @var{package} will be installed, so configure this package
3461 to work with @var{package}.
3462
3463 @c Giving an optional @var{parameter} of
3464 @c @samp{no} should omit @var{package}, if it is used by default.
3465
3466 Possible values of @var{package} include
3467 @samp{gnu-as} (or @samp{gas}), @samp{gnu-ld}, @samp{gnu-libc},
3468 @samp{gdb},
3469 @samp{x},
3470 and
3471 @samp{x-toolkit}.
3472
3473 Do not use a @samp{--with} option to specify the file name to use to
3474 find certain files. That is outside the scope of what @samp{--with}
3475 options are for.
3476 @end table
3477
3478 All @code{configure} scripts should accept all of these ``detail''
3479 options, whether or not they make any difference to the particular
3480 package at hand. In particular, they should accept any option that
3481 starts with @samp{--with-} or @samp{--enable-}. This is so users will
3482 be able to configure an entire GNU source tree at once with a single set
3483 of options.
3484
3485 You will note that the categories @samp{--with-} and @samp{--enable-}
3486 are narrow: they @strong{do not} provide a place for any sort of option
3487 you might think of. That is deliberate. We want to limit the possible
3488 configuration options in GNU software. We do not want GNU programs to
3489 have idiosyncratic configuration options.
3490
3491 Packages that perform part of the compilation process may support
3492 cross-compilation. In such a case, the host and target machines for the
3493 program may be different.
3494
3495 The @code{configure} script should normally treat the specified type of
3496 system as both the host and the target, thus producing a program which
3497 works for the same type of machine that it runs on.
3498
3499 To configure a cross-compiler, cross-assembler, or what have you, you
3500 should specify a target different from the host, using the configure
3501 option @samp{--target=@var{targettype}}. The syntax for
3502 @var{targettype} is the same as for the host type. So the command would
3503 look like this:
3504
3505 @example
3506 ./configure @var{hosttype} --target=@var{targettype}
3507 @end example
3508
3509 Programs for which cross-operation is not meaningful need not accept the
3510 @samp{--target} option, because configuring an entire operating system for
3511 cross-operation is not a meaningful operation.
3512
3513 Bootstrapping a cross-compiler requires compiling it on a machine other
3514 than the host it will run on. Compilation packages accept a
3515 configuration option @samp{--build=@var{buildtype}} for specifying the
3516 configuration on which you will compile them, but the configure script
3517 should normally guess the build machine type (using
3518 @file{config.guess}), so this option is probably not necessary. The
3519 host and target types normally default from the build type, so in
3520 bootstrapping a cross-compiler you must specify them both explicitly.
3521
3522 Some programs have ways of configuring themselves automatically. If
3523 your program is set up to do this, your @code{configure} script can simply
3524 ignore most of its arguments.
3525
3526 @comment The makefile standards are in a separate file that is also
3527 @comment included by make.texinfo. Done by [email protected] on 1/6/93.
3528 @comment For this document, turn chapters into sections, etc.
3529 @lowersections
3530 @include make-stds.texi
3531 @raisesections
3532
3533 @node Releases
3534 @section Making Releases
3535 @cindex packaging
3536
3537 Package the distribution of @code{Foo version 69.96} up in a gzipped tar
3538 file with the name @file{foo-69.96.tar.gz}. It should unpack into a
3539 subdirectory named @file{foo-69.96}.
3540
3541 Building and installing the program should never modify any of the files
3542 contained in the distribution. This means that all the files that form
3543 part of the program in any way must be classified into @dfn{source
3544 files} and @dfn{non-source files}. Source files are written by humans
3545 and never changed automatically; non-source files are produced from
3546 source files by programs under the control of the Makefile.
3547
3548 @cindex @file{README} file
3549 The distribution should contain a file named @file{README} which gives
3550 the name of the package, and a general description of what it does. It
3551 is also good to explain the purpose of each of the first-level
3552 subdirectories in the package, if there are any. The @file{README} file
3553 should either state the version number of the package, or refer to where
3554 in the package it can be found.
3555
3556 The @file{README} file should refer to the file @file{INSTALL}, which
3557 should contain an explanation of the installation procedure.
3558
3559 The @file{README} file should also refer to the file which contains the
3560 copying conditions. The GNU GPL, if used, should be in a file called
3561 @file{COPYING}. If the GNU LGPL is used, it should be in a file called
3562 @file{COPYING.LIB}.
3563
3564 Naturally, all the source files must be in the distribution. It is okay
3565 to include non-source files in the distribution, provided they are
3566 up-to-date and machine-independent, so that building the distribution
3567 normally will never modify them. We commonly include non-source files
3568 produced by Bison, @code{lex}, @TeX{}, and @code{makeinfo}; this helps avoid
3569 unnecessary dependencies between our distributions, so that users can
3570 install whichever packages they want to install.
3571
3572 Non-source files that might actually be modified by building and
3573 installing the program should @strong{never} be included in the
3574 distribution. So if you do distribute non-source files, always make
3575 sure they are up to date when you make a new distribution.
3576
3577 Make sure that the directory into which the distribution unpacks (as
3578 well as any subdirectories) are all world-writable (octal mode 777).
3579 This is so that old versions of @code{tar} which preserve the
3580 ownership and permissions of the files from the tar archive will be
3581 able to extract all the files even if the user is unprivileged.
3582
3583 Make sure that all the files in the distribution are world-readable.
3584
3585 Make sure that no file name in the distribution is more than 14
3586 characters long. Likewise, no file created by building the program
3587 should have a name longer than 14 characters. The reason for this is
3588 that some systems adhere to a foolish interpretation of the @sc{posix}
3589 standard, and refuse to open a longer name, rather than truncating as
3590 they did in the past.
3591
3592 Don't include any symbolic links in the distribution itself. If the tar
3593 file contains symbolic links, then people cannot even unpack it on
3594 systems that don't support symbolic links. Also, don't use multiple
3595 names for one file in different directories, because certain file
3596 systems cannot handle this and that prevents unpacking the
3597 distribution.
3598
3599 Try to make sure that all the file names will be unique on MS-DOS. A
3600 name on MS-DOS consists of up to 8 characters, optionally followed by a
3601 period and up to three characters. MS-DOS will truncate extra
3602 characters both before and after the period. Thus,
3603 @file{foobarhacker.c} and @file{foobarhacker.o} are not ambiguous; they
3604 are truncated to @file{foobarha.c} and @file{foobarha.o}, which are
3605 distinct.
3606
3607 @cindex @file{texinfo.tex}, in a distribution
3608 Include in your distribution a copy of the @file{texinfo.tex} you used
3609 to test print any @file{*.texinfo} or @file{*.texi} files.
3610
3611 Likewise, if your program uses small GNU software packages like regex,
3612 getopt, obstack, or termcap, include them in the distribution file.
3613 Leaving them out would make the distribution file a little smaller at
3614 the expense of possible inconvenience to a user who doesn't know what
3615 other files to get.
3616
3617 @node References
3618 @chapter References to Non-Free Software and Documentation
3619 @cindex references to non-free material
3620
3621 A GNU program should not recommend use of any non-free program. We
3622 can't stop some people from writing proprietary programs, or stop other
3623 people from using them. But we can and should avoid helping to
3624 advertise them to new customers.
3625
3626 Sometimes it is important to mention how to build your package on top of
3627 some non-free operating system or other non-free base package. In such
3628 cases, please mention the name of the non-free package or system in the
3629 briefest possible way. Don't include any references for where to find
3630 more information about the proprietary program. The goal should be that
3631 people already using the proprietary program will get the advice they
3632 need about how to use your free program, while people who don't already
3633 use the proprietary program will not see anything to encourage them to
3634 take an interest in it.
3635
3636 Likewise, a GNU package should not refer the user to any non-free
3637 documentation for free software. The need for free documentation to go
3638 with free software is now a major focus of the GNU project; to show that
3639 we are serious about the need for free documentation, we must not
3640 undermine our position by recommending use of documentation that isn't
3641 free.
3642
3643 @node Index
3644 @unnumbered Index
3645 @printindex cp
3646
3647 @contents
3648
3649 @bye
3650 Local variables:
3651 update-date-leading-regexp: "@c This date is automagically updated when you save this file:\n@set lastupdate "
3652 update-date-trailing-regexp: ""
3653 eval: (load "/gd/gnuorg/update-date.el")
3654 eval: (add-hook 'write-file-hooks 'update-date)
3655 compile-command: "make just-standards"
3656 End: