Bumps for pacman 3.0.3
[pacman.git] / HACKING
blobea8936dbe844097dde7778127ab9304abc305c6c
1 Contributing to pacman
2 ======================
4 Please read 'submitting-patches' and 'translation-help' in the same directory
5 as this file.
7 Coding style
8 ------------
10 1.  All code should be indented with tabs. (Ignore the use of only spaces in
11     this file) By default, source files contain the following VIM modeline:
12       /* vim: set ts=2 sw=2 noet: */
14 2.  When opening new blocks such as 'while', 'if', or 'for', leave the opening
15     brace on the same line as the beginning of the codeblock. The closing brace
16     gets its own line (the only exception being 'else'). Do not use extra
17     spaces around the parentheses of the block. ALWAYS use opening/closing
18     braces, even if it's just a one-line block.
20     for(lp = list; lp; lp = lp->next) {
21       newlist = _alpm_list_add(newlist, strdup(lp->data));
22     }
24     while(it) {
25       ptr = it->next;
26       if(fn) {
27         fn(it->data);
28       } else {
29         return(1);
30       }
31       free(it);
32       it = ptr;
33     }
35 3.  When declaring a new function, put the opening and closing braces on their
36     own line. Also, when declaring a pointer, do not put a space between the
37     asterisk and the variable name.
39     pmlist_t *_alpm_list_add(pmlist_t *list, void *data)
40     {
41       pmlist_t *ptr, *lp;
43       ptr = list;
44      if(ptr == NULL) {
45     ...
46     }
48 4.  Comments should be ANSI-C89 compliant. That means no "// Comment" style;
49     use only "/* Comment */" style.
51 5.  Return statements should be written like a function call.
53     return(0);
54        NOT
55     return 0;
57 6.  The sizeof() operator should accept a type, not a value. (TODO: in certain
58     cases, it may be better- should this be a set guideline? Read "The Practice
59     of Programming")
61     sizeof(alpm_list_t);
62        NOT
63     sizeof(*mylist);
65 Other Concerns
66 --------------
68 Currently our #include usage is in messy shape, but this is no reason to
69 continue down this messy path. When adding an include to a file, follow this
70 general pattern, including blank lines:
72 #include "config.h"
74 #include <standardheader.h>
75 #include <another.h>
76 #include <...>
78 Follow this with some more headers, depending on whether the file is in libalpm
79 or pacman proper. For libalpm:
81 /* libalpm */
82 #include "yourfile.h"
83 #include "alpm_list.h"
84 #include "anythingelse.h"
86 For pacman:
88 #include <alpm.h>
89 #include <alpm_list.h>
91 /* pacman */
92 #include "yourfile.h"
93 #include "anythingelse.h"
95 vim: set ts=2 sw=2 et: