forked from bert/libdxf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHACKING
More file actions
246 lines (201 loc) · 7.69 KB
/
HACKING
File metadata and controls
246 lines (201 loc) · 7.69 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
======= CODING STANDARD FOR LIBDXF =======
Rationale on Coding Style
-------------------------
Here follow some notes to myself, or any other volunteer hacker who wants to
join the effort.
The coding style I follow is the Allman style, named after Eric Allman.
It is sometimes referred to as "ANSI style" for its use in the documents
describing the ANSI C standard.
Proponents of this style often cite its use by ANSI and in other standards as
justification for its adoption.
This style is similar to the standard indentation used by the Pascal programming
language and Transact-SQL, where the braces are equivalent to the "begin" and
"end" keywords.
As I started programming in Pascal way back in the 80's of the former century,
this is the reason for using this coding style in my C code.
If you choose to join in on the fun with your own style, this is not a show
stopper for me.
Please understand that I might reformat your contribution to my own likings as
not to strain my eyes too much.
File headers
------------
File headers contain Doxygen style tags for doumentation generated with Doxygen.
A default header looks similar to the following:
/*!
* \file default.c
* \author Copyright (C) 2008 by Author <author@email.address>
* \brief A brief description of the files use.
*
* A more elaborate description follows here, and can span several lines.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.\n
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n
* See the GNU General Public License for more details.\n
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:\n
* the Free Software Foundation, Inc., \n
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
Doxygen style comments
----------------------
The prefered style for a Doxygen comment for a function or any other entity is:
/*!
* \brief Brief description.
*
* Followed by a more verbose description of what is to be explained about the
* entity.
* \param Description of a parameter.
* \bugs Can be reported here.
* \exception Can be described here.
* \return Return value can be described here.
* \todo Can be described here.
* The more verbose statement is closed with:
*/
Comments
--------
/* Comments should be added at the correct level of identation. */
/* More elaborate comments, which span across the 80 character limit,
* (described below) should have an asterisk in front on every line of the
* comment.
*/
Indentation
-----------
To hack in this code you need to set emacs (or whatever editor you use) to
8 indentation steps and {} at the right places (see code).
No tabs, just plain spaces, except in Makefiles and config stuff where tabs
have a meaning.
My ~/.emacs are:
(defun my-c-mode-hook ()
(turn-on-font-lock)
(setq c-basic-offset 8))
(add-hook 'c-mode-hook 'my-c-mode-hook)
Truncation
----------
It is prefered for lines to not extend beyond 80 characters long.
If you need more than 40 characters to ident (5 levels) you probably should
write a function.
However, I'm not very strict about this myself.
Please do truncate a line at a convenient position, for example:
if (((very_elaborate_variable_description_1 > 0)
|| (very_elaborate_variable_description_2 < 0))
&& (very_elaborate_variable_description_3 > 1000))
{
blah;
}
Improve readability by putting the operator at the start of the new line.
Curly Braces
------------
if ()
{
blah1 ();
blah2 ();
}
else
{
yada1 ();
yada2 ();
}
If there is only one statement you don't need the braces.
for ()
{
do_whatever1 ();
do_whatever2 ();
}
switch ()
{
case foo:
blah1 ();
break;
case bar:
blah2 ();
break;
default:
break;
}
Switch should always have a default case.
Note the whitespace before the ().
ChangeLog
---------
A ChangeLog is generated from all commit message entries entered when a blob
of code is committed with git.
I generate the ChangeLog prior to a new release.
About git commit messages and blobs
-----------------------------------
Keep commit messages as clear as possible:
If a file is added or deleted mentioning "new file: blah.c" or
"deleted file: blah2.c" says it all.
Keep blobs as granular as possible, do not commit blobs from different files in
a single commit. I would rather have five commits if that is what it takes.
About git branches and merging
------------------------------
Use the branch and merge functionality of git for every experiment or issue
[#ticket] to be solved.
As I'm still learning things about git every day I find this a good practice,
and I'm going to have to adopt to this myself.
Functions
---------
The prototype should have return type on the same line as function name:
int some_function (int par1, int par2);
The function implementation should have return type on a separate line
(including eventual pointer star).
The function implementation should have the function name in c-comments
at the closing brace, although I'm not strict with doing this myself (me bad).
int *
some_function (int par1, int par2)
{
/* Implementation */
} /* some_function */
or
int *
some_function
(
int par1, /*!< some Doxygen comment about par1 */
int par2
/*!< some Doxygen comment about par2 which is more elaborate
* and extends the 80 character limit by far.\n
* Add a \n when a new line is to be generated in the Doxygen
* documentation.
*/
)
{
/* Implementation */
} /* some_function */
In a function there should be a maximum of one empty line in a row.
Between functions there should be two empty lines.
Log messages.
-------------
It is prefered to log messages similar like the following example:
<example>
g_log ("", G_LOG_LEVEL_WARNING,
_("pin #1 position with a null pointer found in: %s.\n"),
fpw_filename);
</example>
The following criticality is (and should be) maintained:
/* GLib log levels */
G_LOG_LEVEL_ERROR = 1 << 2, /* Always fatal, abort the application. */
G_LOG_LEVEL_CRITICAL = 1 << 3, /* Functionality of the operation or
* function is no longer guaranteed,
* unwanted or unexpected behaviour
* follows. */
G_LOG_LEVEL_WARNING = 1 << 4, /* Functionality of the operation or
* function is still guaranteed.
* The application will default to a
* safe and expected behaviour. */
G_LOG_LEVEL_MESSAGE = 1 << 5, /* Instructions for the user. */
G_LOG_LEVEL_INFO = 1 << 6, /* Information usefull for the user. */
* Requires the verbose variable to be
* set. */
G_LOG_LEVEL_DEBUG = 1 << 7, /* Information usefull for the developer. */
* Requires the debug variable to be
* set. */
End Of File
-----------
The End Of File is denoted with a comment and a blank line such as:
/* EOF */