Remove unnecessary header file, move one macro to util.c
[pacman-ng.git] / HACKING
blob230cbb09a984bb0e21440392144741312de8b458
1 Pacman - Contributing
2 =====================
4 This file is meant to give you a brief overview of coding style and other
5 concerns when hacking on pacman. If you are interested in contributing, please
6 read link:submitting-patches.html[submitting-patches] and
7 link:translation-help.html[translation-help] as well.
9 Coding style
10 ------------
12 1.  All code should be indented with tabs. (Ignore the use of only spaces in
13     this file) By default, source files contain the following VIM modeline:
15 [C]
16 code~~~~~~~~~~
17 /* vim: set ts=2 sw=2 noet: */
18 code~~~~~~~~~~
20 2.  When opening new blocks such as 'while', 'if', or 'for', leave the opening
21     brace on the same line as the beginning of the codeblock. The closing brace
22     gets its own line (the only exception being 'else'). Do not use extra
23     spaces around the parentheses of the block. ALWAYS use opening and closing
24     braces, even if it's just a one-line block. This reduces future error when
25     blocks are expanded beyond one line.
27 [C]
28 code~~~~~~~~~~
29 for(lp = list; lp; lp = lp->next) {
30   newlist = _alpm_list_add(newlist, strdup(lp->data));
33 while(it) {
34   ptr = it->next;
35   if(fn) {
36     fn(it->data);
37   } else {
38     return(1);
39   }
40   free(it);
41   it = ptr;
43 code~~~~~~~~~~
45 3.  When declaring a new function, put the opening and closing braces on their
46     own line. Also, when declaring a pointer, do not put a space between the
47     asterisk and the variable name.
49 [C]
50 code~~~~~~~~~~
51 alpm_list_t *alpm_list_add(alpm_list_t *list, void *data)
53   alpm_list_t *ptr, *lp;
55   ptr = list;
56   if(ptr == NULL) {
57   ...
58   }
59   ...
61 code~~~~~~~~~~
63 4.  Comments should be ANSI-C89 compliant. That means no `// Comment` style;
64     use only `/* Comment */` style.
66     /* This is a comment */
67        NOT
68     // This is a comment
70 5.  Return statements should be written like a function call.
72     return(0);
73        NOT
74     return 0;
76 6.  The sizeof() operator should accept a type, not a value. (TODO: in certain
77     cases, it may be better- should this be a set guideline? Read "The Practice
78     of Programming")
80     sizeof(alpm_list_t);
81        NOT
82     sizeof(*mylist);
84 7.  When using strcmp() (or any function that returns 0 on success) in a
85     conditional statement, use != 0 or == 0 and not the negation (!) operator.
86     It reads much cleaner for humans (using a negative to check for success is
87     confusing) and the compiler will treat it correctly anyway.
89     if(strcmp(a, b) == 0)
90        NOT
91     if(!strcmp(a, b))
94 Other Concerns
95 --------------
97 Header Includes
98 ~~~~~~~~~~~~~~~
100 Currently our #include usage is in messy shape, but this is no reason to
101 continue down this messy path. When adding an include to a file, follow this
102 general pattern, including blank lines:
105 code~~~~~~~~~~
106 #include "config.h"
108 #include <standardheader.h>
109 #include <another.h>
110 #include <...>
111 code~~~~~~~~~~
113 Follow this with some more headers, depending on whether the file is in libalpm
114 or pacman proper. For libalpm:
117 code~~~~~~~~~~
118 /* libalpm */
119 #include "yourfile.h"
120 #include "alpm_list.h"
121 #include "anythingelse.h"
122 code~~~~~~~~~~
124 For pacman:
127 code~~~~~~~~~~
128 #include <alpm.h>
129 #include <alpm_list.h>
131 /* pacman */
132 #include "yourfile.h"
133 #include "anythingelse.h"
134 code~~~~~~~~~~
136 /////
137 vim: set ts=2 sw=2 syntax=asciidoc et:
138 /////