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