version 1.2, 1994/03/26 03:24:54 |
version 1.11, 1999/07/03 21:47:21 |
|
|
|
/* $NetBSD$ */ |
|
|
/* |
/* |
* Style guide for the 4BSD KNF (Kernel Normal Form). |
* Style guide for the 4BSD KNF (Kernel Normal Form). |
* |
* |
* from: @(#)style 1.12 (Berkeley) 3/18/94 |
* from: @(#)style 1.12 (Berkeley) 3/18/94 |
* $Id$ |
*/ |
|
/* |
|
* An indent(1) profile approximating the style outlined in |
|
* this document lives in /usr/share/misc/indent.pro. It is a |
|
* useful tool to assist in converting code to KNF, but indent(1) |
|
* output generated using this profile must not be considered to |
|
* be an authoritative reference. |
*/ |
*/ |
|
|
/* |
/* |
Line 122 main(argc, argv) |
|
Line 130 main(argc, argv) |
|
* should be checked for accuracy. Code that cannot be reached should |
* should be checked for accuracy. Code that cannot be reached should |
* have a NOTREACHED comment. |
* have a NOTREACHED comment. |
*/ |
*/ |
while ((ch = getopt(argc, argv, "abn")) != EOF) |
while ((ch = getopt(argc, argv, "abn")) != -1) |
switch (ch) { /* Indent the switch. */ |
switch (ch) { /* Indent the switch. */ |
case 'a': /* Don't indent the case. */ |
case 'a': /* Don't indent the case. */ |
aflag = 1; |
aflag = 1; |
Line 133 main(argc, argv) |
|
Line 141 main(argc, argv) |
|
case 'n': |
case 'n': |
num = strtol(optarg, &ep, 10); |
num = strtol(optarg, &ep, 10); |
if (num <= 0 || *ep != '\0') |
if (num <= 0 || *ep != '\0') |
err("illegal number -- %s", optarg); |
err(1,"illegal number -- %s", optarg); |
break; |
break; |
case '?': |
case '?': |
default: |
default: |
Line 166 main(argc, argv) |
|
Line 174 main(argc, argv) |
|
while (cnt < 20) |
while (cnt < 20) |
z = a + really + long + statment + that + needs + two lines + |
z = a + really + long + statment + that + needs + two lines + |
gets + indented + four + spaces + on + the + second + |
gets + indented + four + spaces + on + the + second + |
and + subsequent + lines. |
and + subsequent + lines; |
|
|
/* |
/* |
* Closing and opening braces go on the same line as the else. |
* Closing and opening braces go on the same line as the else. |
Line 187 main(argc, argv) |
|
Line 195 main(argc, argv) |
|
/* |
/* |
* Unary operators don't require spaces, binary operators do. Don't |
* Unary operators don't require spaces, binary operators do. Don't |
* use parenthesis unless they're required for precedence, or the |
* use parenthesis unless they're required for precedence, or the |
* statement is really confusing without them. |
* statement is really confusing without them, such as: |
|
* a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1; |
*/ |
*/ |
a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1; |
a = ((b->c[0] + ~d == (e || f)) || (g && h)) ? i : (j >> 1); |
k = !(l & FLAGS); |
k = !(l & FLAGS); |
|
|
/* |
/* |
Line 200 main(argc, argv) |
|
Line 209 main(argc, argv) |
|
} |
} |
|
|
/* |
/* |
* If a function type is declared, it should be on a line |
* The function type must be declared on a line by itself |
* by itself preceeding the function. |
* preceeding the function. |
*/ |
*/ |
static char * |
static char * |
function(a1, a2, fl, a4) |
function(a1, a2, fl, a4) |
Line 212 function(a1, a2, fl, a4) |
|
Line 221 function(a1, a2, fl, a4) |
|
* When declaring variables in functions declare them sorted by size, |
* When declaring variables in functions declare them sorted by size, |
* then in alphabetical order; multiple ones per line are okay. Old |
* then in alphabetical order; multiple ones per line are okay. Old |
* style function declarations can go on the same line. ANSI style |
* style function declarations can go on the same line. ANSI style |
* function declarations should go in the include file "externs.h". |
* function declarations should go in the include file "extern.h". |
* If a line overflows reuse the type keyword. |
* If a line overflows reuse the type keyword. |
* |
* |
* DO NOT initialize variables in the declarations. |
* DO NOT initialize variables in the declarations. |
Line 252 function(a1, a2, fl, a4) |
|
Line 261 function(a1, a2, fl, a4) |
|
} |
} |
|
|
/* |
/* |
* Don't use ANSI function declarations unless you absolutely have too, |
* Don't use ANSI function declarations unless you absolutely have to, |
* i.e. you're declaring functions with variable numbers of arguments. |
* i.e. you're declaring functions with variable numbers of arguments. |
* |
* |
* ANSI function braces look like regular function braces. |
* ANSI function braces look like regular function braces. |
*/ |
*/ |
|
void |
function(int a1, int a2) |
function(int a1, int a2) |
{ |
{ |
... |
... |