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