69,382
社区成员
发帖
与我相关
我的任务
分享
/* $NetBSD: style,v 1.45 2009/02/15 07:01:41 dholland Exp $ */
/*
* The revision control tag appears first, with a blank line after it.
* Copyright text appears after the revision control tag.
*/
/*
* The NetBSD source code style guide.
* (Previously known as KNF - Kernel Normal Form).
*
* from: @(#)style 1.12 (Berkeley) 3/18/94
*/
/*
* 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.
*/
/*
* Source code revision control identifiers appear after any copyright
* text. Use the appropriate macros from <sys/cdefs.h>. Usually only one
* source file per program contains a __COPYRIGHT() section.
* Historic Berkeley code may also have an __SCCSID() section.
* Only one instance of each of these macros can occur in each file.
* Don't use newlines in the identifiers.
*/
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: style,v 1.45 2009/02/15 07:01:41 dholland Exp $");
/*
* VERY important single-line comments look like this.
*/
/* Most single-line comments look like this. */
/*
* Multi-line comments look like this. Make them real sentences. Fill
* them so they look like real paragraphs.
*/
/*
* Attempt to wrap lines longer than 80 characters appropriately.
* Refer to the examples below for more information.
*/
/*
* EXAMPLE HEADER FILE:
*
* A header file should protect itself against multiple inclusion.
* E.g, <sys/socket.h> would contain something like:
*/
#ifndef _SYS_SOCKET_H_
#define _SYS_SOCKET_H_
/*
* Contents of #include file go between the #ifndef and the #endif at the end.
*/
#endif /* !_SYS_SOCKET_H_ */
/*
* END OF EXAMPLE HEADER FILE.
*/
/*
* If a header file requires structures, defines, typedefs, etc. from
* another header file it should include that header file and not depend
* on the including file for that header including both. If there are
* exceptions to this for specific headers it should be clearly documented
* in the headers and, if appropriate, the documentation. Nothing in this
* rule should suggest relaxation of the multiple inclusion rule and the
* application programmer should be free to include both regardless.
*/
/*
* Kernel include files come first.
*/
#include <sys/types.h> /* Non-local includes in brackets. */
/*
* If it's a network program, put the network include files next.
* Group the includes files by subdirectory.
*/
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
#include <protocols/rwhod.h>
/*
* Then there's a blank line, followed by the /usr include files.
* The /usr include files should be sorted!
*/
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Global pathnames are defined in /usr/include/paths.h. Pathnames local
* to the program go in pathnames.h in the local directory.
*/
#include <paths.h>
/* Then, there's a blank line, and the user include files. */
#include "pathnames.h" /* Local includes in double quotes. */
/*
* ANSI function declarations for private functions (i.e. functions not used
* elsewhere) and the main() function go at the top of the source module.
* Don't associate a name with the types. I.e. use:
* void function(int);
* Use your discretion on indenting between the return type and the name, and
* how to wrap a prototype too long for a single line. In the latter case,
* lining up under the initial left parenthesis may be more readable.
* In any case, consistency is important!
*/
static char *function(int, int, float, int);
static int dirinfo(const char *, struct stat *, struct dirent *,
struct statfs *, int *, char **[]);
static void usage(void);
int main(int, char *[]);
/*
* Macros are capitalized, parenthesized, and should avoid side-effects.
* Spacing before and after the macro name may be any whitespace, though
* use of TABs should be consistent through a file.
* If they are an inline expansion of a function, the function is defined
* all in lowercase, the macro has the same name all in uppercase.
* If the macro is an expression, wrap the expression in parenthesis.
* If the macro is more than a single statement, use ``do { ... } while (0)'',
* so that a trailing semicolon works. Right-justify the backslashes; it
* makes it easier to read. The CONSTCOND comment is to satisfy lint(1).
*/
#define MACRO(v, w, x, y) \
do { \
v = (x) + (y); \
w = (y) + 2; \
} while (/* CONSTCOND */ 0)
#define DOUBLE(x) ((x) * 2)
/* Enum types are capitalized. No comma on the last element. */
enum enumtype {
ONE,
TWO
} et;
/*
* When declaring variables in structures, declare them organized by use in
* a manner to attempt to minimize memory wastage because of compiler alignment
* issues, then by size, and then by alphabetical order. E.g, don't use
* ``int a; char *b; int c; char *d''; use ``int a; int b; char *c; char *d''.
* Each variable gets its own type and line, although an exception can be made
* when declaring bitfields (to clarify that it's part of the one bitfield).
* Note that the use of bitfields in general is discouraged.
*
* Major structures should be declared at the top of the file in which they
* are used, or in separate header files, if they are used in multiple
* source files. Use of the structures should be by separate declarations
* and should be "extern" if they are declared in a header file.
*
* It may be useful to use a meaningful prefix for each member name.
* E.g, for ``struct softc'' the prefix could be ``sc_''.
*/
struct foo {
struct foo *next; /* List of active foo */
struct mumble amumble; /* Comment for mumble */
int bar;
unsigned int baz:1, /* Bitfield; line up entries if desired */
fuz:5,
zap:2;
uint8_t flag;
};
struct foo *foohead; /* Head of global foo list */
/* Make the structure name match the typedef. */
typedef struct BAR {
int level;
} BAR;
/* C99 uintN_t is preferred over u_intN_t. */
uint32_t zero;
while ((ch = getopt(argc, argv, "abn:")) != -1) {
switch (ch) { /* Indent the switch. */
case 'a': /* Don't indent the case. */
aflag = 1;
/* FALLTHROUGH */
case 'b':
bflag = 1;
break;
case 'n':
errno = 0;
num = strtol(optarg, &ep, 10);
if (num <= 0 || *ep != '\0' || (errno == ERANGE &&
(num == LONG_MAX || num == LONG_MIN)) )
errx(1, "illegal number -- %s", optarg);
break;
case '?':
default:
usage();
/* NOTREACHED */
}
}
int
main(int n,char **p)
for(;;)
还有这样的:
for(...;...;...)
continue;
DU8 D_FONT_ShowChar( DU16 chCode, DS32 x, DS32 y, DU32 color)
{
unsigned short uni_str[2];
char gb_str[3];
if ((x >= D_OSD_GetWidth()) || (y >= D_OSD_GetHeight()))
{
return fontStr.fontCurWidth;
}
if((chCode >>8)!=0)
{
chCode = chCode | 0x8080;
}
gb_str[0]=chCode>>8;
gb_str[1]=chCode&0x00ff;
gb_str[2]='\0';
}
/*
*File: scanner.c
*/
#include <stdio.h>
#include <ctype.h>
#include "genlib.h"
#include "strlib.h"
#include "scanner_10-3.h"
/*
*
*/
static string buffer;
static int buflen;
static int cpos;
/*
*
*/
void IntScanner(string line)
{
buffer = line;
buflen = StringLength(buffer);
cpos = 0;
}
/*
*
*/
string GetNextToken(void)
{
char ch;
int start;
if (cpos >= buflen) printf("No more tokes");
ch = IthChar(buffer, cpos);
if(isalnum(ch))
{
start = cpos;
while (cpos < buflen && isalnum(IthChar(buffer, cpos)))
{
cpos ++;
}
return (SubString(buffer, start, cpos - 1));
}
else
{
cpos ++;
return (CharToString(ch));
}
}
/*
*
*/
int AtEndofLine(void)
{
if(cpos >= buflen)
return (1);
else
return(0);
}