style revision 1.74
11.74Srillig/* $NetBSD: style,v 1.74 2023/04/21 16:12:53 rillig Exp $ */
21.6Sthorpej
31.1Scgd/*
41.12Slukem * The revision control tag appears first, with a blank line after it.
51.12Slukem * Copyright text appears after the revision control tag.
61.12Slukem */
71.12Slukem
81.12Slukem/*
91.12Slukem * The NetBSD source code style guide.
101.12Slukem * (Previously known as KNF - Kernel Normal Form).
111.1Scgd *
121.2Scgd *	from: @(#)style	1.12 (Berkeley) 3/18/94
131.10Sscottr */
141.10Sscottr/*
151.10Sscottr * An indent(1) profile approximating the style outlined in
161.10Sscottr * this document lives in /usr/share/misc/indent.pro.  It is a
171.10Sscottr * useful tool to assist in converting code to KNF, but indent(1)
181.10Sscottr * output generated using this profile must not be considered to
191.10Sscottr * be an authoritative reference.
201.1Scgd */
211.1Scgd
221.1Scgd/*
231.12Slukem * Source code revision control identifiers appear after any copyright
241.12Slukem * text.  Use the appropriate macros from <sys/cdefs.h>.  Usually only one
251.12Slukem * source file per program contains a __COPYRIGHT() section.
261.12Slukem * Historic Berkeley code may also have an __SCCSID() section.
271.12Slukem * Only one instance of each of these macros can occur in each file.
281.43Slukem * Don't use newlines in the identifiers.
291.12Slukem */
301.12Slukem#include <sys/cdefs.h>
311.43Slukem__COPYRIGHT("@(#) Copyright (c) 2008\
321.43Slukem The NetBSD Foundation, inc. All rights reserved.");
331.74Srillig__RCSID("$NetBSD: style,v 1.74 2023/04/21 16:12:53 rillig Exp $");
341.12Slukem
351.12Slukem/*
361.1Scgd * VERY important single-line comments look like this.
371.1Scgd */
381.1Scgd
391.1Scgd/* Most single-line comments look like this. */
401.1Scgd
411.1Scgd/*
421.1Scgd * Multi-line comments look like this.  Make them real sentences.  Fill
431.1Scgd * them so they look like real paragraphs.
441.1Scgd */
451.1Scgd
461.2Scgd/*
471.12Slukem * Attempt to wrap lines longer than 80 characters appropriately.
481.12Slukem * Refer to the examples below for more information.
491.12Slukem */
501.12Slukem
511.12Slukem/*
521.12Slukem * EXAMPLE HEADER FILE:
531.12Slukem *
541.12Slukem * A header file should protect itself against multiple inclusion.
551.12Slukem * E.g, <sys/socket.h> would contain something like:
561.12Slukem */
571.12Slukem#ifndef _SYS_SOCKET_H_
581.12Slukem#define _SYS_SOCKET_H_
591.69Sriastrad
601.69Sriastrad/*
611.69Sriastrad * extern declarations must only appear in header files, not in .c
621.69Sriastrad * files, so the same declaration is used by the .c file defining it
631.69Sriastrad * and the .c file using it, giving the compiler the opportunity to
641.69Sriastrad * detect type errors.
651.69Sriastrad *
661.69Sriastrad * extern function declarations should not use the extern keyword,
671.69Sriastrad * which is unnecessary.
681.69Sriastrad *
691.69Sriastrad * Exception: A subroutine written in assembly in an adjacent .S file,
701.69Sriastrad * which is used only in one .c file, may be declared in the .c file.
711.69Sriastrad */
721.69Sriastradextern int frotz;
731.69Sriastrad
741.69Sriastradint frobnicate(const char *);
751.69Sriastrad
761.12Slukem/*
771.12Slukem * Contents of #include file go between the #ifndef and the #endif at the end.
781.12Slukem */
791.12Slukem#endif /* !_SYS_SOCKET_H_ */
801.12Slukem/*
811.12Slukem * END OF EXAMPLE HEADER FILE.
821.12Slukem */
831.12Slukem
841.12Slukem/*
851.39Sdarcy * If a header file requires structures, defines, typedefs, etc. from
861.39Sdarcy * another header file it should include that header file and not depend
871.39Sdarcy * on the including file for that header including both.  If there are
881.39Sdarcy * exceptions to this for specific headers it should be clearly documented
891.39Sdarcy * in the headers and, if appropriate, the documentation.  Nothing in this
901.39Sdarcy * rule should suggest relaxation of the multiple inclusion rule and the
911.39Sdarcy * application programmer should be free to include both regardless.
921.39Sdarcy */
931.39Sdarcy
941.39Sdarcy/*
951.12Slukem * Kernel include files come first.
961.2Scgd */
971.50Sriastrad#include <sys/param.h>		/* <sys/param.h> first, */
981.50Sriastrad#include <sys/types.h>		/*   <sys/types.h> next, */
991.50Sriastrad#include <sys/ioctl.h>		/*   and then the rest, */
1001.50Sriastrad#include <sys/socket.h>		/*   sorted lexicographically.  */
1011.50Sriastrad#include <sys/stat.h>
1021.50Sriastrad#include <sys/wait.h>		/* Non-local includes in brackets.  */
1031.2Scgd
1041.12Slukem/*
1051.12Slukem * If it's a network program, put the network include files next.
1061.60Srillig * Group the include files by subdirectory.
1071.12Slukem */
1081.2Scgd#include <net/if.h>
1091.2Scgd#include <net/if_dl.h>
1101.2Scgd#include <net/route.h>
1111.2Scgd#include <netinet/in.h>
1121.2Scgd#include <protocols/rwhod.h>
1131.2Scgd
1141.2Scgd/*
1151.2Scgd * Then there's a blank line, followed by the /usr include files.
1161.50Sriastrad * The /usr include files should be sorted lexicographically!
1171.2Scgd */
1181.20Skleink#include <assert.h>
1191.25Slukem#include <errno.h>
1201.36Sbriggs#include <inttypes.h>
1211.2Scgd#include <stdio.h>
1221.18Scgd#include <stdlib.h>
1231.1Scgd
1241.1Scgd/*
1251.1Scgd * Global pathnames are defined in /usr/include/paths.h.  Pathnames local
1261.1Scgd * to the program go in pathnames.h in the local directory.
1271.1Scgd */
1281.2Scgd#include <paths.h>
1291.2Scgd
1301.2Scgd/* Then, there's a blank line, and the user include files. */
1311.12Slukem#include "pathnames.h"		/* Local includes in double quotes. */
1321.1Scgd
1331.1Scgd/*
1341.74Srillig * Declarations for file-static functions go at the top of the file.
1351.74Srillig * Don't associate a name with the parameter types.  I.e. use:
1361.12Slukem *	void function(int);
1371.12Slukem * Use your discretion on indenting between the return type and the name, and
1381.12Slukem * how to wrap a prototype too long for a single line.  In the latter case,
1391.15Slukem * lining up under the initial left parenthesis may be more readable.
1401.12Slukem * In any case, consistency is important!
1411.12Slukem */
1421.12Slukemstatic char *function(int, int, float, int);
1431.12Slukemstatic int dirinfo(const char *, struct stat *, struct dirent *,
1441.12Slukem		   struct statfs *, int *, char **[]);
1451.47Schristosstatic void usage(void) __dead;	/* declare functions that don't return dead */
1461.1Scgd
1471.1Scgd/*
1481.1Scgd * Macros are capitalized, parenthesized, and should avoid side-effects.
1491.22Sjhawk * Spacing before and after the macro name may be any whitespace, though
1501.22Sjhawk * use of TABs should be consistent through a file.
1511.1Scgd * If they are an inline expansion of a function, the function is defined
1521.12Slukem * all in lowercase, the macro has the same name all in uppercase.
1531.72Srillig * If the macro is an expression, wrap the expression in parentheses.
1541.64Srillig * If the macro is more than a single statement, use ``do { ... } while (0)''
1551.64Srillig * or ``do { ... } while (false)'', so that a trailing semicolon works.
1561.64Srillig * Right-justify the backslashes; it makes it easier to read.
1571.12Slukem */
1581.12Slukem#define	MACRO(v, w, x, y)						\
1591.12Slukemdo {									\
1601.12Slukem	v = (x) + (y);							\
1611.12Slukem	w = (y) + 2;							\
1621.64Srillig} while (0)
1631.12Slukem
1641.15Slukem#define	DOUBLE(x) ((x) * 2)
1651.12Slukem
1661.55Srillig/* Enum constants are capitalized.  No comma on the last element. */
1671.12Slukemenum enumtype {
1681.12Slukem	ONE,
1691.12Slukem	TWO
1701.63Srillig};
1711.12Slukem
1721.12Slukem/*
1731.54Schristos * Sometimes we want a macro to be conditionally defined for debugging
1741.54Schristos * and expand to nothing (but still as statement) when we are not debugging:
1751.54Schristos */
1761.54Schristos#ifdef FOO_DEBUG
1771.54Schristos# define DPRINTF(...) printf(__VA_ARGS__)
1781.54Schristos#else
1791.54Schristos# define DPRINTF(...) __nothing
1801.54Schristos#endif
1811.54Schristos
1821.54Schristos/*
1831.16Senami * When declaring variables in structures, declare them organized by use in
1841.16Senami * a manner to attempt to minimize memory wastage because of compiler alignment
1851.12Slukem * issues, then by size, and then by alphabetical order. E.g, don't use
1861.12Slukem * ``int a; char *b; int c; char *d''; use ``int a; int b; char *c; char *d''.
1871.12Slukem * Each variable gets its own type and line, although an exception can be made
1881.12Slukem * when declaring bitfields (to clarify that it's part of the one bitfield).
1891.12Slukem * Note that the use of bitfields in general is discouraged.
1901.1Scgd *
1911.2Scgd * Major structures should be declared at the top of the file in which they
1921.2Scgd * are used, or in separate header files, if they are used in multiple
1931.2Scgd * source files.  Use of the structures should be by separate declarations
1941.1Scgd * and should be "extern" if they are declared in a header file.
1951.12Slukem *
1961.12Slukem * It may be useful to use a meaningful prefix for each member name.
1971.12Slukem * E.g, for ``struct softc'' the prefix could be ``sc_''.
1981.1Scgd */
1991.1Scgdstruct foo {
2001.12Slukem	struct foo *next;	/* List of active foo */
2011.12Slukem	struct mumble amumble;	/* Comment for mumble */
2021.12Slukem	int bar;
2031.12Slukem	unsigned int baz:1,	/* Bitfield; line up entries if desired */
2041.12Slukem		     fuz:5,
2051.12Slukem		     zap:2;
2061.27Ssimonb	uint8_t flag;
2071.1Scgd};
2081.1Scgdstruct foo *foohead;		/* Head of global foo list */
2091.2Scgd
2101.2Scgd/* Make the structure name match the typedef. */
2111.12Slukemtypedef struct BAR {
2121.12Slukem	int level;
2131.2Scgd} BAR;
2141.12Slukem
2151.32Sjunyoung/* C99 uintN_t is preferred over u_intN_t. */
2161.32Sjunyounguint32_t zero;
2171.32Sjunyoung
2181.1Scgd/*
2191.1Scgd * All major routines should have a comment briefly describing what
2201.2Scgd * they do.  The comment before the "main" routine should describe
2211.1Scgd * what the program does.
2221.1Scgd */
2231.2Scgdint
2241.12Slukemmain(int argc, char *argv[])
2251.1Scgd{
2261.1Scgd	long num;
2271.1Scgd	int ch;
2281.1Scgd	char *ep;
2291.1Scgd
2301.1Scgd	/*
2311.17Scgd	 * At the start of main(), call setprogname() to set the program
2321.17Scgd	 * name.  This does nothing on NetBSD, but increases portability
2331.17Scgd	 * to other systems.
2341.17Scgd	 */
2351.17Scgd	setprogname(argv[0]);
2361.17Scgd
2371.17Scgd	/*
2381.37Swiz	 * For consistency, getopt should be used to parse options.
2391.37Swiz	 * Options should be sorted in the getopt call and the switch
2401.37Swiz	 * statement, unless parts of the switch cascade.  For the
2411.37Swiz	 * sorting order, see the usage() example below.  Don't forget
2421.37Swiz	 * to add option descriptions to the usage and the manpage.
2431.37Swiz	 * Elements in a switch statement that cascade should have a
2441.37Swiz	 * FALLTHROUGH comment.  Numerical arguments should be checked
2451.37Swiz	 * for accuracy.  Code that cannot be reached should have a
2461.37Swiz	 * NOTREACHED comment.
2471.1Scgd	 */
2481.41Splunky	while ((ch = getopt(argc, argv, "abn:")) != -1) {
2491.1Scgd		switch (ch) {		/* Indent the switch. */
2501.1Scgd		case 'a':		/* Don't indent the case. */
2511.1Scgd			aflag = 1;
2521.1Scgd			/* FALLTHROUGH */
2531.1Scgd		case 'b':
2541.1Scgd			bflag = 1;
2551.1Scgd			break;
2561.1Scgd		case 'n':
2571.25Slukem			errno = 0;
2581.1Scgd			num = strtol(optarg, &ep, 10);
2591.25Slukem			if (num <= 0 || *ep != '\0' || (errno == ERANGE &&
2601.58Sriastrad			    (num == LONG_MAX || num == LONG_MIN)) ) {
2611.12Slukem				errx(1, "illegal number -- %s", optarg);
2621.58Sriastrad			}
2631.1Scgd			break;
2641.1Scgd		case '?':
2651.1Scgd		default:
2661.1Scgd			usage();
2671.2Scgd			/* NOTREACHED */
2681.1Scgd		}
2691.12Slukem	}
2701.1Scgd	argc -= optind;
2711.1Scgd	argv += optind;
2721.1Scgd
2731.1Scgd	/*
2741.58Sriastrad	 * Space after keywords (while, for, return, switch).
2751.58Sriastrad	 *
2761.58Sriastrad	 * Braces around single-line bodies are optional; use discretion.
2771.1Scgd	 *
2781.66Sjkoshy	 * Use narrow scopes for loop variables where possible.
2791.1Scgd	 */
2801.66Sjkoshy	for (char *p = buf; *p != '\0'; ++p)
2811.12Slukem		continue;		/* Explicit no-op */
2821.67Sjkoshy
2831.67Sjkoshy	/*
2841.67Sjkoshy	 * Forever loops are done with for's, not while's.
2851.67Sjkoshy	 */
2861.57Slukem	for (;;)
2871.1Scgd		stmt;
2881.12Slukem
2891.1Scgd	/*
2901.2Scgd	 * Parts of a for loop may be left empty.  Don't put declarations
2911.2Scgd	 * inside blocks unless the routine is unusually complicated.
2921.1Scgd	 */
2931.1Scgd	for (; cnt < 15; cnt++) {
2941.1Scgd		stmt1;
2951.1Scgd		stmt2;
2961.1Scgd	}
2971.1Scgd
2981.2Scgd	/* Second level indents are four spaces. */
2991.58Sriastrad	while (cnt < 20) {
3001.40Schristos		z = a + really + long + statement + that + needs + two + lines +
3011.1Scgd		    gets + indented + four + spaces + on + the + second +
3021.7Senami		    and + subsequent + lines;
3031.58Sriastrad	}
3041.1Scgd
3051.1Scgd	/*
3061.2Scgd	 * Closing and opening braces go on the same line as the else.
3071.1Scgd	 */
3081.12Slukem	if (test) {
3091.12Slukem		/*
3101.12Slukem		 * I have a long comment here.
3111.12Slukem		 */
3121.12Slukem#ifdef zorro
3131.12Slukem		z = 1;
3141.12Slukem#else
3151.12Slukem		b = 3;
3161.12Slukem#endif
3171.12Slukem	} else if (bar) {
3181.1Scgd		stmt;
3191.1Scgd		stmt;
3201.58Sriastrad	} else {
3211.1Scgd		stmt;
3221.58Sriastrad	}
3231.12Slukem
3241.2Scgd	/* No spaces after function names. */
3251.57Slukem	if ((result = function(a1, a2, a3, a4)) == NULL)
3261.68Sjschauma		exit(EXIT_FAILURE);
3271.1Scgd
3281.1Scgd	/*
3291.12Slukem	 * Unary operators don't require spaces, binary operators do.
3301.72Srillig	 * Don't excessively use parentheses, but they should be used if a
3311.9Slukem	 * statement is really confusing without them, such as:
3321.9Slukem	 * a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1;
3331.1Scgd	 */
3341.9Slukem	a = ((b->c[0] + ~d == (e || f)) || (g && h)) ? i : (j >> 1);
3351.2Scgd	k = !(l & FLAGS);
3361.1Scgd
3371.1Scgd	/*
3381.26Sjmmv	 * Exits should be EXIT_SUCCESS on success, and EXIT_FAILURE on
3391.26Sjmmv	 * failure.  Don't denote all the possible exit points, using the
3401.29Schristos	 * integers 1 through 127.  Avoid obvious comments such as "Exit
3411.29Schristos	 * 0 on success.". Since main is a function that returns an int,
3421.29Schristos	 * prefer returning from it, than calling exit.
3431.1Scgd	 */
3441.29Schristos	return EXIT_SUCCESS;
3451.1Scgd}
3461.1Scgd
3471.1Scgd/*
3481.8Ssimonb * The function type must be declared on a line by itself
3491.16Senami * preceding the function.
3501.1Scgd */
3511.1Scgdstatic char *
3521.12Slukemfunction(int a1, int a2, float fl, int a4)
3531.1Scgd{
3541.1Scgd	/*
3551.71Srillig	 * When declaring variables in functions, multiple variables per line
3561.71Srillig	 * are okay. If a line overflows reuse the type keyword.
3571.71Srillig	 *
3581.73Sdholland	 * Function prototypes and external data declarations should go in a
3591.73Sdholland	 * suitable include file.
3601.1Scgd	 *
3611.52Schristos	 * Avoid initializing variables in the declarations; move
3621.52Schristos	 * declarations next to their first use, and initialize
3631.52Schristos	 * opportunistically. This avoids over-initialization and
3641.52Schristos	 * accidental bugs caused by declaration reordering.
3651.1Scgd	 */
3661.1Scgd	struct foo three, *four;
3671.1Scgd	double five;
3681.12Slukem	int *six, seven;
3691.12Slukem	char *eight, *nine, ten, eleven, twelve, thirteen;
3701.12Slukem	char fourteen, fifteen, sixteen;
3711.1Scgd
3721.1Scgd	/*
3731.62Schristos	 * Casts and sizeof's are not followed by a space.
3741.62Schristos	 *
3751.62Schristos	 * We parenthesize sizeof expressions to clarify their precedence:
3761.62Schristos	 *
3771.62Schristos	 * 	sizeof(e) + 4
3781.62Schristos	 * not:
3791.62Schristos	 *	sizeof e + 4
3801.62Schristos	 *
3811.62Schristos	 * We don't put a space before the parenthesis so that it looks like
3821.62Schristos	 * a function call. We always parenthesize the sizeof expression for
3831.62Schristos	 * consistency.
3841.62Schristos	 *
3851.62Schristos	 * On the other hand, we don't parenthesize the return statement
3861.62Schristos	 * because there is never a precedence ambiguity situation (it is
3871.62Schristos	 * a single statement).
3881.62Schristos	 *
3891.62Schristos	 * NULL is any pointer type, and doesn't need to be cast, so use
3901.62Schristos	 * NULL instead of (struct foo *)0 or (struct foo *)NULL.  Also,
3911.62Schristos	 * test pointers against NULL because it indicates the type of the
3921.62Schristos	 * expression to the user. I.e. use:
3931.1Scgd	 *
3941.12Slukem	 *	(p = f()) == NULL
3951.1Scgd	 * not:
3961.1Scgd	 *	!(p = f())
3971.2Scgd	 *
3981.51Schristos	 * The notable exception here is variadic functions. Since our
3991.49Schristos	 * code is designed to compile and work on different environments
4001.49Schristos	 * where we don't have control over the NULL definition (on NetBSD
4011.49Schristos	 * it is defined as ((void *)0), but on other systems it can be
4021.74Srillig	 * defined as (0) and both definitions are valid), it
4031.53Ssalazar	 * it advised to cast NULL to a pointer on variadic functions,
4041.49Schristos	 * because on machines where sizeof(pointer) != sizeof(int) and in
4051.49Schristos	 * the absence of a prototype in scope, passing an un-casted NULL,
4061.49Schristos	 * will result in passing an int on the stack instead of a pointer.
4071.49Schristos	 *
4081.12Slukem	 * Don't use `!' for tests unless it's a boolean.
4091.12Slukem	 * E.g. use "if (*p == '\0')", not "if (!*p)".
4101.12Slukem	 *
4111.31Schristos	 * Routines returning ``void *'' should not have their return
4121.31Schristos	 * values cast to more specific pointer types.
4131.2Scgd	 *
4141.46Schristos	 * Prefer sizeof(*var) over sizeof(type) because if type changes,
4151.46Schristos	 * the change needs to be done in one place.
4161.46Schristos	 *
4171.2Scgd	 * Use err/warn(3), don't roll your own!
4181.61Schristos	 *
4191.61Schristos	 * Prefer EXIT_FAILURE instead of random error codes.
4201.1Scgd	 */
4211.57Slukem	if ((four = malloc(sizeof(*four))) == NULL)
4221.61Schristos		err(EXIT_FAILURE, NULL);
4231.57Slukem	if ((six = (int *)overflow()) == NULL)
4241.61Schristos		errx(EXIT_FAILURE, "Number overflowed.");
4251.23Sfvdl
4261.23Sfvdl	/* No parentheses are needed around the return value. */
4271.23Sfvdl	return eight;
4281.1Scgd}
4291.1Scgd
4301.2Scgd/*
4311.74Srillig * Place the opening brace of a function body in column 1.
4321.12Slukem * As per the wrapped prototypes, use your discretion on how to format
4331.12Slukem * the subsequent lines.
4341.12Slukem */
4351.12Slukemstatic int
4361.12Slukemdirinfo(const char *p, struct stat *sb, struct dirent *de, struct statfs *sf,
4371.12Slukem	int *rargc, char **rargv[])
4381.12Slukem{	/* Insert an empty line if the function has no local variables. */
4391.19Skleink
4401.19Skleink	/*
4411.19Skleink	 * In system libraries, catch obviously invalid function arguments
4421.19Skleink	 * using _DIAGASSERT(3).
4431.19Skleink	 */
4441.19Skleink	_DIAGASSERT(p != NULL);
4451.19Skleink	_DIAGASSERT(filedesc != -1);
4461.12Slukem
4471.61Schristos	/* Prefer checking syscalls against -1 instead of < 0 */
4481.61Schristos	if (stat(p, sb) == -1)
4491.61Schristos		err(EXIT_FAILURE, "Unable to stat %s", p);
4501.14Slukem
4511.14Slukem	/*
4521.61Schristos	 * To printf quantities that might be larger than "long",
4531.65Sjkoshy	 * cast quantities to intmax_t or uintmax_t and use %j.
4541.36Sbriggs	 */
4551.61Schristos	(void)printf("The size of %s is %jd (%#ju)\n", p,
4561.36Sbriggs	    (intmax_t)sb->st_size, (uintmax_t)sb->st_size);
4571.36Sbriggs
4581.36Sbriggs	/*
4591.61Schristos	 * To printf quantities of known bit-width, include <inttypes.h> and
4601.61Schristos	 * use the corresponding defines (generally only done within NetBSD
4611.61Schristos	 * for quantities that exceed 32-bits).
4621.36Sbriggs	 */
4631.36Sbriggs	(void)printf("%s uses %" PRId64 " blocks and has flags %#" PRIx32 "\n",
4641.36Sbriggs	    p, sb->st_blocks, sb->st_flags);
4651.36Sbriggs
4661.36Sbriggs	/*
4671.36Sbriggs	 * There are similar constants that should be used with the *scanf(3)
4681.36Sbriggs	 * family of functions: SCN?MAX, SCN?64, etc.
4691.14Slukem	 */
4701.2Scgd}
4711.2Scgd
4721.12Slukem/*
4731.12Slukem * Functions that support variable numbers of arguments should look like this.
4741.12Slukem * (With the #include <stdarg.h> appearing at the top of the file with the
4751.44Sjschauma * other include files.)
4761.12Slukem */
4771.2Scgd#include <stdarg.h>
4781.2Scgd
4791.2Scgdvoid
4801.2Scgdvaf(const char *fmt, ...)
4811.2Scgd{
4821.2Scgd	va_list ap;
4831.12Slukem
4841.2Scgd	va_start(ap, fmt);
4851.2Scgd	STUFF;
4861.45Sdholland	va_end(ap);
4871.12Slukem				/* No return needed for void functions. */
4881.1Scgd}
4891.1Scgd
4901.1Scgdstatic void
4911.12Slukemusage(void)
4921.12Slukem{
4931.1Scgd
4941.1Scgd	/*
4951.1Scgd	 * Use printf(3), not fputs/puts/putchar/whatever, it's faster and
4961.1Scgd	 * usually cleaner, not to mention avoiding stupid bugs.
4971.12Slukem	 * Use snprintf(3) or strlcpy(3)/strlcat(3) instead of sprintf(3);
4981.12Slukem	 * again to avoid stupid bugs.
4991.1Scgd	 *
5001.37Swiz	 * Usage statements should look like the manual pages.
5011.37Swiz	 * Options w/o operands come first, in alphabetical order
5021.37Swiz	 * inside a single set of braces, upper case before lower case
5031.37Swiz	 * (AaBbCc...).  Next are options with operands, in the same
5041.37Swiz	 * order, each in braces.  Then required arguments in the
5051.37Swiz	 * order they are specified, followed by optional arguments in
5061.37Swiz	 * the order they are specified.  A bar (`|') separates
5071.37Swiz	 * either/or options/arguments, and multiple options/arguments
5081.37Swiz	 * which are specified together are placed in a single set of
5091.37Swiz	 * braces.
5101.1Scgd	 *
5111.17Scgd	 * Use getprogname() instead of hardcoding the program name.
5121.12Slukem	 *
5131.37Swiz	 * "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
5141.1Scgd	 * "usage: f [-a | -b] [-c [-de] [-n number]]\n"
5151.1Scgd	 */
5161.17Scgd	(void)fprintf(stderr, "usage: %s [-ab]\n", getprogname());
5171.33Srillig	exit(EXIT_FAILURE);
5181.1Scgd}
519