2008-01-06 17:14:18 -05:00
|
|
|
Pacman - Contributing
|
|
|
|
=====================
|
2007-02-20 11:29:21 -05:00
|
|
|
|
2008-01-06 17:14:18 -05:00
|
|
|
This file is meant to give you a brief overview of coding style and other
|
|
|
|
concerns when hacking on pacman. If you are interested in contributing, please
|
|
|
|
read link:submitting-patches.html[submitting-patches] and
|
|
|
|
link:translation-help.html[translation-help] as well.
|
2007-02-26 04:19:33 -05:00
|
|
|
|
2013-10-31 17:55:54 -04:00
|
|
|
Coding Style
|
2007-02-20 11:29:21 -05:00
|
|
|
------------
|
|
|
|
|
|
|
|
1. All code should be indented with tabs. (Ignore the use of only spaces in
|
2013-10-31 17:55:54 -04:00
|
|
|
this file) By default, source files contain the following Vim modeline:
|
2007-11-20 19:58:09 -05:00
|
|
|
+
|
2010-07-02 19:18:58 -04:00
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
2007-11-20 19:58:09 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|
2010-07-02 19:18:58 -04:00
|
|
|
-------------------------------------------
|
2007-02-20 11:29:21 -05:00
|
|
|
|
|
|
|
2. When opening new blocks such as 'while', 'if', or 'for', leave the opening
|
|
|
|
brace on the same line as the beginning of the codeblock. The closing brace
|
|
|
|
gets its own line (the only exception being 'else'). Do not use extra
|
2007-11-20 19:58:09 -05:00
|
|
|
spaces around the parentheses of the block. ALWAYS use opening and closing
|
2007-11-19 16:46:02 -05:00
|
|
|
braces, even if it's just a one-line block. This reduces future error when
|
|
|
|
blocks are expanded beyond one line.
|
2007-11-20 19:58:09 -05:00
|
|
|
+
|
2010-07-02 19:18:58 -04:00
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
2007-11-20 19:58:09 -05:00
|
|
|
for(lp = list; lp; lp = lp->next) {
|
|
|
|
newlist = _alpm_list_add(newlist, strdup(lp->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
while(it) {
|
|
|
|
ptr = it->next;
|
|
|
|
if(fn) {
|
|
|
|
fn(it->data);
|
|
|
|
} else {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-11-20 19:58:09 -05:00
|
|
|
}
|
|
|
|
free(it);
|
|
|
|
it = ptr;
|
|
|
|
}
|
2010-07-02 19:18:58 -04:00
|
|
|
-------------------------------------------
|
2007-02-20 11:29:21 -05:00
|
|
|
|
|
|
|
3. When declaring a new function, put the opening and closing braces on their
|
|
|
|
own line. Also, when declaring a pointer, do not put a space between the
|
|
|
|
asterisk and the variable name.
|
2007-11-20 19:58:09 -05:00
|
|
|
+
|
2010-07-02 19:18:58 -04:00
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
2007-11-20 19:58:09 -05:00
|
|
|
alpm_list_t *alpm_list_add(alpm_list_t *list, void *data)
|
|
|
|
{
|
|
|
|
alpm_list_t *ptr, *lp;
|
|
|
|
|
|
|
|
ptr = list;
|
|
|
|
if(ptr == NULL) {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
2010-07-02 19:18:58 -04:00
|
|
|
-------------------------------------------
|
2007-11-20 19:58:09 -05:00
|
|
|
|
|
|
|
4. Comments should be ANSI-C89 compliant. That means no `// Comment` style;
|
|
|
|
use only `/* Comment */` style.
|
2007-02-20 11:29:21 -05:00
|
|
|
|
2007-11-19 16:46:02 -05:00
|
|
|
/* This is a comment */
|
|
|
|
NOT
|
|
|
|
// This is a comment
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
5. Return statements should *not* be written like function calls.
|
2007-02-20 11:29:21 -05:00
|
|
|
|
|
|
|
return 0;
|
2011-03-20 20:45:57 -04:00
|
|
|
NOT
|
|
|
|
return(0);
|
2007-02-20 11:29:21 -05:00
|
|
|
|
|
|
|
6. The sizeof() operator should accept a type, not a value. (TODO: in certain
|
|
|
|
cases, it may be better- should this be a set guideline? Read "The Practice
|
|
|
|
of Programming")
|
|
|
|
|
|
|
|
sizeof(alpm_list_t);
|
|
|
|
NOT
|
|
|
|
sizeof(*mylist);
|
|
|
|
|
2007-11-19 16:46:02 -05:00
|
|
|
7. When using strcmp() (or any function that returns 0 on success) in a
|
|
|
|
conditional statement, use != 0 or == 0 and not the negation (!) operator.
|
|
|
|
It reads much cleaner for humans (using a negative to check for success is
|
|
|
|
confusing) and the compiler will treat it correctly anyway.
|
|
|
|
|
|
|
|
if(strcmp(a, b) == 0)
|
|
|
|
NOT
|
|
|
|
if(!strcmp(a, b))
|
|
|
|
|
2011-12-21 18:00:28 -05:00
|
|
|
8. Use spaces around almost all arithmetic, comparison and assignment
|
|
|
|
operators and after all ',;:' separators.
|
|
|
|
|
|
|
|
foobar[2 * size + 1] = function(a, 6);
|
|
|
|
NOT
|
|
|
|
foobar[2*size+1]=function(a,6);
|
|
|
|
|
2013-01-03 18:10:40 -05:00
|
|
|
for(a = 0; a < n && n > 0; a++, n--) {}
|
2011-12-21 18:00:28 -05:00
|
|
|
NOT
|
|
|
|
for(a=0;a<n&&n>0;a++,n--) {}
|
|
|
|
|
2012-07-31 14:24:31 -04:00
|
|
|
9. Declare all variables at the start of the block.
|
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
|
|
|
int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
|
|
|
|
{
|
|
|
|
char *newurl, *vdata = NULL;
|
|
|
|
|
|
|
|
newurl = url;
|
|
|
|
if(!newurl) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
if(vdata) {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
-------------------------------------------
|
|
|
|
|
|
|
|
NOT
|
|
|
|
|
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
|
|
|
int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
|
|
|
|
{
|
|
|
|
char *newurl = url;
|
|
|
|
|
|
|
|
if(!newurl) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *vdata = NULL;
|
|
|
|
|
|
|
|
if(vdata) {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
-------------------------------------------
|
|
|
|
|
2007-11-19 16:46:02 -05:00
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
Other Concerns
|
|
|
|
--------------
|
|
|
|
|
2007-11-20 19:58:09 -05:00
|
|
|
Header Includes
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
Currently our #include usage is in messy shape, but this is no reason to
|
|
|
|
continue down this messy path. When adding an include to a file, follow this
|
|
|
|
general pattern, including blank lines:
|
|
|
|
|
2010-07-02 19:18:58 -04:00
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
2007-03-05 17:13:33 -05:00
|
|
|
#include <standardheader.h>
|
|
|
|
#include <another.h>
|
|
|
|
#include <...>
|
2010-07-02 19:18:58 -04:00
|
|
|
-------------------------------------------
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
Follow this with some more headers, depending on whether the file is in libalpm
|
|
|
|
or pacman proper. For libalpm:
|
|
|
|
|
2010-07-02 19:18:58 -04:00
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
2007-03-05 17:13:33 -05:00
|
|
|
/* libalpm */
|
|
|
|
#include "yourfile.h"
|
|
|
|
#include "alpm_list.h"
|
|
|
|
#include "anythingelse.h"
|
2010-07-02 19:18:58 -04:00
|
|
|
-------------------------------------------
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
For pacman:
|
|
|
|
|
2010-07-02 19:18:58 -04:00
|
|
|
[source,C]
|
|
|
|
-------------------------------------------
|
2007-03-05 17:13:33 -05:00
|
|
|
#include <alpm.h>
|
|
|
|
#include <alpm_list.h>
|
|
|
|
|
|
|
|
/* pacman */
|
|
|
|
#include "yourfile.h"
|
|
|
|
#include "anythingelse.h"
|
2010-07-02 19:18:58 -04:00
|
|
|
-------------------------------------------
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2011-12-17 21:42:35 -05:00
|
|
|
Never directly include config.h. This will always be added via Makefiles.
|
|
|
|
|
2009-11-15 21:21:50 -05:00
|
|
|
GDB and Valgrind Usage
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
When using GDB or valgrind on pacman, you will want to run it on the actual
|
|
|
|
binary rather than the shell script wrapper produced by libtool. The actual
|
|
|
|
binary lives at `src/pacman/.libs/lt-pacman`, and will exist after running
|
|
|
|
`./src/pacman/pacman` at least once.
|
|
|
|
|
|
|
|
For example, to run valgrind:
|
|
|
|
|
|
|
|
./src/pacman/pacman
|
|
|
|
valgrind --leak-check=full -- src/pacman/.libs/lt-pacman -Syu
|
|
|
|
|
2007-11-20 19:58:09 -05:00
|
|
|
/////
|
2011-06-22 12:06:34 -04:00
|
|
|
vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
|
2007-11-20 19:58:09 -05:00
|
|
|
/////
|