]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/style.9
This commit was generated by cvs2svn to compensate for changes in r166124,
[FreeBSD/FreeBSD.git] / share / man / man9 / style.9
1 .\"-
2 .\" Copyright (c) 1995-2005 The FreeBSD Project
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\"     From: @(#)style 1.14 (Berkeley) 4/28/95
27 .\" $FreeBSD$
28 .\"
29 .Dd February 10, 2005
30 .Dt STYLE 9
31 .Os
32 .Sh NAME
33 .Nm style
34 .Nd "kernel source file style guide"
35 .Sh DESCRIPTION
36 This file specifies the preferred style for kernel source files in the
37 .Fx
38 source tree.
39 It is also a guide for the preferred userland code style.
40 Many of the style rules are implicit in the examples.
41 Be careful to check the examples before assuming that
42 .Nm
43 is silent on an issue.
44 .Bd -literal
45 /*
46  * Style guide for FreeBSD.  Based on the CSRG's KNF (Kernel Normal Form).
47  *
48  *      @(#)style       1.14 (Berkeley) 4/28/95
49  * $FreeBSD$
50  */
51
52 /*
53  * VERY important single-line comments look like this.
54  */
55
56 /* Most single-line comments look like this. */
57
58 /*
59  * Multi-line comments look like this.  Make them real sentences.  Fill
60  * them so they look like real paragraphs.
61  */
62 .Ed
63 .Pp
64 The copyright header should be a multi-line comment, with the first
65 line of the comment having a dash after the star like so:
66 .Bd -literal
67 /*-
68  * Copyright (c) 1984-2025 John Q. Public.  All Rights Reserved.
69  *
70  * Long, boring license goes here, but redacted for brevity
71  */
72 .Ed
73 .Pp
74 An automatic script collects license information from the tree for
75 all comments that start in the first column with
76 .Dq Li "/*-" .
77 If you desire to flag
78 .Xr indent 1
79 to not reformat a comment that starts in the first column which is not a
80 license or copyright notice, change the dash to a star for those
81 comments.
82 Comments starting in columns other than the first are never
83 considered license statements.
84 .Pp
85 After any copyright header, there is a blank line, and the
86 .Li $\&FreeBSD$
87 for non C/C++ language source files.
88 Version control system ID tags should only exist once in a file
89 (unlike in this one).
90 Non-C/C++ source files follow the example above, while C/C++ source files
91 follow the one below.
92 All VCS (version control system) revision identification in files obtained
93 from elsewhere should be maintained, including, where applicable, multiple IDs
94 showing a file's history.
95 In general, do not edit foreign IDs or their infrastructure.
96 Unless otherwise wrapped (such as
97 .Dq Li "#if defined(LIBC_SCCS)" ) ,
98 enclose both in
99 .Dq Li "#if 0 ... #endif"
100 to hide any uncompilable bits
101 and to keep the IDs out of object files.
102 Only add
103 .Dq Li "From: "
104 in front of foreign VCS IDs if the file is renamed.
105 .Bd -literal
106 #if 0
107 #ifndef lint
108 static char sccsid[] = "@(#)style       1.14 (Berkeley) 4/28/95";
109 #endif /* not lint */
110 #endif
111
112 #include <sys/cdefs.h>
113 __FBSDID("$FreeBSD$");
114 .Ed
115 .Pp
116 Leave another blank line before the header files.
117 .Pp
118 Kernel include files (i.e.\&
119 .Pa sys/*.h )
120 come first; normally, include
121 .In sys/types.h
122 OR
123 .In sys/param.h ,
124 but not both.
125 .In sys/types.h
126 includes
127 .In sys/cdefs.h ,
128 and it is okay to depend on that.
129 .Bd -literal
130 #include <sys/types.h>  /* Non-local includes in angle brackets. */
131 .Ed
132 .Pp
133 For a network program, put the network include files next.
134 .Bd -literal
135 #include <net/if.h>
136 #include <net/if_dl.h>
137 #include <net/route.h>
138 #include <netinet/in.h>
139 #include <protocols/rwhod.h>
140 .Ed
141 .Pp
142 Do not use files in
143 .Pa /usr/include
144 for files in the kernel.
145 .Pp
146 Leave a blank line before the next group, the
147 .Pa /usr/include
148 files,
149 which should be sorted alphabetically by name.
150 .Bd -literal
151 #include <stdio.h>
152 .Ed
153 .Pp
154 Global pathnames are defined in
155 .In paths.h .
156 Pathnames local
157 to the program go in
158 .Qq Pa pathnames.h
159 in the local directory.
160 .Bd -literal
161 #include <paths.h>
162 .Ed
163 .Pp
164 Leave another blank line before the user include files.
165 .Bd -literal
166 #include "pathnames.h"          /* Local includes in double quotes. */
167 .Ed
168 .Pp
169 Do not
170 .Ic #define
171 or declare names in the implementation namespace except
172 for implementing application interfaces.
173 .Pp
174 The names of
175 .Dq unsafe
176 macros (ones that have side effects), and the names of macros for
177 manifest constants, are all in uppercase.
178 The expansions of expression-like macros are either a single token
179 or have outer parentheses.
180 Put a single tab character between the
181 .Ic #define
182 and the macro name.
183 If a macro is an inline expansion of a function, the function name is
184 all in lowercase and the macro has the same name all in uppercase.
185 .\" XXX the above conflicts with ANSI style where the names are the
186 .\" same and you #undef the macro (if any) to get the function.
187 .\" It is not followed for MALLOC(), and not very common if inline
188 .\" functions are used.
189 Right-justify the
190 backslashes; it makes it easier to read.
191 If the macro encapsulates a compound statement, enclose it in a
192 .Ic do
193 loop,
194 so that it can safely be used in
195 .Ic if
196 statements.
197 Any final statement-terminating semicolon should be
198 supplied by the macro invocation rather than the macro, to make parsing easier
199 for pretty-printers and editors.
200 .Bd -literal
201 #define MACRO(x, y) do {                                                \e
202         variable = (x) + (y);                                           \e
203         (y) += 2;                                                       \e
204 } while (0)
205 .Ed
206 .Pp
207 When code is conditionally compiled using
208 .Ic #ifdef
209 or
210 .Ic #if ,
211 a comment may be added following the matching
212 .Ic #endif
213 or
214 .Ic #else
215 to permit the reader to easily discern where conditionally compiled code
216 regions end.
217 This comment should be used only for (subjectively) long regions, regions
218 greater than 20 lines, or where a series of nested
219 .Ic #ifdef 's
220 may be confusing to the reader.
221 Exceptions may be made for cases where code is conditionally not compiled for
222 the purposes of
223 .Xr lint 1 ,
224 even though the uncompiled region may be small.
225 The comment should be separated from the
226 .Ic #endif
227 or
228 .Ic #else
229 by a single space.
230 For short conditionally compiled regions, a closing comment should not be
231 used.
232 .Pp
233 The comment for
234 .Ic #endif
235 should match the expression used in the corresponding
236 .Ic #if
237 or
238 .Ic #ifdef .
239 The comment for
240 .Ic #else
241 and
242 .Ic #elif
243 should match the inverse of the expression(s) used in the preceding
244 .Ic #if
245 and/or
246 .Ic #elif
247 statements.
248 In the comments, the subexpression
249 .Dq Li defined(FOO)
250 is abbreviated as
251 .Dq Li FOO .
252 For the purposes of comments,
253 .Dq Ic #ifndef Li FOO
254 is treated as
255 .Dq Ic #if Li !defined(FOO) .
256 .Bd -literal
257 #ifdef KTRACE
258 #include <sys/ktrace.h>
259 #endif
260
261 #ifdef COMPAT_43
262 /* A large region here, or other conditional code. */
263 #else /* !COMPAT_43 */
264 /* Or here. */
265 #endif /* COMPAT_43 */
266
267 #ifndef COMPAT_43
268 /* Yet another large region here, or other conditional code. */
269 #else /* COMPAT_43 */
270 /* Or here. */
271 #endif /* !COMPAT_43 */
272 .Ed
273 .Pp
274 The project is slowly moving to use the
275 .St -isoC-99
276 unsigned integer identifiers of the form
277 .Vt uintXX_t
278 in preference to the older
279 .Bx Ns -style
280 integer identifiers of the form
281 .Vt u_intXX_t .
282 New code should use the former, and old code should be converted to
283 the new form if other major work is being done in that area and
284 there is no overriding reason to prefer the older
285 .Bx Ns -style .
286 Like white-space commits, care should be taken in making
287 .Vt uintXX_t
288 only commits.
289 .Pp
290 Enumeration values are all uppercase.
291 .Bd -literal
292 enum enumtype { ONE, TWO } et;
293 .Ed
294 .Pp
295 In declarations, do not put any whitespace between asterisks and
296 adjacent tokens, except for tokens that are identifiers related to
297 types.
298 (These identifiers are the names of basic types, type
299 qualifiers, and
300 .Ic typedef Ns -names
301 other than the one being declared.)
302 Separate these identifiers from asterisks using a single space.
303 .Pp
304 When declaring variables in structures, declare them sorted by use, then
305 by size (largest to smallest), and then in alphabetical order.
306 The first category normally does not apply, but there are exceptions.
307 Each one gets its own line.
308 Try to make the structure
309 readable by aligning the member names using either one or two tabs
310 depending upon your judgment.
311 You should use one tab only if it suffices to align at least 90% of
312 the member names.
313 Names following extremely long types
314 should be separated by a single space.
315 .Pp
316 Major structures should be declared at the top of the file in which they
317 are used, or in separate header files if they are used in multiple
318 source files.
319 Use of the structures should be by separate declarations
320 and should be
321 .Ic extern
322 if they are declared in a header file.
323 .Bd -literal
324 struct foo {
325         struct foo      *next;          /* List of active foo. */
326         struct mumble   amumble;        /* Comment for mumble. */
327         int             bar;            /* Try to align the comments. */
328         struct verylongtypename *baz;   /* Won't fit in 2 tabs. */
329 };
330 struct foo *foohead;                    /* Head of global foo list. */
331 .Ed
332 .Pp
333 Use
334 .Xr queue 3
335 macros rather than rolling your own lists, whenever possible.
336 Thus,
337 the previous example would be better written:
338 .Bd -literal
339 #include <sys/queue.h>
340
341 struct foo {
342         LIST_ENTRY(foo) link;           /* Use queue macros for foo lists. */
343         struct mumble   amumble;        /* Comment for mumble. */
344         int             bar;            /* Try to align the comments. */
345         struct verylongtypename *baz;   /* Won't fit in 2 tabs. */
346 };
347 LIST_HEAD(, foo) foohead;               /* Head of global foo list. */
348 .Ed
349 .Pp
350 Avoid using typedefs for structure types.
351 Typedefs are problematic because they do not properly hide their
352 underlying type; for example you need to know if the typedef is
353 the structure itself or a pointer to the structure.
354 In addition they must be declared exactly once, whereas an
355 incomplete structure type can be mentioned as many times as
356 necessary.
357 Typedefs are difficult to use in stand-alone header files:
358 the header that defines the typedef must be included
359 before the header that uses it, or by the header that uses
360 it (which causes namespace pollution), or there must be a
361 back-door mechanism for obtaining the typedef.
362 .Pp
363 When convention requires a
364 .Ic typedef ,
365 make its name match the struct tag.
366 Avoid typedefs ending in
367 .Dq Li _t ,
368 except as specified in Standard C or by
369 .Tn POSIX .
370 .Bd -literal
371 /* Make the structure name match the typedef. */
372 typedef struct bar {
373         int     level;
374 } BAR;
375 typedef int             foo;            /* This is foo. */
376 typedef const long      baz;            /* This is baz. */
377 .Ed
378 .Pp
379 All functions are prototyped somewhere.
380 .Pp
381 Function prototypes for private functions (i.e., functions not used
382 elsewhere) go at the top of the first source module.
383 Functions
384 local to one source module should be declared
385 .Ic static .
386 .Pp
387 Functions used from other parts of the kernel are prototyped in the
388 relevant include file.
389 Function prototypes should be listed in a logical order, preferably
390 alphabetical unless there is a compelling reason to use a different
391 ordering.
392 .Pp
393 Functions that are used locally in more than one module go into a
394 separate header file, e.g.\&
395 .Qq Pa extern.h .
396 .Pp
397 Do not use the
398 .Dv __P
399 macro.
400 .Pp
401 In general code can be considered
402 .Dq "new code"
403 when it makes up about 50% or more of the file(s) involved.
404 This is enough
405 to break precedents in the existing code and use the current
406 .Nm
407 guidelines.
408 .Pp
409 The kernel has a name associated with parameter types, e.g., in the kernel
410 use:
411 .Bd -literal
412 void    function(int fd);
413 .Ed
414 .Pp
415 In header files visible to userland applications, prototypes that are
416 visible must use either
417 .Dq protected
418 names (ones beginning with an underscore)
419 or no names with the types.
420 It is preferable to use protected names.
421 E.g., use:
422 .Bd -literal
423 void    function(int);
424 .Ed
425 .Pp
426 or:
427 .Bd -literal
428 void    function(int _fd);
429 .Ed
430 .Pp
431 Prototypes may have an extra space after a tab to enable function names
432 to line up:
433 .Bd -literal
434 static char     *function(int _arg, const char *_arg2, struct foo *_arg3,
435                     struct bar *_arg4);
436 static void      usage(void);
437
438 /*
439  * All major routines should have a comment briefly describing what
440  * they do.  The comment before the "main" routine should describe
441  * what the program does.
442  */
443 int
444 main(int argc, char *argv[])
445 {
446         char *ep;
447         long num;
448         int ch;
449 .Ed
450 .Pp
451 For consistency,
452 .Xr getopt 3
453 should be used to parse options.
454 Options
455 should be sorted in the
456 .Xr getopt 3
457 call and the
458 .Ic switch
459 statement, unless
460 parts of the
461 .Ic switch
462 cascade.
463 Elements in a
464 .Ic switch
465 statement that cascade should have a
466 .Li FALLTHROUGH
467 comment.
468 Numerical arguments should be checked for accuracy.
469 Code that cannot be reached should have a
470 .Li NOTREACHED
471 comment.
472 .Bd -literal
473         while ((ch = getopt(argc, argv, "abNn:")) != -1)
474                 switch (ch) {           /* Indent the switch. */
475                 case 'a':               /* Don't indent the case. */
476                         aflag = 1;      /* Indent case body one tab. */
477                         /* FALLTHROUGH */
478                 case 'b':
479                         bflag = 1;
480                         break;
481                 case 'N':
482                         Nflag = 1;
483                         break;
484                 case 'n':
485                         num = strtol(optarg, &ep, 10);
486                         if (num <= 0 || *ep != '\e0') {
487                                 warnx("illegal number, -n argument -- %s",
488                                     optarg);
489                                 usage();
490                         }
491                         break;
492                 case '?':
493                 default:
494                         usage();
495                         /* NOTREACHED */
496                 }
497         argc -= optind;
498         argv += optind;
499 .Ed
500 .Pp
501 Space after keywords
502 .Pq Ic if , while , for , return , switch .
503 No braces
504 .Ql ( \&{
505 and
506 .Ql \&} )
507 are
508 used for control statements with zero or only a single statement unless that
509 statement is more than a single line in which case they are permitted.
510 Forever loops are done with
511 .Ic for Ns 's ,
512 not
513 .Ic while Ns 's .
514 .Bd -literal
515         for (p = buf; *p != '\e0'; ++p)
516                 ;       /* nothing */
517         for (;;)
518                 stmt;
519         for (;;) {
520                 z = a + really + long + statement + that + needs +
521                     two + lines + gets + indented + four + spaces +
522                     on + the + second + and + subsequent + lines;
523         }
524         for (;;) {
525                 if (cond)
526                         stmt;
527         }
528         if (val != NULL)
529                 val = realloc(val, newsize);
530 .Ed
531 .Pp
532 Parts of a
533 .Ic for
534 loop may be left empty.
535 Do not put declarations
536 inside blocks unless the routine is unusually complicated.
537 .Bd -literal
538         for (; cnt < 15; cnt++) {
539                 stmt1;
540                 stmt2;
541         }
542 .Ed
543 .Pp
544 Indentation is an 8 character tab.
545 Second level indents are four spaces.
546 If you have to wrap a long statement, put the operator at the end of the
547 line.
548 .Bd -literal
549         while (cnt < 20 && this_variable_name_is_too_long &&
550             ep != NULL)
551                 z = a + really + long + statement + that + needs +
552                     two + lines + gets + indented + four + spaces +
553                     on + the + second + and + subsequent + lines;
554 .Ed
555 .Pp
556 Do not add whitespace at the end of a line, and only use tabs
557 followed by spaces
558 to form the indentation.
559 Do not use more spaces than a tab will produce
560 and do not use spaces in front of tabs.
561 .Pp
562 Closing and opening braces go on the same line as the
563 .Ic else .
564 Braces that are not necessary may be left out.
565 .Bd -literal
566         if (test)
567                 stmt;
568         else if (bar) {
569                 stmt;
570                 stmt;
571         } else
572                 stmt;
573 .Ed
574 .Pp
575 No spaces after function names.
576 Commas have a space after them.
577 No spaces
578 after
579 .Ql \&(
580 or
581 .Ql \&[
582 or preceding
583 .Ql \&]
584 or
585 .Ql \&)
586 characters.
587 .Bd -literal
588         error = function(a1, a2);
589         if (error != 0)
590                 exit(error);
591 .Ed
592 .Pp
593 Unary operators do not require spaces, binary operators do.
594 Do not use parentheses unless they are required for precedence or unless the
595 statement is confusing without them.
596 Remember that other people may
597 confuse easier than you.
598 Do YOU understand the following?
599 .Bd -literal
600         a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1;
601         k = !(l & FLAGS);
602 .Ed
603 .Pp
604 Exits should be 0 on success, or according to the predefined
605 values in
606 .Xr sysexits 3 .
607 .Bd -literal
608         exit(EX_OK);    /*
609                          * Avoid obvious comments such as
610                          * "Exit 0 on success."
611                          */
612 }
613 .Ed
614 .Pp
615 The function type should be on a line by itself
616 preceding the function.
617 The opening brace of the function body should be
618 on a line by itself.
619 .Bd -literal
620 static char *
621 function(int a1, int a2, float fl, int a4)
622 {
623 .Ed
624 .Pp
625 When declaring variables in functions declare them sorted by size,
626 then in alphabetical order; multiple ones per line are okay.
627 If a line overflows reuse the type keyword.
628 .Pp
629 Be careful to not obfuscate the code by initializing variables in
630 the declarations.
631 Use this feature only thoughtfully.
632 DO NOT use function calls in initializers.
633 .Bd -literal
634         struct foo one, *two;
635         double three;
636         int *four, five;
637         char *six, seven, eight, nine, ten, eleven, twelve;
638
639         four = myfunction();
640 .Ed
641 .Pp
642 Do not declare functions inside other functions; ANSI C says that
643 such declarations have file scope regardless of the nesting of the
644 declaration.
645 Hiding file declarations in what appears to be a local
646 scope is undesirable and will elicit complaints from a good compiler.
647 .Pp
648 Casts and
649 .Ic sizeof Ns 's
650 are not followed by a space.
651 Note that
652 .Xr indent 1
653 does not understand this rule.
654 .Ic sizeof Ns 's
655 are written with parenthesis always.
656 The redundant parenthesis rules do not apply to
657 .Fn sizeof var
658 instances.
659 .Pp
660 .Dv NULL
661 is the preferred null pointer constant.
662 Use
663 .Dv NULL
664 instead of
665 .Vt ( "type *" ) Ns 0
666 or
667 .Vt ( "type *" ) Ns Dv NULL
668 in contexts where the compiler knows the
669 type, e.g., in assignments.
670 Use
671 .Vt ( "type *" ) Ns Dv NULL
672 in other contexts,
673 in particular for all function args.
674 (Casting is essential for
675 variadic args and is necessary for other args if the function prototype
676 might not be in scope.)
677 Test pointers against
678 .Dv NULL ,
679 e.g., use:
680 .Pp
681 .Bd -literal
682 (p = f()) == NULL
683 .Ed
684 .Pp
685 not:
686 .Bd -literal
687 !(p = f())
688 .Ed
689 .Pp
690 Do not use
691 .Ic \&!
692 for tests unless it is a boolean, e.g.\& use:
693 .Bd -literal
694 if (*p == '\e0')
695 .Ed
696 .Pp
697 not:
698 .Bd -literal
699 if (!*p)
700 .Ed
701 .Pp
702 Routines returning
703 .Vt "void *"
704 should not have their return values cast
705 to any pointer type.
706 .Pp
707 Values in
708 .Ic return
709 statements should be enclosed in parentheses.
710 .Pp
711 Use
712 .Xr err 3
713 or
714 .Xr warn 3 ,
715 do not roll your own.
716 .Bd -literal
717         if ((four = malloc(sizeof(struct foo))) == NULL)
718                 err(1, (char *)NULL);
719         if ((six = (int *)overflow()) == NULL)
720                 errx(1, "number overflowed");
721         return (eight);
722 }
723 .Ed
724 .Pp
725 Old-style function declarations look like this:
726 .Bd -literal
727 static char *
728 function(a1, a2, fl, a4)
729         int a1, a2;     /* Declare ints, too, don't default them. */
730         float fl;       /* Beware double vs. float prototype differences. */
731         int a4;         /* List in order declared. */
732 {
733 .Ed
734 .Pp
735 Use ANSI function declarations unless you explicitly need K&R compatibility.
736 Long parameter lists are wrapped with a normal four space indent.
737 .Pp
738 Variable numbers of arguments should look like this:
739 .Bd -literal
740 #include <stdarg.h>
741
742 void
743 vaf(const char *fmt, ...)
744 {
745         va_list ap;
746
747         va_start(ap, fmt);
748         STUFF;
749         va_end(ap);
750         /* No return needed for void functions. */
751 }
752
753 static void
754 usage()
755 {
756         /* Insert an empty line if the function has no local variables. */
757 .Ed
758 .Pp
759 Use
760 .Xr printf 3 ,
761 not
762 .Xr fputs 3 ,
763 .Xr puts 3 ,
764 .Xr putchar 3 ,
765 whatever; it is faster and usually cleaner, not
766 to mention avoiding stupid bugs.
767 .Pp
768 Usage statements should look like the manual pages
769 .Sx SYNOPSIS .
770 The usage statement should be structured in the following order:
771 .Bl -enum
772 .It
773 Options without operands come first,
774 in alphabetical order,
775 inside a single set of brackets
776 .Ql ( \&[
777 and
778 .Ql \&] ) .
779 .It
780 Options with operands come next,
781 also in alphabetical order,
782 with each option and its argument inside its own pair of brackets.
783 .It
784 Required arguments
785 (if any)
786 are next,
787 listed in the order they should be specified on the command line.
788 .It
789 Finally,
790 any optional arguments should be listed,
791 listed in the order they should be specified,
792 and all inside brackets.
793 .El
794 .Pp
795 A bar
796 .Pq Ql \&|
797 separates
798 .Dq either-or
799 options/arguments,
800 and multiple options/arguments which are specified together are
801 placed in a single set of brackets.
802 .Bd -literal -offset 4n
803 "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\en"
804 "usage: f [-a | -b] [-c [-dEe] [-n number]]\en"
805 .Ed
806 .Bd -literal
807         (void)fprintf(stderr, "usage: f [-ab]\en");
808         exit(EX_USAGE);
809 }
810 .Ed
811 .Pp
812 Note that the manual page options description should list the options in
813 pure alphabetical order.
814 That is, without regard to whether an option takes arguments or not.
815 The alphabetical ordering should take into account the case ordering
816 shown above.
817 .Pp
818 New core kernel code should be reasonably compliant with the
819 .Nm
820 guides.
821 The guidelines for third-party maintained modules and device drivers are more
822 relaxed but at a minimum should be internally consistent with their style.
823 .Pp
824 Stylistic changes (including whitespace changes) are hard on the source
825 repository and are to be avoided without good reason.
826 Code that is approximately
827 .Fx
828 KNF
829 .Nm
830 compliant in the repository must not diverge from compliance.
831 .Pp
832 Whenever possible, code should be run through a code checker
833 (e.g.,
834 .Xr lint 1
835 or
836 .Nm gcc Fl Wall )
837 and produce minimal warnings.
838 .Sh SEE ALSO
839 .Xr indent 1 ,
840 .Xr lint 1 ,
841 .Xr err 3 ,
842 .Xr sysexits 3 ,
843 .Xr warn 3 ,
844 .Xr style.Makefile 5
845 .Sh HISTORY
846 This manual page is largely based on the
847 .Pa src/admin/style/style
848 file from the
849 .Bx 4.4 Lite2
850 release, with occasional updates to reflect the current practice and
851 desire of the
852 .Fx
853 project.