-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnu_standard.c
188 lines (161 loc) · 3.11 KB
/
gnu_standard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* code_standard.c
*
* Follow the following practice in writing GNU source code
*
* Reference: GNU Coding Standard, http://www.gnu.org/prep/standards
*
*/
#if 0
/*
* ==START OF FILE==
* *File name
* *A line or two about the overall purpose of the file
*/
/*
* foo.c
* driver for Ethernet chips (DM9000A)
*/
/*
* ==FUNCTION HEADER==
*/
/**
* \brief swap two integer variables
* \param a pointer to first variable
* \param b pointer to second variable
* \retval 0 on success
* \retval -1 on failure
*/
/*
* ==DECLARING Global or static VARAIBLE==
* *There should be a comment on each static and global variable
* *Avoid upper case letters, use lower case letters and underscore
*/
/* Nonzero means truncate lines in the display;
zero means continue them. */
static int truncate_lines;
/*
* ==FUNCTION==
* *Return type on new line
* *Function name on new line
* *Open-brace on new line
*/
static char *
foo (char *s1, char *s2)
{
//...
}
/*
* ==COMMENTS WITHIN FUNCTIONS==
* *use capital letters to indicate the value in a variable
*/
int node;
//Search for all NODE
for (node = 0; node < MAX; node++)
{
//...
}
/*
* ==CODE==
* *Each level of indentation consists of 2 spaces '{'
* *Add space before open-parentheses '('
* *Add space after comma ','
*/
if (x < foo (y, z))
haha = bar[4] + 5;
else
{
while (z)
{
haha += foo (z, z);
z--;
}
return ++x + bar ();
}
/*
* ==EXPRESSION ON MULTIPLE LINES==
* *Split it before an operator, not after one
*/
if (foo_this_is_long && bar > win (x, y, z)
&& remaining_condition)
/*
* ==DO-WHILE LOOP==
* *Use the following format
*/
do
{
a = foo (a);
}
while (a > 0);
/*
* ==SWITCH-CASE==
* *Use the following format
*/
switch (a)
{
case 0:
{
break;
}
case 1:
{
break;
}
default:
}
/*
* ==#else-#endif==
* *Every #endif should have a comment
* *The comment should state the condition of the conditional that is ending, including its sense.
* *#else should have a comment describing the condition and sense of the code that follows.
*/
#ifdef foo
//...
#else /* not foo */
//...
#endif /* not foo */
#ifdef foo
//...
#endif /* foo */
#ifndef foo
//...
#else /* foo */
//...
#endif /* foo */
#ifndef foo
//...
#endif /* not foo */
/*
* ==#define-enum==
* *When you want to define names with constant integer values, use enum rather than #define
*/
/**
* \enum SMTP_ERR
* SMTP ERROR code
*/
enum SMTP_ERR
{
/** No error */
SMTP_ERR_OK,
/** Timeout */
SMTP_ERR_TIMEOUT,
/** Mail server not ready */
SMTP_ERR_NOT_READY,
/** Error in HELO reply */
SMTP_ERR_HELO,
/** Sender address unavailable */
SMTP_ERR_MAIL_FROM,
/** Recipient address unavailable */
SMTP_ERR_RCPT_TO,
/** Cannot start sending data */
SMTP_ERR_DATA_START,
/** Cannot stop sending data */
SMTP_ERR_DATA_END,
/** AUTH LOGIN not supported */
SMTP_ERR_AUTH_LOGIN,
/** Invalid login name */
SMTP_ERR_USERNAME,
/** Invalid password */
SMTP_ERR_PASSWORD
};
#endif /* do not compile */