Mercurial > hg > xemacs-beta
comparison man/standards.texi @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | cc15677e0335 |
children | 697ef44129c6 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
1 \input texinfo @c -*-texinfo-*- | 1 \input texinfo @c -*-texinfo-*- |
2 @c %**start of header | 2 @c %**start of header |
3 @setfilename ../info/standards.info | 3 @setfilename ../info/standards.info |
4 @settitle GNU Coding Standards | 4 @settitle GNU Coding Standards |
5 @c UPDATE THIS DATE WHENEVER YOU MAKE CHANGES! | 5 @c This date is automagically updated when you save this file: |
6 @set lastupdate 17 May 1996 | 6 @set lastupdate June 24, 1999 |
7 @c %**end of header | 7 @c %**end of header |
8 | 8 |
9 @ifinfo | 9 @ifinfo |
10 @format | 10 @format |
11 START-INFO-DIR-ENTRY | 11 START-INFO-DIR-ENTRY |
26 @set CHAPTER node | 26 @set CHAPTER node |
27 @end ifinfo | 27 @end ifinfo |
28 | 28 |
29 @ifinfo | 29 @ifinfo |
30 GNU Coding Standards | 30 GNU Coding Standards |
31 Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. | 31 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. |
32 | 32 |
33 Permission is granted to make and distribute verbatim copies of | 33 Permission is granted to make and distribute verbatim copies of |
34 this manual provided the copyright notice and this permission notice | 34 this manual provided the copyright notice and this permission notice |
35 are preserved on all copies. | 35 are preserved on all copies. |
36 | 36 |
57 @author Richard Stallman | 57 @author Richard Stallman |
58 @author last updated @value{lastupdate} | 58 @author last updated @value{lastupdate} |
59 @page | 59 @page |
60 | 60 |
61 @vskip 0pt plus 1filll | 61 @vskip 0pt plus 1filll |
62 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. | 62 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
63 | 63 |
64 Permission is granted to make and distribute verbatim copies of | 64 Permission is granted to make and distribute verbatim copies of |
65 this manual provided the copyright notice and this permission notice | 65 this manual provided the copyright notice and this permission notice |
66 are preserved on all copies. | 66 are preserved on all copies. |
67 | 67 |
82 | 82 |
83 Last updated @value{lastupdate}. | 83 Last updated @value{lastupdate}. |
84 @end ifinfo | 84 @end ifinfo |
85 | 85 |
86 @menu | 86 @menu |
87 * Preface:: About the GNU Coding Standards | 87 * Preface:: About the GNU Coding Standards |
88 * Intellectual Property:: Keeping Free Software Free | 88 * Legal Issues:: Keeping Free Software Free |
89 * Design Advice:: General Program Design | 89 * Design Advice:: General Program Design |
90 * Program Behavior:: Program Behavior for All Programs | 90 * Program Behavior:: Program Behavior for All Programs |
91 * Writing C:: Making The Best Use of C | 91 * Writing C:: Making The Best Use of C |
92 * Documentation:: Documenting Programs | 92 * Documentation:: Documenting Programs |
93 * Managing Releases:: The Release Process | 93 * Managing Releases:: The Release Process |
94 * References:: References to Non-Free Software or Documentation | |
94 @end menu | 95 @end menu |
95 | 96 |
96 @node Preface | 97 @node Preface |
97 @chapter About the GNU Coding Standards | 98 @chapter About the GNU Coding Standards |
98 | 99 |
102 guide to writing portable, robust and reliable programs. It focuses on | 103 guide to writing portable, robust and reliable programs. It focuses on |
103 programs written in C, but many of the rules and principles are useful | 104 programs written in C, but many of the rules and principles are useful |
104 even if you write in another programming language. The rules often | 105 even if you write in another programming language. The rules often |
105 state reasons for writing in a certain way. | 106 state reasons for writing in a certain way. |
106 | 107 |
107 Corrections or suggestions regarding this document should be sent to | 108 Corrections or suggestions for this document should be sent to |
108 @code{gnu@@prep.ai.mit.edu}. If you make a suggestion, please include a | 109 @email{gnu@@gnu.org}. If you make a suggestion, please include a |
109 suggested new wording for it; our time is limited. We prefer a context | 110 suggested new wording for it; our time is limited. We prefer a context |
110 diff to the @file{standards.texi} or @file{make-stds.texi} files, but if | 111 diff to the @file{standards.texi} or @file{make-stds.texi} files, but if |
111 you don't have those files, please mail your suggestion anyway. | 112 you don't have those files, please mail your suggestion anyway. |
112 | 113 |
113 This release of the GNU Coding Standards was last updated | 114 This release of the GNU Coding Standards was last updated |
114 @value{lastupdate}. | 115 @value{lastupdate}. |
115 | 116 |
116 @node Intellectual Property | 117 @node Legal Issues |
117 @chapter Keeping Free Software Free | 118 @chapter Keeping Free Software Free |
118 | 119 |
119 This @value{CHAPTER} discusses how you can make sure that GNU software | 120 This @value{CHAPTER} discusses how you can make sure that GNU software |
120 remains unencumbered. | 121 remains unencumbered. |
121 | 122 |
122 @menu | 123 @menu |
123 * Reading Non-Free Code:: Referring to Proprietary Programs | 124 * Reading Non-Free Code:: Referring to Proprietary Programs |
124 * Contributions:: Accepting Contributions | 125 * Contributions:: Accepting Contributions |
125 @end menu | 126 @end menu |
126 | 127 |
127 @node Reading Non-Free Code | 128 @node Reading Non-Free Code |
128 @section Referring to Proprietary Programs | 129 @section Referring to Proprietary Programs |
129 | 130 |
159 | 160 |
160 | 161 |
161 @node Contributions | 162 @node Contributions |
162 @section Accepting Contributions | 163 @section Accepting Contributions |
163 | 164 |
164 If someone else sends you a piece of code to add to the program you are | 165 If the program you are working on is copyrighted by the Free Software |
165 working on, we need legal papers to use it---the same sort of legal | 166 Foundation, then when someone else sends you a piece of code to add to |
166 papers we will need to get from you. @emph{Each} significant | 167 the program, we need legal papers to use it---just as we asked you to |
167 contributor to a program must sign some sort of legal papers in order | 168 sign papers initially. @emph{Each} person who makes a nontrivial |
168 for us to have clear title to the program. The main author alone is not | 169 contribution to a program must sign some sort of legal papers in order |
170 for us to have clear title to the program; the main author alone is not | |
169 enough. | 171 enough. |
170 | 172 |
171 So, before adding in any contributions from other people, tell us | 173 So, before adding in any contributions from other people, please tell |
172 so we can arrange to get the papers. Then wait until we tell you | 174 us, so we can arrange to get the papers. Then wait until we tell you |
173 that we have received the signed papers, before you actually use the | 175 that we have received the signed papers, before you actually use the |
174 contribution. | 176 contribution. |
175 | 177 |
176 This applies both before you release the program and afterward. If | 178 This applies both before you release the program and afterward. If |
177 you receive diffs to fix a bug, and they make significant changes, we | 179 you receive diffs to fix a bug, and they make significant changes, we |
178 need legal papers for it. | 180 need legal papers for that change. |
181 | |
182 This also applies to comments and documentation files. For copyright | |
183 law, comments and code are just text. Copyright applies to all kinds of | |
184 text, so we need legal papers for all kinds. | |
185 | |
186 We know it is frustrating to ask for legal papers; it's frustrating for | |
187 us as well. But if you don't wait, you are going out on a limb---for | |
188 example, what if the contributor's employer won't sign a disclaimer? | |
189 You might have to take that code out again! | |
179 | 190 |
180 You don't need papers for changes of a few lines here or there, since | 191 You don't need papers for changes of a few lines here or there, since |
181 they are not significant for copyright purposes. Also, you don't need | 192 they are not significant for copyright purposes. Also, you don't need |
182 papers if all you get from the suggestion is some ideas, not actual code | 193 papers if all you get from the suggestion is some ideas, not actual code |
183 which you use. For example, if you write a different solution to the | 194 which you use. For example, if someone send you one implementation, but |
184 problem, you don't need to get papers. | 195 you write a different implementation of the same idea, you don't need to |
185 | 196 get papers. |
186 We know this is frustrating; it's frustrating for us as well. But if | |
187 you don't wait, you are going out on a limb---for example, what if the | |
188 contributor's employer won't sign a disclaimer? You might have to take | |
189 that code out again! | |
190 | 197 |
191 The very worst thing is if you forget to tell us about the other | 198 The very worst thing is if you forget to tell us about the other |
192 contributor. We could be very embarrassed in court some day as a | 199 contributor. We could be very embarrassed in court some day as a |
193 result. | 200 result. |
194 | 201 |
202 We have more detailed advice for maintainers of programs; if you have | |
203 reached the stage of actually maintaining a program for GNU (whether | |
204 released or not), please ask us for a copy. | |
205 | |
195 @node Design Advice | 206 @node Design Advice |
196 @chapter General Program Design | 207 @chapter General Program Design |
197 | 208 |
198 This @value{CHAPTER} discusses some of the issues you should take into | 209 This @value{CHAPTER} discusses some of the issues you should take into |
199 account when designing your program. | 210 account when designing your program. |
200 | 211 |
201 @menu | 212 @menu |
202 * Compatibility:: Compatibility with other implementations | 213 * Compatibility:: Compatibility with other implementations |
203 * Using Extensions:: Using non-standard features | 214 * Using Extensions:: Using non-standard features |
204 * ANSI C:: Using ANSI C features | 215 * ANSI C:: Using ANSI C features |
205 * Source Language:: Using languages other than C | 216 * Source Language:: Using languages other than C |
206 @end menu | 217 @end menu |
207 | 218 |
208 @node Compatibility | 219 @node Compatibility |
209 @section Compatibility with Other Implementations | 220 @section Compatibility with Other Implementations |
210 | 221 |
211 With occasional exceptions, utility programs and libraries for GNU | 222 With occasional exceptions, utility programs and libraries for GNU |
212 should be upward compatible with those in Berkeley Unix, and upward | 223 should be upward compatible with those in Berkeley Unix, and upward |
213 compatible with @sc{ansi} C if @sc{ansi} C specifies their behavior, and | 224 compatible with @sc{ansi} C if @sc{ansi} C specifies their behavior, and |
214 upward compatible with @sc{POSIX} if @sc{POSIX} specifies their | 225 upward compatible with @sc{posix} if @sc{posix} specifies their |
215 behavior. | 226 behavior. |
216 | 227 |
217 When these standards conflict, it is useful to offer compatibility | 228 When these standards conflict, it is useful to offer compatibility |
218 modes for each of them. | 229 modes for each of them. |
219 | 230 |
220 @sc{ansi} C and @sc{POSIX} prohibit many kinds of extensions. Feel free | 231 @sc{ansi} C and @sc{posix} prohibit many kinds of extensions. Feel free |
221 to make the extensions anyway, and include a @samp{--ansi}, | 232 to make the extensions anyway, and include a @samp{--ansi}, |
222 @samp{--posix}, or @samp{--compatible} option to turn them off. | 233 @samp{--posix}, or @samp{--compatible} option to turn them off. |
223 However, if the extension has a significant chance of breaking any real | 234 However, if the extension has a significant chance of breaking any real |
224 programs or scripts, then it is not really upward compatible. Try to | 235 programs or scripts, then it is not really upward compatible. Try to |
225 redesign its interface. | 236 redesign its interface. |
226 | 237 |
227 Many GNU programs suppress extensions that conflict with POSIX if the | 238 Many GNU programs suppress extensions that conflict with @sc{posix} if the |
228 environment variable @code{POSIXLY_CORRECT} is defined (even if it is | 239 environment variable @code{POSIXLY_CORRECT} is defined (even if it is |
229 defined with a null value). Please make your program recognize this | 240 defined with a null value). Please make your program recognize this |
230 variable if appropriate. | 241 variable if appropriate. |
231 | 242 |
232 When a feature is used only by users (not by programs or command | 243 When a feature is used only by users (not by programs or command |
234 completely with something totally different and better. (For example, | 245 completely with something totally different and better. (For example, |
235 @code{vi} is replaced with Emacs.) But it is nice to offer a compatible | 246 @code{vi} is replaced with Emacs.) But it is nice to offer a compatible |
236 feature as well. (There is a free @code{vi} clone, so we offer it.) | 247 feature as well. (There is a free @code{vi} clone, so we offer it.) |
237 | 248 |
238 Additional useful features not in Berkeley Unix are welcome. | 249 Additional useful features not in Berkeley Unix are welcome. |
239 Additional programs with no counterpart in Unix may be useful, | |
240 but our first priority is usually to duplicate what Unix already | |
241 has. | |
242 | 250 |
243 @node Using Extensions | 251 @node Using Extensions |
244 @section Using Non-standard Features | 252 @section Using Non-standard Features |
245 | 253 |
246 Many GNU facilities that already exist support a number of convenient | 254 Many GNU facilities that already exist support a number of convenient |
280 that use @sc{ansi} C features (and therefore will not work in | 288 that use @sc{ansi} C features (and therefore will not work in |
281 non-@sc{ansi} compilers). And if a program is already written in | 289 non-@sc{ansi} compilers). And if a program is already written in |
282 @sc{ansi} C, there's no need to convert it to support non-@sc{ansi} | 290 @sc{ansi} C, there's no need to convert it to support non-@sc{ansi} |
283 compilers. | 291 compilers. |
284 | 292 |
293 If you don't know non-@sc{ansi} C, there's no need to learn it; just | |
294 write in @sc{ansi} C. | |
295 | |
285 However, it is easy to support non-@sc{ansi} compilers in most programs, | 296 However, it is easy to support non-@sc{ansi} compilers in most programs, |
286 so you might still consider doing so when you write a program. Instead | 297 so you might still consider doing so when you write a program. And if a |
287 of writing function definitions in @sc{ansi} prototype form, | 298 program you are maintaining has such support, you should try to keep it |
299 working. | |
300 | |
301 To support pre-@sc{ansi} C, instead of writing function definitions in | |
302 @sc{ansi} prototype form, | |
288 | 303 |
289 @example | 304 @example |
290 int | 305 int |
291 foo (int x, int y) | 306 foo (int x, int y) |
292 @dots{} | 307 @dots{} |
309 int foo (int, int); | 324 int foo (int, int); |
310 @end example | 325 @end example |
311 | 326 |
312 You need such a declaration anyway, in a header file, to get the benefit | 327 You need such a declaration anyway, in a header file, to get the benefit |
313 of @sc{ansi} C prototypes in all the files where the function is called. | 328 of @sc{ansi} C prototypes in all the files where the function is called. |
314 And once you have it, you lose nothing by writing the function | 329 And once you have the declaration, you normally lose nothing by writing |
315 definition in the pre-@sc{ansi} style. | 330 the function definition in the pre-@sc{ansi} style. |
316 | 331 |
317 If you don't know non-@sc{ansi} C, there's no need to learn it; just | 332 This technique does not work for integer types narrower than @code{int}. |
318 write in @sc{ansi} C. | 333 If you think of an argument as being of a type narrower than @code{int}, |
334 declare it as @code{int} instead. | |
335 | |
336 There are a few special cases where this technique is hard to use. For | |
337 example, if a function argument needs to hold the system type | |
338 @code{dev_t}, you run into trouble, because @code{dev_t} is shorter than | |
339 @code{int} on some machines; but you cannot use @code{int} instead, | |
340 because @code{dev_t} is wider than @code{int} on some machines. There | |
341 is no type you can safely use on all machines in a non-@sc{ansi} | |
342 definition. The only way to support non-@sc{ansi} C and pass such an | |
343 argument is to check the width of @code{dev_t} using Autoconf and choose | |
344 the argument type accordingly. This may not be worth the trouble. | |
319 | 345 |
320 @node Source Language | 346 @node Source Language |
321 @section Using Languages Other Than C | 347 @section Using Languages Other Than C |
322 | 348 |
323 Using a language other than C is like using a non-standard feature: it | 349 Using a language other than C is like using a non-standard feature: it |
324 will cause trouble for users. Even if GCC supports the other language, | 350 will cause trouble for users. Even if GCC supports the other language, |
325 users may find it inconvenient to have to install the compiler for that | 351 users may find it inconvenient to have to install the compiler for that |
326 other language in order to build your program. So please write in C. | 352 other language in order to build your program. For example, if you |
327 | 353 write your program in C++, people will have to install the C++ compiler |
328 There are three exceptions for this rule: | 354 in order to compile your program. Thus, it is better if you write in C. |
355 | |
356 But there are three situations when there is no disadvantage in using | |
357 some other language: | |
329 | 358 |
330 @itemize @bullet | 359 @itemize @bullet |
331 @item | 360 @item |
332 It is okay to use a special language if the same program contains an | 361 It is okay to use another language if your program contains an |
333 interpreter for that language. | 362 interpreter for that language. |
334 | 363 |
335 For example, if your program links with GUILE, it is ok to write part of | 364 For example, if your program links with GUILE, it is ok to write part of |
336 the program in Scheme or another language supported by GUILE. | 365 the program in Scheme or another language supported by GUILE. |
337 | 366 |
341 | 370 |
342 This is okay because the only people who want to build the tool will be | 371 This is okay because the only people who want to build the tool will be |
343 those who have installed the other language anyway. | 372 those who have installed the other language anyway. |
344 | 373 |
345 @item | 374 @item |
346 If an application is not of extremely widespread interest, then perhaps | 375 If an application is of interest to a narrow community, then perhaps |
347 it's not important if the application is inconvenient to install. | 376 it's not important if the application is inconvenient to install. |
348 @end itemize | 377 @end itemize |
378 | |
379 C has one other advantage over C++ and other compiled languages: more | |
380 people know C, so more people will find it easy to read and modify the | |
381 program if it is written in C. | |
349 | 382 |
350 @node Program Behavior | 383 @node Program Behavior |
351 @chapter Program Behavior for All Programs | 384 @chapter Program Behavior for All Programs |
352 | 385 |
353 This @value{CHAPTER} describes how to write robust software. It also | 386 This @value{CHAPTER} describes how to write robust software. It also |
354 describes general standards for error messages, the command line interface, | 387 describes general standards for error messages, the command line interface, |
355 and how libraries should behave. | 388 and how libraries should behave. |
356 | 389 |
357 @menu | 390 @menu |
358 * Semantics:: Writing robust programs | 391 * Semantics:: Writing robust programs |
359 * Libraries:: Library behavior | 392 * Libraries:: Library behavior |
360 * Errors:: Formatting error messages | 393 * Errors:: Formatting error messages |
361 * User Interfaces:: Standards for command line interfaces | 394 * User Interfaces:: Standards for command line interfaces |
395 * Option Table:: Table of long options. | |
362 * Memory Usage:: When and how to care about memory needs | 396 * Memory Usage:: When and how to care about memory needs |
363 @end menu | 397 @end menu |
364 | 398 |
365 @node Semantics | 399 @node Semantics |
366 @section Writing Robust Programs | 400 @section Writing Robust Programs |
369 structure, including file names, lines, files, and symbols, by allocating | 403 structure, including file names, lines, files, and symbols, by allocating |
370 all data structures dynamically. In most Unix utilities, ``long lines | 404 all data structures dynamically. In most Unix utilities, ``long lines |
371 are silently truncated''. This is not acceptable in a GNU utility. | 405 are silently truncated''. This is not acceptable in a GNU utility. |
372 | 406 |
373 Utilities reading files should not drop NUL characters, or any other | 407 Utilities reading files should not drop NUL characters, or any other |
374 nonprinting characters @emph{including those with codes above 0177}. The | 408 nonprinting characters @emph{including those with codes above 0177}. |
375 only sensible exceptions would be utilities specifically intended for | 409 The only sensible exceptions would be utilities specifically intended |
376 interface to certain types of printers that can't handle those characters. | 410 for interface to certain types of terminals or printers |
411 that can't handle those characters. | |
412 Whenever possible, try to make programs work properly with | |
413 sequences of bytes that represent multibyte characters, using encodings | |
414 such as UTF-8 and others. | |
377 | 415 |
378 Check every system call for an error return, unless you know you wish to | 416 Check every system call for an error return, unless you know you wish to |
379 ignore errors. Include the system error text (from @code{perror} or | 417 ignore errors. Include the system error text (from @code{perror} or |
380 equivalent) in @emph{every} error message resulting from a failing | 418 equivalent) in @emph{every} error message resulting from a failing |
381 system call, as well as the name of the file if any and the name of the | 419 system call, as well as the name of the file if any and the name of the |
413 | 451 |
414 Try to avoid low-level interfaces to obscure Unix data structures (such | 452 Try to avoid low-level interfaces to obscure Unix data structures (such |
415 as file directories, utmp, or the layout of kernel memory), since these | 453 as file directories, utmp, or the layout of kernel memory), since these |
416 are less likely to work compatibly. If you need to find all the files | 454 are less likely to work compatibly. If you need to find all the files |
417 in a directory, use @code{readdir} or some other high-level interface. | 455 in a directory, use @code{readdir} or some other high-level interface. |
418 These will be supported compatibly by GNU. | 456 These are supported compatibly by GNU. |
419 | 457 |
420 By default, the GNU system will provide the signal handling functions of | 458 The preferred signal handling facilities are the BSD variant of |
421 @sc{BSD} and of @sc{POSIX}. So GNU software should be written to use | 459 @code{signal}, and the @sc{posix} @code{sigaction} function; the |
422 these. | 460 alternative USG @code{signal} interface is an inferior design. |
461 | |
462 Nowadays, using the @sc{posix} signal functions may be the easiest way | |
463 to make a program portable. If you use @code{signal}, then on GNU/Linux | |
464 systems running GNU libc version 1, you should include | |
465 @file{bsd/signal.h} instead of @file{signal.h}, so as to get BSD | |
466 behavior. It is up to you whether to support systems where | |
467 @code{signal} has only the USG behavior, or give up on them. | |
423 | 468 |
424 In error checks that detect ``impossible'' conditions, just abort. | 469 In error checks that detect ``impossible'' conditions, just abort. |
425 There is usually no point in printing any message. These checks | 470 There is usually no point in printing any message. These checks |
426 indicate the existence of bugs. Whoever wants to fix the bugs will have | 471 indicate the existence of bugs. Whoever wants to fix the bugs will have |
427 to read the source code and run a debugger. So explain the problem with | 472 to read the source code and run a debugger. So explain the problem with |
475 | 520 |
476 @example | 521 @example |
477 @var{source-file-name}:@var{lineno}: @var{message} | 522 @var{source-file-name}:@var{lineno}: @var{message} |
478 @end example | 523 @end example |
479 | 524 |
525 @noindent | |
526 If you want to mention the column number, use this format: | |
527 | |
528 @example | |
529 @var{source-file-name}:@var{lineno}:@var{column}: @var{message} | |
530 @end example | |
531 | |
532 @noindent | |
533 Line numbers should start from 1 at the beginning of the file, and | |
534 column numbers should start from 1 at the beginning of the line. (Both | |
535 of these conventions are chosen for compatibility.) Calculate column | |
536 numbers assuming that space and all ASCII printing characters have | |
537 equal width, and assuming tab stops every 8 columns. | |
538 | |
480 Error messages from other noninteractive programs should look like this: | 539 Error messages from other noninteractive programs should look like this: |
481 | 540 |
482 @example | 541 @example |
483 @var{program}:@var{source-file-name}:@var{lineno}: @var{message} | 542 @var{program}:@var{source-file-name}:@var{lineno}: @var{message} |
484 @end example | 543 @end example |
490 @var{program}: @var{message} | 549 @var{program}: @var{message} |
491 @end example | 550 @end example |
492 | 551 |
493 @noindent | 552 @noindent |
494 when there is no relevant source file. | 553 when there is no relevant source file. |
554 | |
555 If you want to mention the column number, use this format: | |
556 | |
557 @example | |
558 @var{program}:@var{source-file-name}:@var{lineno}:@var{column}: @var{message} | |
559 @end example | |
495 | 560 |
496 In an interactive program (one that is reading commands from a | 561 In an interactive program (one that is reading commands from a |
497 terminal), it is better not to include the program name in an error | 562 terminal), it is better not to include the program name in an error |
498 message. The place to indicate which program is running is in the | 563 message. The place to indicate which program is running is in the |
499 prompt or with the screen layout. (When the same program runs with | 564 prompt or with the screen layout. (When the same program runs with |
518 Instead, use a run time option or a compilation switch or both | 583 Instead, use a run time option or a compilation switch or both |
519 to select among the alternate behaviors. | 584 to select among the alternate behaviors. |
520 | 585 |
521 Likewise, please don't make the behavior of the program depend on the | 586 Likewise, please don't make the behavior of the program depend on the |
522 type of output device it is used with. Device independence is an | 587 type of output device it is used with. Device independence is an |
523 important principle of the system's design; do not compromise it | 588 important principle of the system's design; do not compromise it merely |
524 merely to save someone from typing an option now and then. | 589 to save someone from typing an option now and then. (Variation in error |
590 message syntax when using a terminal is ok, because that is a side issue | |
591 that people do not depend on.) | |
525 | 592 |
526 If you think one behavior is most useful when the output is to a | 593 If you think one behavior is most useful when the output is to a |
527 terminal, and another is most useful when the output is a file or a | 594 terminal, and another is most useful when the output is a file or a |
528 pipe, then it is usually best to make the default behavior the one that | 595 pipe, then it is usually best to make the default behavior the one that |
529 is useful with output to a terminal, and have an option for the other | 596 is useful with output to a terminal, and have an option for the other |
535 program with a preferred alternate version that does not depend on the | 602 program with a preferred alternate version that does not depend on the |
536 output device type. For example, we provide a @code{dir} program much | 603 output device type. For example, we provide a @code{dir} program much |
537 like @code{ls} except that its default output format is always | 604 like @code{ls} except that its default output format is always |
538 multi-column format. | 605 multi-column format. |
539 | 606 |
540 It is a good idea to follow the @sc{POSIX} guidelines for the | 607 It is a good idea to follow the @sc{posix} guidelines for the |
541 command-line options of a program. The easiest way to do this is to use | 608 command-line options of a program. The easiest way to do this is to use |
542 @code{getopt} to parse them. Note that the GNU version of @code{getopt} | 609 @code{getopt} to parse them. Note that the GNU version of @code{getopt} |
543 will normally permit options anywhere among the arguments unless the | 610 will normally permit options anywhere among the arguments unless the |
544 special argument @samp{--} is used. This is not what @sc{POSIX} | 611 special argument @samp{--} is used. This is not what @sc{posix} |
545 specifies; it is a GNU extension. | 612 specifies; it is a GNU extension. |
546 | 613 |
547 Please define long-named options that are equivalent to the | 614 Please define long-named options that are equivalent to the |
548 single-letter Unix-style options. We hope to make GNU more user | 615 single-letter Unix-style options. We hope to make GNU more user |
549 friendly this way. This is easy to do with the GNU function | 616 friendly this way. This is easy to do with the GNU function |
552 One of the advantages of long-named options is that they can be | 619 One of the advantages of long-named options is that they can be |
553 consistent from program to program. For example, users should be able | 620 consistent from program to program. For example, users should be able |
554 to expect the ``verbose'' option of any GNU program which has one, to be | 621 to expect the ``verbose'' option of any GNU program which has one, to be |
555 spelled precisely @samp{--verbose}. To achieve this uniformity, look at | 622 spelled precisely @samp{--verbose}. To achieve this uniformity, look at |
556 the table of common long-option names when you choose the option names | 623 the table of common long-option names when you choose the option names |
557 for your program. The table appears below. | 624 for your program (@pxref{Option Table}). |
558 | 625 |
559 If you use names not already in the table, please send | 626 It is usually a good idea for file names given as ordinary arguments to |
560 @samp{gnu@@prep.ai.mit.edu} a list of them, with their meanings, so we | 627 be input files only; any output files would be specified using options |
561 can update the table. | 628 (preferably @samp{-o} or @samp{--output}). Even if you allow an output |
562 | 629 file name as an ordinary argument for compatibility, try to provide an |
563 It is usually a good idea for file names given as ordinary arguments | 630 option as another way to specify it. This will lead to more consistency |
564 to be input files only; any output files would be specified using | 631 among GNU utilities, and fewer idiosyncracies for users to remember. |
565 options (preferably @samp{-o}). Even if you allow an output file name | 632 |
566 as an ordinary argument for compatibility, try to provide a suitable | 633 All programs should support two standard options: @samp{--version} |
567 option as well. This will lead to more consistency among GNU | 634 and @samp{--help}. |
568 utilities, so that there are fewer idiosyncracies for users to | 635 |
569 remember. | 636 @table @code |
570 | 637 @item --version |
571 Programs should support an option @samp{--version} which prints the | 638 This option should direct the program to print information about its name, |
572 program's version number on standard output and exits successfully, and | 639 version, origin and legal status, all on standard output, and then exit |
573 an option @samp{--help} which prints option usage information on | 640 successfully. Other options and arguments should be ignored once this |
574 standard output and exits successfully. These options should inhibit | 641 is seen, and the program should not perform its normal function. |
575 the normal function of the command; they should do nothing except print | 642 |
576 the requested information. | 643 The first line is meant to be easy for a program to parse; the version |
644 number proper starts after the last space. In addition, it contains | |
645 the canonical name for this program, in this format: | |
646 | |
647 @example | |
648 GNU Emacs 19.30 | |
649 @end example | |
650 | |
651 @noindent | |
652 The program's name should be a constant string; @emph{don't} compute it | |
653 from @code{argv[0]}. The idea is to state the standard or canonical | |
654 name for the program, not its file name. There are other ways to find | |
655 out the precise file name where a command is found in @code{PATH}. | |
656 | |
657 If the program is a subsidiary part of a larger package, mention the | |
658 package name in parentheses, like this: | |
659 | |
660 @example | |
661 emacsserver (GNU Emacs) 19.30 | |
662 @end example | |
663 | |
664 @noindent | |
665 If the package has a version number which is different from this | |
666 program's version number, you can mention the package version number | |
667 just before the close-parenthesis. | |
668 | |
669 If you @strong{need} to mention the version numbers of libraries which | |
670 are distributed separately from the package which contains this program, | |
671 you can do so by printing an additional line of version info for each | |
672 library you want to mention. Use the same format for these lines as for | |
673 the first line. | |
674 | |
675 Please do not mention all of the libraries that the program uses ``just | |
676 for completeness''---that would produce a lot of unhelpful clutter. | |
677 Please mention library version numbers only if you find in practice that | |
678 they are very important to you in debugging. | |
679 | |
680 The following line, after the version number line or lines, should be a | |
681 copyright notice. If more than one copyright notice is called for, put | |
682 each on a separate line. | |
683 | |
684 Next should follow a brief statement that the program is free software, | |
685 and that users are free to copy and change it on certain conditions. If | |
686 the program is covered by the GNU GPL, say so here. Also mention that | |
687 there is no warranty, to the extent permitted by law. | |
688 | |
689 It is ok to finish the output with a list of the major authors of the | |
690 program, as a way of giving credit. | |
691 | |
692 Here's an example of output that follows these rules: | |
693 | |
694 @smallexample | |
695 GNU Emacs 19.34.5 | |
696 Copyright (C) 1996 Free Software Foundation, Inc. | |
697 GNU Emacs comes with NO WARRANTY, | |
698 to the extent permitted by law. | |
699 You may redistribute copies of GNU Emacs | |
700 under the terms of the GNU General Public License. | |
701 For more information about these matters, | |
702 see the files named COPYING. | |
703 @end smallexample | |
704 | |
705 You should adapt this to your program, of course, filling in the proper | |
706 year, copyright holder, name of program, and the references to | |
707 distribution terms, and changing the rest of the wording as necessary. | |
708 | |
709 This copyright notice only needs to mention the most recent year in | |
710 which changes were made---there's no need to list the years for previous | |
711 versions' changes. You don't have to mention the name of the program in | |
712 these notices, if that is inconvenient, since it appeared in the first | |
713 line. | |
714 | |
715 @item --help | |
716 This option should output brief documentation for how to invoke the | |
717 program, on standard output, then exit successfully. Other options and | |
718 arguments should be ignored once this is seen, and the program should | |
719 not perform its normal function. | |
720 | |
721 Near the end of the @samp{--help} option's output there should be a line | |
722 that says where to mail bug reports. It should have this format: | |
723 | |
724 @example | |
725 Report bugs to @var{mailing-address}. | |
726 @end example | |
727 @end table | |
728 | |
729 @node Option Table | |
730 @section Table of Long Options | |
731 | |
732 Here is a table of long options used by GNU programs. It is surely | |
733 incomplete, but we aim to list all the options that a new program might | |
734 want to be compatible with. If you use names not already in the table, | |
735 please send @email{gnu@@gnu.org} a list of them, with their | |
736 meanings, so we can update the table. | |
577 | 737 |
578 @c Please leave newlines between items in this table; it's much easier | 738 @c Please leave newlines between items in this table; it's much easier |
579 @c to update when it isn't completely squashed together and unreadable. | 739 @c to update when it isn't completely squashed together and unreadable. |
580 @c When there is more than one short option for a long option name, put | 740 @c When there is more than one short option for a long option name, put |
581 @c a semicolon between the lists of the programs that use them, not a | 741 @c a semicolon between the lists of the programs that use them, not a |
582 @c period. --friedman | 742 @c period. --friedman |
583 | 743 |
584 Here is the table of long options used by GNU programs. | |
585 | |
586 @table @samp | 744 @table @samp |
587 | |
588 @item after-date | 745 @item after-date |
589 @samp{-N} in @code{tar}. | 746 @samp{-N} in @code{tar}. |
590 | 747 |
591 @item all | 748 @item all |
592 @samp{-a} in @code{du}, @code{ls}, @code{nm}, @code{stty}, @code{uname}, | 749 @samp{-a} in @code{du}, @code{ls}, @code{nm}, @code{stty}, @code{uname}, |
633 @samp{-A} in @code{ptx}. | 790 @samp{-A} in @code{ptx}. |
634 | 791 |
635 @item avoid-wraps | 792 @item avoid-wraps |
636 @samp{-n} in @code{wdiff}. | 793 @samp{-n} in @code{wdiff}. |
637 | 794 |
795 @item background | |
796 For server programs, run in the background. | |
797 | |
638 @item backward-search | 798 @item backward-search |
639 @samp{-B} in @code{ctags}. | 799 @samp{-B} in @code{ctags}. |
640 | 800 |
641 @item basename | 801 @item basename |
642 @samp{-f} in @code{shar}. | 802 @samp{-f} in @code{shar}. |
756 @samp{-L} in @code{chgrp}, @code{chown}, @code{cpio}, @code{du}, | 916 @samp{-L} in @code{chgrp}, @code{chown}, @code{cpio}, @code{du}, |
757 @code{ls}, and @code{tar}. | 917 @code{ls}, and @code{tar}. |
758 | 918 |
759 @item dereference-args | 919 @item dereference-args |
760 @samp{-D} in @code{du}. | 920 @samp{-D} in @code{du}. |
921 | |
922 @item device | |
923 Specify an I/O device (special file name). | |
761 | 924 |
762 @item diacritics | 925 @item diacritics |
763 @samp{-d} in @code{recode}. | 926 @samp{-d} in @code{recode}. |
764 | 927 |
765 @item dictionary-order | 928 @item dictionary-order |
889 @samp{-f} in @code{cp}, @code{ln}, @code{mv}, and @code{rm}. | 1052 @samp{-f} in @code{cp}, @code{ln}, @code{mv}, and @code{rm}. |
890 | 1053 |
891 @item force-prefix | 1054 @item force-prefix |
892 @samp{-F} in @code{shar}. | 1055 @samp{-F} in @code{shar}. |
893 | 1056 |
1057 @item foreground | |
1058 For server programs, run in the foreground; | |
1059 in other words, don't do anything special to run the server | |
1060 in the background. | |
1061 | |
894 @item format | 1062 @item format |
895 Used in @code{ls}, @code{time}, and @code{ptx}. | 1063 Used in @code{ls}, @code{time}, and @code{ptx}. |
896 | 1064 |
897 @item freeze-state | 1065 @item freeze-state |
898 @samp{-F} in @code{m4}. | 1066 @samp{-F} in @code{m4}. |
1068 Used in @code{su}. | 1236 Used in @code{su}. |
1069 | 1237 |
1070 @item machine | 1238 @item machine |
1071 No listing of which programs already use this; | 1239 No listing of which programs already use this; |
1072 someone should check to | 1240 someone should check to |
1073 see if any actually do and tell @code{gnu@@prep.ai.mit.edu}. | 1241 see if any actually do, and tell @email{gnu@@gnu.org}. |
1074 | 1242 |
1075 @item macro-name | 1243 @item macro-name |
1076 @samp{-M} in @code{ptx}. | 1244 @samp{-M} in @code{ptx}. |
1077 | 1245 |
1078 @item mail | 1246 @item mail |
1193 @samp{-m} in @code{shar}. | 1361 @samp{-m} in @code{shar}. |
1194 | 1362 |
1195 @item no-validate | 1363 @item no-validate |
1196 Used in @code{makeinfo}. | 1364 Used in @code{makeinfo}. |
1197 | 1365 |
1366 @item no-wait | |
1367 Used in @code{emacsclient}. | |
1368 | |
1198 @item no-warn | 1369 @item no-warn |
1199 Used in various programs to inhibit warnings. | 1370 Used in various programs to inhibit warnings. |
1200 | 1371 |
1201 @item node | 1372 @item node |
1202 @samp{-n} in @code{info}. | 1373 @samp{-n} in @code{info}. |
1244 @samp{-f} in @code{gprof}. | 1415 @samp{-f} in @code{gprof}. |
1245 | 1416 |
1246 @item only-time | 1417 @item only-time |
1247 @samp{-F} in @code{gprof}. | 1418 @samp{-F} in @code{gprof}. |
1248 | 1419 |
1420 @item options | |
1421 @samp{-o} in @code{getopt}, @code{fdlist}, @code{fdmount}, | |
1422 @code{fdmountd}, and @code{fdumount}. | |
1423 | |
1249 @item output | 1424 @item output |
1250 In various programs, specify the output file name. | 1425 In various programs, specify the output file name. |
1251 | 1426 |
1252 @item output-prefix | 1427 @item output-prefix |
1253 @samp{-o} in @code{shar}. | 1428 @samp{-o} in @code{shar}. |
1328 @samp{-p} in @code{wdiff}. | 1503 @samp{-p} in @code{wdiff}. |
1329 | 1504 |
1330 @item prompt | 1505 @item prompt |
1331 @samp{-p} in @code{ed}. | 1506 @samp{-p} in @code{ed}. |
1332 | 1507 |
1508 @item proxy | |
1509 Specify an HTTP proxy. | |
1510 | |
1333 @item query-user | 1511 @item query-user |
1334 @samp{-X} in @code{shar}. | 1512 @samp{-X} in @code{shar}. |
1335 | 1513 |
1336 @item question | 1514 @item question |
1337 @samp{-q} in Make. | 1515 @samp{-q} in Make. |
1338 | 1516 |
1339 @item quiet | 1517 @item quiet |
1340 Used in many programs to inhibit the usual output. @strong{Please | 1518 Used in many programs to inhibit the usual output. @strong{Note:} every |
1341 note:} every program accepting @samp{--quiet} should accept | 1519 program accepting @samp{--quiet} should accept @samp{--silent} as a |
1342 @samp{--silent} as a synonym. | 1520 synonym. |
1343 | 1521 |
1344 @item quiet-unshar | 1522 @item quiet-unshar |
1345 @samp{-Q} in @code{shar} | 1523 @samp{-Q} in @code{shar} |
1346 | 1524 |
1347 @item quote-name | 1525 @item quote-name |
1450 @item show-tabs | 1628 @item show-tabs |
1451 @samp{-T} in @code{cat}. | 1629 @samp{-T} in @code{cat}. |
1452 | 1630 |
1453 @item silent | 1631 @item silent |
1454 Used in many programs to inhibit the usual output. | 1632 Used in many programs to inhibit the usual output. |
1455 @strong{Please note:} every program accepting | 1633 @strong{Note:} every program accepting |
1456 @samp{--silent} should accept @samp{--quiet} as a synonym. | 1634 @samp{--silent} should accept @samp{--quiet} as a synonym. |
1457 | 1635 |
1458 @item size | 1636 @item size |
1459 @samp{-s} in @code{ls}. | 1637 @samp{-s} in @code{ls}. |
1638 | |
1639 @item socket | |
1640 Specify a file descriptor for a network server to use for its socket, | |
1641 instead of opening and binding a new socket. This provides a way to | |
1642 run, in a nonpriveledged process, a server that normally needs a | |
1643 reserved port number. | |
1460 | 1644 |
1461 @item sort | 1645 @item sort |
1462 Used in @code{ls}. | 1646 Used in @code{ls}. |
1463 | 1647 |
1464 @item source | 1648 @item source |
1553 @item text-files | 1737 @item text-files |
1554 @samp{-T} in @code{shar}. | 1738 @samp{-T} in @code{shar}. |
1555 | 1739 |
1556 @item time | 1740 @item time |
1557 Used in @code{ls} and @code{touch}. | 1741 Used in @code{ls} and @code{touch}. |
1742 | |
1743 @item timeout | |
1744 Specify how long to wait before giving up on some operation. | |
1558 | 1745 |
1559 @item to-stdout | 1746 @item to-stdout |
1560 @samp{-O} in @code{tar}. | 1747 @samp{-O} in @code{tar}. |
1561 | 1748 |
1562 @item total | 1749 @item total |
1670 | 1857 |
1671 This @value{CHAPTER} provides advice on how best to use the C language | 1858 This @value{CHAPTER} provides advice on how best to use the C language |
1672 when writing GNU software. | 1859 when writing GNU software. |
1673 | 1860 |
1674 @menu | 1861 @menu |
1675 * Formatting:: Formatting Your Source Code | 1862 * Formatting:: Formatting Your Source Code |
1676 * Comments:: Commenting Your Work | 1863 * Comments:: Commenting Your Work |
1677 * Syntactic Conventions:: Clean Use of C Constructs | 1864 * Syntactic Conventions:: Clean Use of C Constructs |
1678 * Names:: Naming Variables and Functions | 1865 * Names:: Naming Variables and Functions |
1679 * System Portability:: Portability between different operating systems | 1866 * System Portability:: Portability between different operating systems |
1680 * CPU Portability:: Supporting the range of CPU types | 1867 * CPU Portability:: Supporting the range of CPU types |
1681 * System Functions:: Portability and ``standard'' library functions | 1868 * System Functions:: Portability and ``standard'' library functions |
1682 * Internationalization:: Techniques for internationalization | 1869 * Internationalization:: Techniques for internationalization |
1870 * Mmap:: How you can safely use @code{mmap}. | |
1683 @end menu | 1871 @end menu |
1684 | 1872 |
1685 @node Formatting | 1873 @node Formatting |
1686 @section Formatting Your Source Code | 1874 @section Formatting Your Source Code |
1687 | 1875 |
1806 @section Commenting Your Work | 1994 @section Commenting Your Work |
1807 | 1995 |
1808 Every program should start with a comment saying briefly what it is for. | 1996 Every program should start with a comment saying briefly what it is for. |
1809 Example: @samp{fmt - filter for simple filling of text}. | 1997 Example: @samp{fmt - filter for simple filling of text}. |
1810 | 1998 |
1999 Please write the comments in a GNU program in English, because English | |
2000 is the one language that nearly all programmers in all countries can | |
2001 read. If you do not write English well, please write comments in | |
2002 English as well as you can, then ask other people to help rewrite them. | |
2003 If you can't write comments in English, please find someone to work with | |
2004 you and translate your comments into English. | |
2005 | |
1811 Please put a comment on each function saying what the function does, | 2006 Please put a comment on each function saying what the function does, |
1812 what sorts of arguments it gets, and what the possible values of | 2007 what sorts of arguments it gets, and what the possible values of |
1813 arguments mean and are used for. It is not necessary to duplicate in | 2008 arguments mean and are used for. It is not necessary to duplicate in |
1814 words the meaning of the C argument declarations, if a C type is being | 2009 words the meaning of the C argument declarations, if a C type is being |
1815 used in its customary fashion. If there is anything nonstandard about | 2010 used in its customary fashion. If there is anything nonstandard about |
1860 @dots{} | 2055 @dots{} |
1861 #else /* not foo */ | 2056 #else /* not foo */ |
1862 @dots{} | 2057 @dots{} |
1863 #endif /* not foo */ | 2058 #endif /* not foo */ |
1864 @end group | 2059 @end group |
2060 @group | |
2061 #ifdef foo | |
2062 @dots{} | |
2063 #endif /* foo */ | |
2064 @end group | |
1865 @end example | 2065 @end example |
1866 | 2066 |
1867 @noindent | 2067 @noindent |
1868 but, by contrast, write the comments this way for a @samp{#ifndef}: | 2068 but, by contrast, write the comments this way for a @samp{#ifndef}: |
1869 | 2069 |
1873 @dots{} | 2073 @dots{} |
1874 #else /* foo */ | 2074 #else /* foo */ |
1875 @dots{} | 2075 @dots{} |
1876 #endif /* foo */ | 2076 #endif /* foo */ |
1877 @end group | 2077 @end group |
1878 @end example | 2078 @group |
1879 | 2079 #ifndef foo |
2080 @dots{} | |
2081 #endif /* not foo */ | |
2082 @end group | |
2083 @end example | |
1880 | 2084 |
1881 @node Syntactic Conventions | 2085 @node Syntactic Conventions |
1882 @section Clean Use of C Constructs | 2086 @section Clean Use of C Constructs |
1883 | 2087 |
1884 Please explicitly declare all arguments to functions. | 2088 Please explicitly declare all arguments to functions. |
2003 | 2207 |
2004 Don't make the program ugly to placate @code{lint}. Please don't insert any | 2208 Don't make the program ugly to placate @code{lint}. Please don't insert any |
2005 casts to @code{void}. Zero without a cast is perfectly fine as a null | 2209 casts to @code{void}. Zero without a cast is perfectly fine as a null |
2006 pointer constant, except when calling a varargs function. | 2210 pointer constant, except when calling a varargs function. |
2007 | 2211 |
2008 @node Names | 2212 @node Names |
2009 @section Naming Variables and Functions | 2213 @section Naming Variables and Functions |
2214 | |
2215 The names of global variables and functions in a program serve as | |
2216 comments of a sort. So don't choose terse names---instead, look for | |
2217 names that give useful information about the meaning of the variable or | |
2218 function. In a GNU program, names should be English, like other | |
2219 comments. | |
2220 | |
2221 Local variable names can be shorter, because they are used only within | |
2222 one context, where (presumably) comments explain their purpose. | |
2223 | |
2224 Try to limit your use of abbreviations in symbol names. It is ok to | |
2225 make a few abbreviations, explain what they mean, and then use them | |
2226 frequently, but don't use lots of obscure abbreviations. | |
2010 | 2227 |
2011 Please use underscores to separate words in a name, so that the Emacs | 2228 Please use underscores to separate words in a name, so that the Emacs |
2012 word commands can be useful within them. Stick to lower case; reserve | 2229 word commands can be useful within them. Stick to lower case; reserve |
2013 upper case for macros and @code{enum} constants, and for name-prefixes | 2230 upper case for macros and @code{enum} constants, and for name-prefixes |
2014 that follow a uniform convention. | 2231 that follow a uniform convention. |
2031 When you want to define names with constant integer values, use | 2248 When you want to define names with constant integer values, use |
2032 @code{enum} rather than @samp{#define}. GDB knows about enumeration | 2249 @code{enum} rather than @samp{#define}. GDB knows about enumeration |
2033 constants. | 2250 constants. |
2034 | 2251 |
2035 Use file names of 14 characters or less, to avoid creating gratuitous | 2252 Use file names of 14 characters or less, to avoid creating gratuitous |
2036 problems on older System V systems. You can use the program @code{doschk} to test for | 2253 problems on older System V systems. You can use the program |
2037 this. @code{doschk} also tests for potential name conflicts if the | 2254 @code{doschk} to test for this. @code{doschk} also tests for potential |
2038 files were loaded onto an MS-DOS file system---something you may or may | 2255 name conflicts if the files were loaded onto an MS-DOS file |
2039 not care about. | 2256 system---something you may or may not care about. |
2040 | 2257 |
2041 @node System Portability | 2258 @node System Portability |
2042 @section Portability between System Types | 2259 @section Portability between System Types |
2043 | 2260 |
2044 In the Unix world, ``portability'' refers to porting to different Unix | 2261 In the Unix world, ``portability'' refers to porting to different Unix |
2064 | 2281 |
2065 Avoid using the format of semi-internal data bases (e.g., directories) | 2282 Avoid using the format of semi-internal data bases (e.g., directories) |
2066 when there is a higher-level alternative (@code{readdir}). | 2283 when there is a higher-level alternative (@code{readdir}). |
2067 | 2284 |
2068 As for systems that are not like Unix, such as MSDOS, Windows, the | 2285 As for systems that are not like Unix, such as MSDOS, Windows, the |
2069 Macintosh, VMS, and MVS, supporting them is usually so much work that it | 2286 Macintosh, VMS, and MVS, supporting them is often a lot of work. When |
2070 is better if you don't. | 2287 that is the case, it is better to spend your time adding features that |
2071 | 2288 will be useful on GNU and GNU/Linux, rather than on supporting other |
2072 The planned GNU kernel is not finished yet, but you can tell which | 2289 incompatible systems. |
2073 facilities it will provide by looking at the GNU C Library Manual. The | |
2074 GNU kernel is based on Mach, so the features of Mach will also be | |
2075 available. However, if you use Mach features, you'll probably have | |
2076 trouble debugging your program today. | |
2077 | 2290 |
2078 @node CPU Portability | 2291 @node CPU Portability |
2079 @section Portability between @sc{cpu}s | 2292 @section Portability between @sc{cpu}s |
2080 | 2293 |
2081 Even GNU systems will differ because of differences among @sc{cpu} | 2294 Even GNU systems will differ because of differences among @sc{cpu} |
2109 that pass their arguments along to @code{printf} and friends: | 2322 that pass their arguments along to @code{printf} and friends: |
2110 | 2323 |
2111 @example | 2324 @example |
2112 error (s, a1, a2, a3) | 2325 error (s, a1, a2, a3) |
2113 char *s; | 2326 char *s; |
2114 int a1, a2, a3; | 2327 char *a1, *a2, *a3; |
2115 @{ | 2328 @{ |
2116 fprintf (stderr, "error: "); | 2329 fprintf (stderr, "error: "); |
2117 fprintf (stderr, s, a1, a2, a3); | 2330 fprintf (stderr, s, a1, a2, a3); |
2118 @} | 2331 @} |
2119 @end example | 2332 @end example |
2120 | 2333 |
2121 @noindent | 2334 @noindent |
2122 In practice, this works on all machines, and it is much simpler than any | 2335 In practice, this works on all machines, since a pointer is generally |
2123 ``correct'' alternative. Be sure @emph{not} to use a prototype | 2336 the widest possible kind of argument, and it is much simpler than any |
2124 for such functions. | 2337 ``correct'' alternative. Be sure @emph{not} to use a prototype for such |
2338 functions. | |
2125 | 2339 |
2126 However, avoid casting pointers to integers unless you really need to. | 2340 However, avoid casting pointers to integers unless you really need to. |
2127 These assumptions really reduce portability, and in most programs they | 2341 Outside of special situations, such casts greatly reduce portability, |
2128 are easy to avoid. In the cases where casting pointers to integers is | 2342 and in most programs they are easy to avoid. In the cases where casting |
2129 essential---such as, a Lisp interpreter which stores type information as | 2343 pointers to integers is essential---such as, a Lisp interpreter which |
2130 well as an address in one word---it is ok to do so, but you'll have to | 2344 stores type information as well as an address in one word---it is ok to |
2131 make explicit provisions to handle different word sizes. | 2345 do it, but you'll have to make explicit provisions to handle different |
2346 word sizes. | |
2132 | 2347 |
2133 @node System Functions | 2348 @node System Functions |
2134 @section Calling System Functions | 2349 @section Calling System Functions |
2135 | 2350 |
2136 C implementations differ substantially. @sc{ansi} C reduces but does not | 2351 C implementations differ substantially. @sc{ansi} C reduces but does not |
2141 | 2356 |
2142 @itemize @bullet | 2357 @itemize @bullet |
2143 @item | 2358 @item |
2144 Don't use the value of @code{sprintf}. It returns the number of | 2359 Don't use the value of @code{sprintf}. It returns the number of |
2145 characters written on some systems, but not on all systems. | 2360 characters written on some systems, but not on all systems. |
2361 | |
2362 @item | |
2363 @code{main} should be declared to return type @code{int}. It should | |
2364 terminate either by calling @code{exit} or by returning the integer | |
2365 status code; make sure it cannot ever return an undefined value. | |
2146 | 2366 |
2147 @item | 2367 @item |
2148 Don't declare system functions explicitly. | 2368 Don't declare system functions explicitly. |
2149 | 2369 |
2150 Almost any declaration for a system function is wrong on some system. | 2370 Almost any declaration for a system function is wrong on some system. |
2273 name} for the package. The text domain name is used to separate the | 2493 name} for the package. The text domain name is used to separate the |
2274 translations for this package from the translations for other packages. | 2494 translations for this package from the translations for other packages. |
2275 Normally, the text domain name should be the same as the name of the | 2495 Normally, the text domain name should be the same as the name of the |
2276 package---for example, @samp{fileutils} for the GNU file utilities. | 2496 package---for example, @samp{fileutils} for the GNU file utilities. |
2277 | 2497 |
2278 To enable gettext to work, avoid writing code that makes assumptions | 2498 To enable gettext to work well, avoid writing code that makes |
2279 about the structure of words. Don't construct words from parts. Here | 2499 assumptions about the structure of words or sentences. When you want |
2280 is an example of what not to do: | 2500 the precise text of a sentence to vary depending on the data, use two or |
2281 | 2501 more alternative string constants each containing a complete sentences, |
2282 @example | 2502 rather than inserting conditionalized words or phrases into a single |
2283 prinf ("%d file%s processed", nfiles, | 2503 sentence framework. |
2284 nfiles > 1 ? "s" : ""); | 2504 |
2505 Here is an example of what not to do: | |
2506 | |
2507 @example | |
2508 printf ("%d file%s processed", nfiles, | |
2509 nfiles != 1 ? "s" : ""); | |
2285 @end example | 2510 @end example |
2286 | 2511 |
2287 @noindent | 2512 @noindent |
2288 The problem with that example is that it assumes that plurals are made | 2513 The problem with that example is that it assumes that plurals are made |
2289 by adding `s'. If you apply gettext to the format string, like this, | 2514 by adding `s'. If you apply gettext to the format string, like this, |
2290 | 2515 |
2291 @example | 2516 @example |
2292 prinf (gettext ("%d file%s processed"), nfiles, | 2517 printf (gettext ("%d file%s processed"), nfiles, |
2293 nfiles > 1 ? "s" : ""); | 2518 nfiles != 1 ? "s" : ""); |
2294 @end example | 2519 @end example |
2295 | 2520 |
2296 @noindent | 2521 @noindent |
2297 the message can use different words, but it will still be forced to use | 2522 the message can use different words, but it will still be forced to use |
2298 `s' for the plural. Here is a better way: | 2523 `s' for the plural. Here is a better way: |
2299 | 2524 |
2300 @example | 2525 @example |
2301 prinf ((nfiles > 1 ? "%d files processed" | 2526 printf ((nfiles != 1 ? "%d files processed" |
2302 : "%d file processed"), | 2527 : "%d file processed"), |
2303 nfiles); | 2528 nfiles); |
2304 @end example | 2529 @end example |
2305 | 2530 |
2306 @noindent | 2531 @noindent |
2307 This way, you can apply gettext to each of the two strings | 2532 This way, you can apply gettext to each of the two strings |
2308 independently: | 2533 independently: |
2309 | 2534 |
2310 @example | 2535 @example |
2311 prinf ((nfiles > 1 ? gettext ("%d files processed") | 2536 printf ((nfiles != 1 ? gettext ("%d files processed") |
2312 : gettext ("%d file processed")), | 2537 : gettext ("%d file processed")), |
2313 nfiles); | 2538 nfiles); |
2314 @end example | 2539 @end example |
2315 | 2540 |
2316 @noindent | 2541 @noindent |
2317 This can handle any language, no matter how it forms the plural of the | 2542 This can be any method of forming the plural of the word for ``file'', and |
2318 word for ``file.'' | 2543 also handles languages that require agreement in the word for |
2544 ``processed''. | |
2545 | |
2546 A similar problem appears at the level of sentence structure with this | |
2547 code: | |
2548 | |
2549 @example | |
2550 printf ("# Implicit rule search has%s been done.\n", | |
2551 f->tried_implicit ? "" : " not"); | |
2552 @end example | |
2553 | |
2554 @noindent | |
2555 Adding @code{gettext} calls to this code cannot give correct results for | |
2556 all languages, because negation in some languages requires adding words | |
2557 at more than one place in the sentence. By contrast, adding | |
2558 @code{gettext} calls does the job straightfowardly if the code starts | |
2559 out like this: | |
2560 | |
2561 @example | |
2562 printf (f->tried_implicit | |
2563 ? "# Implicit rule search has been done.\n", | |
2564 : "# Implicit rule search has not been done.\n"); | |
2565 @end example | |
2566 | |
2567 @node Mmap | |
2568 @section Mmap | |
2569 | |
2570 Don't assume that @code{mmap} either works on all files or fails | |
2571 for all files. It may work on some files and fail on others. | |
2572 | |
2573 The proper way to use @code{mmap} is to try it on the specific file for | |
2574 which you want to use it---and if @code{mmap} doesn't work, fall back on | |
2575 doing the job in another way using @code{read} and @code{write}. | |
2576 | |
2577 The reason this precaution is needed is that the GNU kernel (the HURD) | |
2578 provides a user-extensible file system, in which there can be many | |
2579 different kinds of ``ordinary files.'' Many of them support | |
2580 @code{mmap}, but some do not. It is important to make programs handle | |
2581 all these kinds of files. | |
2319 | 2582 |
2320 @node Documentation | 2583 @node Documentation |
2321 @chapter Documenting Programs | 2584 @chapter Documenting Programs |
2322 | 2585 |
2323 @menu | 2586 @menu |
2324 * GNU Manuals:: Writing proper manuals. | 2587 * GNU Manuals:: Writing proper manuals. |
2325 * Manual Structure Details:: Specific structure conventions. | 2588 * Manual Structure Details:: Specific structure conventions. |
2589 * License for Manuals:: Writing the distribution terms for a manual. | |
2326 * NEWS File:: NEWS files supplement manuals. | 2590 * NEWS File:: NEWS files supplement manuals. |
2327 * Change Logs:: Recording Changes | 2591 * Change Logs:: Recording Changes |
2328 * Man Pages:: Man pages are secondary. | 2592 * Man Pages:: Man pages are secondary. |
2329 * Reading other Manuals:: How far you can go in learning | 2593 * Reading other Manuals:: How far you can go in learning |
2330 from other manuals. | 2594 from other manuals. |
2331 @end menu | 2595 @end menu |
2332 | 2596 |
2333 @node GNU Manuals | 2597 @node GNU Manuals |
2334 @section GNU Manuals | 2598 @section GNU Manuals |
2335 | 2599 |
2336 The preferred way to document part of the GNU system is to write a | 2600 The preferred way to document part of the GNU system is to write a |
2337 manual in the Texinfo formatting language. See the Texinfo manual, | 2601 manual in the Texinfo formatting language. This makes it possible to |
2338 either the hardcopy, or the on-line version available through | 2602 produce a good quality formatted book, using @TeX{}, and to generate an |
2339 @code{info} or the Emacs Info subsystem (@kbd{C-h i}). | 2603 Info file. It is also possible to generate HTML output from Texinfo |
2340 | 2604 source. See the Texinfo manual, either the hardcopy, or the on-line |
2341 The manual should document all of the program's command-line options and | 2605 version available through @code{info} or the Emacs Info subsystem |
2342 all of its commands. It should give examples of their use. But don't | 2606 (@kbd{C-h i}). |
2343 organize the manual as a list of features. Instead, organize it | 2607 |
2344 logically, by subtopics. Address the goals that a user will have in | 2608 Programmers often find it most natural to structure the documentation |
2345 mind, and explain how to accomplish them. | 2609 following the structure of the implementation, which they know. But |
2610 this structure is not necessarily good for explaining how to use the | |
2611 program; it may be irrelevant and confusing for a user. | |
2612 | |
2613 At every level, from the sentences in a paragraph to the grouping of | |
2614 topics into separate manuals, the right way to structure documentation | |
2615 is according to the concepts and questions that a user will have in mind | |
2616 when reading it. Sometimes this structure of ideas matches the | |
2617 structure of the implementation of the software being documented---but | |
2618 often they are different. Often the most important part of learning to | |
2619 write good documentation is learning to notice when you are structuring | |
2620 the documentation like the implementation, and think about better | |
2621 alternatives. | |
2622 | |
2623 For example, each program in the GNU system probably ought to be | |
2624 documented in one manual; but this does not mean each program should | |
2625 have its own manual. That would be following the structure of the | |
2626 implementation, rather than the structure that helps the user | |
2627 understand. | |
2628 | |
2629 Instead, each manual should cover a coherent @emph{topic}. For example, | |
2630 instead of a manual for @code{diff} and a manual for @code{diff3}, we | |
2631 have one manual for ``comparison of files'' which covers both of those | |
2632 programs, as well as @code{cmp}. By documenting these programs | |
2633 together, we can make the whole subject clearer. | |
2634 | |
2635 The manual which discusses a program should document all of the | |
2636 program's command-line options and all of its commands. It should give | |
2637 examples of their use. But don't organize the manual as a list of | |
2638 features. Instead, organize it logically, by subtopics. Address the | |
2639 questions that a user will ask when thinking about the job that the | |
2640 program does. | |
2346 | 2641 |
2347 In general, a GNU manual should serve both as tutorial and reference. | 2642 In general, a GNU manual should serve both as tutorial and reference. |
2348 It should be set up for convenient access to each topic through Info, | 2643 It should be set up for convenient access to each topic through Info, |
2349 and for reading straight through (appendixes aside). A GNU manual | 2644 and for reading straight through (appendixes aside). A GNU manual |
2350 should give a good introduction to a beginner reading through from the | 2645 should give a good introduction to a beginner reading through from the |
2351 start, and should also provide all the details that hackers want. | 2646 start, and should also provide all the details that hackers want. |
2647 The Bison manual is a good example of this---please take a look at it | |
2648 to see what we mean. | |
2352 | 2649 |
2353 That is not as hard as it first sounds. Arrange each chapter as a | 2650 That is not as hard as it first sounds. Arrange each chapter as a |
2354 logical breakdown of its topic, but order the sections, and write their | 2651 logical breakdown of its topic, but order the sections, and write their |
2355 text, so that reading the chapter straight through makes sense. Do | 2652 text, so that reading the chapter straight through makes sense. Do |
2356 likewise when structuring the book into chapters, and when structuring a | 2653 likewise when structuring the book into chapters, and when structuring a |
2361 are purely tutorial and cover the basics of the subject. These provide | 2658 are purely tutorial and cover the basics of the subject. These provide |
2362 the framework for a beginner to understand the rest of the manual. The | 2659 the framework for a beginner to understand the rest of the manual. The |
2363 Bison manual provides a good example of how to do this. | 2660 Bison manual provides a good example of how to do this. |
2364 | 2661 |
2365 Don't use Unix man pages as a model for how to write GNU documentation; | 2662 Don't use Unix man pages as a model for how to write GNU documentation; |
2366 they are a bad example to follow. | 2663 most of them are terse, badly structured, and give inadequate |
2664 explanation of the underlying concepts. (There are, of course | |
2665 exceptions.) Also Unix man pages use a particular format which is | |
2666 different from what we use in GNU manuals. | |
2667 | |
2668 Please include an email address in the manual for where to report | |
2669 bugs @emph{in the manual}. | |
2367 | 2670 |
2368 Please do not use the term ``pathname'' that is used in Unix | 2671 Please do not use the term ``pathname'' that is used in Unix |
2369 documentation; use ``file name'' (two words) instead. We use the term | 2672 documentation; use ``file name'' (two words) instead. We use the term |
2370 ``path'' only for search paths, which are lists of file names. | 2673 ``path'' only for search paths, which are lists of directory names. |
2674 | |
2675 Please do not use the term ``illegal'' to refer to erroneous input to a | |
2676 computer program. Please use ``invalid'' for this, and reserve the term | |
2677 ``illegal'' for violations of law. | |
2371 | 2678 |
2372 @node Manual Structure Details | 2679 @node Manual Structure Details |
2373 @section Manual Structure Details | 2680 @section Manual Structure Details |
2374 | 2681 |
2375 The title page of the manual should state the version of the program | 2682 The title page of the manual should state the version of the programs or |
2376 to which the manual applies. The Top node of the manual should also | 2683 packages documented in the manual. The Top node of the manual should |
2377 contain this information. If the manual is changing more frequently | 2684 also contain this information. If the manual is changing more |
2378 than or independent of the program, also state a version number for | 2685 frequently than or independent of the program, also state a version |
2379 the manual in both of these places. | 2686 number for the manual in both of these places. |
2380 | 2687 |
2381 The manual should have a node named @samp{@var{program} Invocation} or | 2688 Each program documented in the manual should have a node named |
2382 @samp{Invoking @var{program}}, where @var{program} stands for the name | 2689 @samp{@var{program} Invocation} or @samp{Invoking @var{program}}. This |
2383 of the program being described, as you would type it in the shell to run | 2690 node (together with its subnodes, if any) should describe the program's |
2384 the program. This node (together with its subnodes, if any) should | 2691 command line arguments and how to run it (the sort of information people |
2385 describe the program's command line arguments and how to run it (the | 2692 would look in a man page for). Start with an @samp{@@example} |
2386 sort of information people would look in a man page for). Start with an | 2693 containing a template for all the options and arguments that the program |
2387 @samp{@@example} containing a template for all the options and arguments | 2694 uses. |
2388 that the program uses. | |
2389 | 2695 |
2390 Alternatively, put a menu item in some menu whose item name fits one of | 2696 Alternatively, put a menu item in some menu whose item name fits one of |
2391 the above patterns. This identifies the node which that item points to | 2697 the above patterns. This identifies the node which that item points to |
2392 as the node for this purpose, regardless of the node's actual name. | 2698 as the node for this purpose, regardless of the node's actual name. |
2393 | 2699 |
2394 There will be automatic features for specifying a program name and | 2700 There will be automatic features for specifying a program name and |
2395 quickly reading just this part of its manual. | 2701 quickly reading just this part of its manual. |
2396 | 2702 |
2397 If one manual describes several programs, it should have such a node for | 2703 If one manual describes several programs, it should have such a node for |
2398 each program described. | 2704 each program described. |
2705 | |
2706 @node License for Manuals | |
2707 @section License for Manuals | |
2708 | |
2709 If the manual contains a copy of the GNU GPL or GNU LGPL, or if it | |
2710 contains chapters that make political or personal statements, please | |
2711 copy the distribution terms of the GNU Emacs Manual, and adapt it by | |
2712 modifying appropriately the list of special chapters that may not be | |
2713 modified or deleted. | |
2714 | |
2715 If the manual does not contain any such chapters, then imitate the | |
2716 simpler distribution terms of the Texinfo manual. | |
2399 | 2717 |
2400 @node NEWS File | 2718 @node NEWS File |
2401 @section The NEWS File | 2719 @section The NEWS File |
2402 | 2720 |
2403 In addition to its manual, the package should have a file named | 2721 In addition to its manual, the package should have a file named |
2416 | 2734 |
2417 Keep a change log to describe all the changes made to program source | 2735 Keep a change log to describe all the changes made to program source |
2418 files. The purpose of this is so that people investigating bugs in the | 2736 files. The purpose of this is so that people investigating bugs in the |
2419 future will know about the changes that might have introduced the bug. | 2737 future will know about the changes that might have introduced the bug. |
2420 Often a new bug can be found by looking at what was recently changed. | 2738 Often a new bug can be found by looking at what was recently changed. |
2421 More importantly, change logs can help eliminate conceptual | 2739 More importantly, change logs can help you eliminate conceptual |
2422 inconsistencies between different parts of a program; they can give you | 2740 inconsistencies between different parts of a program, by giving you a |
2423 a history of how the conflicting concepts arose. | 2741 history of how the conflicting concepts arose and who they came from. |
2424 | 2742 |
2425 A change log file is normally called @file{ChangeLog} and covers an | 2743 @menu |
2744 * Change Log Concepts:: | |
2745 * Style of Change Logs:: | |
2746 * Simple Changes:: | |
2747 * Conditional Changes:: | |
2748 @end menu | |
2749 | |
2750 @node Change Log Concepts | |
2751 @subsection Change Log Concepts | |
2752 | |
2753 You can think of the change log as a conceptual ``undo list'' which | |
2754 explains how earlier versions were different from the current version. | |
2755 People can see the current version; they don't need the change log | |
2756 to tell them what is in it. What they want from a change log is a | |
2757 clear explanation of how the earlier version differed. | |
2758 | |
2759 The change log file is normally called @file{ChangeLog} and covers an | |
2426 entire directory. Each directory can have its own change log, or a | 2760 entire directory. Each directory can have its own change log, or a |
2427 directory can use the change log of its parent directory--it's up to | 2761 directory can use the change log of its parent directory--it's up to |
2428 you. | 2762 you. |
2429 | 2763 |
2430 Another alternative is to record change log information with a version | 2764 Another alternative is to record change log information with a version |
2431 control system such as RCS or CVS. This can be converted automatically | 2765 control system such as RCS or CVS. This can be converted automatically |
2432 to a @file{ChangeLog} file. | 2766 to a @file{ChangeLog} file using @code{rcs2log}; in Emacs, the command |
2767 @kbd{C-x v a} (@code{vc-update-change-log}) does the job. | |
2768 | |
2769 There's no need to describe the full purpose of the changes or how they | |
2770 work together. If you think that a change calls for explanation, you're | |
2771 probably right. Please do explain it---but please put the explanation | |
2772 in comments in the code, where people will see it whenever they see the | |
2773 code. For example, ``New function'' is enough for the change log when | |
2774 you add a function, because there should be a comment before the | |
2775 function definition to explain what it does. | |
2776 | |
2777 However, sometimes it is useful to write one line to describe the | |
2778 overall purpose of a batch of changes. | |
2433 | 2779 |
2434 The easiest way to add an entry to @file{ChangeLog} is with the Emacs | 2780 The easiest way to add an entry to @file{ChangeLog} is with the Emacs |
2435 command @kbd{M-x add-change-log-entry}. An entry should have an | 2781 command @kbd{M-x add-change-log-entry}. An entry should have an |
2436 asterisk, the name of the changed file, and then in parentheses the name | 2782 asterisk, the name of the changed file, and then in parentheses the name |
2437 of the changed functions, variables or whatever, followed by a colon. | 2783 of the changed functions, variables or whatever, followed by a colon. |
2438 Then describe the changes you made to that function or variable. | 2784 Then describe the changes you made to that function or variable. |
2439 | 2785 |
2440 Separate unrelated entries with blank lines. When two entries | 2786 @node Style of Change Logs |
2441 represent parts of the same change, so that they work together, then | 2787 @subsection Style of Change Logs |
2442 don't put blank lines between them. Then you can omit the file name | 2788 |
2443 and the asterisk when successive entries are in the same file. | 2789 Here are some examples of change log entries: |
2444 | |
2445 Here are some examples: | |
2446 | 2790 |
2447 @example | 2791 @example |
2448 * register.el (insert-register): Return nil. | 2792 * register.el (insert-register): Return nil. |
2449 (jump-to-register): Likewise. | 2793 (jump-to-register): Likewise. |
2450 | 2794 |
2459 * stmt.c (assign_parms): Round size up for move_block_from_reg. | 2803 * stmt.c (assign_parms): Round size up for move_block_from_reg. |
2460 @end example | 2804 @end example |
2461 | 2805 |
2462 It's important to name the changed function or variable in full. Don't | 2806 It's important to name the changed function or variable in full. Don't |
2463 abbreviate function or variable names, and don't combine them. | 2807 abbreviate function or variable names, and don't combine them. |
2464 Subsequent maintainers will often | 2808 Subsequent maintainers will often search for a function name to find all |
2465 search for a function name to find all the change log entries that | 2809 the change log entries that pertain to it; if you abbreviate the name, |
2466 pertain to it; if you abbreviate the name, they won't find it when they | 2810 they won't find it when they search. |
2467 search. For example, some people are tempted to abbreviate groups of | 2811 |
2468 function names by writing @samp{* register.el | 2812 For example, some people are tempted to abbreviate groups of function |
2469 (@{insert,jump-to@}-register)}; this is not a good idea, since searching | 2813 names by writing @samp{* register.el (@{insert,jump-to@}-register)}; |
2470 for @code{jump-to-register} or @code{insert-register} would not find the | 2814 this is not a good idea, since searching for @code{jump-to-register} or |
2471 entry. | 2815 @code{insert-register} would not find that entry. |
2472 | 2816 |
2473 There's no need to describe the full purpose of the changes or how they | 2817 Separate unrelated change log entries with blank lines. When two |
2474 work together. It is better to put such explanations in comments in the | 2818 entries represent parts of the same change, so that they work together, |
2475 code. That's why just ``New function'' is enough; there is a comment | 2819 then don't put blank lines between them. Then you can omit the file |
2476 with the function in the source to explain what it does. | 2820 name and the asterisk when successive entries are in the same file. |
2477 | 2821 |
2478 However, sometimes it is useful to write one line to describe the | 2822 @node Simple Changes |
2479 overall purpose of a large batch of changes. | 2823 @subsection Simple Changes |
2480 | 2824 |
2481 You can think of the change log as a conceptual ``undo list'' which | 2825 Certain simple kinds of changes don't need much detail in the change |
2482 explains how earlier versions were different from the current version. | 2826 log. |
2483 People can see the current version; they don't need the change log | 2827 |
2484 to tell them what is in it. What they want from a change log is a | 2828 When you change the calling sequence of a function in a simple fashion, |
2485 clear explanation of how the earlier version differed. | 2829 and you change all the callers of the function, there is no need to make |
2486 | 2830 individual entries for all the callers that you changed. Just write in |
2487 When you change the calling sequence of a function in a simple | |
2488 fashion, and you change all the callers of the function, there is no | |
2489 need to make individual entries for all the callers. Just write in | |
2490 the entry for the function being called, ``All callers changed.'' | 2831 the entry for the function being called, ``All callers changed.'' |
2491 | 2832 |
2833 @example | |
2834 * keyboard.c (Fcommand_execute): New arg SPECIAL. | |
2835 All callers changed. | |
2836 @end example | |
2837 | |
2492 When you change just comments or doc strings, it is enough to write an | 2838 When you change just comments or doc strings, it is enough to write an |
2493 entry for the file, without mentioning the functions. Write just, | 2839 entry for the file, without mentioning the functions. Just ``Doc |
2494 ``Doc fix.'' | 2840 fixes'' is enough for the change log. |
2495 | 2841 |
2496 There's no need to make change log entries for documentation files. | 2842 There's no need to make change log entries for documentation files. |
2497 This is because documentation is not susceptible to bugs that are hard | 2843 This is because documentation is not susceptible to bugs that are hard |
2498 to fix. Documentation does not consist of parts that must interact in a | 2844 to fix. Documentation does not consist of parts that must interact in a |
2499 precisely engineered fashion. To correct an error, you need not know | 2845 precisely engineered fashion. To correct an error, you need not know |
2500 the history of the erroneous passage; it is enough to compare the | 2846 the history of the erroneous passage; it is enough to compare what the |
2501 passage with the way the program actually works. | 2847 documentation says with the way the program actually works. |
2848 | |
2849 @node Conditional Changes | |
2850 @subsection Conditional Changes | |
2851 | |
2852 C programs often contain compile-time @code{#if} conditionals. Many | |
2853 changes are conditional; sometimes you add a new definition which is | |
2854 entirely contained in a conditional. It is very useful to indicate in | |
2855 the change log the conditions for which the change applies. | |
2856 | |
2857 Our convention for indicating conditional changes is to use square | |
2858 brackets around the name of the condition. | |
2859 | |
2860 Here is a simple example, describing a change which is conditional but | |
2861 does not have a function or entity name associated with it: | |
2862 | |
2863 @example | |
2864 * xterm.c [SOLARIS2]: Include string.h. | |
2865 @end example | |
2866 | |
2867 Here is an entry describing a new definition which is entirely | |
2868 conditional. This new definition for the macro @code{FRAME_WINDOW_P} is | |
2869 used only when @code{HAVE_X_WINDOWS} is defined: | |
2870 | |
2871 @example | |
2872 * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined. | |
2873 @end example | |
2874 | |
2875 Here is an entry for a change within the function @code{init_display}, | |
2876 whose definition as a whole is unconditional, but the changes themselves | |
2877 are contained in a @samp{#ifdef HAVE_LIBNCURSES} conditional: | |
2878 | |
2879 @example | |
2880 * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent. | |
2881 @end example | |
2882 | |
2883 Here is an entry for a change that takes affect only when | |
2884 a certain macro is @emph{not} defined: | |
2885 | |
2886 @example | |
2887 (gethostname) [!HAVE_SOCKETS]: Replace with winsock version. | |
2888 @end example | |
2502 | 2889 |
2503 @node Man Pages | 2890 @node Man Pages |
2504 @section Man Pages | 2891 @section Man Pages |
2505 | 2892 |
2506 In the GNU project, man pages are secondary. It is not necessary or | 2893 In the GNU project, man pages are secondary. It is not necessary or |
2556 layout should also conform to the standards discussed below. Doing so | 2943 layout should also conform to the standards discussed below. Doing so |
2557 makes it easy to include your package into the larger framework of | 2944 makes it easy to include your package into the larger framework of |
2558 all GNU software. | 2945 all GNU software. |
2559 | 2946 |
2560 @menu | 2947 @menu |
2561 * Configuration:: How Configuration Should Work | 2948 * Configuration:: How Configuration Should Work |
2562 * Makefile Conventions:: Makefile Conventions | 2949 * Makefile Conventions:: Makefile Conventions |
2563 * Releases:: Making Releases | 2950 * Releases:: Making Releases |
2564 @end menu | 2951 @end menu |
2565 | 2952 |
2566 @node Configuration | 2953 @node Configuration |
2567 @section How Configuration Should Work | 2954 @section How Configuration Should Work |
2568 | 2955 |
2631 | 3018 |
2632 The @code{configure} script needs to be able to decode all plausible | 3019 The @code{configure} script needs to be able to decode all plausible |
2633 alternatives for how to describe a machine. Thus, @samp{sun3-sunos4.1} | 3020 alternatives for how to describe a machine. Thus, @samp{sun3-sunos4.1} |
2634 would be a valid alias. For many programs, @samp{vax-dec-ultrix} would | 3021 would be a valid alias. For many programs, @samp{vax-dec-ultrix} would |
2635 be an alias for @samp{vax-dec-bsd}, simply because the differences | 3022 be an alias for @samp{vax-dec-bsd}, simply because the differences |
2636 between Ultrix and @sc{BSD} are rarely noticeable, but a few programs | 3023 between Ultrix and BSD are rarely noticeable, but a few programs |
2637 might need to distinguish them. | 3024 might need to distinguish them. |
2638 @c Real 4.4BSD now runs on some Suns. | 3025 @c Real 4.4BSD now runs on some Suns. |
2639 | 3026 |
2640 There is a shell script called @file{config.sub} that you can use | 3027 There is a shell script called @file{config.sub} that you can use |
2641 as a subroutine to validate system types and canonicalize aliases. | 3028 as a subroutine to validate system types and canonicalize aliases. |
2663 to work with @var{package}. | 3050 to work with @var{package}. |
2664 | 3051 |
2665 @c Giving an optional @var{parameter} of | 3052 @c Giving an optional @var{parameter} of |
2666 @c @samp{no} should omit @var{package}, if it is used by default. | 3053 @c @samp{no} should omit @var{package}, if it is used by default. |
2667 | 3054 |
2668 Possible values of @var{package} include @samp{x}, @samp{x-toolkit}, | 3055 Possible values of @var{package} include |
2669 @samp{gnu-as} (or @samp{gas}), @samp{gnu-ld}, @samp{gnu-libc}, and | 3056 @samp{gnu-as} (or @samp{gas}), @samp{gnu-ld}, @samp{gnu-libc}, |
2670 @samp{gdb}. | 3057 @samp{gdb}, |
3058 @samp{x}, | |
3059 and | |
3060 @samp{x-toolkit}. | |
2671 | 3061 |
2672 Do not use a @samp{--with} option to specify the file name to use to | 3062 Do not use a @samp{--with} option to specify the file name to use to |
2673 find certain files. That is outside the scope of what @samp{--with} | 3063 find certain files. That is outside the scope of what @samp{--with} |
2674 options are for. | 3064 options are for. |
2675 | 3065 |
2732 @raisesections | 3122 @raisesections |
2733 | 3123 |
2734 @node Releases | 3124 @node Releases |
2735 @section Making Releases | 3125 @section Making Releases |
2736 | 3126 |
2737 Package the distribution of Foo version 69.96 in a gzipped tar file | 3127 Package the distribution of @code{Foo version 69.96} up in a gzipped tar |
2738 named @file{foo-69.96.tar.gz}. It should unpack into a subdirectory | 3128 file with the name @file{foo-69.96.tar.gz}. It should unpack into a |
2739 named @file{foo-69.96}. | 3129 subdirectory named @file{foo-69.96}. |
2740 | 3130 |
2741 Building and installing the program should never modify any of the files | 3131 Building and installing the program should never modify any of the files |
2742 contained in the distribution. This means that all the files that form | 3132 contained in the distribution. This means that all the files that form |
2743 part of the program in any way must be classified into @dfn{source | 3133 part of the program in any way must be classified into @dfn{source |
2744 files} and @dfn{non-source files}. Source files are written by humans | 3134 files} and @dfn{non-source files}. Source files are written by humans |
2745 and never changed automatically; non-source files are produced from | 3135 and never changed automatically; non-source files are produced from |
2746 source files by programs under the control of the Makefile. | 3136 source files by programs under the control of the Makefile. |
3137 | |
3138 The distribution should contain a file named @file{README} which gives | |
3139 the name of the package, and a general description of what it does. It | |
3140 is also good to explain the purpose of each of the first-level | |
3141 subdirectories in the package, if there are any. The @file{README} file | |
3142 should either state the version number of the package, or refer to where | |
3143 in the package it can be found. | |
3144 | |
3145 The @file{README} file should refer to the file @file{INSTALL}, which | |
3146 should contain an explanation of the installation procedure. | |
3147 | |
3148 The @file{README} file should also refer to the file which contains the | |
3149 copying conditions. The GNU GPL, if used, should be in a file called | |
3150 @file{COPYING}. If the GNU LGPL is used, it should be in a file called | |
3151 @file{COPYING.LIB}. | |
2747 | 3152 |
2748 Naturally, all the source files must be in the distribution. It is okay | 3153 Naturally, all the source files must be in the distribution. It is okay |
2749 to include non-source files in the distribution, provided they are | 3154 to include non-source files in the distribution, provided they are |
2750 up-to-date and machine-independent, so that building the distribution | 3155 up-to-date and machine-independent, so that building the distribution |
2751 normally will never modify them. We commonly include non-source files | 3156 normally will never modify them. We commonly include non-source files |
2767 Make sure that all the files in the distribution are world-readable. | 3172 Make sure that all the files in the distribution are world-readable. |
2768 | 3173 |
2769 Make sure that no file name in the distribution is more than 14 | 3174 Make sure that no file name in the distribution is more than 14 |
2770 characters long. Likewise, no file created by building the program | 3175 characters long. Likewise, no file created by building the program |
2771 should have a name longer than 14 characters. The reason for this is | 3176 should have a name longer than 14 characters. The reason for this is |
2772 that some systems adhere to a foolish interpretation of the POSIX | 3177 that some systems adhere to a foolish interpretation of the @sc{posix} |
2773 standard, and refuse to open a longer name, rather than truncating as | 3178 standard, and refuse to open a longer name, rather than truncating as |
2774 they did in the past. | 3179 they did in the past. |
2775 | 3180 |
2776 Don't include any symbolic links in the distribution itself. If the tar | 3181 Don't include any symbolic links in the distribution itself. If the tar |
2777 file contains symbolic links, then people cannot even unpack it on | 3182 file contains symbolic links, then people cannot even unpack it on |
2795 getopt, obstack, or termcap, include them in the distribution file. | 3200 getopt, obstack, or termcap, include them in the distribution file. |
2796 Leaving them out would make the distribution file a little smaller at | 3201 Leaving them out would make the distribution file a little smaller at |
2797 the expense of possible inconvenience to a user who doesn't know what | 3202 the expense of possible inconvenience to a user who doesn't know what |
2798 other files to get. | 3203 other files to get. |
2799 | 3204 |
3205 @node References | |
3206 @chapter References to Non-Free Software and Documentation | |
3207 | |
3208 A GNU program should not recommend use of any non-free program. We | |
3209 can't stop some people from writing proprietary programs, or stop other | |
3210 people from using them. But we can and should avoid helping to | |
3211 advertise them to new customers. | |
3212 | |
3213 Sometimes it is important to mention how to build your package on top of | |
3214 some non-free operating system or other non-free base package. In such | |
3215 cases, please mention the name of the non-free package or system in the | |
3216 briefest possible way. Don't include any references for where to find | |
3217 more information about the proprietary program. The goal should be that | |
3218 people already using the proprietary program will get the advice they | |
3219 need about how to use your free program, while people who don't already | |
3220 use the proprietary program will not see anything to encourage them to | |
3221 take an interest in it. | |
3222 | |
3223 Likewise, a GNU package should not refer the user to any non-free | |
3224 documentation for free software. The need for free documentation to go | |
3225 with free software is now a major focus of the GNU project; to show that | |
3226 we are serious about the need for free documentation, we must not | |
3227 undermine our position by recommending use of documentation that isn't | |
3228 free. | |
3229 | |
2800 @contents | 3230 @contents |
2801 | 3231 |
2802 @bye | 3232 @bye |